00001 <?php
00024 require('commandLine.inc');
00025 # GLOBALS
00026
00027 $doc = $IP . '/docs/hooks.txt';
00028 $pathinc = array(
00029 $IP.'/',
00030 $IP.'/includes/',
00031 $IP.'/includes/api/',
00032 $IP.'/includes/db/',
00033 $IP.'/includes/diff/',
00034 $IP.'/includes/filerepo/',
00035 $IP.'/includes/parser/',
00036 $IP.'/includes/specials/',
00037 $IP.'/languages/',
00038 $IP.'/maintenance/',
00039 $IP.'/skins/',
00040 );
00041
00042 # FUNCTIONS
00043
00047 function getHooksFromDoc() {
00048 global $doc, $options;
00049 $m = array();
00050 if( isset( $options['online'] ) ){
00051 $content = Http::get( 'http://www.mediawiki.org/w/index.php?title=Manual:Hooks&action=raw' );
00052 preg_match_all( '/\[\[\/([a-zA-Z0-9-_:]+)\|/', $content, $m );
00053 } else {
00054 $content = file_get_contents( $doc );
00055 preg_match_all( "/\n'(.*?)'/", $content, $m );
00056 }
00057 return array_unique( $m[1] );
00058 }
00059
00065 function getHooksFromFile( $file ) {
00066 $content = file_get_contents( $file );
00067 $m = array();
00068 preg_match_all( '/wfRunHooks\(\s*([\'"])(.*?)\1/', $content, $m);
00069 return $m[2];
00070 }
00071
00077 function getHooksFromPath( $path ) {
00078 $hooks = array();
00079 if( $dh = opendir($path) ) {
00080 while(($file = readdir($dh)) !== false) {
00081 if( filetype($path.$file) == 'file' ) {
00082 $hooks = array_merge( $hooks, getHooksFromFile($path.$file) );
00083 }
00084 }
00085 closedir($dh);
00086 }
00087 return $hooks;
00088 }
00089
00095 function getBadHooksFromFile( $file ) {
00096 $content = file_get_contents( $file );
00097 $m = array();
00098 # We want to skip the "function wfRunHooks()" one. :)
00099 preg_match_all( '/(?<!function )wfRunHooks\(\s*[^\s\'"].*/', $content, $m);
00100 $list = array();
00101 foreach( $m[0] as $match ){
00102 $list[] = $match . "(" . $file . ")";
00103 }
00104 return $list;
00105 }
00106
00112 function getBadHooksFromPath( $path ) {
00113 $hooks = array();
00114 if( $dh = opendir($path) ) {
00115 while(($file = readdir($dh)) !== false) {
00116 # We don't want to read this file as it contains bad calls to wfRunHooks()
00117 if( filetype( $path.$file ) == 'file' && !$path.$file == __FILE__ ) {
00118 $hooks = array_merge( $hooks, getBadHooksFromFile($path.$file) );
00119 }
00120 }
00121 closedir($dh);
00122 }
00123 return $hooks;
00124 }
00125
00132 function printArray( $msg, $arr, $sort = true ) {
00133 if($sort) asort($arr);
00134 foreach($arr as $v) echo "$msg: $v\n";
00135 }
00136
00137 # MAIN
00138
00139 $documented = getHooksFromDoc($doc);
00140 $potential = array();
00141 $bad = array();
00142 foreach( $pathinc as $dir ) {
00143 $potential = array_merge( $potential, getHooksFromPath( $dir ) );
00144 $bad = array_merge( $bad, getBadHooksFromPath( $dir ) );
00145 }
00146
00147 $potential = array_unique( $potential );
00148 $bad = array_unique( $bad );
00149 $todo = array_diff( $potential, $documented );
00150 $deprecated = array_diff( $documented, $potential );
00151
00152
00153 printArray('undocumented', $todo );
00154 printArray('not found', $deprecated );
00155 printArray('unclear hook calls', $bad );
00156
00157 if ( count( $todo ) == 0 && count( $deprecated ) == 0 && count( $bad ) == 0 )
00158 echo "Looks good!\n";