MediaWiki workaround

August 18, 2009

MediaWiki had an obsolete stylesheet called "KHTMLFixes" that had some KHTML-specific workarounds (KHTML, recall, is the HTML engine WebKit was forked from). A WebKit fix for correctness caused the workaround to begin causing problems, breaking sites like Wikipedia.

The problematic file in MediaWiki was removed a month ago, with the commit message:

Remove KHTMLFixes.css

This was added more than five years ago, in r3532.  It was being
loaded for WebKit as well as KHTML, and I could notice no
difference in either Chrome or Konqueror whether it was loaded or
not.  It was responsible for causing display errors with an HTML 5
doctype in WebKit.

But even then, there are scores of MediaWiki sites out there, including MediaWiki forks that will never update to include this fix, and all would be broken in WebKit. So it was reluctantly decided to work around it, complete with hardcoding in the CSS comments deep in the bowels of WebKit (code reformatted for clarity):

// Work around <>.
DEFINE_STATIC_LOCAL(const String, slashKHTMLFixesDotCss, ("/KHTMLFixes.css"));
DEFINE_STATIC_LOCAL(const String, mediaWikiKHTMLFixesStyleSheet,
   ("/* KHTML fix stylesheet */\n"
    "/* work around the horizontal scrollbars */\n"
    "#column-content { margin-left: 0; }\n\n"));
if (url.endsWith(slashKHTMLFixesDotCss) &&
    sheetText == mediaWikiKHTMLFixesStyleSheet) {

In the Chrome world, we'd typically also add a bit here that would record a count that would be included in our stats collecting indicating how often this was hit in the wild (as always, only for users that opted into anonymous stats recording); we could then use this to judge when it'd be safe to remove this hack. Unfortunately, WebKit has no such infrastructure.