Page MenuHomePhabricator

Allow customization of target of VisualEditor mediawiki API requests
Closed, ResolvedPublic8 Estimated Story Points

Description

VisualEditor uses the mw.Api() in many internal classes to use mediawiki api. These api requests goes to the current wiki and satisfies the need of VisualEditor. But ContentTranslation, an extension that use VE need to use mediawiki api of more than one wiki based on source and target language of translation. The local wiki may not be the target or source wiki.

To customize the VisualEditor classes to meet this requirement, subclassing and overrding the methods that does the API request can be done, but eventually, it might be lot of customization just for the API end point change.

In https://gerrit.wikimedia.org/r/c/429712/ such a customization was done, but @Esanders suggested that VE should have a better way to override the api in one place.

I think we need a more generic approach for localising APIs & link renderers, otherwise you're going to end up sub-classing most of our tools.
Ideally anywhere in VE we call new mw.Api() for a reading site data, we should replace that with a call to a target getter, which is passed the documentModel to identify the required language, like we did ve.init.mw.Target.prototype.parseWikitextFragment but more generic.
We will want a similar method for rendering links too, that will fix things like the media context linking to the wrong wiki. They probably mostly use mw.util.getUrl, so that should be replaced by a target method (getUrl again?), which CX can override to use their sitemapper.

Basically, we need a method that takes the language as parameter and returns mw.Api or mw.ForeignApi. A CX Override may look like this.

/**
  * Get the MediaWiki API for the given language	
 * @param {string} language	
 * @return {mw.ForeignApi} api	
 */	
ve.init.mw.CXTarget.prototype.getMwApi = function ( language ) {
	return this.siteMapper.getApi( language );
};

Event Timeline

Change 430906 had a related patch set uploaded (by Esanders; owner: Esanders):
[mediawiki/extensions/VisualEditor@master] Create getters for localised APIs (getContentApi/getLocalApi)

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

This first patch addresses most calls to mw.Api in VE. Still to fix are the ApiCache objects (linkCache/imageCache), and the MediaSearch widget in mw core.

Change 431086 had a related patch set uploaded (by Esanders; owner: Esanders):
[mediawiki/extensions/ContentTranslation@master] Replace #parseWikitextFragment with #getContentApi and #getPageName

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

Jdforrester-WMF set the point value for this task to 8.

Change 430906 merged by jenkins-bot:
[mediawiki/extensions/VisualEditor@master] Create getters for localised APIs (getContentApi/getLocalApi)

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

Change 431086 merged by jenkins-bot:
[mediawiki/extensions/ContentTranslation@master] Replace #parseWikitextFragment with #getContentApi and #getPageName

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

Deskana triaged this task as Medium priority.
Vvjjkkii renamed this task from Allow customization of target of VisualEditor mediawiki API requests to fmdaaaaaaa.Jul 1 2018, 1:11 AM
Vvjjkkii reopened this task as Open.
Vvjjkkii removed Esanders as the assignee of this task.
Vvjjkkii raised the priority of this task from Medium to High.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed the point value for this task.
Vvjjkkii removed subscribers: gerritbot, Aklapper.
CommunityTechBot renamed this task from fmdaaaaaaa to Allow customization of target of VisualEditor mediawiki API requests.Jul 2 2018, 4:10 PM
CommunityTechBot closed this task as Resolved.
CommunityTechBot assigned this task to Esanders.
CommunityTechBot lowered the priority of this task from High to Medium.
CommunityTechBot set the point value for this task to 8.
CommunityTechBot updated the task description. (Show Details)
CommunityTechBot added subscribers: gerritbot, Aklapper.