Skip to content

Hooks

Citizen fires several mw.hook events that extensions, gadgets, and user scripts can subscribe to. This page is a quick reference — see the linked feature pages for full details and examples.

Hook reference

HookParametersDescription
citizen.commandPalette.register{ register }Register custom modes and commands in the command palette. register( entry ) accepts a mode or command object.
citizen.preferences.registerregisterRegister custom sections and preferences in the preferences panel. register( config ) accepts a config object with sections and preferences.
citizen.preferences.changedfeatureName, valueFired when a user changes a preference. Use this to react to changes in real time.

Usage pattern

All Citizen hooks follow the standard mw.hook pattern:

js
mw.hook( 'citizen.commandPalette.register' ).add( function ( data ) {
    data.register( myEntry );
} );
js
mw.hook( 'citizen.preferences.register' ).add( function ( register ) {
    register( myConfig );
} );
js
mw.hook( 'citizen.preferences.changed' ).add( function ( featureName, value ) {
    if ( featureName === 'my-feature' ) {
        // React to the change
    }
} );

Timing

mw.hook replays previously fired data to late subscribers. You don't need to worry about load order — your .add() callback will receive the data regardless of whether the firing module has loaded yet.

Deprecated hooks

HookReplacement
skins.citizen.commandPalette.registerCommandcitizen.commandPalette.register

The old hook still works but logs a deprecation warning. See the migration guide for details.