r45563 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r45562 | r45563 (on ViewVC) | r45564 >
Date:14:02, 8 January 2009
Author:aaron
Status:resolved (Comments)
Tags:
Comment:(bug 2164) Add a "reset to site defaults" link to Special:Preferences
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/User.php
===================================================================
--- trunk/phase3/includes/User.php	(revision 45562)
+++ trunk/phase3/includes/User.php	(revision 45563)
@@ -1909,6 +1909,13 @@
 		}
 		$this->mOptions[$oname] = $val;
 	}
+	
+	/**
+	 * Reset all options to the site defaults
+	 */	
+	function restoreOptions() {
+		$this->mOptions = User::getDefaultOptions();
+	}
 
 	/**
 	 * Get the user's preferred date format.
Index: trunk/phase3/includes/specials/SpecialPreferences.php
===================================================================
--- trunk/phase3/includes/specials/SpecialPreferences.php	(revision 45562)
+++ trunk/phase3/includes/specials/SpecialPreferences.php	(revision 45563)
@@ -32,7 +32,7 @@
 	 * Constructor
 	 * Load some values
 	 */
-	function PreferencesForm( &$request ) {
+	function __construct( &$request ) {
 		global $wgContLang, $wgUser, $wgAllowRealName;
 
 		$this->mQuickbar = $request->getVal( 'wpQuickbar' );
@@ -60,6 +60,7 @@
 		$this->mUnderline = $request->getInt( 'wpOpunderline' );
 		$this->mAction = $request->getVal( 'action' );
 		$this->mReset = $request->getCheck( 'wpReset' );
+		$this->mRestoreprefs = $request->getCheck( 'wpRestore' );
 		$this->mPosted = $request->wasPosted();
 		$this->mSuccess = $request->getCheck( 'success' );
 		$this->mWatchlistDays = $request->getVal( 'wpWatchlistDays' );
@@ -117,6 +118,8 @@
 			$this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) );
 		} else if ( $this->mSaveprefs ) {
 			$this->savePreferences();
+		} else if ( $this->mRestoreprefs ) {
+			$this->restorePreferences();
 		} else {
 			$this->resetPrefs();
 			$this->mainPrefsForm( '' );
@@ -435,6 +438,17 @@
 
 		wfRunHooks( 'ResetPreferences', array( $this, $wgUser ) );
 	}
+	
+	/**
+	 * @access private
+	 */
+	function restorePreferences() {
+		global $wgUser;
+		$wgUser->restoreOptions();
+		$wgUser->setCookies();
+		$wgUser->saveSettings();
+		$this->mainPrefsForm( 'success' );
+	}
 
 	/**
 	 * @access private
@@ -1192,13 +1206,13 @@
 		$skin = $wgUser->getSkin();
 		$wgOut->addHTML( "
 	<div id='prefsubmit'>
-	<div>
-		<input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . '"'.$skin->tooltipAndAccesskey('save')." />
+		<input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . 
+			'"'.$skin->tooltipAndAccesskey('save')." />
 		<input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
+		<input type='submit' name='wpRestore' class='btnSavePrefs' style='float:right;' value=\"" . 
+			wfMsgHtml( 'restoreprefs' ) . "\" />
 	</div>
 
-	</div>
-
 	<input type='hidden' name='wpEditToken' value=\"{$token}\" />
 	</div></form>\n" );
 
Index: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php	(revision 45562)
+++ trunk/phase3/languages/messages/MessagesEn.php	(revision 45563)
@@ -1535,6 +1535,7 @@
 'prefs-resetpass'           => 'Change password',
 'saveprefs'                 => 'Save',
 'resetprefs'                => 'Clear unsaved changes',
+'restoreprefs'              => 'Restore all default settings',
 'textboxsize'               => 'Editing',
 'prefs-edit-boxsize'        => 'Size of the edit window.',
 'rows'                      => 'Rows:',

Comments

#Comment by Raymond (Talk | contribs)   14:03, 9 January 2009

At least the restore does not work for the tabs "Skin, TeX, Files, Date/Time, Search".

#Comment by Aaron Schulz (Talk | contribs)   14:21, 9 January 2009

Skin works for me

#Comment by Aaron Schulz (Talk | contribs)   14:24, 9 January 2009

Actually, they all work fine. The first reloading of the page sometimes shows the old ones though..

#Comment by Aaron Schulz (Talk | contribs)   14:26, 9 January 2009

Fixed in r45602

#Comment by Brion VIBBER (Talk | contribs)   21:42, 13 January 2009

This explicit float right is pretty bad for RTL. :)

#Comment by Raymond (Talk | contribs)   21:47, 13 January 2009

A tabindex should be added to the buttons too.

#Comment by Aaron Schulz (Talk | contribs)   13:43, 16 January 2009

Uses a table in r45761

Status & tagging log

Views
Toolbox