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 doesWrites() {
38 public function execute( $par ) {
40 $this->outputHeader();
41 $out = $this->getOutput();
42 $out->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
44 $this->requireLogin( 'prefsnologintext2' );
45 $this->checkReadOnly();
47 if ( $par == 'reset' ) {
48 $this->showResetForm();
53 $out->addModules( 'mediawiki.special.preferences' );
54 $out->addModuleStyles( 'mediawiki.special.preferences.styles' );
56 $request = $this->getRequest();
57 if ( $request->getSessionData( 'specialPreferencesSaveSuccess' ) ) {
58 // Remove session data for the success message
59 $request->setSessionData( 'specialPreferencesSaveSuccess', null );
65 'class' => 'mw-preferences-messagebox successbox',
66 'id' => 'mw-preferences-success'
68 Html
::element( 'p', [], '$1' )
74 $this->addHelpLink( 'Help:Preferences' );
76 // Load the user from the master to reduce CAS errors on double post (T95839)
77 if ( $this->getRequest()->wasPosted() ) {
78 $user = $this->getUser()->getInstanceForUpdate() ?
: $this->getUser();
80 $user = $this->getUser();
83 $htmlForm = Preferences
::getFormObject( $user, $this->getContext() );
84 $htmlForm->setSubmitCallback( [ 'Preferences', 'tryUISubmit' ] );
85 $sectionTitles = $htmlForm->getPreferenceSections();
88 foreach ( $sectionTitles as $key ) {
89 $prefTabs .= Html
::rawElement( 'li',
91 'role' => 'presentation',
92 'class' => ( $key === 'personal' ) ?
'selected' : null
94 Html
::rawElement( 'a',
96 'id' => 'preftab-' . $key,
98 'href' => '#mw-prefsection-' . $key,
99 'aria-controls' => 'mw-prefsection-' . $key,
100 'aria-selected' => ( $key === 'personal' ) ?
'true' : 'false',
101 'tabIndex' => ( $key === 'personal' ) ?
0 : -1,
103 $htmlForm->getLegend( $key )
109 Html
::rawElement( 'ul',
119 private function showResetForm() {
120 if ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) {
121 throw new PermissionsError( 'editmyoptions' );
124 $this->getOutput()->addWikiMsg( 'prefs-reset-intro' );
126 $context = new DerivativeContext( $this->getContext() );
127 $context->setTitle( $this->getPageTitle( 'reset' ) ); // Reset subpage
128 $htmlForm = new HTMLForm( [], $context, 'prefs-restore' );
130 $htmlForm->setSubmitTextMsg( 'restoreprefs' );
131 $htmlForm->setSubmitDestructive();
132 $htmlForm->setSubmitCallback( [ $this, 'submitReset' ] );
133 $htmlForm->suppressReset();
138 public function submitReset( $formData ) {
139 if ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) {
140 throw new PermissionsError( 'editmyoptions' );
143 $user = $this->getUser()->getInstanceForUpdate();
144 $user->resetOptions( 'all', $this->getContext() );
145 $user->saveSettings();
147 // Set session data for the success message
148 $this->getRequest()->setSessionData( 'specialPreferencesSaveSuccess', 1 );
150 $url = $this->getPageTitle()->getFullURL();
151 $this->getOutput()->redirect( $url );
156 protected function getGroupName() {