Index: src/wp-admin/plugin-editor.php
===================================================================
--- src/wp-admin/plugin-editor.php	(revision 34857)
+++ src/wp-admin/plugin-editor.php	(working copy)
@@ -36,11 +36,13 @@
 	exit;
 }
 
-if ( $file ) {
-	$plugin = $file;
-} elseif ( empty( $plugin ) ) {
-	$plugin = array_keys($plugins);
-	$plugin = $plugin[0];
+if ( empty( $plugin ) ) {
+	if ( $file ) {
+		$plugin = $file;
+	} elseif ( empty( $plugin ) ) {
+		$plugin = array_keys($plugins);
+		$plugin = $plugin[0];
+	}
 }
 
 $plugin_files = get_plugin_files($plugin);
@@ -58,47 +60,75 @@
 
 	check_admin_referer('edit-plugin_' . $file);
 
-	$newcontent = wp_unslash( $_POST['newcontent'] );
-	if ( is_writeable($real_file) ) {
-		$f = fopen($real_file, 'w+');
-		fwrite($f, $newcontent);
-		fclose($f);
+	// Shared redirect arguments.
+	$redirect_args = array(
+		'file'     => $file,
+		'plugin'   => $plugin,
+		'scrollto' => $scrollto,
+	);
 
-		$network_wide = is_plugin_active_for_network( $file );
+	if ( is_writeable( $real_file ) ) {
+		$newcontent = wp_unslash( $_POST['newcontent'] );
 
+		file_put_contents( $real_file, $newcontent );
+
+		$network_wide = is_plugin_active_for_network( $plugin );
+
 		// Deactivate so we can test it.
-		if ( is_plugin_active($file) || isset($_POST['phperror']) ) {
-			if ( is_plugin_active($file) )
-				deactivate_plugins($file, true);
+		if ( is_plugin_active( $plugin ) || isset($_POST['phperror'] ) ) {
+			if ( is_plugin_active( $plugin ) )
+				deactivate_plugins( $plugin, true );
 
 			if ( ! is_network_admin() ) {
-				update_option( 'recently_activated', array( $file => time() ) + (array) get_option( 'recently_activated' ) );
+				update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) );
 			} else {
-				update_network_option( 'recently_activated', array( $file => time() ) + (array) get_network_option( 'recently_activated' ) );
+				update_network_option( 'recently_activated', array( $plugin => time() ) + (array) get_network_option( 'recently_activated' ) );
 			}
 
-			wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1&scrollto=$scrollto&networkwide=" . $network_wide));
+			$redirect_args = array_merge( $redirect_args, array(
+				'liveupdate'  => 1,
+				'networkwide' => $network_wide,
+				'_wpnonce'    => wp_create_nonce( "edit-plugin-test_{$file}" ),
+			) );
+
+			wp_redirect( add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' )  ) );
 			exit;
 		}
-		wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") );
+
+		$redirect_args = array_merge( $redirect_args, array( 'updated'  => 1 ) );
+		wp_redirect( add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' ) ) );
 	} else {
-		wp_redirect( self_admin_url("plugin-editor.php?file=$file&scrollto=$scrollto") );
+		wp_redirect( add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' ) ) );
 	}
 	exit;
 
 default:
 
+	// Shared redirect arguments.
+	$redirect_args = array(
+		'file'     => $file,
+		'plugin'   => $plugin,
+	);
+
 	if ( isset($_GET['liveupdate']) ) {
 		check_admin_referer('edit-plugin-test_' . $file);
 
-		$error = validate_plugin($file);
+		$error = validate_plugin( $plugin );
 		if ( is_wp_error($error) )
 			wp_die( $error );
 
-		if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network($file) ) || ! is_plugin_active($file) )
-			activate_plugin($file, "plugin-editor.php?file=$file&phperror=1", ! empty( $_GET['networkwide'] ) ); // we'll override this later if the plugin can be included without fatal error
+		if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network( $plugin ) ) || is_plugin_active( $plugin ) ) {
 
-		wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") );
+			// we'll override this later if the plugin can be included without fatal error
+			$redirect_args = array_merge( $redirect_args, array( 'phperror' => 1 ) );
+			activate_plugin( $plugin, add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' ) ), ! empty( $_GET['networkwide'] ) );
+		}
+
+		$redirect_args = array_merge( $redirect_args, array(
+			'scrollto' => $scrollto,
+			'updated'  => 1
+		) );
+		wp_redirect( add_query_arg( $redirect_args, self_admin_url( 'plugin-editor.php' ) ) );
 		exit;
 	}
 
@@ -115,7 +145,7 @@
 	$editable_extensions = (array) apply_filters( 'editable_extensions', $editable_extensions );
 
 	if ( ! is_file($real_file) ) {
-		wp_die(sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.')));
+		wp_die(  __( 'No such file exists! Double check the name and try again.' ) );
 	} else {
 		// Get the extension of the file
 		if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) {
@@ -122,7 +152,7 @@
 			$ext = strtolower($matches[1]);
 			// If extension is not in the acceptable list, skip it
 			if ( !in_array( $ext, $editable_extensions) )
-				wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.')));
+				wp_die( __( 'Files of this type are not editable.' ) );
 		}
 	}
 
@@ -147,7 +177,7 @@
 
 	require_once(ABSPATH . 'wp-admin/admin-header.php');
 
-	update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
+	update_recently_edited( WP_PLUGIN_DIR . '/' . $plugin );
 
 	$content = file_get_contents( $real_file );
 
@@ -166,14 +196,14 @@
 
 	$content = esc_textarea( $content );
 	?>
-<?php if (isset($_GET['a'])) : ?>
+<?php if ( isset( $_GET['updated'] ) ) : ?>
  <div id="message" class="updated notice is-dismissible"><p><?php _e('File edited successfully.') ?></p></div>
 <?php elseif (isset($_GET['phperror'])) : ?>
  <div id="message" class="updated"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p>
 	<?php
-		if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?>
-	<iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&amp;plugin=<?php echo esc_attr($file); ?>&amp;_wpnonce=<?php echo esc_attr($_GET['_error_nonce']); ?>"></iframe>
-	<?php } ?>
+	if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin ) ) : ?>
+		<iframe style="border:0" width="100%" height="70px" src="<?php echo self_admin_url('plugins.php?action=error_scrape&plugin=' . urlencode($plugin) . '&_wpnonce=' . urlencode($_GET['_error_nonce']) ); ?>"></iframe>
+	<?php endif; ?>
 </div>
 <?php endif; ?>
 <div class="wrap">
