*Add bitfields to various tables for revisiondelete
[mediawiki.git] / maintenance / findhooks.php
blob0308ad133a053f6ae9367221ab1f70a9c7a4aa54
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 * @addtogroup Maintenance
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
17 /** This is a command line script*/
18 include('commandLine.inc');
21 # GLOBALS
23 $doc = $IP . '/docs/hooks.txt';
24 $pathinc = $IP . '/includes/';
27 # FUNCTIONS
29 /**
30 * @return array of documented hooks
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];
40 /**
41 * Get hooks from a php file
42 * @param $file Full filename to the PHP file.
43 * @return array of hooks found.
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];
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.
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) );
65 closedir($dh);
67 return $hooks;
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)
76 function printArray( $msg, $arr, $sort = true ) {
77 if($sort) asort($arr);
78 foreach($arr as $v) print "$msg: $v\n";
82 # MAIN
84 $documented = getHooksFromDoc($doc);
85 $potential = getHooksFromPath($pathinc);
87 $todo = array_diff($potential, $documented);
88 $deprecated = array_diff($documented, $potential);
90 // let's show the results:
91 printArray('undocumented', $todo );
92 printArray('not found', $deprecated );