From 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Dec 2013 09:55:49 +0100 Subject: Update to MediaWiki 1.22.0 --- includes/specials/SpecialResetTokens.php | 145 +++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 includes/specials/SpecialResetTokens.php (limited to 'includes/specials/SpecialResetTokens.php') diff --git a/includes/specials/SpecialResetTokens.php b/includes/specials/SpecialResetTokens.php new file mode 100644 index 00000000..ef2a45da --- /dev/null +++ b/includes/specials/SpecialResetTokens.php @@ -0,0 +1,145 @@ +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(); + } +} -- cgit v1.2.3-54-g00ecf