MediaWiki:Gadget-markreview.js: Difference between revisions
No edit summary Tag: Reverted |
No edit summary Tag: Manual revert |
||
| (6 intermediate revisions by the same user not shown) | |||
| Line 3: | Line 3: | ||
function run($content) { | function run($content) { | ||
// Find the DocMeta table | |||
var $docMeta = $content.find('.doc-meta').first(); | var $docMeta = $content.find('.doc-meta').first(); | ||
if (!$docMeta.length) { | if (!$docMeta.length) { | ||
| Line 13: | Line 14: | ||
var action = mw.config.get('wgAction') || 'view'; | var action = mw.config.get('wgAction') || 'view'; | ||
// Only run on view action and if current user is the owner | |||
if (action !== 'view') return; | if (action !== 'view') return; | ||
if (!owner || !user || owner.toLowerCase() !== user.toLowerCase()) return; | if (!owner || !user || owner.toLowerCase() !== user.toLowerCase()) return; | ||
| Line 18: | Line 20: | ||
function doReview() { | function doReview() { | ||
var page = mw.config.get('wgPageName'); | var page = mw.config.get('wgPageName'); | ||
var | var stamp = new Date().toISOString(); | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
api.postWithToken('csrf', { | |||
api. | action: 'edit', | ||
title: page, | |||
summary: 'Mark as reviewed', | |||
appendtext: '\n<!-- review-ping: ' + stamp + ' -->', | |||
minor: true, | |||
nocreate: true | |||
}).done(function () { | |||
location.reload(); | |||
}).fail(function (err) { | |||
mw.notify('Review failed: ' + (err && err.error && err.error.info ? err.error.info : err), { type: 'error' }); | |||
}); | }); | ||
} | } | ||
| Line 80: | Line 55: | ||
}); | }); | ||
// Place it | // Place it in .doc-meta-actions if present, otherwise create it after the table | ||
var $actions = $docMeta.closest('table').nextAll('.doc-meta-actions').first(); | var $actions = $docMeta.closest('table').nextAll('.doc-meta-actions').first(); | ||
if (!$actions.length) { | if (!$actions.length) { | ||
| Line 88: | Line 63: | ||
} | } | ||
// Run on initial load and after AJAX loads | |||
mw.hook('wikipage.content').add(run); | mw.hook('wikipage.content').add(run); | ||
}); | }); | ||