MediaWiki  1.23.0
SpecialResetTokens.php
Go to the documentation of this file.
1 <?php
30  private $tokensList;
31 
32  public function __construct() {
33  parent::__construct( 'ResetTokens' );
34  }
35 
42  protected function getTokensList() {
43  global $wgHiddenPrefs;
44 
45  if ( !isset( $this->tokensList ) ) {
46  $tokens = array(
47  array( 'preference' => 'watchlisttoken', 'label-message' => 'resettokens-watchlist-token' ),
48  );
49  wfRunHooks( 'SpecialResetTokensTokens', array( &$tokens ) );
50 
51  $tokens = array_filter( $tokens, function ( $tok ) use ( $wgHiddenPrefs ) {
52  return !in_array( $tok['preference'], $wgHiddenPrefs );
53  } );
54 
55  $this->tokensList = $tokens;
56  }
57 
58  return $this->tokensList;
59  }
60 
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();
65 
67 
68  $this->getOutput()->addReturnTo( SpecialPage::getTitleFor( 'Preferences' ) );
69  }
70 
71  public function onSuccess() {
72  $this->getOutput()->wrapWikiMsg(
73  "<div class='successbox'>\n$1\n</div>",
74  'resettokens-done'
75  );
76  }
77 
82  protected function getFormFields() {
83  $user = $this->getUser();
84  $tokens = $this->getTokensList();
85 
86  if ( $tokens ) {
87  $tokensForForm = array();
88  foreach ( $tokens as $tok ) {
89  $label = $this->msg( 'resettokens-token-label' )
90  ->rawParams( $this->msg( $tok['label-message'] )->parse() )
91  ->params( $user->getTokenFromOption( $tok['preference'] ) )
92  ->escaped();
93  $tokensForForm[$label] = $tok['preference'];
94  }
95 
96  $desc = array(
97  'label-message' => 'resettokens-tokens',
98  'type' => 'multiselect',
99  'options' => $tokensForForm,
100  );
101  } else {
102  $desc = array(
103  'label-message' => 'resettokens-no-tokens',
104  'type' => 'info',
105  );
106  }
107 
108  return array(
109  'tokens' => $desc,
110  );
111  }
112 
117  protected function alterForm( HTMLForm $form ) {
118  if ( $this->getTokensList() ) {
119  $form->setSubmitTextMsg( 'resettokens-resetbutton' );
120  } else {
121  $form->suppressDefaultSubmit();
122  }
123  }
124 
125  public function onSubmit( array $formData ) {
126  if ( $formData['tokens'] ) {
127  $user = $this->getUser();
128  foreach ( $formData['tokens'] as $tokenPref ) {
129  $user->resetTokenFromOption( $tokenPref );
130  }
131  $user->saveSettings();
132 
133  return true;
134  }
135 
136  return false;
137  }
138 
139  protected function getGroupName() {
140  return 'users';
141  }
142 
143  public function isListed() {
144  return (bool)$this->getTokensList();
145  }
146 }
SpecialResetTokens\__construct
__construct()
Definition: SpecialResetTokens.php:32
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
SpecialResetTokens\getTokensList
getTokensList()
Returns the token information list for this page after running the hook and filtering out disabled pr...
Definition: SpecialResetTokens.php:42
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:535
$form
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead $form
Definition: hooks.txt:2573
SpecialResetTokens\$tokensList
$tokensList
Definition: SpecialResetTokens.php:30
FormSpecialPage
Special page which uses an HTMLForm to handle processing.
Definition: FormSpecialPage.php:31
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:74
SpecialPage\requireLogin
requireLogin( $reasonMsg=null, $titleMsg=null)
If the user is not logged in, throws UserNotLoggedIn error.
Definition: SpecialPage.php:321
SpecialResetTokens\getFormFields
getFormFields()
Display appropriate message if there's nothing to do.
Definition: SpecialResetTokens.php:82
SpecialResetTokens\execute
execute( $par)
Basic SpecialPage workflow: get a form, send it to the user; get some data back,.
Definition: SpecialResetTokens.php:61
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4001
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:545
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
execute
$batch execute()
SpecialPage\msg
msg()
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:609
SpecialResetTokens\onSuccess
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
Definition: SpecialResetTokens.php:71
FormSpecialPage\$par
string $par
The sub-page of the special page.
Definition: FormSpecialPage.php:35
SpecialResetTokens\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialResetTokens.php:139
SpecialResetTokens\alterForm
alterForm(HTMLForm $form)
Suppress the submit button if there's nothing to do; provide additional message on it otherwise.
Definition: SpecialResetTokens.php:117
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
SpecialResetTokens\isListed
isListed()
Whether this special page is listed in Special:SpecialPages.
Definition: SpecialResetTokens.php:143
HTMLForm\setSubmitTextMsg
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:976
SpecialResetTokens
Let users reset tokens like the watchlist token.
Definition: SpecialResetTokens.php:29
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
SpecialResetTokens\onSubmit
onSubmit(array $formData)
Process the form on POST submission.
Definition: SpecialResetTokens.php:125
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:100