Index: trunk/phase3/maintenance/findhooks.php |
— | — | @@ -7,6 +7,8 @@ |
8 | 8 | * - hooks names in hooks.txt are at the beginning of a line and single quoted. |
9 | 9 | * - hooks names in code are the first parameter of wfRunHooks. |
10 | 10 | * |
| 11 | + * Any instance of wfRunHooks that doesn't meet these parameters will be noted. |
| 12 | + * |
11 | 13 | * @addtogroup Maintenance |
12 | 14 | * |
13 | 15 | * @author Ashar Voultoiz <hashar@altern.org> |
— | — | @@ -38,7 +40,7 @@ |
39 | 41 | } |
40 | 42 | |
41 | 43 | /** |
42 | | - * Get hooks from a php file |
| 44 | + * Get hooks from a PHP file |
43 | 45 | * @param $file Full filename to the PHP file. |
44 | 46 | * @return array of hooks found. |
45 | 47 | */ |
— | — | @@ -68,6 +70,37 @@ |
69 | 71 | } |
70 | 72 | |
71 | 73 | /** |
| 74 | + * Get bad hooks (where the hook name could not be determined) from a PHP file |
| 75 | + * @param $file Full filename to the PHP file. |
| 76 | + * @return array of bad wfRunHooks() lines |
| 77 | + */ |
| 78 | +function getBadHooksFromFile( $file ) { |
| 79 | + $content = file_get_contents( $file ); |
| 80 | + $m = array(); |
| 81 | + # We want to skip the "function wfRunHooks()" one. :) |
| 82 | + preg_match_all( '/(?<!function )wfRunHooks\(\s*[^\s\'"].*/', $content, $m); |
| 83 | + return $m[0]; |
| 84 | +} |
| 85 | + |
| 86 | +/** |
| 87 | + * Get bad hooks from the source code. |
| 88 | + * @param $path Directory where the include files can be found |
| 89 | + * @return array of bad wfRunHooks() lines |
| 90 | + */ |
| 91 | +function getBadHooksFromPath( $path ) { |
| 92 | + $hooks = array(); |
| 93 | + if( $dh = opendir($path) ) { |
| 94 | + while(($file = readdir($dh)) !== false) { |
| 95 | + if( filetype($path.$file) == 'file' ) { |
| 96 | + $hooks = array_merge( $hooks, getBadHooksFromFile($path.$file) ); |
| 97 | + } |
| 98 | + } |
| 99 | + closedir($dh); |
| 100 | + } |
| 101 | + return $hooks; |
| 102 | +} |
| 103 | + |
| 104 | +/** |
72 | 105 | * Nicely output the array |
73 | 106 | * @param $msg A message to show before the value |
74 | 107 | * @param $arr An array |
— | — | @@ -83,6 +116,7 @@ |
84 | 117 | |
85 | 118 | $documented = getHooksFromDoc($doc); |
86 | 119 | $potential = getHooksFromPath($pathinc); |
| 120 | +$bad = getBadHooksFromPath($pathinc); |
87 | 121 | |
88 | 122 | $todo = array_diff($potential, $documented); |
89 | 123 | $deprecated = array_diff($documented, $potential); |
— | — | @@ -90,5 +124,6 @@ |
91 | 125 | // let's show the results: |
92 | 126 | printArray('undocumented', $todo ); |
93 | 127 | printArray('not found', $deprecated ); |
| 128 | +printArray('unclear hook calls', $bad ); |
94 | 129 | |
95 | 130 | |