MediaWiki  master
SpecialGoToInterwiki.php
Go to the documentation of this file.
1 <?php
48  public function __construct() {
49  parent::__construct( 'GoToInterwiki' );
50  }
51 
52  public function execute( $par ) {
53  $par ??= '';
54 
55  // Allow forcing an interstitial for local interwikis. This is used
56  // when a redirect page is reached via a special page which resolves
57  // to a user-dependent value (as defined by
58  // RedirectSpecialPage::personallyIdentifiableTarget). See the hack
59  // for avoiding T109724 in MediaWiki::performRequest (which also
60  // explains why we can't use a query parameter instead).
61  $force = str_starts_with( $par, 'force/' );
62  if ( $force ) {
63  $par = substr( $par, 6 );
64  }
65 
66  $this->setHeaders();
67  $target = Title::newFromText( $par );
68  // Disallow special pages as a precaution against
69  // possible redirect loops.
70  if ( !$target || $target->isSpecialPage() ) {
71  $this->getOutput()->setStatusCode( 404 );
72  $this->getOutput()->addWikiMsg( 'gotointerwiki-invalid' );
73  return;
74  }
75 
76  $url = $target->getFullURL();
77  if ( !$target->isExternal() || ( $target->isLocal() && !$force ) ) {
78  // Either a normal page, or a local interwiki.
79  // Just redirect.
80  $this->getOutput()->redirect( $url, '301' );
81  } else {
82  $this->getOutput()->addWikiMsg(
83  'gotointerwiki-external',
84  $url,
85  $target->getFullText()
86  );
87  }
88  }
89 
93  public function requiresWrite() {
94  return false;
95  }
96 
100  protected function getGroupName() {
101  return 'redirects';
102  }
103 }
Landing page for non-local interwiki links.
execute( $par)
Default execute method Checks user permissions.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:373
Shortcut to construct a special page which is unlisted by default.