Updates findHooks.php for ContentHandler changes.
[lhc/web/wiklou.git] / maintenance / findHooks.php
index 9c9cc74..9ad4df4 100644 (file)
@@ -12,7 +12,7 @@
  *
  * Any instance of wfRunHooks that doesn't meet these parameters will be noted.
  *
- * Copyright © Ashar Voultoiz
+ * Copyright © Antoine Musso
  *
  * 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
  *
  * @file
  * @ingroup Maintenance
- * @author Ashar Voultoiz <hashar at free dot fr>
+ * @author Antoine Musso <hashar at free dot fr>
  */
 
-require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+require_once( __DIR__ . '/Maintenance.php' );
 
+/**
+ * Maintenance script that compares documented and actually present mismatches.
+ *
+ * @ingroup Maintenance
+ */
 class FindHooks extends Maintenance {
        public function __construct() {
                parent::__construct();
@@ -59,12 +64,15 @@ class FindHooks extends Maintenance {
                        $IP . '/includes/actions/',
                        $IP . '/includes/api/',
                        $IP . '/includes/cache/',
+                       $IP . '/includes/content/',
                        $IP . '/includes/context/',
                        $IP . '/includes/db/',
                        $IP . '/includes/diff/',
                        $IP . '/includes/filerepo/',
+                       $IP . '/includes/filerepo/file/',
                        $IP . '/includes/installer/',
                        $IP . '/includes/interwiki/',
+                       $IP . '/includes/logging/',
                        $IP . '/includes/media/',
                        $IP . '/includes/parser/',
                        $IP . '/includes/resourceloader/',
@@ -107,6 +115,29 @@ class FindHooks extends Maintenance {
         */
        private function getHooksFromDoc( $doc ) {
                if ( $this->hasOption( 'online' ) ) {
+                       return $this->getHooksFromOnlineDoc( );
+               } else {
+                       return $this->getHooksFromLocalDoc( $doc );
+               }
+       }
+
+       /**
+        * Get hooks from a local file (for example docs/hooks.txt)
+        * @param $doc string: filename to look in
+        * @return 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] );
+       }
+
+       /**
+        * Get hooks from www.mediawiki.org using the API
+        * @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 );
@@ -130,23 +161,17 @@ class FindHooks extends Maintenance {
                                }
                        }
                        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.
+        * @param $file string 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 );
+               preg_match_all( '/(?:wfRunHooks|Hooks\:\:run|ContentHandler\:\:runLegacyHooks)\(\s*([\'"])(.*?)\1/', $content, $m );
                return $m[2];
        }
 
@@ -171,7 +196,7 @@ class FindHooks extends Maintenance {
 
        /**
         * Get bad hooks (where the hook name could not be determined) from a PHP file
-        * @param $file Full filename to the PHP file.
+        * @param $file string Full filename to the PHP file.
         * @return array of bad wfRunHooks() lines
         */
        private function getBadHooksFromFile( $file ) {