summaryrefslogtreecommitdiff
path: root/maintenance/findhooks.php
diff options
context:
space:
mode:
Diffstat (limited to 'maintenance/findhooks.php')
-rw-r--r--maintenance/findhooks.php103
1 files changed, 55 insertions, 48 deletions
diff --git a/maintenance/findhooks.php b/maintenance/findhooks.php
index 13236b6b..04a5faef 100644
--- a/maintenance/findhooks.php
+++ b/maintenance/findhooks.php
@@ -2,7 +2,7 @@
/**
* Simple script that try to find documented hook and hooks actually
* in the code and show what's missing.
- *
+ *
* This script assumes that:
* - 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.
@@ -12,6 +12,8 @@
*
* Any instance of wfRunHooks that doesn't meet these parameters will be noted.
*
+ * Copyright © Ashar Voultoiz
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -27,14 +29,12 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
+ * @file
* @ingroup Maintenance
- *
- * @author Ashar Voultoiz <hashar@altern.org>
- * @copyright Copyright © Ashar voultoiz
- * @license http://www.gnu.org/copyleft/gpl.html GNU General Public Licence 2.0 or later
+ * @author Ashar Voultoiz <hashar at free dot fr>
*/
-require_once( dirname(__FILE__) . '/Maintenance.php' );
+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
class FindHooks extends Maintenance {
public function __construct() {
@@ -54,37 +54,42 @@ class FindHooks extends Maintenance {
$potential = array();
$bad = array();
$pathinc = array(
- $IP.'/',
- $IP.'/includes/',
- $IP.'/includes/api/',
- $IP.'/includes/db/',
- $IP.'/includes/diff/',
- $IP.'/includes/filerepo/',
- $IP.'/includes/parser/',
- $IP.'/includes/search/',
- $IP.'/includes/specials/',
- $IP.'/includes/upload/',
- $IP.'/languages/',
- $IP.'/maintenance/',
- $IP.'/skins/',
+ $IP . '/',
+ $IP . '/includes/',
+ $IP . '/includes/api/',
+ $IP . '/includes/db/',
+ $IP . '/includes/diff/',
+ $IP . '/includes/filerepo/',
+ $IP . '/includes/installer/',
+ $IP . '/includes/parser/',
+ $IP . '/includes/resourceloader/',
+ $IP . '/includes/revisiondelete/',
+ $IP . '/includes/search/',
+ $IP . '/includes/specials/',
+ $IP . '/includes/upload/',
+ $IP . '/languages/',
+ $IP . '/maintenance/',
+ $IP . '/maintenance/tests/',
+ $IP . '/maintenance/tests/parser/',
+ $IP . '/skins/',
);
- foreach( $pathinc as $dir ) {
+ 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->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" );
}
@@ -93,14 +98,14 @@ class FindHooks extends Maintenance {
* @return array of documented hooks
*/
private function getHooksFromDoc( $doc ) {
- if( $this->hasOption( 'online' ) ){
+ 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 ) {
+ foreach ( $allhookdata['query']['categorymembers'] as $page ) {
$found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches );
- if( $found ) {
+ if ( $found ) {
$hook = str_replace( ' ', '_', $matches[1] );
$allhooks[] = $hook;
}
@@ -109,9 +114,9 @@ class FindHooks extends Maintenance {
$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 ) {
+ foreach ( $oldhookdata['query']['categorymembers'] as $page ) {
$found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches );
- if( $found ) {
+ if ( $found ) {
$hook = str_replace( ' ', '_', $matches[1] );
$removed[] = $hook;
}
@@ -133,7 +138,7 @@ class FindHooks extends Maintenance {
private function getHooksFromFile( $file ) {
$content = file_get_contents( $file );
$m = array();
- preg_match_all( '/wfRunHooks\(\s*([\'"])(.*?)\1/', $content, $m);
+ preg_match_all( '/wfRunHooks\(\s*([\'"])(.*?)\1/', $content, $m );
return $m[2];
}
@@ -144,13 +149,14 @@ class FindHooks extends Maintenance {
*/
private function getHooksFromPath( $path ) {
$hooks = array();
- if( $dh = opendir($path) ) {
- while(($file = readdir($dh)) !== false) {
- if( filetype($path.$file) == 'file' ) {
- $hooks = array_merge( $hooks, $this->getHooksFromFile($path.$file) );
+ $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);
+ closedir( $dh );
}
return $hooks;
}
@@ -164,9 +170,9 @@ class FindHooks extends Maintenance {
$content = file_get_contents( $file );
$m = array();
# We want to skip the "function wfRunHooks()" one. :)
- preg_match_all( '/(?<!function )wfRunHooks\(\s*[^\s\'"].*/', $content, $m);
+ preg_match_all( '/(?<!function )wfRunHooks\(\s*[^\s\'"].*/', $content, $m );
$list = array();
- foreach( $m[0] as $match ){
+ foreach ( $m[0] as $match ) {
$list[] = $match . "(" . $file . ")";
}
return $list;
@@ -179,14 +185,15 @@ class FindHooks extends Maintenance {
*/
private function getBadHooksFromPath( $path ) {
$hooks = array();
- if( $dh = opendir($path) ) {
- while(($file = readdir($dh)) !== false) {
+ $dh = opendir( $path );
+ if ( $dh ) {
+ while ( ( $file = readdir( $dh ) ) !== false ) {
# We don't want to read this file as it contains bad calls to wfRunHooks()
- if( filetype( $path.$file ) == 'file' && !$path.$file == __FILE__ ) {
- $hooks = array_merge( $hooks, $this->getBadHooksFromFile($path.$file) );
+ if ( filetype( $path . $file ) == 'file' && !$path . $file == __FILE__ ) {
+ $hooks = array_merge( $hooks, $this->getBadHooksFromFile( $path . $file ) );
}
}
- closedir($dh);
+ closedir( $dh );
}
return $hooks;
}
@@ -198,10 +205,10 @@ class FindHooks extends Maintenance {
* @param $sort Boolean : wheter 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" );
+ if ( $sort ) asort( $arr );
+ foreach ( $arr as $v ) $this->output( "$msg: $v\n" );
}
}
$maintClass = "FindHooks";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );