Go to the documentation of this file.
49 public static function register(
$name, $callback ) {
50 if ( !isset( self::$handlers[
$name] ) ) {
51 self::$handlers[
$name] = [];
54 self::$handlers[
$name][] = $callback;
67 if ( !defined(
'MW_PHPUNIT_TEST' ) && !defined(
'MW_PARSER_TEST' ) ) {
68 throw new MWException(
'Cannot reset hooks in operation.' );
71 unset( self::$handlers[
$name] );
100 if ( !self::isRegistered(
$name ) ) {
102 } elseif ( !isset( self::$handlers[
$name] ) ) {
105 return self::$handlers[
$name];
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 ) {
214 } elseif (
$retval ===
false ) {
235 foreach ( self::getHandlers( $event )
as $hook ) {
239 throw new UnexpectedValueException(
"Invalid return from $fname for unabortable $event." );
static getHandlers( $name)
Returns an array of all the event functions attached to a hook This combines functions registered via...
static callHook( $event, $hook, array $args, $deprecatedVersion=null, &$fname=null)
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Allows to change the fields on the form that will be generated $name
static clear( $name)
Clears hooks registered via Hooks::register().
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
when a variable name is used in a it is silently declared as a new masking the global
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 account incomplete not yet checked for validity & $retval
static isRegistered( $name)
Returns true if a hook has a function registered to it.
Exception class which takes an HTML error message, and does not produce a backtrace.
$wgHooks['ArticleShow'][]
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
the array() calling protocol came about after MediaWiki 1.4rc1.
static $handlers
Array of events mapped to an array of callbacks to be run when that event is triggered.