49 public static function register(
$name, $callback ) {
50 self::$handlers[
$name][] = $callback;
63 public static function clear( $name ) {
64 if ( !defined(
'MW_PHPUNIT_TEST' ) && !defined(
'MW_PARSER_TEST' ) ) {
65 throw new MWException(
'Cannot reset hooks in operation.' );
68 unset( self::$handlers[$name] );
82 return !empty(
$wgHooks[$name] ) || !empty( self::$handlers[$name] );
97 if ( !self::isRegistered( $name ) ) {
99 } elseif ( !isset( self::$handlers[$name] ) ) {
101 } elseif ( !isset(
$wgHooks[$name] ) ) {
102 return self::$handlers[
$name];
104 return array_merge( self::$handlers[$name],
$wgHooks[$name] );
120 if ( !is_array( $hook ) ) {
124 if ( !array_filter( $hook ) ) {
129 if ( is_array( $hook[0] ) ) {
133 $hook = array_merge( $hook[0], array_slice( $hook, 1 ) );
141 if ( $hook[0] instanceof Closure ) {
142 $fname =
"hook-$event-closure";
143 $callback = array_shift( $hook );
144 } elseif ( is_object( $hook[0] ) ) {
145 $object = array_shift( $hook );
146 $method = array_shift( $hook );
149 if ( $method ===
null ) {
150 $method =
"on$event";
153 $fname = get_class( $object ) .
'::' . $method;
154 $callback = [ $object, $method ];
155 } elseif ( is_string( $hook[0] ) ) {
156 $fname = $callback = array_shift( $hook );
158 throw new MWException(
'Unknown datatype in hooks for ' . $event .
"\n" );
163 if ( !is_callable( $callback ) ) {
164 throw new MWException(
'Invalid callback ' .
$fname .
' in hooks for ' . $event .
"\n" );
168 if ( $deprecatedVersion !==
null ) {
169 wfDeprecated(
"$event hook (used in $fname)", $deprecatedVersion );
173 $hook_args = array_merge( $hook,
$args );
174 return call_user_func_array( $callback, $hook_args );
200 public static function run( $event,
array $args = [], $deprecatedVersion =
null ) {
201 foreach ( self::getHandlers( $event ) as $hook ) {
202 $retval = self::callHook( $event, $hook,
$args, $deprecatedVersion );
211 } elseif (
$retval ===
false ) {
232 foreach ( self::getHandlers( $event ) as $hook ) {
236 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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))