| 1 |
mw.editcheck.BaseEditCheck = function MWBaseEditCheck( config ) { |
| 2 |
this.config = config; |
| 3 |
}; |
| 4 |
|
| 5 |
OO.initClass( mw.editcheck.BaseEditCheck ); |
| 6 |
|
| 7 |
mw.editcheck.BaseEditCheck.static.onlyCoveredNodes = false; |
| 8 |
|
| 9 |
mw.editcheck.BaseEditCheck.static.choices = [ |
| 10 |
{ |
| 11 |
action: 'accept', |
| 12 |
label: ve.msg( 'editcheck-dialog-action-yes' ), |
| 13 |
icon: 'check' |
| 14 |
}, |
| 15 |
{ |
| 16 |
action: 'reject', |
| 17 |
label: ve.msg( 'editcheck-dialog-action-no' ), |
| 18 |
icon: 'close' |
| 19 |
} |
| 20 |
]; |
| 21 |
|
| 22 |
mw.editcheck.BaseEditCheck.static.description = ve.msg( 'editcheck-dialog-addref-description' ); |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
mw.editcheck.BaseEditCheck.prototype.onBeforeSave = null; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
mw.editcheck.BaseEditCheck.prototype.onDocumentChange = null; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
mw.editcheck.BaseEditCheck.prototype.act = null; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
mw.editcheck.BaseEditCheck.prototype.getChoices = function () { |
| 48 |
return this.constructor.static.choices; |
| 49 |
}; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
mw.editcheck.BaseEditCheck.prototype.getDescription = function () { |
| 56 |
return this.constructor.static.description; |
| 57 |
}; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
mw.editcheck.BaseEditCheck.prototype.canBeShown = function () { |
| 69 |
|
| 70 |
if ( mw.config.get( 'wgNamespaceNumber' ) !== mw.config.get( 'wgNamespaceIds' )[ '' ] ) { |
| 71 |
return false; |
| 72 |
} |
| 73 |
|
| 74 |
if ( mw.editcheck.ecenable ) { |
| 75 |
return true; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
if ( this.config.account === 'loggedout' && mw.user.isNamed() ) { |
| 81 |
return false; |
| 82 |
} |
| 83 |
if ( this.config.account === 'loggedin' && !mw.user.isNamed() ) { |
| 84 |
return false; |
| 85 |
} |
| 86 |
|
| 87 |
if ( this.config.maximumEditcount && mw.config.get( 'wgUserEditCount', 0 ) > this.config.maximumEditcount ) { |
| 88 |
return false; |
| 89 |
} |
| 90 |
return true; |
| 91 |
}; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
mw.editcheck.BaseEditCheck.prototype.getModifiedContentRanges = function ( documentModel ) { |
| 100 |
return mw.editcheck.getModifiedRanges( documentModel, this.constructor.static.onlyCoveredNodes ) |
| 101 |
.filter( |
| 102 |
( range ) => range.getLength() >= this.config.minimumCharacters && |
| 103 |
this.isRangeInValidSection( range, documentModel ) |
| 104 |
); |
| 105 |
}; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
mw.editcheck.BaseEditCheck.prototype.isRangeInValidSection = function ( range, documentModel ) { |
| 115 |
const ignoreSections = this.config.ignoreSections || []; |
| 116 |
if ( ignoreSections.length === 0 && !this.config.ignoreLeadSection ) { |
| 117 |
|
| 118 |
return true; |
| 119 |
} |
| 120 |
const isHeading = ( nodeType ) => nodeType === 'mwHeading'; |
| 121 |
|
| 122 |
|
| 123 |
const heading = documentModel.getNearestNodeMatching( isHeading, range.start, -1, 1 ); |
| 124 |
if ( !heading ) { |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
return !( |
| 129 |
this.config.ignoreLeadSection && |
| 130 |
!!documentModel.getNearestNodeMatching( isHeading, range.start, 1 ) |
| 131 |
); |
| 132 |
} |
| 133 |
if ( ignoreSections.length === 0 ) { |
| 134 |
|
| 135 |
return true; |
| 136 |
} |
| 137 |
const compare = new Intl.Collator( documentModel.getLang(), { sensitivity: 'accent' } ).compare; |
| 138 |
const headingText = documentModel.data.getText( false, heading.getRange() ); |
| 139 |
|
| 140 |
return !ignoreSections.some( ( section ) => compare( headingText, section ) === 0 ); |
| 141 |
}; |