3 * Implements Special:ResetTokens
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.
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.
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
21 * @ingroup SpecialPage
25 * Let users reset tokens like the watchlist token.
27 * @ingroup SpecialPage
28 * @deprecated since 1.26
30 class SpecialResetTokens
extends FormSpecialPage
{
33 public function __construct() {
34 parent
::__construct( 'ResetTokens' );
37 public function doesWrites() {
42 * Returns the token information list for this page after running
43 * the hook and filtering out disabled preferences.
47 protected function getTokensList() {
48 if ( !isset( $this->tokensList
) ) {
50 [ 'preference' => 'watchlisttoken', 'label-message' => 'resettokens-watchlist-token' ],
52 Hooks
::run( 'SpecialResetTokensTokens', [ &$tokens ] );
54 $hiddenPrefs = $this->getConfig()->get( 'HiddenPrefs' );
55 $tokens = array_filter( $tokens, function ( $tok ) use ( $hiddenPrefs ) {
56 return !in_array( $tok['preference'], $hiddenPrefs );
59 $this->tokensList
= $tokens;
62 return $this->tokensList
;
65 public function execute( $par ) {
66 // This is a preferences page, so no user JS for y'all.
67 $this->getOutput()->disallowUserJs();
68 $this->requireLogin();
70 parent
::execute( $par );
72 $this->getOutput()->addReturnTo( SpecialPage
::getTitleFor( 'Preferences' ) );
75 public function onSuccess() {
76 $this->getOutput()->wrapWikiMsg(
77 Html
::successBox( '$1' ),
83 * Display appropriate message if there's nothing to do.
84 * The submit button is also suppressed in this case (see alterForm()).
87 protected function getFormFields() {
88 $user = $this->getUser();
89 $tokens = $this->getTokensList();
93 foreach ( $tokens as $tok ) {
94 $label = $this->msg( 'resettokens-token-label' )
95 ->rawParams( $this->msg( $tok['label-message'] )->parse() )
96 ->params( $user->getTokenFromOption( $tok['preference'] ) )
98 $tokensForForm[$label] = $tok['preference'];
102 'label-message' => 'resettokens-tokens',
103 'type' => 'multiselect',
104 'options' => $tokensForForm,
108 'label-message' => 'resettokens-no-tokens',
119 * Suppress the submit button if there's nothing to do;
120 * provide additional message on it otherwise.
121 * @param HTMLForm $form
123 protected function alterForm( HTMLForm
$form ) {
124 $form->setSubmitDestructive();
125 if ( $this->getTokensList() ) {
126 $form->setSubmitTextMsg( 'resettokens-resetbutton' );
128 $form->suppressDefaultSubmit();
132 protected function getDisplayFormat() {
136 public function onSubmit( array $formData ) {
137 if ( $formData['tokens'] ) {
138 $user = $this->getUser();
139 foreach ( $formData['tokens'] as $tokenPref ) {
140 $user->resetTokenFromOption( $tokenPref );
142 $user->saveSettings();
150 protected function getGroupName() {
154 public function isListed() {
155 return (bool)$this->getTokensList();