From: Brad Jorsch Date: Mon, 22 Dec 2014 21:17:46 +0000 (-0500) Subject: API: Add page properties to action=expandtemplates output X-Git-Tag: 1.31.0-rc.0~12876 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/ajouter.php?a=commitdiff_plain;h=98f56b62e12cd7f5d92630fe75db71fb886e7a94;p=lhc%2Fweb%2Fwiklou.git API: Add page properties to action=expandtemplates output This allows for retrieving properties set by double-brace magic words such as {{DEFAULTSORT:}}. Bug: T78737 Change-Id: I971d233e4bed52a363144aa69c304e5672257a73 --- diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index 9183e445dd..00bc155a4c 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -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. diff --git a/includes/api/ApiExpandTemplates.php b/includes/api/ApiExpandTemplates.php index 751be75fbb..4a5afb998f 100644 --- a/includes/api/ApiExpandTemplates.php +++ b/includes/api/ApiExpandTemplates.php @@ -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', diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index d0eb230914..c92db10d44 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -113,7 +113,7 @@ "apihelp-expandtemplates-param-title": "Title of page.", "apihelp-expandtemplates-param-text": "Wikitext to convert.", "apihelp-expandtemplates-param-revid": "Revision ID, for {{REVISIONID}} 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 \"{{Project:Sandbox}}\"",