MediaWiki  master
RedirectSpecialPage.php
Go to the documentation of this file.
1 <?php
31 abstract class RedirectSpecialPage extends UnlistedSpecialPage {
33  protected $mAllowedRedirectParams = [];
34 
36  protected $mAddedRedirectParams = [];
37 
42  public function execute( $subpage ) {
43  $redirect = $this->getRedirect( $subpage );
44  $query = $this->getRedirectQuery( $subpage );
45 
46  if ( $redirect instanceof Title ) {
47  // Redirect to a page title with possible query parameters
48  $url = $redirect->getFullUrlForRedirect( $query );
49  $this->getOutput()->redirect( $url );
50  } elseif ( $redirect === true ) {
51  // Redirect to index.php with query parameters
52  $url = wfAppendQuery( wfScript( 'index' ), $query );
53  $this->getOutput()->redirect( $url );
54  } else {
55  $this->showNoRedirectPage();
56  }
57  }
58 
66  abstract public function getRedirect( $subpage );
67 
76  public function getRedirectQuery( $subpage ) {
77  $params = [];
78  $request = $this->getRequest();
79 
80  foreach ( array_merge( $this->mAllowedRedirectParams,
81  [ 'uselang', 'useskin', 'debug', 'safemode' ] // parameters which can be passed to all pages
82  ) as $arg ) {
83  if ( $request->getVal( $arg, null ) !== null ) {
84  $params[$arg] = $request->getVal( $arg );
85  } elseif ( $request->getArray( $arg, null ) !== null ) {
86  $params[$arg] = $request->getArray( $arg );
87  }
88  }
89 
90  foreach ( $this->mAddedRedirectParams as $arg => $val ) {
91  $params[$arg] = $val;
92  }
93 
94  return count( $params )
95  ? $params
96  : false;
97  }
98 
108  public function personallyIdentifiableTarget() {
109  return false;
110  }
111 
115  protected function showNoRedirectPage() {
116  $class = static::class;
117  throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
118  }
119 }
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:747
UnlistedSpecialPage
Shortcut to construct a special page which is unlisted by default.
Definition: UnlistedSpecialPage.php:31
RedirectSpecialPage
Shortcut to construct a special page alias.
Definition: RedirectSpecialPage.php:31
RedirectSpecialPage\showNoRedirectPage
showNoRedirectPage()
Stable to override.
Definition: RedirectSpecialPage.php:115
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:438
MWException
MediaWiki exception.
Definition: MWException.php:29
RedirectSpecialPage\getRedirectQuery
getRedirectQuery( $subpage)
Return part of the request string for a special redirect page This allows passing,...
Definition: RedirectSpecialPage.php:76
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2526
RedirectSpecialPage\execute
execute( $subpage)
Stable to override.
Definition: RedirectSpecialPage.php:42
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:737
Title
Represents a title within MediaWiki.
Definition: Title.php:41
RedirectSpecialPage\$mAddedRedirectParams
array $mAddedRedirectParams
Query parameters added by redirects.
Definition: RedirectSpecialPage.php:36
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:108
RedirectSpecialPage\getRedirect
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.
RedirectSpecialPage\$mAllowedRedirectParams
array $mAllowedRedirectParams
Query parameters that can be passed through redirects.
Definition: RedirectSpecialPage.php:33