Correct the address of the FSF in some of the GPL headers
[lhc/web/wiklou.git] / includes / specials / SpecialPreferences.php
1 <?php
2 /**
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 */
19
20 class SpecialPreferences extends SpecialPage {
21 function __construct() {
22 parent::__construct( 'Preferences' );
23 }
24
25 function execute( $par ) {
26 global $wgOut, $wgUser, $wgRequest;
27
28 $this->setHeaders();
29 $this->outputHeader();
30 $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
31
32 if ( $wgUser->isAnon() ) {
33 $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext', array( $this->getTitle()->getPrefixedDBkey() ) );
34 return;
35 }
36 if ( wfReadOnly() ) {
37 $wgOut->readOnlyPage();
38 return;
39 }
40
41 if ( $par == 'reset' ) {
42 $this->showResetForm();
43 return;
44 }
45
46 $wgOut->addScriptFile( 'prefs.js' );
47
48 if ( $wgRequest->getCheck( 'success' ) ) {
49 $wgOut->wrapWikiMsg(
50 "<div class=\"successbox\"><strong>\n$1\n</strong></div><div id=\"mw-pref-clear\"></div>",
51 'savedprefs'
52 );
53 }
54
55 if ( $wgRequest->getCheck( 'eauth' ) ) {
56 $wgOut->wrapWikiMsg( "<div class='error' style='clear: both;'>\n$1\n</div>",
57 'eauthentsent', $wgUser->getName() );
58 }
59
60 $htmlForm = Preferences::getFormObject( $wgUser );
61 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryUISubmit' ) );
62
63 $htmlForm->show();
64 }
65
66 function showResetForm() {
67 global $wgOut;
68
69 $wgOut->addWikiMsg( 'prefs-reset-intro' );
70
71 $htmlForm = new HTMLForm( array(), 'prefs-restore' );
72
73 $htmlForm->setSubmitText( wfMsg( 'restoreprefs' ) );
74 $htmlForm->setTitle( $this->getTitle( 'reset' ) );
75 $htmlForm->setSubmitCallback( array( __CLASS__, 'submitReset' ) );
76 $htmlForm->suppressReset();
77
78 $htmlForm->show();
79 }
80
81 static function submitReset( $formData ) {
82 global $wgUser, $wgOut;
83 $wgUser->resetOptions();
84 $wgUser->saveSettings();
85
86 $url = SpecialPage::getTitleFor( 'Preferences' )->getFullURL( 'success' );
87
88 $wgOut->redirect( $url );
89
90 return true;
91 }
92 }