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

מתוך חב"דטקסט, מאגר ספרים חב"דים חופשי בגרסת טקסט.
קפיצה לניווט קפיצה לחיפוש
אין תקציר עריכה
(אין הבדלים)

גרסה מ־07:46, 6 באוקטובר 2017

/*
check recentchanges/watchlist diffs directly without navigation to other pages.
Written by: [[User:ערן]]
*/
$(function(){
	if($.inArray(mw.config.get('wgCanonicalSpecialPageName'),['Watchlist','Recentchanges'])==-1 && mw.util.getParamValue('action') != 'history') return;
	mw.loader.load(['mediawiki.action.history.diff','jquery.spinner']);
 
	var lastRequset, $diffDialog, $diffContent, rcid, patrolBtn;
	$('.mw-line-even,.mw-line-odd').click(function(e) {
		if (e.target !== this || ! $(this).children('a:contains(היסטוריה)').length) { return; }
		//initalizations
		if (!$diffContent) $diffContent = $('<div>');
		if(!$diffDialog) {
			var buttons = {
			'!': 
				function(){
					if (!rcid){
						return;//nothing to do
					}
					var api=new mw.Api();
					api.post({
						action:'patrol',
						rcid: rcid,
						token: mw.user.tokens.get('patrolToken')
					}).done(function(data){
						if (data && data.patrol) {
							patrolBtn.hide();
							mw.notify('העריכה סומנה כבדוקה');
						}
						else {
							var desc = (data && data.error && data.error.info) || '';
							mw.notify('שגיאה:' + desc);
						}
					});
					rcid=0;//dont repost
				}
			};
			$diffDialog = $('<div>').append($diffContent).dialog({
				width: '100%',
				height: '300',
				draggable: false,
				resizable: false,
				buttons: buttons
			});
			$diffDialog.dialog('widget').css({
				position:'fixed',
				bottom: '0',
				top: ''
			});
			patrolBtn = $(":button:contains('!')");
		}
		var self = this,
		    title = $(this).find('.mw-changeslist-title').text(),
		    diffHref = $(this).find('a[tabindex]').prop('href'),
		    unpatrolled = $(this).find('.unpatrolled').length
		patrolBtn.hide();
		if(diffHref) var diffId = diffHref.match(/&diff=(\d+)&oldid=/)[1];
		if(self == lastRequset) {
			return;
		}
		$diffContent.html($.createSpinner());
		var param = {
			action: 'query',
			prop: 'revisions',
			format: 'json'
		}
		if(diffHref){
			param.rvprop = 'timestamp';
			param.rvdiffto = 'prev';
			param.revids = diffId;
		} else {
			param.rvprop = 'content';
			param.titles = title;
		}
		$.getJSON('/api.php', param).done( function(res)
		{
			if (unpatrolled) patrolBtn.show();
			rcid = unpatrolled && /rcid=([0-9]+)/.exec(diffHref);
			if (rcid) {
				rcid = rcid[1];
			}
 
			$(self).css('background','#fc6');
			if(lastRequset){
			$(lastRequset).css('background','#eee');
			}
			lastRequset = self;
			if(res == null)
			{
				$diffContent.html('Error');
				return false;
			}
			var revision = res.query.pages[Object.keys(res.query.pages)[0]].revisions[0];
			var diffString = diffHref ? revision.diff["*"] : revision['*'];
			if(diffString == null)
			{
				$diffContent.html('Error');
				return false;
			}
			var trTemp = $('<tr><td class="diff-marker">&nbsp;</td><td class="diff-context"></td></tr>');
			var newTable = $('<table class="diff"></table>')
				.html('<colgroup><col class="diff-marker"><col class="diff-content"><col class="diff-marker"><col class="diff-content"></colgroup>');
			if(! diffHref){
				newTable.append($('<tr><td colspan="4" class="diff-lineno">דף חדש</td></tr>'));
				var rows = diffString.split('\n');
				for(var tr in rows){
					var curTr = trTemp.clone();
					curTr.find('.diff-context').first().text(rows[tr]);
					newTable.append(curTr);
				}
			} else {
				newTable.append(diffString);
			}
			$diffDialog.dialog('option','title',title);
			$diffContent.html(newTable);
			$diffDialog.dialog('isOpen') || $diffDialog.dialog('widget').show();
		});
	});
});