Mwjames has uploaded a new change for review.

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


Change subject: ContentProcessor implements ContextAware
......................................................................

ContentProcessor implements ContextAware

Change-Id: I4a24910961c5a82b8eb5e1f1ffb41715f2f958a6
---
M SemanticMediaWiki.classes.php
R includes/ContentProcessor.php
M includes/dic/SharedDependencyContainer.php
M tests/phpunit/ParserTestCase.php
R tests/phpunit/includes/ContentProcessorTemplateTransclusionTest.php
R tests/phpunit/includes/ContentProcessorTest.php
M tests/phpunit/includes/dic/SharedDependencyContainerTest.php
7 files changed, 93 insertions(+), 135 deletions(-)


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

diff --git a/SemanticMediaWiki.classes.php b/SemanticMediaWiki.classes.php
index 45f15eb..201c7e4 100644
--- a/SemanticMediaWiki.classes.php
+++ b/SemanticMediaWiki.classes.php
@@ -30,7 +30,7 @@
        'SMW\FactboxCache'          => 'includes/FactboxCache.php',
        'SMWInfolink'               => 'includes/SMW_Infolink.php',
        'SMWOutputs'                => 'includes/SMW_Outputs.php',
-       'SMW\ParserTextProcessor'   => 'includes/ParserTextProcessor.php',
+       'SMW\ContentProcessor'      => 'includes/ContentProcessor.php',
        'SMW\SemanticData'          => 'includes/SMW_SemanticData.php',
        'SMWPageLister'             => 'includes/SMW_PageLister.php',
 
diff --git a/includes/ParserTextProcessor.php b/includes/ContentProcessor.php
similarity index 90%
rename from includes/ParserTextProcessor.php
rename to includes/ContentProcessor.php
index e262620..981aa40 100644
--- a/includes/ParserTextProcessor.php
+++ b/includes/ContentProcessor.php
@@ -12,29 +12,26 @@
  * Class collects all functions for wiki text parsing / processing that are
  * relevant for SMW
  *
- * @since 1.9
+ * This class is contains all functions necessary for parsing wiki text before
+ * it is displayed or previewed while identifying SMW related annotations.
  *
- * @file
- * @ingroup SMW
- * @ingroup Parser
+ * @note Settings involve smwgNamespacesWithSemanticLinks, smwgLinksInValues,
+ * smwgInlineErrors
+ *
+ * @licence GNU GPL v2+
+ * @since 1.9
  *
  * @author Markus Krötzsch
  * @author Denny Vrandecic
  * @author mwjames
  */
