Unverified Commit d1f437f7 authored by Marijn van Wezel's avatar Marijn van Wezel
Browse files

Use the API since the Parser is not always fully initialised

parent 811ddeb9
Pipeline #2886 passed with stage
in 10 seconds
......@@ -20,8 +20,9 @@
namespace SemanticStructuredDiscussions\SemanticMediaWiki\Annotators\ReplyAnnotators;
use MediaWiki\MediaWikiServices;
use Parser;
use ApiMain;
use DerivativeRequest;
use RequestContext;
use SemanticStructuredDiscussions\StructuredDiscussions\SDReply;
use SMW\DIProperty;
use SMW\SemanticData;
......@@ -31,11 +32,6 @@ use SMWDIBlob;
* This annotation contains information about the content of a reply.
*/
class ContentAnnotator extends ReplyAnnotator {
/**
* @var Parser The current MediaWiki parser
*/
private Parser $parser;
/**
* ContentAnnotator constructor.
*
......@@ -43,8 +39,6 @@ class ContentAnnotator extends ReplyAnnotator {
*/
public function __construct( SDReply $reply ) {
parent::__construct($reply);
$this->parser = MediaWikiServices::getInstance()->getParser();
}
/**
......@@ -52,7 +46,7 @@ class ContentAnnotator extends ReplyAnnotator {
*/
public function addAnnotation( SemanticData $semanticData ): void {
$wikitext = $this->reply->getContent();
$content = strip_tags( $this->parser->recursiveTagParseFully( $wikitext ) );
$content = strip_tags( $this->parse( $wikitext ) );
$semanticData->addPropertyObjectValue(
new DIProperty( self::getId() ),
......@@ -85,4 +79,26 @@ 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;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment