Manual:Hooks/ListDefinedTags

From MediaWiki.org
Jump to navigation Jump to search
ListDefinedTags
Available from version 1.15.0
Can be used by extensions to register change tags.
Define function:
public static function onListDefinedTags( &$tags ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"ListDefinedTags": "MyExtensionHooks::onListDefinedTags"
	}
}

For MediaWiki ≤1.25:

$wgHooks['ListDefinedTags'][] = 'MyExtensionHooks::onListDefinedTags';
Called from:File(s): ChangeTags.php

For more information about attaching hooks, see Manual:Hooks.
For examples of extensions using this hook, see Category:ListDefinedTags extensions.

Details[edit]

  • &$tags: The list of tags. Add your extension's tags to this array.

Notes[edit]

If you don't implement this hook, tags used by your extension will show up on Special:Tags as "no longer in use", and administrators will be able to delete them.

You should always implement the ChangeTagsListActive hook as well.

Example[edit]

This imaginary extension is registering two tags, which are both active. One is used to mark automated edits, while the other is used to mark edits requiring attention.

class MyExtensionHooks {
    public static function onRegisterTags( array &$tags ) {
        $tags[] = 'my-extension-automated-edit';
        $tags[] = 'my-extension-attention-required';
        return true;
    }
}

$wgHooks['ListDefinedTags'][] = 'MyExtensionHooks::onRegisterTags';
$wgHooks['ChangeTagsListActive'][] = 'MyExtensionHooks::onRegisterTags';

See also[edit]