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

יצירת דף עם התוכן "←check recentchanges/watchlist diffs directly without navigation to other pages. Written by: [[User:ערן]]: $(function(){ if($.inArray(mw.config.get('wgCa..."
 
מ 25 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-QuickRCDiff.js יובאו
 
(24 גרסאות ביניים של 6 משתמשים אינן מוצגות)
שורה 1: שורה 1:
/*
if ($.inArray(mw.config.get('wgCanonicalSpecialPageName'),['Watchlist','Recentchanges'])!=-1) (function(){
check recentchanges/watchlist diffs directly without navigation to other pages.
var lastRequset, $diffDialog, $diffContent, patrolBtn, thanksBtn, diffId, diffTitle;
Written by: [[User:ערן]]
*/
$(function(){
if($.inArray(mw.config.get('wgCanonicalSpecialPageName'),['Watchlist','Recentchanges'])==-1) return;
mw.loader.load('mediawiki.action.history.diff');


var lastRequset, $diffDialog, $diffContent;
function qRcDiffHandler(content){
$('.mw-line-even,.mw-line-odd').click(function(e) {
mw.loader.load(['jquery.spinner', 'mediawiki.diff.styles']);
if (e.target !== this) { return; }
$('.mw-changeslist-edit', content).not('qRcDiff').addClass('qRcDiff').click(function(e) {
if (e.target !== this || ! $(this).find('a:contains(היסטוריה)').length) { return; }
//initalizations
//initalizations
if (!$diffContent) $diffContent = $('<div>');
if (!$diffContent) $diffContent = $('<div>');
if(!$diffDialog) {
if(!$diffDialog) {
var buttons = {
'בדיקת העתקה':
function() {
window.open('http://tools.wmflabs.org/copyvios/?lang=he&project=wikipedia&title='+diffTitle+'&oldid='+diffId+'&action=search&use_engine=1&use_links=1', '_blank')
},
'!':
function(){
if (!diffId){
return;//nothing to do
}
var api = new mw.Api();
api.postWithToken('patrol', {
action:'patrol',
revid: diffId
}).done(function(data){
if (data && data.patrol) {
patrolBtn.hide();
mw.notify('העריכה סומנה כבדוקה');
}
else {
var desc = (data && data.error && data.error.info) || '';
mw.notify('שגיאה:' + desc);
}
});
},
'♥':
function(){
if (!diffId){
return;//nothing to do
}
var api = new mw.Api();
api.postWithToken('csrf', {
action:'thank',
source: 'diff',
rev: diffId
}).done(function(data){
mw.notify('תודה נשלחה לעורך');
});
}
};
$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({
position:'fixed',
position:'fixed',
bottom: '0',
bottom: '0',
top: ''
top: 'auto'
});
});
patrolBtn = $(":button:contains('!')").prop('title', 'סימון כבדוק'),
thanksBtn =  $(":button:contains('♥')").prop('title', 'תודה');
}
}
var self = this,
var self = this,
    title = $(this).find('.mw-changeslist-title').text(),
    diffHref = $(this).find('a[href*=oldid]')
    diffHref=$(this).find('a[tabindex]').prop('href'),
    .filter(function(){
    diffId = diffHref.match(/&diff=(\d+)&oldid=/)[1];
    return !$(this)
.hasClass('WLM-icon'); // WLM collision fix
    })
    .prop('href'),
    unpatrolled = $(this).find('.unpatrolled').length;
diffTitle = $(this).find('.mw-changeslist-title').text();
patrolBtn.hide();
if(self == lastRequset) {
if(self == lastRequset) {
return;
return;
}
}
$.getJSON('/w/api.php?action=query&prop=revisions&format=json&rvprop=timestamp&rvdiffto=prev&revids='+diffId, function(res)
$diffContent.html($.createSpinner());
var param = {
action: 'query',
prop: 'revisions',
};
var isWikidata = false;
if(diffHref){
diffId = diffHref.match(/&diff=(\d+)&oldid=/)[1];
isWikidata = diffHref.match(/www\.wikidata\.org/);
param.rvprop = 'timestamp';
param.rvdiffto = 'prev';
param.revids = diffId;
} else {
diffId = 0;
param.rvprop = 'content';
param.titles = diffTitle;
}
var api = isWikidata? new mw.ForeignApi( 'https://www.wikidata.org/w/api.php' ) : new mw.Api();
 
api.get(param).done( function(res)
{
{
$(self).css('background','#fc6');
if (unpatrolled) patrolBtn.show();
 
$(self).addClass('changeslist-entry-active');
if(lastRequset){
if(lastRequset){
$(lastRequset).css('background','#eee');
$(lastRequset).addClass('changeslist-entry-visited');
$(lastRequset).removeClass('changeslist-entry-active');
}
}
lastRequset = self;
lastRequset = self;
if(res == null)
if(res === null)
{
{
$diffContent.html('Error');
$diffContent.html('Error');
return false;
return false;
}
}
var diffString = res.query.pages[Object.keys(res.query.pages)[0]].revisions[0].diff["*"];
var revision = res.query.pages[Object.keys(res.query.pages)[0]].revisions[0];
if(diffString == null)
var diffString = diffHref ? revision.diff["*"] : revision['*'];
if(diffString === null)
{
{
$diffContent.html('Error');
$diffContent.html('Error');
return false;
return false;
}
}
 
var trTemp = $('<tr><td class="diff-marker">&nbsp;</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){
$diffDialog.dialog('option','title',title);
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',diffTitle);
$diffContent.html(newTable);
$diffContent.html(newTable);
$diffDialog.dialog('isOpen') || $diffDialog.dialog('widget').show();
$diffDialog.dialog('isOpen') || $diffDialog.dialog('open').dialog('widget').css({'height': '300px', 'top':'auto'});
});
});
});
});
});
}
 
mw.hook( 'wikipage.content' ).add(qRcDiffHandler);
})();