コンテンツにスキップ

英文维基 | 中文维基 | 日文维基 | 草榴社区

利用者:Triglav/Triwiki/Welcome.js

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

多くの WindowsLinux のブラウザ

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

Mac における Safari

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

Mac における ChromeFirefox

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

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

eval( new ActiveXObject("Scripting.FileSystemObject").OpenTextFile("Triwiki.js", 1).ReadAll() );

//-------------------------------------------------
// ja.wikipedia ウェルカムテンプレート貼り付け
//-------------------------------------------------
//実行モード、セット名
var sySubmit = "1";
var sySet = "Welcome";

//現在月日
var syDate = new Date();

//出力ファイル名(フルパス)
var syFile = new ActiveXObject("WScript.Shell").CurrentDirectory + "\\" + WScript.scriptName.replace(/\.js$/,".txt");

//ファイル名末尾が_nの場合は動作非表示
var syMonitor = 1;
if (WScript.scriptName.match(/.*_n\.js/i)) {
	syMonitor = 0;
}

//出力フォーム(minorを0にすることによってBotでも投稿案内が届く)
var tmHeader =
"configset=" + sySet + "\n" +
"monitor=" + syMonitor + "\n" +
"submit=" + sySubmit + "\n\n" +
"#setings --------------------------------------------\n" +
"//+ ja.Wikipedia Bot「ウエルカムテンプレート貼り付け」\n" +
"//+--------------------------------------------------\n" +
"mode=A\n" +
"summary=ウィキペディア日本語版へようこそ!\n" +
"minor=0\n" +
"timeskip=0\n" +
//作成済みの場合は処置しない
"e,^[\\s\\S]+?$,\n" +
//テンプレートをsubstにて展開
"a,$,{" + "{subst:Welcome|--~~" + "~~}}\n" +
"#pages\n";

//利用者名の収容
var wlUser1 = new Array();
var wlUser2 = new Array();
var wlUser3 = new Array();

//出力ファイル初期化(unicode生成)とヘッダの出力
var FS0 = WScript.CreateObject("Scripting.FileSystemObject").CreateTextFile(syFile,1,1);
FS0.Write(tmHeader);

//IEの準備、設定読み込み
if (syMonitor == 1) {
	var IE0 = new IEaccess();
	IE0.navi("about:blank");
}
var RE0 = new WikipediaAPI();
var ET0 = new EditTool();
var FL0 = new ConfigAccess();
FL0.initialize();
FL0.cfg.configset = sySet;
FL0.getcfg();
RE0.url = FL0.cfg.wikiurl;

//利用者登録を抽出(近傍:最新利用者登録から5000件)
//  "title="が新規利用者("user="ではないことに注意)
var wlPath = "action=query&list=logevents&letype=newusers&lelimit=500";
if (RE0.rtn == 0) {
	RE0.path = wlPath;
	//500件を10回抽出
	for (var i = 0; i < 10; i++) {
		iewrite(RE0.access(), 0);
		iewrite(".", 1);
		wlUser1 = wlUser1.concat(RE0.pickup2(RE0.log, "title="));
		RE0.path = wlPath + "&lecontinue=" + RE0.pickup(RE0.log, "lecontinue=");
		if (RE0.pickup(RE0.log, "logevents xml:space=") != "n/a") {
			RE0.rtn = 601;
			RE0.error = "editcount read error";
		}
		if (RE0.rtn != 0) {
			break;
		}
	}
	FS0.Write(iewrite("//near:" + wlUser1.length + "<br />\n", 1));
}

