r28131 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r28130‎ | r28131 | r28132 >
Date:02:08, 4 December 2007
Author:simetrical
Status:old
Tags:
Comment:
maintenance/findhooks.php should find and report wfRunHooks() instances that it can't understand, instead of ignoring them. Lousy cut-and-paste job, but who cares, it's like 100 lines anyway.
Modified paths:
  • /trunk/phase3/maintenance/findhooks.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/findhooks.php
@@ -7,6 +7,8 @@
88 * - hooks names in hooks.txt are at the beginning of a line and single quoted.
99 * - hooks names in code are the first parameter of wfRunHooks.
1010 *
 11+ * Any instance of wfRunHooks that doesn't meet these parameters will be noted.
 12+ *
1113 * @addtogroup Maintenance
1214 *
1315 * @author Ashar Voultoiz <hashar@altern.org>
@@ -38,7 +40,7 @@
3941 }
4042
4143 /**
42 - * Get hooks from a php file
 44+ * Get hooks from a PHP file
4345 * @param $file Full filename to the PHP file.
4446 * @return array of hooks found.
4547 */
@@ -68,6 +70,37 @@
6971 }
7072
7173 /**
 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+/**
72105 * Nicely output the array
73106 * @param $msg A message to show before the value
74107 * @param $arr An array
@@ -83,6 +116,7 @@
84117
85118 $documented = getHooksFromDoc($doc);
86119 $potential = getHooksFromPath($pathinc);
 120+$bad = getBadHooksFromPath($pathinc);
87121
88122 $todo = array_diff($potential, $documented);
89123 $deprecated = array_diff($documented, $potential);
@@ -90,5 +124,6 @@
91125 // let's show the results:
92126 printArray('undocumented', $todo );
93127 printArray('not found', $deprecated );
 128+printArray('unclear hook calls', $bad );
94129
95130

Status & tagging log