]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blobdiff - includes/parser/Tidy.php
MediaWiki 1.17.0
[autoinstalls/mediawiki.git] / includes / parser / Tidy.php
index 95f83621af8b0f6025b4943da99ccc7d343a19dc..38f22fd8ace529ad8c204d9bb3bb72989e7ba192 100644 (file)
@@ -1,4 +1,9 @@
 <?php
+/**
+ * HTML validation and correction
+ *
+ * @file
+ */
 
 /**
  * Class to interact with HTML tidy
@@ -16,8 +21,8 @@ class MWTidy {
         * If tidy isn't able to correct the markup, the original will be
         * returned in all its glory with a warning comment appended.
         *
-        * @param string $text Hideous HTML input
-        * @return string Corrected HTML output
+        * @param $text String: hideous HTML input
+        * @return String: corrected HTML output
         */
        public static function tidy( $text ) {
                global $wgTidyInternal;
@@ -26,9 +31,6 @@ class MWTidy {
 ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'.
 '<head><title>test</title></head><body>'.$text.'</body></html>';
 
-               # Tidy is known to clobber tabs; convert them to entities
-               $wrappedtext = str_replace( "\t", '&#9;', $wrappedtext );
-
                if( $wgTidyInternal ) {
                        $correctedtext = self::execInternalTidy( $wrappedtext );
                } else {
@@ -39,9 +41,6 @@ class MWTidy {
                        return $text . "\n<!-- Tidy found serious XHTML errors -->\n";
                }
 
-               # Convert the tabs back from entities
-               $correctedtext = str_replace( '&#9;', "\t", $correctedtext );
-
                return $correctedtext;
        }
 
@@ -71,7 +70,7 @@ class MWTidy {
         * @param $text String: HTML to check
         * @param $stderr Boolean: Whether to read from STDERR rather than STDOUT
         * @param &$retval Exit code (-1 on internal error)
-        * @retrun mixed String or null
+        * @return mixed String or null
         */
        private static function execExternalTidy( $text, $stderr = false, &$retval = null ) {
                global $wgTidyConf, $wgTidyBin, $wgTidyOpts;
@@ -119,15 +118,13 @@ class MWTidy {
                        $retval = -1;   
                }
 
-               wfProfileOut( __METHOD__ );
-
                if( !$stderr && $cleansource == '' && $text != '' ) {
                        // Some kind of error happened, so we couldn't get the corrected text.
                        // Just give up; we'll use the source text and append a warning.
-                       return null;
-               } else {
-                       return $cleansource;
+                       $cleansource = null;
                }
+               wfProfileOut( __METHOD__ );
+               return $cleansource;
        }
 
        /**
@@ -137,7 +134,7 @@ class MWTidy {
         * 'pear install tidy' should be able to compile the extension module.
         */
        private static function execInternalTidy( $text, $stderr = false, &$retval = null ) {
-               global $wgTidyConf, $IP, $wgDebugTidy;
+               global $wgTidyConf, $wgDebugTidy;
                wfProfileIn( __METHOD__ );
 
                $tidy = new tidy;
@@ -145,6 +142,7 @@ class MWTidy {
 
                if( $stderr ) {
                        $retval = $tidy->getStatus();
+                       wfProfileOut( __METHOD__ );
                        return $tidy->errorBuffer;
                } else {
                        $tidy->cleanRepair();