Lame user side email validator using JQuery.
[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->addModuleScripts( 'mediawiki.specials.preferences' );
57 $wgOut->addModuleStyles( 'mediawiki.specials.preferences' );
58
59 if ( $wgRequest->getCheck( 'success' ) ) {
60 $wgOut->wrapWikiMsg(
61 "<div class=\"successbox\"><strong>\n$1\n</strong></div><div id=\"mw-pref-clear\"></div>",
62 'savedprefs'
63 );
64 }
65
66 if ( $wgRequest->getCheck( 'eauth' ) ) {
67 $wgOut->wrapWikiMsg( "<div class='error' style='clear: both;'>\n$1\n</div>",
68 'eauthentsent', $wgUser->getName() );
69 }
70
71 $htmlForm = Preferences::getFormObject( $wgUser );
72 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryUISubmit' ) );
73
74 $htmlForm->show();
75 }
76
77 function showResetForm() {
78 global $wgOut;
79
80 $wgOut->addWikiMsg( 'prefs-reset-intro' );
81
82 $htmlForm = new HTMLForm( array(), 'prefs-restore' );
83
84 $htmlForm->setSubmitText( wfMsg( 'restoreprefs' ) );
85 $htmlForm->setTitle( $this->getTitle( 'reset' ) );
86 $htmlForm->setSubmitCallback( array( __CLASS__, 'submitReset' ) );
87 $htmlForm->suppressReset();
88
89 $htmlForm->show();
90 }
91
92 static function submitReset( $formData ) {
93 global $wgUser, $wgOut;
94 $wgUser->resetOptions();
95 $wgUser->saveSettings();
96
97 $url = SpecialPage::getTitleFor( 'Preferences' )->getFullURL( 'success' );
98
99 $wgOut->redirect( $url );
100
101 return true;
102 }
103 }