make html generation optional in Content::getParserOutput
authordaniel <daniel.kinzler@wikimedia.de>
Mon, 16 Apr 2012 07:12:34 +0000 (09:12 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Mon, 16 Apr 2012 07:12:34 +0000 (09:12 +0200)
Change-Id: Ie1c6588057dbce1a5e6955ebcbd9905df53b2f5a

includes/Article.php
includes/Content.php
includes/api/ApiParse.php

index e2b920e..7fc436f 100644 (file)
@@ -627,7 +627,7 @@ class Article extends Page {
                                                        # Viewing a redirect page (e.g. with parameter redirect=no)
                                                        $wgOut->addHTML( $this->viewRedirect( $rt ) );
                                                        # Parse just to get categories, displaytitle, etc.
-                                                       $this->mParserOutput = $content->getParserOutput( $this->getTitle(), $oldid, $parserOptions );
+                                                       $this->mParserOutput = $content->getParserOutput( $this->getTitle(), $oldid, $parserOptions, false );
                                                        $wgOut->addParserOutputNoText( $this->mParserOutput );
                                                        $outputDone = true;
                                                }
index 913eb06..30e8400 100644 (file)
@@ -112,9 +112,13 @@ abstract class Content {
      * @param null|Title $title
      * @param null $revId
      * @param null|ParserOptions $options
+     * @param Boolean $generateHtml whether to generate Html (default: true). If false,
+     *        the result of calling getText() on the ParserOutput object returned by
+     *        this method is undefined.
+     *
      * @return ParserOutput
      */
-    public abstract function getParserOutput( Title $title = null, $revId = null, ParserOptions $options = NULL );
+    public abstract function getParserOutput( Title $title = null, $revId = null, ParserOptions $options = NULL, $generateHtml = true );
 
     /**
      * Construct the redirect destination from this content and return an
@@ -317,10 +321,12 @@ abstract class TextContent extends Content {
      *
      * @return ParserOutput representing the HTML form of the text
      */
-    public function getParserOutput( Title $title = null, $revId = null, ParserOptions $options = null ) {
+    public function getParserOutput( Title $title = null, $revId = null, ParserOptions $options = null, $generateHtml = true ) {
         # generic implementation, relying on $this->getHtml()
 
-        $html = $this->getHtml( $options );
+        if ( $generateHtml ) $html = $this->getHtml( $options );
+        else $html = '';
+
         $po = new ParserOutput( $html );
 
         return $po;
@@ -356,7 +362,7 @@ class WikitextContent extends TextContent {
      *
      * @return ParserOutput representing the HTML form of the text
      */
-    public function getParserOutput( Title $title = null, $revId = null, ParserOptions $options = null ) {
+    public function getParserOutput( Title $title = null, $revId = null, ParserOptions $options = null, $generateHtml = true ) {
         global $wgParser;
 
         if ( !$options ) {
index 10f17a2..93e13cb 100644 (file)
@@ -189,7 +189,7 @@ class ApiParse extends ApiBase {
                                return;
                        }
                        // Not cached (save or load)
-                       $p_result = $wgParser->parse( $params['pst'] ? $this->pstText : $this->text, $titleObj, $popts );
+                       $p_result = $wgParser->parse( $params['pst'] ? $this->pstText : $this->text, $titleObj, $popts ); #FIXME: use Content object¡
                }
 
                $result_array = array();