MediaWiki

Gadget-editButton.js

From Dogcraft Wiki

Revision as of 20:21, 3 February 2026 by Domino (talk | contribs) (Label now says "Create (source)" on non-existent pages. Also preloads template documentation layout for newly created templates)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (โŒ˜-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (โŒ˜-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
$( function () {
	var namespace = mw.config.get('wgNamespaceNumber');
	var action = mw.config.get('wgAction');
	var articleId = mw.config.get('wgArticleId');
	
	var wikiEdit = document.createElement("a");
	wikiEdit.setAttribute("id", "wikiEdit");
	if (action === 'edit') {
		wikiEdit.setAttribute("class", "button editButton-view");
		wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName'))
	} else {
		if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0) {
			wikiEdit.setAttribute("class", "button editButton-edit");
			wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&veaction=edit")
		} else {
			wikiEdit.setAttribute("class", "button editButton-editSource");
			if (namespace == 10 && articleId == 0) {
				wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&action=edit&preload=Template%3ANewTemplateInCategory&preloadparams[0]=Add+template+category");
			} else {
				wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&action=edit");
			}
		}
	}
		
	var wikiEditButton = document.createElement("button");
	wikiEdit.appendChild(wikiEditButton);
	
	var wikiEditButtonIcon = document.createElement("i");
	if (action === "edit") 
		wikiEditButtonIcon.setAttribute("class", "fas fa-file");
	else {
		if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0)
			wikiEditButtonIcon.setAttribute("class", "fas fa-pencil");
		else 
			wikiEditButtonIcon.setAttribute("class", "fas fa-code");
	}
	wikiEditButton.appendChild(wikiEditButtonIcon);
	
	var wikiEditButtonLabel = document.createElement("span");
	if (action === "edit") {
		wikiEditButtonLabel.innerText = " Read";
	} else {
		if (articleId == 0) {
			if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0) {
				wikiEditButtonLabel.innerText = " Create";
			} else {
				wikiEditButtonLabel.innerText = " Create source";
			}
		} else {
			if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0) {
				wikiEditButtonLabel.innerText = " Edit";
			} else {
				wikiEditButtonLabel.innerText = " Edit source";
			}
		}
	}
	wikiEditButton.appendChild(wikiEditButtonLabel);
	
	var wikiActions = document.getElementById("wikiActions")
	if (wikiActions) wikiActions.before(wikiEdit);
})
This page was last modified on 3 February 2026, at 20:21. (12 days ago)
Background Takeshi by Edo