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 */ // 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,

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 protectionstring = "protections=", expirystring = "expiry="; if(wpEditProtectType != "nochange"){ protectionstring += "edit=" + wpEditProtectType; expirystring += encodeURIComponent(wpMassProtectExpiry == ""? wpMassProtectExpiry1 : wpMassProtectExpiry) + "|"; }   if(wpCreateProtectType != "nochange"){ protectionstring += "create=" + wpCreateProtectType; expirystring += encodeURIComponent(wpMassProtectExpiry == ""? wpMassProtectExpiry1 : wpMassProtectExpiry) + "|"; }   if(wpMoveProtectType != "nochange"){ protectionstring += "move=" + wpMoveProtectType; 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", 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", 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) + "&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); }                   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", 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 massprotectform { var bodyContent = (skin == "cologneblue" ? "article" : "bodyContent"); 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 ' + '' +' 保護レベルを変更できます. 変更する場合は、保護の方針、半保護の方針に基づいているか確認して下さい. 有効期限のデフォルトは無期限です. 適切な期間・期限を指定してください. 「その他の期間」の記入例（ <a rel="nofollow" class="external text" href="http://www.gnu.org/software/tar/manual/html_node/Date-input-formats.html">GNU標準フォーマット</a> ）："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>保護レベルを変更した場合、ページ上で保護テンプレート（<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>' + ' ※警告 ：このツールを濫用した場合、すべて利用者の責任になります. '       + ' '        + '  保護の確認 ' +' 一括保護 ' + '保護対象の記事群(記事名を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">このページに読み込まれているページを保護する (カスケード保護)  '

+ ' '       + ' ';        + '<form id="wpMassEdit" name="wpMassEdit">' + 'If you abuse this tool, it\'s your fault, not mine.' + ' '       + '

'           + 'Pages to edit (one on each line, please): '               + '<textarea tabindex="1" name="wpMassEditPages" id="wpMassEditPages" rows="10" cols="80"> '           + 'Text 1 (see below): '               + '<textarea tabindex="2" name="wpMassEditText1" id="wpMassEditText1" rows="10" cols="80"> '           + 'Text 2 (see below): '               + '<textarea tabindex="3" name="wpMassEditText2" id="wpMassEditText2" rows="10" cols="80"> ' + '

'               + '  Edit type: ' + ' <select id="wpMassEditType">' + ' Prepend text 1 ' + ' Append text 1 ' + ' Prepend text 1 and append text 2 ' + ' Replace first instance of text 1 with text 2 ' + '<option value="replacetextg">Replace all instances of text 1 with text 2 ' + ' Replace page with text 1 ' + ' '            + '  Edit summary: ' + ' <input type="text" id="wpMassEditSummary" name="wpMassEditSummary" maxlength="255" /> ' + ' Mark edit as minor: ' + ' <input type="checkbox" id="wpMassEditMinor" name="wpMassEditMinor"/> ' + ' Treat replacement string as regex expression: ' + ' <input type="checkbox" id="wpRegexMode" name="wpRegexMode"/> (Please escape the backslashes)  ' + ' <input type="button" id="wpMassEditSubmit" name="wpMassEditSubmit" value="Edit" onclick="doMassEdit" /> ' + ' ';   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); }

} // Tim's Mass Edit Tool (Copy of User:Timotheus Canens/massedit.js) // Adapted from User:Animum/massdelete.js

function doMassEdit { document.getElementById("wpMassEditSubmit").disabled = true; var articles = document.getElementById("wpMassEditPages").value.split("\n"); if(articles.length == 0) return; var newtext = document.getElementById("wpMassEditText1").value; var text2 = document.getElementById("wpMassEditText2").value; var wpMassEditType = document.getElementById("wpMassEditType").value, wpMassEditSummary = document.getElementById("wpMassEditSummary").value, edited = 0, failed = new Array, error = new Array; var wpMassEditMinor = document.getElementById("wpMassEditMinor").checked; var wpRegexMode = document.getElementById("wpRegexMode").checked; for(i=0;i<articles.length;i++) { var article = articles[i]; if(article.length > 0) { var req = new XMLHttpRequest; req.open("GET", wgScriptPath + "/api.php?format=json&action=query&prop=info&intoken=edit&titles=" + encodeURIComponent(article), false); req.send(null); var response = eval("(" + req.responseText + ")").query.pages; for(var index in response) { var info = response[index]; var edittoken = info.edittoken; var postdata = "format=json" + "&action=edit&watchlist=nochange" + "&title=" + encodeURIComponent(article) + "&summary=" + encodeURIComponent(wpMassEditSummary) + "&token=" + encodeURIComponent(edittoken); if(wpMassEditMinor) postdata += "&minor=1"; else postdata += "&notminor=1"; if(wpMassEditType == "prepend"){ postdata += "&prependtext=" + encodeURIComponent(newtext + "\n"); }				else if(wpMassEditType == "append"){ postdata += "&appendtext=" + encodeURIComponent("\n" + newtext); }				else if(wpMassEditType == "replacepage"){ postdata += "&text=" + encodeURIComponent(newtext); }				else if(wpMassEditType == "replacetext" || wpMassEditType == "replacetextg" || wpMassEditType == "bothpend"){ 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); }					else pagetext = newtext + pagetext + text2; postdata += "&text=" + encodeURIComponent(pagetext); }               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(eval("(" + req.responseText + ")").edit ) { //If edited, update the count and the button. edited++; document.getElementById("wpMassEditSubmit").value = "(" + edited + ")"; } 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("wpMassEditSubmit").value = "Done (" + edited + ")"; if(failed.length > 0) { var linkedList = ""; for(x=0; x<failed.length; x++) { linkedList += "<a href=\"" + wgScript + "?title=" + encodeURIComponent(failed[x]) + "\">" + failed[x] + "</a>: " + error[x] + "</li>"; //Links the titles in the "failed" array }               document.getElementById("wpMassEditFailedContainer").innerHTML += ' Failed edits:' + linkedList + '</ul>'; }       }    } }

function gettext(title){ var req = new XMLHttpRequest; req.open("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; }

if(wgNamespaceNumber == -1 && (wgPageName == "Special:MassprotectA" || wgPageName == "Special:MassProtectA") && /autoconfirmed/.test(wgUserGroups)) addOnloadHook(massprotectform); if(wgNamespaceNumber == -1 && (wgPageName == "特別:MassprotectA" || wgPageName == "Special:MassProtectA") && /autoconfirmed/.test(wgUserGroups)) addOnloadHook(massprotectform);