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 | * Shortcuts to construct a special page alias. |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * http://www.gnu.org/copyleft/gpl.html |
19 | * |
20 | * @file |
21 | * @ingroup SpecialPage |
22 | */ |
23 | |
24 | namespace MediaWiki\SpecialPage; |
25 | |
26 | use LogicException; |
27 | use MediaWiki\Title\Title; |
28 | |
29 | /** |
30 | * Shortcut to construct a special page alias. |
31 | * |
32 | * @stable to extend |
33 | * |
34 | * @ingroup SpecialPage |
35 | */ |
36 | abstract class RedirectSpecialPage extends UnlistedSpecialPage { |
37 | /** @var array Query parameters that can be passed through redirects */ |
38 | protected $mAllowedRedirectParams = []; |
39 | |
40 | /** @var array Query parameters added by redirects */ |
41 | protected $mAddedRedirectParams = []; |
42 | |
43 | /** |
44 | * @stable to override |
45 | * @param string|null $subpage |
46 | */ |
47 | public function execute( $subpage ) { |
48 | $redirect = $this->getRedirect( $subpage ); |
49 | $query = $this->getRedirectQuery( $subpage ); |
50 | |
51 | if ( $redirect instanceof Title ) { |
52 | // Redirect to a page title with possible query parameters |
53 | $url = $redirect->getFullUrlForRedirect( $query ); |
54 | $this->getOutput()->redirect( $url ); |
55 | } elseif ( $redirect === true ) { |
56 | // Redirect to index.php with query parameters |
57 | $url = wfAppendQuery( wfScript( 'index' ), $query ); |
58 | $this->getOutput()->redirect( $url ); |
59 | } else { |
60 | $this->showNoRedirectPage(); |
61 | } |
62 | } |
63 | |
64 | /** |
65 | * If the special page is a redirect, then get the Title object it redirects to. |
66 | * False otherwise. |
67 | * |
68 | * @param string|null $subpage |
69 | * @return Title|bool |
70 | */ |
71 | abstract public function getRedirect( $subpage ); |
72 | |
73 | /** |
74 | * Return part of the request string for a special redirect page |
75 | * This allows passing, e.g. action=history to Special:Mypage, etc. |
76 | * |
77 | * @stable to override |
78 | * @param string|null $subpage |
79 | * @return array|false |
80 | */ |
81 | public function getRedirectQuery( $subpage ) { |
82 | $params = []; |
83 | $request = $this->getRequest(); |
84 | |
85 | foreach ( array_merge( $this->mAllowedRedirectParams, |
86 | [ 'uselang', 'useskin', 'variant', 'debug', 'safemode' ] // parameters which can be passed to all pages |
87 | ) as $arg ) { |
88 | if ( $request->getVal( $arg, null ) !== null ) { |
89 | $params[$arg] = $request->getVal( $arg ); |
90 | } elseif ( $request->getArray( $arg, null ) !== null ) { |
91 | $params[$arg] = $request->getArray( $arg ); |
92 | } |
93 | } |
94 | |
95 | foreach ( $this->mAddedRedirectParams as $arg => $val ) { |
96 | $params[$arg] = $val; |
97 | } |
98 | |
99 | return count( $params ) |
100 | ? $params |
101 | : false; |
102 | } |
103 | |
104 | /** |
105 | * Indicate if the target of this redirect can be used to identify |
106 | * a particular user of this wiki (e.g., if the redirect is to the |
107 | * user page of a User). See T109724. |
108 | * |
109 | * @stable to override |
110 | * @since 1.27 |
111 | * @return bool |
112 | */ |
113 | public function personallyIdentifiableTarget() { |
114 | return false; |
115 | } |
116 | |
117 | /** |
118 | * @stable to override |
119 | */ |
120 | protected function showNoRedirectPage() { |
121 | $class = static::class; |
122 | throw new LogicException( "RedirectSpecialPage $class doesn't redirect!" ); |
123 | } |
124 | } |
125 | |
126 | /** @deprecated class alias since 1.41 */ |
127 | class_alias( RedirectSpecialPage::class, 'RedirectSpecialPage' ); |