[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Use ParserOutputPostCacheTransform hook to avoid splitting c...
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/393279 ) Change subject: Use ParserOutputPostCacheTransform hook to avoid splitting cache on 'editsection' .. Use ParserOutputPostCacheTransform hook to avoid splitting cache on 'editsection' Core change Ied5fe1a6 introduces this hook, as well as the concept of stateless post-cache transformations that would break the former logic here. Bug: T168543 Change-Id: I140ff32373430b61b92226689ef9b58cca317450 Depends-On: Ied5fe1a6159c2d4fa48170042b44d735ce7b6f9b --- M repo/Wikibase.hooks.php M repo/Wikibase.php M repo/includes/Content/EntityContent.php M repo/includes/Diff/EntityContentDiffView.php M repo/tests/phpunit/includes/Content/EntityContentTest.php M view/src/ToolbarEditSectionGenerator.php M view/tests/phpunit/ToolbarEditSectionGeneratorTest.php 7 files changed, 25 insertions(+), 13 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified Thiemo Mättig (WMDE): Looks good to me, but someone else must approve diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php index dbe5cab..8fb1aad 100644 --- a/repo/Wikibase.hooks.php +++ b/repo/Wikibase.hooks.php @@ -1004,6 +1004,23 @@ } /** +* Post-cache transformation for Wikibase section-edit markers +* +* @param ParserOutput $out +* @param string &$text Text being transformed +* @param array &$options Transformation options +*/ + public static function onParserOutputPostCacheTransform( + ParserOutput $out, &$text, array &$options + ) { + if ( $options['enableSectionEditLinks'] ) { + $text = str_replace( [ '', '' ], '', $text ); + } else { + $text = preg_replace( '#.*?#s', '', $text ); + } + } + + /** * Add Wikibase-specific ElasticSearch analyzer configurations. * @param array &$config * @param AnalysisConfigBuilder $builder diff --git a/repo/Wikibase.php b/repo/Wikibase.php index a4969d5..d87bb096 100644 --- a/repo/Wikibase.php +++ b/repo/Wikibase.php @@ -1010,6 +1010,7 @@ $wgHooks['ResourceLoaderRegisterModules'][] = 'Wikibase\RepoHooks::onResourceLoaderRegisterModules'; $wgHooks['BeforeDisplayNoArticleText'][] = 'Wikibase\ViewEntityAction::onBeforeDisplayNoArticleText'; $wgHooks['InfoAction'][] = '\Wikibase\RepoHooks::onInfoAction'; + $wgHooks['ParserOutputPostCacheTransform'][] = '\Wikibase\RepoHooks::onParserOutputPostCacheTransform'; $wgHooks['BeforePageDisplayMobile'][] = '\Wikibase\RepoHooks::onBeforePageDisplayMobile'; $wgHooks['CirrusSearchAnalysisConfig'][] = '\Wikibase\RepoHooks::onCirrusSearchAnalysisConfig'; $wgHooks['CirrusSearchScoreBuilder'][] = '\Wikibase\RepoHooks::onCirrusSearchScoreBuilder'; diff --git a/repo/includes/Content/EntityContent.php b/repo/includes/Content/EntityContent.php index 230a062..da186ac 100644 --- a/repo/includes/Content/EntityContent.php +++ b/repo/includes/Content/EntityContent.php @@ -258,19 +258,12 @@ $outputGenerator = $entityParserOutputGeneratorFactory->getEntityParserOutputGenerator( $options->getUserLang(), - $options->getEditSection() + true ); $entityRevision = $this->getEntityRevision( $revisionId ); $output = $outputGenerator->getParserOutput( $entityRevision->getEntity(), $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 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. diff --git a/repo/includes/Diff/EntityContentDiffView.php b/repo/includes/Diff/EntityContentDiffView.php index 2e5a774..d7852ac 100644 --- a/repo/includes/Diff/EntityContentDiffView.php +++ b/repo/includes/Diff/EntityContentDiffView.php @@ -149,7 +149,6 @@ protected function getParserOutput( WikiPage $page, Revision $rev ) { $parserOptions = $page->makeParserOptions( $this->getContext() ); - $parserOptions->setEditSection( false ); // Do not poison parser cache with diff-specific stuff $parserOptions->addExtraKey( 'diff=1' ); diff --git
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Use ParserOutputPostCacheTransform hook to avoid splitting c...
Anomie has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/393279 ) Change subject: Use ParserOutputPostCacheTransform hook to avoid splitting cache on 'editsection' .. Use ParserOutputPostCacheTransform hook to avoid splitting cache on 'editsection' Core change I78b62ec3 introduces this hook, as well as the concept of stateless post-cache transformations that would break the former logic here. Bug: T168543 Change-Id: I140ff32373430b61b92226689ef9b58cca317450 Depends-On: I78b62ec33fcb8273acb9b3b4e9012215442be94c --- M repo/Wikibase.hooks.php M repo/Wikibase.php M repo/includes/Content/EntityContent.php M repo/includes/Diff/EntityContentDiffView.php M view/src/ToolbarEditSectionGenerator.php 5 files changed, 22 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/79/393279/1 diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php index 0d6eb3d..2d38267 100644 --- a/repo/Wikibase.hooks.php +++ b/repo/Wikibase.hooks.php @@ -1002,6 +1002,23 @@ } /** +* Post-cache transformation for Wikibase section-edit markers +* +* @param ParserOutput $out +* @param string &$text Text being transformed +* @param array &$options Transformation options +*/ + public static function onParserOutputPostCacheTransform( + ParserOutput $out, &$text, array &$options + ) { + if ( $options['enableSectionEditLinks'] ) { + $text = str_replace( [ '', '' ], '', $text ); + } else { + $text = preg_replace( '#.*?#s' ], '', $text ); + } + } + + /** * Adds Wikibase-specific ElasticSearch analyzer configurations. * * @param array &$config diff --git a/repo/Wikibase.php b/repo/Wikibase.php index a4969d5..d87bb096 100644 --- a/repo/Wikibase.php +++ b/repo/Wikibase.php @@ -1010,6 +1010,7 @@ $wgHooks['ResourceLoaderRegisterModules'][] = 'Wikibase\RepoHooks::onResourceLoaderRegisterModules'; $wgHooks['BeforeDisplayNoArticleText'][] = 'Wikibase\ViewEntityAction::onBeforeDisplayNoArticleText'; $wgHooks['InfoAction'][] = '\Wikibase\RepoHooks::onInfoAction'; + $wgHooks['ParserOutputPostCacheTransform'][] = '\Wikibase\RepoHooks::onParserOutputPostCacheTransform'; $wgHooks['BeforePageDisplayMobile'][] = '\Wikibase\RepoHooks::onBeforePageDisplayMobile'; $wgHooks['CirrusSearchAnalysisConfig'][] = '\Wikibase\RepoHooks::onCirrusSearchAnalysisConfig'; $wgHooks['CirrusSearchScoreBuilder'][] = '\Wikibase\RepoHooks::onCirrusSearchScoreBuilder'; diff --git a/repo/includes/Content/EntityContent.php b/repo/includes/Content/EntityContent.php index 230a062..da186ac 100644 --- a/repo/includes/Content/EntityContent.php +++ b/repo/includes/Content/EntityContent.php @@ -258,19 +258,12 @@ $outputGenerator = $entityParserOutputGeneratorFactory->getEntityParserOutputGenerator( $options->getUserLang(), - $options->getEditSection() + true ); $entityRevision = $this->getEntityRevision( $revisionId ); $output = $outputGenerator->getParserOutput( $entityRevision->getEntity(), $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 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. diff --git a/repo/includes/Diff/EntityContentDiffView.php b/repo/includes/Diff/EntityContentDiffView.php index 2e5a774..d7852ac 100644 --- a/repo/includes/Diff/EntityContentDiffView.php +++ b/repo/includes/Diff/EntityContentDiffView.php @@ -149,7 +149,6 @@ protected function getParserOutput( WikiPage $page, Revision $rev ) { $parserOptions = $page->makeParserOptions( $this->getContext() ); - $parserOptions->setEditSection( false ); // Do not poison parser cache with diff-specific stuff $parserOptions->addExtraKey( 'diff=1' ); diff --git a/view/src/ToolbarEditSectionGenerator.php b/view/src/ToolbarEditSectionGenerator.php index fef283e..8df0026 100644 --- a/view/src/ToolbarEditSectionGenerator.php +++ b/view/src/ToolbarEditSectionGenerator.php @@ -89,7 +89,9 @@ } private