* GROUP BY support in makeSelectOptions()
[lhc/web/wiklou.git] / includes / Hooks.php
index 5cfde41..021d799 100644 (file)
@@ -1,7 +1,7 @@
 <?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;
 
@@ -39,24 +39,15 @@ if (defined('MEDIAWIKI')) {
                        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;
@@ -64,7 +55,7 @@ if (defined('MEDIAWIKI')) {
                        $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.
@@ -101,19 +92,25 @@ if (defined('MEDIAWIKI')) {
                        } 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);
@@ -125,6 +122,5 @@ if (defined('MEDIAWIKI')) {
                
                return true;
        }
-}
-
+} /* if defined(MEDIAWIKI) */ 
 ?>