Change API result data structure to be cleaner in new formats
authorBrad Jorsch <bjorsch@wikimedia.org>
Fri, 16 Jan 2015 19:00:07 +0000 (14:00 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Mon, 20 Apr 2015 21:49:37 +0000 (17:49 -0400)
Nothing in this patch should result in changed output for format=json or
format=php except as noted in RELEASE-NOTES-1.25, and changed output for
format=xml should be similar or cosmetic. However, other code accessing
the result data directly may need to be updated.

Bug: T87053
Bug: T12887
Change-Id: I3500708965cb8869b5aed1543381aad208dadd13

59 files changed:
RELEASE-NOTES-1.25
includes/api/ApiBlock.php
includes/api/ApiContinuationManager.php
includes/api/ApiEditPage.php
includes/api/ApiExpandTemplates.php
includes/api/ApiImageRotate.php
includes/api/ApiImport.php
includes/api/ApiManageTags.php
includes/api/ApiMove.php
includes/api/ApiOpenSearch.php
includes/api/ApiPageSet.php
includes/api/ApiParamInfo.php
includes/api/ApiParse.php
includes/api/ApiProtect.php
includes/api/ApiPurge.php
includes/api/ApiQuery.php
includes/api/ApiQueryAllCategories.php
includes/api/ApiQueryAllLinks.php
includes/api/ApiQueryAllMessages.php
includes/api/ApiQueryAllUsers.php
includes/api/ApiQueryBacklinks.php
includes/api/ApiQueryBacklinksprop.php
includes/api/ApiQueryBlocks.php
includes/api/ApiQueryCategories.php
includes/api/ApiQueryCategoryInfo.php
includes/api/ApiQueryCategoryMembers.php
includes/api/ApiQueryDeletedrevs.php
includes/api/ApiQueryDuplicateFiles.php
includes/api/ApiQueryExtLinksUsage.php
includes/api/ApiQueryFileRepoInfo.php
includes/api/ApiQueryFilearchive.php
includes/api/ApiQueryIWBacklinks.php
includes/api/ApiQueryImageInfo.php
includes/api/ApiQueryInfo.php
includes/api/ApiQueryLangBacklinks.php
includes/api/ApiQueryLogEvents.php
includes/api/ApiQueryPageProps.php
includes/api/ApiQueryPagesWithProp.php
includes/api/ApiQueryPrefixSearch.php
includes/api/ApiQueryQueryPage.php
includes/api/ApiQueryRecentChanges.php
includes/api/ApiQueryRevisionsBase.php
includes/api/ApiQuerySiteinfo.php
includes/api/ApiQueryTags.php
includes/api/ApiQueryTokens.php
includes/api/ApiQueryUserContributions.php
includes/api/ApiQueryUserInfo.php
includes/api/ApiQueryUsers.php
includes/api/ApiQueryWatchlist.php
includes/api/ApiResult.php
includes/api/ApiSetNotificationTimestamp.php
includes/api/ApiTokens.php
includes/api/ApiWatch.php
tests/phpunit/includes/api/ApiContinuationManagerTest.php
tests/phpunit/includes/api/ApiErrorFormatterTest.php
tests/phpunit/includes/api/ApiResultTest.php
tests/phpunit/includes/api/format/ApiFormatTestBase.php
tests/phpunit/includes/api/query/ApiQueryContinue2Test.php
tests/phpunit/includes/api/query/ApiQueryContinueTest.php

index 13b01d9..530a804 100644 (file)
@@ -268,6 +268,9 @@ production.
     as comma-separated lists.
   * merge events use new-style formatting.
   * delete/event and delete/revision events use new-style formatting.
+* The root node and various other nodes will now always be an object in formats
+  such as json that distinguish between arrays and objects.
+  * Except for action=opensearch where the spec requires an array.
 
 === Action API internal changes in 1.25 ===
 * ApiHelp has been rewritten to support i18n and paginated HTML output.
@@ -316,6 +319,10 @@ production.
   metadata isn't set.
 * (T35235) LogFormatter subclasses are now responsible for formatting log event
   parameters for the API.
+* Many modules have changed result data formats. While this shouldn't affect
+  clients not using the experimental formatversion=2015, code using
+  ApiResult::getResultData() and not using ApiResult::transformForBC() may need
+  updating.
 * The following methods have been deprecated and may be removed in a future
   release:
   * ApiBase::getDescription
index 72aee32..26b5f0e 100644 (file)
@@ -113,27 +113,13 @@ class ApiBlock extends ApiBase {
                }
 
                $res['reason'] = $params['reason'];
-               if ( $params['anononly'] ) {
-                       $res['anononly'] = '';
-               }
-               if ( $params['nocreate'] ) {
-                       $res['nocreate'] = '';
-               }
-               if ( $params['autoblock'] ) {
-                       $res['autoblock'] = '';
-               }
-               if ( $params['noemail'] ) {
-                       $res['noemail'] = '';
-               }
-               if ( $params['hidename'] ) {
-                       $res['hidename'] = '';
-               }
-               if ( $params['allowusertalk'] ) {
-                       $res['allowusertalk'] = '';
-               }
-               if ( $params['watchuser'] ) {
-                       $res['watchuser'] = '';
-               }
+               $res['anononly'] = $params['anononly'];
+               $res['nocreate'] = $params['nocreate'];
+               $res['autoblock'] = $params['autoblock'];
+               $res['noemail'] = $params['noemail'];
+               $res['hidename'] = $params['hidename'];
+               $res['allowusertalk'] = $params['allowusertalk'];
+               $res['watchuser'] = $params['watchuser'];
 
                $this->getResult()->addValue( null, $this->getModuleName(), $res );
        }
index dea1cf4..354f4e7 100644 (file)
@@ -231,7 +231,7 @@ class ApiContinuationManager {
                                ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK );
                }
                if ( $batchcomplete ) {
-                       $result->addValue( null, 'batchcomplete', '',
+                       $result->addValue( null, 'batchcomplete', true,
                                ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK );
                }
        }
