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