מדיה ויקי:Gadget-rcPatrol.js: הבדלים בין גרסאות בדף
מראה
אכא"כ |
ניסוי |
||
| שורה 7: | שורה 7: | ||
mw.loader.load('mediawiki.api'); | mw.loader.load('mediawiki.api'); | ||
$(function() { | $(function() { | ||
function patrol( | function patrol(revid, checkbox) { | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
function tokenReceived(data) { | function tokenReceived( data ) { | ||
var token = data.query.recentchanges[0].patroltoken; | var token = data.query.recentchanges[0].patroltoken; | ||
api.post( | api.post( | ||
{action: 'patrol', | {action: 'patrol', revdi: revid, token: token}, | ||
function(data, textStatus, jqXHR) { | function(data, textStatus, jqXHR) { | ||
if (data && data.patrol) { | if (data && data.patrol) { | ||
| שורה 31: | שורה 31: | ||
} | } | ||
function addCheckbox(elem, abbr) { | function addCheckbox(elem, abbr) { | ||
var a = elem.find('a').filter(function() { return /diff=\d+/.test($(this).attr('href')); } ); | var a = elem.find('a').filter(function() { return /diff=\d+/.test($(this).attr('href')); } ); | ||
if (!a.length) | if (!a.length) | ||
return; | return; | ||
abbr.before($('<input>', {'type': 'checkbox'}).change(function() { | var m = a.eq( 0 ).attr( 'href' ).match( /diff=(\d+)/ ); | ||
if ( ! m ) | |||
return; | |||
abbr.before($('<input>', {'type': 'checkbox'}).change(function() {patrol(m[1], this);})); | |||
abbr.remove(); | abbr.remove(); | ||
} | } | ||
גרסה מ־15:24, 25 ביוני 2013
/* Allows to mark pages as patrolled from the Recentchanges or Watchlist page.
*
* Written by [[User:Yonidebest]]
*/
if ($.inArray(mw.config.get('wgCanonicalSpecialPageName'), ["Recentchanges", "Watchlist", "Recentchangeslinked"]) + 1) {
mw.loader.load('mediawiki.api');
$(function() {
function patrol(revid, checkbox) {
var api = new mw.Api();
function tokenReceived( data ) {
var token = data.query.recentchanges[0].patroltoken;
api.post(
{action: 'patrol', revdi: revid, token: token},
function(data, textStatus, jqXHR) {
if (data && data.patrol) {
mw.util.jsMessage('העריכה בדף ' + data.patrol.title + ' סומנה כבדוקה');
$(checkbox).remove();
}
else {
var desc = (data && data.error && data.error.info) || '';
mw.util.jsMessage('<span style="color:red">אירעה שגיאה ' + desc + '</span>');
}
},
function(jqXHR, textStatus, errorThrown) {
mw.util.jsMessage(jqXHR + '<br/>' + textStatus + '<br/>' + errorThrown);
}
);
}
api.get({list: 'recentchanges', rctoken: 'patrol', rclimit: 1, rctype: 'new|edit'}, tokenReceived);
}
function addCheckbox(elem, abbr) {
var a = elem.find('a').filter(function() { return /diff=\d+/.test($(this).attr('href')); } );
if (!a.length)
return;
var m = a.eq( 0 ).attr( 'href' ).match( /diff=(\d+)/ );
if ( ! m )
return;
abbr.before($('<input>', {'type': 'checkbox'}).change(function() {patrol(m[1], this);}));
abbr.remove();
}
// collect tds in "enhanced" rc list
$('td.mw-enhanced-rc').each(function() {
var td = $(this);
var abbr = td.find('abbr.unpatrolled');
var sib = td.siblings();
if (sib.find('.mw-collapsible-toggle').length)
return;
addCheckbox(sib, abbr);
});
$('li.mw-line-odd, li.mw-line-even').each(function() {
addCheckbox($(this), $(this).find('abbr.unpatrolled'));
});
}); // document.ready
} // in recentchanges page.