Move tidy call from Parser to OutputPage so that it happens
authorWil Mahan <wmahan@users.mediawiki.org>
Sat, 25 Sep 2004 18:22:21 +0000 (18:22 +0000)
committerWil Mahan <wmahan@users.mediawiki.org>
Sat, 25 Sep 2004 18:22:21 +0000 (18:22 +0000)
after link placeholder replacement.

includes/OutputPage.php
includes/Parser.php

index d240667..2fb7fb8 100644 (file)
@@ -232,9 +232,12 @@ class OutputPage {
         * Convert wikitext to HTML and add it to the buffer
         */
        function addWikiText( $text, $linestart = true ) {
-               global $wgParser, $wgTitle;
+               global $wgParser, $wgTitle, $wgUseTidy;
 
                $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart );
+               if ($wgUseTidy) {
+                       $text = Parser::tidy($text);
+               }
                $this->mLanguageLinks += $parserOutput->getLanguageLinks();
                $this->mCategoryLinks += $parserOutput->getCategoryLinks();
                $this->addHTML( $parserOutput->getText() );
@@ -245,13 +248,16 @@ class OutputPage {
         * Saves the text into the parser cache if possible
         */
        function addPrimaryWikiText( $text, $cacheArticle ) {
-               global $wgParser, $wgParserCache, $wgUser, $wgTitle;
+               global $wgParser, $wgParserCache, $wgUser, $wgTitle, $wgUseTidy;
 
                $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, true );
 
                # Replace link holders
                $text = $parserOutput->getText();
                $this->replaceLinkHolders( $text );
+               if ($wgUseTidy) {
+                       $text = Parser::tidy($text);
+               }
                $parserOutput->setText( $text );
                
                if ( $cacheArticle ) {
index c7d27a6..ba9b1d9 100644 (file)
@@ -184,9 +184,6 @@ class Parser
                # only once and last
                $text = $this->doBlockLevels( $text, $linestart );
                $text = $this->unstripNoWiki( $text, $this->mStripState );
-               if($wgUseTidy) {
-                       $text = $this->tidy($text);
-               }
                $this->mOutput->setText( $text );
                wfProfileOut( $fname );
                return $this->mOutput;
@@ -483,7 +480,8 @@ class Parser
        /**
         * interface with html tidy, used if $wgUseTidy = true
         *
-        * @access private
+        * @access public
+        * @static
         */
        function tidy ( $text ) {
                global $wgTidyConf, $wgTidyBin, $wgTidyOpts;
@@ -492,15 +490,16 @@ class Parser
                wfProfileIn( $fname );
 
                $cleansource = '';
+               $opts = '';
                switch(strtoupper($wgOutputEncoding)) {
                        case 'ISO-8859-1':
-                               $wgTidyOpts .= ($wgInputEncoding == $wgOutputEncoding)? ' -latin1':' -raw';
+                               $opts .= ($wgInputEncoding == $wgOutputEncoding)? ' -latin1':' -raw';
                                break;
                        case 'UTF-8':
-                               $wgTidyOpts .= ($wgInputEncoding == $wgOutputEncoding)? ' -utf8':' -raw';
+                               $opts .= ($wgInputEncoding == $wgOutputEncoding)? ' -utf8':' -raw';
                                break;
                        default:
-                               $wgTidyOpts .= ' -raw';
+                               $opts .= ' -raw';
                        }
 
                $wrappedtext = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'.
@@ -511,7 +510,7 @@ class Parser
                        1 => array('pipe', 'w'),
                        2 => array('file', '/dev/null', 'a')
                );
-               $process = proc_open("$wgTidyBin -config $wgTidyConf $wgTidyOpts", $descriptorspec, $pipes);
+               $process = proc_open("$wgTidyBin -config $wgTidyConf $wgTidyOpts$opts", $descriptorspec, $pipes);
                if (is_resource($process)) {
                        fwrite($pipes[0], $wrappedtext);
                        fclose($pipes[0]);