Merge "Rename autonym for 'no' from 'norsk bokmål' to 'norsk'"
[lhc/web/wiklou.git] / includes / specials / SpecialGoToInterwiki.php
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
24 /**
25 * Landing page for non-local interwiki links.
26 *
27 * Meant to warn people that the site they're visiting
28 * is not the local wiki (In case of phishing tricks).
29 * Only meant to be used for things that directly
30 * redirect from url (e.g. Special:Search/google:foo )
31 * Not meant for general interwiki linking (e.g.
32 * [[google:foo]] should still directly link)
33 *
34 * @ingroup SpecialPage
35 */
36 class SpecialGoToInterwiki extends UnlistedSpecialPage {
37 public function __construct( $name = 'GoToInterwiki' ) {
38 parent::__construct( $name );
39 }
40
41 public function execute( $par ) {
42 $this->setHeaders();
43 $target = Title::newFromText( $par );
44 // Disallow special pages as a precaution against
45 // possible redirect loops.
46 if ( !$target || $target->isSpecialPage() ) {
47 $this->getOutput()->setStatusCode( 404 );
48 $this->getOutput()->addWikiMsg( 'gotointerwiki-invalid' );
49 return;
50 }
51
52 $url = $target->getFullURL();
53 if ( !$target->isExternal() || $target->isLocal() ) {
54 // Either a normal page, or a local interwiki.
55 // just redirect.
56 $this->getOutput()->redirect( $url, '301' );
57 } else {
58 $this->getOutput()->addWikiMsg(
59 'gotointerwiki-external',
60 $url,
61 $target->getFullText()
62 );
63 }
64 }
65
66 /**
67 * @return bool
68 */
69 public function requiresWrite() {
70 return false;
71 }
72
73 /**
74 * @return String
75 */
76 protected function getGroupName() {
77 return 'redirects';
78 }
79 }