Index: wp-admin/page-new.php
===================================================================
--- wp-admin/page-new.php	(revision 6891)
+++ wp-admin/page-new.php	(working copy)
@@ -5,7 +5,8 @@
 $editing = true;
 wp_enqueue_script('autosave');
 wp_enqueue_script('page');
-wp_enqueue_script('editor');
+if ( user_can_richedit() )
+	wp_enqueue_script('editor');
 wp_enqueue_script('thickbox');
 wp_enqueue_script('media-upload');
 
Index: wp-admin/page.php
===================================================================
--- wp-admin/page.php	(revision 6891)
+++ wp-admin/page.php	(working copy)
@@ -53,7 +53,8 @@
 	}
 
 	wp_enqueue_script('page');
-	wp_enqueue_script('editor');
+	if ( user_can_richedit() )
+		wp_enqueue_script('editor');
 	wp_enqueue_script('thickbox');
 	wp_enqueue_script('media-upload');
 
Index: wp-admin/post-new.php
===================================================================
--- wp-admin/post-new.php	(revision 6891)
+++ wp-admin/post-new.php	(working copy)
@@ -5,7 +5,8 @@
 $editing = true;
 wp_enqueue_script('autosave');
 wp_enqueue_script('post');
-wp_enqueue_script('editor');
+if ( user_can_richedit() )
+	wp_enqueue_script('editor');
 wp_enqueue_script('thickbox');
 wp_enqueue_script('media-upload');
 
Index: wp-admin/post.php
===================================================================
--- wp-admin/post.php	(revision 6891)
+++ wp-admin/post.php	(working copy)
@@ -62,7 +62,8 @@
 	}
 
 	wp_enqueue_script('post');
-	wp_enqueue_script('editor');
+	if ( user_can_richedit() )
+		wp_enqueue_script('editor');
 	wp_enqueue_script('thickbox');
 	wp_enqueue_script('media-upload');
 
Index: wp-admin/wp-admin.css
===================================================================
--- wp-admin/wp-admin.css	(revision 6891)
+++ wp-admin/wp-admin.css	(working copy)
@@ -260,16 +260,12 @@
 	color: #fff;
 }
 
-#postdivrich #quicktags {
+#postdivrich #quicktags, #postdiv #quicktags {
 	background: #cee1ef;
 	padding: 0;
 	border: 0 none;
 }
 
-#postdiv #quicktags {
-	padding-right: 6px;
-}
-
 #quicktags #ed_toolbar {
 	padding: 0 2px;
 }
Index: wp-includes/general-template.php
===================================================================
--- wp-includes/general-template.php	(revision 6891)
+++ wp-includes/general-template.php	(working copy)
@@ -923,67 +923,40 @@
 	if (($rows < 3) || ($rows > 100))
 		$rows = 12;
 
-	$rows = "rows='$rows'";
-
-	if ( user_can_richedit() ) :
-		$wp_default_editor = wp_default_editor();
-		$active = " class='active'";
-		$inactive = " onclick='switchEditors.go(\"$id\");'";
-
-		if ( 'tinymce' == $wp_default_editor )
-			add_filter('the_editor_content', 'wp_richedit_pre');
-		else if ( 'html' == $wp_default_editor )
-			add_filter('the_editor_content', 'wp_htmledit_pre');
-
-		//	The following line moves the border so that the active button "attaches" to the toolbar. Only IE needs it.
-        ?>
-    <style type="text/css">
-		#postdivrich table, #postdivrich #quicktags {border-top: none;}
-		#quicktags {border-bottom: none; padding-bottom: 2px; margin-bottom: -1px;}
-	</style>
-
-	<div id='editor-toolbar' style='display:none;'>
-		<div class='zerosize'><input accesskey='e' type='button' onclick='switchEditors.go("<?php echo $id; ?>")' /></div>
-		<a id='edButtonHTML'<?php echo 'html' == $wp_default_editor ? $active : $inactive; ?>><?php _e('HTML'); ?></a>
-	        <a id='edButtonPreview'<?php echo 'tinymce' == $wp_default_editor ? $active : $inactive; ?>><?php _e('Visual'); ?></a>
-
-	        <div id="media-buttons">
-	        <?php _e('Add media:'); ?>
-	        <?php do_action( 'media_buttons'); ?>
-	        </div>
+	$rows = "rows='$rows'";	?>
+	<div id="editor-toolbar">
+	<?php if ( user_can_richedit() ) {
+		$wp_default_editor = wp_default_editor(); ?>
+		<div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?>')" /></div>
+		<?php if ( 'tinymce' == $wp_default_editor ) {
+			add_filter('the_editor_content', 'wp_richedit_pre'); ?>
+			<a id="edButtonHTML" onclick="switchEditors.go('<?php echo $id; ?>');"><?php _e('HTML'); ?></a>
+			<a id="edButtonPreview" class="active"><?php _e('Visual'); ?></a>
+		<?php } elseif ( 'html' == $wp_default_editor ) {
+			add_filter('the_editor_content', 'wp_htmledit_pre'); ?>
+			<a id="edButtonHTML" class="active"><?php _e('HTML'); ?></a>
+			<a id="edButtonPreview" onclick="switchEditors.go('<?php echo $id; ?>');"><?php _e('Visual'); ?></a>
+		<?php }
+	} ?>
+		<div id="media-buttons">
+		<?php _e('Add media:'); ?>
+		<?php do_action( 'media_buttons'); ?>
+		</div>
 	</div>
 
