Diferencia entre revisiones de «MediaWiki:Gadget-tag-status-change.js»

Don't tag outside of articles and only tag if the old version also has a status tag and it is a different status tag
m (+)
(Don't tag outside of articles and only tag if the old version also has a status tag and it is a different status tag)
 
(No se muestran 3 ediciones intermedias de otro usuario)
mw.hook('wikipage.diff').add(function tag_status_change() {
 
// 2018-11-06 add status-change tags to pages with diffs that change the status
const diff = document.querySelector('.diff');
if (!diff) return;
 
// exclude pages outside ns 0
diff.querySelectorAll('.diff-addedline').forEach(function (el) {
if (mw.config.get('wgNamespaceNumber') != 0) return;
if (!/\{\{(stub|partial|complete)\}\}/.test(el.innerText)) return
 
const row = el.parentElement
const status_tags = ['[sS]tub', '[pP]artial', '[cC]omplete'];
const rem = row.querySelector('.diff-deletedline')
 
const add = row.querySelector('.diff-addedline')
diff.querySelectorAll('.diff-addedlinedeletedline').forEach(function find_status_change(el) {
const msg = rem.innerText.trim() +' => '+ add.innerText.trim()
const row = el.parentElement;
console.warn('gadget:', 'tag-status-change')
const rem = row.querySelector('.diff-deletedline');
;(new mw.Api).postWithToken('csrf', { action: 'tag', revid: mw.config.get('wgRevisionId'), add: 'status-change', reason: msg, }).then(function () {
const add = row.querySelector('.diff-addedline');
mw.notify('revision tagged with '+ msg)
// FIXME: the above selectors do not work in newer diffs
})
if (!rem || !add) return;
 
var other_tags = [];
var i;
for (i=0; i<status_tags.length; i+=1) {
var st = new RegExp('\{\{' + status_tags[i] + '\}\}');
if (!st.test(rem.innerText)) {
other_tags.push(status_tags[i]);
})
}
if (other_tags.length == status_tags.length) return;
other_tags = other_tags.toString().replaceAll(',', '|');
var ot = new RegExp('\{\{(' + other_tags + ')\}\}');
if (!/\{\{(stub|partial|complete)\}\}/ot.test(eladd.innerText)) return;
const msg = rem.innerText.trim() +' => '+ add.innerText.trim();
 
// guard against tagging latest revision in multi-change diffs
if (diff.querySelector('.diff-multi')) {
// TODO: determine which of the revisions to tag?
console.warn('gadget:', 'tag-status-change', 'ignored on combination diff');
mw.notify('theses revisions contain a potential status-change ('+ msg +') which has been ignored');
return;
}
 
console.warn('gadget:', 'tag-status-change')
 
// send the notification
;(new mw.Api).postWithToken('csrf', {
action: 'tag',
revid: mw.config.get('wgRevisionId'),
add: 'status-change',
reason: msg,
}).then(function notify_success() {
mw.notify('revision tagged with '+ msg);
})
 
 
})
 
5572

ediciones