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.
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.
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
21 namespace MediaWiki\Specials
;
23 use MediaWiki\Html\Html
;
24 use MediaWiki\HTMLForm\HTMLForm
;
25 use MediaWiki\MainConfigNames
;
26 use MediaWiki\SpecialPage\FormSpecialPage
;
27 use MediaWiki\SpecialPage\SpecialPage
;
30 * Let users reset tokens like the watchlist token.
32 * @ingroup SpecialPage
34 * @deprecated since 1.26
36 class SpecialResetTokens
extends FormSpecialPage
{
37 /** @var array|null */
40 public function __construct() {
41 parent
::__construct( 'ResetTokens' );
44 public function doesWrites() {
48 public function requiresUnblock() {
53 * Returns the token information list for this page after running
54 * the hook and filtering out disabled preferences.
58 protected function getTokensList() {
59 if ( !$this->tokensList
) {
61 [ 'preference' => 'watchlisttoken', 'label-message' => 'resettokens-watchlist-token' ],
63 $this->getHookRunner()->onSpecialResetTokensTokens( $tokens );
65 $hiddenPrefs = $this->getConfig()->get( MainConfigNames
::HiddenPrefs
);
66 $tokens = array_filter( $tokens, static function ( $tok ) use ( $hiddenPrefs ) {
67 return !in_array( $tok['preference'], $hiddenPrefs );
70 $this->tokensList
= $tokens;
73 return $this->tokensList
;
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();
81 parent
::execute( $par );
83 $this->getOutput()->addReturnTo( SpecialPage
::getTitleFor( 'Preferences' ) );
86 public function onSuccess() {
87 $this->getOutput()->wrapWikiMsg(
88 Html
::successBox( '$1' ),
94 * Display appropriate message if there's nothing to do.
95 * The submit button is also suppressed in this case (see alterForm()).
98 protected function getFormFields() {
99 $user = $this->getUser();
100 $tokens = $this->getTokensList();
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'] ) )
109 $tokensForForm[$label] = $tok['preference'];
113 'label-message' => 'resettokens-tokens',
114 'type' => 'multiselect',
115 'options' => $tokensForForm,
119 'label-message' => 'resettokens-no-tokens',
130 * Suppress the submit button if there's nothing to do;
131 * provide additional message on it otherwise.
133 protected function alterForm( HTMLForm
$form ) {
134 $form->setSubmitDestructive();
135 if ( $this->getTokensList() ) {
136 $form->setSubmitTextMsg( 'resettokens-resetbutton' );
138 $form->suppressDefaultSubmit();
142 protected function getDisplayFormat() {
146 public function onSubmit( array $formData ) {
147 if ( $formData['tokens'] ) {
148 $user = $this->getUser();
149 foreach ( $formData['tokens'] as $tokenPref ) {
150 $user->resetTokenFromOption( $tokenPref );
152 $user->saveSettings();
160 protected function getGroupName() {
164 public function isListed() {
165 return (bool)$this->getTokensList();
170 * Retain the old class name for backwards compatibility.
171 * @deprecated since 1.41
173 class_alias( SpecialResetTokens
::class, 'SpecialResetTokens' );