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( [ '<wb:sectionedit>',
'</wb:sectionedit>' ], '', $text );
+ } else {
+ $text = preg_replace(
'#<wb:sectionedit>.*?</wb:sectionedit>#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 <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.
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 function getToolbarContainer( $content ) {
- return $this->templateFactory->render(
'wikibase-toolbar-container', $content );
+ return '<wb:sectionedit>'
+ . $this->templateFactory->render(
'wikibase-toolbar-container', $content )
+ . '</wb:sectionedit>';
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/393279
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I140ff32373430b61b92226689ef9b58cca317450
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits