User:Locke/common.js: Difference between revisions

From Zelda Dungeon Wiki
Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.
(load spinner)
(moved to Tabs2.js)
Tag: Blanking
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
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);


    // patrol link click handler
    $patrolAllLink.click(function() {
      mw.loader.load('jquery.spinner');
      mw.loader.load('mediawiki.notification');
      // replace text with spinner
      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,
        titles: title
      } ).done( function ( data ) {
        console.log( data );
/*
      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."});*/
    });
  }
}

Latest revision as of 08:47, June 27, 2020