Creation.js – MediaWiki

From Bohemia Interactive Community
Categories:
m (Fix 1.35 theme update)
m (Fix User creation bug, finally!)
 
Line 48: Line 48:


case "User":
case "User":
if (pageTitle.indexOf("/Sandbox") === pageTitle.length - 8) {
var index = pageTitle.indexOf("/Sandbox");
if (index > -1 && index === pageTitle.length - 8) {
offerCreationPreload("Sandbox");
offerCreationPreload("Sandbox");
return;
return;

Latest revision as of 13:02, 21 February 2024

/*****************************************************************************************
 * JavaScript here will be loaded by MediaWiki:Common.js when "creation" is detected.
 *
 *****************************************************************************************/

(function() { // BEGIN WRAPPER

	/*****************************************************************************************
	 * Function adding a UI feature that if used, preloads templates
	 * helpful during certain page creations.
	 * Maintainer: Lou Montana from Fred Gandt
	 */

		function offerCreationPreload(type) {
			var existingButton = document.getElementById("ca-edit"),
				newButton = existingButton.cloneNode(true),
				link = newButton.getElementsByTagName("a")[0];
			link.removeAttribute("accesskey");
			link.setAttribute("title", "Use Template:Preload/" + type);
			link.setAttribute("href", link.getAttribute("href") + "&preload=Template:Preload/" + type);
			link.innerHTML = "Use a preload template";
			existingButton.after(newButton);
		}
		
		var namespace = mw.config.get("wgCanonicalNamespace");
		var pageTitle = mw.config.get("wgTitle");

		switch (namespace)
		{
			case "":
				if (pageTitle.indexOf("BIS fnc ") === 0 ||
					pageTitle.indexOf("BIN fnc ") === 0) {
					offerCreationPreload("Function");
				} else {
					offerCreationPreload("Command");
				}
				return;

			case "Category":
				if (pageTitle.indexOf("Introduced with ") === 0) {
					offerCreationPreload("IntroductionCategory");
				}
				return;

			case "Template":
				offerCreationPreload("Template");
				return;

			case "User":
				var index = pageTitle.indexOf("/Sandbox");
				if (index > -1 && index === pageTitle.length - 8) {
					offerCreationPreload("Sandbox");
					return;
				}
				if (pageTitle.indexOf("/") === -1) {
					offerCreationPreload("User");
					return;
				}
				return;

			default:
				return;
		}

	/*****************************************************************************************/

	}()); // END WRAPPER