MediaWiki  REL1_19
SpecialPreferences.php
Go to the documentation of this file.
00001 <?php
00029 class SpecialPreferences extends SpecialPage {
00030         function __construct() {
00031                 parent::__construct( 'Preferences' );
00032         }
00033 
00034         public function execute( $par ) {
00035                 $this->setHeaders();
00036                 $this->outputHeader();
00037                 $out = $this->getOutput();
00038                 $out->disallowUserJs();  # Prevent hijacked user scripts from sniffing passwords etc.
00039 
00040                 $user = $this->getUser();
00041                 if ( $user->isAnon() ) {
00042                         $out->showErrorPage( 'prefsnologin', 'prefsnologintext', array( $this->getTitle()->getPrefixedDBkey() ) );
00043                         return;
00044                 }
00045                 $this->checkReadOnly();
00046 
00047                 if ( $par == 'reset' ) {
00048                         $this->showResetForm();
00049                         return;
00050                 }
00051 
00052                 $out->addModules( 'mediawiki.special.preferences' );
00053 
00054                 if ( $this->getRequest()->getCheck( 'success' ) ) {
00055                         $out->wrapWikiMsg(
00056                                 "<div class=\"successbox\"><strong>\n$1\n</strong></div><div id=\"mw-pref-clear\"></div>",
00057                                 'savedprefs'
00058                         );
00059                 }
00060 
00061                 $htmlForm = Preferences::getFormObject( $user, $this->getContext() );
00062                 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryUISubmit' ) );
00063 
00064                 $htmlForm->show();
00065         }
00066 
00067         private function showResetForm() {
00068                 $this->getOutput()->addWikiMsg( 'prefs-reset-intro' );
00069 
00070                 $htmlForm = new HTMLForm( array(), $this->getContext(), 'prefs-restore' );
00071 
00072                 $htmlForm->setSubmitText( wfMsg( 'restoreprefs' ) );
00073                 $htmlForm->setTitle( $this->getTitle( 'reset' ) );
00074                 $htmlForm->setSubmitCallback( array( $this, 'submitReset' ) );
00075                 $htmlForm->suppressReset();
00076 
00077                 $htmlForm->show();
00078         }
00079 
00080         public function submitReset( $formData ) {
00081                 $user = $this->getUser();
00082                 $user->resetOptions();
00083                 $user->saveSettings();
00084 
00085                 $url = SpecialPage::getTitleFor( 'Preferences' )->getFullURL( 'success' );
00086 
00087                 $this->getOutput()->redirect( $url );
00088 
00089                 return true;
00090         }
00091 }