Page MenuHomePhabricator

Wikibase returns relative URLs from various API modules
Open, Needs TriagePublic

Description

As a tool developer, I want to include HTML from various API modules in my tool in order to provide output consistent with Wikidata, without having to post-process it.

Problem:
Wikibase returns entity links with relative URLs (e. g. /wiki/Q1, /wiki/Property:P1) from several API modules: at least wbformatvalue and compare. Those links don’t point to the correct location when used on other domains.

Example:

Acceptance criteria:

  • The Wikibase API can return full URLs.

Open questions:

  • The Wikibase editing UI also uses at least wbformatvalue, and there the relative URLs work. Do we want to keep it this way by default?

Event Timeline

The Wikibase editing UI also uses at least wbformatvalue, and there the relative URLs work. Do we want to keep it this way by default?

  • We could make the module return absolute URLs by default, with an option to return relative URLs. Problem: all Wikibase editing UI requests now have to include this parameter, bloating the requests a bit. (Otherwise, the response will be slightly bloated instead.)
  • We could make the module return relative URLs by default, with an option to return absolute URLs. Problem: all external developers will need to know about this option. (But at least it’s fully backwards compatible, even though the compatible behavior might not be desirable?)
  • We could make the module return relative URLs if the HTTP referrer matches the current wiki, otherwise absolute URLs. Problem: very magical, and also external developers will still see relative URLs on the API sandbox.

By the way, this bit in MediaWiki core’s Title class looks like it solves a similar problem:

/**
 * Get a URL with no fragment or server name (relative URL) from a Title object.
 * If this page is generated with action=render, however,
 * $wgServer is prepended to make an absolute URL.
 * …
 */
public function getLocalURL( $query = '', $query2 = false ) {
	global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
	# …
	// @todo FIXME: This causes breakage in various places when we
	// actually expected a local URL and end up with dupe prefixes.
	if ( $wgRequest->getVal( 'action' ) == 'render' ) {
		$url = $wgServer . $url;
	}
	# …
}

The first version of this seems to date back to 2005 (5af5e209b5)

I like the second solution most.. I can also think of allowing to pass a param like uri_relative that gets either relative or absolute as values. Then have the default value (when no param) in configuration, it is not much different from the second, but makes it easier for other instances to have a different default as well as us switching it if absolute as default proves to be better. (too much impl details I guess)

Harej subscribed.

During triage we have determined that this task is out of scope for our team, but this does generally sound like a good idea.