* Updates
[mediawiki.git] / maintenance / findhooks.php
blob97e6c57d04f8e3384cbdf832ff65ee664385152c
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.
10 * @package MediaWiki
11 * @subpackage Maintenance
13 * @author Ashar Voultoiz <hashar@altern.org>
14 * @copyright Copyright © Ashar voultoiz
15 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public Licence 2.0 or later
18 /** This is a command line script*/
19 include('commandLine.inc');
22 # GLOBALS
24 $doc = $IP . '/docs/hooks.txt';
25 $pathinc = $IP . '/includes/';
28 # FUNCTIONS
30 /**
31 * @return array of documented hooks
33 function getHooksFromDoc() {
34 global $doc;
35 $content = file_get_contents( $doc );
36 $m = array();
37 preg_match_all( "/\n'(.*?)'/", $content, $m);
38 return $m[1];
41 /**
42 * Get hooks from a php file
43 * @param $file Full filename to the PHP file.
44 * @return array of hooks found.
46 function getHooksFromFile( $file ) {
47 $content = file_get_contents( $file );
48 $m = array();
49 preg_match_all( "/wfRunHooks\(\s*\'(.*?)\'/", $content, $m);
50 return $m[1];
53 /**
54 * Get hooks from the source code.
55 * @param $path Directory where the include files can be found
56 * @return array of hooks found.
58 function getHooksFromPath( $path ) {
59 $hooks = array();
60 if( $dh = opendir($path) ) {
61 while(($file = readdir($dh)) !== false) {
62 if( filetype($path.$file) == 'file' ) {
63 $hooks = array_merge( $hooks, getHooksFromFile($path.$file) );
66 closedir($dh);
68 return $hooks;
71 /**
72 * Nicely output the array
73 * @param $msg A message to show before the value
74 * @param $arr An array
75 * @param $sort Boolean : wheter to sort the array (Default: true)
77 function printArray( $msg, $arr, $sort = true ) {
78 if($sort) asort($arr);
79 foreach($arr as $v) print "$msg: $v\n";
83 # MAIN
85 $documented = getHooksFromDoc($doc);
86 $potential = getHooksFromPath($pathinc);
88 $todo = array_diff($potential, $documented);
89 $deprecated = array_diff($documented, $potential);
91 // let's show the results:
92 printArray('undocumented', $todo );
93 printArray('not found', $deprecated );