Commit c96edb51 authored by Marijn van Wezel's avatar 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
{
"name": "Semantic Structured Discussions",
"type": "semantic",
"version": "1.2.1",
"version": "1.3.0",
"author": [
"Marijn van Wezel ([https://wikibase-solutions.com Wikibase Solutions])"
],
......
......@@ -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( $content )
new SMWDIBlob( $this->reply->getContent() )
);
}
......@@ -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;
}
}
......@@ -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();
......
......@@ -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'] );
}
/**
......
......@@ -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;
}
}
/**
......
......@@ -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 ) {
......
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