Index: wp-login.php
===================================================================
--- wp-login.php	(revision 2657)
+++ wp-login.php	(working copy)
@@ -12,8 +12,9 @@
 	if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
 		$_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] );
 	
-	if ( dirname('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) != get_settings('siteurl') )
-		update_option('siteurl', dirname('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) );
+	$schema = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'])=='on')?'https://':'http://';
+	if ( dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) != get_settings('siteurl') )
+		update_option('siteurl', dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) );
 }
 
 switch($action) {
Index: wp-includes/functions.php
===================================================================
--- wp-includes/functions.php	(revision 2657)
+++ wp-includes/functions.php	(working copy)
@@ -685,7 +685,7 @@
 		$link_url = $matches[2][$i];
 		$link_text = $matches[4][$i];
 		$content = str_replace($link_match, $link_text.' '.$link_number, $content);
-		$link_url = (strtolower(substr($link_url,0,7)) != 'http://') ? get_settings('home') . $link_url : $link_url;
+		$link_url = ((strtolower(substr($link_url,0,7)) != 'http://')||(strtolower(substr($link_url,0,7)) != 'https://')) ? get_settings('home') . $link_url : $link_url;
 		$links_summary .= "\n".$link_number.' '.$link_url;
 	}
 	$content = strip_tags($content);
Index: xmlrpc.php
===================================================================
--- xmlrpc.php	(revision 2657)
+++ xmlrpc.php	(working copy)
@@ -283,7 +283,7 @@
 
 	  /* warning: here we make the assumption that the weblog's URI is on the same server */
 	  $filename = get_settings('home') . '/';
-	  $filename = preg_replace('#http://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
+	  $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
 
 	  $f = fopen($filename, 'r');
 	  $content = fread($f, filesize($filename));
@@ -317,7 +317,7 @@
 
 	  /* warning: here we make the assumption that the weblog's URI is on the same server */
 	  $filename = get_settings('home') . '/';
-	  $filename = preg_replace('#http://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
+	  $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
 
 	  if ($f = fopen($filename, 'w+')) {
 	    fwrite($f, $content);
@@ -1086,7 +1086,7 @@
 		$error_code = -1;
 
 		// Check if the page linked to is in our site
-		$pos1 = strpos($pagelinkedto, str_replace('http://', '', str_replace('www.', '', get_settings('home'))));
+		$pos1 = strpos($pagelinkedto, str_replace(array('http://www.','http://','https://www.','https://'), '', get_settings('home')));
 		if( !$pos1 )
 	  		return new IXR_Error(0, 'Is there no link to us?');
 
Index: wp-admin/install.php
===================================================================
--- wp-admin/install.php	(revision 2657)
+++ wp-admin/install.php	(working copy)
@@ -6,7 +6,8 @@
 require_once('../wp-config.php');
 require_once('./upgrade-functions.php');
 
-$guessurl = str_replace('/wp-admin/install.php?step=2', '', 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) );
+$schema = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'])=='on')?'https://':'http://';
+$guessurl = str_replace('/wp-admin/install.php?step=2', '', $schema . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) );
 
 if (isset($_GET['step']))
 	$step = $_GET['step'];
Index: wp-admin/upgrade-schema.php
===================================================================
--- wp-admin/upgrade-schema.php	(revision 2657)
+++ wp-admin/upgrade-schema.php	(working copy)
@@ -149,7 +149,8 @@
 function populate_options() {
 	global $wpdb;
 
-	$guessurl = preg_replace('|/wp-admin/.*|i', '', 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
+	$schema = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'])=='on')?'https://':'http://';
+	$guessurl = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
 	add_option('siteurl', $guessurl, __('WordPress web address'));
 	add_option('blogname', __('My Weblog'), __('Blog title'));
 	add_option('blogdescription', __('Just another WordPress weblog'), __('Short tagline'));
