ApiQueryAllDeletedRevisions: More namespace handling fixes
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 31 Aug 2016 17:19:13 +0000 (13:19 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Wed, 31 Aug 2016 17:19:13 +0000 (13:19 -0400)
* If the user specifically requests an empty list of namespaces, they
  should get no pages.
* `ar_namespace` should always be in the query so MySQL can do a range
  search instead of a full index scan.
* The example provided didn't match its description.

Bug: T89665
Change-Id: I91afc25db488f75c7f2b1ef343766b4bd7da5472

includes/api/ApiQueryAllDeletedRevisions.php

index a559683..3073a95 100644 (file)
@@ -55,6 +55,14 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase {
 
                $result = $this->getResult();
 
+               // If the user wants no namespaces, they get no pages.
+               if ( $params['namespace'] === [] ) {
+                       if ( $resultPageSet === null ) {
+                               $result->addValue( 'query', $this->getModuleName(), [] );
+                       }
+                       return;
+               }
+
                // This module operates in two modes:
                // 'user': List deleted revs by a certain user
                // 'all': List all deleted revs in NS
@@ -153,10 +161,10 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase {
                if ( $mode == 'all' ) {
                        if ( $params['namespace'] !== null ) {
                                $namespaces = $params['namespace'];
-                               $this->addWhereFld( 'ar_namespace', $namespaces );
                        } else {
                                $namespaces = MWNamespace::getValidNamespaces();
                        }
+                       $this->addWhereFld( 'ar_namespace', $namespaces );
 
                        // For from/to/prefix, we have to consider the potential
                        // transformations of the title in all specified namespaces.
@@ -447,7 +455,7 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase {
                return [
                        'action=query&list=alldeletedrevisions&adruser=Example&adrlimit=50'
                                => 'apihelp-query+alldeletedrevisions-example-user',
-                       'action=query&list=alldeletedrevisions&adrdir=newer&adrlimit=50'
+                       'action=query&list=alldeletedrevisions&adrdir=newer&adrnamespace=0&adrlimit=50'
                                => 'apihelp-query+alldeletedrevisions-example-ns-main',
                ];
        }