-	<script type="text/javascript">
-	// <![CDATA[
-		if ( typeof tinyMCE != "undefined" )
-			document.getElementById('editor-toolbar').style.display = 'block';
-	// ]]>
-	</script>
-	
-	<?php else: // Rich editor is disabled in profile but we still need the media buttons	?>
-		
-	<div id='editor-toolbar' style='display:block;'>
-	        <div id="media-buttons">
-	        <?php _e('Add media:'); ?>
-	        <?php do_action( 'media_buttons'); ?>
-	        </div>
-	</div>
-
-	<?php endif; // user_can_richedit() ?>
-
 	<div id="quicktags">
 	<?php wp_print_scripts( 'quicktags' ); ?>
 	<script type="text/javascript">edToolbar()</script>
 	</div>
 
-	<?php if ( 'html' != $wp_default_editor ) : ?>
-	<script type="text/javascript">
-	// <![CDATA[
-		if ( typeof tinyMCE != "undefined" )
-			document.getElementById("quicktags").style.display="none";
-	// ]]>
-	</script>
-	<?php endif; // 'html' != $wp_default_editor
+    <?php if ( 'html' != $wp_default_editor ) : ?>
+    <script type="text/javascript">
+    // <![CDATA[
+        if ( typeof tinyMCE != "undefined" )
+            document.getElementById("quicktags").style.display="none";
+    // ]]>
+    </script>
+    <?php endif; // 'html' != $wp_default_editor
 
 	$the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea class='' $rows cols='40' name='$id' tabindex='2' id='$id'>%s</textarea></div>\n");
 	$the_editor_content = apply_filters('the_editor_content', $content);
@@ -991,13 +964,13 @@
 	printf($the_editor, $the_editor_content);
 
 	?>
