User:Oshwah/Undelete-Log-Links.js: Difference between revisions – Wikipedia

From Wikipedia, the free encyclopedia

Content deleted Content added


 

Line 40: Line 40:

new_user_tool_links.push(checkuser_link, checklog_link, block_link);

new_user_tool_links.push(checkuser_link, checklog_link, block_link);

const new_links_str = new_user_tool_links.join(” | “)(user_tool_links.indexOf(“)”) == (user_tool_links.length() – 1))?(+ “”):(+ “)”);

const new_links_str = new_user_tool_links.join(” | “)(user_tool_links.indexOf(“)”) == (user_tool_links.length – 1))?(+ “”):(+ “)”);

$(this).find(“span.mw-usertoollinks”).html(new_links_str); //After all is done, set the HTML for the user tool links.

$(this).find(“span.mw-usertoollinks”).html(new_links_str); //After all is done, set the HTML for the user tool links.


Latest revision as of 05:44, 30 November 2025

mw.loader.using('mediawiki.util', function() {
	const special_pagename = mw.config.get("wgCanonicalSpecialPageName"); //Gets you the name of the current special page, e.g. 'AbuseLog'; if we're not on a special page, this returns null.
	
	if (special_pagename === "Undelete") {

		var new_user_tool_links = "", talk_link = "", contribs_link = "", block_link = "", publiclog_link = "", checkuser_link = "", checklog_link = "";
		var whois_link = "", geolocate_link = "", proxy_check_link = "", bullseye_check_link = "";
		var ip_pattern = /^(?:(?:(?:1?\d?\d|2[0-4]\d|25[0-5])\.){3}(?:1?\d?\d|2[0-4]\d|25[0-5])|(?:[\da-f]{0,4}:){1,7}[\da-f]{0,4})$/i; //Regex matching the pattern of an IPv4 or IPv6 address or range
		
		$("li:has(.mw-userlink):has(.mw-usertoollinks)").each(function() {

			const current_user = $(this).find(".mw-userlink").first().text(); //Place the current user (whether it be a username of an account or an IP address) into current_user
			const enc_current_user = encodeURIComponent(current_user);
			const user_tool_links = $(this).find("span.mw-usertoollinks").html(); //Pull the HTML code of the current user tool links (to be replaced) from the inner HTML.

			talk_link = user_tool_links.match("^(.*)>talk<\/a>"); //Grab all text from the start of the HTML string to the end of the talk HTML code.
			talk_link = ((talk_link == null)?('<a href="https://en.wikipedia.org/wiki/User_talk:'+current_user+'">talk</a>'):(talk_link[0])); //Check if the link to the user talk page was captured from user_tools_link. If the string is null, insert the HTML code ourselves. Otherwise, flatten the array.

			contribs_link = user_tool_links.match("<a href=\"/wiki/Special:Contributions(.*)>contribs<\/a>"); //Grab all text from the start of the contribs HTML code to the end of the contribs HTML code.
			contribs_link = ((contribs_link == null)?('<a href="https://en.wikipedia.org/wiki/Special:Contributions/'+current_user+'">contribs</a>'):(contribs_link[0])); //"contribs" is not in this list if the IP is a CIDR range. We must check for this and insert the HTML code ourselves if we want it to be there. Otherwise, flatten the array.

			block_link = user_tool_links.match("<span><a href=\"/wiki/Special:Block(.*)>block<\/a><\/span>"); //Grab all text from the start of the block HTML code to the end of the block HTML code.
			block_link = ((block_link == null)?('<a href="https://en.wikipedia.org/wiki/Special:Block/'+current_user+'">block</a>'):(block_link[0])); //Check if the link to the user talk page was captured from user_tools_link. If the string is null, insert the HTML code ourselves. Otherwise, flatten the array.

			publiclog_link = '<a href="https://en.wikipedia.org/wiki/Special:Log?user='+((ip_pattern.test(current_user))?(current_user):(enc_current_user))+'">logs</a>'; //Set public logs link
			checkuser_link = '<a href="https://en.wikipedia.org/w/index.php?title=Special:CheckUser&user='+((ip_pattern.test(current_user))?(current_user):(enc_current_user))+'">checkuser</a>'; //Set checkuser link
			checklog_link = '<a href="https://en.wikipedia.org/w/index.php?title=Special:CheckUserLog&cuSearchType=target&cuSearch='+((ip_pattern.test(current_user))?(current_user):(enc_current_user))+'">checks</a>'; //Set checkuser log link

			new_user_tool_links = [talk_link];
			new_user_tool_links.push(contribs_link, publiclog_link);
			
			if (ip_pattern.test(current_user)) { //The current user in the undeletion log is an IP address.
				whois_link = '<a href="https://tools.wmflabs.org/whois-referral/gateway.py?lookup=true&ip='+current_user+'">WHOIS</a>';
				geolocate_link = '<a href="https://whatismyipaddress.com/ip/'+current_user+'">geolocate</a>';
				proxy_check_link = '<a href="https://spur.us/context/'+current_user+'">proxy</a>';
				bullseye_check_link = '<a href="https://bullseye.toolforge.org/ip/'+current_user+'">bullseye</a>';

				new_user_tool_links.push(whois_link, geolocate_link, proxy_check_link, bullseye_check_link);
			}
			
			new_user_tool_links.push(checkuser_link, checklog_link, block_link);
			const new_links_str = new_user_tool_links.join(" | ")(user_tool_links.indexOf(")") == (user_tool_links.length - 1))?(+ ""):(+ ")");
			
			$(this).find("span.mw-usertoollinks").html(new_links_str); //After all is done, set the HTML for the user tool links.
		});
	}
});

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top