Edit check: Simplify "experience" config to "maximumEditcount"

There's no product need for anything other than an upper limit
on edit count. If one arises in the future we can adjust accordingly,
but better to keep the JSON, and any UI implementation, simple
for now.

Change-Id: I892847ad78b19695f0f0f664002d3c566f7806de
This commit is contained in:
Ed Sanders 2023-10-03 16:20:51 +01:00
parent 47dc22d6c0
commit 70c116a17a
2 changed files with 2 additions and 20 deletions

View file

@ -19,8 +19,7 @@ class ResourceLoaderData {
// TODO: when we have multiple edit checks this will likely be a generic block: // TODO: when we have multiple edit checks this will likely be a generic block:
// account: loggedin, loggedout, anything non-truthy means allow either // account: loggedin, loggedout, anything non-truthy means allow either
'account' => false, 'account' => false,
// experience: [ comparison, number ], compared to wgUserEditCount 'maximumEditcount' => 100
'experience' => [ '<', 100 ],
], ],
]; ];

View file

@ -5,23 +5,6 @@ mw.editcheck = {};
mw.editcheck.config = require( './config.json' ); mw.editcheck.config = require( './config.json' );
var compares = function ( matcher, number ) {
// config is an array of [ comparison, value ]
try {
switch ( matcher[ 0 ] ) {
case '<': return number < matcher[ 1 ];
case '<=': return number <= matcher[ 1 ];
case '>': return number > matcher[ 1 ];
case '>=': return number >= matcher[ 1 ];
case '==': return number === matcher[ 1 ];
case '!=': return number !== matcher[ 1 ];
default: return false;
}
} catch ( err ) {
// In case something uncomparable was given as the number
return false;
}
};
mw.editcheck.accountShouldSeeEditCheck = function ( config ) { mw.editcheck.accountShouldSeeEditCheck = function ( config ) {
// account status: // account status:
// loggedin, loggedout, or any-other-value meaning 'both' // loggedin, loggedout, or any-other-value meaning 'both'
@ -32,7 +15,7 @@ mw.editcheck.accountShouldSeeEditCheck = function ( config ) {
if ( config.account === 'loggedin' && !mw.user.isNamed() ) { if ( config.account === 'loggedin' && !mw.user.isNamed() ) {
return false; return false;
} }
if ( config.experience && !compares( config.experience, mw.config.get( 'wgUserEditCount', 0 ) ) ) { if ( config.maximumEditcount && mw.config.get( 'wgUserEditCount', 0 ) > config.maximumEditcount ) {
return false; return false;
} }
return true; return true;