revert r110340 after talking with krinle
[lhc/web/wiklou.git] / thumb.php
index 758a05a..e5fcf3a 100644 (file)
--- a/thumb.php
+++ b/thumb.php
@@ -29,6 +29,8 @@ wfLogProfilingData();
 
 /**
  * Handle a thumbnail request via query parameters
+ *
+ * @return void
  */
 function wfThumbHandleRequest() {
        $params = get_magic_quotes_gpc()
@@ -40,14 +42,22 @@ function wfThumbHandleRequest() {
 
 /**
  * Handle a thumbnail request via thumbnail file URL
+ *
+ * @return void
  */
 function wfThumbHandle404() {
-       # lighttpd puts the original request in REQUEST_URI, while
-       # sjs sets that to the 404 handler, and puts the original
-       # request in REDIRECT_URL.
+       # lighttpd puts the original request in REQUEST_URI, while sjs sets
+       # that to the 404 handler, and puts the original request in REDIRECT_URL.
        if ( isset( $_SERVER['REDIRECT_URL'] ) ) {
-               # The URL is un-encoded, so put it back how it was.
+               # The URL is un-encoded, so put it back how it was
                $uri = str_replace( "%2F", "/", urlencode( $_SERVER['REDIRECT_URL'] ) );
+               # Just get the URI path (REDIRECT_URL is either a full URL or a path)
+               if ( $uri[0] !== '/' ) {
+                       $bits = wfParseUrl( $uri );
+                       if ( $bits && isset( $bits['path'] ) ) {
+                               $uri = $bits['path'];
+                       }
+               }
        } else {
                $uri = $_SERVER['REQUEST_URI'];
        }
@@ -65,6 +75,7 @@ function wfThumbHandle404() {
  * Stream a thumbnail specified by parameters
  *
  * @param $params Array
+ * @return void
  */
 function wfStreamThumb( array $params ) {
        wfProfileIn( __METHOD__ );
@@ -210,18 +221,28 @@ function wfStreamThumb( array $params ) {
  * Extract the required params for thumb.php from the thumbnail request URI.
  * At least 'width' and 'f' should be set if the result is an array.
  *
- * @param $uri String Thumbnail request URI
+ * @param $uri String Thumbnail request URI path
  * @return Array|null associative params array or null
  */
 function wfExtractThumbParams( $uri ) {
        $repo = RepoGroup::singleton()->getLocalRepo();
 
+       $zoneURI = $repo->getZoneUrl( 'thumb' );
+       if ( substr( $zoneURI, 0, 1 ) !== '/' ) {
+               $bits = wfParseUrl( $zoneURI );
+               if ( $bits && isset( $bits['path'] ) ) {
+                       $zoneURI = $bits['path'];
+               } else {
+                       return null;
+               }
+       }
+       $zoneUrlRegex = preg_quote( $zoneURI );
+
        $hashDirRegex = $subdirRegex = '';
        for ( $i = 0; $i < $repo->getHashLevels(); $i++ ) {
                $subdirRegex .= '[0-9a-f]';
                $hashDirRegex .= "$subdirRegex/";
        }
-       $zoneUrlRegex = preg_quote( $repo->getZoneUrl( 'thumb' ) );
 
        $thumbUrlRegex = "!^$zoneUrlRegex(/archive|/temp|)/$hashDirRegex([^/]*)/([^/]*)$!";
 
@@ -261,6 +282,7 @@ function wfExtractThumbParams( $uri ) {
  *
  * @param $status integer
  * @param $msg string
+ * @return void
  */
 function wfThumbError( $status, $msg ) {
        global $wgShowHostnames;