tokensList ) ) { $tokens = array( array( 'preference' => 'watchlisttoken', 'label-message' => 'resettokens-watchlist-token' ), ); wfRunHooks( 'SpecialResetTokensTokens', array( &$tokens ) ); $tokens = array_filter( $tokens, function ( $tok ) use ( $wgHiddenPrefs ) { return !in_array( $tok['preference'], $wgHiddenPrefs ); } ); $this->tokensList = $tokens; } return $this->tokensList; } public function execute( $par ) { // This is a preferences page, so no user JS for y'all. $this->getOutput()->disallowUserJs(); parent::execute( $par ); $this->getOutput()->addReturnTo( SpecialPage::getTitleFor( 'Preferences' ) ); } public function onSuccess() { $this->getOutput()->wrapWikiMsg( "
\n$1\n
", 'resettokens-done' ); } /** * Display appropriate message if there's nothing to do. * The submit button is also suppressed in this case (see alterForm()). */ protected function getFormFields() { $user = $this->getUser(); $tokens = $this->getTokensList(); if ( $tokens ) { $tokensForForm = array(); foreach ( $tokens as $tok ) { $label = $this->msg( 'resettokens-token-label' ) ->rawParams( $this->msg( $tok['label-message'] )->parse() ) ->params( $user->getTokenFromOption( $tok['preference'] ) ) ->escaped(); $tokensForForm[ $label ] = $tok['preference']; } $desc = array( 'label-message' => 'resettokens-tokens', 'type' => 'multiselect', 'options' => $tokensForForm, ); } else { $desc = array( 'label-message' => 'resettokens-no-tokens', 'type' => 'info', ); } return array( 'tokens' => $desc, ); } /** * Suppress the submit button if there's nothing to do; * provide additional message on it otherwise. */ protected function alterForm( HTMLForm $form ) { if ( $this->getTokensList() ) { $form->setSubmitTextMsg( 'resettokens-resetbutton' ); } else { $form->suppressDefaultSubmit(); } } public function onSubmit( array $formData ) { if ( $formData['tokens'] ) { $user = $this->getUser(); foreach ( $formData['tokens'] as $tokenPref ) { $user->resetTokenFromOption( $tokenPref ); } $user->saveSettings(); return true; } return false; } protected function getGroupName() { return 'users'; } public function isListed() { return (bool)$this->getTokensList(); } }