Index: trunk/phase3/maintenance/findhooks.php |
— | — | @@ -15,22 +15,18 @@ |
16 | 16 | * @copyright Copyright © Ashar voultoiz |
17 | 17 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public Licence 2.0 or later |
18 | 18 | */ |
19 | | - |
| 19 | + |
20 | 20 | /** This is a command line script*/ |
21 | 21 | include('commandLine.inc'); |
22 | | - |
23 | | - |
| 22 | + |
| 23 | + |
24 | 24 | # GLOBALS |
25 | | - |
| 25 | + |
26 | 26 | $doc = $IP . '/docs/hooks.txt'; |
27 | | -$pathinc = $IP . '/includes/'; |
28 | | -$pathfile = $IP . '/includes/filerepo/LocalFile.php'; |
29 | | -$pathlang = $IP . '/languages/Language.php'; |
30 | | -$pathskin = $IP . '/skins/MonoBook.php'; |
31 | | - |
32 | | - |
| 27 | +$pathinc = array( $IP.'/includes/', $IP.'/includes/api/', $IP.'/includes/filerepo/', $IP.'/languages/', $IP.'/maintenance/', $IP.'/skins/' ); |
| 28 | + |
33 | 29 | # FUNCTIONS |
34 | | - |
| 30 | + |
35 | 31 | /** |
36 | 32 | * @return array of documented hooks |
37 | 33 | */ |
— | — | @@ -41,7 +37,7 @@ |
42 | 38 | preg_match_all( "/\n'(.*?)'/", $content, $m); |
43 | 39 | return $m[1]; |
44 | 40 | } |
45 | | - |
| 41 | + |
46 | 42 | /** |
47 | 43 | * Get hooks from a PHP file |
48 | 44 | * @param $file Full filename to the PHP file. |
— | — | @@ -53,7 +49,7 @@ |
54 | 50 | preg_match_all( '/wfRunHooks\(\s*([\'"])(.*?)\1/', $content, $m); |
55 | 51 | return $m[2]; |
56 | 52 | } |
57 | | - |
| 53 | + |
58 | 54 | /** |
59 | 55 | * Get hooks from the source code. |
60 | 56 | * @param $path Directory where the include files can be found |
— | — | @@ -71,7 +67,7 @@ |
72 | 68 | } |
73 | 69 | return $hooks; |
74 | 70 | } |
75 | | - |
| 71 | + |
76 | 72 | /** |
77 | 73 | * Get bad hooks (where the hook name could not be determined) from a PHP file |
78 | 74 | * @param $file Full filename to the PHP file. |
— | — | @@ -82,9 +78,13 @@ |
83 | 79 | $m = array(); |
84 | 80 | # We want to skip the "function wfRunHooks()" one. :) |
85 | 81 | preg_match_all( '/(?<!function )wfRunHooks\(\s*[^\s\'"].*/', $content, $m); |
86 | | - return $m[0]; |
| 82 | + $list = array(); |
| 83 | + foreach( $m[0] as $match ){ |
| 84 | + $list[] = $match . "(" . $file . ")"; |
| 85 | + } |
| 86 | + return $list; |
87 | 87 | } |
88 | | - |
| 88 | + |
89 | 89 | /** |
90 | 90 | * Get bad hooks from the source code. |
91 | 91 | * @param $path Directory where the include files can be found |
— | — | @@ -94,7 +94,8 @@ |
95 | 95 | $hooks = array(); |
96 | 96 | if( $dh = opendir($path) ) { |
97 | 97 | while(($file = readdir($dh)) !== false) { |
98 | | - if( filetype($path.$file) == 'file' ) { |
| 98 | + # We don't want to read this file as it contains bad calls to wfRunHooks() |
| 99 | + if( filetype( $path.$file ) == 'file' && !$path.$file == __FILE__ ) { |
99 | 100 | $hooks = array_merge( $hooks, getBadHooksFromFile($path.$file) ); |
100 | 101 | } |
101 | 102 | } |
— | — | @@ -102,7 +103,7 @@ |
103 | 104 | } |
104 | 105 | return $hooks; |
105 | 106 | } |
106 | | - |
| 107 | + |
107 | 108 | /** |
108 | 109 | * Nicely output the array |
109 | 110 | * @param $msg A message to show before the value |
— | — | @@ -111,33 +112,29 @@ |
112 | 113 | */ |
113 | 114 | function printArray( $msg, $arr, $sort = true ) { |
114 | 115 | if($sort) asort($arr); |
115 | | - foreach($arr as $v) print "$msg: $v\n"; |
| 116 | + foreach($arr as $v) echo "$msg: $v\n"; |
116 | 117 | } |
117 | | - |
118 | | - |
119 | | -# MAIN |
120 | | - |
| 118 | + |
| 119 | + |
| 120 | +# MAIN |
| 121 | + |
121 | 122 | $documented = getHooksFromDoc($doc); |
122 | | - |
123 | | -$potenial_inc = getHooksFromPath($pathinc); |
124 | | -$potential_file = getHooksFromFile($pathfile); |
125 | | -$potential_lang = getHooksFromFile($pathlang); |
126 | | -$potential_skin = getHooksFromFile($pathskin); |
127 | | - |
128 | | -$bad_inc = getBadHooksFromPath($pathinc); |
129 | | -$bad_file = getBadHooksFromFile($pathfile); |
130 | | -$bad_lang = getBadHooksFromFile($pathlang); |
131 | | -$bad_skin = getBadHooksFromFile($pathskin); |
132 | | - |
133 | | -$potential = array_merge($potenial_inc, $potential_file, $potential_lang, $potential_skin); |
134 | | -$bad = array_merge($bad_inc, $bad_file, $bad_lang, $bad_skin); |
135 | | - |
136 | | -$todo = array_diff($potential, $documented); |
137 | | -$deprecated = array_diff($documented, $potential); |
138 | | - |
| 123 | +$potential = array(); |
| 124 | +$bad = array(); |
| 125 | +foreach( $pathinc as $dir ) { |
| 126 | + $potential = array_merge( $potential, getHooksFromPath( $dir ) ); |
| 127 | + $bad = array_merge( $bad, getBadHooksFromPath( $dir ) ); |
| 128 | +} |
| 129 | + |
| 130 | +$potential = array_unique( $potential ); |
| 131 | +$bad = array_unique( $bad ); |
| 132 | +$todo = array_diff( $potential, $documented ); |
| 133 | +$deprecated = array_diff( $documented, $potential ); |
| 134 | + |
139 | 135 | // let's show the results: |
140 | 136 | printArray('undocumented', $todo ); |
141 | 137 | printArray('not found', $deprecated ); |
142 | 138 | printArray('unclear hook calls', $bad ); |
143 | | - |
144 | | - |
| 139 | + |
| 140 | +if ( count( $todo ) == 0 && count( $deprecated ) == 0 && count( $bad ) == 0 ) |
| 141 | + echo "Looks good!\n"; |
\ No newline at end of file |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -380,6 +380,7 @@ |
381 | 381 | in parentheses after them claimed otherwise |
382 | 382 | * (bug 12732) Fix installer and searching to handle built-in tsearch2 for Postgres. |
383 | 383 | * (bug 12784) Change "bool" types to smallint to handle Postgres 8.3 strictness. |
| 384 | +* (bug 12301) Allow maintenance/findhooks.php to search hooks in multiple directories. |
384 | 385 | |
385 | 386 | == Parser changes in 1.12 == |
386 | 387 | |