index 601c64c..0dee147 100644 (file)
@@ -490,7 +490,7 @@ class ApiEditPage extends ApiBase {
                                $this->dieStatus( $status );
 
                        case EditPage::AS_SUCCESS_NEW_ARTICLE:
-                               $r['new'] = '';
+                               $r['new'] = true;
                                // fall-through
 
                        case EditPage::AS_SUCCESS_UPDATE:
@@ -500,7 +500,7 @@ class ApiEditPage extends ApiBase {
                                $r['contentmodel'] = $titleObj->getContentModel();
                                $newRevId = $articleObject->getLatest();
                                if ( $newRevId == $oldRevId ) {
-                                       $r['nochange'] = '';
+                                       $r['nochange'] = true;
                                } else {
                                        $r['oldrevid'] = intval( $oldRevId );
                                        $r['newrevid'] = intval( $newRevId );
index 5c7717f..6d064eb 100644 (file)
@@ -96,9 +96,8 @@ class ApiExpandTemplates extends ApiBase {
                                $retval['parsetree'] = $xml;
                        } else {
                                // the old way
-                               $xml_result = array();
-                               ApiResult::setContentValue( $xml_result, 'xml', $xml );
-                               $result->addValue( null, 'parsetree', $xml_result );
+                               $result->addValue( null, 'parsetree', $xml );
+                               $result->addValue( null, ApiResult::META_BC_SUBELEMENTS, array( 'parsetree' ) );
                        }
                }
 
@@ -129,19 +128,13 @@ class ApiExpandTemplates extends ApiBase {
                                if ( isset( $prop['properties'] ) ) {
                                        $properties = $wgParser->getOutput()->getProperties();
                                        if ( $properties ) {
-                                               $properties_result = array();
-                                               foreach ( $properties as $name => $value ) {
-                                                       $entry = array();
-                                                       $entry['name'] = $name;
-                                                       ApiResult::setContentValue( $entry, 'value', $value );
-                                                       $properties_result[] = $entry;
-                                               }
-                                               ApiResult::setIndexedTagName( $properties_result, 'property' );
-                                               $retval['properties'] = $properties_result;
+                                               ApiResult::setArrayType( $properties, 'BCkvp', 'name' );
+                                               ApiResult::setIndexedTagName( $properties, 'property' );
+                                               $retval['properties'] = $properties;
                                        }
                                }
-                               if ( isset( $prop['volatile'] ) && $frame->isVolatile() ) {
-                                       $retval['volatile'] = '';
+                               if ( isset( $prop['volatile'] ) ) {
+                                       $retval['volatile'] = $frame->isVolatile();
                                }
                                if ( isset( $prop['ttl'] ) && $frame->getTTL() !== null ) {
                                        $retval['ttl'] = $frame->getTTL();
index 7b99921..865d39f 100644 (file)
@@ -42,7 +42,7 @@ class ApiImageRotate extends ApiBase {
                                $v = $val;
                        }
                        if ( $flag !== null ) {
-                               $v[$flag] = '';
+                               $v[$flag] = true;
                        }
                        $result[] = $v;
                }
@@ -71,7 +71,7 @@ class ApiImageRotate extends ApiBase {
                        $r['id'] = $title->getArticleID();
                        ApiQueryBase::addTitleInfo( $r, $title );
                        if ( !$title->exists() ) {
-                               $r['missing'] = '';
+                               $r['missing'] = true;
                        }
 
                        $file = wfFindFile( $title, array( 'latest' => true ) );
index 9d76a46..2e87d22 100644 (file)
@@ -155,7 +155,7 @@ class ApiImportReporter extends ImportReporter {
                if ( $title === null ) {
                        # Invalid or non-importable title
                        $r['title'] = $pageInfo['title'];
-                       $r['invalid'] = '';
+                       $r['invalid'] = true;
                } else {
                        ApiQueryBase::addTitleInfo( $r, $title );
                        $r['revisions'] = intval( $successCount );
index 80317d3..240d350 100644 (file)
@@ -49,8 +49,8 @@ class ApiManageTags extends ApiBase {
                if ( !$status->isGood() ) {
                        $ret['warnings'] = $this->getErrorFormatter()->arrayFromStatus( $status, 'warning' );
                }
-               if ( $status->value !== null ) {
-                       $ret['success'] = '';
+               $ret['success'] = $status->value !== null;
+               if ( $ret['success'] ) {
                        $ret['logid'] = $status->value;
                }
                $result->addValue( null, $this->getModuleName(), $ret );
index 0db18e7..e42958b 100644 (file)
@@ -83,18 +83,14 @@ class ApiMove extends ApiBase {
                        'reason' => $params['reason']
                );
 
-               if ( $fromTitle->exists() ) {
-                       //NOTE: we assume that if the old title exists, it's because it was re-created as
-                       // a redirect to the new title. This is not safe, but what we did before was
-                       // even worse: we just determined whether a redirect should have been created,
-                       // and reported that it was created if it should have, without any checks.
-                       // Also note that isRedirect() is unreliable because of bug 37209.
-                       $r['redirectcreated'] = '';
-               }
+               //NOTE: we assume that if the old title exists, it's because it was re-created as
+               // a redirect to the new title. This is not safe, but what we did before was
+               // even worse: we just determined whether a redirect should have been created,
+               // and reported that it was created if it should have, without any checks.
+               // Also note that isRedirect() is unreliable because of bug 37209.
+               $r['redirectcreated'] = $fromTitle->exists();
 
-               if ( $toTitleExists ) {
-                       $r['moveoverredirect'] = '';
-               }
+               $r['moveoverredirect'] = $toTitleExists;
 
                // Move the talk page
                if ( $params['movetalk'] && $fromTalk->exists() && !$fromTitle->isTalkPage() ) {
@@ -103,9 +99,7 @@ class ApiMove extends ApiBase {
                        if ( $status->isOK() ) {
                                $r['talkfrom'] = $fromTalk->getPrefixedText();
                                $r['talkto'] = $toTalk->getPrefixedText();
-                               if ( $toTalkExists ) {
-                                       $r['talkmoveoverredirect'] = '';
-                               }
+                               $r['talkmoveoverredirect'] = $toTalkExists;
                        } else {
                                // We're not gonna dieUsage() on failure, since we already changed something
                                $error = $this->getErrorFromStatus( $status );
index 33790f9..8c03dce 100644 (file)
@@ -212,6 +212,7 @@ class ApiOpenSearch extends ApiBase {
                switch ( $this->getFormat() ) {
                        case 'json':
                                // http://www.opensearch.org/Specifications/OpenSearch/Extensions/Suggestions/1.1
+                               $result->addArrayType( null, 'array' );
                                $result->addValue( null, 0, strval( $search ) );
                                $terms = array();
                                $descriptions = array();
index 02a25fe..e6f218d 100644 (file)
@@ -96,7 +96,7 @@ class ApiPageSet extends ApiBase {
                                $v = $val;
                        }
                        if ( $flag !== null ) {
-                               $v[$flag] = '';
+                               $v[$flag] = true;
                        }
                        $result[] = $v;
                }
index bb661b2..25069d9 100644 (file)
@@ -216,7 +216,7 @@ class ApiParamInfo extends ApiBase {
                $this->formatHelpMessages( $ret, 'description', $module->getFinalDescription() );
 
                foreach ( $module->getHelpFlags() as $flag ) {
-                       $ret[$flag] = '';
+                       $ret[$flag] = true;
                }
 
                $ret['helpurls'] = (array)$module->getHelpUrls();
@@ -265,12 +265,10 @@ class ApiParamInfo extends ApiBase {
                                $this->formatHelpMessages( $item, 'description', $paramDesc[$name], true );
                        }
 
-                       if ( !empty( $settings[ApiBase::PARAM_REQUIRED] ) ) {
-                               $item['required'] = '';
-                       }
+                       $item['required'] = !empty( $settings[ApiBase::PARAM_REQUIRED] );
 
                        if ( !empty( $settings[ApiBase::PARAM_DEPRECATED] ) ) {
-                               $item['deprecated'] = '';
+                               $item['deprecated'] = true;
                        }
 
                        if ( $name === 'token' && $module->needsToken() ) {
@@ -307,8 +305,8 @@ class ApiParamInfo extends ApiBase {
                                }
                        }
 
-                       if ( !empty( $settings[ApiBase::PARAM_ISMULTI] ) ) {
-                               $item['multi'] = '';
+                       $item['multi'] = !empty( $settings[ApiBase::PARAM_ISMULTI] );
+                       if ( $item['multi'] ) {
                                $item['limit'] = $this->getMain()->canApiHighLimits() ?
                                        ApiBase::LIMIT_SML2 :
                                        ApiBase::LIMIT_SML1;
@@ -317,14 +315,14 @@ class ApiParamInfo extends ApiBase {
                        }
 
                        if ( !empty( $settings[ApiBase::PARAM_ALLOW_DUPLICATES] ) ) {
-                               $item['allowsduplicates'] = '';
+                               $item['allowsduplicates'] = true;
                        }
 
                        if ( isset( $settings[ApiBase::PARAM_TYPE] ) ) {
                                if ( $settings[ApiBase::PARAM_TYPE] === 'submodule' ) {
                                        $item['type'] = $module->getModuleManager()->getNames( $name );
                                        sort( $item['type'] );
-                                       $item['submodules'] = '';
+                                       $item['submodules'] = true;
                                } else {
                                        $item['type'] = $settings[ApiBase::PARAM_TYPE];
                                }
index 267bced..fc004cf 100644 (file)
@@ -225,21 +225,17 @@ class ApiParse extends ApiBase {
                        if ( $params['onlypst'] ) {
                                // Build a result and bail out
                                $result_array = array();
-                               $result_array['text'] = array();
-                               ApiResult::setContentValue( $result_array['text'], 'text', $this->pstContent->serialize( $format ) );
+                               $result_array['text'] = $this->pstContent->serialize( $format );
+                               $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
                                if ( isset( $prop['wikitext'] ) ) {
-                                       $result_array['wikitext'] = array();
-                                       ApiResult::setContentValue( $result_array['wikitext'], 'wikitext', $this->content->serialize( $format ) );
+                                       $result_array['wikitext'] = $this->content->serialize( $format );
+                                       $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'wikitext';
                                }
                                if ( !is_null( $params['summary'] ) ||
                                        ( !is_null( $params['sectiontitle'] ) && $this->section === 'new' )
                                ) {
-                                       $result_array['parsedsummary'] = array();
-                                       ApiResult::setContentValue(
-                                               $result_array['parsedsummary'],
-                                               'parsedsummary',
-                                               $this->formatSummary( $titleObj, $params )
-                                       );
+                                       $result_array['parsedsummary'] = $this->formatSummary( $titleObj, $params );
+                                       $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsedsummary';
                                }
 
                                $result->addValue( null, $this->getModuleName(), $result_array );
@@ -272,19 +268,15 @@ class ApiParse extends ApiBase {
                }
 
                if ( isset( $prop['text'] ) ) {
-                       $result_array['text'] = array();
-                       ApiResult::setContentValue( $result_array['text'], 'text', $p_result->getText() );
+                       $result_array['text'] = $p_result->getText();
+                       $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
                }
 
                if ( !is_null( $params['summary'] ) ||
                        ( !is_null( $params['sectiontitle'] ) && $this->section === 'new' )
                ) {
-                       $result_array['parsedsummary'] = array();
-                       ApiResult::setContentValue(
-                               $result_array['parsedsummary'],
-                               'parsedsummary',
-                               $this->formatSummary( $titleObj, $params )
-                       );
+                       $result_array['parsedsummary'] = $this->formatSummary( $titleObj, $params );
+                       $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsedsummary';
                }
 
                if ( isset( $prop['langlinks'] ) ) {
@@ -307,9 +299,8 @@ class ApiParse extends ApiBase {
                        $result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() );
                }
                if ( isset( $prop['categorieshtml'] ) ) {
-                       $categoriesHtml = $this->categoriesHtml( $p_result->getCategories() );
-                       $result_array['categorieshtml'] = array();
-                       ApiResult::setContentValue( $result_array['categorieshtml'], 'categorieshtml', $categoriesHtml );
+                       $result_array['categorieshtml'] = $this->categoriesHtml( $p_result->getCategories() );
+                       $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'categorieshtml';
                }
                if ( isset( $prop['links'] ) ) {
                        $result_array['links'] = $this->formatLinks( $p_result->getLinks() );
@@ -349,12 +340,8 @@ class ApiParse extends ApiBase {
                        }
 
                        if ( isset( $prop['headhtml'] ) ) {
-                               $result_array['headhtml'] = array();
-                               ApiResult::setContentValue(
-                                       $result_array['headhtml'],
-                                       'headhtml',
-                                       $context->getOutput()->headElement( $context->getSkin() )
-                               );
+                               $result_array['headhtml'] = $context->getOutput()->headElement( $context->getSkin() );
+                               $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'headhtml';
                        }
                }
 
@@ -366,11 +353,8 @@ class ApiParse extends ApiBase {
                }
 
                if ( isset( $prop['indicators'] ) ) {
-                       foreach ( $p_result->getIndicators() as $name => $content ) {
-                               $indicator = array( 'name' => $name );
-                               ApiResult::setContentValue( $indicator, 'content', $content );
-                               $result_array['indicators'][] = $indicator;
-                       }
+                       $result_array['indicators'] = (array)$p_result->getIndicators();
+                       ApiResult::setArrayType( $result_array['indicators'], 'BCkvp', 'name' );
                }
 
                if ( isset( $prop['iwlinks'] ) ) {
@@ -378,15 +362,16 @@ class ApiParse extends ApiBase {
                }
 
                if ( isset( $prop['wikitext'] ) ) {
-                       $result_array['wikitext'] = array();
-                       ApiResult::setContentValue( $result_array['wikitext'], 'wikitext', $this->content->serialize( $format ) );
+                       $result_array['wikitext'] = $this->content->serialize( $format );
+                       $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'wikitext';
                        if ( !is_null( $this->pstContent ) ) {
-                               $result_array['psttext'] = array();
-                               ApiResult::setContentValue( $result_array['psttext'], 'psttext', $this->pstContent->serialize( $format ) );
+                               $result_array['psttext'] = $this->pstContent->serialize( $format );
+                               $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'psttext';
                        }
                }
                if ( isset( $prop['properties'] ) ) {
-                       $result_array['properties'] = $this->formatProperties( $p_result->getProperties() );
+                       $result_array['properties'] = (array)$p_result->getProperties();
+                       ApiResult::setArrayType( $result_array['properties'], 'BCkvp', 'name' );
                }
 
                if ( isset( $prop['limitreportdata'] ) ) {
@@ -394,9 +379,8 @@ class ApiParse extends ApiBase {
                                $this->formatLimitReportData( $p_result->getLimitReportData() );
                }
                if ( isset( $prop['limitreporthtml'] ) ) {
-                       $limitreportHtml = EditPage::getPreviewLimitReport( $p_result );
-                       $result_array['limitreporthtml'] = array();
-                       ApiResult::setContentValue( $result_array['limitreporthtml'], 'limitreporthtml', $limitreportHtml );
+                       $result_array['limitreporthtml'] = EditPage::getPreviewLimitReport( $p_result );
+                       $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'limitreporthtml';
                }
 
                if ( $params['generatexml'] ) {
@@ -411,8 +395,8 @@ class ApiParse extends ApiBase {
                        } else {
                                $xml = $dom->__toString();
                        }
-                       $result_array['parsetree'] = array();
-                       ApiResult::setContentValue( $result_array['parsetree'], 'parsetree', $xml );
+                       $result_array['parsetree'] = $xml;
+                       $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsetree';
                }
 
                $result_mapping = array(
@@ -589,9 +573,9 @@ class ApiParse extends ApiBase {
                        $entry['sortkey'] = $sortkey;
                        ApiResult::setContentValue( $entry, 'category', $link );
                        if ( !isset( $hiddencats[$link] ) ) {
-                               $entry['missing'] = '';
+                               $entry['missing'] = true;
                        } elseif ( $hiddencats[$link] ) {
-                               $entry['hidden'] = '';
+                               $entry['hidden'] = true;
                        }
                        $result[] = $entry;
                }
@@ -613,9 +597,7 @@ class ApiParse extends ApiBase {
                                $entry = array();
                                $entry['ns'] = $ns;
                                ApiResult::setContentValue( $entry, 'title', Title::makeTitle( $ns, $title )->getFullText() );
-                               if ( $id != 0 ) {
-                                       $entry['exists'] = '';
-                               }
+                               $entry['exists'] = $id != 0;
                                $result[] = $entry;
                        }
                }
@@ -655,18 +637,6 @@ class ApiParse extends ApiBase {
                return $result;
        }
 
-       private function formatProperties( $properties ) {
-               $result = array();
-               foreach ( $properties as $name => $value ) {
-                       $entry = array();
-                       $entry['name'] = $name;
-                       ApiResult::setContentValue( $entry, 'value', $value );
-                       $result[] = $entry;
-               }
-
-               return $result;
-       }
-
        private function formatCss( $css ) {
                $result = array();
                foreach ( $css as $file => $link ) {
@@ -689,8 +659,7 @@ class ApiParse extends ApiBase {
                        if ( !is_array( $value ) ) {
                                $value = array( $value );
                        }
-                       ApiResult::setIndexedTagName( $value, 'param' );
-                       ApiResult::setIndexedTagNameOnSubarrays( $value, 'param' );
+                       ApiResult::setIndexedTagNameRecursive( $value, 'param' );
                        $entry = array_merge( $entry, $value );
                        $result[] = $entry;
                }
index 496db8f..c07aaca 100644 (file)
@@ -123,7 +123,7 @@ class ApiProtect extends ApiBase {
                        'reason' => $params['reason']
                );
                if ( $cascade ) {
-                       $res['cascade'] = '';
+                       $res['cascade'] = true;
                }
                $res['protections'] = $resultProtections;
                $result = $this->getResult();
index 67f7834..a22be49 100644 (file)
@@ -53,7 +53,7 @@ class ApiPurge extends ApiBase {
                        ApiQueryBase::addTitleInfo( $r, $title );
                        $page = WikiPage::factory( $title );
                        $page->doPurge(); // Directly purge and skip the UI part of purge().
-                       $r['purged'] = '';
+                       $r['purged'] = true;
 
                        if ( $forceLinkUpdate || $forceRecursiveLinkUpdate ) {
                                if ( !$this->getUser()->pingLimiter( 'linkpurge' ) ) {
@@ -74,7 +74,7 @@ class ApiPurge extends ApiBase {
                                                $title, null, $forceRecursiveLinkUpdate, $p_result );
                                        DataUpdate::runUpdates( $updates );
 
-                                       $r['linkupdate'] = '';
+                                       $r['linkupdate'] = true;
 
                                        if ( $enableParserCache ) {
                                                $pcache = ParserCache::singleton();
index b1069c7..082fccb 100644 (file)
@@ -403,18 +403,18 @@ class ApiQuery extends ApiBase {
                foreach ( $pageSet->getMissingTitles() as $fakeId => $title ) {
                        $vals = array();
                        ApiQueryBase::addTitleInfo( $vals, $title );
-                       $vals['missing'] = '';
+                       $vals['missing'] = true;
                        $pages[$fakeId] = $vals;
                }
                // Report any invalid titles
                foreach ( $pageSet->getInvalidTitles() as $fakeId => $title ) {
-                       $pages[$fakeId] = array( 'title' => $title, 'invalid' => '' );
+                       $pages[$fakeId] = array( 'title' => $title, 'invalid' => true );
                }
                // Report any missing page ids
                foreach ( $pageSet->getMissingPageIDs() as $pageid ) {
                        $pages[$pageid] = array(
                                'pageid' => $pageid,
-                               'missing' => ''
+                               'missing' => true
                        );
                }
                // Report special pages
@@ -422,15 +422,15 @@ class ApiQuery extends ApiBase {
                foreach ( $pageSet->getSpecialTitles() as $fakeId => $title ) {
                        $vals = array();
                        ApiQueryBase::addTitleInfo( $vals, $title );
-                       $vals['special'] = '';
+                       $vals['special'] = true;
                        if ( $title->isSpecialPage() &&
                                !SpecialPageFactory::exists( $title->getDBkey() )
                        ) {
-                               $vals['missing'] = '';
+                               $vals['missing'] = true;
                        } elseif ( $title->getNamespace() == NS_MEDIA &&
                                !wfFindFile( $title )
                        ) {
-                               $vals['missing'] = '';
+                               $vals['missing'] = true;
                        }
                        $pages[$fakeId] = $vals;
                }
@@ -445,6 +445,7 @@ class ApiQuery extends ApiBase {
 
                if ( count( $pages ) ) {
                        $pageSet->populateGeneratorData( $pages );
+                       ApiResult::setArrayType( $pages, 'BCarray' );
 
                        if ( $this->mParams['indexpageids'] ) {
                                $pageIDs = array_keys( $pages );
@@ -525,9 +526,8 @@ class ApiQuery extends ApiBase {
                        $result->addValue( null, 'text', $exportxml, ApiResult::NO_SIZE_CHECK );
                        $result->addValue( null, 'mime', 'text/xml', ApiResult::NO_SIZE_CHECK );
                } else {
-                       $r = array();
-                       ApiResult::setContentValue( $r, 'xml', $exportxml );
-                       $result->addValue( 'query', 'export', $r, ApiResult::NO_SIZE_CHECK );
+                       $result->addValue( 'query', 'export', $exportxml, ApiResult::NO_SIZE_CHECK );
+                       $result->addValue( 'query', ApiResult::META_BC_SUBELEMENTS, array( 'export' ) );
                }
        }
 
index 4ecc4b7..cc0b71a 100644 (file)
@@ -135,8 +135,8 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
                                        $item['files'] = intval( $row->cat_files );
                                        $item['subcats'] = intval( $row->cat_subcats );
                                }
-                               if ( isset( $prop['hidden'] ) && $row->cat_hidden ) {
-                                       $item['hidden'] = '';
+                               if ( isset( $prop['hidden'] ) ) {
+                                       $item['hidden'] = (bool)$row->cat_hidden;
                                }
                                $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $item );
                                if ( !$fit ) {
index 1a4a4d9..fadecfb 100644 (file)
@@ -200,7 +200,9 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                        }
 
                        if ( is_null( $resultPageSet ) ) {
-                               $vals = array();
+                               $vals = array(
+                                       ApiResult::META_TYPE => 'assoc',
+                               );
                                if ( $fld_ids ) {
                                        $vals['fromid'] = intval( $row->pl_from );
                                }
index 00816a3..44af83d 100644 (file)
@@ -146,7 +146,7 @@ class ApiQueryAllMessages extends ApiQueryBase {
                                        $messageIsCustomised = isset( $customisedMessages['pages'][$langObj->ucfirst( $message )] );
                                        if ( $customised === $messageIsCustomised ) {
                                                if ( $customised ) {
-                                                       $a['customised'] = '';
+                                                       $a['customised'] = true;
                                                }
                                        } else {
                                                continue;
@@ -156,7 +156,7 @@ class ApiQueryAllMessages extends ApiQueryBase {
                                $msg = wfMessage( $message, $args )->inLanguage( $langObj );
 
                                if ( !$msg->exists() ) {
-                                       $a['missing'] = '';
+                                       $a['missing'] = true;
                                } else {
                                        // Check if the parser is enabled:
                                        if ( $params['enableparser'] ) {
@@ -170,7 +170,7 @@ class ApiQueryAllMessages extends ApiQueryBase {
                                        if ( isset( $prop['default'] ) ) {
                                                $default = wfMessage( $message )->inLanguage( $langObj )->useDatabase( false );
                                                if ( !$default->exists() ) {
-                                                       $a['defaultmissing'] = '';
+                                                       $a['defaultmissing'] = true;
                                                } elseif ( $default->plain() != $msgString ) {
                                                        $a['default'] = $default->plain();
                                                }
index 8c9e1ba..d7354e2 100644 (file)
@@ -253,7 +253,7 @@ class ApiQueryAllUsers extends ApiQueryBase {
                                $data['blockexpiry'] = $row->ipb_expiry;
                        }
                        if ( $row->ipb_deleted ) {
-                               $data['hidden'] = '';
+                               $data['hidden'] = true;
                        }
                        if ( $fld_editcount ) {
                                $data['editcount'] = intval( $row->user_editcount );
index 92cf62d..1df14e0 100644 (file)
@@ -194,7 +194,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                                $a = array( 'pageid' => intval( $row->page_id ) );
                                ApiQueryBase::addTitleInfo( $a, $t );
                                if ( $row->page_is_redirect ) {
-                                       $a['redirect'] = '';
+                                       $a['redirect'] = true;
                                }
                                // Put all the results in an array first
                                $this->resultArr[$a['pageid']] = $a;
@@ -313,7 +313,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                                $a['pageid'] = intval( $row->page_id );
                                ApiQueryBase::addTitleInfo( $a, Title::makeTitle( $row->page_namespace, $row->page_title ) );
                                if ( $row->page_is_redirect ) {
-                                       $a['redirect'] = '';
+                                       $a['redirect'] = true;
                                }
                                $parentID = $this->pageMap[$ns][$row->{$this->bl_title}];
                                // Put all the results in an array first
index b4752ae..8e271e7 100644 (file)
@@ -287,8 +287,8 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
                                if ( $fld_fragment && $row->rd_fragment !== null && $row->rd_fragment !== '' ) {
                                        $vals['fragment'] = $row->rd_fragment;
                                }
-                               if ( $fld_redirect && $row->page_is_redirect ) {
-                                       $vals['redirect'] = '';
+                               if ( $fld_redirect ) {
+                                       $vals['redirect'] = (bool)$row->page_is_redirect;
                                }
                                $fit = $this->addPageSubItem( $id, $vals );
                                if ( !$fit ) {
index 72e4fef..4a7023b 100644 (file)
@@ -187,7 +187,9 @@ class ApiQueryBlocks extends ApiQueryBase {
                                $this->setContinueEnumParameter( 'continue', "$row->ipb_timestamp|$row->ipb_id" );
                                break;
                        }
-                       $block = array();
+                       $block = array(
+                               ApiResult::META_TYPE => 'assoc',
+                       );
                        if ( $fld_id ) {
                                $block['id'] = $row->ipb_id;
                        }
@@ -218,27 +220,13 @@ class ApiQueryBlocks extends ApiQueryBase {
                        }
                        if ( $fld_flags ) {
                                // For clarity, these flags use the same names as their action=block counterparts
-                               if ( $row->ipb_auto ) {
-                                       $block['automatic'] = '';
-                               }
-                               if ( $row->ipb_anon_only ) {
-                                       $block['anononly'] = '';
-                               }
-                               if ( $row->ipb_create_account ) {
-                                       $block['nocreate'] = '';
-                               }
-                               if ( $row->ipb_enable_autoblock ) {
-                                       $block['autoblock'] = '';
-                               }
-                               if ( $row->ipb_block_email ) {
-                                       $block['noemail'] = '';
-                               }
-                               if ( $row->ipb_deleted ) {
-                                       $block['hidden'] = '';
-                               }
-                               if ( $row->ipb_allow_usertalk ) {
-                                       $block['allowusertalk'] = '';
-                               }
+                               $block['automatic'] = (bool)$row->ipb_auto;
+                               $block['anononly'] = (bool)$row->ipb_anon_only;
+                               $block['nocreate'] = (bool)$row->ipb_create_account;
+                               $block['autoblock'] = (bool)$row->ipb_enable_autoblock;
+                               $block['noemail'] = (bool)$row->ipb_block_email;
+                               $block['hidden'] = (bool)$row->ipb_deleted;
+                               $block['allowusertalk'] = (bool)$row->ipb_allow_usertalk;
                        }
                        $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $block );
                        if ( !$fit ) {
index 6aa714e..35fa56e 100644 (file)
@@ -150,8 +150,8 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
                                if ( isset( $prop['timestamp'] ) ) {
                                        $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->cl_timestamp );
                                }
-                               if ( isset( $prop['hidden'] ) && !is_null( $row->pp_propname ) ) {
-                                       $vals['hidden'] = '';
+                               if ( isset( $prop['hidden'] ) ) {
+                                       $vals['hidden'] = !is_null( $row->pp_propname );
                                }
 
                                $fit = $this->addPageSubItem( $row->cl_from, $vals );
index 5c67ebf..9f6c604 100644 (file)
@@ -86,9 +86,7 @@ class ApiQueryCategoryInfo extends ApiQueryBase {
                        $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
                        $vals['files'] = intval( $row->cat_files );
                        $vals['subcats'] = intval( $row->cat_subcats );
-                       if ( $row->cat_hidden ) {
-                               $vals['hidden'] = '';
-                       }
+                       $vals['hidden'] = (bool)$row->cat_hidden;
                        $fit = $this->addPageSubItems( $catids[$row->cat_title], $vals );
                        if ( !$fit ) {
                                $this->setContinueEnumParameter( 'continue', $row->cat_title );
index 82ab939..ec0c1d1 100644 (file)
@@ -246,7 +246,9 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                        }
 
                        if ( is_null( $resultPageSet ) ) {
-                               $vals = array();
+                               $vals = array(
+                                       ApiResult::META_TYPE => 'assoc',
+                               );
                                if ( $fld_ids ) {
                                        $vals['pageid'] = intval( $row->page_id );
                                }
index b2c59d8..72a331f 100644 (file)
@@ -320,7 +320,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                        }
                        if ( $fld_user || $fld_userid ) {
                                if ( $row->ar_deleted & Revision::DELETED_USER ) {
-                                       $rev['userhidden'] = '';
+                                       $rev['userhidden'] = true;
                                        $anyHidden = true;
                                }
                                if ( Revision::userCanBitfield( $row->ar_deleted, Revision::DELETED_USER, $user ) ) {
@@ -335,7 +335,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
 
                        if ( $fld_comment || $fld_parsedcomment ) {
                                if ( $row->ar_deleted & Revision::DELETED_COMMENT ) {
-                                       $rev['commenthidden'] = '';
+                                       $rev['commenthidden'] = true;
                                        $anyHidden = true;
                                }
                                if ( Revision::userCanBitfield( $row->ar_deleted, Revision::DELETED_COMMENT, $user ) ) {
@@ -349,15 +349,15 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                                }
                        }
 
-                       if ( $fld_minor && $row->ar_minor_edit == 1 ) {
-                               $rev['minor'] = '';
+                       if ( $fld_minor ) {
+                               $rev['minor'] = $row->ar_minor_edit == 1;
                        }
                        if ( $fld_len ) {
                                $rev['len'] = $row->ar_len;
                        }
                        if ( $fld_sha1 ) {
                                if ( $row->ar_deleted & Revision::DELETED_TEXT ) {
-                                       $rev['sha1hidden'] = '';
+                                       $rev['sha1hidden'] = true;
                                        $anyHidden = true;
                                }
                                if ( Revision::userCanBitfield( $row->ar_deleted, Revision::DELETED_TEXT, $user ) ) {
@@ -370,7 +370,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                        }
                        if ( $fld_content ) {
                                if ( $row->ar_deleted & Revision::DELETED_TEXT ) {
-                                       $rev['texthidden'] = '';
+                                       $rev['texthidden'] = true;
                                        $anyHidden = true;
                                }
                                if ( Revision::userCanBitfield( $row->ar_deleted, Revision::DELETED_TEXT, $user ) ) {
@@ -394,7 +394,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                        }
 
                        if ( $anyHidden && ( $row->ar_deleted & Revision::DELETED_RESTRICTED ) ) {
-                               $rev['suppressed'] = '';
+                               $rev['suppressed'] = true;
                        }
 
                        if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
index 010f8d5..4d0bcfe 100644 (file)
@@ -137,11 +137,9 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
                                        $r = array(
                                                'name' => $dupName,
                                                'user' => $dupFile->getUser( 'text' ),
-                                               'timestamp' => wfTimestamp( TS_ISO_8601, $dupFile->getTimestamp() )
+                                               'timestamp' => wfTimestamp( TS_ISO_8601, $dupFile->getTimestamp() ),
+                                               'shared' => !$dupFile->isLocal(),
                                        );
-                                       if ( !$dupFile->isLocal() ) {
-                                               $r['shared'] = '';
-                                       }
                                        $fit = $this->addPageSubItem( $pageId, $r );
                                        if ( !$fit ) {
                                                $this->setContinueEnumParameter( 'continue', $image . '|' . $dupName );
index a26eff2..3f65a19 100644 (file)
@@ -112,7 +112,9 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
                        }
 
                        if ( is_null( $resultPageSet ) ) {
-                               $vals = array();
+                               $vals = array(
+                                       ApiResult::META_TYPE => 'assoc',
+                               );
                                if ( $fld_ids ) {
                                        $vals['pageid'] = intval( $row->page_id );
                                }
index 8896140..9ad7e27 100644 (file)
@@ -56,6 +56,8 @@ class ApiQueryFileRepoInfo extends ApiQueryBase {
 
                $result = $this->getResult();
                ApiResult::setIndexedTagName( $repos, 'repo' );
+               ApiResult::setArrayTypeRecursive( $repos, 'assoc' );
+               ApiResult::setArrayType( $repos, 'array' );
                $result->addValue( array( 'query' ), 'repos', $repos );
        }
 
index cba3b73..4d357a7 100644 (file)
@@ -218,17 +218,17 @@ class ApiQueryFilearchive extends ApiQueryBase {
                        }
 
                        if ( $row->fa_deleted & File::DELETED_FILE ) {
-                               $file['filehidden'] = '';
+                               $file['filehidden'] = true;
                        }
                        if ( $row->fa_deleted & File::DELETED_COMMENT ) {
-                               $file['commenthidden'] = '';
+                               $file['commenthidden'] = true;
                        }
                        if ( $row->fa_deleted & File::DELETED_USER ) {
-                               $file['userhidden'] = '';
+                               $file['userhidden'] = true;
                        }
                        if ( $row->fa_deleted & File::DELETED_RESTRICTED ) {
                                // This file is deleted for normal admins
-                               $file['suppressed'] = '';
+                               $file['suppressed'] = true;
                        }
 
                        $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $file );
index 61928c3..618387d 100644 (file)
@@ -132,7 +132,7 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase {
                                ApiQueryBase::addTitleInfo( $entry, $title );
 
                                if ( $row->page_is_redirect ) {
-                                       $entry['redirect'] = '';
+                                       $entry['redirect'] = true;
                                }
 
                                if ( $iwprefix ) {
index d5da495..94b4bbd 100644 (file)
@@ -373,7 +373,9 @@ class ApiQueryImageInfo extends ApiQueryBase {
                        );
                }
                $version = $opts['version'];
-               $vals = array();
+               $vals = array(
+                       ApiResult::META_TYPE => 'assoc',
+               );
                // Timestamp is shown even if the file is revdelete'd in interface
                // so do same here.
                if ( isset( $prop['timestamp'] ) ) {
@@ -397,7 +399,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
 
                if ( $user || $userid ) {
                        if ( $file->isDeleted( File::DELETED_USER ) ) {
-                               $vals['userhidden'] = '';
+                               $vals['userhidden'] = true;
                                $anyHidden = true;
                        }
                        if ( $canShowField( File::DELETED_USER ) ) {
@@ -408,7 +410,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                        $vals['userid'] = $file->getUser( 'id' );
                                }
                                if ( !$file->getUser( 'id' ) ) {
-                                       $vals['anon'] = '';
+                                       $vals['anon'] = true;
                                }
                        }
                }
@@ -438,7 +440,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
 
                if ( $pcomment || $comment ) {
                        if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
-                               $vals['commenthidden'] = '';
+                               $vals['commenthidden'] = true;
                                $anyHidden = true;
                        }
                        if ( $canShowField( File::DELETED_COMMENT ) ) {
@@ -469,7 +471,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                }
 
                if ( $file->isDeleted( File::DELETED_FILE ) ) {
-                       $vals['filehidden'] = '';
+                       $vals['filehidden'] = true;
                        $anyHidden = true;
                }
 
index db28df7..66178d4 100644 (file)
@@ -395,10 +395,10 @@ class ApiQueryInfo extends ApiQueryBase {
                        $pageInfo['length'] = intval( $this->pageLength[$pageid] );
 
                        if ( isset( $this->pageIsRedir[$pageid] ) && $this->pageIsRedir[$pageid] ) {
-                               $pageInfo['redirect'] = '';
+                               $pageInfo['redirect'] = true;
                        }
                        if ( $this->pageIsNew[$pageid] ) {
-                               $pageInfo['new'] = '';
+                               $pageInfo['new'] = true;
                        }
                }
 
@@ -431,8 +431,8 @@ class ApiQueryInfo extends ApiQueryBase {
                        ApiResult::setIndexedTagName( $pageInfo['restrictiontypes'], 'rt' );
                }
 
-               if ( $this->fld_watched && isset( $this->watched[$ns][$dbkey] ) ) {
-                       $pageInfo['watched'] = '';
+               if ( $this->fld_watched ) {
+                       $pageInfo['watched'] = isset( $this->watched[$ns][$dbkey] );
                }
 
                if ( $this->fld_watchers ) {
@@ -464,8 +464,8 @@ class ApiQueryInfo extends ApiQueryBase {
                        $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT );
                        $pageInfo['canonicalurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CANONICAL );
                }
-               if ( $this->fld_readable && $title->userCan( 'read', $this->getUser() ) ) {
-                       $pageInfo['readable'] = '';
+               if ( $this->fld_readable ) {
+                       $pageInfo['readable'] = $title->userCan( 'read', $this->getUser() );
                }
 
                if ( $this->fld_preload ) {
@@ -497,9 +497,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        $pageInfo['actions'] = array();
                        foreach ( $this->params['testactions'] as $action ) {
                                $this->countTestedActions++;
-                               if ( $title->userCan( $action, $user ) ) {
-                                       $pageInfo['actions'][$action] = '';
-                               }
+                               $pageInfo['actions'][$action] = $title->userCan( $action, $user );
                        }
                }
 
@@ -532,7 +530,7 @@ class ApiQueryInfo extends ApiQueryBase {
                                        'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 )
                                );
                                if ( $row->pr_cascade ) {
-                                       $a['cascade'] = '';
+                                       $a['cascade'] = true;
                                }
                                $this->protections[$title->getNamespace()][$title->getDBkey()][] = $a;
                        }
index 885d10c..7be18b2 100644 (file)
@@ -131,7 +131,7 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase {
                                ApiQueryBase::addTitleInfo( $entry, $title );
 
                                if ( $row->page_is_redirect ) {
-                                       $entry['redirect'] = '';
+                                       $entry['redirect'] = true;
                                }
 
                                if ( $lllang ) {
index 553747e..7b2381f 100644 (file)
@@ -230,9 +230,6 @@ class ApiQueryLogEvents extends ApiQueryBase {
                        }
 
                        $vals = $this->extractRowInfo( $row );
-                       if ( !$vals ) {
-                               continue;
-                       }
                        $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
                        if ( !$fit ) {
                                $this->setContinueEnumParameter( 'continue', "$row->log_timestamp|$row->log_id" );
@@ -270,7 +267,9 @@ class ApiQueryLogEvents extends ApiQueryBase {
 
        private function extractRowInfo( $row ) {
                $logEntry = DatabaseLogEntry::newFromRow( $row );
-               $vals = array();
+               $vals = array(
+                       ApiResult::META_TYPE => 'assoc',
+               );
                $anyHidden = false;
                $user = $this->getUser();
 
@@ -284,7 +283,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
 
                if ( $this->fld_title || $this->fld_ids || $this->fld_details && $row->log_params !== '' ) {
                        if ( LogEventsList::isDeleted( $row, LogPage::DELETED_ACTION ) ) {
-                               $vals['actionhidden'] = '';
+                               $vals['actionhidden'] = true;
                                $anyHidden = true;
                        }
                        if ( LogEventsList::userCan( $row, LogPage::DELETED_ACTION, $user ) ) {
@@ -308,7 +307,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
 
                if ( $this->fld_user || $this->fld_userid ) {
                        if ( LogEventsList::isDeleted( $row, LogPage::DELETED_USER ) ) {
-                               $vals['userhidden'] = '';
+                               $vals['userhidden'] = true;
                                $anyHidden = true;
                        }
                        if ( LogEventsList::userCan( $row, LogPage::DELETED_USER, $user ) ) {
@@ -320,7 +319,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
                                }
 
                                if ( !$row->log_user ) {
-                                       $vals['anon'] = '';
+                                       $vals['anon'] = true;
                                }
                        }
                }
@@ -330,7 +329,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
 
                if ( ( $this->fld_comment || $this->fld_parsedcomment ) && isset( $row->log_comment ) ) {
                        if ( LogEventsList::isDeleted( $row, LogPage::DELETED_COMMENT ) ) {
-                               $vals['commenthidden'] = '';
+                               $vals['commenthidden'] = true;
                                $anyHidden = true;
                        }
                        if ( LogEventsList::userCan( $row, LogPage::DELETED_COMMENT, $user ) ) {
@@ -355,7 +354,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
                }
 
                if ( $anyHidden && LogEventsList::isDeleted( $row, LogPage::DELETED_RESTRICTED ) ) {
-                       $vals['suppressed'] = '';
+                       $vals['suppressed'] = true;
                }
 
                return $vals;
index 269afb1..dd19bf2 100644 (file)
@@ -110,6 +110,7 @@ class ApiQueryPageProps extends ApiQueryBase {
         * @return bool True if it fits in the result
         */
        private function addPageProps( $result, $page, $props ) {
+               ApiResult::setArrayType( $props, 'assoc' );
                $fit = $result->addValue( array( 'query', 'pages', $page ), 'pageprops', $props );
 
                if ( !$fit ) {
index 143bc06..7bcaf24 100644 (file)
@@ -99,7 +99,9 @@ class ApiQueryPagesWithProp extends ApiQueryGeneratorBase {
                        }
 
                        if ( $resultPageSet === null ) {
-                               $vals = array();
+                               $vals = array(
+                                       ApiResult::META_TYPE => 'assoc',
+                               );
                                if ( $fld_ids ) {
                                        $vals['pageid'] = (int)$row->page_id;
                                }
index 35942ca..8eb644f 100644 (file)
@@ -69,7 +69,7 @@ class ApiQueryPrefixSearch extends ApiQueryGeneratorBase {
                                        'title' => $title->getPrefixedText(),
                                );
                                if ( $title->isSpecialPage() ) {
-                                       $vals['special'] = '';
+                                       $vals['special'] = true;
                                } else {
                                        $vals['pageid'] = intval( $title->getArticleId() );
                                }
index 062a44f..650ac8f 100644 (file)
@@ -68,9 +68,9 @@ class ApiQueryQueryPage extends ApiQueryGeneratorBase {
                $r = array( 'name' => $params['page'] );
                if ( $qp->isCached() ) {
                        if ( !$qp->isCacheable() ) {
-                               $r['disabled'] = '';
+                               $r['disabled'] = true;
                        } else {
-                               $r['cached'] = '';
+                               $r['cached'] = true;
                                $ts = $qp->getCachedTimestamp();
                                if ( $ts ) {
                                        $r['cachedtimestamp'] = wfTimestamp( TS_ISO_8601, $ts );
index 28f8b7d..f6a6478 100644 (file)
@@ -384,9 +384,6 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                                $vals = $this->extractRowInfo( $row );
 
                                /* Add that row's data to our final output. */
-                               if ( !$vals ) {
-                                       continue;
-                               }
                                $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
                                if ( !$fit ) {
                                        $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
@@ -428,7 +425,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                /* Create a new entry in the result for the title. */
                if ( $this->fld_title || $this->fld_ids ) {
                        if ( $type === RC_LOG && ( $row->rc_deleted & LogPage::DELETED_ACTION ) ) {
-                               $vals['actionhidden'] = '';
+                               $vals['actionhidden'] = true;
                                $anyHidden = true;
                        }
                        if ( $type !== RC_LOG ||
@@ -452,7 +449,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                /* Add user data and 'anon' flag, if user is anonymous. */
                if ( $this->fld_user || $this->fld_userid ) {
                        if ( $row->rc_deleted & Revision::DELETED_USER ) {
-                               $vals['userhidden'] = '';
+                               $vals['userhidden'] = true;
                                $anyHidden = true;
                        }
                        if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_USER, $user ) ) {
@@ -465,22 +462,16 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                                }
 
                                if ( !$row->rc_user ) {
-                                       $vals['anon'] = '';
+                                       $vals['anon'] = true;
                                }
                        }
                }
 
                /* Add flags, such as new, minor, bot. */
                if ( $this->fld_flags ) {
-                       if ( $row->rc_bot ) {
-                               $vals['bot'] = '';
-                       }
-                       if ( $row->rc_type == RC_NEW ) {
-                               $vals['new'] = '';
-                       }
-                       if ( $row->rc_minor ) {
-                               $vals['minor'] = '';
-                       }
+                       $vals['bot'] = (bool)$row->rc_bot;
+                       $vals['new'] = $row->rc_type == RC_NEW;
+                       $vals['minor'] = (bool)$row->rc_minor;
                }
 
                /* Add sizes of each revision. (Only available on 1.10+) */
@@ -497,7 +488,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                /* Add edit summary / log summary. */
                if ( $this->fld_comment || $this->fld_parsedcomment ) {
                        if ( $row->rc_deleted & Revision::DELETED_COMMENT ) {
-                               $vals['commenthidden'] = '';
+                               $vals['commenthidden'] = true;
                                $anyHidden = true;
                        }
                        if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_COMMENT, $user ) ) {
@@ -512,23 +503,18 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                }
 
                if ( $this->fld_redirect ) {
-                       if ( $row->page_is_redirect ) {
-                               $vals['redirect'] = '';
-                       }
+                       $vals['redirect'] = (bool)$row->page_is_redirect;
                }
 
                /* Add the patrolled flag */
-               if ( $this->fld_patrolled && $row->rc_patrolled == 1 ) {
-                       $vals['patrolled'] = '';
-               }
-
-               if ( $this->fld_patrolled && ChangesList::isUnpatrolled( $row, $user ) ) {
-                       $vals['unpatrolled'] = '';
+               if ( $this->fld_patrolled ) {
+                       $vals['patrolled'] = $row->rc_patrolled == 1;
+                       $vals['unpatrolled'] = ChangesList::isUnpatrolled( $row, $user );
                }
 
                if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
                        if ( $row->rc_deleted & LogPage::DELETED_ACTION ) {
-                               $vals['actionhidden'] = '';
+                               $vals['actionhidden'] = true;
                                $anyHidden = true;
                        }
                        if ( LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user ) ) {
@@ -551,7 +537,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
 
                if ( $this->fld_sha1 && $row->rev_sha1 !== null ) {
                        if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
-                               $vals['sha1hidden'] = '';
+                               $vals['sha1hidden'] = true;
                                $anyHidden = true;
                        }
                        if ( Revision::userCanBitfield( $row->rev_deleted, Revision::DELETED_TEXT, $user ) ) {
@@ -577,7 +563,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                }
 
                if ( $anyHidden && ( $row->rc_deleted & Revision::DELETED_RESTRICTED ) ) {
-                       $vals['suppressed'] = '';
+                       $vals['suppressed'] = true;
                }
 
                return $vals;
index 1805f40..64f6120 100644 (file)
@@ -168,13 +168,13 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
                        }
                }
 
-               if ( $this->fld_flags && $revision->isMinor() ) {
-                       $vals['minor'] = '';
+               if ( $this->fld_flags ) {
+                       $vals['minor'] = $revision->isMinor();
                }
 
                if ( $this->fld_user || $this->fld_userid ) {
                        if ( $revision->isDeleted( Revision::DELETED_USER ) ) {
-                               $vals['userhidden'] = '';
+                               $vals['userhidden'] = true;
                                $anyHidden = true;
                        }
                        if ( $revision->userCan( Revision::DELETED_USER, $user ) ) {
@@ -183,7 +183,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
                                }
                                $userid = $revision->getUser( Revision::RAW );
                                if ( !$userid ) {
-                                       $vals['anon'] = '';
+                                       $vals['anon'] = true;
                                }
 
                                if ( $this->fld_userid ) {
@@ -206,7 +206,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
 
                if ( $this->fld_sha1 ) {
                        if ( $revision->isDeleted( Revision::DELETED_TEXT ) ) {
-                               $vals['sha1hidden'] = '';
+                               $vals['sha1hidden'] = true;
                                $anyHidden = true;
                        }
                        if ( $revision->userCan( Revision::DELETED_TEXT, $user ) ) {
@@ -224,7 +224,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
 
                if ( $this->fld_comment || $this->fld_parsedcomment ) {
                        if ( $revision->isDeleted( Revision::DELETED_COMMENT ) ) {
-                               $vals['commenthidden'] = '';
+                               $vals['commenthidden'] = true;
                                $anyHidden = true;
                        }
                        if ( $revision->userCan( Revision::DELETED_COMMENT, $user ) ) {
@@ -267,10 +267,10 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
                                }
                        }
                        if ( $revision->isDeleted( Revision::DELETED_TEXT ) ) {
-                               $vals['texthidden'] = '';
+                               $vals['texthidden'] = true;
                                $anyHidden = true;
                        } elseif ( !$content ) {
-                               $vals['textmissing'] = '';
+                               $vals['textmissing'] = true;
                        }
                }
                if ( $this->fld_content && $content ) {
@@ -293,7 +293,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
                                        }
                                        $vals['parsetree'] = $xml;
                                } else {
-                                       $vals['badcontentformatforparsetree'] = '';
+                                       $vals['badcontentformatforparsetree'] = true;
                                        $this->setWarning( "Conversion to XML is supported for wikitext only, " .
                                                $title->getPrefixedDBkey() .
                                                " uses content model " . $content->getModel() );
@@ -314,7 +314,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
                                        $this->setWarning( "Template expansion is supported for wikitext only, " .
                                                $title->getPrefixedDBkey() .
                                                " uses content model " . $content->getModel() );
-                                       $vals['badcontentformat'] = '';
+                                       $vals['badcontentformat'] = true;
                                        $text = false;
                                }
                        }
@@ -335,7 +335,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
                                        $name = $title->getPrefixedDBkey();
                                        $this->setWarning( "The requested format {$this->contentFormat} is not " .
                                                "supported for content model $model used by $name" );
-                                       $vals['badcontentformat'] = '';
+                                       $vals['badcontentformat'] = true;
                                        $text = false;
                                } else {
                                        $text = $content->serialize( $format );
@@ -369,7 +369,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
                                                $name = $title->getPrefixedDBkey();
                                                $this->setWarning( "The requested format {$this->contentFormat} is not " .
                                                        "supported for content model $model used by $name" );
-                                               $vals['diff']['badcontentformat'] = '';
+                                               $vals['diff']['badcontentformat'] = true;
                                                $engine = null;
                                        } else {
                                                $difftocontent = ContentHandler::makeContent(
@@ -395,12 +395,12 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
                                        }
                                }
                        } else {
-                               $vals['diff']['notcached'] = '';
+                               $vals['diff']['notcached'] = true;
                        }
                }
 
                if ( $anyHidden && $revision->isDeleted( Revision::DELETED_RESTRICTED ) ) {
-                       $vals['suppressed'] = '';
+                       $vals['suppressed'] = true;
                }
 
                return $vals;
index 22447f7..b81e993 100644 (file)
@@ -150,9 +150,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $allowFrom = array( '' );
                $allowException = true;
                if ( !$config->get( 'AllowExternalImages' ) ) {
-                       if ( $config->get( 'EnableImageWhitelist' ) ) {
-                               $data['imagewhitelistenabled'] = '';
-                       }
+                       $data['imagewhitelistenabled'] = (bool)$config->get( 'EnableImageWhitelist' );
                        $allowFrom = $config->get( 'AllowExternalImagesFrom' );
                        $allowException = !empty( $allowFrom );
                }
@@ -161,13 +159,8 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        ApiResult::setIndexedTagName( $data['externalimages'], 'prefix' );
                }
 
-               if ( !$config->get( 'DisableLangConversion' ) ) {
-                       $data['langconversion'] = '';
-               }
-
-               if ( !$config->get( 'DisableTitleConversion' ) ) {
-                       $data['titleconversion'] = '';
-               }
+               $data['langconversion'] = !$config->get( 'DisableLangConversion' );
+               $data['titleconversion'] = !$config->get( 'DisableTitleConversion' );
 
                if ( $wgContLang->linkPrefixExtension() ) {
                        $linkPrefixCharset = $wgContLang->linkPrefixCharset();
@@ -180,11 +173,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                }
 
                $linktrail = $wgContLang->linkTrail();
-               if ( $linktrail ) {
-                       $data['linktrail'] = $linktrail;
-               } else {
-                       $data['linktrail'] = '';
-               }
+               $data['linktrail'] = $linktrail ?: '';
 
                $data['legaltitlechars'] = Title::legalChars();
 
@@ -224,18 +213,14 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        ApiResult::setIndexedTagName( $data['variants'], 'lang' );
                }
 
-               if ( $wgContLang->isRTL() ) {
-                       $data['rtl'] = '';
-               }
+               $data['rtl'] = $wgContLang->isRTL();
                $data['fallback8bitEncoding'] = $wgContLang->fallback8bitEncoding();
 
-               if ( wfReadOnly() ) {
-                       $data['readonly'] = '';
+               $data['readonly'] = wfReadOnly();
+               if ( $data['readonly'] ) {
                        $data['readonlyreason'] = wfReadOnlyReason();
                }
-               if ( $config->get( 'EnableWriteAPI' ) ) {
-                       $data['writeapi'] = '';
-               }
+               $data['writeapi'] = (bool)$config->get( 'EnableWriteAPI' );
 
                $tz = $config->get( 'Localtimezone' );
                $offset = $config->get( 'LocalTZoffset' );
@@ -251,20 +236,21 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $data['scriptpath'] = $config->get( 'ScriptPath' );
                $data['script'] = $config->get( 'Script' );
                $data['variantarticlepath'] = $config->get( 'VariantArticlePath' );
+               $data[ApiResult::META_BC_BOOLS][] = 'variantarticlepath';
                $data['server'] = $config->get( 'Server' );
                $data['servername'] = $config->get( 'ServerName' );
                $data['wikiid'] = wfWikiID();
                $data['time'] = wfTimestamp( TS_ISO_8601, time() );
 
-               if ( $config->get( 'MiserMode' ) ) {
-                       $data['misermode'] = '';
-               }
+               $data['misermode'] = (bool)$config->get( 'MiserMode' );
 
                $data['maxuploadsize'] = UploadBase::getMaxUploadSize();
 
                $data['thumblimits'] = $config->get( 'ThumbLimits' );
+               ApiResult::setArrayType( $data['thumblimits'], 'BCassoc' );
                ApiResult::setIndexedTagName( $data['thumblimits'], 'limit' );
                $data['imagelimits'] = array();
+               ApiResult::setArrayType( $data['imagelimits'], 'BCassoc' );
                ApiResult::setIndexedTagName( $data['imagelimits'], 'limit' );
                foreach ( $config->get( 'ImageLimits' ) as $k => $limit ) {
                        $data['imagelimits'][$k] = array( 'width' => $limit[0], 'height' => $limit[1] );
@@ -284,7 +270,9 @@ class ApiQuerySiteinfo extends ApiQueryBase {
 
        protected function appendNamespaces( $property ) {
                global $wgContLang;
-               $data = array();
+               $data = array(
+                       ApiResult::META_TYPE => 'assoc',
+               );
                foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
                        $data[$ns] = array(
                                'id' => intval( $ns ),
@@ -293,21 +281,14 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        ApiResult::setContentValue( $data[$ns], 'name', $title );
                        $canonical = MWNamespace::getCanonicalName( $ns );
 
-                       if ( MWNamespace::hasSubpages( $ns ) ) {
-                               $data[$ns]['subpages'] = '';
-                       }
+                       $data[$ns]['subpages'] = MWNamespace::hasSubpages( $ns );
 
                        if ( $canonical ) {
                                $data[$ns]['canonical'] = strtr( $canonical, '_', ' ' );
                        }
 
-                       if ( MWNamespace::isContent( $ns ) ) {
-                               $data[$ns]['content'] = '';
-                       }
-
-                       if ( MWNamespace::isNonincludable( $ns ) ) {
-                               $data[$ns]['nonincludable'] = '';
-                       }
+                       $data[$ns]['content'] = MWNamespace::isContent( $ns );
+                       $data[$ns]['nonincludable'] = MWNamespace::isNonincludable( $ns );
 
                        $contentmodel = MWNamespace::getNamespaceContentModel( $ns );
                        if ( $contentmodel ) {
@@ -367,9 +348,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                foreach ( $wgContLang->getMagicWords() as $magicword => $aliases ) {
                        $caseSensitive = array_shift( $aliases );
                        $arr = array( 'name' => $magicword, 'aliases' => $aliases );
-                       if ( $caseSensitive ) {
-                               $arr['case-sensitive'] = '';
-                       }
+                       $arr['case-sensitive'] = (bool)$caseSensitive;
                        ApiResult::setIndexedTagName( $arr['aliases'], 'alias' );
                        $data[] = $arr;
                }
@@ -402,20 +381,20 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        $val = array();
                        $val['prefix'] = $prefix;
                        if ( isset( $row['iw_local'] ) && $row['iw_local'] == '1' ) {
-                               $val['local'] = '';
+                               $val['local'] = true;
                        }
                        if ( isset( $row['iw_trans'] ) && $row['iw_trans'] == '1' ) {
-                               $val['trans'] = '';
+                               $val['trans'] = true;
                        }
 
                        if ( isset( $langNames[$prefix] ) ) {
                                $val['language'] = $langNames[$prefix];
                        }
                        if ( in_array( $prefix, $localInterwikis ) ) {
-                               $val['localinterwiki'] = '';
+                               $val['localinterwiki'] = true;
                        }
                        if ( in_array( $prefix, $extraLangPrefixes ) ) {
-                               $val['extralanglink'] = '';
+                               $val['extralanglink'] = true;
 
                                $linktext = wfMessage( "interlanguage-link-$prefix" );
                                if ( !$linktext->isDisabled() ) {
@@ -429,9 +408,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        }
 
                        $val['url'] = wfExpandUrl( $row['iw_url'], PROTO_CURRENT );
-                       if ( substr( $row['iw_url'], 0, 2 ) == '//' ) {
-                               $val['protorel'] = '';
-                       }
+                       $val['protorel'] = substr( $row['iw_url'], 0, 2 ) == '//';
                        if ( isset( $row['iw_wikiid'] ) && $row['iw_wikiid'] !== '' ) {
                                $val['wikiid'] = $row['iw_wikiid'];
                        }
@@ -747,10 +724,10 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        $skin = array( 'code' => $name );
                        ApiResult::setContentValue( $skin, 'name', $displayName );
                        if ( !isset( $allowed[$name] ) ) {
-                               $skin['unusable'] = '';
+                               $skin['unusable'] = true;
                        }
                        if ( $name === $default ) {
-                               $skin['default'] = '';
+                               $skin['default'] = true;
                        }
                        $data[] = $skin;
                }
@@ -793,7 +770,9 @@ class ApiQuerySiteinfo extends ApiQueryBase {
        }
 
        public function appendDefaultOptions( $property ) {
-               return $this->getResult()->addValue( 'query', $property, User::getDefaultOptions() );
+               $options = User::getDefaultOptions();
+               $options[ApiResult::META_BC_BOOLS] = array_keys( $options );
+               return $this->getResult()->addValue( 'query', $property, $options );
        }
 
        private function formatParserTags( $item ) {
index aa91216..45f73b2 100644 (file)
@@ -108,8 +108,8 @@ class ApiQueryTags extends ApiQueryBase {
                        $isExtension = isset( $extensionDefinedTags[$tagName] );
                        $isExplicit = isset( $explicitlyDefinedTags[$tagName] );
 
-                       if ( $fld_defined && ( $isExtension || $isExplicit ) ) {
-                               $tag['defined'] = '';
+                       if ( $fld_defined ) {
+                               $tag['defined'] = $isExtension || $isExplicit;
                        }
 
                        if ( $fld_source ) {
@@ -122,10 +122,8 @@ class ApiQueryTags extends ApiQueryBase {
                                }
                        }
 
-                       if ( $fld_active &&
-                               ( $isExplicit || isset( $extensionActivatedTags[$tagName] ) )
-                       ) {
-                               $tag['active'] = '';
+                       if ( $fld_active ) {
+                               $tag['active'] = $isExplicit || isset( $extensionActivatedTags[$tagName] );
                        }
 
                        $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $tag );
index f8eee8d..65a08a3 100644 (file)
@@ -35,7 +35,9 @@ class ApiQueryTokens extends ApiQueryBase {
 
        public function execute() {
                $params = $this->extractRequestParams();
-               $res = array();
+               $res = array(
+                       ApiResult::META_TYPE => 'assoc',
+               );
 
                if ( $this->lacksSameOriginSecurity() ) {
                        $this->setWarning( 'Tokens may not be obtained when the same-origin policy is not applied' );
index f6c6356..e5ec67d 100644 (file)
@@ -335,7 +335,7 @@ class ApiQueryContributions extends ApiQueryBase {
                $anyHidden = false;
 
                if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
-                       $vals['texthidden'] = '';
+                       $vals['texthidden'] = true;
                        $anyHidden = true;
                }
 
@@ -343,7 +343,7 @@ class ApiQueryContributions extends ApiQueryBase {
                $vals['userid'] = $row->rev_user;
                $vals['user'] = $row->rev_user_text;
                if ( $row->rev_deleted & Revision::DELETED_USER ) {
-                       $vals['userhidden'] = '';
+                       $vals['userhidden'] = true;
                        $anyHidden = true;
                }
                if ( $this->fld_ids ) {
@@ -367,20 +367,14 @@ class ApiQueryContributions extends ApiQueryBase {
                }
 
                if ( $this->fld_flags ) {
-                       if ( $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id ) ) {
-                               $vals['new'] = '';
-                       }
-                       if ( $row->rev_minor_edit ) {
-                               $vals['minor'] = '';
-                       }
-                       if ( $row->page_latest == $row->rev_id ) {
-                               $vals['top'] = '';
-                       }
+                       $vals['new'] = $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id );
+                       $vals['minor'] = (bool)$row->rev_minor_edit;
+                       $vals['top'] = $row->page_latest == $row->rev_id;
                }
 
                if ( ( $this->fld_comment || $this->fld_parsedcomment ) && isset( $row->rev_comment ) ) {
                        if ( $row->rev_deleted & Revision::DELETED_COMMENT ) {
-                               $vals['commenthidden'] = '';
+                               $vals['commenthidden'] = true;
                                $anyHidden = true;
                        }
 
@@ -400,8 +394,8 @@ class ApiQueryContributions extends ApiQueryBase {
                        }
                }
 
-               if ( $this->fld_patrolled && $row->rc_patrolled ) {
-                       $vals['patrolled'] = '';
+               if ( $this->fld_patrolled ) {
+                       $vals['patrolled'] = (bool)$row->rc_patrolled;
                }
 
                if ( $this->fld_size && !is_null( $row->rev_len ) ) {
@@ -429,7 +423,7 @@ class ApiQueryContributions extends ApiQueryBase {
                }
 
                if ( $anyHidden && $row->rev_deleted & Revision::DELETED_RESTRICTED ) {
-                       $vals['suppressed'] = '';
+                       $vals['suppressed'] = true;
                }
 
                return $vals;
index fd095fc..3d3590c 100644 (file)
@@ -61,7 +61,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
                $vals['name'] = $user->getName();
 
                if ( $user->isAnon() ) {
-                       $vals['anon'] = '';
+                       $vals['anon'] = true;
                }
 
                if ( isset( $this->prop['blockinfo'] ) ) {
@@ -78,23 +78,26 @@ class ApiQueryUserInfo extends ApiQueryBase {
                        }
                }
 
-               if ( isset( $this->prop['hasmsg'] ) && $user->getNewtalk() ) {
-                       $vals['messages'] = '';
+               if ( isset( $this->prop['hasmsg'] ) ) {
+                       $vals['messages'] = $user->getNewtalk();
                }
 
                if ( isset( $this->prop['groups'] ) ) {
                        $vals['groups'] = $user->getEffectiveGroups();
+                       ApiResult::setArrayType( $vals['groups'], 'array' ); // even if empty
                        ApiResult::setIndexedTagName( $vals['groups'], 'g' ); // even if empty
                }
 
                if ( isset( $this->prop['implicitgroups'] ) ) {
                        $vals['implicitgroups'] = $user->getAutomaticGroups();
+                       ApiResult::setArrayType( $vals['implicitgroups'], 'array' ); // even if empty
                        ApiResult::setIndexedTagName( $vals['implicitgroups'], 'g' ); // even if empty
                }
 
                if ( isset( $this->prop['rights'] ) ) {
                        // User::getRights() may return duplicate values, strip them
                        $vals['rights'] = array_values( array_unique( $user->getRights() ) );
+                       ApiResult::setArrayType( $vals['rights'], 'array' ); // even if empty
                        ApiResult::setIndexedTagName( $vals['rights'], 'r' ); // even if empty
                }
 
@@ -108,6 +111,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
 
                if ( isset( $this->prop['options'] ) ) {
                        $vals['options'] = $user->getOptions();
+                       $vals['options'][ApiResult::META_BC_BOOLS] = array_keys( $vals['options'] );
                }
 
                if ( isset( $this->prop['preferencestoken'] ) ) {
@@ -191,9 +195,13 @@ class ApiQueryUserInfo extends ApiQueryBase {
        }
 
        protected function getRateLimits() {
+               $retval = array(
+                       ApiResult::META_TYPE => 'assoc',
+               );
+
                $user = $this->getUser();
                if ( !$user->isPingLimitable() ) {
-                       return array(); // No limits
+                       return $retval; // No limits
                }
 
                // Find out which categories we belong to
@@ -213,7 +221,6 @@ class ApiQueryUserInfo extends ApiQueryBase {
                $categories = array_merge( $categories, $user->getGroups() );
 
                // Now get the actual limits
-               $retval = array();
                foreach ( $this->getConfig()->get( 'RateLimits' ) as $action => $limits ) {
                        foreach ( $categories as $cat ) {
                                if ( isset( $limits[$cat] ) && !is_null( $limits[$cat] ) ) {
index e2c47f5..f22c213 100644 (file)
@@ -110,7 +110,7 @@ class ApiQueryUsers extends ApiQueryBase {
                foreach ( $users as $u ) {
                        $n = User::getCanonicalName( $u );
                        if ( $n === false || $n === '' ) {
-                               $vals = array( 'name' => $u, 'invalid' => '' );
+                               $vals = array( 'name' => $u, 'invalid' => true );
                                $fit = $result->addValue( array( 'query', $this->getModuleName() ),
                                        null, $vals );
                                if ( !$fit ) {
@@ -190,7 +190,7 @@ class ApiQueryUsers extends ApiQueryBase {
                                        $data[$name]['rights'] = $user->getRights();
                                }
                                if ( $row->ipb_deleted ) {
-                                       $data[$name]['hidden'] = '';
+                                       $data[$name]['hidden'] = true;
                                }
                                if ( isset( $this->prop['blockinfo'] ) && !is_null( $row->ipb_by_text ) ) {
                                        $data[$name]['blockid'] = $row->ipb_id;
@@ -201,8 +201,8 @@ class ApiQueryUsers extends ApiQueryBase {
                                        $data[$name]['blockexpiry'] = $row->ipb_expiry;
                                }
 
-                               if ( isset( $this->prop['emailable'] ) && $user->canReceiveEmail() ) {
-                                       $data[$name]['emailable'] = '';
+                               if ( isset( $this->prop['emailable'] ) ) {
+                                       $data[$name]['emailable'] = $user->canReceiveEmail();
                                }
 
                                if ( isset( $this->prop['gender'] ) ) {
@@ -237,7 +237,7 @@ class ApiQueryUsers extends ApiQueryBase {
                                $iwUser = $urPage->fetchUser( $u );
 
                                if ( $iwUser instanceof UserRightsProxy ) {
-                                       $data[$u]['interwiki'] = '';
+                                       $data[$u]['interwiki'] = true;
 
                                        if ( !is_null( $params['token'] ) ) {
                                                $tokenFunctions = $this->getTokenFunctions();
@@ -252,16 +252,19 @@ class ApiQueryUsers extends ApiQueryBase {
                                                }
                                        }
                                } else {
-                                       $data[$u]['missing'] = '';
+                                       $data[$u]['missing'] = true;
                                }
                        } else {
                                if ( isset( $this->prop['groups'] ) && isset( $data[$u]['groups'] ) ) {
+                                       ApiResult::setArrayType( $data[$u]['groups'], 'array' );
                                        ApiResult::setIndexedTagName( $data[$u]['groups'], 'g' );
                                }
                                if ( isset( $this->prop['implicitgroups'] ) && isset( $data[$u]['implicitgroups'] ) ) {
+                                       ApiResult::setArrayType( $data[$u]['implicitgroups'], 'array' );
                                        ApiResult::setIndexedTagName( $data[$u]['implicitgroups'], 'g' );
                                }
                                if ( isset( $this->prop['rights'] ) && isset( $data[$u]['rights'] ) ) {
+                                       ApiResult::setArrayType( $data[$u]['rights'], 'array' );
                                        ApiResult::setIndexedTagName( $data[$u]['rights'], 'r' );
                                }
                        }
index bd1ed0a..9f7387c 100644 (file)
@@ -307,7 +307,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                if ( $this->fld_title || $this->fld_ids ) {
                        // These should already have been filtered out of the query, but just in case.
                        if ( $type === RC_LOG && ( $row->rc_deleted & LogPage::DELETED_ACTION ) ) {
-                               $vals['actionhidden'] = '';
+                               $vals['actionhidden'] = true;
                                $anyHidden = true;
                        }
                        if ( $type !== RC_LOG ||
@@ -327,7 +327,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                /* Add user data and 'anon' flag, if user is anonymous. */
                if ( $this->fld_user || $this->fld_userid ) {
                        if ( $row->rc_deleted & Revision::DELETED_USER ) {
-                               $vals['userhidden'] = '';
+                               $vals['userhidden'] = true;
                                $anyHidden = true;
                        }
                        if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_USER, $user ) ) {
@@ -342,22 +342,16 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                                }
 
                                if ( !$row->rc_user ) {
-                                       $vals['anon'] = '';
+                                       $vals['anon'] = true;
                                }
                        }
                }
 
                /* Add flags, such as new, minor, bot. */
                if ( $this->fld_flags ) {
-                       if ( $row->rc_bot ) {
-                               $vals['bot'] = '';
-                       }
-                       if ( $row->rc_type == RC_NEW ) {
-                               $vals['new'] = '';
-                       }
-                       if ( $row->rc_minor ) {
-                               $vals['minor'] = '';
-                       }
+                       $vals['bot'] = (bool)$row->rc_bot;
+                       $vals['new'] = $row->rc_type == RC_NEW;
+                       $vals['minor'] = (bool)$row->rc_minor;
                }
 
                /* Add sizes of each revision. (Only available on 1.10+) */
@@ -380,7 +374,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                /* Add edit summary / log summary. */
                if ( $this->fld_comment || $this->fld_parsedcomment ) {
                        if ( $row->rc_deleted & Revision::DELETED_COMMENT ) {
-                               $vals['commenthidden'] = '';
+                               $vals['commenthidden'] = true;
                                $anyHidden = true;
                        }
                        if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_COMMENT, $user ) ) {
@@ -395,17 +389,14 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                }
 
                /* Add the patrolled flag */
-               if ( $this->fld_patrol && $row->rc_patrolled == 1 ) {
-                       $vals['patrolled'] = '';
-               }
-
-               if ( $this->fld_patrol && ChangesList::isUnpatrolled( $row, $user ) ) {
-                       $vals['unpatrolled'] = '';
+               if ( $this->fld_patrol ) {
+                       $vals['patrolled'] = $row->rc_patrolled == 1;
+                       $vals['unpatrolled'] = ChangesList::isUnpatrolled( $row, $user );
                }
 
                if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
                        if ( $row->rc_deleted & LogPage::DELETED_ACTION ) {
-                               $vals['actionhidden'] = '';
+                               $vals['actionhidden'] = true;
                                $anyHidden = true;
                        }
                        if ( LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user ) ) {
@@ -417,7 +408,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                }
 
                if ( $anyHidden && ( $row->rc_deleted & Revision::DELETED_RESTRICTED ) ) {
-                       $vals['suppressed'] = '';
+                       $vals['suppressed'] = true;
                }
 
                return $vals;
index 490b831..5db8ca7 100644 (file)
@@ -180,7 +180,9 @@ class ApiResult implements ApiSerializable {
         * Clear the current result data.
         */
        public function reset() {
-               $this->data = array();
+               $this->data = array(
+                       self::META_TYPE => 'assoc', // Usually what's desired
+               );
                $this->size = 0;
        }
 
@@ -1242,7 +1244,7 @@ class ApiResult implements ApiSerializable {
        }
 
        /**
-        * Alias for self::defineIndexedTagName()
+        * Alias for self::addIndexedTagName()
         * @deprecated since 1.25, use $this->addIndexedTagName() instead
         * @param array $path Path to the array, like addValue()'s $path
         * @param string $tag
index e41ee07..86a3f6a 100644 (file)
@@ -115,21 +115,21 @@ class ApiSetNotificationTimestamp extends ApiBase {
                        foreach ( $pageSet->getInvalidTitles() as $title ) {
                                $r = array();
                                $r['title'] = $title;
-                               $r['invalid'] = '';
+                               $r['invalid'] = true;
                                $result[] = $r;
                        }
                        foreach ( $pageSet->getMissingPageIDs() as $p ) {
                                $page = array();
                                $page['pageid'] = $p;
-                               $page['missing'] = '';
-                               $page['notwatched'] = '';
+                               $page['missing'] = true;
+                               $page['notwatched'] = true;
                                $result[] = $page;
                        }
                        foreach ( $pageSet->getMissingRevisionIDs() as $r ) {
                                $rev = array();
                                $rev['revid'] = $r;
-                               $rev['missing'] = '';
-                               $rev['notwatched'] = '';
+                               $rev['missing'] = true;
+                               $rev['notwatched'] = true;
                                $result[] = $rev;
                        }
 
@@ -163,7 +163,7 @@ class ApiSetNotificationTimestamp extends ApiBase {
                                                'title' => $title->getPrefixedText(),
                                        );
                                        if ( !$title->exists() ) {
-                                               $r['missing'] = '';
+                                               $r['missing'] = true;
                                        }
                                        if ( isset( $timestamps[$ns] ) && array_key_exists( $dbkey, $timestamps[$ns] ) ) {
                                                $r['notificationtimestamp'] = '';
@@ -171,7 +171,7 @@ class ApiSetNotificationTimestamp extends ApiBase {
                                                        $r['notificationtimestamp'] = wfTimestamp( TS_ISO_8601, $timestamps[$ns][$dbkey] );
                                                }
                                        } else {
-                                               $r['notwatched'] = '';
+                                               $r['notwatched'] = true;
                                        }
                                        $result[] = $r;
                                }
index 9eb4020..4d7fc5a 100644 (file)
@@ -37,7 +37,9 @@ class ApiTokens extends ApiBase {
                $this->logFeatureUsage( "action=tokens" );
 
                $params = $this->extractRequestParams();
-               $res = array();
+               $res = array(
+                       ApiResult::META_TYPE => 'assoc',
+               );
 
                $types = $this->getTokenTypes();
                foreach ( $params['type'] as $type ) {
index 6a585d4..85d051d 100644 (file)
@@ -109,15 +109,15 @@ class ApiWatch extends ApiBase {
 
                if ( $params['unwatch'] ) {
                        $status = UnwatchAction::doUnwatch( $title, $user );
+                       $res['unwatched'] = $status->isOK();
                        if ( $status->isOK() ) {
-                               $res['unwatched'] = '';
                                $res['message'] = $this->msg( 'removedwatchtext', $title->getPrefixedText() )
                                        ->title( $title )->parseAsBlock();
                        }
                } else {
                        $status = WatchAction::doWatch( $title, $user );
+                       $res['watched'] = $status->isOK();
                        if ( $status->isOK() ) {
-                               $res['watched'] = '';
                                $res['message'] = $this->msg( 'addedwatchtext', $title->getPrefixedText() )
                                        ->title( $title )->parseAsBlock();
                        }
index ea08c02..2edf0c6 100644 (file)
@@ -84,7 +84,7 @@ class ApiContinuationManagerTest extends MediaWikiTestCase {
                        'gcontinue' => 3,
                        'continue' => 'gcontinue||',
                ), $result->getResultData( 'continue' ) );
-               $this->assertSame( '', $result->getResultData( 'batchcomplete' ) );
+               $this->assertSame( true, $result->getResultData( 'batchcomplete' ) );
 
                $manager = self::getManager( '', $allModules, array( 'mock1', 'mock2' ) );
                $this->assertSame( false, $manager->isGeneratorDone() );
index 344af62..8ebdf60 100644 (file)
@@ -15,6 +15,11 @@ class ApiErrorFormatterTest extends MediaWikiTestCase {
                $result = new ApiResult( 8388608 );
                $formatter = new ApiErrorFormatter( $result, Language::factory( $lang ), $format, $useDB );
 
+               // Add default type
+               $expect1[ApiResult::META_TYPE] = 'assoc';
+               $expect2[ApiResult::META_TYPE] = 'assoc';
+               $expect3[ApiResult::META_TYPE] = 'assoc';
+
                $formatter->addWarning( 'string', 'mainpage' );
                $formatter->addError( 'err', 'mainpage' );
                $this->assertSame( $expect1, $result->getResultData(), 'Simple test' );
@@ -262,6 +267,7 @@ class ApiErrorFormatterTest extends MediaWikiTestCase {
                                        ApiResult::META_CONTENT => 'warnings',
                                ),
                        ),
+                       ApiResult::META_TYPE => 'assoc',
                ), $result->getResultData(), 'Simple test' );
 
                $result->reset();
@@ -293,6 +299,7 @@ class ApiErrorFormatterTest extends MediaWikiTestCase {
                                        ApiResult::META_CONTENT => 'warnings',
                                ),
                        ),
+                       ApiResult::META_TYPE => 'assoc',
                ), $result->getResultData(), 'Complex test' );
 
                $result->reset();
@@ -315,6 +322,7 @@ class ApiErrorFormatterTest extends MediaWikiTestCase {
                                        ApiResult::META_CONTENT => 'warnings',
                                ),
                        ),
+                       ApiResult::META_TYPE => 'assoc',
                ), $result->getResultData(), 'Status test' );
 
                $I = ApiResult::META_INDEXED_TAG_NAME;
index 7e43a24..03d058a 100644 (file)
@@ -144,7 +144,12 @@ class ApiResultTest extends MediaWikiTestCase {
                $result2 = new ApiResult( 8388608 );
                $result2->addValue( null, 'foo', 'bar' );
                ApiResult::setValue( $arr, 'baz', $result2 );
-               $this->assertSame( array( 'baz' => array( 'foo' => 'bar' ) ), $arr );
+               $this->assertSame( array(
+                       'baz' => array(
+                               ApiResult::META_TYPE => 'assoc',
+                               'foo' => 'bar',
+                       )
+               ), $arr );
 
                $arr = array();
                ApiResult::setValue( $arr, 'foo', "foo\x80bar" );
@@ -182,6 +187,7 @@ class ApiResultTest extends MediaWikiTestCase {
                        'unnamed 2',
                        'a' => array( 'b' => array() ),
                        'setContentValue' => '3',
+                       ApiResult::META_TYPE => 'assoc',
                        ApiResult::META_CONTENT => 'setContentValue',
                ), $result->getResultData() );
                $this->assertSame( 20, $result->getSize() );
@@ -217,7 +223,9 @@ class ApiResultTest extends MediaWikiTestCase {
                        $result->getResultData( array( ApiResult::META_CONTENT ) ) );
 
                $result->reset();
-               $this->assertSame( array(), $result->getResultData() );
+               $this->assertSame( array(
+                       ApiResult::META_TYPE => 'assoc',
+               ), $result->getResultData() );
                $this->assertSame( 0, $result->getSize() );
 
                $result->addValue( null, 'foo', 1 );
@@ -227,7 +235,7 @@ class ApiResultTest extends MediaWikiTestCase {
                $result->addValue( null, 'bottom', '2' );
                $result->addValue( null, 'foo', '2', ApiResult::OVERRIDE );
                $result->addValue( null, 'bar', '2', ApiResult::OVERRIDE | ApiResult::ADD_ON_TOP );
-               $this->assertSame( array( 0, 'top', 'foo', 'bar', 'bottom' ),
+               $this->assertSame( array( 0, 'top', 'foo', 'bar', 'bottom', ApiResult::META_TYPE ),
                        array_keys( $result->getResultData() ) );
 
                $result->reset();
@@ -240,8 +248,10 @@ class ApiResultTest extends MediaWikiTestCase {
                $result->reset();
                $result->addValue( null, 'sub', array( 'foo' => 1 ) );
                $result->addValue( null, 'sub', array( 'bar' => 1 ) );
-               $this->assertSame( array( 'sub' => array( 'foo' => 1, 'bar' => 1 ) ),
-                       $result->getResultData() );
+               $this->assertSame( array(
+                       'sub' => array( 'foo' => 1, 'bar' => 1 ),
+                       ApiResult::META_TYPE => 'assoc',
+               ), $result->getResultData() );
 
                try {
                        $result->addValue( null, 'sub', array( 'foo' => 2, 'baz' => 2 ) );
@@ -264,6 +274,7 @@ class ApiResultTest extends MediaWikiTestCase {
                $this->assertSame( array(
                        'title' => (string)$title,
                        'obj' => array( 'foo' => 1, 'bar' => 2, ApiResult::META_TYPE => 'assoc' ),
+                       ApiResult::META_TYPE => 'assoc',
                ), $result->getResultData() );
 
                $fh = tmpfile();
@@ -313,9 +324,15 @@ class ApiResultTest extends MediaWikiTestCase {
 
                $result->reset();
                $result->addParsedLimit( 'foo', 12 );
-               $this->assertSame( array( 'limits' => array( 'foo' => 12 ) ), $result->getResultData() );
+               $this->assertSame( array(
+                       'limits' => array( 'foo' => 12 ),
+                       ApiResult::META_TYPE => 'assoc',
+               ), $result->getResultData() );
                $result->addParsedLimit( 'foo', 13 );
-               $this->assertSame( array( 'limits' => array( 'foo' => 13 ) ), $result->getResultData() );
+               $this->assertSame( array(
+                       'limits' => array( 'foo' => 13 ),
+                       ApiResult::META_TYPE => 'assoc',
+               ), $result->getResultData() );
                $this->assertSame( null, $result->getResultData( array( 'foo', 'bar', 'baz' ) ) );
                $this->assertSame( 13, $result->getResultData( array( 'limits', 'foo' ) ) );
                try {
@@ -345,7 +362,13 @@ class ApiResultTest extends MediaWikiTestCase {
                $result2 = new ApiResult( 8388608 );
                $result2->addValue( null, 'foo', 'bar' );
                $result->addValue( null, 'baz', $result2 );
-               $this->assertSame( array( 'baz' => array( 'foo' => 'bar' ) ), $result->getResultData() );
+               $this->assertSame( array(
+                       'baz' => array(
+                               'foo' => 'bar',
+                               ApiResult::META_TYPE => 'assoc',
+                       ),
+                       ApiResult::META_TYPE => 'assoc',
+               ), $result->getResultData() );
 
                $result = new ApiResult( 8388608 );
                $result->addValue( null, 'foo', "foo\x80bar" );
@@ -355,6 +378,7 @@ class ApiResultTest extends MediaWikiTestCase {
                        'foo' => "foo\xef\xbf\xbdbar",
                        'bar' => "\xc3\xa1",
                        'baz' => 74,
+                       ApiResult::META_TYPE => 'assoc',
                ), $result->getResultData() );
        }
 
@@ -403,7 +427,7 @@ class ApiResultTest extends MediaWikiTestCase {
                $result->removePreserveKeysList( null, 'baz' );
                $result->addArrayTypeRecursive( null, 'default' );
                $result->addArrayType( null, 'array' );
-               $this->assertSame( $expect, $result->getResultData() );
+               $this->assertEquals( $expect, $result->getResultData() );
 
                $arr = array( 'foo' => array( 'bar' => array() ) );
                $expect = array(
@@ -1211,7 +1235,7 @@ class ApiResultTest extends MediaWikiTestCase {
                        'gcontinue' => 3,
                        'continue' => 'gcontinue||',
                ), $result->getResultData( 'continue' ) );
-               $this->assertSame( '', $result->getResultData( 'batchcomplete' ) );
+               $this->assertSame( true, $result->getResultData( 'batchcomplete' ) );
                $this->assertSame( array(
                        'mocklist' => array( 'mlcontinue' => 2 ),
                        'generator' => array( 'gcontinue' => 3 ),
@@ -1229,7 +1253,7 @@ class ApiResultTest extends MediaWikiTestCase {
                        'gcontinue' => 3,
                        'continue' => 'gcontinue||mocklist',
                ), $result->getResultData( 'continue' ) );
-               $this->assertSame( '', $result->getResultData( 'batchcomplete' ) );
+               $this->assertSame( true, $result->getResultData( 'batchcomplete' ) );
                $this->assertSame( array(
                        'generator' => array( 'gcontinue' => 3 ),
                ), $result->getResultData( 'query-continue' ) );
@@ -1283,7 +1307,7 @@ class ApiResultTest extends MediaWikiTestCase {
                        'mlcontinue' => 2,
                        'continue' => '-||mock1|mock2',
                ), $result->getResultData( 'continue' ) );
-               $this->assertSame( '', $result->getResultData( 'batchcomplete' ) );
+               $this->assertSame( true, $result->getResultData( 'batchcomplete' ) );
                $this->assertSame( array(
                        'mocklist' => array( 'mlcontinue' => 2 ),
                ), $result->getResultData( 'query-continue' ) );
@@ -1296,7 +1320,7 @@ class ApiResultTest extends MediaWikiTestCase {
                $result->endContinuation( 'raw' );
                $result->endContinuation( 'standard' );
                $this->assertSame( null, $result->getResultData( 'continue' ) );
-               $this->assertSame( '', $result->getResultData( 'batchcomplete' ) );
+               $this->assertSame( true, $result->getResultData( 'batchcomplete' ) );
                $this->assertSame( null, $result->getResultData( 'query-continue' ) );
                $main->setContinuationManager( null );
 
index 67949ab..cabf62b 100644 (file)
@@ -33,6 +33,7 @@ abstract class ApiFormatTestBase extends MediaWikiTestCase {
                        $main->getModuleManager()->addModule( $this->printerName, 'format', $class );
                }
                $result = $main->getResult();
+               $result->addArrayType( null, 'default' );
                foreach ( $data as $k => $v ) {
                        $result->addValue( null, $k, $v );
                }
index 2431761..cd73522 100644 (file)
@@ -61,7 +61,7 @@ class ApiQueryContinue2Test extends ApiQueryContinueTestBase {
                };
                // generator + 1 prop + 1 list
                $data = $this->query( $mk( 99, 99, true ), 1, 'g1p', false ) +
-                       array( 'batchcomplete' => '' );
+                       array( 'batchcomplete' => true );
                $this->checkC( $data, $mk( 1, 1, true ), 6, 'g1p-11t' );
                $this->checkC( $data, $mk( 2, 2, true ), 3, 'g1p-22t' );
                $this->checkC( $data, $mk( 1, 1, false ), 6, 'g1p-11f' );
index de9965b..d441f4c 100644 (file)
@@ -67,7 +67,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                        );
                };
                $data = $this->query( $mk( 99 ), 1, '1L', false ) +
-                       array( 'batchcomplete' => '' );
+                       array( 'batchcomplete' => true );
 
                // 1 list
                $this->checkC( $data, $mk( 1 ), 5, '1L-1' );
@@ -95,7 +95,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                };
                // 2 lists
                $data = $this->query( $mk( 99, 99 ), 1, '2L', false ) +
-                       array( 'batchcomplete' => '' );
+                       array( 'batchcomplete' => true );
                $this->checkC( $data, $mk( 1, 1 ), 5, '2L-11' );
                $this->checkC( $data, $mk( 2, 2 ), 3, '2L-22' );
                $this->checkC( $data, $mk( 3, 3 ), 2, '2L-33' );
@@ -120,7 +120,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                };
                // generator + 1 prop
                $data = $this->query( $mk( 99, 99 ), 1, 'G1P', false ) +
-                       array( 'batchcomplete' => '' );
+                       array( 'batchcomplete' => true );
                $this->checkC( $data, $mk( 1, 1 ), 11, 'G1P-11' );
                $this->checkC( $data, $mk( 2, 2 ), 6, 'G1P-22' );
                $this->checkC( $data, $mk( 3, 3 ), 4, 'G1P-33' );
@@ -146,7 +146,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                };
                // generator + 2 props
                $data = $this->query( $mk( 99, 99, 99 ), 1, 'G2P', false ) +
-                       array( 'batchcomplete' => '' );
+                       array( 'batchcomplete' => true );
                $this->checkC( $data, $mk( 1, 1, 1 ), 16, 'G2P-111' );
                $this->checkC( $data, $mk( 2, 2, 2 ), 9, 'G2P-222' );
                $this->checkC( $data, $mk( 3, 3, 3 ), 6, 'G2P-333' );
@@ -180,7 +180,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                };
                // generator + 1 prop + 1 list
                $data = $this->query( $mk( 99, 99, 99 ), 1, 'G1P1L', false ) +
-                       array( 'batchcomplete' => '' );
+                       array( 'batchcomplete' => true );
                $this->checkC( $data, $mk( 1, 1, 1 ), 11, 'G1P1L-111' );
                $this->checkC( $data, $mk( 2, 2, 2 ), 6, 'G1P1L-222' );
                $this->checkC( $data, $mk( 3, 3, 3 ), 4, 'G1P1L-333' );
@@ -218,7 +218,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                };
                // generator + 1 prop + 1 list
                $data = $this->query( $mk( 99, 99, 99, 99, 99 ), 1, 'G2P2L1M', false ) +
-                       array( 'batchcomplete' => '' );
+                       array( 'batchcomplete' => true );
                $this->checkC( $data, $mk( 1, 1, 1, 1, 1 ), 16, 'G2P2L1M-11111' );
                $this->checkC( $data, $mk( 2, 2, 2, 2, 2 ), 9, 'G2P2L1M-22222' );
                $this->checkC( $data, $mk( 3, 3, 3, 3, 3 ), 6, 'G2P2L1M-33333' );
@@ -249,7 +249,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                };
                // generator + 1 prop
                $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=P', false ) +
-                       array( 'batchcomplete' => '' );
+                       array( 'batchcomplete' => true );
 
                $this->checkC( $data, $mk( 1, true, 1, true ), 4, 'G=P-1t1t' );
                $this->checkC( $data, $mk( 2, true, 2, true ), 2, 'G=P-2t2t' );
@@ -296,7 +296,7 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                };
                // generator + 1 list
                $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=L', false ) +
-                       array( 'batchcomplete' => '' );
+                       array( 'batchcomplete' => true );
 
                $this->checkC( $data, $mk( 1, true, 1, true ), 5, 'G=L-1t1t' );
                $this->checkC( $data, $mk( 2, true, 2, true ), 3, 'G=L-2t2t' );