Revert "Revert "Add tag when reference added to the page""

This reverts commit 235e5aca00.

Reason for revert: Re-applying with fixes

Change-Id: I9dc5a77045ea5f15c90cf84a15815e13dffd5739
This commit is contained in:
Esanders 2023-07-06 13:16:49 +00:00 committed by Ed Sanders
parent 25f7097e9f
commit b33bb734af
4 changed files with 35 additions and 0 deletions

View file

@ -18,6 +18,8 @@
},
"tag-editcheck-newcontent": "-",
"tag-editcheck-newcontent-description": "EditCheck thinks new content was added to the page",
"tag-editcheck-newreference": "-",
"tag-editcheck-newreference-description": "A reference was added to the page",
"tag-editcheck-references": "-",
"tag-editcheck-references-description": "EditCheck thinks a reference might have been needed",
"tag-visualeditor": "[[{{MediaWiki:visualeditor-descriptionpagelink}}|Visual edit]]",

View file

@ -27,6 +27,8 @@
},
"tag-editcheck-newcontent": "{{ignored}}Short description of the editcheck-newcontent tag.\n\nHidden tag added when EditCheck thinks new content was added to the page.\n\nSee also:\n* {{msg-mw|Tag-editcheck-newcontent-description}}\n{{Related|tag-newcontent-references-description}}",
"tag-editcheck-newcontent-description": "Long description of the editcheck-newcontent tag.\n\nHidden tag added when EditCheck thinks new content was added to the page.\n\nSee also:\n* {{msg-mw|Tag-editcheck-newcontent}}\n{{Related|tag-newcontent-references}}",
"tag-editcheck-newreference": "{{ignored}}Short description of the editcheck-newreference tag.\n\nHidden tag added when a reference is added to the page.\n\nSee also:\n* {{msg-mw|Tag-editcheck-newreference-description}}\n{{Related|tag-newreference-references-description}}",
"tag-editcheck-newreference-description": "Long description of the editcheck-newreference tag.\n\nHidden tag added when a reference is added to the page.\n\nSee also:\n* {{msg-mw|Tag-editcheck-newreference}}\n{{Related|tag-newreference-references}}",
"tag-editcheck-references": "{{ignored}}Short description of the editcheck-references tag.\n\nHidden tag added when EditCheck thinks added content might need a reference.\n\nSee also:\n* {{msg-mw|Tag-editcheck-references-description}}\n{{Related|tag-editcheck-references-description}}",
"tag-editcheck-references-description": "Long description of the editcheck-references tag.\n\nHidden tag added when EditCheck thinks added content might need a reference.\n\nSee also:\n* {{msg-mw|Tag-editcheck-references}}\n{{Related|tag-editcheck-references}}",
"tag-visualeditor": "Short description of the visualeditor tag. Do not translate the link target, but do translate the words \"Visual edit\".\n\nShown on lists of changes (history, recentchanges, etc.) for each edit made using VisualEditor.\n\nRefers to {{msg-mw|Visualeditor-descriptionpagelink}}.\n\nSee also:\n* {{msg-mw|Tag-visualeditor-needcheck}}\n{{Related|Tag-visualeditor}}\n{{Identical|VisualEditor}}",

View file

@ -58,6 +58,7 @@ class Hooks implements TextSlotDiffRendererTablePrefixHook {
// Edit check
'editcheck-references',
'editcheck-newcontent',
'editcheck-newreference',
// No longer in active use:
'visualeditor-needcheck',
'visualeditor-switched'

View file

@ -79,3 +79,33 @@ mw.editcheck.getContentRanges = function ( documentModel, range ) {
} );
return ranges;
};
if ( mw.config.get( 'wgVisualEditorConfig' ).editCheckTagging ) {
mw.hook( 've.activationComplete' ).add( function () {
var target = ve.init.target;
function getRefNodes() {
// The firstNodes list is a numerically indexed array of reference nodes in the document.
// The list is append only, and removed references are set to undefined in place.
// To check if a new reference is being published, we just need to know if a reference
// with an index beyond the initial list (initLength) is still set.
var internalList = target.getSurface().getModel().getDocument().getInternalList();
var group = internalList.getNodeGroup( 'mwReference/' );
return group ? group.firstNodes || [] : [];
}
var initLength = getRefNodes().length;
target.saveFields.vetags = function () {
var refNodes = getRefNodes();
var newLength = refNodes.length;
var newNodesInDoc = false;
for ( var i = initLength; i < newLength; i++ ) {
if ( refNodes[ i ] ) {
newNodesInDoc = true;
break;
}
}
return newNodesInDoc ? 'editcheck-newreference' : '';
};
} );
}