Index: wp-includes/functions-post.php
===================================================================
--- wp-includes/functions-post.php	(revision 3391)
+++ wp-includes/functions-post.php	(working copy)
@@ -880,23 +880,24 @@
 
 // Returns an array containing the current upload directory's path and url, or an error message.
 function wp_upload_dir() {
-	$dir = trim(get_settings('fileupload_realpath'));
-	$url = trim(get_settings('fileupload_url'));
+	$siteurl = get_settings('siteurl');
+	//prepend ABSPATH to $dir and $siteurl to $url if they're not already there
+	$dir = ABSPATH . str_replace(ABSPATH, '', trim(get_settings('fileupload_realpath')));
+	$url = $siteurl . str_replace($siteurl, '', trim(get_settings('fileupload_url')));
 
-	$custom = true;
-	if ( empty($dir) || empty($url) ) {
+	if ( $dir == ABSPATH ) { //the option was empty
 		$dir = ABSPATH . 'wp-content/uploads';
-		$url = get_option('siteurl') . '/wp-content/uploads';
-		$custom = false;
 	}
+	if ( $url == $siteurl ) { //the option was empty
+		$url = get_option('siteurl') . '/' . str_replace(ABSPATH, '', $dir);
+	}
 
 	if ( defined('UPLOADS') ) {
 		$dir = ABSPATH . UPLOADS;
 		$url =  get_option('siteurl') . '/' . UPLOADS;
-		$custom = false;
 	}
 
-	if ( ! $custom) {
+	if ( get_settings('uploads_yearmonth_folders')) {
 		// Generate the yearly and monthly dirs
 		$time = current_time( 'mysql' );
 		$y = substr( $time, 0, 4 );
Index: wp-includes/functions.php
===================================================================
--- wp-includes/functions.php	(revision 3391)
+++ wp-includes/functions.php	(working copy)
@@ -355,12 +355,13 @@
 
 	// If the new and old values are the same, no need to update.
 	$oldvalue = get_option($option_name);
-	if ( $newvalue == $oldvalue )
+	if ( $newvalue == $oldvalue ) {
 		return false;
+	}
 
-        if ( false === $oldvalue ) {
-                add_option($option_name, $newvalue);
-                return true;
+	if ( false === $oldvalue ) {
+		add_option($option_name, $newvalue);
+		return true;
 	}
 
 	if ( is_array($newvalue) || is_object($newvalue) )
Index: wp-admin/options.php
===================================================================
--- wp-admin/options.php	(revision 3391)
+++ wp-admin/options.php	(working copy)
@@ -47,20 +47,21 @@
 	// Options that if not there have 0 value but need to be something like "closed"
 	$nonbools = array('default_ping_status', 'default_comment_status');
 	if ($options) {
-	  foreach ($options as $option) {
-	    $option = trim($option);
-	    $value = trim(stripslashes($_POST[$option]));
-            if( in_array($option, $nonbools) && ( $value == '0' || $value == '') )
-	      $value = 'closed';
-
-	    if( $option == 'blogdescription' || $option == 'blogname' )
-		    if (current_user_can('unfiltered_html') == false)
-			    $value = wp_filter_post_kses( $value );
-
-	    if ( update_option($option, $value) )
-	      $any_changed++;
-	  }
-        }
+		foreach ($options as $option) {
+			$option = trim($option);
+			$value = trim(stripslashes($_POST[$option]));
+				if( in_array($option, $nonbools) && ( $value == '0' || $value == '') )
+				$value = 'closed';
+			
+			if( $option == 'blogdescription' || $option == 'blogname' )
+				if (current_user_can('unfiltered_html') == false)
+					$value = wp_filter_post_kses( $value );
+			
+			if (update_option($option, $value) ) {
+				$any_changed++;
+			}
+		}
+	}
     
 	if ($any_changed) {
 			// If siteurl or home changed, reset cookies.
@@ -78,10 +79,10 @@
 			//$message = sprintf(__('%d setting(s) saved... '), $any_changed);
     }
     
-		$referred = remove_query_arg('updated' , $_SERVER['HTTP_REFERER']);
-		$goback = add_query_arg('updated', 'true', $_SERVER['HTTP_REFERER']);
-		$goback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $goback);
-		wp_redirect($goback);
+	$referred = remove_query_arg('updated' , $_SERVER['HTTP_REFERER']);
+	$goback = add_query_arg('updated', 'true', $_SERVER['HTTP_REFERER']);
+	$goback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $goback);
+	wp_redirect($goback);
     break;
 
 default:
Index: wp-admin/options-writing.php
===================================================================
--- wp-admin/options-writing.php	(revision 3391)
+++ wp-admin/options-writing.php	(working copy)
@@ -44,7 +44,25 @@
 </table>
 
 <fieldset class="options">
-<legend><?php _e('Writing by e-mail') ?></legend>
+<legend><?php _e('Uploading'); ?></legend>
+<table width="100%" cellspacing="2" cellpadding="5" class="editform">
+	<tr valign="top"><th scope="row" width="33%">Where to store images:</th>
+	<td>
+		<label for="uploads_yearmonth_folders">
+			<input name="uploads_yearmonth_folders" type="checkbox" id="uploads_yearmonth_folders" value="1" <?php checked('1', get_settings('uploads_yearmonth_folders')); ?> />
+			<?php _e('Organize my uploads into month- and year-based folders'); ?>
+		</label>
+	</td></tr>
+	<tr valign="top"><th scope="row"><?php _e('Store uploads in (default is wp-content/uploads):'); ?></th>
+	<td>
+		<input name="fileupload_realpath" type="text" id="fileupload_realpath" value="<?php echo str_replace(ABSPATH, '', get_settings('fileupload_realpath')); ?>" size="40" />
+	</td></tr>
+</table>
+
+</fieldset>
+
+<fieldset class="options">
+<legend><?php _e('Writing by e-mail'); ?></legend>
 <p><?php printf(__('To post to WordPress by e-mail you must set up a secret e-mail account with POP3 access. Any mail received at this address will be posted, so it&#8217;s a good idea to keep this address very secret. Here are three random strings you could use: <code>%s</code>, <code>%s</code>, <code>%s</code>.'), substr(md5(uniqid(microtime())),0,5), substr(md5(uniqid(microtime())),0,5), substr(md5(uniqid(microtime())),0,5)) ?></p>
 
 <table width="100%" cellspacing="2" cellpadding="5" class="editform">
@@ -90,7 +108,7 @@
 
 <p class="submit">
 <input type="hidden" name="action" value="update" /> 
-<input type="hidden" name="page_options" value="default_post_edit_rows,use_smilies,rich_editing,ping_sites,mailserver_url,mailserver_port,mailserver_login,mailserver_pass,default_category,default_email_category,use_balanceTags" /> 
+<input type="hidden" name="page_options" value="default_post_edit_rows,use_smilies,rich_editing,ping_sites,mailserver_url,mailserver_port,mailserver_login,mailserver_pass,default_category,default_email_category,use_balanceTags,fileupload_realpath,uploads_yearmonth_folders" /> 
 <input type="submit" name="Submit" value="<?php _e('Update Options') ?> &raquo;" /> 
 </p>
 </form> 
Index: wp-admin/upgrade-schema.php
===================================================================
--- wp-admin/upgrade-schema.php	(revision 3391)
+++ wp-admin/upgrade-schema.php	(working copy)
@@ -216,10 +216,14 @@
 	add_option('html_type', 'text/html');
 	// 1.5.1
 	add_option('use_trackback', 0);
-	// 1.6
+	// 2.0
 	add_option('default_role', 'subscriber');
 	add_option('rich_editing', 'true');
 	add_option('db_version', $wp_db_version);
+	// 2.1
+	add_option('uploads_yearmonth_folders', 1);
+	add_option('fileupload_realpath', ABSPATH . 'wp-content/uploads');
+	add_option('fileupload_url', ''); //if this is empty it will be obtained from fileupload_realpath
 	
 	// Delete unused options
 	$unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog');

