Cast numeric cat names back to string in api output
authoraddshore <addshorewiki@gmail.com>
Thu, 3 Dec 2015 14:15:59 +0000 (15:15 +0100)
committeraddshore <addshorewiki@gmail.com>
Thu, 3 Dec 2015 14:15:59 +0000 (15:15 +0100)
This could be considered a breaking change even
though it unifies behaviour.

Change-Id: Ib6bc7386f689cc6c2812e9e9406f18b20caa8fee

includes/OutputPage.php
includes/api/ApiExpandTemplates.php
includes/api/ApiParse.php

index c35204d..00143c7 100644 (file)
@@ -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 ) {
index 8a63070..72adaf8 100644 (file)
@@ -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' );
index 9de5a02..5754c23 100644 (file)
@@ -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] ) {