Use Doxygen @addtogroup instead of phpdoc @package && @subpackage
[lhc/web/wiklou.git] / maintenance / findhooks.php
1 <?php
2 /**
3 * Simple script that try to find documented hook and hooks actually
4 * in the code and show what's missing.
5 *
6 * This script assumes that:
7 * - hooks names in hooks.txt are at the beginning of a line and single quoted.
8 * - hooks names in code are the first parameter of wfRunHooks.
9 *
10 * @addtogroup Maintenance
11 *
12 * @author Ashar Voultoiz <hashar@altern.org>
13 * @copyright Copyright © Ashar voultoiz
14 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public Licence 2.0 or later
15 */
16
17 /** This is a command line script*/
18 include('commandLine.inc');
19
20
21 # GLOBALS
22
23 $doc = $IP . '/docs/hooks.txt';
24 $pathinc = $IP . '/includes/';
25
26
27 # FUNCTIONS
28
29 /**
30 * @return array of documented hooks
31 */
32 function getHooksFromDoc() {
33 global $doc;
34 $content = file_get_contents( $doc );
35 $m = array();
36 preg_match_all( "/\n'(.*?)'/", $content, $m);
37 return $m[1];
38 }
39
40 /**
41 * Get hooks from a php file
42 * @param $file Full filename to the PHP file.
43 * @return array of hooks found.
44 */
45 function getHooksFromFile( $file ) {
46 $content = file_get_contents( $file );
47 $m = array();
48 preg_match_all( "/wfRunHooks\(\s*\'(.*?)\'/", $content, $m);
49 return $m[1];
50 }
51
52 /**
53 * Get hooks from the source code.
54 * @param $path Directory where the include files can be found
55 * @return array of hooks found.
56 */
57 function getHooksFromPath( $path ) {
58 $hooks = array();
59 if( $dh = opendir($path) ) {
60 while(($file = readdir($dh)) !== false) {
61 if( filetype($path.$file) == 'file' ) {
62 $hooks = array_merge( $hooks, getHooksFromFile($path.$file) );
63 }
64 }
65 closedir($dh);
66 }
67 return $hooks;
68 }
69
70 /**
71 * Nicely output the array
72 * @param $msg A message to show before the value
73 * @param $arr An array
74 * @param $sort Boolean : wheter to sort the array (Default: true)
75 */
76 function printArray( $msg, $arr, $sort = true ) {
77 if($sort) asort($arr);
78 foreach($arr as $v) print "$msg: $v\n";
79 }
80
81
82 # MAIN
83
84 $documented = getHooksFromDoc($doc);
85 $potential = getHooksFromPath($pathinc);
86
87 $todo = array_diff($potential, $documented);
88 $deprecated = array_diff($documented, $potential);
89
90 // let's show the results:
91 printArray('undocumented', $todo );
92 printArray('not found', $deprecated );
93
94 ?>