thumb.php: support an optional "px" width suffix
authorFaidon Liambotis <faidon@wikimedia.org>
Sun, 11 May 2014 14:57:54 +0000 (16:57 +0200)
committerFaidon Liambotis <faidon@wikimedia.org>
Sun, 11 May 2014 14:58:14 +0000 (16:58 +0200)
A large percentage (40-50%) of the 500s that are emitted in production
are for a single URL,
https://commons.wikimedia.org/w/thumb.php?f=Crystal_Clear_action_viewmag.png&width=21px

The reason this fails is because thumb.php expects width to be "21", not
"21px", and it currently tries to fetch (and generate) the "21pxpx"
thumb size, which is obviously an invalid size. (an invalid size
shouldn't result in a 5xx but rather to a 4xx. though; that's a separate
bug that needs to be fixed).

This URL is embedded by a gadget, Gadget-searchbox-js, that is copied in
a lot of our wikis, including a big one, frwiki. mwgrep reveals that
there are a bunch of other URLs in various Gadgets that have width
values with "px" in them, so this presumably worked at some point in the
past.

While we could in theory fix all those URLs in these dozens of gadgets
across wikis to not suffix width with "px", this sounds like a herculean
effort and we're probably better off adding this compatibility branch to
thumb.php that strips the "px" suffix, if existent.

Change-Id: I3a00c9634b1c6af49fb8503cc3ff4cafdaff6b43

thumb.php

index 59bf8dc..d7bf453 100644 (file)
--- a/thumb.php
+++ b/thumb.php
@@ -116,6 +116,10 @@ function wfStreamThumb( array $params ) {
                $params['width'] = $params['w'];
                unset( $params['w'] );
        }
+       if ( isset( $params['width'] ) && substr( $params['width'], -2 ) == 'px' ) {
+               // strip the px (pixel) suffix, if found
+               $params['width'] = substr( $width, 0, strlen( $width ) - 2 );
+       }
        if ( isset( $params['p'] ) ) {
                $params['page'] = $params['p'];
        }