Manuel:Prévisualisation forcée
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 .
NOTE: some of these scripts are outdated and use addOnloadHook
that is deprecated.
Pour MediaWiki 1.23 et plus récent
// 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
Pour MediaWiki 1.17 et plus récent
Not right working with LivePreview (v.1.17) and OOUI (v.1.23).
// -------------------------------------------------------------------------------
// Force Preview JavaScript code - Start
//
// To allow any group to bypass being forced to preview,
// enter the group name in the permittedGroups array.
// E.g.
// var permittedGroups = []; // force everyone
// var permittedGroups = [ "user"]; // permit logged-in users
// var permittedGroups = [ "sysop", "bureaucrat"]; // permit sysop, bureaucrat
// -------------------------------------------------------------------------------
var permittedGroups = [];
function forcePreview() {
if ( mw.config.get( "wgAction" ) !== "edit" ) return;
if ( mw.config.get( "wgUserGroups" ).filter(function(group) {
return permittedGroups.indexOf(group) > -1;
}).length ) return;
var saveButton = document.getElementById( "wpSave" );
if ( !saveButton ) return;
saveButton.disabled = true;
saveButton.value = "Save page (use preview first)";
saveButton.style.fontWeight = "normal";
document.getElementById("wpPreview").style.fontWeight = "bold";
}
jQuery(document).ready( forcePreview );
// -----------------------------------------------------
// Force Preview JavaScript code - End
// -----------------------------------------------------
Pour MediaWiki 1.14 et plus récent
The following will permit you to control who has preview mode forced on them. It permits you to set one or more user groups to bypass forced preview and save directly. In order to permit a user group, add the group name to the permittedGroups array as shown in the comments with the JavaScript code.
// -------------------------------------------------------------------------------
// Force Preview JavaScript code - Start
//
// To allow any group to bypass being forced to preview,
// enter the group name in the permittedGroups array.
// E.g.
// var permittedGroups = []; // force everyone
// var permittedGroups = [ "user"]; // permit logged-in users
// var permittedGroups = [ "sysop", "bureaucrat"]; // permit sysop, bureaucrat
// -------------------------------------------------------------------------------
var permittedGroups = [];
function forcePreview()
{
if( wgAction !== "edit") return;
if( wgUserGroups === null) {
wgUserGroups = [];
}
if( wgUserGroups.filter(function(group) {
return permittedGroups.indexOf(group) > -1;
}).length ) {
return;
}
var saveButton = document.getElementById("wpSave");
if( !saveButton )
return;
saveButton.disabled = true;
saveButton.value = "Save page (use preview first)";
saveButton.style.fontWeight = "normal";
document.getElementById("wpPreview").style.fontWeight = "bold";
}
addOnloadHook(forcePreview);
// -----------------------------------------------------
// Force Preview JavaScript code - End
// -----------------------------------------------------
Anciennes versions
The below scripts are based on Marc Mongenet's script, from fr.wikipedia.org
.
Force preview par wgUserGroups, nécessite MW version >= 1.10
function forcePreview() {
if (wgUserGroups === "user" || wgAction !== "edit") return;
saveButton = document.getElementById("wpSave");
if (!saveButton) return;
saveButton.disabled = true;
saveButton.value = "Save page (use preview first)";
saveButton.style.fontWeight = "normal";
document.getElementById("wpPreview").style.fontWeight = "bold";
}
addOnloadHook(forcePreview);
If you wish to provide exceptions to certain usergroups. Just change === (EQUAL TO) signs to !== (NOT EQUAL TO)
if (wgUserGroups !== "user" || wgAction !== "edit") return;
Common choices range from "user", "bureaucrat", "sysop" and more depending on your configuration.
L'aperçu forcé de Marc Mongenet par wgUserName nécessite une version MW > 1.6
/* Force preview for anons */
/* by Marc Mongenet, 2006, fr.wikipedia */
function forcePreview() {
if (wgUserName !== null || wgAction !== "edit") return;
saveButton = document.getElementById("wpSave");
if (!saveButton) return;
saveButton.disabled = true;
saveButton.value = "Save page (use preview first)";
saveButton.style.fontWeight = "normal";
document.getElementById("wpPreview").style.fontWeight = "bold";
}
addOnloadHook(forcePreview);
/* End of forcePreview */
Voir aussi
- FAQ
- Extension:ForcePreview - A MediaWiki extension that performs the same function, but cannot be circumvented by disabling javascript