Add category output to ApiExpandTemplates
authorJackmcbarn <jackmcbarn@gmail.com>
Thu, 29 May 2014 17:50:27 +0000 (13:50 -0400)
committerJackmcbarn <jackmcbarn@gmail.com>
Fri, 30 May 2014 18:31:53 +0000 (14:31 -0400)
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

index b42a30b..9a472f5 100644 (file)
@@ -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();