@@ -182,7 +212,7 @@
 <div class="fileedit-sub">
 <div class="alignleft">
 <big><?php
-	if ( is_plugin_active( $plugin ) ) {
+	if ( is_plugin_active( $plugin ) || is_plugin_active_for_network( $plugin ) ) {
 		if ( is_writeable( $real_file ) ) {
 			/* translators: %s: plugin file name */
 			echo sprintf( __( 'Editing %s (active)' ), '<strong>' . $file . '</strong>' );
@@ -257,9 +287,9 @@
 		<div id="documentation" class="hide-if-no-js"><label for="docs-list"><?php _e('Documentation:') ?></label> <?php echo $docs_select ?> <input type="button" class="button" value="<?php esc_attr_e( 'Look Up' ) ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&amp;locale=<?php echo urlencode( get_locale() ) ?>&amp;version=<?php echo urlencode( $wp_version ) ?>&amp;redirect=true'); }" /></div>
 		<?php endif; ?>
 <?php if ( is_writeable($real_file) ) : ?>
-	<?php if ( in_array( $file, (array) get_option( 'active_plugins', array() ) ) ) { ?>
+	<?php if ( is_plugin_active( $plugin ) || is_plugin_active_for_network( $plugin ) ) : ?>
 		<p><?php _e('<strong>Warning:</strong> Making changes to active plugins is not recommended. If your changes cause a fatal error, the plugin will be automatically deactivated.'); ?></p>
-	<?php } ?>
+	<?php endif; ?>
 	<p class="submit">
 	<?php
 		if ( isset($_GET['phperror']) ) {
