לדלג לתוכן

מדיה ויקי:Gadget-rcPatrol.js: הבדלים בין גרסאות בדף

מתוך צפונות ויקי
ניסיון לתיקון תקלה שדווחה בויקיפדיה:סקריפטים/תקלות. קח אסימון ממש לפני הקריאה ל-patrol.
using [[mw:CodeEditor|CodeEditor]]: לפי הוראות מבגזילה.
שורה 28: שורה 28:
);
);
}
}
api.get({list: 'recentchanges', rctoken: 'patrol', rclimit: 1}, tokenReceived);
api.get({list: 'recentchanges', rctoken: 'patrol', rclimit: 1, rctype: 'new|edit'}, tokenReceived);
}
}



גרסה מ־02:55, 19 באפריל 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(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, rctype: 'new|edit'}, 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.