mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-23 22:13:34 +00:00
Merge "Edit check: stop from appearing outside the main namespace"
This commit is contained in:
commit
b19679e381
|
@ -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 );
|
||||
};
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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' );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue