Pass Context to User::resetOptions
[lhc/web/wiklou.git] / includes / specials / SpecialPreferences.php
index 38ae223..cc7b8fa 100644 (file)
@@ -35,19 +35,21 @@ class SpecialPreferences extends SpecialPage {
                $this->setHeaders();
                $this->outputHeader();
                $out = $this->getOutput();
-               $out->disallowUserJs();  # Prevent hijacked user scripts from sniffing passwords etc.
+               $out->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
 
                $user = $this->getUser();
                if ( $user->isAnon() ) {
-                       $out->showErrorPage( 'prefsnologin', 'prefsnologintext', array( $this->getTitle()->getPrefixedDBkey() ) );
-                       return;
-               }
-               if ( wfReadOnly() ) {
-                       throw new ReadOnlyError;
+                       throw new ErrorPageError(
+                               'prefsnologin',
+                               'prefsnologintext',
+                               array( $this->getTitle()->getPrefixedDBkey() )
+                       );
                }
+               $this->checkReadOnly();
 
                if ( $par == 'reset' ) {
                        $this->showResetForm();
+
                        return;
                }
 
@@ -55,7 +57,7 @@ class SpecialPreferences extends SpecialPage {
 
                if ( $this->getRequest()->getCheck( 'success' ) ) {
                        $out->wrapWikiMsg(
-                               "<div class=\"successbox\"><strong>\n$1\n</strong></div><div id=\"mw-pref-clear\"></div>",
+                               "<div class=\"successbox mw-sp-pref-successbox\">\n$1\n</div>",
                                'savedprefs'
                        );
                }
@@ -67,11 +69,15 @@ class SpecialPreferences extends SpecialPage {
        }
 
        private function showResetForm() {
+               if ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) {
+                       throw new PermissionsError( 'editmyoptions' );
+               }
+
                $this->getOutput()->addWikiMsg( 'prefs-reset-intro' );
 
                $htmlForm = new HTMLForm( array(), $this->getContext(), 'prefs-restore' );
 
-               $htmlForm->setSubmitText( wfMsg( 'restoreprefs' ) );
+               $htmlForm->setSubmitTextMsg( 'restoreprefs' );
                $htmlForm->setTitle( $this->getTitle( 'reset' ) );
                $htmlForm->setSubmitCallback( array( $this, 'submitReset' ) );
                $htmlForm->suppressReset();
@@ -80,14 +86,22 @@ class SpecialPreferences extends SpecialPage {
        }
 
        public function submitReset( $formData ) {
+               if ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) {
+                       throw new PermissionsError( 'editmyoptions' );
+               }
+
                $user = $this->getUser();
-               $user->resetOptions();
+               $user->resetOptions( 'all', $this->getContext() );
                $user->saveSettings();
 
-               $url = SpecialPage::getTitleFor( 'Preferences' )->getFullURL( 'success' );
+               $url = $this->getTitle()->getFullURL( 'success' );
 
                $this->getOutput()->redirect( $url );
 
                return true;
        }
+
+       protected function getGroupName() {
+               return 'users';
+       }
 }