mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-23 14:06:52 +00:00
Merge "Edit check: move config defaults to the client-side"
This commit is contained in:
commit
3ffa2ac018
|
@ -13,19 +13,6 @@ use MessageLocalizer;
|
||||||
|
|
||||||
class ResourceLoaderData {
|
class ResourceLoaderData {
|
||||||
|
|
||||||
private const DEFAULTS = [
|
|
||||||
'addReference' => [
|
|
||||||
'minimumCharacters' => 50,
|
|
||||||
'beforePunctuation' => false,
|
|
||||||
// TODO: when we have multiple edit checks this will likely be a generic block:
|
|
||||||
// account: loggedin, loggedout, anything non-truthy means allow either
|
|
||||||
'account' => false,
|
|
||||||
'maximumEditcount' => 100,
|
|
||||||
'ignoreSections' => [],
|
|
||||||
'ignoreLeadSection' => false,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return configuration data for edit checks, fetched from an on-wiki JSON message
|
* Return configuration data for edit checks, fetched from an on-wiki JSON message
|
||||||
*
|
*
|
||||||
|
@ -35,6 +22,6 @@ class ResourceLoaderData {
|
||||||
public static function getConfig( MessageLocalizer $context ): array {
|
public static function getConfig( MessageLocalizer $context ): array {
|
||||||
$raw_config = json_decode( $context->msg( 'editcheck-config.json' )->inContentLanguage()->plain(), true );
|
$raw_config = json_decode( $context->msg( 'editcheck-config.json' )->inContentLanguage()->plain(), true );
|
||||||
|
|
||||||
return array_replace_recursive( self::DEFAULTS, $raw_config ?? [] );
|
return $raw_config ?? [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
mw.editcheck.BaseEditCheck = function MWBaseEditCheck( config ) {
|
mw.editcheck.BaseEditCheck = function MWBaseEditCheck( config ) {
|
||||||
this.config = config;
|
this.config = ve.extendObject( {}, this.constructor.static.defaultConfig, config );
|
||||||
};
|
};
|
||||||
|
|
||||||
OO.initClass( mw.editcheck.BaseEditCheck );
|
OO.initClass( mw.editcheck.BaseEditCheck );
|
||||||
|
@ -19,6 +19,13 @@ mw.editcheck.BaseEditCheck.static.choices = [
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
mw.editcheck.BaseEditCheck.static.defaultConfig = {
|
||||||
|
account: false, // 'loggedin', 'loggedout', anything non-truthy means allow either
|
||||||
|
maximumEditcount: 100,
|
||||||
|
ignoreSections: [],
|
||||||
|
ignoreLeadSection: false
|
||||||
|
};
|
||||||
|
|
||||||
mw.editcheck.BaseEditCheck.static.description = ve.msg( 'editcheck-dialog-addref-description' );
|
mw.editcheck.BaseEditCheck.static.description = ve.msg( 'editcheck-dialog-addref-description' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,6 +9,11 @@ mw.editcheck.AddReferenceEditCheck.static.name = 'addReference';
|
||||||
|
|
||||||
mw.editcheck.AddReferenceEditCheck.static.description = ve.msg( 'editcheck-dialog-addref-description' );
|
mw.editcheck.AddReferenceEditCheck.static.description = ve.msg( 'editcheck-dialog-addref-description' );
|
||||||
|
|
||||||
|
mw.editcheck.AddReferenceEditCheck.static.defaultConfig = ve.extendObject( {}, mw.editcheck.BaseEditCheck.static.defaultConfig, {
|
||||||
|
minimumCharacters: 50,
|
||||||
|
beforePunctuation: false
|
||||||
|
} );
|
||||||
|
|
||||||
mw.editcheck.AddReferenceEditCheck.prototype.onBeforeSave = function ( surfaceModel ) {
|
mw.editcheck.AddReferenceEditCheck.prototype.onBeforeSave = function ( surfaceModel ) {
|
||||||
return this.findAddedContent( surfaceModel.getDocument() ).map( ( range ) => {
|
return this.findAddedContent( surfaceModel.getDocument() ).map( ( range ) => {
|
||||||
const fragment = surfaceModel.getLinearFragment( range );
|
const fragment = surfaceModel.getLinearFragment( range );
|
||||||
|
|
Loading…
Reference in a new issue