MediaWiki  1.28.0
SpecialPreferences.php
Go to the documentation of this file.
1 <?php
30  function __construct() {
31  parent::__construct( 'Preferences' );
32  }
33 
34  public function doesWrites() {
35  return true;
36  }
37 
38  public function execute( $par ) {
39  $this->setHeaders();
40  $this->outputHeader();
41  $out = $this->getOutput();
42  $out->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
43 
44  $this->requireLogin( 'prefsnologintext2' );
45  $this->checkReadOnly();
46 
47  if ( $par == 'reset' ) {
48  $this->showResetForm();
49 
50  return;
51  }
52 
53  $out->addModules( 'mediawiki.special.preferences' );
54  $out->addModuleStyles( 'mediawiki.special.preferences.styles' );
55 
56  $session = $this->getRequest()->getSession();
57  if ( $session->get( 'specialPreferencesSaveSuccess' ) ) {
58  // Remove session data for the success message
59  $session->remove( 'specialPreferencesSaveSuccess' );
60  $out->addModuleStyles( 'mediawiki.notification.convertmessagebox.styles' );
61 
62  $out->addHTML(
64  'div',
65  [
66  'class' => 'mw-preferences-messagebox mw-notify-success successbox',
67  'id' => 'mw-preferences-success',
68  'data-mw-autohide' => 'false',
69  ],
70  Html::element( 'p', [], $this->msg( 'savedprefs' )->text() )
71  )
72  );
73  }
74 
75  $this->addHelpLink( 'Help:Preferences' );
76 
77  // Load the user from the master to reduce CAS errors on double post (T95839)
78  if ( $this->getRequest()->wasPosted() ) {
79  $user = $this->getUser()->getInstanceForUpdate() ?: $this->getUser();
80  } else {
81  $user = $this->getUser();
82  }
83 
84  $htmlForm = Preferences::getFormObject( $user, $this->getContext() );
85  $htmlForm->setSubmitCallback( [ 'Preferences', 'tryUISubmit' ] );
86  $sectionTitles = $htmlForm->getPreferenceSections();
87 
88  $prefTabs = '';
89  foreach ( $sectionTitles as $key ) {
90  $prefTabs .= Html::rawElement( 'li',
91  [
92  'role' => 'presentation',
93  'class' => ( $key === 'personal' ) ? 'selected' : null
94  ],
95  Html::rawElement( 'a',
96  [
97  'id' => 'preftab-' . $key,
98  'role' => 'tab',
99  'href' => '#mw-prefsection-' . $key,
100  'aria-controls' => 'mw-prefsection-' . $key,
101  'aria-selected' => ( $key === 'personal' ) ? 'true' : 'false',
102  'tabIndex' => ( $key === 'personal' ) ? 0 : -1,
103  ],
104  $htmlForm->getLegend( $key )
105  )
106  );
107  }
108 
109  $out->addHTML(
110  Html::rawElement( 'ul',
111  [
112  'id' => 'preftoc',
113  'role' => 'tablist'
114  ],
115  $prefTabs )
116  );
117  $htmlForm->show();
118  }
119 
120  private function showResetForm() {
121  if ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) {
122  throw new PermissionsError( 'editmyoptions' );
123  }
124 
125  $this->getOutput()->addWikiMsg( 'prefs-reset-intro' );
126 
127  $context = new DerivativeContext( $this->getContext() );
128  $context->setTitle( $this->getPageTitle( 'reset' ) ); // Reset subpage
129  $htmlForm = new HTMLForm( [], $context, 'prefs-restore' );
130 
131  $htmlForm->setSubmitTextMsg( 'restoreprefs' );
132  $htmlForm->setSubmitDestructive();
133  $htmlForm->setSubmitCallback( [ $this, 'submitReset' ] );
134  $htmlForm->suppressReset();
135 
136  $htmlForm->show();
137  }
138 
139  public function submitReset( $formData ) {
140  if ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) {
141  throw new PermissionsError( 'editmyoptions' );
142  }
143 
144  $user = $this->getUser()->getInstanceForUpdate();
145  $user->resetOptions( 'all', $this->getContext() );
146  $user->saveSettings();
147 
148  // Set session data for the success message
149  $this->getRequest()->getSession()->set( 'specialPreferencesSaveSuccess', 1 );
150 
151  $url = $this->getPageTitle()->getFullURL();
152  $this->getOutput()->redirect( $url );
153 
154  return true;
155  }
156 
157  protected function getGroupName() {
158  return 'users';
159  }
160 }
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:802
$context
Definition: load.php:50
getContext()
Gets the context this SpecialPage is executed in.
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:209
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable from
An IContextSource implementation which will inherit context from another source but allow individual ...
msg()
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
The package scripts
Definition: README.txt:1
addHelpLink($to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
outputHeader($summaryMessageKey= '')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
A special page that allows users to change their preferences.
Parent class for all special pages.
Definition: SpecialPage.php:36
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add etc
Definition: design.txt:12
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 and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Wikitext formatted, in the key only.
Definition: distributors.txt:9
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
static getFormObject($user, IContextSource $context, $formClass= 'PreferencesForm', array $remove=[])
Object handling generic submission, CSRF protection, layout and other logic for UI forms...
Definition: HTMLForm.php:128
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
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
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 local account $user
Definition: hooks.txt:242
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
requireLogin($reasonMsg= 'exception-nologin-text', $titleMsg= 'exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
getUser()
Shortcut to get the User executing this instance.
Show an error when a user tries to do something they do not have the necessary permissions for...
getRequest()
Get the WebRequest being used for this instance.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:229
getPageTitle($subpage=false)
Get a self-referential title object.