Special case opus mime detction
[mediawiki.git] / includes / specials / SpecialResetTokens.php
blob3e896863b293d0d0df92328ebd0a0abd504622b0
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 since 1.26
30 class SpecialResetTokens extends FormSpecialPage {
31 private $tokensList;
33 public function __construct() {
34 parent::__construct( 'ResetTokens' );
37 public function doesWrites() {
38 return true;
41 /**
42 * Returns the token information list for this page after running
43 * the hook and filtering out disabled preferences.
45 * @return array
47 protected function getTokensList() {
48 if ( !isset( $this->tokensList ) ) {
49 $tokens = [
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 );
57 } );
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 "<div class='successbox'>\n$1\n</div>",
78 'resettokens-done'
82 /**
83 * Display appropriate message if there's nothing to do.
84 * The submit button is also suppressed in this case (see alterForm()).
85 * @return array
87 protected function getFormFields() {
88 $user = $this->getUser();
89 $tokens = $this->getTokensList();
91 if ( $tokens ) {
92 $tokensForForm = [];
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'] ) )
97 ->escaped();
98 $tokensForForm[$label] = $tok['preference'];
101 $desc = [
102 'label-message' => 'resettokens-tokens',
103 'type' => 'multiselect',
104 'options' => $tokensForForm,
106 } else {
107 $desc = [
108 'label-message' => 'resettokens-no-tokens',
109 'type' => 'info',
113 return [
114 'tokens' => $desc,
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 if ( $this->getTokensList() ) {
125 $form->setSubmitTextMsg( 'resettokens-resetbutton' );
126 } else {
127 $form->suppressDefaultSubmit();
131 protected function getDisplayFormat() {
132 return 'ooui';
135 public function onSubmit( array $formData ) {
136 if ( $formData['tokens'] ) {
137 $user = $this->getUser();
138 foreach ( $formData['tokens'] as $tokenPref ) {
139 $user->resetTokenFromOption( $tokenPref );
141 $user->saveSettings();
143 return true;
146 return false;
149 protected function getGroupName() {
150 return 'users';
153 public function isListed() {
154 return (bool)$this->getTokensList();