ICT:Hooks – How Hooks Work in MediaWiki
ICT:Hooks – How Hooks Work in MediaWiki
This page explains how MediaWiki’s hook system works, where hook parameters such as $skin, $bar, and $links come from, and how administrators can look up the official documentation for each hook.
This page is intended for future stewards of the archive infrastructure.
1. What a Hook Is
A hook is a point inside MediaWiki’s execution flow where custom PHP code can run.
MediaWiki internally calls:
Hooks::run( 'HookName', [ $param1, $param2, ... ] );
Your code registers a function to be executed at that moment:
$wgHooks['HookName'][] = function ( $param1, $param2 ) {
# custom logic
return true;
};
Returning true tells MediaWiki to continue normal processing.
Returning false stops further handlers.
2. Where Do Parameters Like $skin, $bar, $links Come From
Each hook defines:
- how many parameters it passes
- what type each parameter is
- whether parameters are passed by reference
- what you are allowed to modify
This information is published in the official MediaWiki hook documentation.
For example:
SkinBuildSidebar
- Documentation: https://www.mediawiki.org/wiki/Manual:Hooks/SkinBuildSidebar
- Parameters:
*$skin— instance ofSkinor a subclass (e.g.,SkinVector) *&$bar— associative array representing the sidebar sections
SkinTemplateNavigation::Universal
- Documentation: https://www.mediawiki.org/wiki/Manual:Hooks/SkinTemplateNavigation::Universal
- Parameters:
*$skin— instance ofSkinTemplate*&$links— nested array containing the action tabs (views, actions, variants)
These pages define exactly what the objects contain and how they may be modified.
3. How to Read Hook Documentation
Every hook page on mediawiki.org includes:
- a description of when the hook fires
- a list of parameters
- the PHP types of each parameter
- examples of usage
- notes about return values
Example from the documentation:
/**
* @param Skin $skin
* @param array &$bar
*/
This tells you:
$skinis aSkinobject$baris an array passed by reference- modifying
$barchanges the sidebar
4. Why Hooks Are Used in LocalSettings.php
Hooks allow you to:
- hide or modify UI elements
- enforce role‑based behavior
- override default navigation
- add or remove actions
- customize rendering without modifying core files
They are the official, stable way to extend MediaWiki.
All hook code in LocalSettings.php is standard PHP.
5. Example: Understanding the Parameters
Example 1: SkinBuildSidebar
function ( $skin, &$bar ) { ... }
$skin→ gives access to:
*$skin->getUser()*$skin->getTitle()*$skin->getSkinName()
$bar→ the sidebar structure:
$bar = [
'navigation' => [
[ 'text' => 'Main Page', 'href' => '/wiki/Main_Page' ],
],
'tools' => [ ... ],
];
Example 2: SkinTemplateNavigation::Universal
function ( $skin, &$links ) { ... }
$linkscontains the action tabs:
$links = [
'views' => [
'edit' => [ 'text' => 'Edit', 'href' => ... ],
'history' => [ ... ],
],
'actions' => [
'delete' => [ ... ],
'move' => [ ... ],
],
];
6. How to Find Any Hook
All hooks are listed here:
Each hook page includes:
- purpose
- parameters
- examples
- version notes
This is the authoritative reference for understanding hook parameters.
7. Why This Matters for Successors
Understanding hooks ensures that future stewards can:
- safely modify UI behavior
- understand why certain elements are hidden
- maintain or extend the decluttered interface
- avoid modifying core files or skins
- keep the system stable and upgrade‑friendly
This page provides the conceptual foundation needed to understand the hook‑based customizations used in the archive infrastructure.
This page is part of the ICT documentation set for the archive infrastructure.