Skip to content

Commit

Permalink
fluff: Avoid using Morebits.queryString to parse the url for 'oldid'
Browse files Browse the repository at this point in the history
The url on diffs and old revisions is fickle, and may not necessarily display exactly what you think or expect based solely on the value of oldid.

- wgRevisionId added in MW 1.22 circa (2013)
- wgDiffOldId and wgDiffNewId added in MW 1.30 (2017)
  • Loading branch information
Amorymeltzer committed Mar 22, 2019
1 parent 4b98f05 commit 3e5ec5b
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions modules/twinklefluff.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var buildLink = function(color, text) {

Twinkle.fluff = {
auto: function() {
if( parseInt( Morebits.queryString.get('oldid'), 10) !== mw.config.get('wgCurRevisionId') ) {
if( mw.config.get('wgRevisionId') !== mw.config.get('wgCurRevisionId') ) {
// not latest revision
alert("Can't rollback, page has changed in the meantime.");
return;
Expand Down Expand Up @@ -99,13 +99,7 @@ Twinkle.fluff = {
return;
}

var old_rev_url = $("#mw-diff-otitle1").find("strong a").attr("href");

// Lets first add a [restore this revision] link
var query = new Morebits.queryString( old_rev_url.split( '?', 2 )[1] );

var oldrev = query.get('oldid');

var revertToRevision = document.createElement('div');
revertToRevision.setAttribute( 'id', 'tw-revert-to-orevision' );
revertToRevision.style.fontWeight = 'bold';
Expand All @@ -114,24 +108,21 @@ Twinkle.fluff = {

revertToRevisionLink.href = "#";
$(revertToRevisionLink).click(function(){
Twinkle.fluff.revertToRevision(oldrev);
Twinkle.fluff.revertToRevision(mw.config.get('wgDiffOldId').toString());
});

revertToRevision.appendChild(revertToRevisionLink);
otitle.insertBefore( revertToRevision, otitle.firstChild );

if( document.getElementById('differences-nextlink') ) {
// Not latest revision
var new_rev_url = $("#mw-diff-ntitle1").find("strong a").attr("href");
query = new Morebits.queryString( new_rev_url.split( '?', 2 )[1] );
var newrev = query.get('oldid');
revertToRevision = document.createElement('div');
revertToRevision.setAttribute( 'id', 'tw-revert-to-nrevision' );
revertToRevision.style.fontWeight = 'bold';
revertToRevisionLink = buildLink('SaddleBrown', 'restore this version');
revertToRevisionLink.href = "#";
$(revertToRevisionLink).click(function(){
Twinkle.fluff.revertToRevision(newrev);
Twinkle.fluff.revertToRevision(mw.config.get('wgDiffNewId').toString());
});
revertToRevision.appendChild(revertToRevisionLink);
ntitle.insertBefore( revertToRevision, ntitle.firstChild );
Expand Down

0 comments on commit 3e5ec5b

Please sign in to comment.