From f508561f7bde2f410055bfe1c602619cd8893fe9 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Tue, 4 Feb 2014 11:50:11 -0800 Subject: [PATCH] Moved $wgQueryPages stuff out of the global scope and into a function Change-Id: Ica034bdad89133bfce0b4238d62ed00865936644 --- RELEASE-NOTES-1.23 | 2 + docs/hooks.txt | 6 +- includes/QueryPage.php | 109 ++++++++++-------- includes/api/ApiQueryQueryPage.php | 9 +- maintenance/updateSpecialPages.php | 7 +- .../specials/QueryAllSpecialPagesTest.php | 10 +- 6 files changed, 68 insertions(+), 75 deletions(-) diff --git a/RELEASE-NOTES-1.23 b/RELEASE-NOTES-1.23 index 379b21973f..d140f05641 100644 --- a/RELEASE-NOTES-1.23 +++ b/RELEASE-NOTES-1.23 @@ -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. diff --git a/docs/hooks.txt b/docs/hooks.txt index e944d55c61..e4037e6a07 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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. diff --git a/includes/QueryPage.php b/includes/QueryPage.php index bb6a0c3ef0..b808408e6e 100644 --- a/includes/QueryPage.php +++ b/includes/QueryPage.php @@ -21,57 +21,6 @@ * @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; * diff --git a/includes/api/ApiQueryQueryPage.php b/includes/api/ApiQueryQueryPage.php index 2fc26760c6..b13f797209 100644 --- a/includes/api/ApiQueryQueryPage.php +++ b/includes/api/ApiQueryQueryPage.php @@ -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]; } diff --git a/maintenance/updateSpecialPages.php b/maintenance/updateSpecialPages.php index c5ade2d807..12c4a2c060 100644 --- a/maintenance/updateSpecialPages.php +++ b/maintenance/updateSpecialPages.php @@ -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; diff --git a/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php b/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php index ba845ebe98..39462b4a5e 100644 --- a/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php +++ b/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php @@ -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 */ @@ -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; -- 2.20.1