מדיה ויקי:Gadget-QuickRCDiff.js: הבדלים בין גרסאות בדף
מראה
מאין תקציר עריכה |
הוספת האפשרות לצפיה בתוכנו של דף חדש ישירות מדף השינויים האחרונים |
||
| שורה 9: | שורה 9: | ||
var lastRequset, $diffDialog, $diffContent, rcid, patrolBtn; | var lastRequset, $diffDialog, $diffContent, rcid, patrolBtn; | ||
$('.mw-line-even,.mw-line-odd').click(function(e) { | $('.mw-line-even,.mw-line-odd').click(function(e) { | ||
if (e.target !== this) { return; } | if (e.target !== this || ! $(this).children('a:contains(היסטוריה)').length) { return; } | ||
//initalizations | //initalizations | ||
if (!$diffContent) $diffContent = $('<div>'); | if (!$diffContent) $diffContent = $('<div>'); | ||
| שורה 55: | שורה 55: | ||
diffHref = $(this).find('a[tabindex]').prop('href'), | diffHref = $(this).find('a[tabindex]').prop('href'), | ||
unpatrolled = $(this).find('.unpatrolled').length | unpatrolled = $(this).find('.unpatrolled').length | ||
patrolBtn.hide(); | patrolBtn.hide(); | ||
var diffId = diffHref.match(/&diff=(\d+)&oldid=/)[1]; | if(diffHref) var diffId = diffHref.match(/&diff=(\d+)&oldid=/)[1]; | ||
if(self == lastRequset) { | if(self == lastRequset) { | ||
return; | return; | ||
} | } | ||
$diffContent.html($.createSpinner()); | $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('/w/api.php', param, function(res) | |||
{ | { | ||
if (unpatrolled) patrolBtn.show(); | if (unpatrolled) patrolBtn.show(); | ||
| שורה 69: | שורה 81: | ||
rcid = rcid[1]; | rcid = rcid[1]; | ||
} | } | ||
$(self).css('background','#fc6'); | $(self).css('background','#fc6'); | ||
if(lastRequset){ | if(lastRequset){ | ||
| שורה 80: | שורה 92: | ||
return false; | return false; | ||
} | } | ||
var | var revision = res.query.pages[Object.keys(res.query.pages)[0]].revisions[0]; | ||
var diffString = diffHref ? revision.diff["*"] : revision['*']; | |||
if(diffString == null) | if(diffString == null) | ||
{ | { | ||
| שורה 86: | שורה 99: | ||
return false; | return false; | ||
} | } | ||
var trTemp = $('<tr><td class="diff-marker"> </td><td class="diff-context"></td></tr>'); | |||
var newTable = $('<table class="diff"></table>') | 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>') | .html('<colgroup><col class="diff-marker"><col class="diff-content"><col class="diff-marker"><col class="diff-content"></colgroup>'); | ||
.append(diffString); | 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); | $diffDialog.dialog('option','title',title); | ||
$diffContent.html(newTable); | $diffContent.html(newTable); | ||
גרסה מ־16:57, 28 בספטמבר 2013
/*
check recentchanges/watchlist diffs directly without navigation to other pages.
Written by: [[User:ערן]]
*/
$(function(){
if($.inArray(mw.config.get('wgCanonicalSpecialPageName'),['Watchlist','Recentchanges'])==-1) 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')
}, 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('/w/api.php', param, 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"> </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();
});
});
});