- if (!array_key_exists($event, $wgHooks)) {
- return true;
- }
-
- if (!is_array($wgHooks[$event])) {
- wfDebugDieBacktrace("Hooks array for event '$event' is not an array!\n");
- return false;
- }
-
- foreach ($wgHooks[$event] as $hook) {
-
- $object = NULL;
- $method = 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.
- */
-
- if (is_array($hook)) {
- if (count($hook) < 1) {
- wfDebugDieBacktrace("Empty array in hooks for " . $event . "\n");
- } else if (is_object($hook[0])) {
- $object = $hook[0];
- if (count($hook) < 2) {
+/**
+ * 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($event, $args = array()) {
+
+ global $wgHooks;
+
+ // Return quickly in the most common case
+ if ( !isset( $wgHooks[$event] ) ) {
+ return true;
+ }
+
+ 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) {
+
+ $object = null;
+ $method = null;
+ $func = null;
+ $data = null;
+ $have_data = false;
+ $closure = 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.
+ */
+
+ if ( is_array( $hook ) ) {
+ if ( count( $hook ) < 1 ) {
+ throw new MWException("Empty array in hooks for " . $event . "\n");
+ } else if ( is_object( $hook[0] ) ) {
+ $object = $wgHooks[$event][$index][0];
+ if ( $object instanceof Closure ) {
+ $closure = true;
+ if ( count( $hook ) > 1 ) {
+ $data = $hook[1];
+ $have_data = true;
+ }
+ } else {
+ if ( count( $hook ) < 2 ) {