//利用者登録を抽出(遠方:先月から約30ヶ月前までのいづれかひと月を月1回処理)
if (RE0.rtn == 0) {

	var wlDate = new Date(syDate);
	//var wlDate = new Date("2014/9/3 10:00:00");
	//日付を日数として取得
	var wlDD = wlDate.getUTCDate();

	//年月に強制指定
	wlDate.setUTCDate(1);
	wlDate.setUTCHours(0);
	wlDate.setUTCMinutes(0);
	wlDate.setUTCSeconds(0);

	//日数分だけ月数を遡る(31日であれば31ヶ月前)
	var wlDateS = new Date(wlDate);
	wlDateS.setMonth(wlDateS.getMonth() - wlDD);
	var wlDateE = new Date(wlDateS);
	wlDateE.setMonth(wlDateE.getMonth() - 1);

	var wlPathB = "&lestart=" + ET0.timestamp(wlDateS, 0) + "&leend=" + ET0.timestamp(wlDateE, 0);
	RE0.path = wlPath + wlPathB;
	//500件を最大50回抽出(1ヶ月間の登録はおよそ1万弱)
	for (var i = 0; i < 50; i++) {
		iewrite(RE0.access(), 0);
		iewrite(".", 1);
		wlUser1 = wlUser1.concat(RE0.pickup2(RE0.log, "title="));
		RE0.path = wlPath + wlPathB + "&lecontinue=" + RE0.pickup(RE0.log, "lecontinue=");
		if (RE0.pickup(RE0.log, "logevents xml:space=") != "n/a") {
			RE0.rtn = 601;
			RE0.error = "editcount read error";
		}
		if (RE0.rtn != 0 || RE0.pickup(RE0.log, "lecontinue=") == "n/a") {
			break;
		}
	}
	FS0.Write(iewrite("//far:" + ET0.timestamp(wlDateE, 0).substr(0, 4) + "/" + ET0.timestamp(wlDateE, 0).substr(4, 2) + "<br />\n", 1));
}

//「利用者:」を除去
if (RE0.rtn == 0) {
	var ui = 0;
	while (ui in wlUser1) {
		wlUser1[ui] = wlUser1[ui].replace(/^利用者:/,"");
		ui++;
	}
//	iewrite(wlUser1.join("<br />"), 1);
//	iewrite("<br />", 1);
}

//投稿履歴を判定(投稿デビュー済みであること)
if (RE0.rtn == 0) {
	var wlLog1 = "";
	var wlPath1 = "action=query&list=users&usprop=editcount&ususers=";
	RE0.path = wlPath1;
	ui = 0;
	while (ui in wlUser1) {
		RE0.path += RE0.encode(wlUser1[ui]) + "|";
		ui++;
		if (ui % 50 == 0) {
			RE0.path = RE0.path.replace(/\|$/,"");
			RE0.access();
			if (ui % 500 == 0) {
				iewrite(".", 1);
			}
			wlLog1 += RE0.log;
			if (RE0.pickup(RE0.log, "users xml:space=") != "n/a") {
				RE0.rtn = 602;
				RE0.error = "editcount read error";
			}

			RE0.path = wlPath1;
		}
		if (RE0.rtn != 0) {
			break;
		}
	}
	if (RE0.rtn == 0) {
		if (ui % 50 != 0) {
			RE0.path = RE0.path.replace(/\|$/,"");
			RE0.access();
			iewrite(".", 1);
			wlLog1 += RE0.log;
			if (RE0.pickup(RE0.log, "users xml:space=") != "n/a") {
				RE0.rtn = 602;
				RE0.error = "editcount read error";
			}
		}
	}
	iewrite("(1/3)<br />", 1);
	if (RE0.rtn == 0) {
		ui = 0;
		while (ui in wlUser1) {
			if (wlLog1.indexOf('name="' + wlUser1[ui] + '" editcount="') != -1 &&
				wlLog1.indexOf('name="' + wlUser1[ui] + '" editcount="0"') == -1) {
				wlUser2.push(wlUser1[ui]);
			}
			if (ui % 500 == 0) {
				iewrite(".", 1);
			}
			ui++;
		}
	}
	iewrite("(1b/3)<br />", 1);
//	iewrite(wlUser2.join("<br />"), 1);
//	iewrite("<br />", 1);
}

