Moved $wgQueryPages stuff out of the global scope and into a function
authorChad Horohoe <chadh@wikimedia.org>
Tue, 4 Feb 2014 19:50:11 +0000 (11:50 -0800)
committerChad Horohoe <chadh@wikimedia.org>
Tue, 18 Mar 2014 15:36:32 +0000 (08:36 -0700)
Change-Id: Ica034bdad89133bfce0b4238d62ed00865936644

RELEASE-NOTES-1.23
docs/hooks.txt
includes/QueryPage.php
includes/api/ApiQueryQueryPage.php
maintenance/updateSpecialPages.php
tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php

index 379b219..d140f05 100644 (file)
@@ -48,6 +48,8 @@ production.
   allows more than one value of $wgLocalInterwiki to be specified and
   understood by the parser. The value of $wgLocalInterwiki is automatically
   prepended to the start of this array.
+* $wgQueryPages has been removed. Query Pages should be added to by using the
+  wgQueryPages hook.
 
 === New features in 1.23 ===
 * ResourceLoader can utilize the Web Storage API to cache modules client-side.
index e944d55..e4037e6 100644 (file)
@@ -2916,9 +2916,9 @@ run a MediaWiki cli script.
 &$options: Associative array of options, may contain the 'php' and 'wrapper'
   keys
 
-'wgQueryPages': Called when initialising $wgQueryPages, use this to add new
-query pages to be updated with maintenance/updateSpecialPages.php.
-$query: $wgQueryPages itself
+'wgQueryPages': Called when initialising list of QueryPage subclasses, use this
+to add new query pages to be updated with maintenance/updateSpecialPages.php.
+$qp: The list of QueryPages
 
 'XmlDumpWriterOpenPage': Called at the end of XmlDumpWriter::openPage, to allow
 extra metadata to be added.
index bb6a0c3..b808408 100644 (file)
  * @ingroup SpecialPage
  */
 
-/**
- * List of query page classes and their associated special pages,
- * for periodic updates.
- *
- * DO NOT CHANGE THIS LIST without testing that
- * maintenance/updateSpecialPages.php still works.
- */
-global $wgQueryPages; // not redundant
-$wgQueryPages = array(
-//         QueryPage subclass, Special page name, Limit (false for none, none for the default)
-// ----------------------------------------------------------------------------
-       array( 'AncientPagesPage', 'Ancientpages' ),
-       array( 'BrokenRedirectsPage', 'BrokenRedirects' ),
-       array( 'DeadendPagesPage', 'Deadendpages' ),
-       array( 'DoubleRedirectsPage', 'DoubleRedirects' ),
-       array( 'FileDuplicateSearchPage', 'FileDuplicateSearch' ),
-       array( 'LinkSearchPage', 'LinkSearch' ),
-       array( 'ListredirectsPage', 'Listredirects' ),
-       array( 'LonelyPagesPage', 'Lonelypages' ),
-       array( 'LongPagesPage', 'Longpages' ),
-       array( 'MIMEsearchPage', 'MIMEsearch' ),
-       array( 'MostcategoriesPage', 'Mostcategories' ),
-       array( 'MostimagesPage', 'Mostimages' ),
-       array( 'MostinterwikisPage', 'Mostinterwikis' ),
-       array( 'MostlinkedCategoriesPage', 'Mostlinkedcategories' ),
-       array( 'MostlinkedtemplatesPage', 'Mostlinkedtemplates' ),
-       array( 'MostlinkedPage', 'Mostlinked' ),
-       array( 'MostrevisionsPage', 'Mostrevisions' ),
-       array( 'FewestrevisionsPage', 'Fewestrevisions' ),
-       array( 'ShortPagesPage', 'Shortpages' ),
-       array( 'UncategorizedCategoriesPage', 'Uncategorizedcategories' ),
-       array( 'UncategorizedPagesPage', 'Uncategorizedpages' ),
-       array( 'UncategorizedImagesPage', 'Uncategorizedimages' ),
-       array( 'UncategorizedTemplatesPage', 'Uncategorizedtemplates' ),
-       array( 'UnusedCategoriesPage', 'Unusedcategories' ),
-       array( 'UnusedimagesPage', 'Unusedimages' ),
-       array( 'WantedCategoriesPage', 'Wantedcategories' ),
-       array( 'WantedFilesPage', 'Wantedfiles' ),
-       array( 'WantedPagesPage', 'Wantedpages' ),
-       array( 'WantedTemplatesPage', 'Wantedtemplates' ),
-       array( 'UnwatchedPagesPage', 'Unwatchedpages' ),
-       array( 'UnusedtemplatesPage', 'Unusedtemplates' ),
-       array( 'WithoutInterwikiPage', 'Withoutinterwiki' ),
-);
-wfRunHooks( 'wgQueryPages', array( &$wgQueryPages ) );
-
-global $wgDisableCounters;
-if ( !$wgDisableCounters ) {
-       $wgQueryPages[] = array( 'PopularPagesPage', 'Popularpages' );
-}
-
 /**
  * This is a class for doing query pages; since they're almost all the same,
  * we factor out some of the functionality into a superclass, and let
@@ -108,6 +57,64 @@ abstract class QueryPage extends SpecialPage {
         */
        protected $shownavigation = true;
 
