mediawiki-extensions-Visual.../includes/EditCheck/ResourceLoaderData.php
David Lynch 80f3ef9531 Edit check config: account-state and experience
Bug: T330112
Change-Id: If713a7edcb71a5ea8123da27a3b1bffc45992ad0
2023-09-11 15:56:42 -05:00

39 lines
1.1 KiB
PHP

<?php
/**
* Utilities for ResourceLoader modules used by EditCheck.
*
* @file
* @ingroup Extensions
* @license MIT
*/
namespace MediaWiki\Extension\VisualEditor\EditCheck;
use MessageLocalizer;
class ResourceLoaderData {
protected static array $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,
// experience: [ comparison, number ], compared to wgUserEditCount
'experience' => [ '<', 100 ],
],
];
/**
* Return configuration data for edit checks, fetched from an on-wiki JSON message
*
* @param MessageLocalizer $context
* @return array Configuration data for edit checks
*/
public static function getConfig( MessageLocalizer $context ) {
$raw_config = json_decode( $context->msg( 'editcheck-config.json' )->inContentLanguage()->plain(), true );
return array_replace_recursive( self::$defaults, $raw_config ?? [] );
}
}