Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 59 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
SpecialResetTokens | |
0.00% |
0 / 58 |
|
0.00% |
0 / 12 |
342 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
doesWrites | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
requiresUnblock | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTokensList | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
execute | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
onSuccess | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getFormFields | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
12 | |||
alterForm | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getDisplayFormat | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onSubmit | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isListed | |
0.00% |
0 / 1 |
|
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\Specials; |
22 | |
23 | use MediaWiki\Html\Html; |
24 | use MediaWiki\HTMLForm\HTMLForm; |
25 | use MediaWiki\MainConfigNames; |
26 | use MediaWiki\SpecialPage\FormSpecialPage; |
27 | use MediaWiki\SpecialPage\SpecialPage; |
28 | |
29 | /** |
30 | * Let users reset tokens like the watchlist token. |
31 | * |
32 | * @ingroup SpecialPage |
33 | * @ingroup Auth |
34 | * @deprecated since 1.26 |
35 | */ |
36 | class SpecialResetTokens extends FormSpecialPage { |
37 | /** @var array|null */ |
38 | private $tokensList; |
39 | |
40 | public function __construct() { |
41 | parent::__construct( 'ResetTokens' ); |
42 | } |
43 | |
44 | public function doesWrites() { |
45 | return true; |
46 | } |
47 | |
48 | public function requiresUnblock() { |
49 | return false; |
50 | } |
51 | |
52 | /** |
53 | * Returns the token information list for this page after running |
54 | * the hook and filtering out disabled preferences. |
55 | * |
56 | * @return array |
57 | */ |
58 | protected function getTokensList() { |
59 | if ( !isset( $this->tokensList ) ) { |
60 | $tokens = [ |
61 | [ 'preference' => 'watchlisttoken', 'label-message' => 'resettokens-watchlist-token' ], |
62 | ]; |
63 | $this->getHookRunner()->onSpecialResetTokensTokens( $tokens ); |
64 | |
65 | $hiddenPrefs = $this->getConfig()->get( MainConfigNames::HiddenPrefs ); |
66 | $tokens = array_filter( $tokens, static function ( $tok ) use ( $hiddenPrefs ) { |
67 | return !in_array( $tok['preference'], $hiddenPrefs ); |
68 | } ); |
69 | |
70 | $this->tokensList = $tokens; |
71 | } |
72 | |
73 | return $this->tokensList; |
74 | } |
75 | |
76 | public function execute( $par ) { |
77 | // This is a preferences page, so no user JS for y'all. |
78 | $this->getOutput()->disallowUserJs(); |
79 | $this->requireNamedUser(); |
80 | |
81 | parent::execute( $par ); |
82 | |
83 | $this->getOutput()->addReturnTo( SpecialPage::getTitleFor( 'Preferences' ) ); |
84 | } |
85 | |
86 | public function onSuccess() { |
87 | $this->getOutput()->wrapWikiMsg( |
88 | Html::successBox( '$1' ), |
89 | 'resettokens-done' |
90 | ); |
91 | } |
92 | |
93 | /** |
94 | * Display appropriate message if there's nothing to do. |
95 | * The submit button is also suppressed in this case (see alterForm()). |
96 | * @return array |
97 | */ |
98 | protected function getFormFields() { |
99 | $user = $this->getUser(); |
100 | $tokens = $this->getTokensList(); |
101 | |
102 | if ( $tokens ) { |
103 | $tokensForForm = []; |
104 | foreach ( $tokens as $tok ) { |
105 | $label = $this->msg( 'resettokens-token-label' ) |
106 | ->rawParams( $this->msg( $tok['label-message'] )->parse() ) |
107 | ->params( $user->getTokenFromOption( $tok['preference'] ) ) |
108 | ->escaped(); |
109 | $tokensForForm[$label] = $tok['preference']; |
110 | } |
111 | |
112 | $desc = [ |
113 | 'label-message' => 'resettokens-tokens', |
114 | 'type' => 'multiselect', |
115 | 'options' => $tokensForForm, |
116 | ]; |
117 | } else { |
118 | $desc = [ |
119 | 'label-message' => 'resettokens-no-tokens', |
120 | 'type' => 'info', |
121 | ]; |
122 | } |
123 | |
124 | return [ |
125 | 'tokens' => $desc, |
126 | ]; |
127 | } |
128 | |
129 | /** |
130 | * Suppress the submit button if there's nothing to do; |
131 | * provide additional message on it otherwise. |
132 | * @param HTMLForm $form |
133 | */ |
134 | protected function alterForm( HTMLForm $form ) { |
135 | $form->setSubmitDestructive(); |
136 | if ( $this->getTokensList() ) { |
137 | $form->setSubmitTextMsg( 'resettokens-resetbutton' ); |
138 | } else { |
139 | $form->suppressDefaultSubmit(); |
140 | } |
141 | } |
142 | |
143 | protected function getDisplayFormat() { |
144 | return 'ooui'; |
145 | } |
146 | |
147 | public function onSubmit( array $formData ) { |
148 | if ( $formData['tokens'] ) { |
149 | $user = $this->getUser(); |
150 | foreach ( $formData['tokens'] as $tokenPref ) { |
151 | $user->resetTokenFromOption( $tokenPref ); |
152 | } |
153 | $user->saveSettings(); |
154 | |
155 | return true; |
156 | } |
157 | |
158 | return false; |
159 | } |
160 | |
161 | protected function getGroupName() { |
162 | return 'login'; |
163 | } |
164 | |
165 | public function isListed() { |
166 | return (bool)$this->getTokensList(); |
167 | } |
168 | } |
169 | |
170 | /** |
171 | * Retain the old class name for backwards compatibility. |
172 | * @deprecated since 1.41 |
173 | */ |
174 | class_alias( SpecialResetTokens::class, 'SpecialResetTokens' ); |