MediaWiki REL1_35
Hooks.php
Go to the documentation of this file.
1<?php
2
29
38class Hooks {
39
48 public static function register( $name, $callback ) {
49 if ( !defined( 'MW_SERVICE_BOOTSTRAP_COMPLETE' ) ) {
50 wfDeprecatedMsg( 'Registering handler for ' . $name .
51 ' before MediaWiki bootstrap complete was deprecated in MediaWiki 1.35',
52 '1.35' );
53 }
54 $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
55 $hookContainer->register( $name, $callback );
56 }
57
70 public static function clear( $name ) {
71 wfDeprecated( __METHOD__, '1.35' );
72 if ( !defined( 'MW_PHPUNIT_TEST' ) && !defined( 'MW_PARSER_TEST' ) ) {
73 throw new MWException( 'Cannot reset hooks in operation.' );
74 }
75 $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
76 $hookContainer->clear( $name );
77 }
78
88 public static function isRegistered( $name ) {
89 $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
90 return $hookContainer->isRegistered( $name );
91 }
92
102 public static function getHandlers( $name ) {
103 $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
104 $handlers = $hookContainer->getLegacyHandlers( $name );
105 $funcName = 'on' . strtr( ucfirst( $name ), ':-', '__' );
106 foreach ( $hookContainer->getHandlers( $name ) as $obj ) {
107 $handlers[] = [ $obj, $funcName ];
108 }
109 return $handlers;
110 }
111
134 public static function run( $event, array $args = [], $deprecatedVersion = null ) {
135 $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
136 $options = $deprecatedVersion ? [ 'deprecatedVersion' => $deprecatedVersion ] : [];
137 return $hookContainer->run( $event, $args, $options );
138 }
139
151 public static function runWithoutAbort( $event, array $args = [], $deprecatedVersion = null ) {
152 $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
153 $options = $deprecatedVersion ? [ 'deprecatedVersion' => $deprecatedVersion ] : [];
154 $options[ 'abortable' ] = false;
155 return $hookContainer->run( $event, $args, $options );
156 }
157
172 public static function runner() {
173 return new HookRunner( MediaWikiServices::getInstance()->getHookContainer() );
174 }
175}
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Hooks class.
Definition Hooks.php:38
static clear( $name)
Clears hooks registered via Hooks::register().
Definition Hooks.php:70
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition Hooks.php:172
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition Hooks.php:134
static getHandlers( $name)
Returns an array of all the event functions attached to a hook This combines functions registered via...
Definition Hooks.php:102
static isRegistered( $name)
Returns true if a hook has a function registered to it.
Definition Hooks.php:88
static runWithoutAbort( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition Hooks.php:151
MediaWiki exception.
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
MediaWikiServices is the service locator for the application scope of MediaWiki.
if( $line===false) $args
Definition mcc.php:124