Wikipedia talk:WikiProject User scripts/Scripts/Fix diff width

bugzilla:01229 – "Balance diff display more evenly"
bugzilla:04801 – "user:foo/monobook.js does not render in preview"

Beautiful!

edit

I tried doing this a while ago with just css but it didn't work very well. — Omegatron 02:17, 12 January 2006 (UTC)Reply

Is there a way to get this formatting while still using tables? It was pointed out on bugzilla:1229 that the diffs are inherently tabular. I have to agree. If I turn off css, the diffs become a useless list of blocks, instead of staying in their table form. — Omegatron 21:23, 30 January 2006 (UTC)Reply

Known bugs

edit

The following problems have not been fully worked around yet. If you have further information about their causes or if you find additional problems, please add them to the list. Both of the currently listed problems are fairly minor, and the script is perfectly usable on the affected browsers.

  • Mozilla: A vertical scroll bar sometimes appears in some boxes, usually on the right column, for no apparent reason. Resizing the window fixes the problem.
  • Konqueror: The signs are sometimes not centered vertically. This appears to be caused by a race condition where the centering code runs before the boxes have fully rendered. A brief delay has been added to the script to mitigate the effect. Resizing or reloading usually fixes the problem.

Fixed bugs

edit

The following problems have been worked around in the latest version:

  • All browsers: There is no standard CSS way to center the +/- signs vertically. This has been worked around using a nonstandard dynamic CSS rule for IE and a JavaScript kluge for other browsers.
  • Internet Explorer: IE does not expand boxes to accommodate the scroll bar, but simply places it on top of the content. An IE-specific dynamic CSS rule has been added to fix this issue, but it currently has to make assumptions about the scroll bar size.
  • Internet Explorer: IE often needlessly adds vertical scroll bars to boxes. This has been fixed with an overflow-y CSS rule.
  • Internet Explorer: The xdiff-row and xdiff-outer wrapper elements have been introduced to fix a number of rendering inconsistencies between IE and other browsers.
  • Mozilla: The IE-specific dynamic CSS rules mentioned above cause Firefox 1.5 to emit warnings to the JavaScript Console. This has been fixed by hiding the rules from non-IE browsers.

Just another code

edit
if (document.URL.indexOf("&diff=",30)>0) addOnloadHook(function (){
 var diffT = document.getElementById("bodyContent"),
 diffTable = diffT.getElementsByTagName("table")[0];
 var diffT = diffTable.getElementsByTagName("tr")[0].getElementsByTagName("td"),
 diffo = diffT[0], diffn = diffT[1],
 diff_width = (diffo.clientWidth < diffn.clientWidth)? diffn.clientWidth: diffo.clientWidth;
 diffTable.setAttribute("width", diff_width*2);
});

This alternativ code fixes only the table-width. What do you think? --Olliminatore 17:00, 27 April 2006 (UTC)Reply

How does it work? — Omegatron 17:10, 27 April 2006 (UTC)Reply
It does give (after the diff-page is loaded) the both columns again real 50%, but with a maximum of the other. ps: test example hereOlliminatore 17:40, 27 April 2006 (UTC)Reply

Alternative to highlighting diff with red font color (only)

edit

Perhaps it's worth considering highlighting this way for example, instead of this way. The advantage would be that blanks would also be highlighted. I've already looked at the JavaScript code myself, but haven't the faintest idea of how that could be done. And last not least – thanks for a great solution :)  -- ParaDox 16:17, 13 May 2006 (UTC)Reply

This can be easily accomplished by editing your monobook.css. For example, mine contains the line:
span.diffchange { text-decoration: underline; }
This makes the changes appear like this. It works just fine either with or without this script. (However, note that it doesn't completely solve the whitespace issue — some whitespace changes are still hidden, probably due to the browser merging adjacent spaces into one.) —Ilmari Karonen (talk) 18:01, 13 May 2006 (UTC)Reply
Thank you :-)  Works fine. -- ParaDox 13:42, 14 May 2006 (UTC)Reply

RowsMax-Patch (not only for Win98-Systems)

edit

Perhaps someone might also experience trouble through using the script on a Win98-System (with Firefox). If a diff produces very many table-rows, like this example with 741 rows, it will use up system-resources down to zero, making a reset necessary. Not being any good with JavaScript, my patch isn't very elegant, simply limiting diffs to 200 (until I have some experience in every day wathchlist use). A good idea would be a version which switches to normal diff-mode if a table threatens to get too large, perhaps asking the user which option they want, etc. ;) -- ParaDox 15:49, 21 May 2006 (UTC)Reply

I've added some output to the browser status-line in the script to give feedback to the user about "size of xdiffs" etc.
-- ParaDox 08:40, 22 May 2006 (UTC)Reply
The script can indeed be slow for large diffs. Any optimizations would be welcome, but the proper solution, of course, would be to roll this thing into the MediaWiki code so that we don't need to do it in JavaScript. I'll try to submit a patch to do that one of these days, as soon as I find that round tuit I've been looking for... —Ilmari Karonen (talk) 20:53, 22 May 2006 (UTC)Reply
Since my RowsMax-Patch with a limit of 200 rows, I no longer have any problems, and through observation have found out, that critically low system-resource levels are no longer reached, no matter how many diff-rows occur. The limit of 200 also has the pleasant effect, that the browser no longer hangs too long with large diffs. -- ParaDox 10:58, 23 May 2006 (UTC)Reply

Very simple CSS fix?

edit

I added this rule to my CSS:

.diff-context, .diff-deletedline, .diff-addedline { overflow: auto; display: block; }

I can see no substantial screwiness with the way it displays, and it loads instantly. —Simetrical (talk • contribs) 01:31, 13 June 2006 (UTC)Reply

Hmm. Works nicely in Firefox 1.5, not at all on Konqueror 3.3.2. Haven't tested other browsers yet. —Ilmari Karonen (talk) 14:51, 13 June 2006 (UTC)Reply
More testing: Works on Opera 8.52, no effect on Internet Explorer 5.00. —Ilmari Karonen (talk) 15:01, 13 June 2006 (UTC)Reply

Now that it's obsolete...

edit

Should we alert those still including it in their *.js that it's no longer needed and indeed is buggy? (I removed it after I saw that it was messing up diff display in my FF2 once Brion's changes went live.) Also, one might want to further deprecate it by removing the link from the Wikiproject - I doubt many powerusers interested in adding scripts will be using browsers old enough that Brion's fix doesn't work for them. --Gwern (contribs) 23:59 16 May 2007 (GMT)

Well, they certainly shouldn't be, since Brion's version basically does on the server side what this one does on the client side — the browser support should be pretty similar. If anything, the client-side implementation may require a newer browser. The script does have some tweaks that we might want to eventually incorporate into the server-side solutions, particularly involving IE6 compatibility, but it is indeed pretty much obsolete. It might be best to look for any userspace copies of this script and simply disable them (by, say, prepending if (false) to the addOnloadHook() line). —Ilmari Karonen (talk) 04:55, 17 May 2007 (UTC)Reply
...which I just did — there weren't really all that many. I left Steel359's version alone, since it was already wrapped in a conditional. Incidentally, a lot of the pages returned by that query only contained the CSS-injection part, but not the actual body of the script. Presumably these were all copied from a single source, perhaps User:Xy7/monobook.js. —Ilmari Karonen (talk) 05:32, 17 May 2007 (UTC)Reply