X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialRedirect.php;h=82d8b73b1f51d59672179883f509c02950295347;hb=70e2881cec98b89edc5afebfae55650782937e67;hp=1b2bda9a93484690454c908906dd0b304429b26c;hpb=58f810a0dceb346b127fd0030be3922e05d8fdee;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialRedirect.php b/includes/specials/SpecialRedirect.php index 1b2bda9a93..82d8b73b1f 100644 --- a/includes/specials/SpecialRedirect.php +++ b/includes/specials/SpecialRedirect.php @@ -21,6 +21,8 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; + /** * A special page that redirects to: the user for a numeric user id, * the file for a given filename, or the page for a given revision id. @@ -61,8 +63,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; } /** @@ -81,9 +83,16 @@ class SpecialRedirect extends FormSpecialPage { // Message: redirect-not-exists return Status::newFatal( $this->getMessagePrefix() . '-not-exists' ); } + if ( $user->isHidden() && !MediaWikiServices::getInstance()->getPermissionManager() + ->userHasRight( $this->getUser(), 'hideuser' ) + ) { + throw new PermissionsError( null, [ 'badaccess-group0' ] ); + } $userpage = Title::makeTitle( NS_USER, $username ); - return Status::newGood( $userpage->getFullURL( '', false, PROTO_CURRENT ) ); + return Status::newGood( [ + $userpage->getFullURL( '', false, PROTO_CURRENT ), 302 + ] ); } /** @@ -101,7 +110,7 @@ class SpecialRedirect extends FormSpecialPage { } catch ( MalformedTitleException $e ) { return Status::newFatal( $e->getMessageObject() ); } - $file = wfFindFile( $title ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title ); if ( !$file || !$file->exists() ) { // Message: redirect-not-exists @@ -119,7 +128,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 +235,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; }