Oops, forgot to change this in r71426
[lhc/web/wiklou.git] / includes / api / ApiExpandTemplates.php
index fa2070f..fe281cc 100644 (file)
@@ -1,11 +1,10 @@
 <?php
-
-/*
- * Created on Oct 05, 2007
- *
+/**
  * API for MediaWiki 1.8+
  *
- * Copyright (C) 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Created on Oct 05, 2007
+ *
+ * Copyright © 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  */
 
-if (!defined('MEDIAWIKI')) {
+if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ("ApiBase.php");
+       require_once( "ApiBase.php" );
 }
 
 /**
@@ -37,29 +38,32 @@ if (!defined('MEDIAWIKI')) {
  */
 class ApiExpandTemplates extends ApiBase {
 
-       public function __construct($main, $action) {
-               parent :: __construct($main, $action);
+       public function __construct( $main, $action ) {
+               parent::__construct( $main, $action );
        }
 
        public function execute() {
+               // Cache may vary on $wgUser because ParserOptions gets data from it
+               $this->getMain()->setCacheMode( 'anon-public-user-private' );
+
                // Get parameters
-               extract( $this->extractRequestParams() );
-               $retval = '';
+               $params = $this->extractRequestParams();
 
-               //Create title for parser
-               $title_obj = Title :: newFromText( $title );
-               if(!$title_obj)
-                       $title_obj = Title :: newFromText( "API" );     //  Default title is "API". For example, ExpandTemplates uses "ExpendTemplates" for it
+               // Create title for parser
+               $title_obj = Title::newFromText( $params['title'] );
+               if ( !$title_obj ) {
+                       $title_obj = Title::newFromText( 'API' ); // default
+               }
 
                $result = $this->getResult();
 
                // Parse text
                global $wgParser;
                $options = new ParserOptions();
-               if ( $generatexml )
-               {
+
+               if ( $params['generatexml'] ) {
                        $wgParser->startExternalParse( $title_obj, $options, OT_PREPROCESS );
-                       $dom = $wgParser->preprocessToDom( $text );
+                       $dom = $wgParser->preprocessToDom( $params['text'] );
                        if ( is_callable( array( $dom, 'saveXML' ) ) ) {
                                $xml = $dom->saveXML();
                        } else {
@@ -67,9 +71,9 @@ class ApiExpandTemplates extends ApiBase {
                        }
                        $xml_result = array();
                        $result->setContent( $xml_result, $xml );
-            $result->addValue( null, 'parsetree', $xml_result);
+                       $result->addValue( null, 'parsetree', $xml_result );
                }
-               $retval = $wgParser->preprocess( $text, $title_obj, $options );
+               $retval = $wgParser->preprocess( $params['text'], $title_obj, $options );
 
                // Return result
                $retval_array = array();
@@ -78,9 +82,9 @@ class ApiExpandTemplates extends ApiBase {
        }
 
        public function getAllowedParams() {
-               return array (
+               return array(
                        'title' => array(
-                               ApiBase :: PARAM_DFLT => 'API',
+                               ApiBase::PARAM_DFLT => 'API',
                        ),
                        'text' => null,
                        'generatexml' => false,
@@ -88,7 +92,7 @@ class ApiExpandTemplates extends ApiBase {
        }
 
        public function getParamDescription() {
-               return array (
+               return array(
                        'text' => 'Wikitext to convert',
                        'title' => 'Title of page',
                        'generatexml' => 'Generate XML parse tree',
@@ -100,7 +104,7 @@ class ApiExpandTemplates extends ApiBase {
        }
 
        protected function getExamples() {
-               return array (
+               return array(
                        'api.php?action=expandtemplates&text={{Project:Sandbox}}'
                );
        }