mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-27 15:50:29 +00:00
Edit check: stop from appearing outside the main namespace
This was accidentally removed in d69d366469
during its refactor.
Because of the change to how checks are decided to be shown, I've made
AddReferenceEditCheck always be required -- later code in
hasAddedContentNeedingReference assumes that it's loaded anyway, so a
wiki deciding to configure it to not load at all for some account types
would have broken saving.
Bug: T373692
Change-Id: I007cd705451581ebacfa12e8ac5502bd1bc56a38
This commit is contained in:
parent
dedd30bfef
commit
e947e53f98
|
@ -47,10 +47,33 @@ mw.editcheck.BaseEditCheck.prototype.getDescription = function ( /* action */ )
|
||||||
return this.constructor.static.description;
|
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 ) {
|
* Find out whether the check should be applied
|
||||||
return [];
|
*
|
||||||
|
* 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 )
|
return diff.getModifiedRanges( this.constructor.static.onlyCoveredNodes )
|
||||||
.filter( ( range ) => this.shouldApplyToSection( diff, range ) && range.getLength() >= this.config.minimumCharacters );
|
.filter( ( range ) => this.shouldApplyToSection( diff, range ) && range.getLength() >= this.config.minimumCharacters );
|
||||||
};
|
};
|
||||||
|
|
|
@ -58,6 +58,9 @@ mw.editcheck.EditCheckFactory.prototype.createAllByListener = function ( listene
|
||||||
const newChecks = [];
|
const newChecks = [];
|
||||||
this.getNamesByListener( listener ).forEach( ( checkName ) => {
|
this.getNamesByListener( listener ).forEach( ( checkName ) => {
|
||||||
const check = this.create( checkName, mw.editcheck.config[ checkName ] );
|
const check = this.create( checkName, mw.editcheck.config[ checkName ] );
|
||||||
|
if ( !check.canBeShown() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const actions = check[ listener ]( diff );
|
const actions = check[ listener ]( diff );
|
||||||
if ( actions.length > 0 ) {
|
if ( actions.length > 0 ) {
|
||||||
ve.batchPush( newChecks, actions );
|
ve.batchPush( newChecks, actions );
|
||||||
|
|
|
@ -11,6 +11,9 @@ require( './EditCheckAction.js' );
|
||||||
require( './BaseEditCheck.js' );
|
require( './BaseEditCheck.js' );
|
||||||
|
|
||||||
mw.editcheck.accountShouldSeeEditCheck = function ( config ) {
|
mw.editcheck.accountShouldSeeEditCheck = function ( config ) {
|
||||||
|
if ( mw.editcheck.ecenable ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
// account status:
|
// account status:
|
||||||
// loggedin, loggedout, or any-other-value meaning 'both'
|
// loggedin, loggedout, or any-other-value meaning 'both'
|
||||||
// we'll count temporary users as "logged out" by using isNamed here
|
// 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
|
// TODO: Load these checks behind feature flags
|
||||||
// require( './ConvertReferenceEditCheck.js' );
|
// require( './ConvertReferenceEditCheck.js' );
|
||||||
// require( './TextMatchEditCheck.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
|
* 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 ) {
|
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' )[ '' ] ) {
|
if ( mw.config.get( 'wgNamespaceNumber' ) !== mw.config.get( 'wgNamespaceIds' )[ '' ] ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue