מדיה ויקי:Gadget-QuickRCDiff.js: הבדלים בין גרסאות בדף
מראה
יצירת דף עם התוכן "←check recentchanges/watchlist diffs directly without navigation to other pages. Written by: [[User:ערן]]: $(function(){ if($.inArray(mw.config.get('wgCa..." |
מאין תקציר עריכה |
||
| שורה 5: | שורה 5: | ||
$(function(){ | $(function(){ | ||
if($.inArray(mw.config.get('wgCanonicalSpecialPageName'),['Watchlist','Recentchanges'])==-1) return; | if($.inArray(mw.config.get('wgCanonicalSpecialPageName'),['Watchlist','Recentchanges'])==-1) return; | ||
mw.loader.load('mediawiki.action.history.diff'); | mw.loader.load(['mediawiki.action.history.diff','jquery.spinner']); | ||
var lastRequset, $diffDialog, $diffContent; | 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) { return; } | ||
| שורה 13: | שורה 13: | ||
if (!$diffContent) $diffContent = $('<div>'); | if (!$diffContent) $diffContent = $('<div>'); | ||
if(!$diffDialog) { | 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({ | $diffDialog = $('<div>').append($diffContent).dialog({ | ||
width: '100%', | width: '100%', | ||
height: '300', | height: '300', | ||
draggable: false, | draggable: false, | ||
resizable: false | resizable: false, | ||
buttons: buttons | |||
}); | }); | ||
$diffDialog.dialog('widget').css({ | $diffDialog.dialog('widget').css({ | ||
| שורה 24: | שורה 49: | ||
top: '' | top: '' | ||
}); | }); | ||
patrolBtn = $(":button:contains('!')"); | |||
} | } | ||
var self = this, | var self = this, | ||
title = $(this).find('.mw-changeslist-title').text(), | title = $(this).find('.mw-changeslist-title').text(), | ||
diffHref=$(this).find('a[tabindex]').prop('href'), | diffHref = $(this).find('a[tabindex]').prop('href'), | ||
diffId = diffHref.match(/&diff=(\d+)&oldid=/)[1]; | unpatrolled = $(this).find('.unpatrolled').length | ||
if (!diffHref) return;//no diff | |||
patrolBtn.hide(); | |||
var diffId = diffHref.match(/&diff=(\d+)&oldid=/)[1]; | |||
if(self == lastRequset) { | if(self == lastRequset) { | ||
return; | return; | ||
} | } | ||
$diffContent.html($.createSpinner()); | |||
$.getJSON('/w/api.php?action=query&prop=revisions&format=json&rvprop=timestamp&rvdiffto=prev&revids='+diffId, function(res) | $.getJSON('/w/api.php?action=query&prop=revisions&format=json&rvprop=timestamp&rvdiffto=prev&revids='+diffId, function(res) | ||
{ | { | ||
if (unpatrolled) patrolBtn.show(); | |||
rcid = unpatrolled && /rcid=([0-9]+)/.exec(diffHref); | |||
if (rcid) { | |||
rcid = rcid[1]; | |||
} | |||
$(self).css('background','#fc6'); | $(self).css('background','#fc6'); | ||
if(lastRequset){ | if(lastRequset){ | ||
גרסה מ־13:01, 26 במרץ 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) { 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
if (!diffHref) return;//no diff
patrolBtn.hide();
var diffId = diffHref.match(/&diff=(\d+)&oldid=/)[1];
if(self == lastRequset) {
return;
}
$diffContent.html($.createSpinner());
$.getJSON('/w/api.php?action=query&prop=revisions&format=json&rvprop=timestamp&rvdiffto=prev&revids='+diffId, 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 diffString = res.query.pages[Object.keys(res.query.pages)[0]].revisions[0].diff["*"];
if(diffString == null)
{
$diffContent.html('Error');
return false;
}
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>')
.append(diffString);
$diffDialog.dialog('option','title',title);
$diffContent.html(newTable);
$diffDialog.dialog('isOpen') || $diffDialog.dialog('widget').show();
});
});
});