User:Infinite0694/Mass RevisionDelete tool/ja.js

/** * Copy from w:User:Writ Keeper/Scripts/massRevdel.js * https://en.wikipedia.org/wiki/User:Writ_Keeper/Scripts/massRevdel.js * w:Special:PermaLink/691117524 * @license * @author w:en:User:Writ Keeper */

$(document).ready(function {	var api = new mw.Api;	if(mw.config.get("wgCanonicalSpecialPageName") == "Contributions")	{		$("ul.mw-contributions-list:first").before(" 版指定削除 選択した版の不可視化: \  本文の不可視化 \  利用者名の不可視化 \  編集要約の不可視化 \  本文の復元 \  利用者名の復元 \  編集要約の復元 \ その他の理由  著作権侵害のおそれ 著作権侵害のおそれ プライバシー侵害のおそれ 名誉毀損のおそれ <option value='不適切な利用者名'>不適切な利用者名 <option value='ISECHIKA'>ISECHIKA  <optgroup label='Common delete reasons'><option value='Copyright violation'>Copyright violation <option value='Inappropriate comment or personal information'>Inappropriate comment or personal information <option value='Inappropriate username'>Inappropriate username <option value='Potentially libelous information'>Potentially libelous information <option value='Grossly insulting, degrading, or offensive material'>Grossly insulting, degrading, or offensive material   <input name='wpReason' size='60' id='wpReason' maxlength='100'>\ <input type='button' class='revdelSubmit' id='revdelSubmit' value='選択した版を版指定削除'> <input type='button' class='revdelSubmit' id='oversightSubmit' value='選択した版をオーバーサイト'> ");		$("ul.mw-contributions-list .mw-revdelundel-link").each(function(ind,el){			var revId = /ids=(\d+)/.exec($(this).children("a").attr("href"))[1];			var pageTitle = /target=([^&]+)/.exec($(this).children("a").attr("href"))[1];			el.innerHTML = "<input type='checkbox' name='"+decodeURIComponent(pageTitle)+"' class='revdelIds' value='"+revId+"'>";		});		$("ul.mw-contributions-list").after(" ");		//load canned summaries		$.get("/w/index.php?title=MediaWiki:Revdelete-reason-dropdown&action=raw",function(data)		{			reasons = data.replace(/\*\* ([^\*]+)/g, '<option value="$1">$1 ');			reasons = reasons.replace(/\* ([^<]+)([^\*]+)/g, '<optgroup label="$1">$2 ');			$('#wpRevDeleteReasonList').append(reasons);		});		//attach handlers $("#revdelSelectAll").click(			function			{				$('input.revdelIds').each(function {					$(this).prop("checked", true); })			}		);		$("#revdelSelectNone").click(			function			{				$('input.revdelIds').each(function {					$(this).prop("checked", false); })			}		);		$("#revdelSubmit").click(			function			{				//figure out which revisions and pages we're working on.				var revCount = 0;				var numTitles = 0;				var pageTitles = {};				$("input.revdelIds:checked").each(function(ind) {					revCount = ind + 1; if(ind > 49) {						alert("1度に50版以上操作することはできません！取り消しています……"); return false; }					if(typeof pageTitles[$(this).attr("name")] == "undefined") {						pageTitles[$(this).attr("name")] = $(this).val; numTitles++; }					else {						pageTitles[$(this).attr("name")] = pageTitles[$(this).attr("name")] + "|" + $(this).val; }				});				if(numTitles == 0)				{					alert("不可視化する版が何も選択されていません！");					return false;				}				var confirmString = revCount + " 版の設定を操作しようとしています. \n " + " \n\n以下の閲覧レベルが変更されます:\n";				//figure out what we're doing to each revision. This is pretty clunky, but whatever.				var deleteString = "";				var revealString = "";				var typeString = "revdel";				if($("#revdelContent").prop("checked") == $("#undelContent").prop("checked"))				{					confirmString = confirmString + "-版の本文は変更されません. \n";				}				else if($("#revdelContent").prop("checked"))				{					deleteString = "content";					confirmString = confirmString + "-版の本文が不可視化されます. \n";				}				else				{					revealString = "content";					confirmString = confirmString + "-版の本文が可視化されます. \n";				}				if($("#revdelComment").prop("checked") == $("#undelComment").prop("checked"))				{					confirmString = confirmString + "-編集の要約は変更されません. \n"; }				else if($("#revdelComment").prop("checked")) {					if(deleteString != "") {						deleteString = deleteString + "|"; }					deleteString = deleteString + "comment"; confirmString = confirmString + "-編集の要約が不可視化されます. \n"; }				else {					if(revealString != "") {						revealString = revealString + "|"; }					revealString = revealString + "comment"; confirmString = confirmString + "-編集の要約が可視化されます. \n"; }				if($("#revdelName").prop("checked") == $("#undelName").prop("checked")) {					confirmString = confirmString + "-投稿者の利用者名/IPアドレスは変更されません. \n"; }				else if($("#revdelName").prop("checked")) {					if(deleteString != "") {						deleteString = deleteString + "|"; }					deleteString = deleteString + "user"; confirmString = confirmString + "-投稿者の利用者名/IPアドレスが不可視化されます. \n"; }				else {					if(revealString != "") {						revealString = revealString + "|"; }					revealString = revealString + "user"; confirmString = confirmString + "-投稿者の利用者名/IPアドレスが可視化されます. \n"; }				if(deleteString == "" && revealString == "") {					alert("閲覧レベル制限の設定がされていません！"); return false; }				var summary = ""; //construct the revdel summary if($("#wpRevDeleteReasonList").val == "other") {					if($("#wpReason").val == "") {						alert("版指定削除する理由が入力されていません！"); return false; }					summary = $("#wpReason").val; }				else {					summary = $("#wpRevDeleteReasonList").val; if($("#wpReason").val != "") {						summary = summary + ": " + $("#wpReason").val; }				}				confirmString = confirmString + "\n閲覧レベルを変更する理由: "+ summary +"\n\n本当に実行しますか？"; if(confirm(confirmString)) {					var numCompleted = 0; for (title in pageTitles) {						var ajaxData; ajaxData = {action:"revisiondelete",type:"revision",ids:pageTitles[title],reason:summary}; if(deleteString != "") {							ajaxData.hide=deleteString; }						if(revealString != "") {							ajaxData.show=revealString; }						api.postWithToken('csrf', ajaxData).done(function						{							numCompleted++;							if(numCompleted == numTitles)							{								alert(revCount + " 版の閲覧レベルが変更されました！");								return false;							}						}); }				}				return false; }		)		$("#oversightSubmit").click( function {				//figure out which revisions and pages we're working on. var revCount = 0; var numTitles = 0; var pageTitles = {}; $("input.revdelIds:checked").each(function(ind)				{					revCount = ind + 1;					if(ind > 49)					{						alert("You can't do more than 50 revdels at once! Canceling...");						return false;					}					if(typeof pageTitles[$(this).attr("name")] == "undefined")					{						pageTitles[$(this).attr("name")] = $(this).val;						numTitles++;					}					else					{						pageTitles[$(this).attr("name")] = pageTitles[$(this).attr("name")] + "|" + $(this).val;					}				}); if(numTitles == 0) {					alert("You didn't select any revisions to delete!"); return false; }				var confirmString = "You are attempting to modify " + revCount + " revisions.\n\nThe following revision attributes will be changed:\n"; //figure out what we're doing to each revision. This is pretty clunky, but whatever. var deleteString = ""; var oversighting = -1; if($("#revdelContent").prop("checked") == $("#undelContent").prop("checked")) {					confirmString = confirmString + "-Content visibility won't change.\n"; }				else if($("#revdelContent").prop("checked")) {					deleteString = "content"; confirmString = confirmString + "-Content will be oversighted.\n"; oversighting = 1; }				else {					if(oversighting == 1) {						alert("we can't oversight and un-oversight edits at the same time!"); return false; }					deleteString = "content"; confirmString = confirmString + "-Content will be returned to normal (admin-only) revision deletion.\n"; oversighting = 0; }				if($("#revdelComment").prop("checked") == $("#undelComment").prop("checked")) {					confirmString = confirmString + "-Edit summary visibility won't change.\n"; }				else if($("#revdelComment").prop("checked")) {					if(oversighting == 0) {						alert("we can't oversight and un-oversight edits at the same time!"); return false; }					if(deleteString != "") {						deleteString = deleteString + "|"; }					deleteString = deleteString + "comment"; confirmString = confirmString + "-Edit summary will be oversighted.\n"; oversighting = 1; }				else {					if(oversighting == 1) {						alert("we can't oversight and un-oversight edits at the same time!"); return false; }					if(deleteString != "") {						deleteString = deleteString + "|"; }					deleteString = deleteString + "comment"; confirmString = confirmString + "-Edit summary will be returned to normal (admin-only) revision deletion.\n"; oversighting = 0; }				if($("#revdelName").prop("checked") == $("#undelName").prop("checked")) {					confirmString = confirmString + "-User name visibility won't change.\n"; }				else if($("#revdelName").prop("checked")) {					if(oversighting == 0) {						alert("we can't oversight and un-oversight edits at the same time!"); return false; }					if(deleteString != "") {						deleteString = deleteString + "|"; }					deleteString = deleteString + "user"; confirmString = confirmString + "-User name will be oversighted.\n"; oversighting = 1; }				else {					if(oversighting == 1) {						alert("we can't oversight and un-oversight edits at the same time!"); return false; }					if(deleteString != "") {						deleteString = deleteString + "|"; }					deleteString = deleteString + "user"; confirmString = confirmString + "-User name will be returned to normal (admin-only) revision deletion.\n"; oversighting = 0; }				if(deleteString == "") {					alert("You didn't select any properties of the revisions to change!"); return false; }				var summary = ""; //construct the revdel summary if($("#wpRevDeleteReasonList").val == "other") {					if($("#wpReason").val == "") {						alert("You didn't select or write in an edit summary for the logs!"); return false; }					summary = $("#wpReason").val; }				else {					summary = $("#wpRevDeleteReasonList").val; if($("#wpReason").val != "") {						summary = summary + ": " + $("#wpReason").val; }				}				confirmString = confirmString + "\nYour oversight summary is: "+ summary +"\n\nAre you sure you want to do this?"; if(confirm(confirmString)) {					var numCompleted = 0; for (title in pageTitles) {						var ajaxData; ajaxData = {action:"revisiondelete",type:"revision",ids:pageTitles[title],reason:summary,hide:deleteString}; if(oversighting == 1) {							ajaxData.suppress = "yes"; }						else if(oversighting == 0) {							ajaxData.suppress = "no"; }						else {							alert("Something went wrong, so we're going to abort without doing anything."); }					　　api.postWithToken('csrf', ajaxData).done(function						{							numCompleted++;							if(numCompleted == numTitles)							{								alert("modified " + revCount + " revision(s) successfully!");								return false;							}						}); }				}				return false; }		)	} });