Adrian Heine has uploaded a new change for review.

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

Change subject: Limit ParserOptions handling to EntityContent
......................................................................

Limit ParserOptions handling to EntityContent

This consolidates ParserOptions usage so that it's obvious why and on what the
parser cache is split.

Change-Id: I48d83d73b6fc46905ff7bedddd084370da8fdeb8
---
M repo/includes/Content/EntityContent.php
M repo/includes/ParserOutput/EntityParserOutputGenerator.php
M repo/includes/ParserOutput/EntityParserOutputGeneratorFactory.php
M repo/tests/phpunit/includes/Content/EntityContentTest.php
M 
repo/tests/phpunit/includes/ParserOutput/EntityParserOutputGeneratorFactoryTest.php
M repo/tests/phpunit/includes/ParserOutput/EntityParserOutputGeneratorTest.php
6 files changed, 47 insertions(+), 71 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/00/275800/1

diff --git a/repo/includes/Content/EntityContent.php 
b/repo/includes/Content/EntityContent.php
index c29fd47..1b306a2 100644
--- a/repo/includes/Content/EntityContent.php
+++ b/repo/includes/Content/EntityContent.php
@@ -287,12 +287,24 @@
                $entityParserOutputGeneratorFactory = 
WikibaseRepo::getDefaultInstance()->getEntityParserOutputGeneratorFactory();
 
                $outputGenerator = 
$entityParserOutputGeneratorFactory->getEntityParserOutputGenerator(
-                       $options
+                       $options->getUserLang(),
+                       $options->getEditSection()
                );
 
                $entityRevision = $this->getEntityRevision( $revisionId );
 
-               $output = $outputGenerator->getParserOutput( $entityRevision, 
$options, $generateHtml );
+               $output = $outputGenerator->getParserOutput( $entityRevision, 
$generateHtml );
+
+               // Force parser cache split by whether edit links are show.
+               // MediaWiki core has the ability to split on editsection, but 
does not trigger it
+               // automatically when $parserOptions->getEditSection() is 
called. Presumably this
+               // is because core uses <mw:editsection> tags that are 
substituted by ParserOutput::getText
+               // using the info from ParserOutput::getEditSectionTokens.
+               $output->recordOption( 'editsection' );
+
+               // Since the output depends on the user language, we must make 
sure
+               // ParserCache::getKey() includes it in the cache key.
+               $output->recordOption( 'userlang' );
 
                $this->applyEntityPageProperties( $output );
 
