Mwjames has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/68008


Change subject: Don't run the ParserTextProcessor on SpecialPages
......................................................................

Don't run the ParserTextProcessor on SpecialPages

Thanks to the NamespaceExaminer and the existing unit tests which
uncovered that there is no reason why the ParserTextProcessor would
have to run on any SpecialPage.

Change-Id: I475c638bf97a403d55353dcfa6875f2734f7bd22
---
M SemanticMediaWiki.hooks.php
M includes/ParserTextProcessor.php
M tests/phpunit/includes/ParserTextProcessorTest.php
3 files changed, 12 insertions(+), 30 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki 
refs/changes/08/68008/1

diff --git a/SemanticMediaWiki.hooks.php b/SemanticMediaWiki.hooks.php
index f8e1154..31d8389 100644
--- a/SemanticMediaWiki.hooks.php
+++ b/SemanticMediaWiki.hooks.php
@@ -624,17 +624,15 @@
         */
        public static function onInternalParseBeforeLinks( Parser &$parser, 
&$text ) {
 
-               $settings = SMW\Settings::newFromArray( array(
-                       'smwgNamespacesWithSemanticLinks' => 
$GLOBALS['smwgNamespacesWithSemanticLinks'],
-                       'smwgLinksInValues' => $GLOBALS['smwgLinksInValues'],
-                       'smwgInlineErrors'  => $GLOBALS['smwgInlineErrors']
-               ) );
+               if ( !$parser->getTitle()->isSpecialPage() ) {
 
-               $processor = new SMW\ParserTextProcessor(
-                       new SMW\ParserData( $parser->getTitle(), 
$parser->getOutput() ),
-                       $settings
-               );
-               $processor->parse( $text );
+                       $processor = new SMW\ParserTextProcessor(
+                               new \SMW\ParserData( $parser->getTitle(), 
$parser->getOutput() ),
+                               \SMW\Settings::newFromGlobals()
+                       );
+
+                       $processor->parse( $text );
+               }
 
                return true;
        }
diff --git a/includes/ParserTextProcessor.php b/includes/ParserTextProcessor.php
index 0df3193..7cf3446 100644
--- a/includes/ParserTextProcessor.php
+++ b/includes/ParserTextProcessor.php
@@ -117,7 +117,7 @@
                $this->stripMagicWords( $text );
 
                // Attest if semantic data should be processed
-               $this->isSemanticEnabled( $title );
+               $this->isEnabled = NamespaceExaminer::newFromArray( 
$this->settings->get( 'smwgNamespacesWithSemanticLinks' ) )->isSemanticEnabled( 
$title->getNamespace() );
 
                // Process redirects
                $this->setRedirect( $title );
@@ -134,22 +134,6 @@
                $this->parserData->getOutput()->addModules( $this->getModules() 
 );
                $this->parserData->updateOutput();
                SMWOutputs::commitToParserOutput( 
$this->parserData->getOutput() );
-       }
-
-       /**
-        * Attest if semantic data should be processed and displayed
-        * for a page in the given namespace. (have to parse them in
-        * any case, in order to clean the wiki source for further processing)
-        *
-        * @since 1.9
-        *
-        * @param Title $title
-        *
-        * @return boolean
-        */
-       protected function isSemanticEnabled( Title $title ) {
-               $namespaces = $this->settings->get( 
'smwgNamespacesWithSemanticLinks' );
-               $this->isEnabled = !empty( $namespaces[$title->getNamespace()] 
);
        }
 
        /**
diff --git a/tests/phpunit/includes/ParserTextProcessorTest.php 
b/tests/phpunit/includes/ParserTextProcessorTest.php
index e423f29..dc401ec 100644
--- a/tests/phpunit/includes/ParserTextProcessorTest.php
+++ b/tests/phpunit/includes/ParserTextProcessorTest.php
@@ -364,9 +364,9 @@
                // Make protected methods accessible
                $reflection = new ReflectionClass( $this->getClass() );
 
-               $method = $reflection->getMethod( 'isSemanticEnabled' );
-               $method->setAccessible( true );
-               $method->invoke( $instance, $mockTitle );
+               $property = $reflection->getProperty( 'isEnabled' );
+               $property->setAccessible( true );
+               $property->setValue( $instance, true );
 
                $method = $reflection->getMethod( 'setRedirect' );
                $method->setAccessible( true );

-- 
To view, visit https://gerrit.wikimedia.org/r/68008
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I475c638bf97a403d55353dcfa6875f2734f7bd22
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to