بەکارھێنەر:Épine/script-copyvio.js

لە ئینسایکڵۆپیدیای ئازادی ویکیپیدیاوە
تێبینی: دوای پاشەکەوتکردن، پێویستە کاشی وێبگەڕەکەت پاک بکەیتەوە تا گۆڕانکارییەکان ببینیت. بۆ گووگڵ کڕۆم، فایەرفۆکس، مایکرۆسۆفت ئێج و سافاری: پەنجە لەسەر دوگمەی ⇧ Shift ڕاگرە و کرتە لەسەر Reload بکە. بۆ وردەکاری و ڕێنمایییەکان لەسەر وێبگەڕەکانی تر، بڕوانە ئێرە.
/* Modified from [[User:Technical 13/Scripts/CVD.js]] */
// stolen from User:Ahecht/Scripts/CVD.js
/* Define which tools to use */
if(typeof(dupdet) === "undefined"){ var dupdet = false; }// Currently defaulted to FALSE due to [[User talk:Dcoetzee#Dupe Detector OK?]] and the fact it may open a lot of tabs.
if(typeof(copyvios) === "undefined"){ var copyvios = true; }// Defaulted to TRUE as it opens just one tab
 
/* Get links from page */
var externalLinks = [];
$('a.external').each(function(){
    externalLinks[externalLinks.length] = $(this).attr('href');
});
/* Clean out the duplicates */
externalLinks.sort().reverse();
var uniqueLinks = [];
$.each( externalLinks, function( i, el ){
    if($.inArray(el + '/', uniqueLinks) === -1 && $.inArray(el, uniqueLinks) === -1) uniqueLinks.push(el);
});
uniqueLinks.reverse();
/* Filter out the invalid ones */
var uniqueURLs = [];
$.each( uniqueLinks, function( i, el ){
    if(
/*     Internal WMF links            */
    el.search(/\/\/(enwp|([\w]{2}|test|meta)\.wiki[mp]edia)\.org\/?(w|wiki)?(\/index.php\?)?/i) === -1 &&/* Wikipedias */
    el.search(/\/\/en\.wikichecker\.com\/user\//i) === -1 &&/* Wikichecker */
    el.search(/\/\/tools(erver|\.wmflabs)\.org\/?/i) === -1 &&/* Tools and Labs */
/*     Stats.grok.[\w]{2}            */
    el.search(/\/\/stats\.grok\.[\w]{2}\/?/i) === -1 &&
/*     Wikiblame                     */
    el.search(/\/\/wikipedia\.ramselehof\.de\/wikiblame\.php/i) === -1 &&
/*     Google and Bing searches      */
    el.search(/\/\/(scholar|www).(bing|google).com\/(images|scholar|search|webhp)\?([\w_#&]*)?=/i) === -1 &&
/*     jstor search                  */
    el.search(/\/\/www\.jstor\.org\/action\/doBasicSearch\?Query=/i) === -1 &&
/*     Webchat / IRC                 */
    el.search(/(irc:\/\/|\/\/webchat.freenode.net\/?)/i) === -1 &&
/*     edwardbetts find link tool    */
    el.search(/\/\/edwardbetts\.com\/find_link\?q=/i) === -1
    ){
        if(el.search(/https?:/i) === -1){
            el= 'http:' + el;
        }
        uniqueURLs.push(el);
    }
});
 
/* TRON report */
 
function lpad(n, e, d) {
  var o = ''; if(typeof(d) === 'undefined'){ d='0'; } if(typeof(e) === 'undefined'){ e=2; }
  if(n.length < e){ for(var r=0; r < e - n.length; r++){ o += d; } o += n; } else { o=n; }
  return o;
}
var loadTS = new Date;
loadTS = lpad(loadTS.getUTCFullYear().toString(), 4) + lpad((loadTS.getUTCMonth()+1).toString(), 2) + lpad(loadTS.getUTCDate().toString(), 2) + lpad(loadTS.getUTCHours().toString(), 2) + lpad(loadTS.getUTCMinutes().toString(), 2) + lpad(loadTS.getUTCSeconds().toString(), 2);
var taskBUG = '== سکاڵادان بۆ [[User:Épine/script-copyvio|پشکنەری دەق]] ' + mw.config.get('wgPageName') + ' لەلایەن ' +  mw.config.get('wgUserName').replace(/ /g,'_') + ' ==\n';
taskBUG += '{'+'{User8|' + mw.config.get('wgUserName') + '}} <sup>([[Wikipedia:User access levels|<abbr title="' + mw.config.get('wgUserGroups').join(', ') + '">usergroups</abbr>]])</sup> loaded [[' + mw.config.get('wgPageName').replace(/_/g,' ') + ']] at {'+'{#time: H:i:s, F j, Y|' + loadTS + '}} (UTC).\n' + mw.config.get('wgUserName') + ' is ';
if(copyvios === true && dupdet === true){ taskBUG += 'کردنەوەی ھەموو بەستەرەکان بە بەکارھێنانی ھەردوو ئامرازەکە.'; }else if(copyvios === true && dupdet === false){ taskBUG += 'کردنەوەی ھەموو بەستەرەکان بە بەکارھێنانی پشکنەری دەق.'; }else if(copyvios === false && dupdet === true){ taskBUG += 'کردنەوەی ھەموو بەستەرەکان بە بەکارھێنانی دووپ دێت.'; }else{ taskBUG += 'ھیچ شتێک بەدەست ناھێنرێت بە بەکارھێنانی ئەم مۆدیوولە'; if(confirm('تۆ پشکنەری دەقت چالاکت کردووە بەڵام ھەموو تایبەتمەندییەکانیت ناچالاک کردووە.\تکایە پەیوەندی لەگەڵ [[user:Épine]] ببەستە.'/* + '\n\nClick "OK" to request assistance or "Cancel" to dismiss.'*/)){/* OPEN MY USER TALK PAGE WITH A NEW SECTION IN EDIT MODE */} }
taskBUG += 'The script found the following ' + externalLinks.length.toString() + ' link(s) and filtered out ' + (externalLinks.length - uniqueLinks.length).toString() + ' duplicate(s) and ' + (uniqueLinks.length - uniqueURLs.length).toString() + ' invalid link(s).  This left the ' + uniqueURLs.length + ' URL(s) listed below.';
var linkBUG = '{'+'{Hst|reason=Links}}\n{'+'{Div col start|2}}\n# ' + externalLinks.join('\n# ') + '\n{'+'{Div col end}}\n{'+'{Hsb}}';
var urlBUG = '; URLs\n{'+'{Div col start|2}}\n# ' + uniqueURLs.join('\n# ') + '\n{'+'{Div col end}}';
if(externalLinks.length > 0){ var eL = true; } else { var el = false; } if(uniqueURLs.length > 0){ var eU = true; } else { var eU = false; } if(eL && eU){ var bugBUG = '{'+'{Hst|reason='; } if(eL){ bugBUG += 'Links'; } if(eL && eU){ bugBUG += ' and '; } if(eU){ bugBUG += 'URLs' } if(eL && eU){ bugBUG += ' returned by script}}\n'; } if(eL){ bugBUG += linkBUG; } if(eL && eU){ bugBUG += '\n'; } if(eU){ bugBUG += urlBUG; } if(eL && eU){ bugBUG += '\n{'+'{Hsb}}'; }
console.info('<!-- BUG REPORT HELPER CODE BELOW.  Do not include this comment. -->\n%s\n%s\n<!-- END OF BUG REPORT HELPER CODE. Do not include this comment. -->', taskBUG, bugBUG);
 
/* report TROFF */

var toolTip = 'Scan for copyright violations';
if(uniqueURLs.length !== 0) {
	toolTip += ' in the '+ uniqueURLs.length + ' unique URL'; 
	if(uniqueURLs.length !== 1){ toolTip += 's'; }
	toolTip += ' detected';
}
toolTip += ' using '

if(dupdet === true){
	toolTip += 'پشکنەری دووبارەبوونەوەی دێرێک کۆتزی';
	if(copyvios === true){
		var countURLs = ' (' + (uniqueURLs.length +1) + ')';
		toolTip += ' و ئامرازەکانی پێشێلکردنی مافی بڵاوکردنەوەی ئیرویگ (';
		if(uniqueURLs.length > 9){ toolTip += 'WARNING: '; }
		toolTip += 'ئەمە ' + (uniqueURLs.length +1) + ' تاب/پەنجەرەی نوێ دەکاتەوە.)';
	}else{
		var countURLs = ' (' + uniqueURLs.length + ')';
		toolTip += ' tool. (';
		if(uniqueURLs.length > 9){ toolTip += 'ئاگاداری: '; }
		toolTip += 'ئەمە ' + (uniqueURLs.length) + ' تاب/پەنجەرەی نوێ دەکاتەوە';
		if(uniqueURLs.length !== 1){ toolTip += 's'; }
		toolTip += '.)';
	}
}else{
	if(copyvios === true){
		var countURLs = '';
		toolTip += 'Earwig\'s Copyvio Detector tool. (This will open in a new tab/window)';
	}else{
		var countURLs = '';
		toolTip += 'ئامراز نییە.';
	}
}

var scanCV = mw.util.addPortletLink(
    'p-tb',
    '#',
    'پشکنەری دەق' + countURLs,
    'p-cv-detector',
    toolTip
);
 
$( scanCV ).click( function ( e ) {
    e.preventDefault();
    if(dupdet){
        if(uniqueURLs.length > 19){
            var lottaTabs = confirm('دڵنیایت دەتەوێت ' + (uniqueURLs.length +1) + ' تابی نوێ بکەیتەوە؟');
            if(lottaTabs === true){
                for(var i=0; i < uniqueURLs.length; i++){
                    window.open('http://tools.wmflabs.org/dupdet/compare.php?url1=' + encodeURIComponent('https:' + wgServer + mw.config.get('wgScriptPath') + '/index.php?title=' + mw.config.get('wgPageName')) + '&url2=' + encodeURIComponent(uniqueURLs[i]), '_blank');
                }
            } else {
                alert('کەواتە تەنیا تاب بۆ پێنج بەستەری سەرەتا دەکرێتەوە');
               for(var i=0; i < 5; i++){
                    window.open('http:///tools.wmflabs.org/dupdet/compare.php?url1=' + encodeURIComponent('https:' + wgServer + mw.config.get('wgScriptPath') + '/index.php?title=' + mw.config.get('wgPageName')) + '&url2=' + encodeURIComponent(uniqueURLs[i]), '_blank');
                }
            }
        } else {
            for(var i=0; i < uniqueURLs.length; i++){
                window.open('http:///tools.wmflabs.org/dupdet/compare.php?url1=' + encodeURIComponent('https:' + wgServer + mw.config.get('wgScriptPath') + '/index.php?title=' + mw.config.get('wgPageName')) + '&url2=' + encodeURIComponent(uniqueURLs[i]), '_blank');
            }
        }
    }
    if(copyvios){
    	var siteName = wgSiteName.toLowerCase();
    	if(!/mediawiki|wikibooks|wikidata|wikimedia|wikinews|wikipedia|wikiquote|wikisource|wikiversity|wikivoyage|wiktionary/.test(siteName)) { siteName = 'wikipedia'; }
        window.open('http://tools.wmflabs.org/copyvios?lang=' + wgContentLanguage + '&project=' + siteName + '&title=' + encodeURIComponent(mw.config.get('wgPageName')), '_blank');
    }
});

/* Ping API */// Disabling for now per request of [[User:The Earwig]] because it is too many queries on the API due to cost concerns
/*
var CopyViosAPIQ = {
	action: 'search',
	project: mw.config.get('wgNoticeProject'),
	lang: mw.config.get('wgPageContentLanguage'),
	oldid: mw.config.get('wgRevisionId')
};
$.get("//tools.wmflabs.org/copyvios/api.json", CopyViosAPIQ, function(CopyViosAPIR){
	console.log(CopyViosAPIR.best.confidence);
	var bestMatchPercent = " (" + Math.round(CopyViosAPIR.best.confidence*1000)/10 + "%)";
	$( '#p-cv-detector' ).html($( '#p-cv-detector' ).html() + bestMatchPercent)
});
*/