Rewrite importUseModWiki to subclass maintenance, general cleanup, etc. Also fixing...
[lhc/web/wiklou.git] / maintenance / findhooks.php
index 6b36b26..5c180be 100644 (file)
@@ -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
  * 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' );
@@ -39,8 +39,8 @@ 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' );
+               $this->mDescription = 'Find hooks that are undocumented, missing, or just plain wrong';
+               $this->addOption( 'online', 'Check against MediaWiki.org hook documentation' );
        }
 
        public function getDbType() {
@@ -60,13 +60,18 @@ class FindHooks extends Maintenance {
                        $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 . '/tests/',
+                       $IP . '/tests/parser/',
+                       $IP . '/tests/phpunit/suites/',
                        $IP . '/skins/',
                );
 
@@ -74,23 +79,25 @@ class FindHooks extends Maintenance {
                        $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
+        * Get the hook documentation, either locally or from MediaWiki.org
         * @return array of documented hooks
         */
        private function getHooksFromDoc( $doc ) {
@@ -134,7 +141,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|Hooks\:\:run)\(\s*([\'"])(.*?)\1/', $content, $m );
                return $m[2];
        }
 
@@ -145,7 +152,8 @@ class FindHooks extends Maintenance {
         */
        private function getHooksFromPath( $path ) {
                $hooks = array();
-               if ( $dh = opendir( $path ) ) {
+               $dh = opendir( $path );
+               if ( $dh ) {
                        while ( ( $file = readdir( $dh ) ) !== false ) {
                                if ( filetype( $path . $file ) == 'file' ) {
                                        $hooks = array_merge( $hooks, $this->getHooksFromFile( $path . $file ) );
@@ -180,7 +188,8 @@ class FindHooks extends Maintenance {
         */
        private function getBadHooksFromPath( $path ) {
                $hooks = array();
-               if ( $dh = opendir( $path ) ) {
+               $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__ ) {
@@ -194,15 +203,19 @@ class FindHooks extends Maintenance {
 
        /**
         * Nicely output the array
-        * @param $msg A message to show before the value
-        * @param $arr An array
-        * @param $sort Boolean : wheter to sort the array (Default: true)
+        * @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" );
+               if ( $sort ) {
+                       asort( $arr );
+               }
+               foreach ( $arr as $v ) {
+                       $this->output( "$msg: $v\n" );
+               }
        }
 }
 
-$maintClass = "FindHooks";
-require_once( DO_MAINTENANCE );
+$maintClass = 'FindHooks';
+require_once( RUN_MAINTENANCE_IF_MAIN );