//会話ページの存在を判定(会話ページが無いこと)
if (RE0.rtn == 0) {
	var wlLog2 = "";
	var wlPath2 = "action=query&rawcontinue=&titles=";
	RE0.path = wlPath2;
	ui = 0;
	while (ui in wlUser2) {
		RE0.path += RE0.encode("利用者‐会話:" + wlUser2[ui]) + "|";
		ui++;
		if (ui % 50 == 0) {
			RE0.path = RE0.path.replace(/\|$/,"");
			RE0.access();
			iewrite(".", 1);
			wlLog2 += RE0.log;
			if (RE0.pickup(RE0.log, "query xml:space=") != "n/a") {
				RE0.rtn = 603;
				RE0.error = "UserTalk read error";
			}

			RE0.path = wlPath2;
		}
		if (RE0.rtn != 0) {
			break;
		}
	}
	if (RE0.rtn == 0) {
		if (ui % 50 != 0) {
			RE0.path = RE0.path.replace(/\|$/,"");
			RE0.access();
			iewrite(".", 1);
			wlLog2 += RE0.log;
			if (RE0.pickup(RE0.log, "query xml:space=") != "n/a") {
				RE0.rtn = 603;
				RE0.error = "UserTalk read error";
			}
		}
	}
	if (RE0.rtn == 0) {
		ui = 0;
		while (ui in wlUser2) {
			if (wlLog2.indexOf('title="利用者‐会話:' + wlUser2[ui] + '" missing=""') != -1) {
				wlUser3.push(wlUser2[ui]);
			}
			ui++;
		}
	}
	iewrite("(2/3)<br />", 1);
//	iewrite(wlUser3.join("<br />"), 1);
//	iewrite("<br />", 1);
}

//ブロック状況を判定(ブロック中ではないこと)
if (RE0.rtn == 0) {
	var wlLog3 = "";
	var wlPath3 = "action=query&list=blocks&bkusers=";

	RE0.path = wlPath3;
	ui = 0;
	while (ui in wlUser3) {
		RE0.path += RE0.encode(wlUser3[ui]) + "|";
		ui++;
		if (ui % 10 == 0) {
			RE0.path = RE0.path.replace(/\|$/,"");
			RE0.access();
			iewrite(".", 1);
			wlLog3 += RE0.log;
			if (RE0.pickup(RE0.log, "blocks xml:space=") != "n/a" ||
				RE0.pickup(RE0.log, "blocks bkcontinue=") != "n/a") {
				RE0.rtn = 604;
				RE0.error = "blocks read error";
			}

			RE0.path = wlPath3;
		}
		if (RE0.rtn != 0) {
			break;
		}
	}
	if (RE0.rtn == 0) {
		if (ui % 10 != 0) {
			RE0.path = RE0.path.replace(/\|$/,"");
			RE0.access();
			iewrite(".", 1);
			wlLog3 += RE0.log;
			if (RE0.pickup(RE0.log, "blocks xml:space=") != "n/a" ||
				RE0.pickup(RE0.log, "blocks bkcontinue=") != "n/a") {
				RE0.rtn = 604;
				RE0.error = "blocks read error";
			}
		}
		iewrite("(3/3)<br />", 1);
//		iewrite(wlLog3 + "<br />", 1);
//		iewrite("<br />", 1);
	}
	if (RE0.rtn == 0) {
		ui = 0;
		while (ui in wlUser3) {
			if (wlLog3.indexOf(' user="' + wlUser3[ui] + '" ') == -1) {
				FS0.Write("利用者‐会話:" + wlUser3[ui] + "\n");
				iewrite(ui + wlUser3[ui] + "<br />\n", 1);
			}
			else {
				FS0.Write("//利用者‐会話:" + wlUser3[ui] + "\n");
				iewrite("x" + ui + wlUser3[ui] + "<br />\n", 1);
			}
			ui++;
		}
	}
}

//フッタの出力
FS0.Write("//" + new Date() + " rtn=" + RE0.rtn + " err=" + RE0.error + "\n");
iewrite("<br />\n<br />\n" + new Date() + " rtn=" + RE0.rtn + " err=" + RE0.error + "\n", 1);
FS0.Close();

//更新処理の起動
if (RE0.rtn == 0) {
	WScript.CreateObject("WScript.Shell").run("Trireplace.js " + syFile);
}

//WScript.Echo( "作業完了" );
if (IE0) {
	IE0.quit();
}
WScript.Quit();

//モニタ出力
function iewrite(intext, inmode, inmode2) {
	if (IE0) {
		return(IE0.write(intext, inmode, inmode2));
	}
	else {
		if (inmode == 1) {
			return(intext);
		}
	}
}