summaryrefslogtreecommitdiff
path: root/includes/api/ApiExpandTemplates.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiExpandTemplates.php')
-rw-r--r--includes/api/ApiExpandTemplates.php38
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 $';
}
}
-