Overview
Citizen provides hook handlers to integrate with MediaWiki’s hook system. Hook classes are located inincludes/Hooks/ and handle both skin-specific and ResourceLoader-related functionality.
Namespace: MediaWiki\Skins\Citizen\Hooks
SkinHooks
Handles skin-related hooks for modifying page display, navigation, and UI elements. Location:includes/Hooks/SkinHooks.php
Implements:
BeforePageDisplayHookOutputPageAfterGetHeadLinksArrayHookSidebarBeforeOutputHookSkinBuildSidebarHookSkinPageReadyConfigHook
onBeforePageDisplay
Adds inline theme switcher script to page head for Citizen skin.The OutputPage object
The current skin instance
- Only runs when
$skin->getSkinName()is'citizen' - Only adds script when
CitizenEnablePreferencesconfig istrue - Minifies and caches the inline script from
resources/skins.citizen.scripts/inline.js
onOutputPageAfterGetHeadLinksArray
Replaces the viewport meta tag with Citizen’s optimized version.Reference to array of HTML head tags
The OutputPage object
- Added:
viewport-fit=coverfor iOS notch support - Removed:
user-scalable=yes(default behavior) - Removed:
minimum-scale=0.25(outdated iOS workaround) - Removed:
maximum-scale=5.0(outdated iOS workaround)
onSidebarBeforeOutput
Modifies toolbox menu items before sidebar output.The current skin instance
Reference to sidebar data array
onSkinBuildSidebar cannot access the toolbox reliably.
onSkinBuildSidebar
Modifies sidebar navigation links with icons and adds site tools.The current skin instance
Reference to sidebar navigation array
- Adds Special:SpecialPages link (on MW < 1.44)
- Adds Upload link if uploads are enabled
- Maps icons to menu items:
n-specialpages→specialPagest-specialpages→specialPagest-upload→upload
- Generates icon HTML for mapped items
CitizenGlobalToolsPortlet to specify which portlet should contain site tools:
onSkinPageReadyConfig
Tells MediaWiki’s page ready module not to wire up search (Citizen handles it).ResourceLoader context
Reference to configuration array
$config['search'] = false to prevent MediaWiki’s default search initialization.
onSkinTemplateNavigation (static)
Modifies navigation links for various menus with icons and styling.The skin template instance
Reference to navigation links array
actions- Page action menu (delete, move, protect, purge, etc.)associated-pages- Namespace tabs (article, talk, user, etc.)TOOLBOX- Toolbox menu (related changes, print, etc.)notifications- Echo notifications (if installed)user-menu- User menuuser-interface-preferences- UI preference menuviews- View/edit menu
- Adds
citizen-ve-edit-mergedclass to both buttons - Changes source edit icon from
edittowikiText - Makes edit buttons progressive primary instead of quiet
ResourceLoaderHooks
Provides configuration data to ResourceLoader modules. Location:includes/Hooks/ResourceLoaderHooks.php
getCitizenResourceLoaderConfig (static)
Passes configuration toskins.citizen.scripts ResourceLoader module.
ResourceLoader context
Configuration object
Configuration array with these keys:
wgCitizenEnablePreferences: boolwgCitizenOverflowInheritedClasses: arraywgCitizenOverflowNowrapClasses: arraywgCitizenSearchModule: stringwgCitizenEnableCommandPalette: bool
getCitizenPreferencesResourceLoaderConfig (static)
Passes configuration toskins.citizen.preferences ResourceLoader module.
ResourceLoader context
Configuration object
Configuration with
wgCitizenThemeDefault keygetCitizenSearchResourceLoaderConfig (static)
Passes configuration toskins.citizen.search ResourceLoader module.
ResourceLoader context
Configuration object
Configuration array:
isAdvancedSearchExtensionEnabled: boolisMediaSearchExtensionEnabled: boolwgCitizenSearchGateway: stringwgCitizenSearchDescriptionSource: stringwgCitizenMaxSearchResults: intwgScriptPath: stringwgSearchSuggestCacheExpiry: int
getCitizenCommandPaletteResourceLoaderConfig (static)
Passes configuration toskins.citizen.commandPalette ResourceLoader module.
ResourceLoader context
Configuration object
Configuration with extension status and cache settings:
isMediaSearchExtensionEnabled: boolwgSearchSuggestCacheExpiry: int
getCitizenPreferencesOverrides (static)
Returns on-wiki preference overrides with resolved message texts.ResourceLoader context
Configuration object
Preference overrides with structure:
Registering Hooks
Hooks are registered inskin.json under the Hooks section:
Related
- SkinCitizen - Main skin class that uses these hooks
- Components - Components that hooks modify
- MediaWiki Hooks Documentation