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