diff --git a/extension.json b/extension.json
index 8b42e19c..ddff3446 100644
--- a/extension.json
+++ b/extension.json
@@ -24,7 +24,6 @@
"Hooks": {
"ParserFirstCallInit": "main",
"OutputPageParserOutput": "main",
- "MakeGlobalVariablesScript": "main",
"BeforePageDisplay": "main",
"ResourceLoaderGetConfigVars": "main",
"SkinAfterContent": "main"
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 40559c81..f2dbb66b 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -10,7 +10,6 @@ use MediaWiki\Hook\ParserFirstCallInitHook;
use MediaWiki\Hook\SkinAfterContentHook;
use MediaWiki\Html\Html;
use MediaWiki\Output\Hook\BeforePageDisplayHook;
-use MediaWiki\Output\Hook\MakeGlobalVariablesScriptHook;
use MediaWiki\Output\Hook\OutputPageParserOutputHook;
use MediaWiki\Output\OutputPage;
use MediaWiki\Parser\Parser;
@@ -22,7 +21,6 @@ use Skin;
class Hooks implements
ParserFirstCallInitHook,
OutputPageParserOutputHook,
- MakeGlobalVariablesScriptHook,
BeforePageDisplayHook,
ResourceLoaderGetConfigVarsHook,
SkinAfterContentHook
@@ -38,22 +36,6 @@ class Hooks implements
$this->disambiguatorLookup = $disambiguatorLookup;
}
- /**
- * Handler for the MakeGlobalVariablesScript
hook.
- *
- * Sets the value of the wgRelatedArticles
global variable
- * to the list of related articles in the cached parser output.
- *
- * @param array &$vars variables to be added into the output of OutputPage::headElement.
- * @param OutputPage $out OutputPage instance calling the hook
- */
- public function onMakeGlobalVariablesScript( &$vars, $out ): void {
- $editorCuratedPages = $out->getProperty( 'RelatedArticles' );
- if ( $editorCuratedPages ) {
- $vars['wgRelatedArticles'] = $editorCuratedPages;
- }
- }
-
/**
* Uses the Disambiguator extension to test whether the page is a disambiguation page.
*
@@ -191,17 +173,11 @@ class Hooks implements
*/
public static function onFuncRelated( Parser $parser, ...$args ) {
$parserOutput = $parser->getOutput();
- $relatedPages = $parserOutput->getExtensionData( 'RelatedArticles' );
- if ( !$relatedPages ) {
- $relatedPages = [];
- }
-
// Add all the related pages passed by the parser function
// {{#related:Test with read more|Foo|Bar}}
foreach ( $args as $relatedPage ) {
- $relatedPages[] = $relatedPage;
+ $parserOutput->appendJsConfigVar( 'wgRelatedArticles', $relatedPage );
}
- $parserOutput->setExtensionData( 'RelatedArticles', $relatedPages );
return '';
}
@@ -213,15 +189,14 @@ class Hooks implements
* The list of related pages will be retrieved using
* ParserOutput#getExtensionData
.
*
- * @param OutputPage $out the OutputPage object
+ * @param OutputPage $outputPage the OutputPage object
* @param ParserOutput $parserOutput ParserOutput object
*/
- public function onOutputPageParserOutput( $out, $parserOutput ): void {
- $related = $parserOutput->getExtensionData( 'RelatedArticles' );
-
- if ( $related ) {
- $out->setProperty( 'RelatedArticles', $related );
- }
+ public function onOutputPageParserOutput( $outputPage, $parserOutput ): void {
+ // Backwards-compatibility with old cached content (T371421)
+ // This hook can be removed once this is no longer needed.
+ $related = $parserOutput->getExtensionData( 'RelatedArticles' ) ?? [];
+ $outputPage->addJsConfigVars( 'wgRelatedArticlesCompat', $related );
}
/**
diff --git a/resources/ext.relatedArticles.readMore/index.js b/resources/ext.relatedArticles.readMore/index.js
index 6a98ca18..ded49641 100644
--- a/resources/ext.relatedArticles.readMore/index.js
+++ b/resources/ext.relatedArticles.readMore/index.js
@@ -10,7 +10,10 @@ const relatedPages = new RelatedPagesGateway(
}
} ),
mw.config.get( 'wgPageName' ),
- mw.config.get( 'wgRelatedArticles' ),
+ Object.keys( mw.config.get( 'wgRelatedArticles' ) || Object.create( null ) )
+ // Backward compatibility with old parser cache contents
+ // This .concat can be removed once no longer needed (T371421)
+ .concat( mw.config.get( 'wgRelatedArticlesCompat' ) ),
data.useCirrusSearch,
data.onlyUseCirrusSearch,
data.descriptionSource