MediaWiki  1.34.0
RedirectSpecialPage.php
Go to the documentation of this file.
1 <?php
29 abstract class RedirectSpecialPage extends UnlistedSpecialPage {
30  // Query parameters that can be passed through redirects
31  protected $mAllowedRedirectParams = [];
32 
33  // Query parameters added by redirects
34  protected $mAddedRedirectParams = [];
35 
39  public function execute( $subpage ) {
40  $redirect = $this->getRedirect( $subpage );
41  $query = $this->getRedirectQuery( $subpage );
42 
43  if ( $redirect instanceof Title ) {
44  // Redirect to a page title with possible query parameters
45  $url = $redirect->getFullUrlForRedirect( $query );
46  $this->getOutput()->redirect( $url );
47  } elseif ( $redirect === true ) {
48  // Redirect to index.php with query parameters
49  $url = wfAppendQuery( wfScript( 'index' ), $query );
50  $this->getOutput()->redirect( $url );
51  } else {
52  $this->showNoRedirectPage();
53  }
54  }
55 
63  abstract public function getRedirect( $subpage );
64 
72  public function getRedirectQuery( $subpage ) {
73  $params = [];
74  $request = $this->getRequest();
75 
76  foreach ( array_merge( $this->mAllowedRedirectParams,
77  [ 'uselang', 'useskin', 'debug', 'safemode' ] // parameters which can be passed to all pages
78  ) as $arg ) {
79  if ( $request->getVal( $arg, null ) !== null ) {
80  $params[$arg] = $request->getVal( $arg );
81  } elseif ( $request->getArray( $arg, null ) !== null ) {
82  $params[$arg] = $request->getArray( $arg );
83  }
84  }
85 
86  foreach ( $this->mAddedRedirectParams as $arg => $val ) {
87  $params[$arg] = $val;
88  }
89 
90  return count( $params )
91  ? $params
92  : false;
93  }
94 
103  public function personallyIdentifiableTarget() {
104  return false;
105  }
106 
107  protected function showNoRedirectPage() {
108  $class = static::class;
109  throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
110  }
111 }
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:719
UnlistedSpecialPage
Shortcut to construct a special page which is unlisted by default.
Definition: UnlistedSpecialPage.php:29
RedirectSpecialPage\$mAddedRedirectParams
$mAddedRedirectParams
Definition: RedirectSpecialPage.php:34
RedirectSpecialPage
Shortcut to construct a special page alias.
Definition: RedirectSpecialPage.php:29
RedirectSpecialPage\showNoRedirectPage
showNoRedirectPage()
Definition: RedirectSpecialPage.php:107
wfAppendQuery
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Definition: GlobalFunctions.php:439
RedirectSpecialPage\$mAllowedRedirectParams
$mAllowedRedirectParams
Definition: RedirectSpecialPage.php:31
MWException
MediaWiki exception.
Definition: MWException.php:26
RedirectSpecialPage\getRedirectQuery
getRedirectQuery( $subpage)
Return part of the request string for a special redirect page This allows passing,...
Definition: RedirectSpecialPage.php:72
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2642
RedirectSpecialPage\execute
execute( $subpage)
Definition: RedirectSpecialPage.php:39
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:709
Title
Represents a title within MediaWiki.
Definition: Title.php:42
RedirectSpecialPage\personallyIdentifiableTarget
personallyIdentifiableTarget()
Indicate if the target of this redirect can be used to identify a particular user of this wiki (e....
Definition: RedirectSpecialPage.php:103
RedirectSpecialPage\getRedirect
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.