Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
72.73% |
16 / 22 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
SpecialGoToInterwiki | |
76.19% |
16 / 21 |
|
25.00% |
1 / 4 |
11.35 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
83.33% |
15 / 18 |
|
0.00% |
0 / 1 |
7.23 | |||
requiresWrite | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\Specials; |
22 | |
23 | use MediaWiki\SpecialPage\UnlistedSpecialPage; |
24 | use MediaWiki\Title\Title; |
25 | |
26 | /** |
27 | * Landing page for non-local interwiki links. |
28 | * |
29 | * This exists for security and privacy reasons. |
30 | * |
31 | * The landing page warns people and obtains consent before leaving |
32 | * the site and visiting a third-party website. This can reduce |
33 | * impact of phishing tricks as well. |
34 | * |
35 | * This is meant to be used as the replacement URL when resolving |
36 | * an interwiki link things in a context where it would be |
37 | * navigated to without clear consent. For example, when doing |
38 | * a simple search (not "advanced") in which we would normally |
39 | * redirect to the first result if there is an exact match |
40 | * (e.g. Special:Search/google:foo). |
41 | * |
42 | * This is not needed for external interwiki links in content, |
43 | * e.g. [[google:foo]] in parser output may link directly. |
44 | * |
45 | * Further context at https://phabricator.wikimedia.org/T122209. |
46 | * |
47 | * @ingroup SpecialPage |
48 | */ |
49 | class SpecialGoToInterwiki extends UnlistedSpecialPage { |
50 | public function __construct() { |
51 | parent::__construct( 'GoToInterwiki' ); |
52 | } |
53 | |
54 | public function execute( $par ) { |
55 | $par ??= ''; |
56 | |
57 | // Allow forcing an interstitial for local interwikis. This is used |
58 | // when a redirect page is reached via a special page which resolves |
59 | // to a user-dependent value (as defined by |
60 | // RedirectSpecialPage::personallyIdentifiableTarget). See the hack |
61 | // for avoiding T109724 in MediaWiki::performRequest (which also |
62 | // explains why we can't use a query parameter instead). |
63 | $force = str_starts_with( $par, 'force/' ); |
64 | if ( $force ) { |
65 | $par = substr( $par, 6 ); |
66 | } |
67 | |
68 | $this->setHeaders(); |
69 | $target = Title::newFromText( $par ); |
70 | // Disallow special pages as a precaution against |
71 | // possible redirect loops. |
72 | if ( !$target || $target->isSpecialPage() ) { |
73 | $this->getOutput()->setStatusCode( 404 ); |
74 | $this->getOutput()->addWikiMsg( 'gotointerwiki-invalid' ); |
75 | return; |
76 | } |
77 | |
78 | $url = $target->getFullURL(); |
79 | if ( !$target->isExternal() || ( $target->isLocal() && !$force ) ) { |
80 | // Either a normal page, or a local interwiki. |
81 | // Just redirect. |
82 | $this->getOutput()->redirect( $url, '301' ); |
83 | } else { |
84 | $this->getOutput()->addWikiMsg( |
85 | 'gotointerwiki-external', |
86 | $url, |
87 | $target->getFullText() |
88 | ); |
89 | } |
90 | } |
91 | |
92 | /** |
93 | * @return bool |
94 | */ |
95 | public function requiresWrite() { |
96 | return false; |
97 | } |
98 | |
99 | /** |
100 | * @return string |
101 | */ |
102 | protected function getGroupName() { |
103 | return 'redirects'; |
104 | } |
105 | } |
106 | |
107 | /** @deprecated class alias since 1.41 */ |
108 | class_alias( SpecialGoToInterwiki::class, 'SpecialGoToInterwiki' ); |