diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2008-08-15 01:29:47 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2008-08-15 01:29:47 +0200 |
commit | 370e83bb0dfd0c70de268c93bf07ad5ee0897192 (patch) | |
tree | 491674f4c242e4d6ba0d04eafa305174c35a3391 /includes/api/ApiExpandTemplates.php | |
parent | f4debf0f12d0524d2b2427c55ea3f16b680fad97 (diff) |
Update auf 1.13.0
Diffstat (limited to 'includes/api/ApiExpandTemplates.php')
-rw-r--r-- | includes/api/ApiExpandTemplates.php | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/includes/api/ApiExpandTemplates.php b/includes/api/ApiExpandTemplates.php index 278896fa..397aece3 100644 --- a/includes/api/ApiExpandTemplates.php +++ b/includes/api/ApiExpandTemplates.php @@ -33,7 +33,7 @@ if (!defined('MEDIAWIKI')) { * any templates in a provided string, and returns the result of this expansion * to the caller. * - * @addtogroup API + * @ingroup API */ class ApiExpandTemplates extends ApiBase { @@ -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 ); @@ -66,10 +79,11 @@ class ApiExpandTemplates extends ApiBase { public function getAllowedParams() { return array ( - 'title' => array( + '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', ); } @@ -91,7 +106,6 @@ class ApiExpandTemplates extends ApiBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiExpandTemplates.php 30222 2008-01-28 19:05:26Z catrope $'; + return __CLASS__ . ': $Id: ApiExpandTemplates.php 35098 2008-05-20 17:13:28Z ialex $'; } } - |