* (bug 9948) Workaround for diff regression with old Mozilla versions
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 13 Jun 2007 20:08:19 +0000 (20:08 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 13 Jun 2007 20:08:19 +0000 (20:08 +0000)
Use JS to detect old Gecko versions known to have bogus implementation of overflow: auto for vertical sizing <div>s in table cells and change it to overflow: visible for an ugly but more-or-less-legible fallback behavior.

RELEASE-NOTES
includes/DifferenceEngine.php
includes/EditPage.php
skins/common/diff.css
skins/common/diff.js [new file with mode: 0644]

index 8160300..223f155 100644 (file)
@@ -164,6 +164,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 10215) Show custom editing introduction when editing existing pages
 * (bug 10223) Fix edit link in noarticletext localizations for fr, oc
 * (bug 10247) Fix IP address regex to avoid false positive IPv6 matches
+* (bug 9948) Workaround for diff regression with old Mozilla versions
 
 
 == API changes since 1.10 ==
index 8d96e3d..98847b9 100644 (file)
@@ -296,11 +296,22 @@ CONTROL;
                        $wgOut->addWikitext( wfMsg( 'missingarticle', "<nowiki>(fixme, bug)</nowiki>" ) );
                        return false;
                } else {
-                       $wgOut->addStyle( 'common/diff.css' );
+                       $this->showDiffStyle();
                        $wgOut->addHTML( $diff );
                        return true;
                }
        }
+       
+       /**
+        * Add style sheets and supporting JS for diff display.
+        */
+       function showDiffStyle() {
+               global $wgStylePath, $wgStyleVersion, $wgOut;
+               $wgOut->addStyle( 'common/diff.css' );
+               
+               // JS is needed to detect old versions of Mozilla to work around an annoyance bug.
+               $wgOut->addScript( "<script type=\"text/javascript\" src=\"$wgStylePath/common/diff.js?$wgStyleVersion\"></script>" );
+       }
 
        /**
         * Get diff table, including header
index b67189f..3a8038a 100644 (file)
@@ -1104,8 +1104,7 @@ class EditPage {
                        }
 
                        if ( 'diff' == $this->formtype ) {
-                               $wgOut->addStyle( 'common/diff.css' );
-                               $wgOut->addHTML( $this->getDiff() );
+                               $this->showDiff();
                        }
                }
 
@@ -1287,8 +1286,7 @@ END
                        }
 
                        if ( $this->formtype == 'diff') {
-                               $wgOut->addStyle( 'common/diff.css' );
-                               $wgOut->addHTML( $this->getDiff() );
+                               $this->showDiff();
                        }
 
                }
@@ -1910,10 +1908,8 @@ END
         *
         * If this is a section edit, we'll replace the section as for final
         * save and then make a comparison.
-        *
-        * @return string HTML
         */
-       function getDiff() {
+       function showDiff() {
                $oldtext = $this->mArticle->fetchContent();
                $newtext = $this->mArticle->replaceSection(
                        $this->section, $this->textbox1, $this->summary, $this->edittime );
@@ -1924,11 +1920,13 @@ END
                        $de = new DifferenceEngine( $this->mTitle );
                        $de->setText( $oldtext, $newtext );
                        $difftext = $de->getDiff( $oldtitle, $newtitle );
+                       $de->showDiffStyle();
                } else {
                        $difftext = '';
                }
 
-               return '<div id="wikiDiff">' . $difftext . '</div>';
+               global $wgOut;
+               $wgOut->addHtml( '<div id="wikiDiff">' . $difftext . '</div>' );
        }
 
        /**
index f8825a3..6a1f23b 100644 (file)
@@ -62,4 +62,13 @@ table.diff td div {
        /* As fallback, scrollbars will be added for very wide cells
           instead of text overflowing or widening */
        overflow: auto;
+       
+       /* The above rule breaks on very old versions of Mozilla due
+          to a bug which collapses the table cells to a single line.
+          
+          In Mozilla 1.1 and below with JavaScript enabled, the rule
+          will be overridden with this by diff.js; wide cell contents
+          then spill horizontally without widening the rest of the
+          table: */
+       /* overflow: visible; */
 }
diff --git a/skins/common/diff.js b/skins/common/diff.js
new file mode 100644 (file)
index 0000000..e80a895
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+Workaround for overflow bug in Mozilla 1.1 and earlier, where scrolling
+<div>s in <td> cells collapse their height to a single line.
+
+Known to be fixed in 1.2.1 (Gecko 20021130), but the CSS hacks I've tried
+with overflow-x disable the scrolling all the way until Mozilla 1.8 / FF 1.5
+and break Opera as well.
+
+So... we check for reaaaally old Gecko and hack in an alternate rule to let
+the wide cells spill instead of scrolling them. Not ideal as it won't work
+if JS is disabled, of course.
+*/
+
+if (navigator && navigator.product == "Gecko" && navigator.productSub < "20021130") {
+       var sheets = document.styleSheets;
+       var lastSheet = sheets[sheets.length-1];
+       lastSheet.insertRule(
+               "table.diff td div { overflow: visible; }",
+               lastSheet.cssRules.length);
+}
\ No newline at end of file