Creation.js – MediaWiki

From Bohemia Interactive Community
Categories:
m (Purge button attempt)
m (Fix User creation bug, finally!)
 
(11 intermediate revisions by the same user not shown)
Line 8: Line 8:
/*****************************************************************************************
/*****************************************************************************************
* Function adding a UI feature that if used, preloads templates
* Function adding a UI feature that if used, preloads templates
* helpful during certain page creations.
* helpful during certain page creations.
* Maintainer: Lou Montana from Fred Gandt
* Maintainer: Lou Montana from Fred Gandt
*/
*/


function offerCreationPreload(type) {
function offerCreationPreload(type) {
var createBar = document.getElementById("ca-edit"),
var existingButton = document.getElementById("ca-edit"),
button = createBar.getElementsByTagName("span")[0].cloneNode(true),
newButton = existingButton.cloneNode(true),
link = button.getElementsByTagName("a")[0];
link = newButton.getElementsByTagName("a")[0];
link.removeAttribute("accesskey");
link.removeAttribute("accesskey");
link.setAttribute("title", "Preload a " + type + " guide for this creation");
link.setAttribute("title", "Use Template:Preload/" + type);
link.setAttribute("href", link.getAttribute("href") + "&preload=Template:" + type + "/preload");
link.setAttribute("href", link.getAttribute("href") + "&preload=Template:Preload/" + type);
link.innerHTML = "Preload " + type + " template";
link.innerHTML = "Use a preload template";
createBar.appendChild(button);
existingButton.after(newButton);
}
if (mw.config.get("wgCanonicalNamespace") === "Template") {
offerCreationPreload("Template");
} else if (mw.config.get("wgCanonicalNamespace") === "") {
if (mw.config.get("wgTitle").indexOf("BIS fnc ") === 0 ||
mw.config.get("wgTitle").indexOf("BIN fnc ") === 0) {
offerCreationPreload("Function");
} else {
offerCreationPreload("Command");
}
}
}
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;


function offerPurgeButton() {
default:
var protectButton = document.getElementById("ca-protect"),
return;
link = button.getElementsByTagName("a")[0].cloneNode(true);
link.removeAttribute("accesskey");
link.setAttribute("title", "Purge the page's cache");
link.setAttribute("href", link.getAttribute("href") + "?action=purge");
link.innerHTML = "Purge";
protectButton.appendChild(button);
}
if (
[
"Lou Montana",
/* allowed authors */
].includes(mw.config.get("wgUserName"))) {
offerPurgeButton();
}
}



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