maintenance: Fix detection of bad hooks (wfRunHooks -> Hooks::run)
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 10 Jan 2019 19:33:10 +0000 (11:33 -0800)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 10 Jan 2019 19:33:10 +0000 (11:33 -0800)
It was still looking for wfRunHooks, which no longer exists
as of MediaWiki 1.32.

After this, it is now able to find one bad hook:

> Unclear hook calls:
> - Hooks::run( $action . 'ArticleComplete', [ .. ] ); # SpecialEditWatchlist

Also, remove the matching of wfRunHooks generally, given it no
longer exists. And also remove the historic notes from hooks.txt.

Change-Id: I4ac52ed75fb99d7775d4b4755e3f0871003d70a8

docs/hooks.txt
maintenance/findHooks.php

index 28065fc..d175bcd 100644 (file)
@@ -226,14 +226,9 @@ Hooks::run() returns true if the calling function should continue processing
 error occurred, or one of the hooks handled the action already). Checking the
 return value matters more for "before" hooks than for "complete" hooks.
 
-Hooks::run() was added in MediaWiki 1.18, before that the global function
-wfRunHooks must be used, which was deprecated in MediaWiki 1.25.
-
 Note that hook parameters are passed in an array; this is a necessary
-inconvenience to make it possible to pass reference values (that can be changed)
-into the hook code. Also note that earlier versions of wfRunHooks took a
-variable number of arguments; the array calling protocol came about after
-MediaWiki 1.4rc1.
+inconvenience to make it possible to pass reference values (which can be changed)
+by the hook callback.
 
 ==Events and parameters==
 
index ebb1f26..ed7a762 100644 (file)
@@ -5,12 +5,12 @@
  *
  * This script assumes that:
  * - hooks names in hooks.txt are at the beginning of a line and single quoted.
- * - hooks names in code are the first parameter of wfRunHooks.
+ * - hooks names in code are the first parameter of Hooks::run.
  *
  * if --online option is passed, the script will compare the hooks in the code
  * with the ones at https://www.mediawiki.org/wiki/Manual:Hooks
  *
- * Any instance of wfRunHooks that doesn't meet these parameters will be noted.
+ * Any instance of Hooks::run that doesn't meet these requirements will be noted.
  *
  * Copyright © Antoine Musso
  *
@@ -245,7 +245,7 @@ class FindHooks extends Maintenance {
                $m = [];
                preg_match_all(
                        // All functions which runs hooks
-                       '/(?:wfRunHooks|Hooks\:\:run|Hooks\:\:runWithoutAbort)\s*\(\s*' .
+                       '/(?:Hooks\:\:run|Hooks\:\:runWithoutAbort)\s*\(\s*' .
                                // First argument is the hook name as string
                                '([\'"])(.*?)\1' .
                                // Comma for second argument
@@ -287,13 +287,12 @@ class FindHooks extends Maintenance {
        /**
         * Get bad hooks (where the hook name could not be determined) from a PHP file
         * @param string $filePath Full filename to the PHP file.
-        * @return array Array of bad wfRunHooks() lines
+        * @return array Array of source code lines
         */
        private function getBadHooksFromFile( $filePath ) {
                $content = file_get_contents( $filePath );
                $m = [];
-               // We want to skip the "function wfRunHooks()" one.  :)
-               preg_match_all( '/(?<!function )wfRunHooks\(\s*[^\s\'"].*/', $content, $m );
+               preg_match_all( '/(?:Hooks\:\:run|Hooks\:\:runWithoutAbort)\(\s*[^\s\'"].*/', $content, $m );
                $list = [];
                foreach ( $m[0] as $match ) {
                        $list[] = $match . "(" . $filePath . ")";