MediaWiki
REL1_24
|
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->setSubmitDestructive(); 00077 $htmlForm->setSubmitCallback( array( $this, 'submitReset' ) ); 00078 $htmlForm->suppressReset(); 00079 00080 $htmlForm->show(); 00081 } 00082 00083 public function submitReset( $formData ) { 00084 if ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) { 00085 throw new PermissionsError( 'editmyoptions' ); 00086 } 00087 00088 $user = $this->getUser(); 00089 $user->resetOptions( 'all', $this->getContext() ); 00090 $user->saveSettings(); 00091 00092 $url = $this->getPageTitle()->getFullURL( 'success' ); 00093 00094 $this->getOutput()->redirect( $url ); 00095 00096 return true; 00097 } 00098 00099 protected function getGroupName() { 00100 return 'users'; 00101 } 00102 }