-	<script type="text/javascript">
-	//<!--
-	edCanvas = document.getElementById('<?php echo $id; ?>');
-	<?php if ( $prev_id && user_can_richedit() ) : ?>
-	// If tinyMCE is defined.
-	if ( typeof tinyMCE != 'undefined' ) {
-	// This code is meant to allow tabbing from Title to Post (TinyMCE).
+    <script type="text/javascript">
+    // <![CDATA[
+    edCanvas = document.getElementById('<?php echo $id; ?>');
+    <?php if ( $prev_id && user_can_richedit() ) : ?>
+    // If tinyMCE is defined.
+    if ( typeof tinyMCE != 'undefined' ) {
+    // This code is meant to allow tabbing from Title to Post (TinyMCE).
         document.getElementById('<?php echo $prev_id; ?>').onkeydown = function (e) {
             e = e || window.event;
             if (e.keyCode == 9 && !e.shiftKey && !e.controlKey && !e.altKey) {
@@ -1010,11 +983,11 @@
                 return true;
             }
         }
-	}
-	<?php endif; ?>
-	//-->
-	</script>
-	<?php
+    }
+    <?php endif; ?>
+    // ]]>
+    </script>
+    <?php
 }
 
 function get_search_query() {
Index: wp-includes/js/tinymce/tiny_mce_config.php
===================================================================
--- wp-includes/js/tinymce/tiny_mce_config.php	(revision 6891)
+++ wp-includes/js/tinymce/tiny_mce_config.php	(working copy)
@@ -47,11 +47,11 @@
 $https = ( isset($_SERVER['HTTPS']) && 'on' == $_SERVER['HTTPS'] ) ? true : false;
 	
 $baseurl = get_option('siteurl') . '/wp-includes/js/tinymce';
-$baseurl = $https ? str_replace('http://', 'https://', $baseurl) : $baseurl;
+if ( $https ) str_replace('http://', 'https://', $baseurl);
 
 $mce_css = $baseurl . '/wordpress.css';
 $mce_css = apply_filters('mce_css', $mce_css);
-$mce_css = $https ? str_replace('http://', 'https://', $mce_css) : $mce_css;
+if ( $https ) str_replace('http://', 'https://', $mce_css);
 
 $valid_elements = '*[*]';
 $valid_elements = apply_filters('mce_valid_elements', $valid_elements);
@@ -72,17 +72,17 @@
 $ext_plugins = "\n";
 foreach ( $mce_external_plugins as $name => $url ) {
 	$plugins[] = '-' . $name;
-	$url = $https ? str_replace('http://', 'https://', $url) : $url;
+	if ( $https ) str_replace('http://', 'https://', $url);
 	
 	$ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
 }
 
 $plugins = implode($plugins, ',');
 
-$mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', '|', 'bullist', 'numlist', 'outdent', 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', '|', 'link', 'unlink', 'image', 'wp_more', '|', 'spellchecker', '|', 'wp_help', 'wp_adv' ));
+$mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', '|', 'bullist', 'numlist', 'outdent', 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', '|', 'link', 'unlink', 'image', 'wp_more', '|', 'spellchecker', 'fullscreen', 'wp_adv' ));
 $mce_buttons = implode($mce_buttons, ',');
 
-$mce_buttons_2 = apply_filters('mce_buttons_2', array('formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', '|', 'removeformat', 'cleanup', '|', 'media', 'charmap', 'blockquote', '|', 'undo', 'redo', 'fullscreen' ));
+$mce_buttons_2 = apply_filters('mce_buttons_2', array('formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', '|', 'removeformat', 'cleanup', '|', 'media', 'charmap', 'blockquote', '|', 'undo', 'redo', 'wp_help' ));
 $mce_buttons_2 = implode($mce_buttons_2, ',');
 
 $mce_buttons_3 = apply_filters('mce_buttons_3', array());
@@ -91,10 +91,6 @@
 $mce_buttons_4 = apply_filters('mce_buttons_4', array());
 $mce_buttons_4 = implode($mce_buttons_4, ',');
 
-// all these browsers are now 100% supported, no need for this
-//$mce_browsers = apply_filters('mce_browsers', array('msie', 'gecko', 'opera', 'safari'));
-//$mce_browsers = implode($mce_browsers, ',');
-
 $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1
 
 // TinyMCE init settings
@@ -114,13 +110,11 @@
 	'theme_advanced_statusbar_location' => 'bottom',
 	'theme_advanced_resizing' => true,
 	'theme_advanced_resize_horizontal' => false,
-//	'browsers' => "$mce_browsers",
 	'dialog_type' => 'modal',
-	'convert_urls' => false,
 	'relative_urls' => false,
 	'remove_script_host' => false,
 	'fix_list_elements' => true,
-	'fix_table_elements' => true,
+//	'fix_table_elements' => true,
 	'gecko_spellcheck' => true,
 	'entities' => '38,amp,60,lt,62,gt',
 	'accessibility_focus' => false,
@@ -131,7 +125,7 @@
 	// pass-through the settings for compression and caching, so they can be changed with "tiny_mce_before_init"
 	'disk_cache' => true,
 	'compress' => true,
-	'del_old_cache' => true
+	'old_cache_max' => '3' // number of cache files to keep
 );
 
 if ( $valid_elements ) $initArray['valid_elements'] = $valid_elements;