+       /**
+        * Get a list of query page classes and their associated special pages,
+        * for periodic updates.
+        *
+        * DO NOT CHANGE THIS LIST without testing that
+        * maintenance/updateSpecialPages.php still works.
+        * @return array
+        */
+       public static function getPages() {
+               global $wgDisableCounters;
+               static $qp = null;
+
+               if ( $qp === null ) {
+                       // QueryPage subclass, Special page name
+                       $qp = array(
+                               array( 'AncientPagesPage', 'Ancientpages' ),
+                               array( 'BrokenRedirectsPage', 'BrokenRedirects' ),
+                               array( 'DeadendPagesPage', 'Deadendpages' ),
+                               array( 'DoubleRedirectsPage', 'DoubleRedirects' ),
+                               array( 'FileDuplicateSearchPage', 'FileDuplicateSearch' ),
+                               array( 'LinkSearchPage', 'LinkSearch' ),
+                               array( 'ListredirectsPage', 'Listredirects' ),
+                               array( 'LonelyPagesPage', 'Lonelypages' ),
+                               array( 'LongPagesPage', 'Longpages' ),
+                               array( 'MIMEsearchPage', 'MIMEsearch' ),
+                               array( 'MostcategoriesPage', 'Mostcategories' ),
+                               array( 'MostimagesPage', 'Mostimages' ),
+                               array( 'MostinterwikisPage', 'Mostinterwikis' ),
+                               array( 'MostlinkedCategoriesPage', 'Mostlinkedcategories' ),
+                               array( 'MostlinkedtemplatesPage', 'Mostlinkedtemplates' ),
+                               array( 'MostlinkedPage', 'Mostlinked' ),
+                               array( 'MostrevisionsPage', 'Mostrevisions' ),
+                               array( 'FewestrevisionsPage', 'Fewestrevisions' ),
+                               array( 'ShortPagesPage', 'Shortpages' ),
+                               array( 'UncategorizedCategoriesPage', 'Uncategorizedcategories' ),
+                               array( 'UncategorizedPagesPage', 'Uncategorizedpages' ),
+                               array( 'UncategorizedImagesPage', 'Uncategorizedimages' ),
+                               array( 'UncategorizedTemplatesPage', 'Uncategorizedtemplates' ),
+                               array( 'UnusedCategoriesPage', 'Unusedcategories' ),
+                               array( 'UnusedimagesPage', 'Unusedimages' ),
+                               array( 'WantedCategoriesPage', 'Wantedcategories' ),
+                               array( 'WantedFilesPage', 'Wantedfiles' ),
+                               array( 'WantedPagesPage', 'Wantedpages' ),
+                               array( 'WantedTemplatesPage', 'Wantedtemplates' ),
+                               array( 'UnwatchedPagesPage', 'Unwatchedpages' ),
+                               array( 'UnusedtemplatesPage', 'Unusedtemplates' ),
+                               array( 'WithoutInterwikiPage', 'Withoutinterwiki' ),
+                       );
+                       wfRunHooks( 'wgQueryPages', array( &$qp ) );
+
+                       if ( !$wgDisableCounters ) {
+                               $qp[] = array( 'PopularPagesPage', 'Popularpages' );
+                       }
+               }
+
+               return $qp;
+       }
+
        /**
         * A mutator for $this->listoutput;
         *
index 2fc2676..b13f797 100644 (file)
@@ -34,15 +34,10 @@ class ApiQueryQueryPage extends ApiQueryGeneratorBase {
 
        public function __construct( $query, $moduleName ) {
                parent::__construct( $query, $moduleName, 'qp' );
-               // We need to do this to make sure $wgQueryPages is set up
-               // This SUCKS
-               global $IP;
-               require_once "$IP/includes/QueryPage.php";
-
                // Build mapping from special page names to QueryPage classes
-               global $wgQueryPages, $wgAPIUselessQueryPages;
+               global $wgAPIUselessQueryPages;
                $this->qpMap = array();
-               foreach ( $wgQueryPages as $page ) {
+               foreach ( QueryPage::getPages() as $page ) {
                        if ( !in_array( $page[1], $wgAPIUselessQueryPages ) ) {
                                $this->qpMap[$page[1]] = $page[0];
                        }
index c5ade2d..12c4a2c 100644 (file)
@@ -40,16 +40,13 @@ class UpdateSpecialPages extends Maintenance {
        }
 
        public function execute() {
-               global $IP, $wgQueryPages, $wgQueryCacheLimit, $wgDisableQueryPageUpdate;
+               global $wgQueryCacheLimit, $wgDisableQueryPageUpdate;
 
                $dbw = wfGetDB( DB_MASTER );
 
                $this->doSpecialPageCacheUpdates( $dbw );
 
-               // This is needed to initialise $wgQueryPages
-               require_once "$IP/includes/QueryPage.php";
-
-               foreach ( $wgQueryPages as $page ) {
+               foreach ( QueryPage::getPages() as $page ) {
                        list( $class, $special ) = $page;
                        $limit = isset( $page[2] ) ? $page[2] : null;
 
index ba845eb..39462b4 100644 (file)
@@ -8,13 +8,6 @@
  * @group Database
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       die( 1 );
-}
-
-global $IP;
-require_once "$IP/includes/QueryPage.php"; // Needed to populate $wgQueryPages
-
 /**
  * @covers QueryPage<extended>
  */
@@ -41,8 +34,7 @@ class QueryAllSpecialPagesTest extends MediaWikiTestCase {
        function __construct() {
                parent::__construct();
 
-               global $wgQueryPages;
-               foreach ( $wgQueryPages as $page ) {
+               foreach ( QueryPage::getPages() as $page ) {
                        $class = $page[0];
                        if ( !in_array( $class, $this->manualTest ) ) {
                                $this->queryPages[$class] = new $class;