+class ContentProcessor implements ContextAware {
 
-/**
- * This class is contains all functions necessary for parsing wiki text before
- * it is displayed or previewed while identifying SMW related
- * annotations.
- *
- * @ingroup SMW
- * @ingroup Parser
- */
-class ParserTextProcessor {
+       /** @var ContextResource */
+       protected $context = null;
 
        /** @var Settings */
-       protected $settings;
+       protected $settings = null;
 
        /** @var ParserData */
        protected $parserData;
@@ -50,29 +47,25 @@
        protected $isAnnotation = true;
 
        /**
-        * @par Example:
-        * @code
-        * $settings = Settings::newFromArray( array(
-        *  'smwgNamespacesWithSemanticLinks' => 
$GLOBALS['smwgNamespacesWithSemanticLinks'],
-        *  'smwgLinksInValues' => $GLOBALS['smwgLinksInValues'],
-        *  'smwgInlineErrors'  => $GLOBALS['smwgInlineErrors']
-        * ) );
-        *
-        * $parserData = new ParserData( $title, $parserOutput );
-        *
-        * new ParserTextProcessor( $parserData, $settings );
-        * @endcode
-        *
-        * @see SMWHooks::onInternalParseBeforeLinks
-        *
         * @since 1.9
         *
         * @param ParserData $parserData
-        * @param Settings $settings
+        * @param ContextResource $context
         */
-       public function __construct( ParserData $parserData, Settings $settings 
) {
+       public function __construct( ParserData $parserData, ContextResource 
$context ) {
                $this->parserData = $parserData;
-               $this->settings = $settings;
+               $this->context = $context;
+       }
+
+       /**
+        * @see ContextAware::withContext
+        *
+        * @since 1.9
+        *
+        * @return ContextResource
+        */
+       public function withContext() {
+               return $this->context;
        }
 
        /**
@@ -85,6 +78,7 @@
         */
        public function parse( &$text ) {
                $title = $this->parserData->getTitle();
+               $this->settings = $this->withContext()->getSettings();
 
                // Strip magic words from text body
                $this->stripMagicWords( $text );
diff --git a/includes/dic/SharedDependencyContainer.php 
b/includes/dic/SharedDependencyContainer.php
index e65317c..1666bb8 100644
--- a/includes/dic/SharedDependencyContainer.php
+++ b/includes/dic/SharedDependencyContainer.php
@@ -86,12 +86,19 @@
                        'UpdateObserver'        => $this->getUpdateObserver(),
                        'BasePropertyAnnotator' => 
$this->getBasePropertyAnnotator(),
 
+                       /**
+                        * ContentProcessor object definition
+                        *
+                        * @since  1.9
+                        *
+                        * @return ContentProcessor
+                        */
                        'ContentProcessor' => function ( DependencyBuilder 
$builder ) {
-                                       return new ParserTextProcessor(
-                                               $builder->getArgument( 
'ParserData' ),
-                                               $builder->newObject( 'Settings' 
)
-                                       );
-                               },
+                               return new ContentProcessor(
+                                       $builder->getArgument( 'ParserData' ),
+                                       $builder->newObject( 'BaseContext' )
+                               );
+                       },
 
                        'ContentParser' => function ( DependencyBuilder 
$builder ) {
                                        return new ContentParser( 
$builder->getArgument( 'Title' ) );
diff --git a/tests/phpunit/ParserTestCase.php b/tests/phpunit/ParserTestCase.php
index cf24800..c725647 100644
--- a/tests/phpunit/ParserTestCase.php
+++ b/tests/phpunit/ParserTestCase.php
@@ -3,9 +3,10 @@
 namespace SMW\Test;
 
 use SMW\ParserParameterFormatter;
-use SMW\ParserTextProcessor;
+use SMW\ContentProcessor;
 use SMW\ParserData;
 use SMW\Settings;
+use SMW\EmptyContext;
 
 use ParserOutput;
 use Title;
@@ -110,10 +111,13 @@
         * @return ParserTextProcessor
         */
        protected function getParserTextProcessor( Title $title, ParserOutput 
$parserOutput, Settings $settings ) {
-               return new ParserTextProcessor(
-                       $this->newParserData( $title, $parserOutput ),
-                       $settings
-               );
+
+               $context = new EmptyContext();
+               
$context->getDependencyBuilder()->getContainer()->registerObject( 'Settings', 
$settings );
+
+               $parserData = $this->newParserData( $title, $parserOutput );
+
+               return new ContentProcessor( $parserData, $context );
        }
 
        /**
diff --git 
a/tests/phpunit/includes/ParserTextProcessorTemplateTransclusionTest.php 
b/tests/phpunit/includes/ContentProcessorTemplateTransclusionTest.php
similarity index 76%
rename from 
tests/phpunit/includes/ParserTextProcessorTemplateTransclusionTest.php
rename to tests/phpunit/includes/ContentProcessorTemplateTransclusionTest.php
index 86fcac1..230aa6b 100644
--- a/tests/phpunit/includes/ParserTextProcessorTemplateTransclusionTest.php
+++ b/tests/phpunit/includes/ContentProcessorTemplateTransclusionTest.php
@@ -2,57 +2,45 @@
 
 namespace SMW\Test;
 
-use SMW\ParserTextProcessor;
+use SMW\ContentProcessor;
+use SMW\EmptyContext;
 
 use Title;
 use ParserOutput;
 
 /**
- * Tests for the ParserTextProcessor class
- *
- * @since 1.9
- *
- * @file
- * @ingroup SMW
- * @ingroup Test
- *
- * @licence GNU GPL v2+
- * @author mwjames
- */
-
-/**
- * @covers \SMW\ParserTextProcessor
- *
- * @ingroup Test
+ * @covers \SMW\ContentProcessor
  *
  * @group SMW
  * @group SMWExtension
+ *
+ * @licence GNU GPL v2+
+ * @since 1.9
+ *
+ * @author mwjames
  */
-class ParserTextProcessorTemplateTransclusionTest extends ParserTestCase {
+class ContentProcessorTemplateTransclusionTest extends ParserTestCase {
 
        /**
-        * Returns the name of the class to be tested
-        *
         * @return string|false
         */
        public function getClass() {
-               return '\SMW\ParserTextProcessor';
+               return '\SMW\ContentProcessor';
        }
 
        /**
-        * Helper method that returns a ParserTextProcessor object
+        * @since  1.9
         *
-        * @param $title
-        * @param $parserOutput
-        * @param $settings
-        *
-        * @return ParserTextProcessor
+        * @return ContentProcessor
         */
        private function newInstance( Title $title, ParserOutput $parserOutput, 
array $settings = array() ) {
-               return new ParserTextProcessor(
-                       $this->newParserData( $title, $parserOutput ),
-                       $this->newSettings( $settings )
-               );
+
+               $context = new EmptyContext();
+               
$context->getDependencyBuilder()->getContainer()->registerObject( 'Settings', 
$this->newSettings( $settings ) );
+
+               $parserData = $this->newParserData( $title, $parserOutput );
+
+               return new ContentProcessor( $parserData, $context );
        }
 
        /**
@@ -61,6 +49,8 @@
         * process in order to access a Template
         *
         * @note Part of the routine has been taken from MW's ExtraParserTest
+        *
+        * @since 1.9
         *
         * @param $title
         * @param $text
@@ -89,16 +79,9 @@
        }
 
        /**
-        * @test ParserTextProcessor::parse
         * @dataProvider templateDataProvider
         *
         * @since 1.9
-        *
-        * @param $namespace
-        * @param array $settings
-        * @param $text
-        * @param $tmplValue
-        * @param array $expected
         */
        public function testPreprocessTemplateAndParse( $namespace, array 
$settings, $text, $tmplValue, array $expected ) {
 
diff --git a/tests/phpunit/includes/ParserTextProcessorTest.php 
b/tests/phpunit/includes/ContentProcessorTest.php
similarity index 90%
rename from tests/phpunit/includes/ParserTextProcessorTest.php
rename to tests/phpunit/includes/ContentProcessorTest.php
index ef4a9fa..10b128a 100644
--- a/tests/phpunit/includes/ParserTextProcessorTest.php
+++ b/tests/phpunit/includes/ContentProcessorTest.php
@@ -2,68 +2,52 @@
 
 namespace SMW\Test;
 
-use SMW\ParserTextProcessor;
+use SMW\ContentProcessor;
+use SMW\EmptyContext;
 
 use Title;
 use ParserOutput;
 use ReflectionClass;
 
 /**
- * Tests for the ParserTextProcessor class
- *
- * @since 1.9
- *
- * @file
- * @ingroup SMW
- * @ingroup Test
- *
- * @licence GNU GPL v2+
- * @author mwjames
- */
-
-/**
- * Tests for the ParserTextProcessor class
- * @covers \SMW\ParserTextProcessor
- *
- * @ingroup Test
+ * @covers \SMW\ContentProcessor
  *
  * @group SMW
  * @group SMWExtension
+ *
+ * @licence GNU GPL v2+
+ * @since 1.9
+ *
+ * @author mwjames
  */
-class ParserTextProcessorTest extends ParserTestCase {
+class ContentProcessorTest extends ParserTestCase {
 
        /**
-        * Returns the name of the class to be tested
-        *
         * @return string|false
         */
        public function getClass() {
-               return '\SMW\ParserTextProcessor';
+               return '\SMW\ContentProcessor';
        }
 
        /**
-        * Helper method that returns a ParserTextProcessor object
+        * @since  1.9
         *
-        * @param $title
-        * @param $parserOutput
-        * @param $settings
-        *
-        * @return ParserTextProcessor
+        * @return ContentProcessor
         */
        private function newInstance( Title $title, ParserOutput $parserOutput, 
array $settings = array() ) {
-               return new ParserTextProcessor(
-                       $this->newParserData( $title, $parserOutput ),
-                       $this->newSettings( $settings )
-               );
+
+               $context = new EmptyContext();
+               
$context->getDependencyBuilder()->getContainer()->registerObject( 'Settings', 
$this->newSettings( $settings ) );
+
+               $parserData = $this->newParserData( $title, $parserOutput );
+
+               return new ContentProcessor( $parserData, $context );
        }
 
        /**
-        * @test ParserTextProcessor::__construct
         * @dataProvider textDataProvider
         *
         * @since 1.9
-        *
-        * @param $namespace
         */
        public function testConstructor( $namespace ) {
                $instance = $this->newInstance( $this->newTitle( $namespace ), 
$this->newParserOutput() );
@@ -71,14 +55,9 @@
        }
 
        /**
-        * @test ParserTextProcessor::stripMagicWords
         * @dataProvider magicWordDataProvider
         *
         * @since 1.9
-        *
-        * @param $namespace
-        * @param $text
-        * @param array $expected
         */
        public function testStripMagicWords( $namespace, $text, array $expected 
) {
 
@@ -108,15 +87,9 @@
        }
 
        /**
-        * @test ParserTextProcessor::parse
         * @dataProvider textDataProvider
         *
         * @since 1.9
-        *
-        * @param $namespace
-        * @param array $settings
-        * @param $text
-        * @param array $expected
         */
        public function testParse( $namespace, array $settings, $text, array 
$expected ) {
 
@@ -139,8 +112,6 @@
        }
 
        /**
-        * @test ParserTextProcessor::parse
-        *
         * @since 1.9
         */
        public function testRedirect() {
@@ -160,7 +131,10 @@
 
                $parserData = $this->newParserData( $title, $parserOutput );
 
-               $instance = new ParserTextProcessor( $parserData, $settings );
+               $context = new EmptyContext();
+               
$context->getDependencyBuilder()->getContainer()->registerObject( 'Settings', 
$settings );
+
+               $instance = new ContentProcessor( $parserData, $context );
                $instance->parse( $text );
 
                // Build expected results from a successful setRedirect 
execution
@@ -174,8 +148,6 @@
        }
 
        /**
-        * @test ParserTextProcessor::process
-        *
         * @since 1.9
         */
        public function testProcess() {
@@ -369,8 +341,6 @@
        }
 
        /**
-        * Provides magic words sample text
-        *
         * @return array
         */
        public function magicWordDataProvider() {
diff --git a/tests/phpunit/includes/dic/SharedDependencyContainerTest.php 
b/tests/phpunit/includes/dic/SharedDependencyContainerTest.php
index 5a40a06..4d3b9dc 100644
--- a/tests/phpunit/includes/dic/SharedDependencyContainerTest.php
+++ b/tests/phpunit/includes/dic/SharedDependencyContainerTest.php
@@ -132,7 +132,7 @@
                        )
                );
 
-               $provider[] = array( 'ContentProcessor', array( 
'\SMW\ParserTextProcessor' => array(
+               $provider[] = array( 'ContentProcessor', array( 
'\SMW\ContentProcessor' => array(
                                'ParserData'  => 
$this->newMockBuilder()->newObject( 'ParserData' )
                                )
                        )

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4a24910961c5a82b8eb5e1f1ffb41715f2f958a6
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