summaryrefslogtreecommitdiff
path: root/maintenance/findhooks.php
diff options
context:
space:
mode:
Diffstat (limited to 'maintenance/findhooks.php')
-rw-r--r--maintenance/findhooks.php62
1 files changed, 40 insertions, 22 deletions
diff --git a/maintenance/findhooks.php b/maintenance/findhooks.php
index 8433571d..7a2ba53f 100644
--- a/maintenance/findhooks.php
+++ b/maintenance/findhooks.php
@@ -7,37 +7,56 @@
* - 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.
*
+ * 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.
*
- * @addtogroup Maintenance
+ * @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
*/
-
+
/** This is a command line script*/
include('commandLine.inc');
-
-
+
# GLOBALS
-
+
$doc = $IP . '/docs/hooks.txt';
-$pathinc = array( $IP.'/includes/', $IP.'/includes/api/', $IP.'/includes/filerepo/', $IP.'/languages/', $IP.'/maintenance/', $IP.'/skins/' );
-
+$pathinc = array(
+ $IP.'/',
+ $IP.'/includes/',
+ $IP.'/includes/api/',
+ $IP.'/includes/db/',
+ $IP.'/includes/filerepo/',
+ $IP.'/includes/parser/',
+ $IP.'/includes/specials/',
+ $IP.'/languages/',
+ $IP.'/maintenance/',
+ $IP.'/skins/',
+);
+
# FUNCTIONS
-
+
/**
* @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
* @param $file Full filename to the PHP file.
@@ -49,7 +68,7 @@ function getHooksFromFile( $file ) {
preg_match_all( '/wfRunHooks\(\s*([\'"])(.*?)\1/', $content, $m);
return $m[2];
}
-
+
/**
* Get hooks from the source code.
* @param $path Directory where the include files can be found
@@ -67,7 +86,7 @@ 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.
@@ -84,7 +103,7 @@ function getBadHooksFromFile( $file ) {
}
return $list;
}
-
+
/**
* Get bad hooks from the source code.
* @param $path Directory where the include files can be found
@@ -103,7 +122,7 @@ function getBadHooksFromPath( $path ) {
}
return $hooks;
}
-
+
/**
* Nicely output the array
* @param $msg A message to show before the value
@@ -114,10 +133,9 @@ function printArray( $msg, $arr, $sort = true ) {
if($sort) asort($arr);
foreach($arr as $v) echo "$msg: $v\n";
}
-
-
+
# MAIN
-
+
$documented = getHooksFromDoc($doc);
$potential = array();
$bad = array();
@@ -125,12 +143,12 @@ foreach( $pathinc as $dir ) {
$potential = array_merge( $potential, getHooksFromPath( $dir ) );
$bad = array_merge( $bad, 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:
printArray('undocumented', $todo );
printArray('not found', $deprecated );