Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
SpecialUrlRedirector | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\UrlShortener; |
4 | |
5 | use MediaWiki\SpecialPage\SpecialPage; |
6 | use MediaWiki\SpecialPage\UnlistedSpecialPage; |
7 | |
8 | class SpecialUrlRedirector extends UnlistedSpecialPage { |
9 | |
10 | public function __construct() { |
11 | parent::__construct( 'UrlRedirector' ); |
12 | } |
13 | |
14 | /** |
15 | * @inheritDoc |
16 | */ |
17 | public function execute( $par ) { |
18 | $out = $this->getOutput(); |
19 | if ( $par === null ) { |
20 | // Send them to the form |
21 | $out->redirect( SpecialPage::getTitleFor( 'UrlShortener' )->getFullURL() ); |
22 | return; |
23 | } |
24 | |
25 | // Redirect destinations are public information |
26 | // Allow redirects to be resolved across domains (T358049). |
27 | $this->getRequest()->response()->header( 'Access-Control-Allow-Origin: *' ); |
28 | |
29 | $url = UrlShortenerUtils::getURL( $par, PROTO_CURRENT ); |
30 | if ( $url !== false ) { |
31 | $out->setCdnMaxage( UrlShortenerUtils::CACHE_TTL_VALID ); |
32 | $out->redirect( $url, '301' ); |
33 | } else { |
34 | // Invalid $par |
35 | // This page is being served from the short domain, so we can't use |
36 | // any of the MediaWiki interface because all relative URLs will be wrong. |
37 | // And force English because we likely don't know the proper interface lang :( |
38 | $title = $this->msg( 'urlshortener-not-found-title' )->inLanguage( 'en' )->text(); |
39 | $text = $this->msg( 'urlshortener-not-found-message' )->inLanguage( 'en' )->text(); |
40 | $out->setCdnMaxage( UrlShortenerUtils::CACHE_TTL_INVALID ); |
41 | // wfHttpError does escaping |
42 | wfHttpError( 404, $title, $text ); |
43 | } |
44 | } |
45 | } |