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 $this->getMain()->setCacheMode( 'anon-public-user-private' );
00047
00048
00049 $params = $this->extractRequestParams();
00050
00051
00052 $title_obj = Title :: newFromText( $params['title'] );
00053 if(!$title_obj)
00054 $title_obj = Title :: newFromText( "API" );
00055
00056 $result = $this->getResult();
00057
00058
00059 global $wgParser;
00060 $options = new ParserOptions();
00061 if ( $params['generatexml'] )
00062 {
00063 $wgParser->startExternalParse( $title_obj, $options, OT_PREPROCESS );
00064 $dom = $wgParser->preprocessToDom( $params['text'] );
00065 if ( is_callable( array( $dom, 'saveXML' ) ) ) {
00066 $xml = $dom->saveXML();
00067 } else {
00068 $xml = $dom->__toString();
00069 }
00070 $xml_result = array();
00071 $result->setContent( $xml_result, $xml );
00072 $result->addValue( null, 'parsetree', $xml_result);
00073 }
00074 $retval = $wgParser->preprocess( $params['text'], $title_obj, $options );
00075
00076
00077 $retval_array = array();
00078 $result->setContent( $retval_array, $retval );
00079 $result->addValue( null, $this->getModuleName(), $retval_array );
00080 }
00081
00082 public function getAllowedParams() {
00083 return array (
00084 'title' => array(
00085 ApiBase :: PARAM_DFLT => 'API',
00086 ),
00087 'text' => null,
00088 'generatexml' => false,
00089 );
00090 }
00091
00092 public function getParamDescription() {
00093 return array (
00094 'text' => 'Wikitext to convert',
00095 'title' => 'Title of page',
00096 'generatexml' => 'Generate XML parse tree',
00097 );
00098 }
00099
00100 public function getDescription() {
00101 return 'This module expand all templates in wikitext';
00102 }
00103
00104 protected function getExamples() {
00105 return array (
00106 'api.php?action=expandtemplates&text={{Project:Sandbox}}'
00107 );
00108 }
00109
00110 public function getVersion() {
00111 return __CLASS__ . ': $Id: ApiExpandTemplates.php 69986 2010-07-27 03:57:39Z tstarling $';
00112 }
00113 }