Creation.js – MediaWiki

From Bohemia Interactive Community
Categories:
m (woopsie)
m (Purge button attempt)
Line 3: Line 3:
  *
  *
  *****************************************************************************************/
  *****************************************************************************************/
 
(function() { // BEGIN WRAPPER
(function() { // BEGIN WRAPPER
 
/*****************************************************************************************
/*****************************************************************************************
* Function adding a UI feature that if used, preloads templates
* Function adding a UI feature that if used, preloads templates
Line 11: Line 11:
* 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 createBar = document.getElementById("ca-edit"),
Line 32: Line 32:
}
}
}
}
/*****************************************************************************************/
/*****************************************************************************************/
 
function offerPurgeButton() {
var protectButton = document.getElementById("ca-protect"),
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();
}
 
/*****************************************************************************************/
 
}()); // END WRAPPER
}()); // END WRAPPER

Revision as of 01:39, 30 December 2020

/*****************************************************************************************
 * 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 createBar = document.getElementById("ca-edit"),
				button = createBar.getElementsByTagName("span")[0].cloneNode(true),
				link = button.getElementsByTagName("a")[0];
			link.removeAttribute("accesskey");
			link.setAttribute("title", "Preload a " + type + " guide for this creation");
			link.setAttribute("href", link.getAttribute("href") + "&preload=Template:" + type + "/preload");
			link.innerHTML = "Preload " + type + " template";
			createBar.appendChild(button);
		}
		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");
			}
		}

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

		function offerPurgeButton() {
			var protectButton = document.getElementById("ca-protect"),
				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();
		}

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

	}()); // END WRAPPER