API: Handle pltitles/tltemplates/clcategories/imimages with only invalid titles
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 12 Apr 2017 16:04:50 +0000 (12:04 -0400)
committerAnomie <bjorsch@wikimedia.org>
Thu, 12 Oct 2017 15:48:15 +0000 (15:48 +0000)
If the parameter contains only invalid titles, it shouldn't be ignored.

Bug: T162816
Change-Id: I3ee6aeab421db5732b652fed21292d8509f8d757

includes/api/ApiQueryCategories.php
includes/api/ApiQueryImages.php
includes/api/ApiQueryLinks.php

index c4428d5..f728dc5 100644 (file)
@@ -69,7 +69,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
 
                $this->addTables( 'categorylinks' );
                $this->addWhereFld( 'cl_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
-               if ( !is_null( $params['categories'] ) ) {
+               if ( $params['categories'] ) {
                        $cats = [];
                        foreach ( $params['categories'] as $cat ) {
                                $title = Title::newFromText( $cat );
@@ -79,6 +79,10 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
                                        $cats[] = $title->getDBkey();
                                }
                        }
+                       if ( !$cats ) {
+                               // No titles so no results
+                               return;
+                       }
                        $this->addWhereFld( 'cl_to', $cats );
                }
 
index 0086c58..01a54de 100644 (file)
@@ -85,7 +85,7 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
                }
                $this->addOption( 'LIMIT', $params['limit'] + 1 );
 
-               if ( !is_null( $params['images'] ) ) {
+               if ( $params['images'] ) {
                        $images = [];
                        foreach ( $params['images'] as $img ) {
                                $title = Title::newFromText( $img );
@@ -95,6 +95,10 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
                                        $images[] = $title->getDBkey();
                                }
                        }
+                       if ( !$images ) {
+                               // No titles so no results
+                               return;
+                       }
                        $this->addWhereFld( 'il_to', $images );
                }
 
index 4b34091..2f75e76 100644 (file)
@@ -89,7 +89,7 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
                $this->addWhereFld( $this->prefix . '_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
                $this->addWhereFld( $this->prefix . '_namespace', $params['namespace'] );
 
-               if ( !is_null( $params[$this->titlesParam] ) ) {
+               if ( $params[$this->titlesParam] ) {
                        $lb = new LinkBatch;
                        foreach ( $params[$this->titlesParam] as $t ) {
                                $title = Title::newFromText( $t );
@@ -102,6 +102,9 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
                        $cond = $lb->constructSet( $this->prefix, $this->getDB() );
                        if ( $cond ) {
                                $this->addWhere( $cond );
+                       } else {
+                               // No titles so no results
+                               return;
                        }
                }