User:Locke/common.js: Difference between revisions
Jump to navigation
Jump to search
Want an adless experience? Log in or Create an account.
No edit summary |
No edit summary |
||
Line 4: | Line 4: | ||
if ($diffMultiNotice.length > 0) { | if ($diffMultiNotice.length > 0) { | ||
var $patrolAllLink = $('<a href="#">Mark all as patrolled</a>'); | var $patrolAllLink = $('<a href="#">Mark all as patrolled</a>'); | ||
$diffMultiNotice.append('<br>').append($patrolAllLink); | $diffMultiNotice.append('<br>[').append($patrolAllLink).append(']'); | ||
// patrol link click handler | // patrol link click handler | ||
$patrolAllLink.click(function() { | $patrolAllLink.click(function(e) { | ||
var $this = $(this); | var $this = $(this); | ||
// replace text with spinner | // replace text with spinner |
Revision as of 22:54, March 20, 2017
if (mw.user.tokens.exists('patrolToken')) { // add patrol link under diff-multi notice var $diffMultiNotice = $('td.diff-multi'); if ($diffMultiNotice.length > 0) { var $patrolAllLink = $('<a href="#">Mark all as patrolled</a>'); $diffMultiNotice.append('<br>[').append($patrolAllLink).append(']'); // patrol link click handler $patrolAllLink.click(function(e) { var $this = $(this); // replace text with spinner mw.loader.using('jquery.spinner').then(function() { var $spinner = $.createSpinner({ size :'small', type: 'inline' }); $this.hide().after($spinner); }); // find bounding revision ids var oldid = mw.util.getParamValue('oldid', $('#mw-diff-otitle1 strong a').attr('href')); var newid = mw.util.getParamValue('oldid', $('#mw-diff-ntitle1 strong a').attr('href')); var title = mw.util.getParamValue('title', $('#mw-diff-ntitle1 strong a').attr('href')); // call api for all revisions in that span var api = new mw.Api(); api.get({ action: 'query', prop: 'revisions', rvprop: 'ids', rvstartid: newid, rvendid: oldid, rvlimit: 'max', titles: title } ).done( function ( data ) { console.log( data ); /* // mw.loader.load('mediawiki.notification'); apiRequest.postWithToken('patrol', { formatversion: 2, action: 'patrol', rcid: rcid }) .done(function(data) { $patrolLinks.closest('.patrollink').remove(); if(data.patrol !== undefined) { var title = new mw.Title(data.patrol.title); mw.notify(mw.msg('markedaspatrollednotify', title.toText())); } else { mw.notify(mw.msg('markedaspatrollederrornotify'), { type: 'error' }); } }) .fail(function(error) { $spinner.remove(); $patrolLinks.show(); if (error === 'noautopatrol') { mw.notify(mw.msg('markedaspatrollederror-noautopatrol'), { type: 'warn' }); } else { mw.notify(mw.msg('markedaspatrollederrornotify'), { type: 'error' }); } }); */ } ); e.preventDefault(); /*{"markedaspatrollederror-noautopatrol":"You are not allowed to mark your own changes as patrolled.","markedaspatrollederrornotify":"Marking as patrolled failed.","markedaspatrollednotify":"This change to $1 has been marked as patrolled."});*/ }); } }