<?php
/**
* Hooks.php -- a tool for running hook functions
- * Copyright 2004, Evan Prodromou <evan@wikitravel.org>.
+ * Copyright 2004, 2005 Evan Prodromou <evan@wikitravel.org>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * @author <evan@wikitravel.org>
+ * @author Evan Prodromou <evan@wikitravel.org>
* @package MediaWiki
- * @seealso hooks.doc
+ * @see hooks.txt
*/
if (defined('MEDIAWIKI')) {
- /*
+ /**
* 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.
*/
- function wfRunHooks() {
+ function wfRunHooks($event, $args) {
global $wgHooks;
return false;
}
- $args = func_get_args();
-
- if (count($args) < 1) {
- wfDieDebugBacktrace("No event name given for wfRunHooks().\n");
- return false;
- }
-
- $event = array_shift($args);
-
if (!array_key_exists($event, $wgHooks)) {
return true;
}
-
+
if (!is_array($wgHooks[$event])) {
wfDieDebugBacktrace("Hooks array for event '$event' is not an array!\n");
return false;
}
-
+
foreach ($wgHooks[$event] as $hook) {
$object = NULL;
$func = NULL;
$data = NULL;
$have_data = false;
-
+
/* $hook can be: a function, an object, an array of $function and $data,
* an array of just a function, an array of object and method, or an
* array of object, method, and data.
} else {
wfDieDebugBacktrace("Unknown datatype in hooks for " . $event . "\n");
}
-
+
+ /* We put the first data element on, if needed. */
+
if ($have_data) {
$hook_args = array_merge(array($data), $args);
} else {
$hook_args = $args;
}
+ /* Call the hook. */
+
if ($object) {
$retval = call_user_func_array(array($object, $method), $hook_args);
} else {
$retval = call_user_func_array($func, $hook_args);
}
+ /* String return is an error; false return means stop processing. */
+
if (is_string($retval)) {
global $wgOut;
$wgOut->fatalError($retval);
return true;
}
-}
-
+} /* if defined(MEDIAWIKI) */
?>