Page MenuHomePhabricator

External links should skip the scheme if it's the same as the site
Closed, InvalidPublic

Description

Each external or interwiki* link to a standard web site on a MediaWiki wiki has the scheme/protocol http: at the front of the href and link title. This is not necessary when the wiki is already at a http: URL.

Links like //www.example.com/ are perfectly valid and point to http://www.example.com/ in this context, just as a link to /wiki/Something is valid and unique on http://en.wikipedia.org/

If we remove the scheme from the emitted XHTML if identical to that of the site, ten bytes could be saved on each link. This would add up even if the site is gzipped; sadly, many - including Wikipedia's own front page; see bug 15944 - are not. On the current wikipedia.org it would save 1685 bytes, or 3%; if gzipped, it would save 59 bytes, or 0.4%. Still not bad for free!

It is not possible to specify a URL like [//example.com/ this] in the wikitext itself, either, but this is probably not a bad thing, as links should point to the same site when copied to another wiki.

  • It will be possible to specify interwiki links without schemes once bug 18664 is fixed, and it might be necessary to modify the same code when fixing this one.

Version: unspecified
Severity: enhancement

Details

Reference
bz18889

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 10:44 PM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz18889.
bzimport added a subscriber: Unknown Object (MLST).

I notice {{SERVER}} , {{fullurl:ZZZZZ}} don't make smarter links (href="/" and href="/wiki/ZZZZZ") either.

Too bad we can't fix most of bug 18274 at the same time.

I'm going to have to say no to this, as there's a possible plan afoot to improve our cache locality by using protocol-relative links for site-local links allowing us to use the same cached HTML entries for SSL and non-SSL access.

In this case, we wouldn't be able to guarantee that other links would be consistent and functional; the savings of a few characters per link is fairly small versus the liklihood of breakage.

Unless I'm misunderstanding you, the problem you applies only to sites accessible by more than one protocol, which is a rather small proportion of MediaWiki sites.

I can understand this being at a low priority (and not something you want to work on) if Wikipedia has to keep it turned off, but I don't think it makes the idea invalid. If I get time, I'll see about making a patch for it.

Patch won't be accepted as it has no functional purpose and would interfere with production use, but feel free to post it if you like.

Created attachment 6313
Hack to remove http: from links (not safe for other protocols, see comment)

Seeing as this is not likely to get in, I'll just throw out what we're using at wikifur.com. Potential reusers should bear in mind that makeExternalLink is called from several other places, and the result of suddenly giving these callers a protocol-less link is undefined and untested. You have been warned! :-)

I figure almost all sites using this will be using http:. A more general patch would support https: as well, perhaps by taking $wgServer and finding the position of the colon, then comparing that and the preceding string against $url.

For bonus marks, consider removing http: from your interwiki table entries as well to cut protocols from your language and Wikipedia: links (phpMyAdmin + SQL export with drop table option + find+replace 687474703a2f2f with 2f2f [or http:// with //] + SQL reimport, requires patches for bug 18664 and bug 19270)

Attached: