49 public static function register(
$name, $callback ) {
50 if ( !isset( self::$handlers[$name] ) ) {
51 self::$handlers[
$name] = [];
54 self::$handlers[
$name][] = $callback;
66 public static function clear( $name ) {
67 if ( !defined(
'MW_PHPUNIT_TEST' ) && !defined(
'MW_PARSER_TEST' ) ) {
68 throw new MWException(
'Cannot reset hooks in operation.' );
71 unset( self::$handlers[$name] );
85 return !empty(
$wgHooks[$name] ) || !empty( self::$handlers[$name] );
100 if ( !self::isRegistered( $name ) ) {
102 } elseif ( !isset( self::$handlers[$name] ) ) {
104 } elseif ( !isset(
$wgHooks[$name] ) ) {
105 return self::$handlers[
$name];
107 return array_merge( self::$handlers[$name],
$wgHooks[$name] );
119 private static function callHook( $event, $hook, array
$args, $deprecatedVersion =
null,
123 if ( !is_array( $hook ) ) {
127 if ( !array_filter( $hook ) ) {
132 if ( is_array( $hook[0] ) ) {
136 $hook = array_merge( $hook[0], array_slice( $hook, 1 ) );
144 if ( $hook[0] instanceof Closure ) {
145 $fname =
"hook-$event-closure";
146 $callback = array_shift( $hook );
147 } elseif ( is_object( $hook[0] ) ) {
148 $object = array_shift( $hook );
149 $method = array_shift( $hook );
152 if ( $method ===
null ) {
153 $method =
"on$event";
156 $fname = get_class( $object ) .
'::' . $method;
157 $callback = [ $object, $method ];
158 } elseif ( is_string( $hook[0] ) ) {
159 $fname = $callback = array_shift( $hook );
161 throw new MWException(
'Unknown datatype in hooks for ' . $event .
"\n" );
166 if ( !is_callable( $callback ) ) {
167 throw new MWException(
'Invalid callback ' .
$fname .
' in hooks for ' . $event .
"\n" );
171 if ( $deprecatedVersion !==
null ) {
172 wfDeprecated(
"$event hook (used in $fname)", $deprecatedVersion );
176 $hook_args = array_merge( $hook,
$args );
177 return call_user_func_array( $callback, $hook_args );
203 public static function run( $event, array
$args = [], $deprecatedVersion =
null ) {
204 foreach ( self::getHandlers( $event ) as $hook ) {
205 $retval = self::callHook( $event, $hook,
$args, $deprecatedVersion );
214 } elseif (
$retval ===
false ) {
235 foreach ( self::getHandlers( $event ) as $hook ) {
239 throw new UnexpectedValueException(
"Invalid return from $fname for unabortable $event." );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Exception class which takes an HTML error message, and does not produce a backtrace.
static $handlers
Array of events mapped to an array of callbacks to be run when that event is triggered.
static clear( $name)
Clears hooks registered via Hooks::register().
static callHook( $event, $hook, array $args, $deprecatedVersion=null, &$fname=null)
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
static getHandlers( $name)
Returns an array of all the event functions attached to a hook This combines functions registered via...
static isRegistered( $name)
Returns true if a hook has a function registered to it.
static runWithoutAbort( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
$wgHooks['ArticleShow'][]
Allows to change the fields on the form that will be generated $name