<?php
/**
- * Hooks.php -- a tool for running hook functions
+ * A tool for running hook functions.
+ *
* Copyright 2004, 2005 Evan Prodromou <evan@wikitravel.org>.
*
* This program is free software; you can redistribute it and/or modify
/**
+ * Call hook functions defined in $wgHooks
+ *
* Because programmers assign to $wgHooks, we need to be very
* careful about its contents. So, there's a lot more error-checking
* in here than would normally be necessary.
+ *
+ * @param $event String: event name
+ * @param $args Array: parameters passed to hook functions
+ * @return Boolean
*/
function wfRunHooks($event, $args = array()) {
if (!is_array($wgHooks)) {
throw new MWException("Global hooks array is not an array!\n");
- return false;
}
if (!is_array($wgHooks[$event])) {
throw new MWException("Hooks array for event '$event' is not an array!\n");
- return false;
}
foreach ($wgHooks[$event] as $index => $hook) {
* problem here.
*/
$retval = null;
- $handler = set_error_handler( 'hookErrorHandler' );
+ set_error_handler( 'hookErrorHandler' );
wfProfileIn( $func );
try {
$retval = call_user_func_array( $callback, $hook_args );
$badhookmsg = $e->getMessage();
}
wfProfileOut( $func );
- // Need to check for null, because set_error_handler borks on it... sigh
- if ( $handler !== null ) set_error_handler( $handler );
+ restore_error_handler();
/* String return is an error; false return means stop processing. */
-
if ( is_string( $retval ) ) {
global $wgOut;
$wgOut->showFatalError( $retval );