diff --git a/modules/friendlytag.js b/modules/friendlytag.js index 0f8f90ad6..53822a321 100644 --- a/modules/friendlytag.js +++ b/modules/friendlytag.js @@ -370,6 +370,8 @@ Twinkle.tag.callback = function friendlytagCallback() { // Redirects and files: Add a link to each template's description page Morebits.quickForm.getElements(result, 'tags').forEach(generateLinks); } + + Twinkle.notifyOnChanges(); }; diff --git a/modules/twinkleprod.js b/modules/twinkleprod.js index c0a103278..13f21c5cf 100644 --- a/modules/twinkleprod.js +++ b/modules/twinkleprod.js @@ -109,6 +109,7 @@ Twinkle.prod.callback = function twinkleprodCallback() { evt.initEvent('change', true, true); result.prodtype[0].dispatchEvent(evt); + Twinkle.notifyOnChanges(); }; diff --git a/modules/twinklespeedy.js b/modules/twinklespeedy.js index 75c57099f..a6a523747 100644 --- a/modules/twinklespeedy.js +++ b/modules/twinklespeedy.js @@ -225,6 +225,8 @@ Twinkle.speedy.initDialog = function twinklespeedyInitDialog(callbackfunc) { // Check for prior deletions. Just once, upon init Twinkle.speedy.callback.priorDeletionCount(); + + Twinkle.notifyOnChanges(); }; Twinkle.speedy.callback.modeChanged = function twinklespeedyCallbackModeChanged(form) { diff --git a/modules/twinklexfd.js b/modules/twinklexfd.js index 37dfd3fda..bdeaeeea6 100644 --- a/modules/twinklexfd.js +++ b/modules/twinklexfd.js @@ -227,6 +227,8 @@ Twinkle.xfd.callback = function twinklexfdCallback() { var evt = document.createEvent('Event'); evt.initEvent('change', true, true); result.venue.dispatchEvent(evt); + + Twinkle.notifyOnChanges(); }; Twinkle.xfd.callback.wrongVenueWarning = function twinklexfdWrongVenueWarning(venue) { diff --git a/twinkle.js b/twinkle.js index 489214a21..597496016 100644 --- a/twinkle.js +++ b/twinkle.js @@ -467,6 +467,58 @@ Twinkle.makeFindSourcesDiv = function makeSourcesDiv(divID) { } }; +Twinkle.notifyOnChanges = function notifyOnChanges() { + let checkIfChanges = function (response) { + if (response.query.pages[0].missing) { + mw.notify('This page has just been deleted!', { + title: 'Twinkle', + autoHide: false, + type: 'error' + }); + return true; + } + if (response.query.pages[0].revisions) { + mw.notify('Page has been edited in the meantime. Reload to see latest changes.', { + title: 'Twinkle', + autoHide: false, + type: 'warn' + }); + return true; + } + return false; + }; + let api = new mw.Api(); + api.get({ + action: 'query', + format: 'json', + prop: 'revisions', + revids: mw.config.get('wgRevisionId'), + formatversion: '2', + rvprop: 'ids|timestamp', + rvslots: 'main' + }).then(function (response) { + if (!checkIfChanges(response)) { + let timestamp = response.query.pages[0].revisions[0].timestamp; + let interval = setInterval(function () { + api.get({ + action: 'query', + prop: 'revisions', + titles: Morebits.pageNameNorm, + formatversion: '2', + rvprop: 'ids', + rvslots: 'main', + rvstart: new Date(new Date(timestamp).getTime() + 1000).toISOString(), + rvdir: 'newer' + }).then(function (response) { + if (checkIfChanges(response)) { + clearInterval(interval); + } + }); + }, 5000); + } + }); +}; + /** Twinkle-specific utility functions shared by multiple modules */ // Used in batch, unlink, and deprod to sort pages by namespace, as // json formatversion=2 sorts by pageid instead (#1251)