From 9992e6adb360133318dba218d3ec8a77f81a4db0 Mon Sep 17 00:00:00 2001 From: addshore Date: Thu, 3 Dec 2015 15:15:59 +0100 Subject: [PATCH] Cast numeric cat names back to string in api output This could be considered a breaking change even though it unifies behaviour. Change-Id: Ib6bc7386f689cc6c2812e9e9406f18b20caa8fee --- includes/OutputPage.php | 2 ++ includes/api/ApiExpandTemplates.php | 2 +- includes/api/ApiParse.php | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index c35204d604..00143c76f8 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1354,6 +1354,8 @@ class OutputPage extends ContextSource { array( &$this, $categories, &$this->mCategoryLinks ) ) ) { foreach ( $categories as $category => $type ) { + // array keys will cast numeric category names to ints, so cast back to string + $category = (string)$category; $origcategory = $category; $title = Title::makeTitleSafe( NS_CATEGORY, $category ); if ( !$title ) { diff --git a/includes/api/ApiExpandTemplates.php b/includes/api/ApiExpandTemplates.php index 8a63070ce6..72adaf8618 100644 --- a/includes/api/ApiExpandTemplates.php +++ b/includes/api/ApiExpandTemplates.php @@ -115,7 +115,7 @@ class ApiExpandTemplates extends ApiBase { foreach ( $categories as $category => $sortkey ) { $entry = array(); $entry['sortkey'] = $sortkey; - ApiResult::setContentValue( $entry, 'category', $category ); + ApiResult::setContentValue( $entry, 'category', (string)$category ); $categories_result[] = $entry; } ApiResult::setIndexedTagName( $categories_result, 'category' ); diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 9de5a02386..5754c2368d 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -634,7 +634,8 @@ class ApiParse extends ApiBase { foreach ( $links as $link => $sortkey ) { $entry = array(); $entry['sortkey'] = $sortkey; - ApiResult::setContentValue( $entry, 'category', $link ); + // array keys will cast numeric category names to ints, so cast back to string + ApiResult::setContentValue( $entry, 'category', (string)$link ); if ( !isset( $hiddencats[$link] ) ) { $entry['missing'] = true; } elseif ( $hiddencats[$link] ) { -- 2.20.1