OutputPage: Mark MakeGlobalVariablesScriptHook as void and improve docs

No extension is meant to be able to prevent other extensions from
using this hook. Incidents of that have only been accidents.

Change-Id: I048e3ac4a6a6889fc55681b8d49d6fd433e8b3fc
This commit is contained in:
Timo Tijhof 2021-03-10 23:57:43 +00:00 committed by Ammarpad
parent 68d66c2c39
commit 7d41328cc2
2 changed files with 16 additions and 9 deletions

View file

@ -13,16 +13,22 @@ use OutputPage;
*/
interface MakeGlobalVariablesScriptHook {
/**
* This hook is called at end of OutputPage::getJSVars.
* Ideally, this hook should only be used to add variables that depend on
* the current page/request; static configuration should be added through
* ResourceLoaderGetConfigVars instead.
* Export user- or page-specific `mw.config` variables to JavaScript.
*
* When using this hook, be as selective as possible about when the data is set.
* Reduce the cost by setting values only for specific titles, namespaces, or user-rights.
*
* Data exported here is transmitted with the highest possible bandwidth priority (ahead of
* page content even). Any data that is not dependant on the current request, should go
* through MediaWiki\ResourceLoader\Hook\ResourceLoaderGetConfigVarsHook instead.
*
* This hook is called from OutputPage::getJSVars.
*
* @since 1.35
*
* @param array &$vars Variable (or multiple variables)
* @param OutputPage $out OutputPage which called the hook, can be used to get the real title
* @return bool|void True or no return value to continue or false to abort
* @return void This hook must not abort, it must return no value
*/
public function onMakeGlobalVariablesScript( &$vars, $out );
public function onMakeGlobalVariablesScript( &$vars, $out ) : void;
}

View file

@ -2539,10 +2539,11 @@ class HookRunner implements
);
}
public function onMakeGlobalVariablesScript( &$vars, $out ) {
return $this->container->run(
public function onMakeGlobalVariablesScript( &$vars, $out ) : void {
$this->container->run(
'MakeGlobalVariablesScript',
[ &$vars, $out ]
[ &$vars, $out ],
[ 'abortable' => false ]
);
}