MediaWiki REL1_40
Hooks.php
Go to the documentation of this file.
1<?php
2
29
38class 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 $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
87 return $hookContainer->isRegistered( $name );
88 }
89
99 public static function getHandlers( $name ) {
100 $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
101 $handlers = $hookContainer->getLegacyHandlers( $name );
102 $funcName = 'on' . strtr( ucfirst( $name ), ':-', '__' );
103 foreach ( $hookContainer->getHandlers( $name ) as $obj ) {
104 $handlers[] = [ $obj, $funcName ];
105 }
106 return $handlers;
107 }
108
131 public static function run( $event, array $args = [], $deprecatedVersion = null ) {
132 $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
133 $options = $deprecatedVersion ? [ 'deprecatedVersion' => $deprecatedVersion ] : [];
134 return $hookContainer->run( $event, $args, $options );
135 }
136
148 public static function runWithoutAbort( $event, array $args = [], $deprecatedVersion = null ) {
149 $hookContainer = MediaWikiServices::getInstance()->getHookContainer();
150 $options = $deprecatedVersion ? [ 'deprecatedVersion' => $deprecatedVersion ] : [];
151 $options[ 'abortable' ] = false;
152 return $hookContainer->run( $event, $args, $options );
153 }
154
170 public static function runner() {
171 return new HookRunner( MediaWikiServices::getInstance()->getHookContainer() );
172 }
173}
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:170
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition Hooks.php:131
static getHandlers( $name)
Returns an array of all the event functions attached to a hook This combines functions registered via...
Definition Hooks.php:99
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:148
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Service locator for MediaWiki core services.