MediaWiki:Common.js

From Heureka Wiki
Revision as of 11:01, 20 December 2023 by Jonare (talk | contribs) (Updated the Force Preview-script.)
Jump to navigation Jump to search

Note: After saving, 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: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Any JavaScript here will be loaded for all users on every page load. */

var isViewingMainPage = (/^MediaWiki(\/.+)? - MediaWiki$/.test(document.title));
if (isViewingMainPage) {
  document.write('<style type="text/css">/*<![CDATA[*/ #lastmod, #siteSub, h1.firstHeading { display: none !important; } #content { padding-top: 1em; }/*]]>*/</style>');
}

// Force Preview and Edit-Summary - Start
// Force preview is JavaScript that prevents specified individuals or groups from saving a wiki page before they preview it at least once.
// https://www.mediawiki.org/wiki/Manual:Force_preview
if (mw.config.get("wgAction") === "edit")
	$.when(mw.loader.using("user.options"), $.ready).then(function () {
		var $wpSave = $("#wpSave"),
			$wpPreview = $("#wpPreview"),
			saveVal = $wpSave.val(),
			classNames = "oo-ui-widget-enabled oo-ui-flaggedElement-progressive oo-ui-flaggedElement-primary";
		if (!mw.user.options.get("forceeditsummary") || mw.user.options.get("previewonfirst"))
			mw.loader.using("mediawiki.api", function () {
				new mw.Api().saveOptions({forceeditsummary: 1, previewonfirst: 0});
			});
		if (!$("#wikiPreview,#wikiDiff").is(":visible") && $wpSave.length && $wpPreview.length) {
			$wpSave.prop("disabled", true)
				.val("Save page (use preview first)")
				.parent().removeClass(classNames).addClass("oo-ui-widget-disabled");
			$wpPreview.one("click", function (e) { // re-enable
				$wpSave.prop("disabled", false)
					.val(saveVal)
					.parent().removeClass("oo-ui-widget-disabled").addClass(classNames);
			}).parent().addClass(classNames);
		}
	});
// Force Preview and Edit-Summary - End


/** includePage ************
 * force the loading of another JavaScript file
 *
 * Maintainer: [[Commons:User:Dschwen]]
 */
 
function includePage( name )
{
 document.write('<script type="text/javascript" src="' + wgScript + '?title='
  + name 
  + '&action=raw&ctype=text/javascript"><\/script>' 
 );
}
/* End of includePage */


/* Including extra .js pages */ 

// switches for scripts
// TODO: migrate to JSConfig
// var load_extratabs = true;
var load_edittools = true;

// extra drop down menu on editing for adding special characters
includePage( 'MediaWiki:Edittools.js' );

//Editpage scripts
if (wgAction=='edit' || wgAction == 'submit')
  importScript('MediaWiki:Editpage.js')

/* End of extra pages */