00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 if (!defined('MEDIAWIKI')) {
00027
00028 require_once ("ApiBase.php");
00029 }
00030
00038 class ApiExpandTemplates extends ApiBase {
00039
00040 public function __construct($main, $action) {
00041 parent :: __construct($main, $action);
00042 }
00043
00044 public function execute() {
00045
00046 $params = $this->extractRequestParams();
00047
00048
00049 $title_obj = Title :: newFromText( $params['title'] );
00050 if(!$title_obj)
00051 $title_obj = Title :: newFromText( "API" );
00052
00053 $result = $this->getResult();
00054
00055
00056 global $wgParser;
00057 $options = new ParserOptions();
00058 if ( $params['generatexml'] )
00059 {
00060 $wgParser->startExternalParse( $title_obj, $options, OT_PREPROCESS );
00061 $dom = $wgParser->preprocessToDom( $params['text'] );
00062 if ( is_callable( array( $dom, 'saveXML' ) ) ) {
00063 $xml = $dom->saveXML();
00064 } else {
00065 $xml = $dom->__toString();
00066 }
00067 $xml_result = array();
00068 $result->setContent( $xml_result, $xml );
00069 $result->addValue( null, 'parsetree', $xml_result);
00070 }
00071 $retval = $wgParser->preprocess( $params['text'], $title_obj, $options );
00072
00073
00074 $retval_array = array();
00075 $result->setContent( $retval_array, $retval );
00076 $result->addValue( null, $this->getModuleName(), $retval_array );
00077 }
00078
00079 public function getAllowedParams() {
00080 return array (
00081 'title' => array(
00082 ApiBase :: PARAM_DFLT => 'API',
00083 ),
00084 'text' => null,
00085 'generatexml' => false,
00086 );
00087 }
00088
00089 public function getParamDescription() {
00090 return array (
00091 'text' => 'Wikitext to convert',
00092 'title' => 'Title of page',
00093 'generatexml' => 'Generate XML parse tree',
00094 );
00095 }
00096
00097 public function getDescription() {
00098 return 'This module expand all templates in wikitext';
00099 }
00100
00101 protected function getExamples() {
00102 return array (
00103 'api.php?action=expandtemplates&text={{Project:Sandbox}}'
00104 );
00105 }
00106
00107 public function getVersion() {
00108 return __CLASS__ . ': $Id: ApiExpandTemplates.php 44719 2008-12-17 16:34:01Z catrope $';
00109 }
00110 }