Page MenuHomePhabricator

Make URL normalisation/shortening a core MediaWiki interface
Open, Needs TriagePublic

Description

Problem statement

There are various use cases in core and extensions not directly related to URL-shortening. Cases where one want to show urls to users that should take advantage of URL shortening. There should be a core service to support this transformation, where you can pass in an URL (or maybe a Title object and an array of query parameters) and get back another URL which resolves to the same address but if possible is shorter.

Proposal

The default behavior in MediaWiki core could be to just return the URL unchanged, or maybe to use curid instead of title page name (that changes the semantics though as page name and page id are not inseparably linked together).

The non-default behavior could be implemented by an extension like UrlShortener.

One complication is that shortening a URL that wasn't shortened before requires a DB write, which should be avoided on GET requests.
Another is that it should work with cross-DB titles (as the main use case is Commons file description pages).

See also:

  • File::getDescriptionShortUrl()

Event Timeline

Tgr created this task.Jun 26 2016, 1:47 PM
Restricted Application added subscribers: Zppix, Aklapper. · View Herald TranscriptJun 26 2016, 1:47 PM
Legoktm claimed this task.Jun 26 2016, 1:57 PM
Legoktm removed Legoktm as the assignee of this task.Aug 4 2016, 3:55 AM

Un-cookie licking for now, I might get back to this later at some point.

One thing I wasn't sure how to get around...UrlShortener generates short URLs on demand, and requires a db write to save them, which we can't do on GET requests, only POST ones. So the best workaround I can think of is to see if one is already in the db, but if not make an internal API request to generate a new short URL. But that also kind of sucks.

Tgr added a comment.Aug 4 2016, 4:39 AM

Have separate methods for getting and saving a short URL, I guess? And making it the caller's responsibility to invoke the saving method first, and doing so on a POST.

Jdlrobson added a subscriber: Jdlrobson.

Any ideas for how to do this @Legoktm? We've been brainstorming ways over in the phabricator ticket T172902 for the print mode and it would be good to get some input on how best to do this (the patch you just reviewed was a strawman proposal to show one way it might be done). I like the idea of something more generic but I'm not sure what that would look like.

Tgr renamed this task from MediaWiki should have a hook for short URLs to MediaWiki should have a service for short URLs.Sep 8 2017, 8:26 PM
Tgr updated the task description. (Show Details)
greg added a subscriber: greg.Nov 16 2017, 5:45 AM
Krinkle renamed this task from MediaWiki should have a service for short URLs to Make URL normalisation/shortening a core MediaWiki interface.Jan 26 2019, 7:17 AM
Krinkle added a project: TechCom.
Krinkle updated the task description. (Show Details)
Krinkle added a subscriber: Krinkle.

I believe this was originally proposed in context of T122439. Note that that has since been resolved. Is there still interest, use cases, and resourcing for this idea to be abstracted in core?

Tgr added a comment.EditedJan 26 2019, 6:48 PM

Curid is a poor replacement as discussed in T122439#1906099. Adding a core service does not need much resourcing; OTOH there is also not much point to it as long as nothing would override it. So this is effectively blocked on T108557: Review and deploy UrlShortener extension to Wikimedia wikis.

Tgr updated the task description. (Show Details)Jan 26 2019, 6:54 PM
greg removed a subscriber: greg.Jan 27 2019, 6:45 AM
mobrovac moved this task from Inbox to Backlog on the TechCom board.Feb 5 2019, 8:21 PM
MJL added a subscriber: MJL.Apr 7 2019, 9:22 PM