MediaWiki REL1_31
RedirectSpecialPage.php
Go to the documentation of this file.
1<?php
30 // Query parameters that can be passed through redirects
32
33 // Query parameters added by redirects
34 protected $mAddedRedirectParams = [];
35
40 public function execute( $subpage ) {
41 $redirect = $this->getRedirect( $subpage );
42 $query = $this->getRedirectQuery();
43 // Redirect to a page title with possible query parameters
44 if ( $redirect instanceof Title ) {
45 $url = $redirect->getFullUrlForRedirect( $query );
46 $this->getOutput()->redirect( $url );
47
48 return $redirect;
49 } elseif ( $redirect === true ) {
50 // Redirect to index.php with query parameters
51 $url = wfAppendQuery( wfScript( 'index' ), $query );
52 $this->getOutput()->redirect( $url );
53
54 return $redirect;
55 } else {
56 $this->showNoRedirectPage();
57 }
58 }
59
67 abstract public function getRedirect( $subpage );
68
75 public function getRedirectQuery() {
76 $params = [];
77 $request = $this->getRequest();
78
79 foreach ( array_merge( $this->mAllowedRedirectParams,
80 [ 'uselang', 'useskin', 'debug' ] // parameters which can be passed to all pages
81 ) as $arg ) {
82 if ( $request->getVal( $arg, null ) !== null ) {
83 $params[$arg] = $request->getVal( $arg );
84 } elseif ( $request->getArray( $arg, null ) !== null ) {
85 $params[$arg] = $request->getArray( $arg );
86 }
87 }
88
89 foreach ( $this->mAddedRedirectParams as $arg => $val ) {
90 $params[$arg] = $val;
91 }
92
93 return count( $params )
94 ? $params
95 : false;
96 }
97
107 return false;
108 }
109
110 protected function showNoRedirectPage() {
111 $class = static::class;
112 throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
113 }
114}
115
121 protected $redirName;
122
124 protected $redirSubpage;
125
126 function __construct(
127 $name, $redirName, $redirSubpage = false,
128 $allowedRedirectParams = [], $addedRedirectParams = []
129 ) {
130 parent::__construct( $name );
131 $this->redirName = $redirName;
132 $this->redirSubpage = $redirSubpage;
133 $this->mAllowedRedirectParams = $allowedRedirectParams;
134 $this->mAddedRedirectParams = $addedRedirectParams;
135 }
136
141 public function getRedirect( $subpage ) {
142 if ( $this->redirSubpage === false ) {
143 return SpecialPage::getTitleFor( $this->redirName, $subpage );
144 }
145
146 return SpecialPage::getTitleFor( $this->redirName, $this->redirSubpage );
147 }
148}
149
214 function __construct( $name ) {
215 parent::__construct( $name );
216 $redirectParams = [
217 'action',
218 'redirect', 'rdfrom',
219 # Options for preloaded edits
220 'preload', 'preloadparams', 'editintro', 'preloadtitle', 'summary', 'nosummary',
221 # Options for overriding user settings
222 'preview', 'minor', 'watchthis',
223 # Options for history/diffs
224 'section', 'oldid', 'diff', 'dir',
225 'limit', 'offset', 'feed',
226 # Misc options
227 'redlink',
228 # Options for action=raw; missing ctype can break JS or CSS in some browsers
229 'ctype', 'maxage', 'smaxage',
230 ];
231
232 Hooks::run( "RedirectSpecialArticleRedirectParams", [ &$redirectParams ] );
233 $this->mAllowedRedirectParams = $redirectParams;
234 }
235}
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 path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
MediaWiki exception.
Superclass for any RedirectSpecialPage which redirects the user to a particular article (as opposed t...
Shortcut to construct a special page alias.
getRedirectQuery()
Return part of the request string for a special redirect page This allows passing,...
personallyIdentifiableTarget()
Indicate if the target of this redirect can be used to identify a particular user of this wiki (e....
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.
getOutput()
Get the OutputPage being used for this instance.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
getRequest()
Get the WebRequest being used for this instance.
string $redirName
Name of redirect target.
__construct( $name, $redirName, $redirSubpage=false, $allowedRedirectParams=[], $addedRedirectParams=[])
string $redirSubpage
Name of subpage of redirect target.
Represents a title within MediaWiki.
Definition Title.php:39
Shortcut to construct a special page which is unlisted by default.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2806
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition hooks.txt:1620
$params