Switch <editsection> to <mw:editsection> and start hiding these editsection tags...
authorDaniel Friesen <dantman@users.mediawiki.org>
Sun, 6 Feb 2011 01:38:33 +0000 (01:38 +0000)
committerDaniel Friesen <dantman@users.mediawiki.org>
Sun, 6 Feb 2011 01:38:33 +0000 (01:38 +0000)
includes/parser/Parser.php
includes/parser/ParserOutput.php
includes/parser/Tidy.php

index ab702c3..b7c63bf 100644 (file)
@@ -3948,10 +3948,10 @@ class Parser {
                                // We use a page and section attribute to stop the language converter from converting these important bits
                                // of data, but put the headline hint inside a content block because the language converter is supposed to
                                // be able to convert that piece of data.
-                               $editlink = '<editsection page="' . htmlspecialchars($editlinkArgs[0]);
+                               $editlink = '<mw:editsection page="' . htmlspecialchars($editlinkArgs[0]);
                                $editlink .= '" section="' . htmlspecialchars($editlinkArgs[1]) .'"';
                                if ( isset($editlinkArgs[2]) ) {
-                                       $editlink .= '>' . $editlinkArgs[2] . '</editsection>';
+                                       $editlink .= '>' . $editlinkArgs[2] . '</mw:editsection>';
                                } else {
                                        $editlink .= '/>';
                                }
index ee596a8..80d5343 100644 (file)
@@ -137,7 +137,7 @@ class ParserOutput extends CacheTime {
 
        function getText() {
                if ( $this->mEditSectionTokens ) {
-                       return preg_replace_callback( '#<editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</editsection>))#', array( &$this, 'replaceEditSectionLinksCallback' ), $this->mText );
+                       return preg_replace_callback( '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#', array( &$this, 'replaceEditSectionLinksCallback' ), $this->mText );
                }
                return $this->mText;
        }
index 49f5d0b..2988f3e 100644 (file)
@@ -5,6 +5,54 @@
  * @file
  */
 
+/**
+ * Class used to hide mw:editsection tokens from Tidy so that it doesn't break them
+ * or break on them. This is a bit of a hack for now, but hopefully in the future
+ * we may create a real postprocessor or something that will replace this.
+ * It's called wrapper because for now it basically takes over MWTidy::tidy's task
+ * of wrapping the text in a xhtml block
+ * 
+ * This re-uses some of the parser's UNIQ tricks, though some of it is private so it's
+ * duplicated. Perhaps we should create an abstract marker hiding class.
+ */
+class MWTidyWrapper {
+
+       protected $mTokens, $mUniqPrefix;
+
+       public function __construct() {
+               $this->mTokens = null;
+               $this->mUniqPrefix = null;
+       }
+
+       public function getWrapped( $text ) {
+               $this->mTokens = new ReplacementArray;
+               $this->mUniqPrefix = "\x7fUNIQ" . dechex( mt_rand( 0, 0x7fffffff ) ) . dechex( mt_rand( 0, 0x7fffffff ) );
+               $this->mMarkerIndex = 0;
+               $wrappedtext = preg_replace_callback( '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#', array( &$this, 'replaceEditSectionLinksCallback' ), $text );
+
+               $wrappedtext = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'.
+                       ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'.
+                       '<head><title>test</title></head><body>'.$wrappedtext.'</body></html>';
+
+               return $wrappedtext;
+       }
+
+       /**
+        * @private
+        */
+       function replaceEditSectionLinksCallback( $m ) {
+               $marker = "{$this->mUniqPrefix}-item-{$this->mMarkerIndex}" . Parser::MARKER_SUFFIX;
+               $this->mMarkerIndex++;
+               $this->mTokens->setPair( $marker, $m[0] );
+               return $marker;
+       }
+
+       public function postprocess( $text ) {
+               return $this->mTokens->replace( $text );
+       }
+
+}
+
 /**
  * Class to interact with HTML tidy
  *
@@ -27,9 +75,8 @@ class MWTidy {
        public static function tidy( $text ) {
                global $wgTidyInternal;
 
-               $wrappedtext = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'.
-' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'.
-'<head><title>test</title></head><body>'.$text.'</body></html>';
+               $wrapper = new MWTidyWrapper;
+               $wrappedtext = $wrapper->getWrapped( $text );
 
                if( $wgTidyInternal ) {
                        $correctedtext = self::execInternalTidy( $wrappedtext );
@@ -41,8 +88,14 @@ class MWTidy {
                        return $text . "\n<!-- Tidy found serious XHTML errors -->\n";
                }
 
+               $correctedtext = $wrapper->postprocess( $correctedtext ); // restore any hidden tokens
+
                return $correctedtext;
        }
+       
+       function replaceEditSectionLinksCallback( $m ) {
+               
+       }
 
        /**
         * Check HTML for errors, used if $wgValidateAllHtml = true.