Manual:Hooks/UnknownAction

From MediaWiki.org
Jump to: navigation, search
UnknownAction
Available from version 1.4.0
Used to add new query-string actions
Define function:
public static function onUnknownAction( $action, Article $article ) { ... }
Attach hook:
$wgHooks['UnknownAction'][] = 'MyExtensionHooks::onUnknownAction';
Called from: File(s): Wiki.php

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

Details[edit | edit source]

Actions for a page are passed to MediaWiki via the action parameter in the URL. For example, to edit the page 'Foo' the action edit would be appended to the main article URL, giving http://www.mywiki.org/wiki/index.php?title=Foo&action=edit.

This hook allows you to add custom actions to MediaWiki. If an action is requested that the software doesn't handle natively, this hook will be called. It is deprecated since MediaWiki version 1.19. Instead extensions add to $wgActions.

Returning false will allow processing to continue, but it will not output any content for the page. You will need to use $wgOut->addWikiText(...); and similar functions to create the appropriate page content for this action, and $wgOut->setPageTitle(...); to set the title for display at the top of the page.

Returning true will cause the standard 'no such action' message that you get when entering &action=nonexistant_action.

Arguments[edit | edit source]

  • $action: action name
  • $article: article "acted on" - this is a Page object, not the article name.

See also[edit | edit source]

  • $wgActions
  • MediaWikiPerformAction hook - used before default actions are called, used for overriding normal processes (ie: alternate action=edit, action=watch)