From 1204a50435cda092cd3ec00adfc3533a59bfa73a Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Fri, 10 Oct 2014 15:22:35 -0400 Subject: [PATCH] API: Fix ApiQueryBacklinks redirlinks The fast case needs to pass the redirlinks subarray through array_values and set an indexed tag name. Bug: 71907 Change-Id: I865aad6485a2598c9e574ab5c38e8e0923d11ddd --- includes/api/ApiQueryBacklinks.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/includes/api/ApiQueryBacklinks.php b/includes/api/ApiQueryBacklinks.php index 52445d279f..f00a6e7f33 100644 --- a/includes/api/ApiQueryBacklinks.php +++ b/includes/api/ApiQueryBacklinks.php @@ -287,7 +287,6 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { $res = $this->select( __METHOD__ ); $count = 0; - $result = $this->getResult(); foreach ( $res as $row ) { $ns = $this->hasNS ? $row->{$this->bl_ns} : NS_FILE; @@ -319,10 +318,6 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { $parentID = $this->pageMap[$ns][$row->{$this->bl_title}]; // Put all the results in an array first $this->resultArr[$parentID]['redirlinks'][$row->page_id] = $a; - $result->setIndexedTagName( - $this->resultArr[$parentID]['redirlinks'], - $this->bl_code - ); } else { $resultPageSet->processDbRow( $row ); } @@ -427,7 +422,15 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { if ( is_null( $resultPageSet ) ) { // Try to add the result data in one go and pray that it fits - $fit = $result->addValue( 'query', $this->getModuleName(), array_values( $this->resultArr ) ); + $code = $this->bl_code; + $data = array_map( function ( $arr ) use ( $result, $code ) { + if ( isset( $arr['redirlinks'] ) ) { + $arr['redirlinks'] = array_values( $arr['redirlinks'] ); + $result->setIndexedTagName( $arr['redirlinks'], $code ); + } + return $arr; + }, array_values( $this->resultArr ) ); + $fit = $result->addValue( 'query', $this->getModuleName(), $data ); if ( !$fit ) { // It didn't fit. Add elements one by one until the // result is full. -- 2.20.1