Index: trunk/phase3/maintenance/findhooks.php |
— | — | @@ -1,225 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Simple script that try to find documented hook and hooks actually |
5 | | - * in the code and show what's missing. |
6 | | - * |
7 | | - * This script assumes that: |
8 | | - * - hooks names in hooks.txt are at the beginning of a line and single quoted. |
9 | | - * - hooks names in code are the first parameter of wfRunHooks. |
10 | | - * |
11 | | - * if --online option is passed, the script will compare the hooks in the code |
12 | | - * with the ones at http://www.mediawiki.org/wiki/Manual:Hooks |
13 | | - * |
14 | | - * Any instance of wfRunHooks that doesn't meet these parameters will be noted. |
15 | | - * |
16 | | - * Copyright © Ashar Voultoiz |
17 | | - * |
18 | | - * This program is free software; you can redistribute it and/or modify |
19 | | - * it under the terms of the GNU General Public License as published by |
20 | | - * the Free Software Foundation; either version 2 of the License, or |
21 | | - * (at your option) any later version. |
22 | | - * |
23 | | - * This program is distributed in the hope that it will be useful, |
24 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
25 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26 | | - * GNU General Public License for more details. |
27 | | - * |
28 | | - * You should have received a copy of the GNU General Public License along |
29 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
30 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
31 | | - * http://www.gnu.org/copyleft/gpl.html |
32 | | - * |
33 | | - * @file |
34 | | - * @ingroup Maintenance |
35 | | - * @author Ashar Voultoiz <hashar at free dot fr> |
36 | | - */ |
37 | | - |
38 | | -require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
39 | | - |
40 | | -class FindHooks extends Maintenance { |
41 | | - public function __construct() { |
42 | | - parent::__construct(); |
43 | | - $this->mDescription = 'Find hooks that are undocumented, missing, or just plain wrong'; |
44 | | - $this->addOption( 'online', 'Check against MediaWiki.org hook documentation' ); |
45 | | - } |
46 | | - |
47 | | - public function getDbType() { |
48 | | - return Maintenance::DB_NONE; |
49 | | - } |
50 | | - |
51 | | - public function execute() { |
52 | | - global $IP; |
53 | | - |
54 | | - $documented = $this->getHooksFromDoc( $IP . '/docs/hooks.txt' ); |
55 | | - $potential = array(); |
56 | | - $bad = array(); |
57 | | - $pathinc = array( |
58 | | - $IP . '/', |
59 | | - $IP . '/includes/', |
60 | | - $IP . '/includes/actions/', |
61 | | - $IP . '/includes/api/', |
62 | | - $IP . '/includes/cache/', |
63 | | - $IP . '/includes/db/', |
64 | | - $IP . '/includes/diff/', |
65 | | - $IP . '/includes/filerepo/', |
66 | | - $IP . '/includes/installer/', |
67 | | - $IP . '/includes/interwiki/', |
68 | | - $IP . '/includes/media/', |
69 | | - $IP . '/includes/parser/', |
70 | | - $IP . '/includes/resourceloader/', |
71 | | - $IP . '/includes/revisiondelete/', |
72 | | - $IP . '/includes/search/', |
73 | | - $IP . '/includes/specials/', |
74 | | - $IP . '/includes/upload/', |
75 | | - $IP . '/languages/', |
76 | | - $IP . '/maintenance/', |
77 | | - $IP . '/tests/', |
78 | | - $IP . '/tests/parser/', |
79 | | - $IP . '/tests/phpunit/suites/', |
80 | | - $IP . '/skins/', |
81 | | - ); |
82 | | - |
83 | | - foreach ( $pathinc as $dir ) { |
84 | | - $potential = array_merge( $potential, $this->getHooksFromPath( $dir ) ); |
85 | | - $bad = array_merge( $bad, $this->getBadHooksFromPath( $dir ) ); |
86 | | - } |
87 | | - |
88 | | - $potential = array_unique( $potential ); |
89 | | - $bad = array_unique( $bad ); |
90 | | - $todo = array_diff( $potential, $documented ); |
91 | | - $deprecated = array_diff( $documented, $potential ); |
92 | | - |
93 | | - // let's show the results: |
94 | | - $this->printArray( 'Undocumented', $todo ); |
95 | | - $this->printArray( 'Documented and not found', $deprecated ); |
96 | | - $this->printArray( 'Unclear hook calls', $bad ); |
97 | | - |
98 | | - if ( count( $todo ) == 0 && count( $deprecated ) == 0 && count( $bad ) == 0 ) |
99 | | - { |
100 | | - $this->output( "Looks good!\n" ); |
101 | | - } |
102 | | - } |
103 | | - |
104 | | - /** |
105 | | - * Get the hook documentation, either locally or from MediaWiki.org |
106 | | - * @return array of documented hooks |
107 | | - */ |
108 | | - private function getHooksFromDoc( $doc ) { |
109 | | - if ( $this->hasOption( 'online' ) ) { |
110 | | - // All hooks |
111 | | - $allhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:MediaWiki_hooks&cmlimit=500&format=php' ); |
112 | | - $allhookdata = unserialize( $allhookdata ); |
113 | | - $allhooks = array(); |
114 | | - foreach ( $allhookdata['query']['categorymembers'] as $page ) { |
115 | | - $found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches ); |
116 | | - if ( $found ) { |
117 | | - $hook = str_replace( ' ', '_', $matches[1] ); |
118 | | - $allhooks[] = $hook; |
119 | | - } |
120 | | - } |
121 | | - // Removed hooks |
122 | | - $oldhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Removed_hooks&cmlimit=500&format=php' ); |
123 | | - $oldhookdata = unserialize( $oldhookdata ); |
124 | | - $removed = array(); |
125 | | - foreach ( $oldhookdata['query']['categorymembers'] as $page ) { |
126 | | - $found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches ); |
127 | | - if ( $found ) { |
128 | | - $hook = str_replace( ' ', '_', $matches[1] ); |
129 | | - $removed[] = $hook; |
130 | | - } |
131 | | - } |
132 | | - return array_diff( $allhooks, $removed ); |
133 | | - } else { |
134 | | - $m = array(); |
135 | | - $content = file_get_contents( $doc ); |
136 | | - preg_match_all( "/\n'(.*?)'/", $content, $m ); |
137 | | - return array_unique( $m[1] ); |
138 | | - } |
139 | | - } |
140 | | - |
141 | | - /** |
142 | | - * Get hooks from a PHP file |
143 | | - * @param $file Full filename to the PHP file. |
144 | | - * @return array of hooks found. |
145 | | - */ |
146 | | - private function getHooksFromFile( $file ) { |
147 | | - $content = file_get_contents( $file ); |
148 | | - $m = array(); |
149 | | - preg_match_all( '/(?:wfRunHooks|Hooks\:\:run)\(\s*([\'"])(.*?)\1/', $content, $m ); |
150 | | - return $m[2]; |
151 | | - } |
152 | | - |
153 | | - /** |
154 | | - * Get hooks from the source code. |
155 | | - * @param $path Directory where the include files can be found |
156 | | - * @return array of hooks found. |
157 | | - */ |
158 | | - private function getHooksFromPath( $path ) { |
159 | | - $hooks = array(); |
160 | | - $dh = opendir( $path ); |
161 | | - if ( $dh ) { |
162 | | - while ( ( $file = readdir( $dh ) ) !== false ) { |
163 | | - if ( filetype( $path . $file ) == 'file' ) { |
164 | | - $hooks = array_merge( $hooks, $this->getHooksFromFile( $path . $file ) ); |
165 | | - } |
166 | | - } |
167 | | - closedir( $dh ); |
168 | | - } |
169 | | - return $hooks; |
170 | | - } |
171 | | - |
172 | | - /** |
173 | | - * Get bad hooks (where the hook name could not be determined) from a PHP file |
174 | | - * @param $file Full filename to the PHP file. |
175 | | - * @return array of bad wfRunHooks() lines |
176 | | - */ |
177 | | - private function getBadHooksFromFile( $file ) { |
178 | | - $content = file_get_contents( $file ); |
179 | | - $m = array(); |
180 | | - # We want to skip the "function wfRunHooks()" one. :) |
181 | | - preg_match_all( '/(?<!function )wfRunHooks\(\s*[^\s\'"].*/', $content, $m ); |
182 | | - $list = array(); |
183 | | - foreach ( $m[0] as $match ) { |
184 | | - $list[] = $match . "(" . $file . ")"; |
185 | | - } |
186 | | - return $list; |
187 | | - } |
188 | | - |
189 | | - /** |
190 | | - * Get bad hooks from the source code. |
191 | | - * @param $path Directory where the include files can be found |
192 | | - * @return array of bad wfRunHooks() lines |
193 | | - */ |
194 | | - private function getBadHooksFromPath( $path ) { |
195 | | - $hooks = array(); |
196 | | - $dh = opendir( $path ); |
197 | | - if ( $dh ) { |
198 | | - while ( ( $file = readdir( $dh ) ) !== false ) { |
199 | | - # We don't want to read this file as it contains bad calls to wfRunHooks() |
200 | | - if ( filetype( $path . $file ) == 'file' && !$path . $file == __FILE__ ) { |
201 | | - $hooks = array_merge( $hooks, $this->getBadHooksFromFile( $path . $file ) ); |
202 | | - } |
203 | | - } |
204 | | - closedir( $dh ); |
205 | | - } |
206 | | - return $hooks; |
207 | | - } |
208 | | - |
209 | | - /** |
210 | | - * Nicely output the array |
211 | | - * @param $msg String: a message to show before the value |
212 | | - * @param $arr Array: an array |
213 | | - * @param $sort Boolean: whether to sort the array (Default: true) |
214 | | - */ |
215 | | - private function printArray( $msg, $arr, $sort = true ) { |
216 | | - if ( $sort ) { |
217 | | - asort( $arr ); |
218 | | - } |
219 | | - foreach ( $arr as $v ) { |
220 | | - $this->output( "$msg: $v\n" ); |
221 | | - } |
222 | | - } |
223 | | -} |
224 | | - |
225 | | -$maintClass = 'FindHooks'; |
226 | | -require_once( RUN_MAINTENANCE_IF_MAIN ); |
Index: trunk/phase3/maintenance/findHooks.php |
— | — | @@ -0,0 +1,225 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Simple script that try to find documented hook and hooks actually |
| 5 | + * in the code and show what's missing. |
| 6 | + * |
| 7 | + * This script assumes that: |
| 8 | + * - hooks names in hooks.txt are at the beginning of a line and single quoted. |
| 9 | + * - hooks names in code are the first parameter of wfRunHooks. |
| 10 | + * |
| 11 | + * if --online option is passed, the script will compare the hooks in the code |
| 12 | + * with the ones at http://www.mediawiki.org/wiki/Manual:Hooks |
| 13 | + * |
| 14 | + * Any instance of wfRunHooks that doesn't meet these parameters will be noted. |
| 15 | + * |
| 16 | + * Copyright © Ashar Voultoiz |
| 17 | + * |
| 18 | + * This program is free software; you can redistribute it and/or modify |
| 19 | + * it under the terms of the GNU General Public License as published by |
| 20 | + * the Free Software Foundation; either version 2 of the License, or |
| 21 | + * (at your option) any later version. |
| 22 | + * |
| 23 | + * This program is distributed in the hope that it will be useful, |
| 24 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 25 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 26 | + * GNU General Public License for more details. |
| 27 | + * |
| 28 | + * You should have received a copy of the GNU General Public License along |
| 29 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 30 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 31 | + * http://www.gnu.org/copyleft/gpl.html |
| 32 | + * |
| 33 | + * @file |
| 34 | + * @ingroup Maintenance |
| 35 | + * @author Ashar Voultoiz <hashar at free dot fr> |
| 36 | + */ |
| 37 | + |
| 38 | +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
| 39 | + |
| 40 | +class FindHooks extends Maintenance { |
| 41 | + public function __construct() { |
| 42 | + parent::__construct(); |
| 43 | + $this->mDescription = 'Find hooks that are undocumented, missing, or just plain wrong'; |
| 44 | + $this->addOption( 'online', 'Check against MediaWiki.org hook documentation' ); |
| 45 | + } |
| 46 | + |
| 47 | + public function getDbType() { |
| 48 | + return Maintenance::DB_NONE; |
| 49 | + } |
| 50 | + |
| 51 | + public function execute() { |
| 52 | + global $IP; |
| 53 | + |
| 54 | + $documented = $this->getHooksFromDoc( $IP . '/docs/hooks.txt' ); |
| 55 | + $potential = array(); |
| 56 | + $bad = array(); |
| 57 | + $pathinc = array( |
| 58 | + $IP . '/', |
| 59 | + $IP . '/includes/', |
| 60 | + $IP . '/includes/actions/', |
| 61 | + $IP . '/includes/api/', |
| 62 | + $IP . '/includes/cache/', |
| 63 | + $IP . '/includes/db/', |
| 64 | + $IP . '/includes/diff/', |
| 65 | + $IP . '/includes/filerepo/', |
| 66 | + $IP . '/includes/installer/', |
| 67 | + $IP . '/includes/interwiki/', |
| 68 | + $IP . '/includes/media/', |
| 69 | + $IP . '/includes/parser/', |
| 70 | + $IP . '/includes/resourceloader/', |
| 71 | + $IP . '/includes/revisiondelete/', |
| 72 | + $IP . '/includes/search/', |
| 73 | + $IP . '/includes/specials/', |
| 74 | + $IP . '/includes/upload/', |
| 75 | + $IP . '/languages/', |
| 76 | + $IP . '/maintenance/', |
| 77 | + $IP . '/tests/', |
| 78 | + $IP . '/tests/parser/', |
| 79 | + $IP . '/tests/phpunit/suites/', |
| 80 | + $IP . '/skins/', |
| 81 | + ); |
| 82 | + |
| 83 | + foreach ( $pathinc as $dir ) { |
| 84 | + $potential = array_merge( $potential, $this->getHooksFromPath( $dir ) ); |
| 85 | + $bad = array_merge( $bad, $this->getBadHooksFromPath( $dir ) ); |
| 86 | + } |
| 87 | + |
| 88 | + $potential = array_unique( $potential ); |
| 89 | + $bad = array_unique( $bad ); |
| 90 | + $todo = array_diff( $potential, $documented ); |
| 91 | + $deprecated = array_diff( $documented, $potential ); |
| 92 | + |
| 93 | + // let's show the results: |
| 94 | + $this->printArray( 'Undocumented', $todo ); |
| 95 | + $this->printArray( 'Documented and not found', $deprecated ); |
| 96 | + $this->printArray( 'Unclear hook calls', $bad ); |
| 97 | + |
| 98 | + if ( count( $todo ) == 0 && count( $deprecated ) == 0 && count( $bad ) == 0 ) |
| 99 | + { |
| 100 | + $this->output( "Looks good!\n" ); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Get the hook documentation, either locally or from MediaWiki.org |
| 106 | + * @return array of documented hooks |
| 107 | + */ |
| 108 | + private function getHooksFromDoc( $doc ) { |
| 109 | + if ( $this->hasOption( 'online' ) ) { |
| 110 | + // All hooks |
| 111 | + $allhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:MediaWiki_hooks&cmlimit=500&format=php' ); |
| 112 | + $allhookdata = unserialize( $allhookdata ); |
| 113 | + $allhooks = array(); |
| 114 | + foreach ( $allhookdata['query']['categorymembers'] as $page ) { |
| 115 | + $found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches ); |
| 116 | + if ( $found ) { |
| 117 | + $hook = str_replace( ' ', '_', $matches[1] ); |
| 118 | + $allhooks[] = $hook; |
| 119 | + } |
| 120 | + } |
| 121 | + // Removed hooks |
| 122 | + $oldhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Removed_hooks&cmlimit=500&format=php' ); |
| 123 | + $oldhookdata = unserialize( $oldhookdata ); |
| 124 | + $removed = array(); |
| 125 | + foreach ( $oldhookdata['query']['categorymembers'] as $page ) { |
| 126 | + $found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches ); |
| 127 | + if ( $found ) { |
| 128 | + $hook = str_replace( ' ', '_', $matches[1] ); |
| 129 | + $removed[] = $hook; |
| 130 | + } |
| 131 | + } |
| 132 | + return array_diff( $allhooks, $removed ); |
| 133 | + } else { |
| 134 | + $m = array(); |
| 135 | + $content = file_get_contents( $doc ); |
| 136 | + preg_match_all( "/\n'(.*?)'/", $content, $m ); |
| 137 | + return array_unique( $m[1] ); |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * Get hooks from a PHP file |
| 143 | + * @param $file Full filename to the PHP file. |
| 144 | + * @return array of hooks found. |
| 145 | + */ |
| 146 | + private function getHooksFromFile( $file ) { |
| 147 | + $content = file_get_contents( $file ); |
| 148 | + $m = array(); |
| 149 | + preg_match_all( '/(?:wfRunHooks|Hooks\:\:run)\(\s*([\'"])(.*?)\1/', $content, $m ); |
| 150 | + return $m[2]; |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * Get hooks from the source code. |
| 155 | + * @param $path Directory where the include files can be found |
| 156 | + * @return array of hooks found. |
| 157 | + */ |
| 158 | + private function getHooksFromPath( $path ) { |
| 159 | + $hooks = array(); |
| 160 | + $dh = opendir( $path ); |
| 161 | + if ( $dh ) { |
| 162 | + while ( ( $file = readdir( $dh ) ) !== false ) { |
| 163 | + if ( filetype( $path . $file ) == 'file' ) { |
| 164 | + $hooks = array_merge( $hooks, $this->getHooksFromFile( $path . $file ) ); |
| 165 | + } |
| 166 | + } |
| 167 | + closedir( $dh ); |
| 168 | + } |
| 169 | + return $hooks; |
| 170 | + } |
| 171 | + |
| 172 | + /** |
| 173 | + * Get bad hooks (where the hook name could not be determined) from a PHP file |
| 174 | + * @param $file Full filename to the PHP file. |
| 175 | + * @return array of bad wfRunHooks() lines |
| 176 | + */ |
| 177 | + private function getBadHooksFromFile( $file ) { |
| 178 | + $content = file_get_contents( $file ); |
| 179 | + $m = array(); |
| 180 | + # We want to skip the "function wfRunHooks()" one. :) |
| 181 | + preg_match_all( '/(?<!function )wfRunHooks\(\s*[^\s\'"].*/', $content, $m ); |
| 182 | + $list = array(); |
| 183 | + foreach ( $m[0] as $match ) { |
| 184 | + $list[] = $match . "(" . $file . ")"; |
| 185 | + } |
| 186 | + return $list; |
| 187 | + } |
| 188 | + |
| 189 | + /** |
| 190 | + * Get bad hooks from the source code. |
| 191 | + * @param $path Directory where the include files can be found |
| 192 | + * @return array of bad wfRunHooks() lines |
| 193 | + */ |
| 194 | + private function getBadHooksFromPath( $path ) { |
| 195 | + $hooks = array(); |
| 196 | + $dh = opendir( $path ); |
| 197 | + if ( $dh ) { |
| 198 | + while ( ( $file = readdir( $dh ) ) !== false ) { |
| 199 | + # We don't want to read this file as it contains bad calls to wfRunHooks() |
| 200 | + if ( filetype( $path . $file ) == 'file' && !$path . $file == __FILE__ ) { |
| 201 | + $hooks = array_merge( $hooks, $this->getBadHooksFromFile( $path . $file ) ); |
| 202 | + } |
| 203 | + } |
| 204 | + closedir( $dh ); |
| 205 | + } |
| 206 | + return $hooks; |
| 207 | + } |
| 208 | + |
| 209 | + /** |
| 210 | + * Nicely output the array |
| 211 | + * @param $msg String: a message to show before the value |
| 212 | + * @param $arr Array: an array |
| 213 | + * @param $sort Boolean: whether to sort the array (Default: true) |
| 214 | + */ |
| 215 | + private function printArray( $msg, $arr, $sort = true ) { |
| 216 | + if ( $sort ) { |
| 217 | + asort( $arr ); |
| 218 | + } |
| 219 | + foreach ( $arr as $v ) { |
| 220 | + $this->output( "$msg: $v\n" ); |
| 221 | + } |
| 222 | + } |
| 223 | +} |
| 224 | + |
| 225 | +$maintClass = 'FindHooks'; |
| 226 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Property changes on: trunk/phase3/maintenance/findHooks.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
1 | 227 | Merged /branches/sqlite/maintenance/findhooks.php:r58211-58321 |
2 | 228 | Merged /branches/new-installer/phase3/maintenance/findhooks.php:r43664-66004 |
3 | 229 | Merged /branches/REL1_15/phase3/maintenance/findhooks.php:r51646 |
4 | 230 | Merged /branches/REL1_17/phase3/maintenance/findhooks.php:r81445,81448 |
Added: svn:eol-style |
5 | 231 | + native |