3 * Simple script that try to find documented hook and hooks actually
4 * in the code and show what's missing.
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.
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');
24 $doc = $IP . '/docs/hooks.txt';
25 $pathinc = $IP . '/includes/';
31 * @return array of documented hooks
33 function getHooksFromDoc() {
35 $content = file_get_contents( $doc );
36 preg_match_all( "/\n'(.*?)'/", $content, $m);
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 preg_match_all( "/wfRunHooks\(\s*\'(.*?)\'/", $content, $m);
52 * Get hooks from the source code.
53 * @param $path Directory where the include files can be found
54 * @return array of hooks found.
56 function getHooksFromPath( $path ) {
58 if( $dh = opendir($path) ) {
59 while(($file = readdir($dh)) !== false) {
60 if( filetype($path.$file) == 'file' ) {
61 $hooks = array_merge( $hooks, getHooksFromFile($path.$file) );
70 * Nicely output the array
71 * @param $msg A message to show before the value
72 * @param $arr An array
73 * @param $sort Boolean : wheter to sort the array (Default: true)
75 function printArray( $msg, $arr, $sort = true ) {
76 if($sort) asort($arr);
77 foreach($arr as $v) print "$msg: $v\n";
83 $documented = getHooksFromDoc($doc);
84 $potential = getHooksFromPath($pathinc);
86 $todo = array_diff($potential, $documented);
87 $deprecated = array_diff($documented, $potential);
89 // let's show the results:
90 printArray('undocumented', $todo );
91 printArray('not found', $deprecated );