MediaWiki  master
Hooks.php
Go to the documentation of this file.
1 <?php
2 
29 
38 class 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' . str_replace( ':', '_', 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 }
Hooks\getHandlers
static getHandlers( $name)
Returns an array of all the event functions attached to a hook This combines functions registered via...
Definition: Hooks.php:102
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:154
Hooks\clear
static clear( $name)
Clears hooks registered via Hooks::register().
Definition: Hooks.php:70
wfDeprecatedMsg
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
Definition: GlobalFunctions.php:1058
MWException
MediaWiki exception.
Definition: MWException.php:29
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1026
$args
if( $line===false) $args
Definition: mcc.php:124
Hooks\runWithoutAbort
static runWithoutAbort( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:151
Hooks\runner
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:172
Hooks\isRegistered
static isRegistered( $name)
Returns true if a hook has a function registered to it.
Definition: Hooks.php:88
MediaWiki\HookContainer\HookRunner
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Definition: HookRunner.php:570
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:134
Hooks
Hooks class.
Definition: Hooks.php:38