MediaWiki  master
Hooks.php
Go to the documentation of this file.
1 <?php
2 
29 
38 class Hooks {
39 
50  public static function register( $name, $handler ) {
51  wfDeprecated( __METHOD__, '1.35' );
52  $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
53  $hookContainer->register( $name, $handler );
54  }
55 
67  public static function clear( $name ) {
68  wfDeprecated( __METHOD__, '1.35' );
69  if ( !defined( 'MW_PHPUNIT_TEST' ) && !defined( 'MW_PARSER_TEST' ) ) {
70  throw new BadMethodCallException( 'Cannot reset hooks in operation.' );
71  }
72  $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
73  $hookContainer->clear( $name );
74  }
75 
85  public static function isRegistered( $name ) {
86  wfDeprecated( __METHOD__, '1.35' );
87  $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
88  return $hookContainer->isRegistered( $name );
89  }
90 
100  public static function getHandlers( $name ) {
101  wfDeprecated( __METHOD__, '1.35' );
102  $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
103  $handlers = $hookContainer->getLegacyHandlers( $name );
104  $funcName = 'on' . strtr( ucfirst( $name ), ':-', '__' );
105  foreach ( $hookContainer->getHandlers( $name ) as $obj ) {
106  $handlers[] = [ $obj, $funcName ];
107  }
108  return $handlers;
109  }
110 
133  public static function run( $event, array $args = [], $deprecatedVersion = null ) {
134  wfDeprecated( __METHOD__, '1.35' );
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  wfDeprecated( __METHOD__, '1.35' );
153  $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
154  $options = $deprecatedVersion ? [ 'deprecatedVersion' => $deprecatedVersion ] : [];
155  $options[ 'abortable' ] = false;
156  return $hookContainer->run( $event, $args, $options );
157  }
158 
175  public static function runner() {
176  wfDeprecated( __METHOD__, '1.41' );
177  return new HookRunner( MediaWikiServices::getInstance()->getHookContainer() );
178  }
179 }
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Hooks class.
Definition: Hooks.php:38
static clear( $name)
Clears hooks registered via Hooks::register().
Definition: Hooks.php:67
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:175
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:133
static getHandlers( $name)
Returns an array of all the event functions attached to a hook This combines functions registered via...
Definition: Hooks.php:100
static isRegistered( $name)
Returns true if a hook has a function registered to it.
Definition: Hooks.php:85
static runWithoutAbort( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:151
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Definition: HookRunner.php:565
Service locator for MediaWiki core services.