문서 편집 권한이 없습니다. 다음 이유를 확인해주세요: 요청한 명령은 다음 권한을 가진 사용자에게 제한됩니다: 사용자. 여기에는 다른 사용자의 개인 설정이 포함되어 있기 때문에 이 자바스크립트 문서를 편집할 수 없습니다. 문서의 원본을 보거나 복사할 수 있습니다. // 영어 위키백과 User:Frietjes/findargdups.js // jQuery(document).ready(function($) { var myContent = document.getElementsByName('wpTextbox1')[0]; // -------------------------------------------------------------------------------- // var mysummary = "[[사:Namoroka/중복된 인수 찾기|도구]]를 이용하여 [[:분류:중복된 인수를 사용한 틀의 호출을 포함한 문서|중복된 인수]]를 정리함"; if(typeof findargdupseditsummary == 'string') {mysummary = findargdupseditsummary;} var morefound = "또 다른 중복된 인수가 있으나 생략되었습니다. 수정 후 다시 검사해보세요."; if(typeof findargdupsmorefound == 'string') {morefound = findargdupsmorefound;} var linktext = "중복된 인수 찾기"; if(typeof findargdupslinktext == 'string') {linktext = findargdupslinktext;} var showresultsbox = 0; if(typeof findargdupsresultsbox == 'string') { showresultsbox = 1;} // -------------------------------------------------------------------------------- // if(mw.config.get('wgNamespaceNumber') != -1 && myContent) { var portletlink = mw.util.addPortletLink('p-tb', '#', linktext, 't-fdup'); $(portletlink).click(function(e) { e.preventDefault(); wpFindDuplicateArgs(0); }); } // -------------------------------------------------------------------------------- // function wpAddResultsBox(text, num) { var div = document.getElementById('wpSummaryLabel').parentNode; if( div ) { if( num < 2 ) { if( document.getElementById('FindArgDupsResultsBox') ) { document.getElementById('FindArgDupsResultsBox').innerHTML = ''; } else { div.innerHTML = '<div id="FindArgDupsResultsBox"></div>' + div.innerHTML; } } div1 = document.getElementById('FindArgDupsResultsBox'); if( div1 ) { text = text.replace(/</g, '<'); text = text.replace(/>/g, '>'); div1.innerHTML = div1.innerHTML + '<div class="FindArgDupsResultsBox" ' + 'id="FindArgDupsResultsBox-' + num + '" ' + 'style="max-height:5em; overflow:auto; padding:5px; border:#aaa 1px solid; ' + 'background-color:cornsilk;">' + text + '</div>' + "\n"; } } } function wpClearResultsBox() { var div = document.getElementById('wpSummaryLabel').parentNode; if( div ) { if( document.getElementById('FindArgDupsResultsBox') ) { document.getElementById('FindArgDupsResultsBox').innerHTML = ''; } } } // -------------------------------------------------------------------------------- // function wpFindDuplicateArgs(debugflag) { // Flag used to determine if we have issued an alert popup var alertissued=0; // Internal for and while loop variables var i=0; var j=0; var loopcount=0; // Array used to hold the list of unnested templates var tlist = []; // Regular expression which matchs a template arg var argexp = new RegExp("\\|[\\s]*([^\\s=\\|\\[\\]\\{\\}][^=\\|\\[\\]\\{\\}]*[^\\s=\\|\\[\\]\\{\\}]|[^\\s=\\|\\[\\]\\{\\}]|)[\\s]*=", "gm"); // Copy the contents of the text window so we can modify it without problems var mytxt = myContent.value; // Remove some includeonly, noinclude, and onlyinclude tags mytxt = mytxt.replace(/<\/?[ ]*(?:includeonly|noinclude|onlyinclude)[ ]*>/gi, ''); // Remove PAGENAME, BASEPAGENAME, ... nested inside of triple braces mytxt = mytxt.replace(/\{\{\{[^\{\}]*\|[ ]*\{\{[A-Z]+\}\}\}\}\}/g, ''); // Remove some triple braces and parserfunctions inside of triple braces loopcount = 0; while((mytxt.search(/\{\{\{[^\{\}]*\}\}\}/g) >= 0) && (loopcount < 5) ) { mytxt = mytxt.replace(/\{\{\{[^\{\}]*\}\}\}/g, ''); mytxt = mytxt.replace(/\{\{#[a-z]+:[^{}=]*\}\}/gi, ''); loopcount++; } // Replace some bare braces with HTML equivalent mytxt = mytxt.replace(/([^\{])\{([^\{])/g, '$1{$2'); mytxt = mytxt.replace(/([^\}])\}([^\}])/g, '$1}$2'); // Remove newlines and tabs which confuse the regexp search mytxt = mytxt.replace(/[\s]/gm, ' '); // Compress whitespace mytxt = mytxt.replace(/[\s][\s]+/gm, ' '); // Remove some nowiki and pre text mytxt = mytxt.replace(/<nowiki[^<>]*>(?:<[^\/]|[^<])*<\/nowiki[^<>]*>/gi, ''); mytxt = mytxt.replace(/<pre[^<>]*>(?:<[^\/]|[^<])*<\/pre[^<>]*>/gi, ''); // Remove some HTML comments mytxt = mytxt.replace(/<!--(?:[^>]|[^\-]>|[^\-]->)*-->/gm, ''); // Modify some = inside of file/image/wikilinks which cause false positives loopcount = 0; while((mytxt.search(/\[\[[^\[\]\{\}]*=/gi) >= 0) && (loopcount < 5) ) { mytxt = mytxt.replace(/(\[\[[^\[\]\{\}]*)=/gi, '$1='); loopcount++; } // Now start unnesting the templates loopcount = 0; while( (mytxt.search(/(?:\{\{|\}\})/g) >= 0) && (loopcount < 20) ) { // Split into chunks, isolating the unnested templates var strlist = mytxt.split(/(\{\{[^\{\}]*\}\})/); // Loop through the chunks, removing the unnested templates for (i = 0; i < strlist.length; i++) { if( strlist[i].search(/^\{\{[^\{\}]*\}\}$/) >= 0 ) { tlist.push(strlist[i]); strlist[i] = ''; } } // Join the chunks back together for the next iteration mytxt = strlist.join(''); loopcount++; } // Preprocess some = signs inside of non-citation-templated citations for(i=0; i < tlist.length; ++i) { j=0; while( (tlist[i].search(/<ref[^<>\/]*>(?:<[^\/]|[^<])*=/gi) >= 0) && (j < 50) ) { tlist[i] = tlist[i].replace(/(<ref[^<>\/]*>(?:<[^\/]|[^<])*)=/gi, '$1='); } } // Now find duplicates in the list of unnested templates for(i=0; i < tlist.length; ++i) { // Add numbers for unnamed parameters var unp=0; tlist[i] = tlist[i].replace(/(\{\{[\s_]*#invoke[\s ]*:[^{}\|]*)\|([^{}\|=]*\|)/gi, '$1|0=$2'); while((tlist[i].search(/(\{\{(?:[^{}\[\]]|\[\[[^\[\]]*\]\])*?\|)((?:[^{}\[\]=\|]|\[[^\[\]=]*\]|\[\[[^\[\]]*\]\])*(?:\||\}\}))/) >= 0) && (unp < 25)) { unp++; tlist[i] = tlist[i].replace(/(\{\{(?:[^{}\[\]]|\[\[[^\[\]]*\]\])*?\|)((?:[^{}\[\]=\|]|\[[^\[\]=]*\]|\[\[[^\[\]]*\]\])*(?:\||\}\}))/, '$1' + unp + '=$2'); } // Array to hold any found duplicate args (reduce number of alerts) var f = []; // Split the template into an array of | arg = ... strings var p = tlist[i].match(argexp); if( p ) { for(j=0; j < p.length; ++j) { p[j] = p[j].replace(argexp, '$1'); } p = p.sort(); for(j=0; j < p.length - 1; ++j) { if( p[j] == p[j+1]) { f.push(p[j]); } } } if(f.length > 0) { alertissued = alertissued + 1; if(alertissued < 5) { if(showresultsbox > 0) { wpAddResultsBox('Duplicate \"' + f.join('\", \"') + '\" in\n' + tlist[i], alertissued); } alert('중복된 인수: \"' + f.join('\", \"') + '\"\n' + tlist[i]); } else if(alertissued == 6) { alert(morefound); } } } if (alertissued) { var editsummary = document.getElementsByName('wpSummary')[0]; if(typeof editsummary == 'object') { if (editsummary.value.indexOf(mysummary) == -1) { if (editsummary.value.match(/[^\*\/\s][^\/\s]?\s*$/)) { editsummary.value += '; ' + mysummary; } else { editsummary.value += mysummary; } } } } else { if(showresultsbox > 0) { wpClearResultsBox(); } } } // -------------------------------------------------------------------------------- // }); 사용자:Namoroka/findargdups.js 문서로 돌아갑니다.