From 454b199537b53bf1851afe8d38c9c0a817a6a310 Mon Sep 17 00:00:00 2001 From: Reedy Date: Mon, 20 Mar 2017 17:54:40 +0000 Subject: [PATCH] Disable filter by redirect Special:AllPages and query=allpages in miser mode Bug: T160916 Change-Id: Ib9562b404731e1f621b9f07c33821d04cd2aa6ae --- RELEASE-NOTES-1.29 | 4 +++ includes/api/ApiQueryAllPages.php | 36 +++++++++++++++++++++++---- includes/specials/SpecialAllPages.php | 12 ++++++++- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES-1.29 b/RELEASE-NOTES-1.29 index 0c483e9974..b9a93f1585 100644 --- a/RELEASE-NOTES-1.29 +++ b/RELEASE-NOTES-1.29 @@ -80,6 +80,7 @@ production. * (T27187) Search suggestions based on jquery.suggestions will now correctly only highlight prefix matches in the results. * (T157035) "new mw.Uri()" was ignoring options when using default URI. +* Special:Allpages can no longer be filtered by redirect in miser mode. === Action API changes in 1.29 === * Submitting sensitive authentication request parameters to action=login, @@ -114,6 +115,9 @@ production. * action=purge now requires a POST. * There is a new `languagevariants` siprop for action=query&meta=siteinfo, which returns a list of languages with active LanguageConverter instances. +* action=query&query=allpages will no longer filter redirects using a database + query in miser mode. This may result in less results being returned than were + requested. === Action API internal changes in 1.29 === * New methods were added to ApiBase to handle errors and warnings using i18n diff --git a/includes/api/ApiQueryAllPages.php b/includes/api/ApiQueryAllPages.php index 7460bd5377..6b959ae774 100644 --- a/includes/api/ApiQueryAllPages.php +++ b/includes/api/ApiQueryAllPages.php @@ -76,10 +76,13 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { $this->addWhere( "page_title $op= $cont_from" ); } - if ( $params['filterredir'] == 'redirects' ) { - $this->addWhereFld( 'page_is_redirect', 1 ); - } elseif ( $params['filterredir'] == 'nonredirects' ) { - $this->addWhereFld( 'page_is_redirect', 0 ); + $miserMode = $this->getConfig()->get( 'MiserMode' ); + if ( !$miserMode ) { + if ( $params['filterredir'] == 'redirects' ) { + $this->addWhereFld( 'page_is_redirect', 1 ); + } elseif ( $params['filterredir'] == 'nonredirects' ) { + $this->addWhereFld( 'page_is_redirect', 0 ); + } } $this->addWhereFld( 'page_namespace', $params['namespace'] ); @@ -108,6 +111,18 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { $selectFields = $resultPageSet->getPageTableFields(); } + $miserModeFilterRedirValue = null; + $miserModeFilterRedir = $miserMode && $params['filterredir'] !== 'all'; + if ( $miserModeFilterRedir ) { + $selectFields[] = 'page_is_redirect'; + + if ( $params['filterredir'] == 'redirects' ) { + $miserModeFilterRedirValue = 1; + } elseif ( $params['filterredir'] == 'nonredirects' ) { + $miserModeFilterRedirValue = 0; + } + } + $this->addFields( $selectFields ); $forceNameTitleIndex = true; if ( isset( $params['minsize'] ) ) { @@ -219,6 +234,11 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { break; } + if ( $miserModeFilterRedir && (int)$row->page_is_redirect !== $miserModeFilterRedirValue ) { + // Filter implemented in PHP due to being in Miser Mode + continue; + } + if ( is_null( $resultPageSet ) ) { $title = Title::makeTitle( $row->page_namespace, $row->page_title ); $vals = [ @@ -242,7 +262,7 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { } public function getAllowedParams() { - return [ + $ret = [ 'from' => null, 'continue' => [ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', @@ -314,6 +334,12 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { ApiBase::PARAM_DFLT => 'all' ], ]; + + if ( $this->getConfig()->get( 'MiserMode' ) ) { + $ret['filterredir'][ApiBase::PARAM_HELP_MSG_APPEND] = [ 'api-help-param-limited-in-miser-mode' ]; + } + + return $ret; } protected function getExamplesMessages() { diff --git a/includes/specials/SpecialAllPages.php b/includes/specials/SpecialAllPages.php index 4b8446a795..fd7bc3f5c4 100644 --- a/includes/specials/SpecialAllPages.php +++ b/includes/specials/SpecialAllPages.php @@ -69,7 +69,11 @@ class SpecialAllPages extends IncludableSpecialPage { $from = $request->getVal( 'from', null ); $to = $request->getVal( 'to', null ); $namespace = $request->getInt( 'namespace' ); - $hideredirects = $request->getBool( 'hideredirects', false ); + + $miserMode = (bool)$this->getConfig()->get( 'MiserMode' ); + + // Redirects filter is disabled in MiserMode + $hideredirects = $request->getBool( 'hideredirects', false ) && !$miserMode; $namespaces = $this->getLanguage()->getNamespaces(); @@ -100,6 +104,7 @@ class SpecialAllPages extends IncludableSpecialPage { protected function outputHTMLForm( $namespace = NS_MAIN, $from = '', $to = '', $hideRedirects = false ) { + $miserMode = (bool)$this->getConfig()->get( 'MiserMode' ); $fields = [ 'from' => [ 'type' => 'text', @@ -133,6 +138,11 @@ class SpecialAllPages extends IncludableSpecialPage { 'value' => $hideRedirects, ], ]; + + if ( $miserMode ) { + unset ( $fields['hideredirects'] ); + } + $form = HTMLForm::factory( 'table', $fields, $this->getContext() ); $form->setMethod( 'get' ) ->setWrapperLegendMsg( 'allpages' ) -- 2.20.1