Make WordPress Core

Ticket #17552: 17552.patch

File 17552.patch, 7.4 KB (added by dd32, 13 years ago)
  • wp-admin/plugin-editor.php

     
    2020$title = __("Edit Plugins");
    2121$parent_file = 'plugins.php';
    2222
    23 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'plugin'));
     23wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'updated', 'file', 'plugin'));
    2424
    2525wp_admin_css( 'theme-editor' );
    2626
     
    2929if ( empty($plugins) )
    3030        wp_die( __('There are no plugins installed on this site.') );
    3131
    32 if ( isset($_REQUEST['file']) )
    33         $plugin = stripslashes($_REQUEST['file']);
    34 
    3532if ( empty($plugin) ) {
    36         $plugin = array_keys($plugins);
    37         $plugin = $plugin[0];
     33        if ( ! empty($file) ) {
     34                $plugin = $file;
     35        } else {
     36                $plugin = array_keys($plugins);
     37                $plugin = $plugin[0];
     38        }
    3839}
    3940
    4041$plugin_files = get_plugin_files($plugin);
     
    5455
    5556        check_admin_referer('edit-plugin_' . $file);
    5657
    57         $newcontent = stripslashes($_POST['newcontent']);
    5858        if ( is_writeable($real_file) ) {
    59                 $f = fopen($real_file, 'w+');
    60                 fwrite($f, $newcontent);
    61                 fclose($f);
     59                $newcontent = stripslashes($_POST['newcontent']);
    6260
    63                 $network_wide = is_plugin_active_for_network( $file );
     61                file_put_contents($real_file, $newcontent);
    6462
     63                $network_wide = is_plugin_active_for_network( $plugin );
     64// @TODO: Network Wide activated plugins do not go through this lint check
    6565                // Deactivate so we can test it.
    66                 if ( is_plugin_active($file) || isset($_POST['phperror']) ) {
    67                         if ( is_plugin_active($file) )
    68                                 deactivate_plugins($file, true);
     66                if ( is_plugin_active($plugin) || isset($_POST['phperror']) ) {
     67                        if ( is_plugin_active($plugin) )
     68                                deactivate_plugins($plugin, true);
    6969
    70                         update_option('recently_activated', array($file => time()) + (array)get_option('recently_activated'));
     70                        update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated'));
    7171
    72                         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));
     72                        wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&plugin=$plugin&liveupdate=1&scrollto=$scrollto&networkwide=" . $network_wide));
    7373                        exit;
    7474                }
    75                 wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") );
     75                wp_redirect( self_admin_url("plugin-editor.php?file=$file&plugin=$plugin&updated=1&scrollto=$scrollto") );
    7676        } else {
    77                 wp_redirect( self_admin_url("plugin-editor.php?file=$file&scrollto=$scrollto") );
     77                wp_redirect( self_admin_url("plugin-editor.php?file=$file&plugin=$plugin&scrollto=$scrollto") );
    7878        }
    7979        exit;
    8080
     
    8585        if ( isset($_GET['liveupdate']) ) {
    8686                check_admin_referer('edit-plugin-test_' . $file);
    8787
    88                 $error = validate_plugin($file);
     88                $error = validate_plugin($plugin);
    8989                if ( is_wp_error($error) )
    9090                        wp_die( $error );
    9191
    92                 if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network($file) ) || ! is_plugin_active($file) )
    93                         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
     92                if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network($plugin) ) || ! is_plugin_active($plugin) )
     93                        activate_plugin($plugin, "plugin-editor.php?file=$file&plugin=$plugin&phperror=1", ! empty( $_GET['networkwide'] ) ); // we'll override this later if the plugin can be included without fatal error
    9494
    95                 wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") );
     95                wp_redirect( self_admin_url("plugin-editor.php?file=$file&plugin=$plugin&updated=1&scrollto=$scrollto") );
    9696                exit;
    9797        }
    9898
     
    101101        $editable_extensions = (array) apply_filters('editable_extensions', $editable_extensions);
    102102
    103103        if ( ! is_file($real_file) ) {
    104                 wp_die(sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.')));
     104                wp_die( __('No such file exists! Double check the name and try again.') );
    105105        } else {
    106106                // Get the extension of the file
    107107                if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) {
    108108                        $ext = strtolower($matches[1]);
    109109                        // If extension is not in the acceptable list, skip it
    110110                        if ( !in_array( $ext, $editable_extensions) )
    111                                 wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.')));
     111                                wp_die( __('Files of this type are not editable.') );
    112112                }
    113113        }
    114114
     
    136136                if ( !empty($functions) ) {
    137137                        $docs_select = '<select name="docs-list" id="docs-list">';
    138138                        $docs_select .= '<option value="">' . __( 'Function Name&hellip;' ) . '</option>';
    139                         foreach ( $functions as $function) {
     139                        foreach ( $functions as $function ) {
    140140                                $docs_select .= '<option value="' . esc_attr( $function ) . '">' . esc_html( $function ) . '()</option>';
    141141                        }
    142142                        $docs_select .= '</select>';
     
    145145
    146146        $content = esc_textarea( $content );
    147147        ?>
    148 <?php if (isset($_GET['a'])) : ?>
     148<?php if (isset($_GET['updated'])) : ?>
    149149 <div id="message" class="updated"><p><?php _e('File edited successfully.') ?></p></div>
    150150<?php elseif (isset($_GET['phperror'])) : ?>
    151151 <div id="message" class="updated"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p>
    152152        <?php
    153                 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?>
    154         <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>
     153                if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) ) { ?>
     154                //@TODO: Is this Network Admin safe? (admin_url())
     155        <iframe style="border:0" width="100%" height="70px" src="<?php echo admin_url('plugins.php?action=error_scrape&plugin=' . urlencode($plugin) . '&_wpnonce=' . urlencode($_GET['_error_nonce']) ); ?>"></iframe>
    155156        <?php } ?>
    156157</div>
    157158<?php endif; ?>
     
    162163<div class="fileedit-sub">
    163164<div class="alignleft">
    164165<big><?php
    165         if ( is_plugin_active($plugin) ) {
     166        if ( is_plugin_active($plugin) || is_plugin_active_for_network($plugin) ) {
    166167                if ( is_writeable($real_file) )
    167168                        echo sprintf(__('Editing <strong>%s</strong> (active)'), $file);
    168169                else
     
    231232                <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( 'Lookup' ) ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'http://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>
    232233                <?php endif; ?>
    233234<?php if ( is_writeable($real_file) ) : ?>
    234         <?php if ( in_array( $file, (array) get_option( 'active_plugins', array() ) ) ) { ?>
     235        <?php if ( is_plugin_active($plugin) || is_plugin_active_for_network($plugin) ) { ?>
    235236                <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>
    236237        <?php } ?>
    237238        <p class="submit">