Skip to content

Commit

Permalink
Show notification on new changes to pre-empt edit conflicts
Browse files Browse the repository at this point in the history
Solves #1418.
  • Loading branch information
siddharthvp committed May 3, 2024
1 parent 100cfbf commit c82a301
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/friendlytag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions modules/twinkleprod.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Twinkle.prod.callback = function twinkleprodCallback() {
evt.initEvent('change', true, true);
result.prodtype[0].dispatchEvent(evt);

Twinkle.notifyOnChanges();
};


Expand Down
2 changes: 2 additions & 0 deletions modules/twinklespeedy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions modules/twinklexfd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions twinkle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c82a301

Please sign in to comment.