// 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 .= '/>';
}
* @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
*
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 );
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.