API: Add page properties to action=expandtemplates output
authorBrad Jorsch <bjorsch@wikimedia.org>
Mon, 22 Dec 2014 21:17:46 +0000 (16:17 -0500)
committerJackmcbarn <jackmcbarn@gmail.com>
Mon, 22 Dec 2014 21:45:59 +0000 (21:45 +0000)
This allows for retrieving properties set by double-brace magic words
such as {{DEFAULTSORT:}}.

Bug: T78737
Change-Id: I971d233e4bed52a363144aa69c304e5672257a73

RELEASE-NOTES-1.25
includes/api/ApiExpandTemplates.php
includes/api/i18n/en.json

index 9183e44..00bc155 100644 (file)
@@ -159,6 +159,7 @@ production.
 * (T76051) list=tags will now continue correctly.
 * (T76052) list=tags can now indicate whether a tag is defined.
 * (T75522) list=prefixsearch now supports continuation
+* (T78737) action=expandtemplates can now return page properties.
 
 === Action API internal changes in 1.25 ===
 * ApiHelp has been rewritten to support i18n and paginated HTML output.
index 751be75..4a5afb9 100644 (file)
@@ -114,7 +114,7 @@ class ApiExpandTemplates extends ApiBase {
                        } else {
                                if ( isset( $prop['categories'] ) ) {
                                        $categories = $wgParser->getOutput()->getCategories();
-                                       if ( !empty( $categories ) ) {
+                                       if ( $categories ) {
                                                $categories_result = array();
                                                foreach ( $categories as $category => $sortkey ) {
                                                        $entry = array();
@@ -126,6 +126,20 @@ class ApiExpandTemplates extends ApiBase {
                                                $retval['categories'] = $categories_result;
                                        }
                                }
+                               if ( isset( $prop['properties'] ) ) {
+                                       $properties = $wgParser->getOutput()->getProperties();
+                                       if ( $properties ) {
+                                               $properties_result = array();
+                                               foreach ( $properties as $name => $value ) {
+                                                       $entry = array();
+                                                       $entry['name'] = $name;
+                                                       ApiResult::setContent( $entry, $value );
+                                                       $properties_result[] = $entry;
+                                               }
+                                               $result->setIndexedTagName( $properties_result, 'property' );
+                                               $retval['properties'] = $properties_result;
+                                       }
+                               }
                                if ( isset( $prop['volatile'] ) && $frame->isVolatile() ) {
                                        $retval['volatile'] = '';
                                }
@@ -157,6 +171,7 @@ class ApiExpandTemplates extends ApiBase {
                                ApiBase::PARAM_TYPE => array(
                                        'wikitext',
                                        'categories',
+                                       'properties',
                                        'volatile',
                                        'ttl',
                                        'parsetree',
index d0eb230..c92db10 100644 (file)
        "apihelp-expandtemplates-param-title": "Title of page.",
        "apihelp-expandtemplates-param-text": "Wikitext to convert.",
        "apihelp-expandtemplates-param-revid": "Revision ID, for <nowiki>{{REVISIONID}}</nowiki> and similar variables.",
-       "apihelp-expandtemplates-param-prop": "Which pieces of information to get:\n;wikitext:The expanded wikitext.\n;categories:Any categories present in the input that are not represented in the wikitext output.\n;volatile:Whether the output is volatile and should not be reused elsewhere within the page.\n;ttl:The maximum time after which caches of the result should be invalidated.\n;parsetree:The XML parse tree of the input.\nNote that if no values are selected, the result will contain the wikitext, but the output will be in a deprecated format.",
+       "apihelp-expandtemplates-param-prop": "Which pieces of information to get:\n;wikitext:The expanded wikitext.\n;categories:Any categories present in the input that are not represented in the wikitext output.\n;properties:Page properties defined by expanded magic words in the wikitext.\n;volatile:Whether the output is volatile and should not be reused elsewhere within the page.\n;ttl:The maximum time after which caches of the result should be invalidated.\n;parsetree:The XML parse tree of the input.\nNote that if no values are selected, the result will contain the wikitext, but the output will be in a deprecated format.",
        "apihelp-expandtemplates-param-includecomments": "Whether to include HTML comments in the output.",
        "apihelp-expandtemplates-param-generatexml": "Generate XML parse tree (replaced by $1prop=parsetree).",
        "apihelp-expandtemplates-example-simple": "Expand the wikitext \"<nowiki>{{Project:Sandbox}}</nowiki>\"",