Follow-up r79964: Use the existing message 'parentheses' instead of introducing an...
[lhc/web/wiklou.git] / includes / specials / SpecialPreferences.php
1 <?php
2 /**
3 * Implements Special:Preferences
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * A special page that allows users to change their preferences
26 *
27 * @ingroup SpecialPage
28 */
29 class SpecialPreferences extends SpecialPage {
30 function __construct() {
31 parent::__construct( 'Preferences' );
32 }
33
34 function execute( $par ) {
35 global $wgOut, $wgUser, $wgRequest;
36
37 $this->setHeaders();
38 $this->outputHeader();
39 $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
40
41 if ( $wgUser->isAnon() ) {
42 $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext', array( $this->getTitle()->getPrefixedDBkey() ) );
43 return;
44 }
45 if ( wfReadOnly() ) {
46 $wgOut->readOnlyPage();
47 return;
48 }
49
50 if ( $par == 'reset' ) {
51 $this->showResetForm();
52 return;
53 }
54
55 $wgOut->addModules( 'mediawiki.legacy.prefs' );
56 $wgOut->addModules( 'mediawiki.special.preferences' );
57
58 if ( $wgRequest->getCheck( 'success' ) ) {
59 $wgOut->wrapWikiMsg(
60 "<div class=\"successbox\"><strong>\n$1\n</strong></div><div id=\"mw-pref-clear\"></div>",
61 'savedprefs'
62 );
63 }
64
65 if ( $wgRequest->getCheck( 'eauth' ) ) {
66 $wgOut->wrapWikiMsg( "<div class='error' style='clear: both;'>\n$1\n</div>",
67 'eauthentsent', $wgUser->getName() );
68 }
69
70 $htmlForm = Preferences::getFormObject( $wgUser );
71 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryUISubmit' ) );
72
73 $htmlForm->show();
74 }
75
76 function showResetForm() {
77 global $wgOut;
78
79 $wgOut->addWikiMsg( 'prefs-reset-intro' );
80
81 $htmlForm = new HTMLForm( array(), 'prefs-restore' );
82
83 $htmlForm->setSubmitText( wfMsg( 'restoreprefs' ) );
84 $htmlForm->setTitle( $this->getTitle( 'reset' ) );
85 $htmlForm->setSubmitCallback( array( __CLASS__, 'submitReset' ) );
86 $htmlForm->suppressReset();
87
88 $htmlForm->show();
89 }
90
91 static function submitReset( $formData ) {
92 global $wgUser, $wgOut;
93 $wgUser->resetOptions();
94 $wgUser->saveSettings();
95
96 $url = SpecialPage::getTitleFor( 'Preferences' )->getFullURL( 'success' );
97
98 $wgOut->redirect( $url );
99
100 return true;
101 }
102 }