jenkins-bot has submitted this change and it was merged.

Change subject: Make sure the 301 redirect from Special:UrlRedirector is cached
......................................................................


Make sure the 301 redirect from Special:UrlRedirector is cached

Change-Id: Ib6a47be12116b293732947a93ed8c17370fdc69c
---
M ApiShortenUrl.php
M SpecialUrlRedirector.php
M UrlShortener.utils.php
3 files changed, 14 insertions(+), 4 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/ApiShortenUrl.php b/ApiShortenUrl.php
index cc6031a..56a4ed1 100644
--- a/ApiShortenUrl.php
+++ b/ApiShortenUrl.php
@@ -27,7 +27,7 @@
 
                // You get the cached response, YOU get the cached response, 
EVERYONE gets the cached response.
                $this->getMain()->setCacheMode( "public" );
-               $this->getMain()->setCacheMaxAge( 30 * 24 * 60 * 60 );
+               $this->getMain()->setCacheMaxAge( UrlShortenerUtils::CACHE_TIME 
);
 
                $this->getResult()->addValue( null, $this->getModuleName(),
                        array( 'shorturl' => $shortUrl )
diff --git a/SpecialUrlRedirector.php b/SpecialUrlRedirector.php
index 7715255..f52c2c4 100644
--- a/SpecialUrlRedirector.php
+++ b/SpecialUrlRedirector.php
@@ -7,17 +7,19 @@
        }
 
        public function execute( $par ) {
+               $out = $this->getOutput();
                if ( $par === null ) {
                        // Send them to the form
-                       $this->getOutput()->redirect( SpecialPage::getTitleFor( 
'UrlShortener' )->getFullURL() );
+                       $out->redirect( SpecialPage::getTitleFor( 
'UrlShortener' )->getFullURL() );
                        return;
                }
                $url = UrlShortenerUtils::getURL( $par, PROTO_CURRENT );
                if ( $url !== false ) {
-                       $this->getOutput()->redirect( $url, '301' );
+                       $out->setSquidMaxage( UrlShortenerUtils::CACHE_TIME );
+                       $out->redirect( $url, '301' );
                } else {
                        // Invalid $par
-                       $this->getOutput()->showErrorPage( 
'urlshortener-not-found-title', 'urlshortener-not-found-message' );
+                       $out->showErrorPage( 'urlshortener-not-found-title', 
'urlshortener-not-found-message' );
                }
        }
 }
diff --git a/UrlShortener.utils.php b/UrlShortener.utils.php
index 72ad2df..d8ab8b6 100755
--- a/UrlShortener.utils.php
+++ b/UrlShortener.utils.php
@@ -14,6 +14,14 @@
 }
 
 class UrlShortenerUtils {
+
+       /**
+        * How long to cache things in Squid (one month)
+        *
+        * @var int
+        */
+       const CACHE_TIME = 2592000;
+
        static $decodeMap;
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/247992
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib6a47be12116b293732947a93ed8c17370fdc69c
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/UrlShortener
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to