Skip to content

Commit

Permalink
Disable filter by redirect Special:AllPages and query=allpages in mis…
Browse files Browse the repository at this point in the history
…er mode

Bug: T160916
Change-Id: Ib9562b404731e1f621b9f07c33821d04cd2aa6ae
  • Loading branch information
reedy authored and anomiex committed Mar 20, 2017
1 parent aa5eca0 commit 454b199
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
4 changes: 4 additions & 0 deletions RELEASE-NOTES-1.29
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
36 changes: 31 additions & 5 deletions includes/api/ApiQueryAllPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ private function run( $resultPageSet = null ) {
$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'] );
Expand Down Expand Up @@ -108,6 +111,18 @@ private function run( $resultPageSet = null ) {
$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'] ) ) {
Expand Down Expand Up @@ -219,6 +234,11 @@ private function run( $resultPageSet = null ) {
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 = [
Expand All @@ -242,7 +262,7 @@ private function run( $resultPageSet = null ) {
}

public function getAllowedParams() {
return [
$ret = [
'from' => null,
'continue' => [
ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
Expand Down Expand Up @@ -314,6 +334,12 @@ public function getAllowedParams() {
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() {
Expand Down
12 changes: 11 additions & 1 deletion includes/specials/SpecialAllPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ function execute( $par ) {
$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();

Expand Down Expand Up @@ -100,6 +104,7 @@ function execute( $par ) {
protected function outputHTMLForm( $namespace = NS_MAIN,
$from = '', $to = '', $hideRedirects = false
) {
$miserMode = (bool)$this->getConfig()->get( 'MiserMode' );
$fields = [
'from' => [
'type' => 'text',
Expand Down Expand Up @@ -133,6 +138,11 @@ protected function outputHTMLForm( $namespace = NS_MAIN,
'value' => $hideRedirects,
],
];

if ( $miserMode ) {
unset ( $fields['hideredirects'] );
}

$form = HTMLForm::factory( 'table', $fields, $this->getContext() );
$form->setMethod( 'get' )
->setWrapperLegendMsg( 'allpages' )
Expand Down

0 comments on commit 454b199

Please sign in to comment.