From 295d35a9d40922bfc020d9e8374ca0eae69d8713 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Tue, 16 Jun 2015 12:55:11 -0400 Subject: [PATCH] API: Add some BCarray into ApiQuerySiteinfo The main change is that siprop=namespaces will output an array instead of a numerically-keyed object with formatversion=2. Various other properties also got the same treatment, but in those cases the intention was always array and possible non-array output was due to array_unique or odd indexes in config variables. Bug: T102645 Change-Id: I486131ac0d6763c3fe40fa45bcee472fe1b46fd6 --- RELEASE-NOTES-1.26 | 4 ++++ includes/api/ApiQuerySiteinfo.php | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/RELEASE-NOTES-1.26 b/RELEASE-NOTES-1.26 index 3cc1d263f0..db560c6745 100644 --- a/RELEASE-NOTES-1.26 +++ b/RELEASE-NOTES-1.26 @@ -41,6 +41,10 @@ production. to be set. If they are both set, the value of rootpage= will be ignored. * prop=revision output in enum mode is now sorted by timestamp rather than revision ID. This usually won't make any difference. +* (T102645) Namespace list from meta=siteinfo&siprop=namespaces is now an array + with formatversion=2. +* Various other output from meta=siteinfo will now always be arrays instead of + sometimes being numerically-indexed objects with formatversion=2. === Action API internal changes in 1.26 === diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 1dc9985db5..a112cf04bb 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -297,6 +297,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { } } + ApiResult::setArrayType( $data, 'BCarray' ); ApiResult::setIndexedTagName( $data, 'ns' ); return $this->getResult()->addValue( 'query', $property, $data ); @@ -511,6 +512,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { $groups = array_intersect( $rights[$group], $allGroups ); if ( $groups ) { $arr[$type] = $groups; + ApiResult::setArrayType( $arr[$type], 'BCarray' ); ApiResult::setIndexedTagName( $arr[$type], 'group' ); } } @@ -682,6 +684,11 @@ class ApiQuerySiteinfo extends ApiQueryBase { 'semiprotectedlevels' => $config->get( 'SemiprotectedRestrictionLevels' ), ); + ApiResult::setArrayType( $data['types'], 'BCarray' ); + ApiResult::setArrayType( $data['levels'], 'BCarray' ); + ApiResult::setArrayType( $data['cascadinglevels'], 'BCarray' ); + ApiResult::setArrayType( $data['semiprotectedlevels'], 'BCarray' ); + ApiResult::setIndexedTagName( $data['types'], 'type' ); ApiResult::setIndexedTagName( $data['levels'], 'level' ); ApiResult::setIndexedTagName( $data['cascadinglevels'], 'level' ); @@ -741,6 +748,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { global $wgParser; $wgParser->firstCallInit(); $tags = array_map( array( $this, 'formatParserTags' ), $wgParser->getTags() ); + ApiResult::setArrayType( $tags, 'BCarray' ); ApiResult::setIndexedTagName( $tags, 't' ); return $this->getResult()->addValue( 'query', $property, $tags ); @@ -750,6 +758,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { global $wgParser; $wgParser->firstCallInit(); $hooks = $wgParser->getFunctionHooks(); + ApiResult::setArrayType( $hooks, 'BCarray' ); ApiResult::setIndexedTagName( $hooks, 'h' ); return $this->getResult()->addValue( 'query', $property, $hooks ); @@ -757,6 +766,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { public function appendVariables( $property ) { $variables = MagicWord::getVariableIDs(); + ApiResult::setArrayType( $variables, 'BCarray' ); ApiResult::setIndexedTagName( $variables, 'v' ); return $this->getResult()->addValue( 'query', $property, $variables ); @@ -765,6 +775,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { public function appendProtocols( $property ) { // Make a copy of the global so we don't try to set the _element key of it - bug 45130 $protocols = array_values( $this->getConfig()->get( 'UrlProtocols' ) ); + ApiResult::setArrayType( $protocols, 'BCarray' ); ApiResult::setIndexedTagName( $protocols, 'p' ); return $this->getResult()->addValue( 'query', $property, $protocols ); @@ -792,6 +803,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { 'subscribers' => array_map( array( 'SpecialVersion', 'arrayToString' ), $subscribers ), ); + ApiResult::setArrayType( $arr['subscribers'], 'BCarray' ); ApiResult::setIndexedTagName( $arr['subscribers'], 's' ); $data[] = $arr; } -- 2.20.1