Page MenuHomePhabricator

Display short url version of links on desktop and PDF print styles
Closed, DeclinedPublic

Description

background

When printing an article, a URL is included in the footer (inside .printfooter) at the bottom of the page.

For printed content, URLs in multiple languages can get quite lengthy. If a user were to enter the url manually from printed content, it would take quite a bit of time.

acceptance criteria

  • Replace displayed URL for articles with short url

example:
For the article https://hi.wikipedia.org/wiki/%E0%A4%AD%E0%A5%82%E0%A4%B8%E0%A5%8D%E0%A4%A5%E0%A4%BF%E0%A4%B0_%E0%A4%89%E0%A4%AA%E0%A4%97%E0%A5%8D%E0%A4%B0%E0%A4%B9_%E0%A4%AA%E0%A5%8D%E0%A4%B0%E0%A4%95%E0%A5%8D%E0%A4%B7%E0%A5%87%E0%A4%AA%E0%A4%A3_%E0%A4%AF%E0%A4%BE%E0%A4%A8_%E0%A4%B8%E0%A4%82%E0%A4%B8%E0%A5%8D%E0%A4%95%E0%A4%B0%E0%A4%A3_3, display https://hi.wikipedia.org/s/anp3 versus https://hi.wikipedia.org/w/index.php?title=भू थर_उप ह_ ेपण_यान_स ं करण_3&oldid=3506997" से लया गया (current version in print styles)

Developer notes

  • The URL in question is generated by Skin::printSource
  • Short URLs are provided by extension Extension:ShortUrl
  • The ShortUrl extension will need to communicate with Skin::printSource and replace the URL before it is outputted

Strawman proposals

Using GetCanonicalURL hook

There already exists a GetCanonicalURL hook called inside Title::getCanonicalURL. This is used in various places and a short url is probably not best used in this way.

Rely on JavaScript

Will not work without JS.
It also relies on $wgShortUrlReadOnly being enabled - which adds an element #t-shorturl containing the URL to the page HTML

New Hook

  • We' add a hook to Skin::printSource e.g. Hook::run('getSkinPrintUrl')
  • The hook can only be run once. If the hook is used more than once, then it's a race condition - whoever uses it last wins
  • The hook when executed will return the value of the print url
  • ShortUrl will use this hook

Config variable

Example: https://gerrit.wikimedia.org/r/376581

  • We could also use a config variable that specifies the name of a static function that returns the title
  • The static function is passed the $title
  • ShortUrl can be configured to use this.

Other

..?

See also

T138719

Event Timeline

ovasileva triaged this task as Medium priority.Aug 9 2017, 3:33 PM
ovasileva added a subscriber: hindustanilanguage.
Jdlrobson subscribed.

I don't understand what this task means. https://hi.wikipedia.org/wiki/%E0%A4%AD%E0%A5%82%E0%A4%B8%E0%A5%8D%E0%A4%A5%E0%A4%BF%E0%A4%B0_%E0%A4%89%E0%A4%AA%E0%A4%97%E0%A5%8D%E0%A4%B0%E0%A4%B9_%E0%A4%AA%E0%A5%8D%E0%A4%B0%E0%A4%95%E0%A5%8D%E0%A4%B7%E0%A5%87%E0%A4%AA%E0%A4%A3_%E0%A4%AF%E0%A4%BE%E0%A4%A8_%E0%A4%B8%E0%A4%82%E0%A4%B8%E0%A5%8D%E0%A4%95%E0%A4%B0%E0%A4%A3_3 is the URL-safe encoded version of the title.

It sounds like you are asking to use tiny urls - but I'm not sure where these would appear and why. These will always be resolved/redirect to the real URL e.g. the one above.

EXAMPLE: Take this HiWiki article: https://hi.wikipedia.org/wiki/2014_शीतकालीन_ओलंपिक_में_नेपाल . If I want a PDF, I find a complex text at the bottom of the article similar to the depiction in this screenshot-pic:

598b4a6b501ca.png (31×745 px, 5 KB)
or something cited above by Ovasilova. What we want is instead of these two, short url display such as https://hi.wikipedia.org/s/bos9 making it easier for people to either click or type the link. This should be at the bottom of the PDF.

Got it! Thanks for the context and background @hindustanilanguage ! :)

Moving to needs analysis as there's still open questions on implementations

We estimated this and estimations ranged from 5 to ? and there was confusion about how this would work. @phuedx suggested a spike may be necessary to decide how to do this.

Open questions:

  • Should this be done for every URL on the page? If so, then are there any performance concerns?

Edit: This isn't what this task is talking about.

  • How do we replace the URL for a link in the print view of a page?

Edit: This is exactly what this task is asking.

Change 376581 had a related patch set uploaded (by Jdlrobson; owner: Jdlrobson):
[mediawiki/core@master] Allow extensions to override the print url

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

Jdlrobson moved this task from Needs Prioritization to Upcoming on the Web-Team-Backlog board.

^ the above patch implements one of the proposals. Would be good to talk about it vs other proposals in a future grooming session.

@ovasileva i thought we are stalling this as this is scope creep to print work

I played around with something similar for the concatenation patch (where the default print URL would point to a special page that's not intended to be exposed to users). Something like

    Hooks::register( 'SkinTemplateOutputPageBeforeExec', function ( SkinTemplate &$skinTemplate, QuickTemplate &$tpl ) {
        $url = htmlspecialchars( wfExpandIRI( $skin->getTitle()->getCanonicalURL( [ 'oldid' => $skin->getRevisionId() ?: null ] ) ) );
        $linkText = getShortUrlSomeHow();
	$footer = $skinTemplate->msg( 'retrievedfrom' )
            ->rawParams( '<a dir="ltr" href="' . $linkText . '">' . $url . '</a>' )
            ->parse();
        $tpl->set( 'printfooter', $footer );
    } );

works but it's rather ugly. The other option without core changes is to wrap the skin into a decorator class which replaces Skin::printSource() which is even more ugly.

Adding a new core setting just for the print footer link would be too much of a proliferation of options IMO. Maybe push footer links through LinkRenderer and add some kind of semantic role parameter to make* calls which gets passed to hooks?

@ovasileva i thought we are stalling this as this is scope creep to print work

@Nirzar See https://phabricator.wikimedia.org/T172902#3589643. The patch is just exploratory work to see how we might do this - a proof of concept. It has no chance of getting merged or going any further without us committing time.

Change 376581 abandoned by Jdlrobson:
Allow extensions to override the print url

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

ovasileva lowered the priority of this task from Medium to Low.Sep 19 2017, 4:51 PM
ovasileva moved this task from Upcoming to Triaged but Future on the Web-Team-Backlog board.
Krinkle closed this task as Declined.EditedJul 29 2020, 4:06 PM
Krinkle subscribed.

The ShortUrl extension is being sunset. It is deployed on a limited number of wikis but no additional ones are approved. It currently suffers significant performance and design issues. It will effectively be replaced by the UrlShortener project (https://w.wiki). However display of the url directly on articles is one of the main problems with the ShortUrl extension and is therefore not provided by UrlShortener.

It'll be up to the new product owner to decide what to do if a new request comes up, but I'm closing out this one for now.

Ref T187045.