Index: trunk/phase3/includes/parser/Tidy.php |
— | — | @@ -6,6 +6,54 @@ |
7 | 7 | */ |
8 | 8 | |
9 | 9 | /** |
| 10 | + * Class used to hide mw:editsection tokens from Tidy so that it doesn't break them |
| 11 | + * or break on them. This is a bit of a hack for now, but hopefully in the future |
| 12 | + * we may create a real postprocessor or something that will replace this. |
| 13 | + * It's called wrapper because for now it basically takes over MWTidy::tidy's task |
| 14 | + * of wrapping the text in a xhtml block |
| 15 | + * |
| 16 | + * This re-uses some of the parser's UNIQ tricks, though some of it is private so it's |
| 17 | + * duplicated. Perhaps we should create an abstract marker hiding class. |
| 18 | + */ |
| 19 | +class MWTidyWrapper { |
| 20 | + |
| 21 | + protected $mTokens, $mUniqPrefix; |
| 22 | + |
| 23 | + public function __construct() { |
| 24 | + $this->mTokens = null; |
| 25 | + $this->mUniqPrefix = null; |
| 26 | + } |
| 27 | + |
| 28 | + public function getWrapped( $text ) { |
| 29 | + $this->mTokens = new ReplacementArray; |
| 30 | + $this->mUniqPrefix = "\x7fUNIQ" . dechex( mt_rand( 0, 0x7fffffff ) ) . dechex( mt_rand( 0, 0x7fffffff ) ); |
| 31 | + $this->mMarkerIndex = 0; |
| 32 | + $wrappedtext = preg_replace_callback( '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#', array( &$this, 'replaceEditSectionLinksCallback' ), $text ); |
| 33 | + |
| 34 | + $wrappedtext = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'. |
| 35 | + ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'. |
| 36 | + '<head><title>test</title></head><body>'.$wrappedtext.'</body></html>'; |
| 37 | + |
| 38 | + return $wrappedtext; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @private |
| 43 | + */ |
| 44 | + function replaceEditSectionLinksCallback( $m ) { |
| 45 | + $marker = "{$this->mUniqPrefix}-item-{$this->mMarkerIndex}" . Parser::MARKER_SUFFIX; |
| 46 | + $this->mMarkerIndex++; |
| 47 | + $this->mTokens->setPair( $marker, $m[0] ); |
| 48 | + return $marker; |
| 49 | + } |
| 50 | + |
| 51 | + public function postprocess( $text ) { |
| 52 | + return $this->mTokens->replace( $text ); |
| 53 | + } |
| 54 | + |
| 55 | +} |
| 56 | + |
| 57 | +/** |
10 | 58 | * Class to interact with HTML tidy |
11 | 59 | * |
12 | 60 | * Either the external tidy program or the in-process tidy extension |
— | — | @@ -27,9 +75,8 @@ |
28 | 76 | public static function tidy( $text ) { |
29 | 77 | global $wgTidyInternal; |
30 | 78 | |
31 | | - $wrappedtext = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'. |
32 | | -' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'. |
33 | | -'<head><title>test</title></head><body>'.$text.'</body></html>'; |
| 79 | + $wrapper = new MWTidyWrapper; |
| 80 | + $wrappedtext = $wrapper->getWrapped( $text ); |
34 | 81 | |
35 | 82 | if( $wgTidyInternal ) { |
36 | 83 | $correctedtext = self::execInternalTidy( $wrappedtext ); |
— | — | @@ -41,8 +88,14 @@ |
42 | 89 | return $text . "\n<!-- Tidy found serious XHTML errors -->\n"; |
43 | 90 | } |
44 | 91 | |
| 92 | + $correctedtext = $wrapper->postprocess( $correctedtext ); // restore any hidden tokens |
| 93 | + |
45 | 94 | return $correctedtext; |
46 | 95 | } |
| 96 | + |
| 97 | + function replaceEditSectionLinksCallback( $m ) { |
| 98 | + |
| 99 | + } |
47 | 100 | |
48 | 101 | /** |
49 | 102 | * Check HTML for errors, used if $wgValidateAllHtml = true. |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -3948,10 +3948,10 @@ |
3949 | 3949 | // We use a page and section attribute to stop the language converter from converting these important bits |
3950 | 3950 | // of data, but put the headline hint inside a content block because the language converter is supposed to |
3951 | 3951 | // be able to convert that piece of data. |
3952 | | - $editlink = '<editsection page="' . htmlspecialchars($editlinkArgs[0]); |
| 3952 | + $editlink = '<mw:editsection page="' . htmlspecialchars($editlinkArgs[0]); |
3953 | 3953 | $editlink .= '" section="' . htmlspecialchars($editlinkArgs[1]) .'"'; |
3954 | 3954 | if ( isset($editlinkArgs[2]) ) { |
3955 | | - $editlink .= '>' . $editlinkArgs[2] . '</editsection>'; |
| 3955 | + $editlink .= '>' . $editlinkArgs[2] . '</mw:editsection>'; |
3956 | 3956 | } else { |
3957 | 3957 | $editlink .= '/>'; |
3958 | 3958 | } |
Index: trunk/phase3/includes/parser/ParserOutput.php |
— | — | @@ -137,7 +137,7 @@ |
138 | 138 | |
139 | 139 | function getText() { |
140 | 140 | if ( $this->mEditSectionTokens ) { |
141 | | - return preg_replace_callback( '#<editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</editsection>))#', array( &$this, 'replaceEditSectionLinksCallback' ), $this->mText ); |
| 141 | + return preg_replace_callback( '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#', array( &$this, 'replaceEditSectionLinksCallback' ), $this->mText ); |
142 | 142 | } |
143 | 143 | return $this->mText; |
144 | 144 | } |