Merge "Add checkDependencies.php"
[lhc/web/wiklou.git] / includes / specials / SpecialRedirect.php
index 1b2bda9..49f1b3c 100644 (file)
@@ -61,8 +61,8 @@ class SpecialRedirect extends FormSpecialPage {
        function setParameter( $subpage ) {
                // parse $subpage to pull out the parts
                $parts = explode( '/', $subpage, 2 );
-               $this->mType = count( $parts ) > 0 ? $parts[0] : null;
-               $this->mValue = count( $parts ) > 1 ? $parts[1] : null;
+               $this->mType = $parts[0];
+               $this->mValue = $parts[1] ?? null;
        }
 
        /**
@@ -119,7 +119,9 @@ class SpecialRedirect extends FormSpecialPage {
                        // ... and we can
                        if ( $mto && !$mto->isError() ) {
                                // ... change the URL to point to a thumbnail.
-                               $url = $mto->getUrl();
+                               // Note: This url is more temporary as can change
+                               // if file is reuploaded and has different aspect ratio.
+                               $url = [ $mto->getUrl(), $height === -1 ? 301 : 302 ];
                        }
                }
 
@@ -224,7 +226,21 @@ class SpecialRedirect extends FormSpecialPage {
                                break;
                }
                if ( $status && $status->isGood() ) {
-                       $this->getOutput()->redirect( $status->getValue() );
+                       // These urls can sometimes be linked from prominent places,
+                       // so varnish cache.
+                       $value = $status->getValue();
+                       if ( is_array( $value ) ) {
+                               list( $url, $code ) = $value;
+                       } else {
+                               $url = $value;
+                               $code = 301;
+                       }
+                       if ( $code === 301 ) {
+                               $this->getOutput()->setCdnMaxage( 60 * 60 );
+                       } else {
+                               $this->getOutput()->setCdnMaxage( 10 );
+                       }
+                       $this->getOutput()->redirect( $url, $code );
 
                        return true;
                }