From 0006103d403ddc13ab535960f62f4eeacae923f6 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Tue, 13 May 2008 09:03:23 +0000 Subject: [PATCH] (bug 13829) Expose parse tree via action=expandtemplates --- RELEASE-NOTES | 1 + includes/api/ApiExpandTemplates.php | 31 +++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index f009b6725a..3e732d74f1 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -332,6 +332,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 14028) Added language attribute to interwiki map in meta=siteinfo * (bug 14022) Added usprop=registration and auprop=blockinfo * (bug 14021) Removed titles= support from list=backlinks (has been obsolete for ages) +* (bug 13829) Expose parse tree via action=expandtemplates === Languages updated in 1.13 === diff --git a/includes/api/ApiExpandTemplates.php b/includes/api/ApiExpandTemplates.php index 99f9fa8099..c32c4e6b3f 100644 --- a/includes/api/ApiExpandTemplates.php +++ b/includes/api/ApiExpandTemplates.php @@ -43,22 +43,35 @@ class ApiExpandTemplates extends ApiBase { public function execute() { // Get parameters - $params = $this->extractRequestParams(); - $text = $params['text']; - $title = $params['title']; + extract( $this->extractRequestParams() ); $retval = ''; //Create title for parser - $title_obj = Title :: newFromText($params['title']); + $title_obj = Title :: newFromText( $title ); if(!$title_obj) - $title_obj = Title :: newFromText("API"); // Default title is "API". For example, ExpandTemplates uses "ExpendTemplates" for it + $title_obj = Title :: newFromText( "API" ); // Default title is "API". For example, ExpandTemplates uses "ExpendTemplates" for it + + $result = $this->getResult(); // Parse text global $wgParser; - $retval = $wgParser->preprocess( $text, $title_obj, new ParserOptions() ); + $options = new ParserOptions(); + if ( $generatexml ) + { + $wgParser->startExternalParse( $title_obj, $options, OT_PREPROCESS ); + $dom = $wgParser->preprocessToDom( $text ); + if ( is_callable( array( $dom, 'saveXML' ) ) ) { + $xml = $dom->saveXML(); + } else { + $xml = $dom->__toString(); + } + $xml_result = array(); + $result->setContent( $xml_result, $xml ); + $result->addValue( null, 'parsetree', $xml_result); + } + $retval = $wgParser->preprocess( $text, $title_obj, $options ); // Return result - $result = $this->getResult(); $retval_array = array(); $result->setContent( $retval_array, $retval ); $result->addValue( null, $this->getModuleName(), $retval_array ); @@ -69,7 +82,8 @@ class ApiExpandTemplates extends ApiBase { 'title' => array( ApiBase :: PARAM_DFLT => 'API', ), - 'text' => null + 'text' => null, + 'generatexml' => false, ); } @@ -77,6 +91,7 @@ class ApiExpandTemplates extends ApiBase { return array ( 'text' => 'Wikitext to convert', 'title' => 'Title of page', + 'generatexml' => 'Generate XML parse tree', ); } -- 2.20.1