MediaWiki master
RedirectSpecialPage.php
Go to the documentation of this file.
1<?php
8
9use LogicException;
11
22
24 protected $mAddedRedirectParams = [];
25
30 public function execute( $subpage ) {
31 $redirect = $this->getRedirect( $subpage );
32 $query = $this->getRedirectQuery( $subpage );
33
34 if ( $redirect instanceof Title ) {
35 // Redirect to a page title with possible query parameters
36 $url = $redirect->getFullUrlForRedirect( $query );
37 $this->getOutput()->redirect( $url );
38 } elseif ( $redirect === true ) {
39 // Redirect to index.php with query parameters
40 $url = wfAppendQuery( wfScript( 'index' ), $query );
41 $this->getOutput()->redirect( $url );
42 } else {
43 $this->showNoRedirectPage();
44 }
45 }
46
54 abstract public function getRedirect( $subpage );
55
64 public function getRedirectQuery( $subpage ) {
65 $params = [];
66 $request = $this->getRequest();
67
68 foreach ( array_merge(
69 $this->mAllowedRedirectParams,
70 // parameters which can be passed to all pages
71 [ 'uselang', 'useskin', 'useformat', 'variant', 'debug', 'safemode' ]
72 ) as $arg ) {
73 if ( $request->getVal( $arg ) !== null ) {
74 $params[$arg] = $request->getVal( $arg );
75 } elseif ( $request->getArray( $arg ) !== null ) {
76 $params[$arg] = $request->getArray( $arg );
77 }
78 }
79
80 foreach ( $this->mAddedRedirectParams as $arg => $val ) {
81 $params[$arg] = $val;
82 }
83
84 return count( $params )
85 ? $params
86 : false;
87 }
88
98 public function personallyIdentifiableTarget() {
99 return false;
100 }
101
105 protected function showNoRedirectPage() {
106 $class = static::class;
107 throw new LogicException( "RedirectSpecialPage $class doesn't redirect!" );
108 }
109}
110
112class_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.
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:69