diff --git a/repo/includes/ParserOutput/EntityParserOutputGenerator.php 
b/repo/includes/ParserOutput/EntityParserOutputGenerator.php
index 2e7ab29..7230450 100644
--- a/repo/includes/ParserOutput/EntityParserOutputGenerator.php
+++ b/repo/includes/ParserOutput/EntityParserOutputGenerator.php
@@ -82,6 +82,11 @@
        private $languageCode;
 
        /**
+        * @var bool
+        */
+       private $editable;
+
+       /**
         * @param DispatchingEntityViewFactory $entityViewFactory
         * @param ParserOutputJsConfigBuilder $configBuilder
         * @param EntityTitleLookup $entityTitleLookup
@@ -91,6 +96,7 @@
         * @param EntityDataFormatProvider $entityDataFormatProvider
         * @param ParserOutputDataUpdater[] $dataUpdaters
         * @param string $languageCode
+        * @param bool $editable
         */
        public function __construct(
                DispatchingEntityViewFactory $entityViewFactory,
@@ -101,7 +107,8 @@
                TemplateFactory $templateFactory,
                EntityDataFormatProvider $entityDataFormatProvider,
                array $dataUpdaters,
-               $languageCode
+               $languageCode,
+               $editable
        ) {
                $this->entityViewFactory = $entityViewFactory;
                $this->configBuilder = $configBuilder;
@@ -112,6 +119,7 @@
                $this->entityDataFormatProvider = $entityDataFormatProvider;
                $this->dataUpdaters = $dataUpdaters;
                $this->languageCode = $languageCode;
+               $this->editable = $editable;
        }
 
        /**
@@ -119,11 +127,7 @@
         *
         * @since 0.5
         *
-        * @note: the new ParserOutput will be registered as a watcher with 
$options by
-        *        calling $options->registerWatcher( array( $parserOutput, 
'recordOption' ) ).
-        *
         * @param EntityRevision $entityRevision
-        * @param ParserOptions $options
         * @param bool $generateHtml
         *
         * @throws InvalidArgumentException
@@ -131,20 +135,9 @@
         */
        public function getParserOutput(
                EntityRevision $entityRevision,
-               ParserOptions $options,
                $generateHtml = true
        ) {
                $parserOutput = new ParserOutput();
-               $options->registerWatcher( array( $parserOutput, 'recordOption' 
) );
-
-               // @note: SIDE EFFECT: the call to $options->getUserLang() 
effectively splits
-               // the parser cache. It gets reported to the ParserOutput which 
is registered
-               // as a watcher to $options above.
-               if ( $options->getUserLang() !== $this->languageCode ) {
-                       // The language requested by $parserOptions is 
different from what
-                       // this generator was configured for. This indicates an 
inconsistency.
-                       throw new InvalidArgumentException( 'Unexpected user 
language in ParserOptions' );
-               }
 
                $entity = $entityRevision->getEntity();
 
@@ -160,8 +153,7 @@
                        $this->addHtmlToParserOutput(
                                $parserOutput,
                                $entityRevision,
-                               $this->getEntityInfo( $parserOutput ),
-                               $options->getEditSection()
+                               $this->getEntityInfo( $parserOutput )
                        );
                } else {
                        // If we don't have HTML, the ParserOutput in question
@@ -259,20 +251,18 @@
         * @param ParserOutput $parserOutput
         * @param EntityRevision $entityRevision
         * @param EntityInfo $entityInfo
-        * @param bool $editable
         */
        private function addHtmlToParserOutput(
                ParserOutput $parserOutput,
                EntityRevision $entityRevision,
-               EntityInfo $entityInfo,
-               $editable = true
+               EntityInfo $entityInfo
        ) {
                $labelDescriptionLookup = new 
LanguageFallbackLabelDescriptionLookup(
                        new EntityInfoTermLookup( $entityInfo ),
                        $this->languageFallbackChain
                );
 
-               $editSectionGenerator = $editable ? new 
ToolbarEditSectionGenerator(
+               $editSectionGenerator = $this->editable ? new 
ToolbarEditSectionGenerator(
                        new RepoSpecialPageLinker(),
                        $this->templateFactory
                ) : new EmptyEditSectionGenerator();
@@ -292,17 +282,6 @@
                $html = $entityView->getHtml( $entityRevision );
                $parserOutput->setText( $html );
                $parserOutput->setExtensionData( 'wikibase-view-chunks', 
$entityView->getPlaceholders() );
-
-               // Force parser cache split by whether edit links are show.
-               // MediaWiki core has the ability to split on editsection, but 
does not trigger it
-               // automatically when $parserOptions->getEditSection() is 
called. Presumably this
-               // is because core uses <mw:editsection> tags that are 
substituted by ParserOutput::getText
-               // using the info from ParserOutput::getEditSectionTokens.
-               $parserOutput->recordOption( 'editsection' );
-
-               // Since the output depends on the user language, we must make 
sure
-               // ParserCache::getKey() includes it in the cache key.
-               $parserOutput->recordOption( 'userlang' );
        }
 
        /**
diff --git a/repo/includes/ParserOutput/EntityParserOutputGeneratorFactory.php 
b/repo/includes/ParserOutput/EntityParserOutputGeneratorFactory.php
index 9679576..aedbabb 100644
--- a/repo/includes/ParserOutput/EntityParserOutputGeneratorFactory.php
+++ b/repo/includes/ParserOutput/EntityParserOutputGeneratorFactory.php
@@ -119,23 +119,25 @@
        /**
         * Creates an EntityParserOutputGenerator to create the ParserOutput 
for the entity
         *
-        * @param ParserOptions $options
+        * @param string $userLanguageCode
+        * @param bool $editable
         *
         * @return EntityParserOutputGenerator
         */
-       public function getEntityParserOutputGenerator( ParserOptions $options 
) {
-               $language = $options->getUserLangObj();
+       public function getEntityParserOutputGenerator( $userLanguageCode, 
$editable ) {
 
+               $userLanguage = Language::factory( $userLanguageCode );
                return new EntityParserOutputGenerator(
                        $this->entityViewFactory,
                        $this->newParserOutputJsConfigBuilder(),
                        $this->entityTitleLookup,
                        $this->entityInfoBuilderFactory,
-                       $this->getLanguageFallbackChain( $language ),
+                       $this->getLanguageFallbackChain( $userLanguage ),
                        $this->templateFactory,
                        $this->entityDataFormatProvider,
                        $this->getDataUpdaters(),
-                       $language->getCode()
+                       $userLanguageCode,
+                       $editable
                );
        }
 
diff --git a/repo/tests/phpunit/includes/Content/EntityContentTest.php 
b/repo/tests/phpunit/includes/Content/EntityContentTest.php
index 15b12e6..dbbd08d 100644
--- a/repo/tests/phpunit/includes/Content/EntityContentTest.php
+++ b/repo/tests/phpunit/includes/Content/EntityContentTest.php
@@ -154,6 +154,14 @@
                $title = Title::newFromText( 'Foo' );
                $parserOutput = $content->getParserOutput( $title );
 
+               $expectedUsedOptions = array( 'userlang', 'editsection' );
+               $actualOptions = $parserOutput->getUsedOptions();
+               $missingOptions = array_diff( $expectedUsedOptions, 
$actualOptions );
+               $this->assertEmpty(
+                       $missingOptions,
+                       'Missing cache-split flags: ' . join( '|', 
$missingOptions ) . '. Options: ' . join( '|', $actualOptions )
+               );
+
                $this->assertInstanceOf( '\ParserOutput', $parserOutput );
                $this->assertEquals( EntityContent::STATUS_EMPTY, 
$parserOutput->getProperty( 'wb-status' ) );
        }
diff --git 
a/repo/tests/phpunit/includes/ParserOutput/EntityParserOutputGeneratorFactoryTest.php
 
b/repo/tests/phpunit/includes/ParserOutput/EntityParserOutputGeneratorFactoryTest.php
index 217e7e3..f1a711a 100644
--- 
a/repo/tests/phpunit/includes/ParserOutput/EntityParserOutputGeneratorFactoryTest.php
+++ 
b/repo/tests/phpunit/includes/ParserOutput/EntityParserOutputGeneratorFactoryTest.php
@@ -24,19 +24,7 @@
                $testUser = new \TestUser( 'Wikibase User' );
 
                $instance = 
$parserOutputGeneratorFactory->getEntityParserOutputGenerator(
-                       new ParserOptions( $testUser->getUser(), 
Language::factory( 'en' ) )
-               );
-
-               $this->assertInstanceOf( 
'Wikibase\Repo\ParserOutput\EntityParserOutputGenerator', $instance );
-       }
-
-       public function 
testGetEntityParserOutputGenerator_noParserOptionLanguage() {
-               $parserOutputGeneratorFactory = 
$this->getEntityParserOutputGeneratorFactory();
-
-               $testUser = new \TestUser( 'Wikibase User' );
-
-               $instance = 
$parserOutputGeneratorFactory->getEntityParserOutputGenerator(
-                       new ParserOptions( $testUser->getUser() )
+                       'en', true
                );
 
                $this->assertInstanceOf( 
'Wikibase\Repo\ParserOutput\EntityParserOutputGenerator', $instance );
diff --git 
a/repo/tests/phpunit/includes/ParserOutput/EntityParserOutputGeneratorTest.php 
b/repo/tests/phpunit/includes/ParserOutput/EntityParserOutputGeneratorTest.php
index c130f7d..a31defb 100644
--- 
a/repo/tests/phpunit/includes/ParserOutput/EntityParserOutputGeneratorTest.php
+++ 
b/repo/tests/phpunit/includes/ParserOutput/EntityParserOutputGeneratorTest.php
@@ -3,9 +3,7 @@
 namespace Wikibase\Repo\Tests\ParserOutput;
 
 use DataValues\StringValue;
-use Language;
 use MediaWikiTestCase;
-use ParserOptions;
 use SpecialPage;
 use Title;
 use Wikibase\DataModel\Entity\BasicEntityIdParser;
@@ -44,7 +42,7 @@
                $timestamp = wfTimestamp( TS_MW );
                $revision = new EntityRevision( $item, 13044, $timestamp );
 
-               $parserOutput = $entityParserOutputGenerator->getParserOutput( 
$revision, $this->getParserOptions() );
+               $parserOutput = $entityParserOutputGenerator->getParserOutput( 
$revision );
 
                $this->assertSame( '<TITLE>', $parserOutput->getTitleText(), 
'title text' );
                $this->assertSame( '<HTML>', $parserOutput->getText(), 'html 
text' );
@@ -92,14 +90,6 @@
                        $parserOutput->getExtensionData( 'referenced-entities' )
                );
 
-               $expectedUsedOptions = array( 'userlang', 'editsection' );
-               $actualOptions = $parserOutput->getUsedOptions();
-               $missingOptions = array_diff( $expectedUsedOptions, 
$actualOptions );
-               $this->assertEmpty(
-                       $missingOptions,
-                       'Missing cache-split flags: ' . join( '|', 
$missingOptions ) . '. Options: ' . join( '|', $actualOptions )
-               );
-
                $jsonHref = SpecialPage::getTitleFor( 'EntityData', 
$item->getId()->getSerialization() . '.json' )->getCanonicalURL();
                $ntHref = SpecialPage::getTitleFor( 'EntityData', 
$item->getId()->getSerialization() . '.nt' )->getCanonicalURL();
 
@@ -128,7 +118,7 @@
                $timestamp = wfTimestamp( TS_MW );
                $revision = new EntityRevision( $item, 13044, $timestamp );
 
-               $parserOutput = $entityParserOutputGenerator->getParserOutput( 
$revision, $this->getParserOptions(), false );
+               $parserOutput = $entityParserOutputGenerator->getParserOutput( 
$revision, false );
 
                $this->assertSame( '', $parserOutput->getText() );
                // ParserOutput without HTML must not end up in the cache.
@@ -144,7 +134,7 @@
                $timestamp = wfTimestamp( TS_MW );
                $revision = new EntityRevision( $item, 13045, $timestamp );
 
-               $parserOutput = $entityParserOutputGenerator->getParserOutput( 
$revision, $this->getParserOptions() );
+               $parserOutput = $entityParserOutputGenerator->getParserOutput( 
$revision );
 
                $this->assertEquals(
                        'Q7799929',
@@ -181,7 +171,8 @@
                        TemplateFactory::getDefaultInstance(),
                        $entityDataFormatProvider,
                        $dataUpdaters,
-                       'en'
+                       'en',
+                       true
                );
        }
 
@@ -297,10 +288,6 @@
                $dataTypeLookup->setDataTypeForProperty( new PropertyId( 'P10' 
), 'commonsMedia' );
 
                return $dataTypeLookup;
-       }
-
-       private function getParserOptions() {
-               return new ParserOptions( null, Language::factory( 'en' ) );
        }
 
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I48d83d73b6fc46905ff7bedddd084370da8fdeb8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Adrian Heine <[email protected]>

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

Reply via email to