diff --git a/editcheck/modules/BaseEditCheck.js b/editcheck/modules/BaseEditCheck.js index a573e38201..60e01899ce 100644 --- a/editcheck/modules/BaseEditCheck.js +++ b/editcheck/modules/BaseEditCheck.js @@ -47,10 +47,33 @@ mw.editcheck.BaseEditCheck.prototype.getDescription = function ( /* action */ ) return this.constructor.static.description; }; -mw.editcheck.BaseEditCheck.prototype.getModifiedRangesFromDiff = function ( diff ) { - if ( !mw.editcheck.ecenable && this.config.maximumEditcount && mw.config.get( 'wgUserEditCount', 0 ) > this.config.maximumEditcount ) { - return []; +/** + * Find out whether the check should be applied + * + * This is a general check for its applicability to the viewer / page, rather + * than a specific check based on the current edit. It's used to filter out + * checks before any maybe-expensive content analysis happens. + * + * @return {boolean} Whether the check should be shown + */ +mw.editcheck.BaseEditCheck.prototype.canBeShown = function () { + // all checks are only in the main namespace for now + if ( mw.config.get( 'wgNamespaceNumber' ) !== mw.config.get( 'wgNamespaceIds' )[ '' ] ) { + return false; } + // some checks are configured to only be for logged in / out users + if ( !mw.editcheck.accountShouldSeeEditCheck( this.config ) ) { + // includes checking for mw.editcheck.ecenable + return false; + } + // some checks are only shown for newer users + if ( this.config.maximumEditcount && mw.config.get( 'wgUserEditCount', 0 ) > this.config.maximumEditcount ) { + return false; + } + return true; +}; + +mw.editcheck.BaseEditCheck.prototype.getModifiedRangesFromDiff = function ( diff ) { return diff.getModifiedRanges( this.constructor.static.onlyCoveredNodes ) .filter( ( range ) => this.shouldApplyToSection( diff, range ) && range.getLength() >= this.config.minimumCharacters ); }; diff --git a/editcheck/modules/EditCheckFactory.js b/editcheck/modules/EditCheckFactory.js index a6b7acac2b..2ecee8d351 100644 --- a/editcheck/modules/EditCheckFactory.js +++ b/editcheck/modules/EditCheckFactory.js @@ -58,6 +58,9 @@ mw.editcheck.EditCheckFactory.prototype.createAllByListener = function ( listene const newChecks = []; this.getNamesByListener( listener ).forEach( ( checkName ) => { const check = this.create( checkName, mw.editcheck.config[ checkName ] ); + if ( !check.canBeShown() ) { + return; + } const actions = check[ listener ]( diff ); if ( actions.length > 0 ) { ve.batchPush( newChecks, actions ); diff --git a/editcheck/modules/init.js b/editcheck/modules/init.js index 48b0f29df7..c8e35d66e3 100644 --- a/editcheck/modules/init.js +++ b/editcheck/modules/init.js @@ -11,6 +11,9 @@ require( './EditCheckAction.js' ); require( './BaseEditCheck.js' ); mw.editcheck.accountShouldSeeEditCheck = function ( config ) { + if ( mw.editcheck.ecenable ) { + return true; + } // account status: // loggedin, loggedout, or any-other-value meaning 'both' // we'll count temporary users as "logged out" by using isNamed here @@ -26,9 +29,7 @@ mw.editcheck.accountShouldSeeEditCheck = function ( config ) { // TODO: Load these checks behind feature flags // require( './ConvertReferenceEditCheck.js' ); // require( './TextMatchEditCheck.js' ); -if ( mw.editcheck.accountShouldSeeEditCheck( mw.editcheck.config.addReference ) || mw.editcheck.ecenable ) { - require( './AddReferenceEditCheck.js' ); -} +require( './AddReferenceEditCheck.js' ); /** * Return the content ranges (content branch node interiors) contained within a range @@ -104,7 +105,9 @@ mw.editcheck.Diff.prototype.getModifiedRanges = function ( coveredNodesOnly ) { }; mw.editcheck.hasAddedContentNeedingReference = function ( surface, includeReferencedContent ) { - // helper for ve.init.mw.ArticleTarget save-tagging, keep logic below in-sync with AddReferenceEditCheck + // helper for ve.init.mw.ArticleTarget save-tagging, keep logic below in-sync with AddReferenceEditCheck. + // This is bypassing the normal "should this check apply?" logic for creation, so we need to manually + // apply the "only the main namespace" rule. if ( mw.config.get( 'wgNamespaceNumber' ) !== mw.config.get( 'wgNamespaceIds' )[ '' ] ) { return false; }