Page MenuHomePhabricator

QR code returns shorturl code instead of URL
Closed, ResolvedPublicBUG REPORT

Description

When Special:QrCode generates a QR code for a URL which is longer than $wgUrlShortenerQrCodeShortenLimit, and $wgUrlShortenerTemplate is set, the QR code just contains the integer ID of the short code, not the URL.

Originally reported at T242467#9490672:

@MusikAnimal I am not sure about some of the QR codes I have generated on beta. Sometimes instead of a full URL I get two characters. I assume these should be passed to https://w-beta.wmflabs.org, but even then they sometimes redirect to the wrong URL.

Downlading the QR code from https://en.wikipedia.beta.wmflabs.org/wiki/Topic:So5c1xwx7pse3oyg and decoding the SVG returns 42. https://w-beta.wmflabs.org/42 redirects to https://deployment.wikimedia.beta.wmflabs.org/w/index.php?title=Main_Page&action=history.

Other examples:

Python script I have used for decoding QR codes:

from cairosvg import svg2png
from qrtools import QR

svg2png(url="qrcode.svg", write_to="qrcode.png")
qrcode = QR(filename="qrcode.png")
if qrcode.decode():
    print(qrcode.data)

Event Timeline

Change 993719 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/UrlShortener@master] Use makeUrl() on short codes when generating QR codes

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

Change 993719 merged by jenkins-bot:

[mediawiki/extensions/UrlShortener@master] Use makeUrl() on short codes when generating QR codes

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

As a follow-up (sort of a mental note for myself), it would be great to refactor a bit of the code to avoid the confusion that caused this bug. Namely, the Status object that's being passed around contains the keys url and alt, when both are actually short codes, and not URLs.