MediaWiki REL1_39
RedirectSpecialPage.php
Go to the documentation of this file.
1<?php
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', 'variant', '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
109 return false;
110 }
111
115 protected function showNoRedirectPage() {
116 $class = static::class;
117 throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
118 }
119}
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.
Shortcut to construct a special page alias.
array $mAddedRedirectParams
Query parameters added by redirects.
getRedirectQuery( $subpage)
Return part of the request string for a special redirect page This allows passing,...
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....
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.
getRequest()
Get the WebRequest being used for this instance.
Represents a title within MediaWiki.
Definition Title.php:49
Shortcut to construct a special page which is unlisted by default.