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