and...
[lhc/web/wiklou.git] / includes / specials / SpecialPreferences.php
1 <?php
2
3 class SpecialPreferences extends SpecialPage {
4 function __construct() {
5 parent::__construct( 'Preferences' );
6 }
7
8 function execute( $par ) {
9 global $wgOut, $wgUser, $wgRequest;
10
11 $this->setHeaders();
12 $this->outputHeader();
13
14 $wgOut->addScriptFile( 'prefs.js' );
15
16 $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
17
18 if ( $wgUser->isAnon() ) {
19 $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext', array( $this->getTitle()->getPrefixedDBkey() ) );
20 return;
21 }
22 if ( wfReadOnly() ) {
23 $wgOut->readOnlyPage();
24 return;
25 }
26
27 if ( $par == 'reset' ) {
28 $this->showResetForm();
29 return;
30 }
31
32 if ( $wgRequest->getCheck( 'success' ) ) {
33 $wgOut->wrapWikiMsg(
34 '<div class="successbox"><strong>$1</strong></div>',
35 'savedprefs'
36 );
37 }
38
39 $htmlForm = Preferences::getFormObject( $wgUser );
40
41 $htmlForm->show();
42 }
43
44 function showResetForm() {
45 global $wgOut;
46
47 $wgOut->addWikiMsg( 'prefs-reset-intro' );
48
49 $htmlForm = new HTMLForm( array(), 'prefs-restore' );
50
51 $htmlForm->setSubmitText( wfMsg( 'restoreprefs' ) );
52 $htmlForm->setTitle( $this->getTitle( 'reset' ) );
53 $htmlForm->setSubmitCallback( array( __CLASS__, 'submitReset' ) );
54 $htmlForm->suppressReset();
55
56 $htmlForm->show();
57 }
58
59 static function submitReset( $formData ) {
60 global $wgUser, $wgOut;
61 $wgUser->resetOptions();
62
63 $url = SpecialPage::getTitleFor( 'Preferences' )->getFullURL( 'success' );
64
65 $wgOut->redirect( $url );
66
67 return true;
68 }
69 }