From 3f1814f36ed0dbaee0c12884cea1bf337c6a2b14 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Mon, 15 Dec 2014 11:04:57 -0500 Subject: [PATCH] API: Don't use an empty LinkBatch in ApiOpenSearch, part 2. While Ie4609b08 took care of the empty $titles case, we get the same problem if $titles is non-empty but contains only Special-namespace titles. Bug: T78074 Change-Id: Ic6572628e1da9953ef8212e49d4944e94d799f44 --- includes/api/ApiOpenSearch.php | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/includes/api/ApiOpenSearch.php b/includes/api/ApiOpenSearch.php index af09656814..5fc9f2b8a5 100644 --- a/includes/api/ApiOpenSearch.php +++ b/includes/api/ApiOpenSearch.php @@ -135,22 +135,24 @@ class ApiOpenSearch extends ApiBase { if ( $resolveRedir ) { // Query for redirects - $db = $this->getDb(); - $lb = new LinkBatch( $titles ); - $res = $db->select( - array( 'page', 'redirect' ), - array( 'page_namespace', 'page_title', 'rd_namespace', 'rd_title' ), - array( - 'rd_from = page_id', - 'rd_interwiki IS NULL OR rd_interwiki = ' . $db->addQuotes( '' ), - $lb->constructSet( 'page', $db ), - ), - __METHOD__ - ); $redirects = array(); - foreach ( $res as $row ) { - $redirects[$row->page_namespace][$row->page_title] = - array( $row->rd_namespace, $row->rd_title ); + $lb = new LinkBatch( $titles ); + if ( !$lb->isEmpty() ) { + $db = $this->getDb(); + $res = $db->select( + array( 'page', 'redirect' ), + array( 'page_namespace', 'page_title', 'rd_namespace', 'rd_title' ), + array( + 'rd_from = page_id', + 'rd_interwiki IS NULL OR rd_interwiki = ' . $db->addQuotes( '' ), + $lb->constructSet( 'page', $db ), + ), + __METHOD__ + ); + foreach ( $res as $row ) { + $redirects[$row->page_namespace][$row->page_title] = + array( $row->rd_namespace, $row->rd_title ); + } } // Bypass any redirects -- 2.20.1