X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FfindHooks.php;h=86c01f4c409cad7f855b32eaac1bcc6b481e18b7;hb=17b631a1719a70a9490740a3ceb58d4ca70cb333;hp=6d7de091c87d99e1f0c071cbedee994806302886;hpb=dc27e4cd0f74a09b95866de877011387c3f1b9e7;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/findHooks.php b/maintenance/findHooks.php index 6d7de091c8..86c01f4c40 100644 --- a/maintenance/findHooks.php +++ b/maintenance/findHooks.php @@ -142,14 +142,15 @@ class FindHooks extends Maintenance { /** * Get hooks from a local file (for example docs/hooks.txt) - * @param $doc string: filename to look in - * @return array of documented hooks + * @param string $doc filename to look in + * @return array Array of documented hooks */ private function getHooksFromLocalDoc( $doc ) { - $m = array(); - $content = file_get_contents( $doc ); - preg_match_all( "/\n'(.*?)':/", $content, $m ); - return array_unique( $m[1] ); + $m = array(); + $content = file_get_contents( $doc ); + preg_match_all( "/\n'(.*?)':/", $content, $m ); + + return array_unique( $m[1] ); } /** @@ -157,47 +158,59 @@ class FindHooks extends Maintenance { * @return array of documented hooks */ private function getHooksFromOnlineDoc() { - // 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; - } + // 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; - } + } + // 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 ); + } + + return array_diff( $allhooks, $removed ); } /** * Get hooks from a PHP file - * @param $file string Full filename to the PHP file. + * @param string $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|ContentHandler\:\:runLegacyHooks)\(\s*([\'"])(.*?)\1/', $content, $m ); + preg_match_all( + '/(?:wfRunHooks|Hooks\:\:run|ContentHandler\:\:runLegacyHooks)\(\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. + * @param string $path Directory where the include files can be found + * @return array Array of hooks found. */ private function getHooksFromPath( $path ) { $hooks = array(); @@ -210,13 +223,14 @@ class FindHooks extends Maintenance { } closedir( $dh ); } + return $hooks; } /** * Get bad hooks (where the hook name could not be determined) from a PHP file - * @param $file string Full filename to the PHP file. - * @return array of bad wfRunHooks() lines + * @param string $file Full filename to the PHP file. + * @return array Array of bad wfRunHooks() lines */ private function getBadHooksFromFile( $file ) { $content = file_get_contents( $file ); @@ -227,13 +241,14 @@ class FindHooks extends Maintenance { foreach ( $m[0] as $match ) { $list[] = $match . "(" . $file . ")"; } + return $list; } /** * Get bad hooks from the source code. - * @param $path Directory where the include files can be found - * @return array of bad wfRunHooks() lines + * @param string $path Directory where the include files can be found + * @return array Array of bad wfRunHooks() lines */ private function getBadHooksFromPath( $path ) { $hooks = array(); @@ -247,14 +262,15 @@ class FindHooks extends Maintenance { } 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) + * @param string $msg A message to show before the value + * @param array $arr + * @param bool $sort Whether to sort the array (Default: true) */ private function printArray( $msg, $arr, $sort = true ) { if ( $sort ) {