From d06c05497181ffc301b85dfb4c334a1d5a009b8e Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Sun, 6 Feb 2011 01:38:33 +0000 Subject: [PATCH] Switch to and start hiding these editsection tags from Tidy so it doesn't break them. --- includes/parser/Parser.php | 4 +-- includes/parser/ParserOutput.php | 2 +- includes/parser/Tidy.php | 59 ++++++++++++++++++++++++++++++-- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index ab702c3812..b7c63bfc17 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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 = ''; + $editlink .= '>' . $editlinkArgs[2] . ''; } else { $editlink .= '/>'; } diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index ee596a8c36..80d53439d8 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -137,7 +137,7 @@ class ParserOutput extends CacheTime { function getText() { if ( $this->mEditSectionTokens ) { - return preg_replace_callback( '#|>(.*?)())#', array( &$this, 'replaceEditSectionLinksCallback' ), $this->mText ); + return preg_replace_callback( '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)())#', array( &$this, 'replaceEditSectionLinksCallback' ), $this->mText ); } return $this->mText; } diff --git a/includes/parser/Tidy.php b/includes/parser/Tidy.php index 49f5d0b433..2988f3e399 100644 --- a/includes/parser/Tidy.php +++ b/includes/parser/Tidy.php @@ -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="(.*?)"(?:/>|>(.*?)())#', array( &$this, 'replaceEditSectionLinksCallback' ), $text ); + + $wrappedtext = ''. + 'test'.$wrappedtext.''; + + 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 = ''. -'test'.$text.''; + $wrapper = new MWTidyWrapper; + $wrappedtext = $wrapper->getWrapped( $text ); if( $wgTidyInternal ) { $correctedtext = self::execInternalTidy( $wrappedtext ); @@ -41,8 +88,14 @@ class MWTidy { return $text . "\n\n"; } + $correctedtext = $wrapper->postprocess( $correctedtext ); // restore any hidden tokens + return $correctedtext; } + + function replaceEditSectionLinksCallback( $m ) { + + } /** * Check HTML for errors, used if $wgValidateAllHtml = true. -- 2.20.1