From: Brad Jorsch Date: Wed, 12 Apr 2017 16:04:50 +0000 (-0400) Subject: API: Handle pltitles/tltemplates/clcategories/imimages with only invalid titles X-Git-Tag: 1.31.0-rc.0~1800 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=61de3c3e6112825ea10d6908d62302efe1994b9e;p=lhc%2Fweb%2Fwiklou.git API: Handle pltitles/tltemplates/clcategories/imimages with only invalid titles If the parameter contains only invalid titles, it shouldn't be ignored. Bug: T162816 Change-Id: I3ee6aeab421db5732b652fed21292d8509f8d757 --- diff --git a/includes/api/ApiQueryCategories.php b/includes/api/ApiQueryCategories.php index c4428d575a..f728dc5fa8 100644 --- a/includes/api/ApiQueryCategories.php +++ b/includes/api/ApiQueryCategories.php @@ -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 ); } diff --git a/includes/api/ApiQueryImages.php b/includes/api/ApiQueryImages.php index 0086c58a93..01a54de9e9 100644 --- a/includes/api/ApiQueryImages.php +++ b/includes/api/ApiQueryImages.php @@ -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 ); } diff --git a/includes/api/ApiQueryLinks.php b/includes/api/ApiQueryLinks.php index 4b340912e8..2f75e76343 100644 --- a/includes/api/ApiQueryLinks.php +++ b/includes/api/ApiQueryLinks.php @@ -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; } }