3fa5fd526cb219c2d59a295a50d723b2671be70f
3 * Implements Special:Preferences
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
21 * @ingroup SpecialPage
25 * A special page that allows users to change their preferences
27 * @ingroup SpecialPage
29 class SpecialPreferences
extends SpecialPage
{
30 function __construct() {
31 parent
::__construct( 'Preferences' );
34 public function execute( $par ) {
36 $this->outputHeader();
37 $out = $this->getOutput();
38 $out->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
40 $this->requireLogin( 'prefsnologintext2' );
41 $this->checkReadOnly();
43 if ( $par == 'reset' ) {
44 $this->showResetForm();
49 $out->addModules( 'mediawiki.special.preferences' );
50 $out->addModuleStyles( 'mediawiki.special.preferences.styles' );
52 $request = $this->getRequest();
53 if ( $request->getSessionData( 'specialPreferencesSaveSuccess' ) ) {
54 // Remove session data for the success message
55 $request->setSessionData( 'specialPreferencesSaveSuccess', null );
61 'class' => 'mw-preferences-messagebox successbox',
62 'id' => 'mw-preferences-success'
64 Html
::element( 'p', array(), '$1' )
70 $this->addHelpLink( 'Help:Preferences' );
72 // Load the user from the master to reduce CAS errors on double post (T95839)
73 $user = $this->getUser()->getInstanceForUpdate() ?
: $this->getUser();
75 $htmlForm = Preferences
::getFormObject( $user, $this->getContext() );
76 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryUISubmit' ) );
77 $sectionTitles = $htmlForm->getPreferenceSections();
80 foreach ( $sectionTitles as $key ) {
81 $prefTabs .= Html
::rawElement( 'li',
83 'role' => 'presentation',
84 'class' => ( $key === 'personal' ) ?
'selected' : null
86 Html
::rawElement( 'a',
88 'id' => 'preftab-' . $key,
90 'href' => '#mw-prefsection-' . $key,
91 'aria-controls' => 'mw-prefsection-' . $key,
92 'aria-selected' => ( $key === 'personal' ) ?
'true' : 'false',
93 'tabIndex' => ( $key === 'personal' ) ?
0 : -1,
95 $htmlForm->getLegend( $key )
101 Html
::rawElement( 'ul',
111 private function showResetForm() {
112 if ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) {
113 throw new PermissionsError( 'editmyoptions' );
116 $this->getOutput()->addWikiMsg( 'prefs-reset-intro' );
118 $context = new DerivativeContext( $this->getContext() );
119 $context->setTitle( $this->getPageTitle( 'reset' ) ); // Reset subpage
120 $htmlForm = new HTMLForm( array(), $context, 'prefs-restore' );
122 $htmlForm->setSubmitTextMsg( 'restoreprefs' );
123 $htmlForm->setSubmitDestructive();
124 $htmlForm->setSubmitCallback( array( $this, 'submitReset' ) );
125 $htmlForm->suppressReset();
130 public function submitReset( $formData ) {
131 if ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) {
132 throw new PermissionsError( 'editmyoptions' );
135 $user = $this->getUser()->getInstanceForUpdate();
136 $user->resetOptions( 'all', $this->getContext() );
137 $user->saveSettings();
139 // Set session data for the success message
140 $this->getRequest()->setSessionData( 'specialPreferencesSaveSuccess', 1 );
142 $url = $this->getPageTitle()->getFullURL();
143 $this->getOutput()->redirect( $url );
148 protected function getGroupName() {