r30829 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r30828‎ | r30829 | r30830 >
Date:09:37, 11 February 2008
Author:huji
Status:old
Tags:
Comment:
(bug 12301) Allow maintenance/findhooks.php to search hooks in multiple directories. Applying the patch created by Alexandre Emsenhuber (ialex)
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/maintenance/findhooks.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/findhooks.php
@@ -15,22 +15,18 @@
1616 * @copyright Copyright © Ashar voultoiz
1717 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public Licence 2.0 or later
1818 */
19 -
 19+
2020 /** This is a command line script*/
2121 include('commandLine.inc');
22 -
23 -
 22+
 23+
2424 # GLOBALS
25 -
 25+
2626 $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+
3329 # FUNCTIONS
34 -
 30+
3531 /**
3632 * @return array of documented hooks
3733 */
@@ -41,7 +37,7 @@
4238 preg_match_all( "/\n'(.*?)'/", $content, $m);
4339 return $m[1];
4440 }
45 -
 41+
4642 /**
4743 * Get hooks from a PHP file
4844 * @param $file Full filename to the PHP file.
@@ -53,7 +49,7 @@
5450 preg_match_all( '/wfRunHooks\(\s*([\'"])(.*?)\1/', $content, $m);
5551 return $m[2];
5652 }
57 -
 53+
5854 /**
5955 * Get hooks from the source code.
6056 * @param $path Directory where the include files can be found
@@ -71,7 +67,7 @@
7268 }
7369 return $hooks;
7470 }
75 -
 71+
7672 /**
7773 * Get bad hooks (where the hook name could not be determined) from a PHP file
7874 * @param $file Full filename to the PHP file.
@@ -82,9 +78,13 @@
8379 $m = array();
8480 # We want to skip the "function wfRunHooks()" one. :)
8581 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;
8787 }
88 -
 88+
8989 /**
9090 * Get bad hooks from the source code.
9191 * @param $path Directory where the include files can be found
@@ -94,7 +94,8 @@
9595 $hooks = array();
9696 if( $dh = opendir($path) ) {
9797 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__ ) {
99100 $hooks = array_merge( $hooks, getBadHooksFromFile($path.$file) );
100101 }
101102 }
@@ -102,7 +103,7 @@
103104 }
104105 return $hooks;
105106 }
106 -
 107+
107108 /**
108109 * Nicely output the array
109110 * @param $msg A message to show before the value
@@ -111,33 +112,29 @@
112113 */
113114 function printArray( $msg, $arr, $sort = true ) {
114115 if($sort) asort($arr);
115 - foreach($arr as $v) print "$msg: $v\n";
 116+ foreach($arr as $v) echo "$msg: $v\n";
116117 }
117 -
118 -
119 -# MAIN
120 -
 118+
 119+
 120+# MAIN
 121+
121122 $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+
139135 // let's show the results:
140136 printArray('undocumented', $todo );
141137 printArray('not found', $deprecated );
142138 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 @@
381381 in parentheses after them claimed otherwise
382382 * (bug 12732) Fix installer and searching to handle built-in tsearch2 for Postgres.
383383 * (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.
384385
385386 == Parser changes in 1.12 ==
386387

Status & tagging log