MediaWiki master
RedirectSpecialPage.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\SpecialPage;
22
23use LogicException;
25
36
38 protected $mAddedRedirectParams = [];
39
44 public function execute( $subpage ) {
45 $redirect = $this->getRedirect( $subpage );
46 $query = $this->getRedirectQuery( $subpage );
47
48 if ( $redirect instanceof Title ) {
49 // Redirect to a page title with possible query parameters
50 $url = $redirect->getFullUrlForRedirect( $query );
51 $this->getOutput()->redirect( $url );
52 } elseif ( $redirect === true ) {
53 // Redirect to index.php with query parameters
54 $url = wfAppendQuery( wfScript( 'index' ), $query );
55 $this->getOutput()->redirect( $url );
56 } else {
57 $this->showNoRedirectPage();
58 }
59 }
60
68 abstract public function getRedirect( $subpage );
69
78 public function getRedirectQuery( $subpage ) {
79 $params = [];
80 $request = $this->getRequest();
81
82 foreach ( array_merge( $this->mAllowedRedirectParams,
83 [ 'uselang', 'useskin', 'variant', 'debug', 'safemode' ] // parameters which can be passed to all pages
84 ) as $arg ) {
85 if ( $request->getVal( $arg, null ) !== null ) {
86 $params[$arg] = $request->getVal( $arg );
87 } elseif ( $request->getArray( $arg, null ) !== null ) {
88 $params[$arg] = $request->getArray( $arg );
89 }
90 }
91
92 foreach ( $this->mAddedRedirectParams as $arg => $val ) {
93 $params[$arg] = $val;
94 }
95
96 return count( $params )
97 ? $params
98 : false;
99 }
100
111 return false;
112 }
113
117 protected function showNoRedirectPage() {
118 $class = static::class;
119 throw new LogicException( "RedirectSpecialPage $class doesn't redirect!" );
120 }
121}
122
124class_alias( RedirectSpecialPage::class, 'RedirectSpecialPage' );
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
wfScript( $script='index')
Get the URL path to a MediaWiki entry point.
array $params
The job parameters.
Shortcut to construct a special page alias.
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.
array $mAllowedRedirectParams
Query parameters that can be passed through redirects.
personallyIdentifiableTarget()
Indicate if the target of this redirect can be used to identify a particular user of this wiki (e....
getRedirectQuery( $subpage)
Return part of the request string for a special redirect page This allows passing,...
array $mAddedRedirectParams
Query parameters added by redirects.
getRequest()
Get the WebRequest being used for this instance.
getOutput()
Get the OutputPage being used for this instance.
Shortcut to construct a special page which is unlisted by default.
Represents a title within MediaWiki.
Definition Title.php:78