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  wfDeprecated( 'Registering handler for ' . $name .
51  ' before MediaWiki bootstrap complete', '1.35' );
52  }
53  $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
54  $hookContainer->register( $name, $callback );
55  }
56 
69  public static function clear( $name ) {
70  wfDeprecated( __METHOD__, '1.35' );
71  if ( !defined( 'MW_PHPUNIT_TEST' ) && !defined( 'MW_PARSER_TEST' ) ) {
72  throw new MWException( 'Cannot reset hooks in operation.' );
73  }
74  $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
75  $hookContainer->clear( $name );
76  }
77 
87  public static function isRegistered( $name ) {
88  $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
89  return $hookContainer->isRegistered( $name );
90  }
91 
101  public static function getHandlers( $name ) {
102  $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
103  $handlers = $hookContainer->getLegacyHandlers( $name );
104  $funcName = 'on' . str_replace( ':', '_', 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  $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
135  $options = $deprecatedVersion ? [ 'deprecatedVersion' => $deprecatedVersion ] : [];
136  return $hookContainer->run( $event, $args, $options );
137  }
138 
150  public static function runWithoutAbort( $event, array $args = [], $deprecatedVersion = null ) {
151  $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
152  $options = $deprecatedVersion ? [ 'deprecatedVersion' => $deprecatedVersion ] : [];
153  $options[ 'abortable' ] = false;
154  return $hookContainer->run( $event, $args, $options );
155  }
156 
171  public static function runner() {
172  return new HookRunner( MediaWikiServices::getInstance()->getHookContainer() );
173  }
174 }
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:101
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:144
Hooks\clear
static clear( $name)
Clears hooks registered via Hooks::register().
Definition: Hooks.php:69
MWException
MediaWiki exception.
Definition: MWException.php:26
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1030
$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:150
Hooks\runner
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:171
Hooks\isRegistered
static isRegistered( $name)
Returns true if a hook has a function registered to it.
Definition: Hooks.php:87
MediaWiki\HookContainer\HookRunner
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Definition: HookRunner.php:23
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:133
Hooks
Hooks class.
Definition: Hooks.php:38