MediaWiki REL1_34
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
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
104 return false;
105 }
106
107 protected function showNoRedirectPage() {
108 $class = static::class;
109 throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
110 }
111}
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.
getRedirectQuery( $subpage)
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.
getRequest()
Get the WebRequest being used for this instance.
Represents a title within MediaWiki.
Definition Title.php:42
Shortcut to construct a special page which is unlisted by default.