Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
(New page: →Any JavaScript here will be loaded for all users on every page load.: var isViewingMainPage = (/^MediaWiki(\/.+)? - MediaWiki$/.test(document.title)); if (isViewingMainPage) { docu...) |
(Updated the Force Preview-script.) |
||
Line 6: | Line 6: | ||
} | } | ||
− | / | + | // 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 ************ | /** includePage ************ |
Revision as of 11:01, 20 December 2023
/* 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 */