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