diff --git a/editcheck/includes/ResourceLoaderData.php b/editcheck/includes/ResourceLoaderData.php index 2cb80026f8..912502f341 100644 --- a/editcheck/includes/ResourceLoaderData.php +++ b/editcheck/includes/ResourceLoaderData.php @@ -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 ?? []; } } diff --git a/editcheck/modules/BaseEditCheck.js b/editcheck/modules/BaseEditCheck.js index e5d8a81a51..84da82d225 100644 --- a/editcheck/modules/BaseEditCheck.js +++ b/editcheck/modules/BaseEditCheck.js @@ -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' ); /** diff --git a/editcheck/modules/editchecks/AddReferenceEditCheck.js b/editcheck/modules/editchecks/AddReferenceEditCheck.js index db3ddece86..caf8828085 100644 --- a/editcheck/modules/editchecks/AddReferenceEditCheck.js +++ b/editcheck/modules/editchecks/AddReferenceEditCheck.js @@ -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 );