MediaWiki REL1_41
SpecialGoToInterwiki.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Specials;
25
28
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
98 public function requiresWrite() {
99 return false;
100 }
101
105 protected function getGroupName() {
106 return 'redirects';
107 }
108}
109
113class_alias( SpecialGoToInterwiki::class, 'SpecialGoToInterwiki' );
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
Shortcut to construct a special page which is unlisted by default.
Landing page for non-local interwiki links.
execute( $par)
Default execute method Checks user permissions.
Represents a title within MediaWiki.
Definition Title.php:76
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...