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