From: Chad Horohoe Date: Wed, 15 Jun 2011 01:34:23 +0000 (+0000) Subject: Use camelCase, as pointed out by siebrand on r89731 X-Git-Tag: 1.31.0-rc.0~29523 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=d852179c93d7bc02e3b6802b5fdc90ead7d5aeea;p=lhc%2Fweb%2Fwiklou.git Use camelCase, as pointed out by siebrand on r89731 --- diff --git a/maintenance/findHooks.php b/maintenance/findHooks.php new file mode 100644 index 0000000000..5996fd3a5b --- /dev/null +++ b/maintenance/findHooks.php @@ -0,0 +1,225 @@ + + */ + +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); + +class FindHooks extends Maintenance { + public function __construct() { + parent::__construct(); + $this->mDescription = 'Find hooks that are undocumented, missing, or just plain wrong'; + $this->addOption( 'online', 'Check against MediaWiki.org hook documentation' ); + } + + public function getDbType() { + return Maintenance::DB_NONE; + } + + public function execute() { + global $IP; + + $documented = $this->getHooksFromDoc( $IP . '/docs/hooks.txt' ); + $potential = array(); + $bad = array(); + $pathinc = array( + $IP . '/', + $IP . '/includes/', + $IP . '/includes/actions/', + $IP . '/includes/api/', + $IP . '/includes/cache/', + $IP . '/includes/db/', + $IP . '/includes/diff/', + $IP . '/includes/filerepo/', + $IP . '/includes/installer/', + $IP . '/includes/interwiki/', + $IP . '/includes/media/', + $IP . '/includes/parser/', + $IP . '/includes/resourceloader/', + $IP . '/includes/revisiondelete/', + $IP . '/includes/search/', + $IP . '/includes/specials/', + $IP . '/includes/upload/', + $IP . '/languages/', + $IP . '/maintenance/', + $IP . '/tests/', + $IP . '/tests/parser/', + $IP . '/tests/phpunit/suites/', + $IP . '/skins/', + ); + + foreach ( $pathinc as $dir ) { + $potential = array_merge( $potential, $this->getHooksFromPath( $dir ) ); + $bad = array_merge( $bad, $this->getBadHooksFromPath( $dir ) ); + } + + $potential = array_unique( $potential ); + $bad = array_unique( $bad ); + $todo = array_diff( $potential, $documented ); + $deprecated = array_diff( $documented, $potential ); + + // let's show the results: + $this->printArray( 'Undocumented', $todo ); + $this->printArray( 'Documented and not found', $deprecated ); + $this->printArray( 'Unclear hook calls', $bad ); + + if ( count( $todo ) == 0 && count( $deprecated ) == 0 && count( $bad ) == 0 ) + { + $this->output( "Looks good!\n" ); + } + } + + /** + * Get the hook documentation, either locally or from MediaWiki.org + * @return array of documented hooks + */ + private function getHooksFromDoc( $doc ) { + if ( $this->hasOption( 'online' ) ) { + // All hooks + $allhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:MediaWiki_hooks&cmlimit=500&format=php' ); + $allhookdata = unserialize( $allhookdata ); + $allhooks = array(); + foreach ( $allhookdata['query']['categorymembers'] as $page ) { + $found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches ); + if ( $found ) { + $hook = str_replace( ' ', '_', $matches[1] ); + $allhooks[] = $hook; + } + } + // Removed hooks + $oldhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Removed_hooks&cmlimit=500&format=php' ); + $oldhookdata = unserialize( $oldhookdata ); + $removed = array(); + foreach ( $oldhookdata['query']['categorymembers'] as $page ) { + $found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches ); + if ( $found ) { + $hook = str_replace( ' ', '_', $matches[1] ); + $removed[] = $hook; + } + } + return array_diff( $allhooks, $removed ); + } else { + $m = array(); + $content = file_get_contents( $doc ); + preg_match_all( "/\n'(.*?)'/", $content, $m ); + return array_unique( $m[1] ); + } + } + + /** + * Get hooks from a PHP file + * @param $file Full filename to the PHP file. + * @return array of hooks found. + */ + private function getHooksFromFile( $file ) { + $content = file_get_contents( $file ); + $m = array(); + preg_match_all( '/(?:wfRunHooks|Hooks\:\:run)\(\s*([\'"])(.*?)\1/', $content, $m ); + return $m[2]; + } + + /** + * Get hooks from the source code. + * @param $path Directory where the include files can be found + * @return array of hooks found. + */ + private function getHooksFromPath( $path ) { + $hooks = array(); + $dh = opendir( $path ); + if ( $dh ) { + while ( ( $file = readdir( $dh ) ) !== false ) { + if ( filetype( $path . $file ) == 'file' ) { + $hooks = array_merge( $hooks, $this->getHooksFromFile( $path . $file ) ); + } + } + closedir( $dh ); + } + 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 + */ + private function getBadHooksFromFile( $file ) { + $content = file_get_contents( $file ); + $m = array(); + # We want to skip the "function wfRunHooks()" one. :) + preg_match_all( '/(?getBadHooksFromFile( $path . $file ) ); + } + } + closedir( $dh ); + } + return $hooks; + } + + /** + * Nicely output the array + * @param $msg String: a message to show before the value + * @param $arr Array: an array + * @param $sort Boolean: whether to sort the array (Default: true) + */ + private function printArray( $msg, $arr, $sort = true ) { + if ( $sort ) { + asort( $arr ); + } + foreach ( $arr as $v ) { + $this->output( "$msg: $v\n" ); + } + } +} + +$maintClass = 'FindHooks'; +require_once( RUN_MAINTENANCE_IF_MAIN ); diff --git a/maintenance/findhooks.php b/maintenance/findhooks.php deleted file mode 100644 index 5996fd3a5b..0000000000 --- a/maintenance/findhooks.php +++ /dev/null @@ -1,225 +0,0 @@ - - */ - -require_once( dirname( __FILE__ ) . '/Maintenance.php' ); - -class FindHooks extends Maintenance { - public function __construct() { - parent::__construct(); - $this->mDescription = 'Find hooks that are undocumented, missing, or just plain wrong'; - $this->addOption( 'online', 'Check against MediaWiki.org hook documentation' ); - } - - public function getDbType() { - return Maintenance::DB_NONE; - } - - public function execute() { - global $IP; - - $documented = $this->getHooksFromDoc( $IP . '/docs/hooks.txt' ); - $potential = array(); - $bad = array(); - $pathinc = array( - $IP . '/', - $IP . '/includes/', - $IP . '/includes/actions/', - $IP . '/includes/api/', - $IP . '/includes/cache/', - $IP . '/includes/db/', - $IP . '/includes/diff/', - $IP . '/includes/filerepo/', - $IP . '/includes/installer/', - $IP . '/includes/interwiki/', - $IP . '/includes/media/', - $IP . '/includes/parser/', - $IP . '/includes/resourceloader/', - $IP . '/includes/revisiondelete/', - $IP . '/includes/search/', - $IP . '/includes/specials/', - $IP . '/includes/upload/', - $IP . '/languages/', - $IP . '/maintenance/', - $IP . '/tests/', - $IP . '/tests/parser/', - $IP . '/tests/phpunit/suites/', - $IP . '/skins/', - ); - - foreach ( $pathinc as $dir ) { - $potential = array_merge( $potential, $this->getHooksFromPath( $dir ) ); - $bad = array_merge( $bad, $this->getBadHooksFromPath( $dir ) ); - } - - $potential = array_unique( $potential ); - $bad = array_unique( $bad ); - $todo = array_diff( $potential, $documented ); - $deprecated = array_diff( $documented, $potential ); - - // let's show the results: - $this->printArray( 'Undocumented', $todo ); - $this->printArray( 'Documented and not found', $deprecated ); - $this->printArray( 'Unclear hook calls', $bad ); - - if ( count( $todo ) == 0 && count( $deprecated ) == 0 && count( $bad ) == 0 ) - { - $this->output( "Looks good!\n" ); - } - } - - /** - * Get the hook documentation, either locally or from MediaWiki.org - * @return array of documented hooks - */ - private function getHooksFromDoc( $doc ) { - if ( $this->hasOption( 'online' ) ) { - // All hooks - $allhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:MediaWiki_hooks&cmlimit=500&format=php' ); - $allhookdata = unserialize( $allhookdata ); - $allhooks = array(); - foreach ( $allhookdata['query']['categorymembers'] as $page ) { - $found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches ); - if ( $found ) { - $hook = str_replace( ' ', '_', $matches[1] ); - $allhooks[] = $hook; - } - } - // Removed hooks - $oldhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Removed_hooks&cmlimit=500&format=php' ); - $oldhookdata = unserialize( $oldhookdata ); - $removed = array(); - foreach ( $oldhookdata['query']['categorymembers'] as $page ) { - $found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches ); - if ( $found ) { - $hook = str_replace( ' ', '_', $matches[1] ); - $removed[] = $hook; - } - } - return array_diff( $allhooks, $removed ); - } else { - $m = array(); - $content = file_get_contents( $doc ); - preg_match_all( "/\n'(.*?)'/", $content, $m ); - return array_unique( $m[1] ); - } - } - - /** - * Get hooks from a PHP file - * @param $file Full filename to the PHP file. - * @return array of hooks found. - */ - private function getHooksFromFile( $file ) { - $content = file_get_contents( $file ); - $m = array(); - preg_match_all( '/(?:wfRunHooks|Hooks\:\:run)\(\s*([\'"])(.*?)\1/', $content, $m ); - return $m[2]; - } - - /** - * Get hooks from the source code. - * @param $path Directory where the include files can be found - * @return array of hooks found. - */ - private function getHooksFromPath( $path ) { - $hooks = array(); - $dh = opendir( $path ); - if ( $dh ) { - while ( ( $file = readdir( $dh ) ) !== false ) { - if ( filetype( $path . $file ) == 'file' ) { - $hooks = array_merge( $hooks, $this->getHooksFromFile( $path . $file ) ); - } - } - closedir( $dh ); - } - 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 - */ - private function getBadHooksFromFile( $file ) { - $content = file_get_contents( $file ); - $m = array(); - # We want to skip the "function wfRunHooks()" one. :) - preg_match_all( '/(?getBadHooksFromFile( $path . $file ) ); - } - } - closedir( $dh ); - } - return $hooks; - } - - /** - * Nicely output the array - * @param $msg String: a message to show before the value - * @param $arr Array: an array - * @param $sort Boolean: whether to sort the array (Default: true) - */ - private function printArray( $msg, $arr, $sort = true ) { - if ( $sort ) { - asort( $arr ); - } - foreach ( $arr as $v ) { - $this->output( "$msg: $v\n" ); - } - } -} - -$maintClass = 'FindHooks'; -require_once( RUN_MAINTENANCE_IF_MAIN );