Merge "Remove not used private member variable mParserWarnings from OutputPage"
[mediawiki.git] / includes / specials / SpecialResetTokens.php
blobcba5a449303c604c40636737d9a47f26858f6e14
1 <?php
2 /**
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
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * Let users reset tokens like the watchlist token.
27 * @ingroup SpecialPage
28 * @deprecated 1.26
30 class SpecialResetTokens extends FormSpecialPage {
31 private $tokensList;
33 public function __construct() {
34 parent::__construct( 'ResetTokens' );
37 /**
38 * Returns the token information list for this page after running
39 * the hook and filtering out disabled preferences.
41 * @return array
43 protected function getTokensList() {
44 if ( !isset( $this->tokensList ) ) {
45 $tokens = array(
46 array( 'preference' => 'watchlisttoken', 'label-message' => 'resettokens-watchlist-token' ),
48 Hooks::run( 'SpecialResetTokensTokens', array( &$tokens ) );
50 $hiddenPrefs = $this->getConfig()->get( 'HiddenPrefs' );
51 $tokens = array_filter( $tokens, function ( $tok ) use ( $hiddenPrefs ) {
52 return !in_array( $tok['preference'], $hiddenPrefs );
53 } );
55 $this->tokensList = $tokens;
58 return $this->tokensList;
61 public function execute( $par ) {
62 // This is a preferences page, so no user JS for y'all.
63 $this->getOutput()->disallowUserJs();
64 $this->requireLogin();
66 parent::execute( $par );
68 $this->getOutput()->addReturnTo( SpecialPage::getTitleFor( 'Preferences' ) );
71 public function onSuccess() {
72 $this->getOutput()->wrapWikiMsg(
73 "<div class='successbox'>\n$1\n</div>",
74 'resettokens-done'
78 /**
79 * Display appropriate message if there's nothing to do.
80 * The submit button is also suppressed in this case (see alterForm()).
81 * @return array
83 protected function getFormFields() {
84 $user = $this->getUser();
85 $tokens = $this->getTokensList();
87 if ( $tokens ) {
88 $tokensForForm = array();
89 foreach ( $tokens as $tok ) {
90 $label = $this->msg( 'resettokens-token-label' )
91 ->rawParams( $this->msg( $tok['label-message'] )->parse() )
92 ->params( $user->getTokenFromOption( $tok['preference'] ) )
93 ->escaped();
94 $tokensForForm[$label] = $tok['preference'];
97 $desc = array(
98 'label-message' => 'resettokens-tokens',
99 'type' => 'multiselect',
100 'options' => $tokensForForm,
102 } else {
103 $desc = array(
104 'label-message' => 'resettokens-no-tokens',
105 'type' => 'info',
109 return array(
110 'tokens' => $desc,
115 * Suppress the submit button if there's nothing to do;
116 * provide additional message on it otherwise.
117 * @param HTMLForm $form
119 protected function alterForm( HTMLForm $form ) {
120 if ( $this->getTokensList() ) {
121 $form->setSubmitTextMsg( 'resettokens-resetbutton' );
122 } else {
123 $form->suppressDefaultSubmit();
127 protected function getDisplayFormat() {
128 return 'ooui';
131 public function onSubmit( array $formData ) {
132 if ( $formData['tokens'] ) {
133 $user = $this->getUser();
134 foreach ( $formData['tokens'] as $tokenPref ) {
135 $user->resetTokenFromOption( $tokenPref );
137 $user->saveSettings();
139 return true;
142 return false;
145 protected function getGroupName() {
146 return 'users';
149 public function isListed() {
150 return (bool)$this->getTokensList();