User:Quibik/EightRequestsHelper.js

// To use this script, place "importScript( 'User:Quibik/EightRequestsHelper.js' ); // [[User:Quibik/EightRequestsHelper.js]]" // to the botto

// To use this script, place "importScript( 'User:Quibik/EightRequestsHelper.js' ); // [[User:Quibik/EightRequestsHelper.js]]"
// to the bottom of the page opened by http://en.wikipedia.org/wiki/Special:MyPage/vector.js
// This will add a link "Update Eight Requests" to the menu next to the search box, if you are on the Eight Requests page.

function eightRequestsHelper() {

if (/erhelper=init/i.test(location.href)) {
	//window.open("/w/index.php?title=Wikipedia:Graphics_Lab/Photography_workshop/Eight_Requests/Users_log&action=edit&erhelper=process", "ER User Log");
	window.open("/w/index.php?title=Wikipedia:Graphics_Lab/Photography_workshop/Eight_Requests/Archive/" + (new Date()).getFullYear() + "&action=edit&erhelper=process", "ER Archive");
	window.open("http://commons.wikimedia.org/wiki/User:Quibik/Files_by_viewcounts", "Files by viewcounts");
}

if (/\/Eight_Requests/i.test(location.href) && mw.config.get( 'wgAction' ) === 'edit') {
	if (!/\/Eight_Requests\//i.test(location.href)) {
		// Replace the completed requests with empty fields
		var m = /<!--COPY.+\s*(<gallery[\s\S]+<\/gallery>)/i.exec(jQuery("#wpTextbox1").val());
		if (!m) {
			return;
		}
		var cleanGallery = m[1];
		jQuery("#wpTextbox1").val(jQuery("#wpTextbox1").val()
			.replace(/<center>\s*(<gallery[\s\S]+<\/gallery>)\s*<\/center>/i, "<center>\n" + cleanGallery + "\n</center>"));
		jQuery("#wpSummary").val("Added a new set of images. (using a [[User:Quibik/EightRequestsHelper.js|script]])");
	}
	else {
		jQuery.get("/w/index.php?title=Wikipedia:Graphics_Lab/Photography_workshop/Eight_Requests&action=raw&nocache=" + new Date().getTime(), "", function(data) {
			var m = /<center>\s*(<gallery[\s\S]+<\/gallery>)\s*<\/center>/i.exec(data);
			if (!m) {
				return;
			}
			var gal = m[1];
			
			var re = /^\s*(?:File|Image):.+taken by\s*=\s*([^|]+)\s*\|.+$/mig;
			var requests = "";
			var counts = new Object();
			while (true) {
				m = re.exec(gal);
				if (!m)
					break;
				requests += m[0] + "\n";
				m[1] = jQuery.trim(m[1]);
				if (m[1].length > 0)
					counts[m[1]] = (counts.hasOwnProperty(m[1]) ? counts[m[1]] : 0) + 1;
			}
			
			if (/\/Eight_Requests\/Archive/i.test(location.href)) {
				// Archive the most recent set of requests
				var monthnames = [ "January", "February", "March", "April", "May", "June",
					"July", "August", "September", "October", "November", "December" ];
				var d = new Date();
				jQuery("#wpTextbox1").val(jQuery("#wpTextbox1").val() + 
					"\n;" + d.getDate() + " " + monthnames[d.getMonth()] + "\n" +
					"<gallery widths=\"160px\" perrow=\"4\">\n" +
					requests +
					"</gallery>"
				);
				jQuery("#wpSummary").val("Archived the most recent set. (using a [[User:Quibik/EightRequestsHelper.js|script]])");
				jQuery("#wpDiff").click();
			}
			else if (/\/Eight_Requests\/Users_log/i.test(location.href)) {
				// Update the user log
				var re = /^\|\s*{{User\|\s*([^}]+)\s*}}\s*\|\|\s*(\d+)\s*$/mig;
				var m;
				while (true) {
					m = re.exec(jQuery("#wpTextbox1").val());
					if (!m)
						break;
					m[1] = jQuery.trim(m[1]);
					counts[m[1]] = (counts.hasOwnProperty(m[1]) ? counts[m[1]] : 0) + parseInt(m[2]);
				}
				var names = [];
				for(var name in counts){
					names.push(name);
				}
				names.sort();
				
				userList = ""
				for (x in names) {
					name = names[x];
					userList += "|-\n| {{User|" + name + "}} || " + counts[name] + "\n";
				}
				jQuery("#wpTextbox1").val(jQuery("#wpTextbox1").val()
					.replace(/\|-[\s\S]+\|}\n\n==/i, userList + "|}\n\n==")
					.replace(/as of \d.+/im, "as of ~~~~~. Updated by ~~~"));
				jQuery("#wpSummary").val("Updated. (using a [[User:Quibik/EightRequestsHelper.js|script]])");
				jQuery("#wpDiff").click();
			}
		});
	}
}
}

$( document ).ready( function () {
	if (/\/Eight_Requests/i.test(location.href))
		mw.util.addPortletLink ( "p-cactions", "/w/index.php?title=Wikipedia:Graphics_Lab/Photography_workshop/Eight_Requests&action=edit&erhelper=init", "Update Eight Requests", "ca-eightRequestsHelper");
	if (/erhelper=/i.test(location.href))
		eightRequestsHelper();
} );

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.