Page MenuHomePhabricator

References no longer open with specific dialog in the translation
Closed, ResolvedPublic

Description

References are often structured using templates such as Cite web or Cite book. When users edit such references, a specific form for such templates is shown instead of the general reference one in Visul Editor.

This was supported in Content translation (T199512), but a regression seems to have happened. Testing the same example checked in T199512#5049505 you can observe that the generic dialog is shown now for references:

Sep-09-2019 14-13-23.gif (332×640 px, 2 MB)


Note that this ticket is specifically for references in the translation. The same issue for references on the source document is captured at T221241 and has some additional technical complications.

Event Timeline

Note that two cards are shown at the tools column, one for the reference and another for the specific kind of reference ("website" in the example below):

Screenshot 2019-12-12 at 13.07.20.png (254×1 px, 86 KB)

I spent some time today to understand how this works in VE and Cite extension.

  • Even if Cite extension is installed, the wiki should have MediaWiki:Visualeditor-cite-tool-definition.json‎(example) to actually get reference type specific reference context items(the cards in CX tools column, or popups in VE)
  • Cite extension creates custom context items for each of the cite tools in the MediaWiki:Visualeditor-cite-tool-definition.json using ve.ui.MWReference.init.js. Each of those ContextItems are sub classes of ve.ui.MWCitationContextItem which is a sub class of ve.ui.MWReferenceContextItem.
  • So a wiki with MediaWiki:Visualeditor-cite-tool-definition.json and Cite extension, every reference node will get one of "Web", "News", "Jounal", "Book" reference contextItems.
  • But CX also subclasses ve.ui.MWReferenceContextItem and creates ve.ui.CXReferenceContextItem which takes care of adaptation status of template between source-target language. This is shown as general Reference context item.
  • So A reference node gets both ContextItems. Clicking on "Web", "News", "Jounal", "Book" context items opens the Citation editor, while CX's context items first opens a template editor and then a reference editor

As per my understanding, to avoid multiple contextItems, and to properly customize references so that adaptations status can be rendered, ve.ui.CXReferenceContextItem should inherit the GeneratedMWCitationContextItem classes for each of "Web", "News", "Jounal", "Book" citations. But that is not straight forward as far as I can see.

@DLynch Is my understanding correct?

Any recommendations to customize the ContextItems for "Web", "News", "Jounal", "Book" etc?

(Please cc anybody else who maintain this part of code in VE. Thanks)

@santhosh That's all correct, yes.

As per my understanding, to avoid multiple contextItems, and to properly customize references so that adaptations status can be rendered, ve.ui.CXReferenceContextItem should inherit the GeneratedMWCitationContextItem classes for each of "Web", "News", "Jounal", "Book" citations. But that is not straight forward as far as I can see.

Any recommendations to customize the ContextItems for "Web", "News", "Jounal", "Book" etc?

I think you could subclass each of them in a loop, much like how Cite generates them in a loop. Something like this:

function addCxSubclass( parentContextItem ) {
	var contextItem = function CXGeneratedMWCitationContextItem() {
		/* ... */
		// Parent constructor
		parentContextItem.apply( this, arguments );
	};
	OO.inheritClass( contextItem, parentContextItem );

	// Override any methods here
	// (Or you could use OO.mixinClass())
	contextItem.prototype.getRendering = function () {
		/* ... */
		return contextItem.super.prototype.getRendering.apply( this, arguments );
	};

	ve.ui.contextItemFactory.register( contextItem );
}

// Note: Don't iterate directly with `for ( name in ve.ui.contextItemFactory.registry )`,
// because we're modifying that object in the loop body
var names = Object.keys( ve.ui.contextItemFactory.registry );
for ( var i = 0; i < names.length; i++ ) {
	var name = names[ i ];
	if ( name.slice( 0, 5 ) === 'cite-' ) {
		var parentContextItem = ve.ui.contextItemFactory.lookup( name );
		addCxSubclass( parentContextItem );
	}
}

Change 740780 had a related patch set uploaded (by Santhosh; author: Santhosh):

