Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
RedirectSpecialPage | |
0.00% |
0 / 26 |
|
0.00% |
0 / 4 |
132 | |
0.00% |
0 / 1 |
execute | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
getRedirect | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getRedirectQuery | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
42 | |||
personallyIdentifiableTarget | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
showNoRedirectPage | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\SpecialPage; |
22 | |
23 | use LogicException; |
24 | use MediaWiki\Title\Title; |
25 | |
26 | /** |
27 | * Shortcut to construct a special page alias. |
28 | * |
29 | * @stable to extend |
30 | * |
31 | * @ingroup SpecialPage |
32 | */ |
33 | abstract class RedirectSpecialPage extends UnlistedSpecialPage { |
34 | /** @var array Query parameters that can be passed through redirects */ |
35 | protected $mAllowedRedirectParams = []; |
36 | |
37 | /** @var array Query parameters added by redirects */ |
38 | protected $mAddedRedirectParams = []; |
39 | |
40 | /** |
41 | * @stable to override |
42 | * @param string|null $subpage |
43 | */ |
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 | |
61 | /** |
62 | * If the special page is a redirect, then get the Title object it redirects to. |
63 | * False otherwise. |
64 | * |
65 | * @param string|null $subpage |
66 | * @return Title|bool |
67 | */ |
68 | abstract public function getRedirect( $subpage ); |
69 | |
70 | /** |
71 | * Return part of the request string for a special redirect page |
72 | * This allows passing, e.g. action=history to Special:Mypage, etc. |
73 | * |
74 | * @stable to override |
75 | * @param string|null $subpage |
76 | * @return array|false |
77 | */ |
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 | |
101 | /** |
102 | * Indicate if the target of this redirect can be used to identify |
103 | * a particular user of this wiki (e.g., if the redirect is to the |
104 | * user page of a User). See T109724. |
105 | * |
106 | * @stable to override |
107 | * @since 1.27 |
108 | * @return bool |
109 | */ |
110 | public function personallyIdentifiableTarget() { |
111 | return false; |
112 | } |
113 | |
114 | /** |
115 | * @stable to override |
116 | */ |
117 | protected function showNoRedirectPage() { |
118 | $class = static::class; |
119 | throw new LogicException( "RedirectSpecialPage $class doesn't redirect!" ); |
120 | } |
121 | } |
122 | |
123 | /** @deprecated class alias since 1.41 */ |
124 | class_alias( RedirectSpecialPage::class, 'RedirectSpecialPage' ); |