From e658bf0402edda6150fc90197211e085f5371fb2 Mon Sep 17 00:00:00 2001 From: Jackmcbarn Date: Thu, 29 May 2014 13:50:27 -0400 Subject: [PATCH] Add category output to ApiExpandTemplates The preprocessor sometimes adds pages to categories itself, which don't have any representation in the output of ApiExpandTemplates. Because of this, add a new field containing these categories. Change-Id: I7ae2eb9daf68e032dcc7a650bd8391d445ee1037 --- includes/api/ApiExpandTemplates.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/includes/api/ApiExpandTemplates.php b/includes/api/ApiExpandTemplates.php index b42a30b029..9a472f5318 100644 --- a/includes/api/ApiExpandTemplates.php +++ b/includes/api/ApiExpandTemplates.php @@ -70,6 +70,18 @@ class ApiExpandTemplates extends ApiBase { } $frame = $wgParser->getPreprocessor()->newFrame(); $retval = $wgParser->preprocess( $params['text'], $title_obj, $options, null, $frame ); + $categories = $wgParser->getOutput()->getCategories(); + if ( !empty( $categories ) ) { + $categories_result = array(); + foreach ( $categories as $category => $sortkey ) { + $entry = array(); + $entry['sortkey'] = $sortkey; + ApiResult::setContent( $entry, $category ); + $categories_result[] = $entry; + } + $result->setIndexedTagName( $categories_result, 'category' ); + $result->addValue( null, 'categories', $categories_result ); + } // Return result $retval_array = array(); -- 2.20.1