Merge "EditCheck: Add more method documentation"

This commit is contained in:
jenkins-bot 2024-11-19 18:07:43 +00:00 committed by Gerrit Code Review
commit c6303220e1
6 changed files with 65 additions and 0 deletions

View file

@ -1,3 +1,12 @@
/**
* EditCheckAction
*
* @param {Object} config
* @param {mw.editcheck.BaseEditCheck} check
* @param {ve.dm.SurfaceFragment[]} highlights Fragments to highlight
* @param {ve.dm.SurfaceFragment} selection Fragment to select when acting
* @param {jQuery|string|Function|OO.ui.HtmlSnippet} message Check message body
*/
mw.editcheck.EditCheckAction = function MWEditCheckAction( config ) { mw.editcheck.EditCheckAction = function MWEditCheckAction( config ) {
this.check = config.check; this.check = config.check;
this.highlights = config.highlights; this.highlights = config.highlights;
@ -7,10 +16,20 @@ mw.editcheck.EditCheckAction = function MWEditCheckAction( config ) {
OO.initClass( mw.editcheck.EditCheckAction ); OO.initClass( mw.editcheck.EditCheckAction );
/**
* Get the available choices
*
* @return {Object[]}
*/
mw.editcheck.EditCheckAction.prototype.getChoices = function () { mw.editcheck.EditCheckAction.prototype.getChoices = function () {
return this.check.getChoices( this ); return this.check.getChoices( this );
}; };
/**
* Get a description of the check
*
* @return {string}
*/
mw.editcheck.EditCheckAction.prototype.getDescription = function () { mw.editcheck.EditCheckAction.prototype.getDescription = function () {
return this.check.getDescription( this ); return this.check.getDescription( this );
}; };

View file

@ -64,6 +64,11 @@ ve.ui.EditCheckContextItem.prototype.renderBody = function () {
); );
}; };
/**
* Close the context item
*
* @param {Object} data Window closing data
*/
ve.ui.EditCheckContextItem.prototype.close = function ( data ) { ve.ui.EditCheckContextItem.prototype.close = function ( data ) {
// HACK: Un-suppress close button on mobile context // HACK: Un-suppress close button on mobile context
if ( this.context.isMobile() ) { if ( this.context.isMobile() ) {
@ -72,6 +77,11 @@ ve.ui.EditCheckContextItem.prototype.close = function ( data ) {
this.data.callback( data, this.data ); this.data.callback( data, this.data );
}; };
/**
* Handle click events on a choice button
*
* @param {string} choice Choice identifier, e.g. 'accept' or 'reject'
*/
ve.ui.EditCheckContextItem.prototype.onChoiceClick = function ( choice ) { ve.ui.EditCheckContextItem.prototype.onChoiceClick = function ( choice ) {
this.data.action.check.act( choice, this.data.action, this ); this.data.action.check.act( choice, this.data.action, this );
}; };

View file

@ -14,6 +14,9 @@ OO.inheritClass( mw.editcheck.EditCheckFactory, OO.Factory );
/* Methods */ /* Methods */
/**
* @inheritdoc
*/
mw.editcheck.EditCheckFactory.prototype.register = function ( constructor, name ) { mw.editcheck.EditCheckFactory.prototype.register = function ( constructor, name ) {
name = name || ( constructor.static && constructor.static.name ); name = name || ( constructor.static && constructor.static.name );
@ -53,6 +56,15 @@ mw.editcheck.EditCheckFactory.prototype.getNamesByListener = function ( listener
return this.checksByListener[ listener ]; return this.checksByListener[ listener ];
}; };
/**
* Create all checks actions for a given listener
*
* TODO: Rename to createAllActionsByListener
*
* @param {string} listener Listener name
* @param {ve.dm.Surface} surfaceModel Surface model
* @return {mw.editcheck.EditCheckActions[]} Actions, sorted by range
*/
mw.editcheck.EditCheckFactory.prototype.createAllByListener = function ( listener, surfaceModel ) { mw.editcheck.EditCheckFactory.prototype.createAllByListener = function ( listener, surfaceModel ) {
const newChecks = []; const newChecks = [];
this.getNamesByListener( listener ).forEach( ( checkName ) => { this.getNamesByListener( listener ).forEach( ( checkName ) => {

View file

@ -135,6 +135,9 @@ ve.ui.EditCheckInspector.prototype.getReadyProcess = function ( data ) {
}, this ); }, this );
}; };
/**
* @inheritdoc
*/
ve.ui.EditCheckInspector.prototype.getActionProcess = function ( action ) { ve.ui.EditCheckInspector.prototype.getActionProcess = function ( action ) {
if ( action === '' ) { if ( action === '' ) {
return new OO.ui.Process( function () { return new OO.ui.Process( function () {

View file

@ -20,6 +20,13 @@ mw.editcheck.AddReferenceEditCheck.prototype.onBeforeSave = function ( surfaceMo
} ); } );
}; };
/**
* Find content ranges which have been inserted
*
* @param {ve.dm.Document} documentModel
* @param {boolean} includeReferencedContent Include contents that already contains a reference
* @return {ve.Range[]}
*/
mw.editcheck.AddReferenceEditCheck.prototype.findAddedContent = function ( documentModel, includeReferencedContent ) { mw.editcheck.AddReferenceEditCheck.prototype.findAddedContent = function ( documentModel, includeReferencedContent ) {
// Broken out so a helper for tagging can call it // Broken out so a helper for tagging can call it
const ranges = this.getModifiedContentRanges( documentModel ).filter( ( range ) => { const ranges = this.getModifiedContentRanges( documentModel ).filter( ( range ) => {

View file

@ -44,6 +44,13 @@ mw.editcheck.getContentRanges = function ( documentModel, range, covers ) {
return ranges; return ranges;
}; };
/**
* Check if the document has content needing a reference, for AddReferenceEditCheck
*
* @param {ve.dm.Document} documentModel
* @param {boolean} includeReferencedContent Include contents that already contains a reference
* @return {boolean}
*/
mw.editcheck.hasAddedContentNeedingReference = function ( documentModel, includeReferencedContent ) { mw.editcheck.hasAddedContentNeedingReference = function ( documentModel, 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 // This is bypassing the normal "should this check apply?" logic for creation, so we need to manually
@ -55,6 +62,13 @@ mw.editcheck.hasAddedContentNeedingReference = function ( documentModel, include
return check.findAddedContent( documentModel, includeReferencedContent ).length > 0; return check.findAddedContent( documentModel, includeReferencedContent ).length > 0;
}; };
/**
* Get content ranges which have been inserted
*
* @param {ve.dm.Document} documentModel
* @param {boolean} coveredNodesOnly Only include ranges which cover the whole of their node
* @return {ve.Range[]}
*/
mw.editcheck.getModifiedRanges = function ( documentModel, coveredNodesOnly ) { mw.editcheck.getModifiedRanges = function ( documentModel, coveredNodesOnly ) {
if ( !documentModel.completeHistory.getLength() ) { if ( !documentModel.completeHistory.getLength() ) {
return []; return [];