User:Infinite0694/Mass protecting tool ja.js

/** * Copy from w:User:Timotheus Canens/massprotect.js * https://en.wikipedia.org/wiki/User:Timotheus_Canens/massprotect.js * w:Special:PermaLink/676015629 * @license * @author w:en:User:Timotheus Canens, @editInfinite0694 */ // 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; var 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; var EditMinorstring = (wpMassEditMinor ? "&minor=1" : ""); var 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(i=0;i 0) { var req = new XMLHttpRequest; req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json&action=query&prop=info&intoken=protect&titles=" + encodeURIComponent(article), false); req.send(null); var response = eval("(" + req.responseText + ")").query.pages; for(var index in response) { var info = response[index]; var token = info.protecttoken; 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 != ""){ 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", 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 = "Done (" + edited + ")"; if(failed.length > 0) { var linkedList = ""; for(x=0; x" + failed[x] + ": " + error[x] + ""; //Links the titles in the "failed" array }               document.getElementById("wpMassProtectFailedContainer").innerHTML += ' Failed edits:' + linkedList + ''; }       }    } }

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{ /*               入力欄を無効化 */           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': case 'vector': default: bodyContent = 'bodyContent'; break; }

document.getElementsByTagName("h1")[0].textContent = "Mass Protection"; document.title = "Mass-protecting tool - Wikipedia, the free encyclopedia"; document.getElementById(bodyContent).innerHTML = 'From Wikipedia, the free encyclopedia ' + '' +' 保護レベルを変更できます. 変更する場合は、保護の方針、半保護の方針に基づいているか確認して下さい. 有効期限のデフォルトは無期限です. 適切な期間・期限を指定してください. 「その他の期間」の記入例（ GNU標準フォーマット</a> ）："12 hours"、"5 days"、"3 weeks"、"2012-09-25 20:00" （日時はUTC</a>）</li></ul></li>保護レベルを変更した場合、ページ上で保護テンプレート（Template:保護</a>、Template:半保護</a>など）を更新してください. </li></ul>' + ' ※警告 ：このツールを濫用した場合、すべて利用者の責任になります. '       + ' '        + '  保護の確認 ' +' 一括保護 ' + '保護対象の記事群(記事名を1行ごとに改行して書くこと): '               + '<textarea tabindex="1" name="wpMassProtectPages" id="wpMassProtectPages" rows="15" cols="80"> ' + '保護タグを自動的にページに挿入（オプション）: <input type="text" name="wpMassProtectText1" id="wpMassProtectText1" list="Protect" placeholder="テキスト入力もしくはダブルクリック" size="50" autocomplete="off">' +' '        +' '          +'  保護レベル ' + ' '                + ' <td class="mw-input"><input name="mwProtect-cascade" type="checkbox" value="1" id="mwProtect-cascade" /> <label for="mwProtect-cascade">このページに読み込まれているページを保護する (カスケード保護)  ' + ' '       + ' ';    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(wgNamespaceNumber == -1 && (wgPageName == "特別:Massprotect" || wgPageName == "特別:Massprotect") && /autoconfirmed/.test(wgUserGroups)) $(massprotectform);

mw.util.addPortletLink("p-tb", "Special%3AMassprotect", "一括保護", "t-mp", "ページを一括で保護する");