[mediawiki/extensions/ContentTranslation@master] Reference support: Customize Cite ContextIttem classes for references

https://gerrit.wikimedia.org/r/740780

Thanks @matmarex. That helped.

Screenshot after the fix:

image.png (862×1 px, 66 KB)

Change 740780 merged by jenkins-bot:

[mediawiki/extensions/ContentTranslation@master] Reference support: Customize Cite ContextItem classes for references

https://gerrit.wikimedia.org/r/740780

Nikerabbit subscribed.

I assume this is ready for QA (probably deployed already). Correct if wrong.

The cards are no longer duplicated. However, the card shows now as empty with no details of the reference until you open it:

Kapture 2022-01-21 at 11.26.03.gif (786×1 px, 3 MB)

@santhosh if you think this is an unrelated issue, feel free to create a separate ticket.

Pginer-WMF changed the task status from Open to In Progress.Jan 21 2022, 11:41 AM

Change 760901 had a related patch set uploaded (by Santhosh; author: Santhosh):

[mediawiki/extensions/ContentTranslation@master] CX: Avoid empty reference cards when clicked

https://gerrit.wikimedia.org/r/760901

Change 760901 merged by jenkins-bot:

[mediawiki/extensions/ContentTranslation@master] CX: Avoid empty reference cards when clicked

https://gerrit.wikimedia.org/r/760901

Can you clarify if you need anything from us (Editing)? The patches you wrote looked good to me, and it seems like they fix the issue.

Can you clarify if you need anything from us (Editing)? The patches you wrote looked good to me, and it seems like they fix the issue.

Thank you. Nothing else needed for this ticket. We need some help from Editng team with https://phabricator.wikimedia.org/T286788#7526054 though.

Re-run the test cases from https://phabricator.wikimedia.org/T199512#4629883

  • wmf.25: en:Victoria island translated to Catalan with Apertium.
Web site referenceEdit Website reference
Screen Shot 2022-03-11 at 12.19.20 PM.png (318×3 px, 235 KB)
Screen Shot 2022-03-11 at 12.21.12 PM.png (726×2 px, 157 KB)
Book referenceEdit Book reference
Screen Shot 2022-03-11 at 12.23.37 PM.png (336×2 px, 259 KB)
Screen Shot 2022-03-11 at 12.23.01 PM.png (566×3 px, 204 KB)
  • wmf.25: en:Silent Hill 2 translated to Catalan with Apertium.
Cite newsEdit Cite news referenceComments
Screen Shot 2022-03-11 at 11.58.14 AM.png (364×3 px, 252 KB)
(1) the reference is recognized as Cite news when a user hovers over it (2) Only two values (fields) of the original Cite news are displayed
Screen Shot 2022-03-11 at 12.08.15 PM.png (466×2 px, 71 KB)
The original Cite news reference:
Screen Shot 2022-03-11 at 11.58.54 AM.png (400×2 px, 281 KB)
Cite journalEdit Cite journal referenceComments
Screen Shot 2022-03-11 at 12.13.12 PM.png (402×2 px, 291 KB)
Screen Shot 2022-03-11 at 12.13.25 PM.png (704×2 px, 163 KB)
The original Cite journal reference
Screen Shot 2022-03-11 at 12.17.01 PM.png (584×1 px, 243 KB)

Question:

  • Cite news seems to be the only reference that presents an issue. Should it be addressed in a separate task?

News is not defined for Cite tool in Catalan wikipedia. It is defined in Spanish wikipedia though. So the behaviour of Cite News at Catalan wikipedia is expected.

News is not defined for Cite tool in Catalan wikipedia. It is defined in Spanish wikipedia though. So the behaviour of Cite News at Catalan wikipedia is expected.

Thanks, @santhosh! Re-checked Cite news on eswiki wmf.26 - works as expected:
Cite news ( translation en:Silent Hill 2 to Spanish)

Screen Shot 2022-03-16 at 12.15.02 PM.png (624×3 px, 395 KB)
Screen Shot 2022-03-16 at 12.15.14 PM.png (1×3 px, 387 KB)