mediawiki-extensions-Visual.../modules/editcheck/init.js
Ed Sanders 9bf7e65cd0 Only run edit check on main namespace
Bug: T324730
Change-Id: I1a267c00b5a333c809e81f6000c734c66cd1a803
2023-03-28 19:11:15 +00:00

35 lines
1.2 KiB
JavaScript

mw.editcheck = {};
mw.editcheck.doesAddedContentNeedReference = function ( documentModel ) {
if ( mw.config.get( 'wgNamespaceNumber' ) !== mw.config.get( 'wgNamespaceIds' )[ '' ] ) {
return false;
}
var ranges = [];
var offset = 0;
var endOffset = documentModel.getDocumentRange().end;
documentModel.completeHistory.squash().transactions[ 0 ].operations.every( function ( op ) {
if ( op.type === 'retain' ) {
offset += op.length;
} else if ( op.type === 'replace' ) {
ranges.push( new ve.Range( offset, offset + op.insert.length ) );
offset += op.insert.length;
}
// Reached the end of the doc / start of internal list, stop searching
return offset < endOffset;
} );
return ranges.some( function ( range ) {
var minimumCharacters = 50;
// 1. Check that at least minimumCharacters characters have been inserted sequentially
if ( range.getLength() >= minimumCharacters ) {
// 2. Exclude any ranges that already contain references
for ( var i = range.start; i < range.end; i++ ) {
if ( documentModel.data.isElementData( i ) && documentModel.data.getType( i ) === 'mwReference' ) {
return false;
}
}
return true;
}
return false;
} );
};