מדיה ויקי:Gadget-rcPatrol.js: הבדלים בין גרסאות בדף
מראה
added default behavior: cache=false |
ניסיון לתיקון תקלה שדווחה בויקיפדיה:סקריפטים/תקלות. קח אסימון ממש לפני הקריאה ל-patrol. |
||
| שורה 4: | שורה 4: | ||
*/ | */ | ||
if ($.inArray(wgCanonicalSpecialPageName, ["Recentchanges", "Watchlist", "Recentchangeslinked"]) + 1) | if ($.inArray(mw.config.get('wgCanonicalSpecialPageName'), ["Recentchanges", "Watchlist", "Recentchangeslinked"]) + 1) { | ||
mw.loader.load('mediawiki.api'); | |||
$(function() { | |||
function patrol(rcid, checkbox) { | |||
var api = new mw.Api(); | |||
function tokenReceived(data) { | |||
var token = data.query.recentchanges[0].patroltoken; | |||
api.post( | |||
{action: 'patrol', rcid: rcid, token: token}, | |||
function(data, textStatus, jqXHR) { | |||
if (data && data.patrol) { | |||
if (data && data.patrol) | |||
mw.util.jsMessage('העריכה בדף ' + data.patrol.title + ' סומנה כבדוקה'); | mw.util.jsMessage('העריכה בדף ' + data.patrol.title + ' סומנה כבדוקה'); | ||
$(checkbox).remove(); | |||
} | |||
else { | else { | ||
var desc = (data && data.error && data.error.info) || ''; | var desc = (data && data.error && data.error.info) || ''; | ||
| שורה 23: | שורה 23: | ||
} | } | ||
}, | }, | ||
function(jqXHR, textStatus, errorThrown) { | |||
mw.util.jsMessage(jqXHR + '<br/>' + textStatus + '<br/>' + errorThrown); | mw.util.jsMessage(jqXHR + '<br/>' + textStatus + '<br/>' + errorThrown); | ||
} | } | ||
); | ); | ||
} | } | ||
api.get({list: 'recentchanges', rctoken: 'patrol', rclimit: 1}, tokenReceived); | |||
} | |||
function addCheckbox(elem, abbr) { | |||
var a = elem.find('a[href*="rcid="]'); | |||
if (!a.length) | |||
return; | |||
var matches = a.attr('href').match(/rcid=(\d+)/); | |||
if (matches) { | |||
var rcid = matches[1]; | |||
abbr.before($('<input>', {'type': 'checkbox'}).change(function() {patrol(rcid, 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 | }); // document.ready | ||
} // in recentchanges page. | |||
גרסה מ־20:32, 9 בספטמבר 2012
/* 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(rcid, checkbox) {
var api = new mw.Api();
function tokenReceived(data) {
var token = data.query.recentchanges[0].patroltoken;
api.post(
{action: 'patrol', rcid: rcid, 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}, tokenReceived);
}
function addCheckbox(elem, abbr) {
var a = elem.find('a[href*="rcid="]');
if (!a.length)
return;
var matches = a.attr('href').match(/rcid=(\d+)/);
if (matches) {
var rcid = matches[1];
abbr.before($('<input>', {'type': 'checkbox'}).change(function() {patrol(rcid, 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.