MediaWiki master
SpecialGoToInterwiki.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
25
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
95 public function requiresWrite() {
96 return false;
97 }
98
102 protected function getGroupName() {
103 return 'redirects';
104 }
105}
106
108class_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:79