사용자:기나ㅏㄴ/massprotect.js
보이기
< 사용자:기나ㅏㄴ
참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다. 구글 크롬, 파이어폭스, 마이크로소프트 엣지, 사파리: ⇧ Shift 키를 누른 채 "새로 고침" 버튼을 클릭하십시오. 더 자세한 정보를 보려면 위키백과:캐시 무시하기 항목을 참고하십시오.
// Adapted from [[User:Animum/massdelete.js]]
$.when(mw.loader.using(['mediawiki.util'], $.ready)).done( function() {
mw.util.addPortletLink("p-tb", mw.config.get('wgArticlePath').replace('$1', "특수:Massprotect"), '대량 문서 보호기' , "대량 문서 보호" , "대량 문서 보호");
});
if (mw.config.get('wgCanonicalNamespace')+':'+mw.config.get('wgTitle') === '특수:Massprotect' && mw.config.get('wgAction') == 'view');
function doMassProtect() {
document.getElementById("wpMassProtectSubmit").disabled = true;
var articles = document.getElementById("wpMassProtectPages").value.split("\n");
if(articles.length == 0) return;
var text = document.getElementById("wpMassProtectText1").value;
var wpEditProtectType = document.getElementById("wpEditProtectType").value,
wpMassProtectSummary = document.getElementById("wpMassProtectSummary").value,
wpCreateProtectType = document.getElementById("wpCreateProtectType").value,
wpMoveProtectType = document.getElementById("wpMoveProtectType").value,
done = 0, failed = new Array(), error = new Array(),
wpMassProtectExpiry = document.getElementById("wpMassProtectExpiry").value;
var protectionstring = "protections=", expirystring = "expiry=";
if(wpEditProtectType != "nochange"){
protectionstring += "edit=" + wpEditProtectType;
}
if(wpCreateProtectType != "nochange"){
if(wpEditProtectType != "nochange"){
protectionstring += "|";
}
protectionstring += "create=" + wpCreateProtectType;
}
if(wpMoveProtectType != "nochange"){
if(wpEditProtectType != "nochange" || wpCreateProtectType != "nochange"){
protectionstring += "|";
}
protectionstring += "move=" + wpMoveProtectType;
}
if(protectionstring == "protections=") return;
expirystring += encodeURIComponent(wpMassProtectExpiry);
for(i=0;i<articles.length;i++) {
var article = articles[i];
if(article.length > 0) {
var req = new XMLHttpRequest();
req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json&action=query&prop=info&meta=tokens&type=csrf&titles=" + encodeURIComponent(article), false);
req.send(null);
var query = eval("(" + req.responseText + ")").query;
var token = query.tokens.csrftoken;
var response = query.pages;
for(var index in response) {
var info = response[index];
var postdata = "format=json"
+ "&action=protect"
+ "&title=" + encodeURIComponent(article)
+ "&" + protectionstring
+ "&" + expirystring
+ "&reason=" + wpMassProtectSummary + " - [[사용자:기나ㅏㄴ/massprotect|massprotect]]"
+ "&token=" + encodeURIComponent(token);
var req = new XMLHttpRequest();
req.open("POST", mw.config.get('wgScriptPath') + "/api.php", false);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", postdata.length);
req.send(postdata);
if(eval("(" + req.responseText + ")").protect ) { //If protection successful, add a tag (if page exists), update the count and the button.
if(text != ""){
var postdata = "format=json"
+ "&action=edit&nocreate=1"
+ "&title=" + encodeURIComponent(article)
+ "&prependtext=" + encodeURIComponent(text + "\n")
+ "&summary=" + encodeURIComponent(text) + " - [[사용자:기나ㅏㄴ/massprotect|massprotect]]"
+ "&token=" + encodeURIComponent(token);
var req = new XMLHttpRequest();
req.open("POST", mw.config.get('wgScriptPath') + "/api.php", false);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", postdata.length);
req.send(postdata);
}
done++;
document.getElementById("wpMassProtectSubmit").value = "(" + done + ")";
} else { //If not edited, add the title to the "failed" array and a description of the error to the "error" array.
failed.push(article);
error.push(eval("(" + req.responseText + ")").error.info);
}
}
}
if(!articles[i+1]) {
document.getElementById("wpMassProtectSubmit").value = "완료 (" + done + ")";
if(failed.length > 0) {
var linkedList = "";
for(x=0; x<failed.length; x++) {
linkedList += "<li><a href=\"" + mw.config.get('wgScript') + "?title=" + encodeURIComponent(failed[x]) + "\">" + failed[x] + "</a>: " + error[x] + "</li>"; //Links the titles in the "failed" array
}
document.getElementById("wpMassProtectFailedContainer").innerHTML += '<br /><b>실패:</b><ul>' + linkedList + '</ul>';
}
}
}
}
function gettext(title){
var req = new XMLHttpRequest();
req.open("GET", mw.config.get('wgScriptPath') + "/api.php?action=query&prop=revisions&rvprop=content&format=json&indexpageids=1&titles="+encodeURIComponent(title), false);
req.send(null);
var response = eval('(' + req.responseText + ')');
pageid = response['query']['pageids'][0];
if (pageid == "-1") {
delete req;
return '';
}
var pagetext = response['query']['pages'][pageid]['revisions'][0]['*'];
return pagetext;
}
function massprotectform() {
var bodyContent;
switch (mw.config.get('skin')) {
case 'modern':
bodyContent = 'mw_contentholder';
break;
case 'cologneblue':
bodyContent = 'article';
break;
case 'monobook':
case 'vector':
default:
bodyContent = 'bodyContent';
break;
}
document.getElementsByTagName("h1")[0].textContent = "대량 문서 보호기";
document.title = "대량 문서 보호기 - 위키백과, 우리 모두의 백과사전";
document.getElementById(bodyContent).innerHTML = '<h3 id="siteSub">위키백과, 우리 모두의 백과사전</h3><br /><br />'
+ '<form id="wpMassProtect" name="wpMassProtect">'
+ '<b>도구 사용 미숙으로 인해 발생하는 문제에 대한 책임은 <i>전적으로 귀하</i>에게 있습니다.</b>'
+ '<div id="wpMassProtectFailedContainer"></div>'
+ '<br /><br />'
+ '보호할 문서 (한 줄에 한 문서):<br />'
+ '<textarea tabindex="1" name="wpMassProtectPages" id="wpMassProtectPages" rows="10" cols="80"></textarea>'
+ '보호된 문서에 부착할 보호 태그 (옵션):<br />'
+ '<textarea tabindex="2" name="wpMassProtectText1" id="wpMassProtectText1" rows="10" cols="80"></textarea>'
+ '<br /><br /><table style="background-color:transparent">'
+ '<tr><td>편집:</td>'
+ '<td><select id="wpEditProtectType">'
+ '<option value="nochange">변경사항 없음</option>'
+ '<option value="all">보호하지 않음</option>'
+ '<option value="autoconfirmed">준보호</option>'
+ '<option value="extendedconfirmed">장기인증보호</option>'
+ '<option value="sysop">완전보호</option>'
+ '</select></td></tr>'
+ '<tr><td>생성:</td>'
+ '<td><select id="wpCreateProtectType">'
+ '<option value="nochange">변경사항 없음</option>'
+ '<option value="all">보호하지 않음</option>'
+ '<option value="autoconfirmed">준보호</option>'
+ '<option value="extendedconfirmed">장기인증보호</option>'
+ '<option value="sysop">완전보호</option>'
+ '</select></td></tr>'
+ '<tr><td>이동:</td>'
+ '<td><select id="wpMoveProtectType">'
+ '<option value="nochange">변경사항 없음</option>'
+ '<option value="all">보호하지 않음</option>'
+ '<option value="autoconfirmed">준보호</option>'
+ '<option value="extendedconfirmed">장기인증보호</option>'
+ '<option value="sysop">완전보호</option>'
+ '</select></td></tr>'
+ '<tr><td>이유:</td>'
+ '<td><input type="text" id="wpMassProtectSummary" name="wpMassProtectSummary" maxlength="255" /></td></tr>'
+ '<tr><td>기간:</td>'
+ '<td><input type="text" id="wpMassProtectExpiry" name="wpMassProtectExpiry" maxlength="255" /></td></tr>'
+ '<tr><td><input type="button" id="wpMassProtectSubmit" name="wpMassProtectSubmit" value="보호" onclick="doMassProtect()" /></td></tr></table>'
+ '</form>';
}
if(mw.config.get("wgNamespaceNumber") == -1 && mw.config.get("wgTitle").toLowerCase() == "massprotect" && /sysop/.test(mw.config.get("wgUserGroups"))) $(massprotectform);