mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-23 14:06:52 +00:00
Edit check: move config defaults to the client-side
This lets us encapsulate everything about a check in its JS definition, which makes it much simpler for other extensions or gadgets to create checks. Change-Id: Ica23fc26a576d55addb001e4baf78b3702927208
This commit is contained in:
parent
c7979510e6
commit
d806186810
|
@ -13,19 +13,6 @@ use MessageLocalizer;
|
|||
|
||||
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
|
||||
*
|
||||
|
@ -35,6 +22,6 @@ class ResourceLoaderData {
|
|||
public static function getConfig( MessageLocalizer $context ): array {
|
||||
$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 ) {
|
||||
this.config = config;
|
||||
this.config = ve.extendObject( {}, this.constructor.static.defaultConfig, config );
|
||||
};
|
||||
|
||||
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' );
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.defaultConfig = ve.extendObject( {}, mw.editcheck.BaseEditCheck.static.defaultConfig, {
|
||||
minimumCharacters: 50,
|
||||
beforePunctuation: false
|
||||
} );
|
||||
|
||||
mw.editcheck.AddReferenceEditCheck.prototype.onBeforeSave = function ( surfaceModel ) {
|
||||
return this.findAddedContent( surfaceModel.getDocument() ).map( ( range ) => {
|
||||
const fragment = surfaceModel.getLinearFragment( range );
|
||||
|
|
Loading…
Reference in a new issue