resourceloader: Move RL hooks to own namespace, use PSR-4

Follows-up f5aaf75ad1.

* Improve some docs for these hooks.
* Add type hints.
* Add them as a subgroup within the ResourceLoader docgroup
  for easy navigation.

Bug: T246855
Change-Id: I52f31e2b63dcf265b27e68ba8fd4f885d82088ac
This commit is contained in:
Timo Tijhof 2020-04-21 19:08:02 +01:00 committed by Krinkle
parent a24f8e9173
commit b7ac554304
9 changed files with 48 additions and 43 deletions

View file

@ -994,12 +994,6 @@ $wgAutoloadLocalClasses = [
'MediaWiki\\Hook\\RecentChangesPurgeRowsHook' => __DIR__ . '/includes/jobqueue/jobs/Hook/RecentChangesPurgeRowsHook.php',
'MediaWiki\\Hook\\RejectParserCacheValueHook' => __DIR__ . '/includes/parser/Hook/RejectParserCacheValueHook.php',
'MediaWiki\\Hook\\RequestContextCreateSkinHook' => __DIR__ . '/includes/context/Hook/RequestContextCreateSkinHook.php',
'MediaWiki\\Hook\\ResourceLoaderForeignApiModulesHook' => __DIR__ . '/includes/resourceloader/Hook/ResourceLoaderForeignApiModulesHook.php',
'MediaWiki\\Hook\\ResourceLoaderGetConfigVarsHook' => __DIR__ . '/includes/resourceloader/Hook/ResourceLoaderGetConfigVarsHook.php',
'MediaWiki\\Hook\\ResourceLoaderJqueryMsgModuleMagicWordsHook' => __DIR__ . '/includes/resourceloader/Hook/ResourceLoaderJqueryMsgModuleMagicWordsHook.php',
'MediaWiki\\Hook\\ResourceLoaderSiteModulePagesHook' => __DIR__ . '/includes/resourceloader/Hook/ResourceLoaderSiteModulePagesHook.php',
'MediaWiki\\Hook\\ResourceLoaderSiteStylesModulePagesHook' => __DIR__ . '/includes/resourceloader/Hook/ResourceLoaderSiteStylesModulePagesHook.php',
'MediaWiki\\Hook\\ResourceLoaderTestModulesHook' => __DIR__ . '/includes/resourceloader/Hook/ResourceLoaderTestModulesHook.php',
'MediaWiki\\Hook\\SendWatchlistEmailNotificationHook' => __DIR__ . '/includes/mail/Hook/SendWatchlistEmailNotificationHook.php',
'MediaWiki\\Hook\\ShortPagesQueryHook' => __DIR__ . '/includes/specials/Hook/ShortPagesQueryHook.php',
'MediaWiki\\Hook\\SidebarBeforeOutputHook' => __DIR__ . '/includes/skins/Hook/SidebarBeforeOutputHook.php',

View file

@ -150,6 +150,7 @@ class AutoLoader {
'MediaWiki\\Logger\Monolog\\' => __DIR__ . '/debug/logger/monolog/',
'MediaWiki\\Page\\' => __DIR__ . '/page/',
'MediaWiki\\Preferences\\' => __DIR__ . '/preferences/',
'MediaWiki\\ResourceLoader\\Hook\\' => __DIR__ . '/resourceloader/Hook/',
'MediaWiki\\Search\\' => __DIR__ . '/search/',
'MediaWiki\\Search\\SearchWidgets\\' => __DIR__ . '/search/searchwidgets/',
'MediaWiki\\Session\\' => __DIR__ . '/session/',

View file

@ -1,21 +1,21 @@
<?php
namespace MediaWiki\Hook;
namespace MediaWiki\ResourceLoader\Hook;
use ResourceLoaderContext;
/**
* @stable for implementation
* @ingroup Hooks
* @ingroup ResourceLoaderHooks
*/
interface ResourceLoaderForeignApiModulesHook {
/**
* Add dependencies to the `mediawiki.ForeignApi` module when you wish
* to override its behavior. See the JS docs for more information.
*
* This hook is called from ResourceLoaderForeignApiModule.
* Use this hook to add dependencies to mediawiki.ForeignApi module when you wish
* to override its behavior. See the module docs for more information.
*
* @since 1.35
*
* @param string[] &$dependencies List of modules that mediawiki.ForeignApi should
* depend on
* @param ResourceLoaderContext|null $context

View file

@ -1,28 +1,29 @@
<?php
namespace MediaWiki\Hook;
namespace MediaWiki\ResourceLoader\Hook;
use Config;
use Skin;
/**
* @stable for implementation
* @ingroup Hooks
* @ingroup ResourceLoaderHooks
*/
interface ResourceLoaderGetConfigVarsHook {
/**
* This hook is called at the end of
* ResourceLoaderStartUpModule::getConfigSettings(). Use this hook to export static
* configuration variables to JavaScript. Things that depend on the current page
* or request state must be added through MakeGlobalVariablesScript instead.
* Skin is made available for skin specific config.
* Export static site-wide `mw.config` variables to JavaScript.
*
* Variables that depend on the current page or request state must be added
* through MediaWiki\Hook\MakeGlobalVariablesScriptHook instead.
* The skin name is made available to send skin-specific config only when needed.
*
* This hook is called from ResourceLoaderStartUpModule.
*
* @since 1.35
*
* @param array &$vars [ variable name => value ]
* @param array &$vars `[ variable name => value ]`
* @param Skin $skin
* @param Config $config since 1.34
* @return bool|void True or no return value to continue or false to abort
*/
public function onResourceLoaderGetConfigVars( &$vars, $skin, $config );
public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config );
}

View file

@ -1,26 +1,27 @@
<?php
namespace MediaWiki\Hook;
namespace MediaWiki\ResourceLoader\Hook;
use ResourceLoaderContext;
/**
* @stable for implementation
* @ingroup Hooks
* @ingroup ResourceLoaderHooks
*/
interface ResourceLoaderJqueryMsgModuleMagicWordsHook {
/**
* This hook is called in ResourceLoaderJqueryMsgModule to allow
* adding magic words for jQueryMsg. The value should be a string,
* and they can depend only on the ResourceLoaderContext.
* Add magic words to the `mediawiki.jqueryMsg` module. The values should be a string,
* and they may only vary by what's in the ResourceLoaderContext.
*
* This hook is called from ResourceLoaderJqueryMsgModule.
*
* @since 1.35
*
* @param ResourceLoaderContext $context
* @param string[] &$magicWords Associative array mapping all-caps magic word to a string value
* @return bool|void True or no return value to continue or false to abort
*/
public function onResourceLoaderJqueryMsgModuleMagicWords( $context,
&$magicWords
public function onResourceLoaderJqueryMsgModuleMagicWords(
ResourceLoaderContext $context,
array &$magicWords
);
}

View file

@ -1,20 +1,21 @@
<?php
namespace MediaWiki\Hook;
namespace MediaWiki\ResourceLoader\Hook;
/**
* @stable for implementation
* @ingroup Hooks
* @ingroup ResourceLoaderHooks
*/
interface ResourceLoaderSiteModulePagesHook {
/**
* Use this hook to modify list of pages for a given skin.
* Change which wiki pages comprise the `site` module in given skin.
*
* This hook is called from ResourceLoaderSiteModule.
*
* @since 1.35
*
* @param string $skin Current skin key
* @param array &$pages Array of pages and their types
* @return bool|void True or no return value to continue or false to abort
*/
public function onResourceLoaderSiteModulePages( $skin, &$pages );
public function onResourceLoaderSiteModulePages( $skin, array &$pages );
}

View file

@ -1,20 +1,21 @@
<?php
namespace MediaWiki\Hook;
namespace MediaWiki\ResourceLoader\Hook;
/**
* @stable for implementation
* @ingroup Hooks
* @ingroup ResourceLoaderHooks
*/
interface ResourceLoaderSiteStylesModulePagesHook {
/**
* Use this hook to modify list of pages for a given skin.
* Change which wiki pages comprise the `site.styles` module in given skin.
*
* This hook is called from ResourceLoaderSiteStylesModule.
*
* @since 1.35
*
* @param string $skin Current skin key
* @param array &$pages Array of pages and their types
* @return bool|void True or no return value to continue or false to abort
*/
public function onResourceLoaderSiteStylesModulePages( $skin, &$pages );
public function onResourceLoaderSiteStylesModulePages( $skin, array &$pages );
}

View file

@ -1,12 +1,12 @@
<?php
namespace MediaWiki\Hook;
namespace MediaWiki\ResourceLoader\Hook;
use ResourceLoader;
/**
* @deprecated since 1.33
* @ingroup Hooks
* @ingroup ResourceLoaderHooks
*/
interface ResourceLoaderTestModulesHook {
/**
@ -25,8 +25,8 @@ interface ResourceLoaderTestModulesHook {
* 'script' => [ 'tests/qunit/foo.js' ],
* 'dependencies' => [ 'ext.Example.foo' ]
* ];
* @param ResourceLoader $ResourceLoader
* @param ResourceLoader $rl
* @return bool|void True or no return value to continue or false to abort
*/
public function onResourceLoaderTestModules( &$testModules, $ResourceLoader );
public function onResourceLoaderTestModules( array &$testModules, ResourceLoader $rl );
}

View file

@ -37,6 +37,12 @@ use Wikimedia\WrappedString;
* For higher level documentation, see <https://www.mediawiki.org/wiki/ResourceLoader/Architecture>.
*/
/**
* @defgroup ResourceLoaderHooks ResourceLoader Hooks
* @ingroup ResourceLoader
* @ingroup Hooks
*/
/**
* ResourceLoader is a loading system for JavaScript and CSS resources.
*