MediaWiki
REL1_23
|
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 $this->requireLogin( 'prefsnologintext2' ); 00041 $this->checkReadOnly(); 00042 00043 if ( $par == 'reset' ) { 00044 $this->showResetForm(); 00045 00046 return; 00047 } 00048 00049 $out->addModules( 'mediawiki.special.preferences' ); 00050 00051 if ( $this->getRequest()->getCheck( 'success' ) ) { 00052 $out->wrapWikiMsg( 00053 "<div class=\"successbox\">\n$1\n</div>", 00054 'savedprefs' 00055 ); 00056 } 00057 00058 $htmlForm = Preferences::getFormObject( $this->getUser(), $this->getContext() ); 00059 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryUISubmit' ) ); 00060 00061 $htmlForm->show(); 00062 } 00063 00064 private function showResetForm() { 00065 if ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) { 00066 throw new PermissionsError( 'editmyoptions' ); 00067 } 00068 00069 $this->getOutput()->addWikiMsg( 'prefs-reset-intro' ); 00070 00071 $context = new DerivativeContext( $this->getContext() ); 00072 $context->setTitle( $this->getPageTitle( 'reset' ) ); // Reset subpage 00073 $htmlForm = new HTMLForm( array(), $context, 'prefs-restore' ); 00074 00075 $htmlForm->setSubmitTextMsg( 'restoreprefs' ); 00076 $htmlForm->setSubmitCallback( array( $this, 'submitReset' ) ); 00077 $htmlForm->suppressReset(); 00078 00079 $htmlForm->show(); 00080 } 00081 00082 public function submitReset( $formData ) { 00083 if ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) { 00084 throw new PermissionsError( 'editmyoptions' ); 00085 } 00086 00087 $user = $this->getUser(); 00088 $user->resetOptions( 'all', $this->getContext() ); 00089 $user->saveSettings(); 00090 00091 $url = $this->getPageTitle()->getFullURL( 'success' ); 00092 00093 $this->getOutput()->redirect( $url ); 00094 00095 return true; 00096 } 00097 00098 protected function getGroupName() { 00099 return 'users'; 00100 } 00101 }