사용자:기나ㅏㄴ/massblock.js

위키백과, 우리 모두의 백과사전.

참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다. 구글 크롬, 파이어폭스, 마이크로소프트 엣지, 사파리: ⇧ Shift 키를 누른 채 "새로 고침" 버튼을 클릭하십시오. 더 자세한 정보를 보려면 위키백과:캐시 무시하기 항목을 참고하십시오.

// After adding to your monobook.js, navigate to [[특수:Massblock]] to use the tool.

$.when(mw.loader.using(['mediawiki.util'], $.ready)).done( function() {
	mw.util.addPortletLink("p-tb", mw.config.get('wgArticlePath').replace('$1', "특수:Massblock"), '사용자 대량 차단기' , "대량 차단" , "대량 차단");
});
if (mw.config.get('wgCanonicalNamespace')+':'+mw.config.get('wgTitle') === '특수:Massblock' && mw.config.get('wgAction') == 'view');

function doMassBlock() {
    document.getElementById("wpMassBlockSubmit").disabled = true;
    var users = document.getElementById("wpMassBlockUsers").value.split("\n");
    if(users.length == 0) return;
    var wpMassBlockReasons = document.getElementById("wpMassBlockReasons").value, wpMassBlockReason = document.getElementById("wpMassBlockReason").value, blocked = 0, talkpageedited = 0, userpageedited = 0, failed = new Array(), error = new Array();
    var wpMassBlockAnononly = document.getElementById("wpMassBlockAnononly").checked, wpMassBlockNocreate = document.getElementById("wpMassBlockNocreate").checked, wpMassBlockEmail = document.getElementById("wpMassBlockEmail").checked, wpMassBlockAutoblock = document.getElementById("wpMassBlockAutoblock").checked, wpMassBlockTalkpage = document.getElementById("wpMassBlockTalkpage").checked, wpMassBlockReblock = document.getElementById("wpMassBlockReblock").checked;
    var wpMassBlockMessage = document.getElementById("wpMassBlockMessage").value, wpMassBlockTag = document.getElementById("wpMassBlockTag").value, wpMassBlockExpiry = document.getElementById("wpMassBlockExpiry").value;
    var wpMassBlockSummaryTalk = document.getElementById("wpMassBlockSummaryTalk").value, wpMassBlockSummaryUser = document.getElementById("wpMassBlockSummaryUser").value, wpMassBlockExpiry = document.getElementById("wpMassBlockExpiry").value;
    var blocksettingstring = "&expiry=" + encodeURIComponent(wpMassBlockExpiry == ""? "indefinite" : wpMassBlockExpiry) + (wpMassBlockAnononly ? "&anononly=1" : "") + (wpMassBlockNocreate ? "&nocreate=1" : "") + (wpMassBlockAutoblock ? "&autoblock=1" : "") + (wpMassBlockEmail ? "&noemail=1" : "") + (wpMassBlockTalkpage ? "" : "&allowusertalk=1") + (wpMassBlockReblock ? "&reblock=1" : "");
    for(i=0;i<users.length;i++) {
        var user = users[i];
        if(user.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=User:" + encodeURIComponent(user), false);
            req.send(null);
            var query = eval("(" + req.responseText + ")").query;
            var blocktoken = query.tokens.csrftoken;
            var response = query.pages;
            for(var index in response) {
                var info = response[index];
                var postdata = "format=json"
                             + "&action=block"
                             + "&user=" + encodeURIComponent(user)
                             + "&reason=" + encodeURIComponent(wpMassBlockReasons == "other" ? wpMassBlockReason : wpMassBlockReasons + (wpMassBlockReason ? ": " + wpMassBlockReason + " - [[사용자:기나ㅏㄴ/massblock|massblock]]": "[[사용자:기나ㅏㄴ/massblock|massblock]]"))
                             +  blocksettingstring
                             + "&token=" + encodeURIComponent(blocktoken);
                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 + ")")['block']) { //If blockd, update the blockd count and the button.
                    blocked++;
		    // now edit user and user talk.
                    if(wpMassBlockMessage != "") {
                        var postdata = "format=json&action=edit&watchlist=nochange&title=User%20talk:" + encodeURIComponent(user) + "&summary=" + encodeURIComponent(wpMassBlockSummaryTalk) + " - [[사용자:기나ㅏㄴ/massblock|massblock]]"
                             + "&appendtext=" + '\n' + encodeURIComponent(wpMassBlockMessage)
                             + "&token=" + encodeURIComponent(blocktoken);
                        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 + ")")['edit']) { talkpageedited ++; }
                        else { //If not edited, add the title to the "failed" array and a description of the error to the "error" array.
                            failed.push("User talk:" + user);
                            error.push(eval("(" + req.responseText + ")").error.info);
                        }
		    }
                    if(wpMassBlockTag != "") {
                        var postdata = "format=json&action=edit&watchlist=nochange&title=User:" + encodeURIComponent(user) + "&summary=" + encodeURIComponent(wpMassBlockSummaryUser) + " - [[사용자:기나ㅏㄴ/massblock|massblock]]"
                             + "&text=" + encodeURIComponent(wpMassBlockTag)
                             + "&token=" + encodeURIComponent(blocktoken);
                        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 + ")")['edit']) { userpageedited ++; }
                        else { //If not edited, add the title to the "failed" array and a description of the error to the "error" array.
                            failed.push("User talk:" + user);
                            error.push(eval("(" + req.responseText + ")").error.info);
                        }
		    }
                    document.getElementById("wpMassBlockSubmit").value = "(" + blocked + "/" + talkpageedited + "/" + userpageedited + ")";
                } else { //If not blocked, add the title to the "failed" array and a description of the error to the "error" array.
                    failed.push("Special:Block/" + user);
                    error.push(eval("(" + req.responseText + ")").error.info);
                }
            }
        }
        if(!users[i+1]) {
            document.getElementById("wpMassBlockSubmit").value = "(" + blocked + "/" + talkpageedited + "/" + userpageedited + ")";
            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("wpMassBlockFailedContainer").innerHTML += '<br /><b>Failed actions:</b><ul>' + linkedList + '</ul>';
            }
            
        }
    }
}
 