@@ -148,7 +142,7 @@
 ob_end_clean();
 
 /*
-// Do we need to support this? Most likely will breal TinyMCE 3...
+// Do we need to support this? Most likely will break TinyMCE 3...
 ob_start();
 do_action('tinymce_before_init');
 $mce_deprecated2 = ob_get_contents() || '';
@@ -161,10 +155,10 @@
 
 $disk_cache = ( ! isset($initArray['disk_cache']) || false == $initArray['disk_cache'] ) ? false : true;
 $compress = ( ! isset($initArray['compress']) || false == $initArray['compress'] ) ? false : true;
-$del_old_cache = ( ! isset($initArray['del_old_cache']) || false == $initArray['del_old_cache'] ) ? false : true;
+$old_cache_max = ( isset($initArray['old_cache_max']) ) ? (int) $initArray['old_cache_max'] : 0;
 
-$initArray['disk_cache'] = $initArray['compress'] = $initArray['del_old_cache'] = null;
-unset( $initArray['disk_cache'], $initArray['compress'], $initArray['del_old_cache'] );
+$initArray['disk_cache'] = $initArray['compress'] = $initArray['old_cache_max'] = null;
+unset( $initArray['disk_cache'], $initArray['compress'], $initArray['old_cache_max'] );
 
 $plugins = explode( ',', $initArray['plugins'] );
 $theme = ( 'simple' == $initArray['theme'] ) ? 'simple' : 'advanced';
@@ -188,13 +182,16 @@
 if ( $disk_cache && $cache_path ) {
 
 	$ver = isset($_GET['ver']) ? (int) $_GET['ver'] : '';
-	$cacheKey = $initArray['plugins'] . $language . $theme . $suffix . $ver;
+	$cacheKey = $suffix . $ver;
 
+	foreach ( $initArray as $v )
+		$cacheKey .= $v;
+	
 	foreach ( $custom_js as $file )
 		$cacheKey .= $file;
 
 	$cacheKey = md5( $cacheKey );
-	$cache_file = $cache_path . '/tiny_mce_' . $cacheKey . $cache_ext;
+	$cache_file = $cache_path . '/tinymce_' . $cacheKey . $cache_ext;
 }
 
 cache_javascript_headers();
@@ -209,13 +206,12 @@
 }
 
 foreach ( $initArray as $k => $v ) 
-    $mce_options .= $k . ':"' . $v . '", ';
+    $mce_options .= $k . ':"' . $v . '",';
 
 $mce_options .= $mce_deprecated1;
 $mce_options = rtrim( trim($mce_options), '\n\r,' );
 
-$content = 'var tinyMCEPreInit = { suffix : "' . $suffix . '", base : "' . $baseurl . '" };';
-$content .= 'var tinyMCE_GZ = { settings : { themes : "' . $theme . '", plugins : "' . $initArray['plugins'] . '", languages : "' . $language . '", debug : false, suffix : "' . $suffix . '" }, baseURL : "' . $baseurl . '" };';
+$content .= 'var tinyMCEPreInit = { settings : { themes : "' . $theme . '", plugins : "' . $initArray['plugins'] . '", languages : "' . $language . '", debug : false }, base : "' . $baseurl . '", suffix : "' . $suffix . '" };';
 
 // Load patch
 $content .= getFileContents( 'tiny_mce_ext.js' );
@@ -224,7 +220,7 @@
 $content .= getFileContents( 'tiny_mce' . $suffix . '.js' );
 
 // Patch loading functions
-$content .= 'tinyMCE_GZ.start();';
+$content .= 'tinyMCEPreInit.start();';
 
 // Add all languages (WP)
 include_once( dirname(__FILE__).'/langs/wp-langs.php' );
@@ -247,26 +243,38 @@
 // Generate GZIP'd content
 if ( '.gz' == $cache_ext ) {
 	header('Content-Encoding: ' . $enc);
-	$cache_data = gzencode( $content, 9, FORCE_GZIP );
-} else
-	$cache_data = $content;
+	$content = gzencode( $content, 9, FORCE_GZIP );
+}
 
 // Stream to client
-echo $cache_data;
+echo $content;
 
 // Write file
-if ( '' != $cacheKey ) {
-	if ( $del_old_cache ) {
-		$old_key = getFileContents('tiny_mce_compressed_key');
+if ( '' != $cacheKey && $cache_path ) {
+	if ( $old_cache_max ) {
+		$old_keys = getFileContents('tinymce_compressed_key' . $cache_ext);
 			
-		if ( '' != $old_key ) { //  && $old_key != $cacheKey
-			$old_cache = $cache_path . '/tiny_mce_' . $old_key . $cache_ext;
-			@unlink($old_cache);
+		if ( '' != $old_keys ) {
+			$keys_ar = explode( "\n", $old_keys );
+			if ( ($old_cache_max - 1) > count($old_keys_ar) )
+				$old_keys_rem = array_slice( $keys_ar, ($old_cache_max - 1) );
+			
+			foreach ( $old_keys_rem as $key ) {
+				$key = trim($key);
+				if ( 32 != strlen($key) ) continue;
+				$old_cache = $cache_path . '/tinymce_' . $key . $cache_ext;
+				@unlink($old_cache);
+			}
+			
+			array_unshift( $keys_ar, $cacheKey );
+			$keys_ar = array_slice( $keys_ar, 0, $old_cache_max );
+			$cacheKey = trim( implode( "\n", $keys_ar ) );
+			
 		}
-			
-		putFileContents( 'tiny_mce_compressed_key', $cacheKey );
+		
+		putFileContents( 'tinymce_compressed_key' . $cache_ext, $cacheKey );
 	}
-		
-	putFileContents( $cache_file, $cache_data );
+	
+	putFileContents( $cache_file, $content );
 }
 ?>
\ No newline at end of file
Index: wp-includes/js/tinymce/tiny_mce_ext.js
===================================================================
--- wp-includes/js/tinymce/tiny_mce_ext.js	(revision 6891)
+++ wp-includes/js/tinymce/tiny_mce_ext.js	(working copy)
@@ -1,12 +1,11 @@
-
-tinyMCE_GZ.start = function() {
+tinyMCEPreInit.start = function() {
 	var t = this, each = tinymce.each, s = t.settings, sl = tinymce.ScriptLoader, ln = s.languages.split(',');
 
 	function load(u, sp) {
 		var o;
 
 		if (!sp)
-			u = t.baseURL + u;
+			u = t.base + u;
 
 		o = {url : u, state : 2};
 		sl.queue.push(o);
@@ -22,7 +21,7 @@
 	// Add themes with languages
 	each(s.themes.split(','), function(n) {
 		if (n) {
-			load('/themes/' + n + '/editor_template' + s.suffix + '.js');
+			load('/themes/' + n + '/editor_template' + t.suffix + '.js');
 
 			each (ln, function(c) {
 				if (c)
@@ -34,7 +33,7 @@
 	// Add plugins with languages
 	each(s.plugins.split(','), function(n) {
 		if (n && n.charAt(0) != '-') {
-			load('/plugins/' + n + '/editor_plugin' + s.suffix + '.js');
+			load('/plugins/' + n + '/editor_plugin' + t.suffix + '.js');
 
 			each (ln, function(c) {
 				if (c)
Index: wp-includes/script-loader.php
===================================================================
--- wp-includes/script-loader.php	(revision 6891)
+++ wp-includes/script-loader.php	(working copy)
@@ -29,10 +29,17 @@
 
 		$this->add( 'colorpicker', '/wp-includes/js/colorpicker.js', false, '3517' );
 
-		// Modify this version when tinyMCE plugins are changed
-		$mce_config = apply_filters('tiny_mce_config_url', '/wp-includes/js/tinymce/tiny_mce_config.php');
-		$this->add( 'tiny_mce', $mce_config, false, '20080209' );
+		// Let a plugin replace the visual editor
+		$visual_editor = apply_filters('visual_editor', array('tiny_mce'));
+		$this->add( 'editor', false, $visual_editor, '20080218' );
 		
+		$this->add( 'editor_functions', '/wp-admin/js/editor.js', false, '20080208' );
+		
+		// Modify this version when tinyMCE plugins are changed.
+		$mce_version = apply_filters('tiny_mce_version', '20080209');
+		$this->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('editor_functions'), $mce_version );
+		$this->localize( 'tiny_mce', 'wpTinyMCEConfig', array( 'defaultEditor' => wp_default_editor() ) );
+		
 		$this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6');
 
 		$this->add( 'autosave', '/wp-includes/js/autosave.js', array('jquery', 'schedule'), '20080206');
@@ -474,12 +481,6 @@
 	return $js_array;
 }
 
-// These localizations require information that may not be loaded even by init
-function wp_just_in_time_script_localization() {
-	wp_localize_script( 'tiny_mce', 'wpTinyMCEConfig', array( 'defaultEditor' => wp_default_editor() ) );
-}
-
-add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' );
 add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
 
-?>
+?>
\ No newline at end of file
