Ticket #23601: 23601.diff

File 23601.diff, 12.4 KB (added by wonderboymusic, 3 months ago)
  • wp-admin/css/wp-admin.css

    diff --git wp-admin/css/wp-admin.css wp-admin/css/wp-admin.css
    index 7ca3745..8033047 100644
    body.full-overlay-active { 
    58475847        width: 98%; 
    58485848} 
    58495849 
    5850 #template div { 
    5851         margin-right: 190px; 
    5852 } 
    5853  
    58545850p.pagenav { 
    58555851        margin: 0; 
    58565852        display: inline; 
    h3 span { 
    79217917        font-weight: normal; 
    79227918} 
    79237919 
    7924 #template textarea { 
    7925         font-family: Consolas, Monaco, monospace; 
    7926         font-size: 12px; 
    7927         width: 97%; 
    7928         background: #f9f9f9; 
    7929         outline: none; 
     7920#wp-ace-editor { 
     7921        position: relative; 
     7922        width: 75%; 
     7923        height: 400px; 
     7924        margin-right: 190px; 
     7925} 
     7926 
     7927#newcontent { 
     7928        display: none; 
     7929} 
     7930 
     7931#editor-mods { 
     7932        margin-bottom: 10px; 
    79307933} 
    79317934 
    79327935#template p { 
  • new file wp-admin/includes/code-editor.php

    diff --git wp-admin/includes/code-editor.php wp-admin/includes/code-editor.php
    new file mode 100644
    index 0000000..3d6e593
    - +  
     1<?php 
     2$editor_modes = array( 
     3        'asciidoc' => 'ASCII Doc', 
     4        'c_cpp' => 'C/C++', 
     5        'clojure' => 'Clojure', 
     6        'coffee' => 'CoffeeScript', 
     7        'coldfusion' => 'ColdFusion', 
     8        'csharp' => 'C#', 
     9        'css' => '', 
     10        'curly' => 'Curly', 
     11        'dart' => 'Dart', 
     12        'diff' => 'Difference', 
     13        'django' => 'Django', 
     14        'dot' => 'Dot', 
     15        'golang' => 'Go', 
     16        'groovy' => 'Groovy', 
     17        'haml' => '', 
     18        'haxe' => 'Haxe', 
     19        'html' => '', 
     20        'jade' => 'Jade', 
     21        'java' => 'Java', 
     22        'javascript' => 'JavaScript', 
     23        'json' => '', 
     24        'jsp' => '', 
     25        'jsx' => '', 
     26        'latex' => 'Latex', 
     27        'less' => '', 
     28        'liquid' => 'Liquid', 
     29        'lisp' => 'Lisp', 
     30        'livescript' => 'LiveScript', 
     31        'lua' => 'Lua', 
     32        'luapage' => 'Lua Page', 
     33        'lucene' => 'Lucene', 
     34        'makefile' => 'Makefile', 
     35        'markdown' => 'Markdown', 
     36        'objectivec' => 'Objective-C', 
     37        'ocaml' => 'OCaml', 
     38        'perl' => 'Perl', 
     39        'pgsql' => 'PL/pgSQL', 
     40        'php' => '', 
     41        'powershell' => 'PowerShell', 
     42        'python' => 'Python', 
     43        'r' => '', 
     44        'rdoc' => 'RDoc', 
     45        'rhtml' => '', 
     46        'ruby' => 'Ruby', 
     47        'scad' => '', 
     48        'scala' => 'Scala', 
     49        'scheme' => 'Scheme', 
     50        'scss' => '', 
     51        'sh' => 'Shell', 
     52        'sql' => '', 
     53        'stylus' => 'Stylus', 
     54        'svg' => '', 
     55        'tcl' => '', 
     56        'tex' => 'TeX', 
     57        'text' => 'Text', 
     58        'textile' => 'Textile', 
     59        'tm_snippet' => 'Textmate Snippet', 
     60        'typescript' => 'TypeScript', 
     61        'vbscript' => 'VBScript', 
     62        'xml' => '', 
     63        'xquery' => 'XQuery', 
     64        'yaml' => '' 
     65); 
     66 
     67$editor_themes = array( 
     68        'chaos', 'chrome', 'clouds', 'clouds_midnight', 'cobalt', 'crimson_editor', 
     69        'dawn', 'dreamweaver', 'eclipse', 'github', 'idle_fingers', 
     70        'kr', 'merbivore', 'mono_industrial', 'monokai', 'pastel_on_dark', 
     71        'solarized_dark', 'solarized_light', 'textmate', 'tomorrow', 
     72        'tomorrow_night', 'tomorrow_night_blue', 'tomorrow_night_bright', 'tomorrow_night_eighties', 
     73        'twilight', 'vibrant_link', 'xcode' 
     74); 
     75 
     76$current_mode = ''; 
     77if ( ! empty( $_GET['editor-mode'] ) ) 
     78        $current_mode = $_GET['editor-mode']; 
     79 
     80if ( ! empty( $file ) ) { 
     81        $filetype = wp_check_filetype( $file ); 
     82        if ( empty( $filetype['ext'] ) && '.php' === substr( $file, -4 ) ) { 
     83                $current_mode = 'php'; 
     84        } elseif ( ! empty( $filetype['ext'] ) && in_array( $filetype['ext'], array_keys( $editor_modes ) ) ) { 
     85                $current_mode = $filetype['ext']; 
     86        } 
     87} 
     88?> 
     89<form id="editor-mods"> 
     90        <select name="editor-theme"> 
     91                <option value="">- <?php _e( 'Code Editor Theme' ) ?> -</option> 
     92                <?php foreach ( $editor_themes as $editor_theme ): ?> 
     93                <option <?php selected( ! empty( $_GET['editor-theme'] ) && $_GET['editor-theme'] === $editor_theme ) ?> value="<?php echo $editor_theme ?>"> 
     94                        <?php echo ucwords( str_replace( '_', ' ', $editor_theme ) ) ?> 
     95                </option> 
     96                <?php endforeach ?> 
     97        </select> 
     98        <select name="editor-mode"> 
     99                <option value="">- <?php _e( 'Code Editor Mode' ) ?> -</option> 
     100                <?php foreach ( $editor_modes as $editor_mode => $label ): ?> 
     101                <option <?php selected( ! empty( $current_mode ) && $editor_mode === $current_mode ); 
     102                        ?> value="<?php echo $editor_mode ?>"><?php 
     103                        if ( empty( $label ) ) 
     104                                echo strtoupper( $editor_mode ); 
     105                        else 
     106                                echo $label; 
     107                        ?></option> 
     108                <?php endforeach ?> 
     109        </select> 
     110        <input type="submit" class="button" value="<?php esc_attr_e( 'Update Editor' ) ?>" /> 
     111</form> 
     112 No newline at end of file 
  • wp-admin/plugin-editor.php

    diff --git wp-admin/plugin-editor.php wp-admin/plugin-editor.php
    index 122362a..395577d 100644
    $file = validate_file_to_edit($file, $plugin_files); 
    4444$real_file = WP_PLUGIN_DIR . '/' . $file; 
    4545$scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0; 
    4646 
     47$editor_mods = ''; 
     48if ( ! empty( $_REQUEST['editor-theme'] ) || ! empty( $_REQUEST['editor-mode'] ) ) { 
     49        if ( ! empty( $_REQUEST['editor-theme'] ) ) 
     50                $editor_mods .= '&editor-theme=' . $_REQUEST['editor-theme']; 
     51        if ( ! empty( $_REQUEST['editor-mode'] ) ) 
     52                $editor_mods .= '&editor-mode=' . $_REQUEST['editor-mode']; 
     53} 
     54 
    4755switch ( $action ) { 
    4856 
    4957case 'update': 
    case 'update': 
    6977                        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)); 
    7078                        exit; 
    7179                } 
    72                 wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") ); 
     80                wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto$editor_mods") ); 
    7381        } else { 
    74                 wp_redirect( self_admin_url("plugin-editor.php?file=$file&scrollto=$scrollto") ); 
     82                wp_redirect( self_admin_url("plugin-editor.php?file=$file&scrollto=$scrollto$editor_mods") ); 
    7583        } 
    7684        exit; 
    7785 
    default: 
    8997                if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network($file) ) || ! is_plugin_active($file) ) 
    9098                        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 
    9199 
    92                 wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") ); 
     100                wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto$editor_mods") ); 
    93101                exit; 
    94102        } 
    95103 
    default: 
    109117                } 
    110118        } 
    111119 
     120        wp_enqueue_script( 'wp-ace' ); 
     121 
    112122        get_current_screen()->add_help_tab( array( 
    113123        'id'            => 'overview', 
    114124        'title'         => __('Overview'), 
    foreach ( $plugin_files as $plugin_file ) : 
    218228                // No extension found 
    219229                continue; 
    220230        } 
     231 
     232        $url = sprintf( 'plugin-editor.php?file=%s&amp;plugin=%s', urlencode( $plugin_file ), urlencode( $plugin ) ); 
     233        if ( ! empty( $_GET['editor-theme'] ) ) 
     234                $url .= '&amp;editor-theme=' . urlencode( $_GET['editor-theme'] ); 
     235        if ( ! empty( $_GET['editor-mode'] ) ) 
     236                $url .= '&amp;editor-mode=' . urlencode( $_GET['editor-mode'] ); 
    221237?> 
    222                 <li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="plugin-editor.php?file=<?php echo urlencode( $plugin_file ) ?>&amp;plugin=<?php echo urlencode( $plugin ) ?>"><?php echo $plugin_file ?></a></li> 
     238                <li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="<?php echo $url ?>"><?php echo $plugin_file ?></a></li> 
    223239<?php endforeach; ?> 
    224240        </ul> 
    225241</div> 
     242 
     243<?php include( ABSPATH . 'wp-admin/includes/code-editor.php' );  ?> 
     244 
    226245<form name="template" id="template" action="plugin-editor.php" method="post"> 
    227246        <?php wp_nonce_field('edit-plugin_' . $file) ?> 
    228                 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" aria-describedby="newcontent-description"><?php echo $content; ?></textarea> 
     247                <div id="wp-ace-editor" data-theme="<?php 
     248                        if ( ! empty( $_GET['editor-theme'] ) ) 
     249                                echo $_GET['editor-theme']; 
     250                ?>" data-mode="<?php echo $current_mode ?>"><?php echo $content; ?></div> 
     251                <textarea id="newcontent" name="newcontent"><?php echo $content; ?></textarea> 
    229252                <input type="hidden" name="action" value="update" /> 
     253                <?php if ( ! empty( $_GET['editor-theme'] ) ): ?> 
     254                <input type="hidden" name="editor-theme" value="<?php echo esc_attr( $_GET['editor-theme'] ) ?>" /> 
     255                <?php endif ?> 
     256                <?php if ( ! empty( $_GET['editor-mode'] ) ): ?> 
     257                <input type="hidden" name="editor-mode" value="<?php echo esc_attr( $_GET['editor-mode'] ) ?>" /> 
     258                <?php endif ?> 
    230259                <input type="hidden" name="file" value="<?php echo esc_attr($file) ?>" /> 
    231260                <input type="hidden" name="plugin" value="<?php echo esc_attr($plugin) ?>" /> 
    232261                <input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" /> 
  • wp-admin/theme-editor.php

    diff --git wp-admin/theme-editor.php wp-admin/theme-editor.php
    index 2033a23..2277d5f 100644
    if ( empty( $file ) ) { 
    7575validate_file_to_edit( $file, $allowed_files ); 
    7676$scrollto = isset( $_REQUEST['scrollto'] ) ? (int) $_REQUEST['scrollto'] : 0; 
    7777 
     78$editor_mods = ''; 
     79if ( ! empty( $_REQUEST['editor-theme'] ) || ! empty( $_REQUEST['editor-mode'] ) ) { 
     80        if ( ! empty( $_REQUEST['editor-theme'] ) ) 
     81                $editor_mods .= '&editor-theme=' . $_REQUEST['editor-theme']; 
     82        if ( ! empty( $_REQUEST['editor-mode'] ) ) 
     83                $editor_mods .= '&editor-mode=' . $_REQUEST['editor-mode']; 
     84} 
     85 
    7886switch( $action ) { 
    7987case 'update': 
    8088        check_admin_referer( 'edit-theme_' . $file . $stylesheet ); 
    8189        $newcontent = wp_unslash( $_POST['newcontent'] ); 
    82         $location = 'theme-editor.php?file=' . urlencode( $relative_file ) . '&theme=' . urlencode( $stylesheet ) . '&scrollto=' . $scrollto; 
     90        $location = 'theme-editor.php?file=' . urlencode( $relative_file ) . '&theme=' . urlencode( $stylesheet ) . '&scrollto=' . $scrollto . $editor_mods; 
    8391        if ( is_writeable( $file ) ) { 
    8492                //is_writable() not always reliable, check return value. see comments @ http://uk.php.net/is_writable 
    8593                $f = fopen( $file, 'w+' ); 
    break; 
    96104 
    97105default: 
    98106 
     107        wp_enqueue_script( 'wp-ace' ); 
     108 
    99109        require_once( ABSPATH . 'wp-admin/admin-header.php' ); 
    100110 
    101111        update_recently_edited( $file ); 
    if ( $allowed_files ) : 
    186196 
    187197                if ( $absolute_filename == $file ) 
    188198                        $file_description = '<span class="highlight">' . $file_description . '</span>'; 
     199 
     200                $url = sprintf( 'theme-editor.php?file=%s&amp;theme=%s', urlencode( $filename ), urlencode( $stylesheet ) ); 
     201                if ( ! empty( $_GET['editor-theme'] ) ) 
     202                        $url .= '&amp;editor-theme=' . urlencode( $_GET['editor-theme'] ); 
     203                if ( ! empty( $_GET['editor-mode'] ) ) 
     204                        $url .= '&amp;editor-mode=' . urlencode( $_GET['editor-mode'] ); 
    189205?> 
    190                 <li><a href="theme-editor.php?file=<?php echo urlencode( $filename ) ?>&amp;theme=<?php echo urlencode( $stylesheet ) ?>"><?php echo $file_description; ?></a></li> 
     206                <li><a href="<?php echo $url ?>"><?php echo $file_description; ?></a></li> 
    191207<?php 
    192208        endforeach; 
    193209?> 
    if ( $allowed_files ) : 
    197213<?php if ( $error ) : 
    198214        echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>'; 
    199215else : ?> 
     216 
     217        <?php include( ABSPATH . 'wp-admin/includes/code-editor.php' ); ?> 
     218 
    200219        <form name="template" id="template" action="theme-editor.php" method="post"> 
    201220        <?php wp_nonce_field( 'edit-theme_' . $file . $stylesheet ); ?> 
    202                 <div><textarea cols="70" rows="30" name="newcontent" id="newcontent" aria-describedby="newcontent-description"><?php echo $content; ?></textarea> 
     221                <div id="wp-ace-editor" data-theme="<?php 
     222                        if ( ! empty( $_GET['editor-theme'] ) ) 
     223                                echo $_GET['editor-theme']; 
     224                ?>" data-mode="<?php echo $current_mode ?>"><?php echo $content; ?></div> 
     225                <textarea id="newcontent" name="newcontent"><?php echo $content; ?></textarea> 
    203226                <input type="hidden" name="action" value="update" /> 
     227                <?php if ( ! empty( $_GET['editor-theme'] ) ): ?> 
     228                <input type="hidden" name="editor-theme" value="<?php echo esc_attr( $_GET['editor-theme'] ) ?>" /> 
     229                <?php endif ?> 
     230                <?php if ( ! empty( $_GET['editor-mode'] ) ): ?> 
     231                <input type="hidden" name="editor-mode" value="<?php echo esc_attr( $_GET['editor-mode'] ) ?>" /> 
     232                <?php endif ?> 
    204233                <input type="hidden" name="file" value="<?php echo esc_attr( $relative_file ); ?>" /> 
    205234                <input type="hidden" name="theme" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" /> 
    206235                <input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" /> 
  • wp-includes/script-loader.php

    diff --git wp-includes/script-loader.php wp-includes/script-loader.php
    index cfb865e..26637bc 100644
    function wp_default_scripts( &$scripts ) { 
    197197                        'loadingAnimation' => includes_url('js/thickbox/loadingAnimation.gif'), 
    198198                        'closeImage' => includes_url('js/thickbox/tb-close.png') 
    199199        ) ); 
     200        $scripts->add( 'ace', "/wp-includes/js/ace/ace.js", array('jquery'), '1.0.0' ); 
     201        $scripts->add( 'wp-ace', "/wp-includes/js/wp-ace.js", array('ace'), '1.0.0' ); 
    200202 
    201203        $scripts->add( 'jcrop', "/wp-includes/js/jcrop/jquery.Jcrop.min.js", array('jquery'), '0.9.10'); 
    202204