X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2Ffindhooks.php;h=d7cad253c642705af042f5e444188e157ffe1cab;hb=6c44caccec40b572da8be1091d6b55a4434eb5f2;hp=97e6c57d04f8e3384cbdf832ff65ee664385152c;hpb=a78478c449cc53d9459ed669423e1e4d7d206f6f;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/findhooks.php b/maintenance/findhooks.php index 97e6c57d04..d7cad253c6 100644 --- a/maintenance/findhooks.php +++ b/maintenance/findhooks.php @@ -7,8 +7,13 @@ * - hooks names in hooks.txt are at the beginning of a line and single quoted. * - hooks names in code are the first parameter of wfRunHooks. * - * @package MediaWiki - * @subpackage Maintenance + * if --online option is passed, the script will compare the hooks in the code + * with the ones at http://www.mediawiki.org/wiki/Manual:Hooks + * + * Any instance of wfRunHooks that doesn't meet these parameters will be noted. + * + * @file + * @ingroup Maintenance * * @author Ashar Voultoiz * @copyright Copyright © Ashar voultoiz @@ -18,12 +23,22 @@ /** This is a command line script*/ include('commandLine.inc'); - # GLOBALS $doc = $IP . '/docs/hooks.txt'; -$pathinc = $IP . '/includes/'; - +$pathinc = array( + $IP.'/', + $IP.'/includes/', + $IP.'/includes/api/', + $IP.'/includes/db/', + $IP.'/includes/diff/', + $IP.'/includes/filerepo/', + $IP.'/includes/parser/', + $IP.'/includes/specials/', + $IP.'/languages/', + $IP.'/maintenance/', + $IP.'/skins/', +); # FUNCTIONS @@ -31,23 +46,28 @@ $pathinc = $IP . '/includes/'; * @return array of documented hooks */ function getHooksFromDoc() { - global $doc; - $content = file_get_contents( $doc ); + global $doc, $options; $m = array(); - preg_match_all( "/\n'(.*?)'/", $content, $m); - return $m[1]; + if( isset( $options['online'] ) ){ + $content = Http::get( 'http://www.mediawiki.org/w/index.php?title=Manual:Hooks&action=raw' ); + preg_match_all( '/\[\[\/([a-zA-Z0-9-_:]+)\|/', $content, $m ); + } else { + $content = file_get_contents( $doc ); + preg_match_all( "/\n'(.*?)'/", $content, $m ); + } + return array_unique( $m[1] ); } /** - * Get hooks from a php file + * Get hooks from a PHP file * @param $file Full filename to the PHP file. * @return array of hooks found. */ function getHooksFromFile( $file ) { $content = file_get_contents( $file ); $m = array(); - preg_match_all( "/wfRunHooks\(\s*\'(.*?)\'/", $content, $m); - return $m[1]; + preg_match_all( '/wfRunHooks\(\s*([\'"])(.*?)\1/', $content, $m); + return $m[2]; } /** @@ -68,6 +88,42 @@ function getHooksFromPath( $path ) { return $hooks; } +/** + * Get bad hooks (where the hook name could not be determined) from a PHP file + * @param $file Full filename to the PHP file. + * @return array of bad wfRunHooks() lines + */ +function getBadHooksFromFile( $file ) { + $content = file_get_contents( $file ); + $m = array(); + # We want to skip the "function wfRunHooks()" one. :) + preg_match_all( '/(? +printArray('unclear hook calls', $bad ); + +if ( count( $todo ) == 0 && count( $deprecated ) == 0 && count( $bad ) == 0 ) + echo "Looks good!\n"; \ No newline at end of file