function massblockform() {
    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="wpMassBlock" name="wpMassBlock">'
        + '<b>도구 사용 미숙으로 인해 발생하는 문제에 대한 책임은 <i>전적으로 귀하</i>에게 있습니다</b>'
        + '<div id="wpMassBlockFailedContainer"></div>'
        + '<br /><br />'
            + '차단할 사용자 (한 줄에 한 사용자):<br />'
                + '<textarea tabindex="1" accesskey="," name="wpMassBlockUsers" id="wpMassBlockUsers" rows="10" cols="80"></textarea>'
            + '작성할 사용자 토론 내용(메시지를 보내고 싶지 않다면 비워두시오):<br />'
                + '<textarea tabindex="2" accesskey="," name="wpMassBlockMessage" id="wpMassBlockMessage" rows="10" cols="80"></textarea>'
            + '사용자 문서 내용 치환(사용자 문서를 편집하고 싶지 않다면 비워두시오.):<br />'
                + '<textarea tabindex="3" accesskey="," name="wpMassBlockTag" id="wpMassBlockTag" rows="10" cols="80"></textarea>'
            + '<br /><br /><table style="background-color:transparent">'
                + '<tr><td>일반적인 이유:</td>'
                    + '<td><select id="wpMassBlockReasons">'
                        + '<optgroup label="다른 이유">'
                            + '<option value="other">다른 이유</option>'
                        + '</optgroup>'
                        + '<optgroup label="일반적인 차단 이유">'
                            + '<option value="[[백:문서 훼손|문서 훼손]] 반복">[[백:문서 훼손|문서 훼손]] 반복</option>'
                            + '<option value="스팸 삽입">스팸 삽입</option>'
                            + '<option value="지속적인 장난">지속적인 장난</option>'
                            + '<option value="[[백:인신 공격 금지|협박/욕설/인신 공격]]/[[백:법적 위협 금지|법적 위협]]">[[백:인신 공격 금지|협박/욕설/인신 공격]]/[[백:법적 위협 금지|법적 위협]]</option>'
                            + '<option value="[[백:토론에서 지켜야 할 점|협업 정신에 어긋난 토론 태도]]">[[백:토론에서 지켜야 할 점|협업 정신에 어긋난 토론 태도]]</option>'
                            + '<option value="[[백:다중 계정|다중 계정]]의 악용">[[백:다중 계정|다중 계정]]의 악용</option>'
                            + '<option value="[[백:차단 정책|차단]] 회피">[[백:차단 정책|차단]] 회피</option>'
                            + '<option value="[[백:계정 이름#적절하지 않은 계정 이름|부적절한 계정 이름]]">[[백:계정 이름#적절하지 않은 계정 이름|부적절한 계정 이름]]</option>'
                            + '<option value="[[백:공개 프록시|공개 프록시]] (Open Proxy)">[[백:공개 프록시|공개 프록시]] (Open Proxy)</option>'
                            + '<option value="사칭 계정 사용">사칭 계정 사용</option>'
                        + '</optgroup>'
                    + '</select></td></tr>'
            + '<tr><td>다른/추가적인 이유:</td>'
                + '<td><input type="text" id="wpMassBlockReason" name="wpMassBlockReason" maxlength="255" /></td></tr>'
            + '<tr><td>차단 기한(무기한 차단일 경우 비워두시오):</td>'
                + '<td><input type="text" id="wpMassBlockExpiry" name="wpMassBlockExpiry" maxlength="255" /></td></tr>'
            + '<tr><td>사용자 토론 문서 편집 시 편집 요약:</td>'
                + '<td><input type="text" id="wpMassBlockSummaryTalk" name="wpMassBlockSummaryTalk" maxlength="255" /></td></tr>'
            + '<tr><td>사용자 문서 편집 시 편집 요약:</td>'
                + '<td><input type="text" id="wpMassBlockSummaryUser" name="wpMassBlockSummaryUser" maxlength="255" /></td></tr>'
                + '<tr><td>IP만 차단(IP 차단에서만 사용):</td><td><input type="checkbox" id="wpMassBlockAnononly" name="wpMassBlockAnononly" /></td></tr>'
                + '<tr><td>자동 차단 활성화(계정 차단에서만 사용):</td><td><input type="checkbox" id="wpMassBlockAutoblock" name="wpMassBlockAutoblock" checked="checked" /></td></tr>'
                + '<tr><td>계정 만들기 금지:</td><td><input type="checkbox" id="wpMassBlockNocreate" name="wpMassBlockNocreate" checked="checked" /></td></tr>'
                + '<tr><td>이메일 보내기 금지:</td><td><input type="checkbox" id="wpMassBlockEmail" name="wpMassBlockEmail" /></td></tr>'
                + '<tr><td>자신의 사용자 토론 문서 편집 금지:</td><td><input type="checkbox" id="wpMassBlockTalkpage" name="wpMassBlockTalkpage" /></td></tr>'
                + '<tr><td>기존의 차단 재설정:</td><td><input type="checkbox" id="wpMassBlockReblock" name="wpMassBlockReblock" checked="checked" /></td></tr>'
                + '<tr><td><input type="button" id="wpMassBlockSubmit" name="wpMassBlockSubmit" value="차단" onclick="doMassBlock()" /></td></tr>'
        + '</form>';
    document.getElementById("wpMassBlockReasons").onchange = function() {
        var maxlength = (document.getElementById("wpMassBlockReasons").value == "other" ? 255 : 253-document.getElementById("wpMassBlockReasons").value.length); //It's 25e because of the two characters (": ") in addition to the selected summary.
        document.getElementById("wpMassBlockReason").setAttribute("maxlength", maxlength);
    }
}
 
if(mw.config.get("wgNamespaceNumber") == -1 && mw.config.get("wgTitle").toLowerCase() == "massblock" && /sysop/.test(mw.config.get("wgUserGroups"))) $(massblockform);