Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Community
Semantic Structured Discussions
Commits
c96edb51
Commit
c96edb51
authored
May 03, 2022
by
Marijn van Wezel
❤
Browse files
Use format='html' directly instead of using the MediaWiki Parser
parent
5798b62a
Pipeline
#2989
passed with stage
in 9 seconds
Changes
6
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
extension.json
View file @
c96edb51
{
"name"
:
"Semantic Structured Discussions"
,
"type"
:
"semantic"
,
"version"
:
"1.
2.1
"
,
"version"
:
"1.
3.0
"
,
"author"
:
[
"Marijn van Wezel ([https://wikibase-solutions.com Wikibase Solutions])"
],
...
...
src/SemanticMediaWiki/Annotators/ReplyAnnotators/ContentAnnotator.php
View file @
c96edb51
...
...
@@ -45,12 +45,9 @@ class ContentAnnotator extends ReplyAnnotator {
* @inheritDoc
*/
public
function
addAnnotation
(
SemanticData
$semanticData
):
void
{
$wikitext
=
$this
->
reply
->
getContent
();
$content
=
strip_tags
(
$this
->
parse
(
$wikitext
)
);
$semanticData
->
addPropertyObjectValue
(
new
DIProperty
(
self
::
getId
()
),
new
SMWDIBlob
(
$
c
ontent
)
new
SMWDIBlob
(
$
this
->
reply
->
getC
ontent
()
)
);
}
...
...
@@ -79,26 +76,4 @@ class ContentAnnotator extends ReplyAnnotator {
'annotable'
=>
false
];
}
/**
* Parses the given wikitext using the API.
*
* @param string $wikitext
* @return string
*/
private
function
parse
(
string
$wikitext
):
string
{
$request
=
new
DerivativeRequest
(
RequestContext
::
getMain
()
->
getRequest
(),
array
(
'action'
=>
'parse'
,
'text'
=>
$wikitext
,
'contentmodel'
=>
'wikitext'
)
);
$api
=
new
ApiMain
(
$request
);
$api
->
execute
();
return
$api
->
getResult
()
->
getResultData
()[
'parse'
][
'text'
]
??
$wikitext
;
}
}
src/StructuredDiscussions/CallSubmoduleTrait.php
View file @
c96edb51
...
...
@@ -21,10 +21,12 @@
namespace
SemanticStructuredDiscussions\StructuredDiscussions
;
use
ApiMain
;
use
DerivativeRequest
;
use
Exception
;
use
FauxRequest
;
use
MediaWiki\Session\SessionManager
;
use
MWException
;
use
RequestContext
;
trait
CallSubmoduleTrait
{
/**
...
...
@@ -37,15 +39,10 @@ trait CallSubmoduleTrait {
*/
private
function
callSubmodule
(
string
$submodule
,
array
$parameters
,
bool
$wasPosted
=
false
):
?array
{
$parameters
=
[
'action'
=>
'flow'
,
'submodule'
=>
$submodule
]
+
$parameters
;
$globalSession
=
SessionManager
::
getGlobalSession
();
$baseRequest
=
RequestContext
::
getMain
()
->
getRequest
();
$derivativeRequest
=
new
DerivativeRequest
(
$baseRequest
,
$parameters
,
$wasPosted
);
try
{
$fauxRequest
=
new
FauxRequest
(
$parameters
,
$wasPosted
,
$globalSession
);
}
catch
(
MWException
$exception
)
{
return
null
;
}
$module
=
new
ApiMain
(
$fauxRequest
,
false
);
$module
=
new
ApiMain
(
$derivativeRequest
,
false
);
try
{
$module
->
execute
();
...
...
src/StructuredDiscussions/SDReply.php
View file @
c96edb51
...
...
@@ -50,12 +50,12 @@ final class SDReply {
}
/**
* Returns the content of this revision
as wikitext
.
* Returns the content of this revision
with HTML tags stripped
.
*
* @return string
*/
public
function
getContent
():
string
{
return
$this
->
replyRevision
[
'content'
][
'content'
];
return
strip_tags
(
$this
->
replyRevision
[
'content'
][
'content'
]
)
;
}
/**
...
...
src/StructuredDiscussions/SDTopic.php
View file @
c96edb51
...
...
@@ -67,7 +67,13 @@ final class SDTopic {
* @return string|null
*/
public
function
getSummary
():
?string
{
return
$this
->
getRootRevision
()[
'summary'
][
'revision'
][
'content'
][
'content'
]
??
null
;
$rootRevision
=
$this
->
getRootRevision
();
if
(
isset
(
$rootRevision
[
'summary'
][
'revision'
][
'content'
][
'content'
]
)
)
{
return
strip_tags
(
$rootRevision
[
'summary'
][
'revision'
][
'content'
][
'content'
]
);
}
else
{
return
null
;
}
}
/**
...
...
src/StructuredDiscussions/TopicRepository.php
View file @
c96edb51
...
...
@@ -36,7 +36,7 @@ class TopicRepository {
* @return SDTopic|null The corresponding Topic, or NULL when the topic does not exist or when something went wrong
*/
public
function
getByTitle
(
Title
$title
):
?SDTopic
{
$parameters
=
[
'page'
=>
$title
->
getFullText
(),
'vtformat'
=>
'
wikitext
'
];
$parameters
=
[
'page'
=>
$title
->
getFullText
(),
'vtformat'
=>
'
html
'
];
$viewTopic
=
$this
->
callSubmodule
(
'view-topic'
,
$parameters
);
if
(
$viewTopic
===
null
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment