Index: wp-admin/plugins.php
===================================================================
--- wp-admin/plugins.php	(revision 5856)
+++ wp-admin/plugins.php	(working copy)
@@ -11,7 +11,7 @@
 		if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )
 			wp_die(__('Plugin file does not exist.'));
 		if (!in_array($plugin, $current)) {
-			wp_redirect('plugins.php?error=true'); // we'll override this later if the plugin can be included without fatal error
+			wp_redirect('plugins.php?error=true&plugin='.urlencode($plugin)); // we'll override this later if the plugin can be included without fatal error
 			ob_start();
 			@include(ABSPATH . PLUGINDIR . '/' . $plugin);
 			$current[] = $plugin;
@@ -21,24 +21,59 @@
 			ob_end_clean();
 		}
 		wp_redirect('plugins.php?activate=true'); // overrides the ?error=true one above
-	} else if ('deactivate' == $_GET['action']) {
+	} elseif ('deactivate' == $_GET['action']) {
 		check_admin_referer('deactivate-plugin_' . $_GET['plugin']);
 		$current = get_option('active_plugins');
 		array_splice($current, array_search( $_GET['plugin'], $current), 1 ); // Array-fu!
 		update_option('active_plugins', $current);
 		do_action('deactivate_' . trim( $_GET['plugin'] ));
 		wp_redirect('plugins.php?deactivate=true');
-	} elseif ($_GET['action'] == 'deactivate-all') {
+	} elseif ('deactivate-all' == $_GET['action']) {
 		check_admin_referer('deactivate-all');
 		$current = get_option('active_plugins');
 		
 		foreach ($current as $plugin) {
-			array_splice($current, array_search($plugin, $current), 1);
 			do_action('deactivate_' . $plugin);
 		}
 		
 		update_option('active_plugins', array());
+		update_option('deactivated_plugins', $current);
 		wp_redirect('plugins.php?deactivate-all=true');
+	} elseif ('reactivate-all' == $_GET['action']) {
+		check_admin_referer('reactivate-all');
+		$prev_plugins = get_option('deactivated_plugins');
+		$current = array();
+		$errors = array();
+		
+		// We'll keep track of errors in the $errors array,
+		// and report them after we're done.
+		foreach ($prev_plugins as $plugin) {
+			if ( validate_file($plugin) )
+				$errors[$plugin] = __('Invalid plugin.');
+			elseif ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )
+				$errors[$plugin] = __('Plugin file does not exist.');
+			elseif (!in_array($plugin, $current)) {
+				// A fatal error in any one plugin means NO
+				// plugins will be reactivated. Sorry, but that's
+				// just the way it is. :-/
+				wp_redirect('plugins.php?error=true&plugin='.urlencode($plugin)); // we'll override this later if the plugin can be included without fatal error
+				$errors[$plugin] = __('Plugin generated a fatal error.'); // we'll override this later if the plugin can be included without fatal error
+				ob_start();
+				@include(ABSPATH . PLUGINDIR . '/' . $plugin);
+				$current[] = $plugin;
+				do_action('activate_' . $plugin);
+				unset($errors[$plugin]);
+				ob_end_clean();
+			}
+		}
+		
+		sort($current);
+		
+		update_option('deactivated_plugins', array());
+		update_option('active_plugins', $current);
+		update_option('problem_plugins', $errors);
+		wp_redirect('plugins.php?reactivate-all=true'); // overrides the ?error=true one above
+	
 	}
 	exit;
 }
@@ -73,13 +108,38 @@
 ?>
 
 <?php if ( isset($_GET['error']) ) : ?>
-	<div id="message" class="updated fade"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>.') ?></p></div>
+	<?php 
+	$plugin = $_GET['plugin'];
+	$plugin = wp_specialchars($plugin);
+	?>
+	<div id="message" class="updated fade"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>. ('. $plugin . ')') ?></p></div>
 <?php elseif ( isset($_GET['activate']) ) : ?>
 	<div id="message" class="updated fade"><p><?php _e('Plugin <strong>activated</strong>.') ?></p></div>
 <?php elseif ( isset($_GET['deactivate']) ) : ?>
 	<div id="message" class="updated fade"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div>
 <?php elseif (isset($_GET['deactivate-all'])) : ?>
 	<div id="message" class="updated fade"><p><?php _e('All plugins <strong>deactivated</strong>.'); ?></p></div>
+<?php elseif (isset($_GET['reactivate-all'])) : ?>
+	<div id="message" class="updated fade">
+	<p><?php _e('All plugins <strong>reactivated</strong>.'); ?></p>
+<?php
+ $errors = get_option('problem_plugins');
+ if (! empty($errors)) {
+ 	// Display any errors:
+ 	?>
+ 	<p><?php _e('The following plugins generated errors:'); ?></p>
+ 	<ul>
+ 	<?php foreach ($errors as $plugin => $errmsg) {
+ 	?>
+ 	<li><?php echo $plugin . ': ' . $errmsg ?></li>
+ 	<?php
+ 	}
+ 	?>
+ 	</ul>
+ 	<?php
+ }
+?>
+	</div>
 <?php endif; ?>
 
 <div class="wrap">
@@ -152,7 +212,21 @@
 
 <tr>
 	<td colspan="3">&nbsp;</td>
-	<td colspan="2" style="width:12em;"><a href="<?php echo wp_nonce_url('plugins.php?action=deactivate-all', 'deactivate-all'); ?>" class="delete"><?php _e('Deactivate All Plugins'); ?></a></td>
+	<td colspan="2" style="width:12em;">
+	<?php 
+	$active = get_option('active_plugins');
+	$inactive = get_option('deactivated_plugins');
+	if (!empty($active)) {
+	?>
+	<a href="<?php echo wp_nonce_url('plugins.php?action=deactivate-all', 'deactivate-all'); ?>" class="delete"><?php _e('Deactivate All Plugins'); ?></a>
+	<?php 
+	} elseif (empty($active) && !empty($inactive)) {
+	?>
+	<a href="<?php echo wp_nonce_url('plugins.php?action=reactivate-all', 'reactivate-all'); ?>" class="delete"><?php _e('Reactivate All Plugins'); ?></a>
+	<?php
+	} // endif active/inactive plugin check
+	?>
+	</td>
 </tr>
 
 </table>

