From c82a30172ca7c02e8757fcfe165609bc64ab99f0 Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Fri, 3 May 2024 12:46:29 +0300 Subject: [PATCH] Show notification on new changes to pre-empt edit conflicts Solves #1418. --- modules/friendlytag.js | 1 + modules/twinkleprod.js | 1 + modules/twinklespeedy.js | 2 ++ modules/twinklexfd.js | 1 + twinkle.js | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 37 insertions(+) diff --git a/modules/friendlytag.js b/modules/friendlytag.js index 0f8f90ad6..7a901020a 100644 --- a/modules/friendlytag.js +++ b/modules/friendlytag.js @@ -289,6 +289,7 @@ Twinkle.tag.callback = function friendlytagCallback() { var result = form.render(); Window.setContent(result); Window.display(); + Twinkle.notifyOnChanges(); // for quick filter: $allCheckboxDivs = $(result).find('[name$=tags]').parent(); 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..30a2c2de3 100644 --- a/modules/twinklexfd.js +++ b/modules/twinklexfd.js @@ -221,6 +221,7 @@ Twinkle.xfd.callback = function twinklexfdCallback() { var result = form.render(); Window.setContent(result); Window.display(); + Twinkle.notifyOnChanges(); result.previewer = new Morebits.wiki.preview($(result).find('div#twinklexfd-previewbox').last()[0]); // We must init the controls diff --git a/twinkle.js b/twinkle.js index 489214a21..0879fd632 100644 --- a/twinkle.js +++ b/twinkle.js @@ -467,6 +467,38 @@ Twinkle.makeFindSourcesDiv = function makeSourcesDiv(divID) { } }; +Twinkle.notifyOnChanges = function pollChanges() { + let interval = setInterval(function () { + let api = new mw.Api(); + api.get({ + action: 'query', + format: 'json', + prop: 'revisions', + titles: Morebits.pageNameNorm, + formatversion: '2', + rvprop: 'ids', + rvslots: 'main', + rvstartid: mw.config.get('wgCurRevisionId') + 1, + rvdir: 'newer' + }).then(function (response) { + if (response.query.pages[0].missing) { + mw.notify('[Twinkle] This page has just been deleted!', { + type: 'error', + autoHide: false + }); + clearInterval(interval); + } + if (response.query.pages[0].revisions) { + mw.notify('[Twinkle] Page has been edited in the meantime. Reload to see latest changes.', { + type: 'warn', + autoHide: false + }); + 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)