Diferencia entre revisiones de «MediaWiki:Gadget-tag-status-change.js»
Ir a la navegación
Ir a la búsqueda
m (guard combo diffs from tagging wrong revision) |
m (+fn names) |
||
Línea 1: | Línea 1: | ||
− | mw.hook('wikipage.diff').add(function () { |
+ | mw.hook('wikipage.diff').add(function tag_status_change() { |
// 2018-11-06 add status-change tags to pages with diffs that change the status |
// 2018-11-06 add status-change tags to pages with diffs that change the status |
||
Línea 5: | Línea 5: | ||
if (!diff) return; |
if (!diff) return; |
||
− | diff.querySelectorAll('.diff-addedline').forEach(function (el) { |
+ | diff.querySelectorAll('.diff-addedline').forEach(function find_status_change(el) { |
if (!/\{\{(stub|partial|complete)\}\}/.test(el.innerText)) return |
if (!/\{\{(stub|partial|complete)\}\}/.test(el.innerText)) return |
||
const row = el.parentElement |
const row = el.parentElement |
||
Línea 23: | Línea 23: | ||
// send the notification |
// send the notification |
||
− | ;(new mw.Api).postWithToken('csrf', |
+ | ;(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) |
mw.notify('revision tagged with '+ msg) |
||
}) |
}) |
Revisión del 19:37 14 oct 2019
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; diff.querySelectorAll('.diff-addedline').forEach(function find_status_change(el) { if (!/\{\{(stub|partial|complete)\}\}/.test(el.innerText)) return const row = el.parentElement const rem = row.querySelector('.diff-deletedline') const add = row.querySelector('.diff-addedline') 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) }) }) })