Manual:Hooks/SpecialPage_initList
SpecialPage_initList | |
---|---|
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate> permits filtering of the list of special pages enabled for the system | |
<translate> Define function:</translate> | public static function onSpecialPage_initList( array &$specialPages ) { ... }
|
<translate> Attach hook:</translate> | <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
"Hooks": {
"SpecialPage_initList": "MediaWiki\\Extension\\MyExtension\\Hooks::onSpecialPageinitList"
}
}
|
<translate> Called from:</translate> | <translate> File(s):</translate> SpecialPageFactory.php <translate> Function(s):</translate> getPageList() |
<translate> Interface:</translate> | SpecialPage_initListHook.php |
<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:SpecialPage_initList extensions</tvar>.</translate>
Use cases
MediaWiki installations use the SpecialPage_initList
hook when they want to add to or remove pages from the special page list. They can use this to:
- dynamically add special pages from a database or other resource
- remove undesirable built-in special pages from the default list
- enable context dependent list of special pages - e.g. lists that depend on current server load, user's access method (local host, VPN, public internet)
- replace the default class associated with a special page with a custom subclass
- limit access to special pages based on user identity even in cases where the special page is not permissions aware
Background
A special page is a "virtual" MediaWiki article. Instead of being loaded from a file or database like a normal MediaWiki page, its content is generated on the fly using PHP code.
By default, MediaWiki builds the list of special pages from two sources: a list of built-in special pages hardcoded into the MediaWiki core and the configuration variable $wgSpecialPages. As a final step, MediaWiki passes the default list to all the functions attached to the SpecialPage_initList
.
Usage
Functions attached to this hook add and remove elements from $aSpecialPages
. This array has the same structure as $wgSpecialPages.
The hook function should return true
so as not to interfere with other functions that might be attached to this hook.