Merge "Implement FauxRequest::getRequestURL() - needed for MF tests"
[lhc/web/wiklou.git] / maintenance / findHooks.php
index 074388f..66e8da0 100644 (file)
@@ -99,6 +99,7 @@ class FindHooks extends Maintenance {
                        $IP . '/includes/revisiondelete/',
                        $IP . '/includes/search/',
                        $IP . '/includes/site/',
+                       $IP . '/includes/skins/',
                        $IP . '/includes/specialpage/',
                        $IP . '/includes/specials/',
                        $IP . '/includes/upload/',
@@ -109,9 +110,6 @@ class FindHooks extends Maintenance {
                        $IP . '/tests/',
                        $IP . '/tests/parser/',
                        $IP . '/tests/phpunit/suites/',
-                       $IP . '/skins/',
-                       $IP . '/skins/MonoBook/',
-                       $IP . '/skins/Vector/',
                );
 
                foreach ( $pathinc as $dir ) {
@@ -136,7 +134,8 @@ class FindHooks extends Maintenance {
 
        /**
         * Get the hook documentation, either locally or from MediaWiki.org
-        * @return Array of documented hooks
+        * @param string $doc
+        * @return array Array of documented hooks
         */
        private function getHooksFromDoc( $doc ) {
                if ( $this->hasOption( 'online' ) ) {
@@ -149,7 +148,7 @@ class FindHooks extends Maintenance {
        /**
         * Get hooks from a local file (for example docs/hooks.txt)
         * @param string $doc Filename to look in
-        * @return Array of documented hooks
+        * @return array Array of documented hooks
         */
        private function getHooksFromLocalDoc( $doc ) {
                $m = array();
@@ -161,45 +160,48 @@ class FindHooks extends Maintenance {
 
        /**
         * Get hooks from www.mediawiki.org using the API
-        * @return Array of documented hooks
+        * @return array 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'
+               $allhooks = $this->getHooksFromOnlineDocCategory( 'MediaWiki_hooks' );
+               $removed = $this->getHooksFromOnlineDocCategory( 'Removed_hooks' );
+               return array_diff( $allhooks, $removed );
+       }
+
+       /**
+        * @param string $title
+        * @return array
+        */
+       private function getHooksFromOnlineDocCategory( $title ) {
+               $params = array(
+                       'action' => 'query',
+                       'list' => 'categorymembers',
+                       'cmtitle' => "Category:$title",
+                       'cmlimit' => 500,
+                       'format' => 'json',
+                       'continue' => '',
                );
-               $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;
+
+               $retval = array();
+               while ( true ) {
+                       $json = Http::get( wfAppendQuery( 'http://www.mediawiki.org/w/api.php', $params ) );
+                       $data = FormatJson::decode( $json, true );
+                       foreach ( $data['query']['categorymembers'] as $page ) {
+                               if ( preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $m ) ) {
+                                       $retval[] = str_replace( ' ', '_', $m[1] );
+                               }
                        }
-               }
-               // 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;
+                       if ( !isset( $data['continue'] ) ) {
+                               return $retval;
                        }
+                       $params = array_replace( $params, $data['continue'] );
                }
-
-               return array_diff( $allhooks, $removed );
        }
 
        /**
         * Get hooks from a PHP file
         * @param string $file Full filename to the PHP file.
-        * @return Array of hooks found.
+        * @return array Array of hooks found
         */
        private function getHooksFromFile( $file ) {
                $content = file_get_contents( $file );
@@ -216,7 +218,7 @@ class FindHooks extends Maintenance {
        /**
         * Get hooks from the source code.
         * @param string $path Directory where the include files can be found
-        * @return Array of hooks found.
+        * @return array Array of hooks found
         */
        private function getHooksFromPath( $path ) {
                $hooks = array();
@@ -236,7 +238,7 @@ class FindHooks extends Maintenance {
        /**
         * Get bad hooks (where the hook name could not be determined) from a PHP file
         * @param string $file Full filename to the PHP file.
-        * @return Array of bad wfRunHooks() lines
+        * @return array Array of bad wfRunHooks() lines
         */
        private function getBadHooksFromFile( $file ) {
                $content = file_get_contents( $file );
@@ -254,7 +256,7 @@ class FindHooks extends Maintenance {
        /**
         * Get bad hooks from the source code.
         * @param string $path Directory where the include files can be found
-        * @return Array of bad wfRunHooks() lines
+        * @return array Array of bad wfRunHooks() lines
         */
        private function getBadHooksFromPath( $path ) {
                $hooks = array();