Skip to content

Commit

Permalink
morebits: Do triage properly, with extra query to determine if page i…
Browse files Browse the repository at this point in the history
…s in queue

Original structure from wikimedia-gadgets#930, where we can properly asses and handle cases, rather than just swallowing all errors and avoiding stuff like wikimedia-gadgets#1093/wikimedia-gadgets#1145 and wikimedia-gadgets#1150.  Restore AfD's `triage` to where it (sensibly) was before wikimedia-gadgets#1093.
  • Loading branch information
Amorymeltzer committed Oct 11, 2020
1 parent 2773351 commit 9772ce0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 39 deletions.
9 changes: 5 additions & 4 deletions modules/twinklexfd.js
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,11 @@ Twinkle.xfd.callbacks = {

// Now we know we want to go ahead with it, trigger the other AJAX requests

// Mark the page as curated/patrolled, if wanted
if (Twinkle.getPref('markXfdPagesAsPatrolled')) {
new Morebits.wiki.page(Morebits.pageNameNorm).triage();
}

// Start discussion page, will also handle pagetriage and delsort listings
var wikipedia_page = new Morebits.wiki.page(params.discussionpage, 'Creating article deletion discussion page');
wikipedia_page.setCallbackParameters(params);
Expand Down Expand Up @@ -1053,10 +1058,6 @@ Twinkle.xfd.callbacks = {
delsortPage.load(Twinkle.xfd.callbacks.afd.delsortListing);
});
}
// Mark the page as curated/patrolled, if wanted
if (Twinkle.getPref('markXfdPagesAsPatrolled')) {
new Morebits.wiki.page(Morebits.pageNameNorm).triage();
}
});
},
todaysList: function(pageobj) {
Expand Down
73 changes: 38 additions & 35 deletions morebits.js
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,7 @@ Morebits.wiki.page = function(pageName, currentAction) {
patrolApi: null,
patrolProcessApi: null,
triageApi: null,
triageProcessListApi: null,
triageProcessApi: null,
deleteApi: null,
deleteProcessApi: null,
Expand Down Expand Up @@ -2818,6 +2819,8 @@ Morebits.wiki.page = function(pageName, currentAction) {
* passing a pageid to the API is sufficient, so in those cases just
* using Morebits.wiki.api is probably preferable.
*
* Will first check if the page is queued via fnProcessTriageList
*
* No error handling since we don't actually care about the errors
*/
this.triage = function() {
Expand All @@ -2832,11 +2835,11 @@ Morebits.wiki.page = function(pageName, currentAction) {
// If on the page in question, don't need to query for page ID
if (new mw.Title(Morebits.pageNameNorm).getPrefixedText() === new mw.Title(ctx.pageName).getPrefixedText()) {
ctx.pageID = mw.config.get('wgArticleId');
fnProcessTriage(this, this);
fnProcessTriageList(this, this);
} else {
var query = fnNeedTokenInfoQuery('triage');

ctx.triageApi = new Morebits.wiki.api('retrieving token...', query, fnProcessTriage);
ctx.triageApi = new Morebits.wiki.api('retrieving token...', query, fnProcessTriageList);
ctx.triageApi.setParent(this);
ctx.triageApi.post();
}
Expand Down Expand Up @@ -3455,56 +3458,56 @@ Morebits.wiki.page = function(pageName, currentAction) {
ctx.patrolProcessApi.post();
};

var fnProcessTriage = function() {
var pageID, token;

// Ensure that the page is curatable
var fnProcessTriageList = function() {
if (ctx.pageID) {
token = mw.user.tokens.get('csrfToken');
pageID = ctx.pageID;
ctx.csrfToken = mw.user.tokens.get('csrfToken');
} else {
var xml = ctx.triageApi.getXML();

pageID = $(xml).find('page').attr('pageid');
if (!pageID) {
ctx.pageID = $(xml).find('page').attr('pageid');
if (!ctx.pageID) {
return;
}

token = $(xml).find('tokens').attr('csrftoken');
if (!token) {
ctx.csrfToken = $(xml).find('tokens').attr('csrftoken');
if (!ctx.csrfToken) {
return;
}
}

var query = {
action: 'pagetriageaction',
pageid: pageID,
reviewed: 1,
// tags: ctx.changeTags, // pagetriage tag support: [[phab:T252980]]
// Could use an adder to modify/create note:
// summaryAd, but that seems overwrought
token: token
action: 'pagetriagelist',
page_id: ctx.pageID
};

var triageStat = new Morebits.status('Marking page as curated');

ctx.triageProcessApi = new Morebits.wiki.api('curating page...', query, fnProcessTriageSuccess, triageStat, fnProcessTriageError);
ctx.triageProcessApi.setParent(this);
ctx.triageProcessApi.post();
ctx.triageProcessListApi = new Morebits.wiki.api('checking curation status...', query, fnProcessTriage);
ctx.triageProcessListApi.setParent(this);
ctx.triageProcessListApi.post();
};

// callback from triageProcessApi.post()
var fnProcessTriageSuccess = function() {
// Swallow succesful return if nothing changed i.e. page in queue and already triaged
if ($(ctx.triageProcessApi.getResponse()).find('pagetriageaction').attr('pagetriage_unchanged_status')) {
ctx.triageProcessApi.getStatusElement().unlink();
var fnProcessTriage = function() {
var $xml = $(ctx.triageProcessListApi.getXML());
// Exit if not in the queue
if ($xml.find('pagetriagelist').attr('result') !== 'success') {
return;
}
};

// callback from triageProcessApi.post()
var fnProcessTriageError = function() {
// Ignore error if page not in queue, see https://github.com/azatoth/twinkle/pull/930
if (ctx.triageProcessApi.getErrorCode() === 'bad-pagetriage-page') {
ctx.triageProcessApi.getStatusElement().unlink();
var page = $xml.find('pages _v');
// Nothing if page already triaged/patrolled
if (!page || !parseInt(page.attr('patrol_status'), 10)) {
var query = {
action: 'pagetriageaction',
pageid: ctx.pageID,
reviewed: 1,
// tags: ctx.changeTags, // pagetriage tag support: [[phab:T252980]]
// Could use an adder to modify/create note:
// summaryAd, but that seems overwrought
token: ctx.csrfToken
};
var triageStat = new Morebits.status('Marking page as curated');
ctx.triageProcessApi = new Morebits.wiki.api('curating page...', query, null, triageStat);
ctx.triageProcessApi.setParent(this);
ctx.triageProcessApi.post();
}
};

Expand Down

0 comments on commit 9772ce0

Please sign in to comment.