Snippets/Force preview
Appearance
< Snippets
(Redirected from Manual:Force preview)Force preview | |
---|---|
Language(s): | JavaScript |
Compatible with: | MediaWiki 1.23++ (Vector) |
Force preview is JavaScript that prevents specified individuals or groups from saving a wiki page before they preview it at least once.
In order to use this code, insert it into your wiki's MediaWiki:Common.js page.
Note that this method is not foolproof. If a user disables JavaScript in their browser, they will not have preview forced on them. If you want to ensure that this policy is enforced, then you should look at Extension:ForcePreview .
// Force Preview and Edit-Summary - Start
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
See also
[edit]- Manual:FAQ
- Extension:ForcePreview - A MediaWiki extension that performs the same function, but cannot be circumvented by disabling javascript