Make WordPress Core

Changeset 10476


Ignore:
Timestamp:
02/01/2009 09:45:24 AM (16 years ago)
Author:
azaozz
Message:

Detect when the server compresses output, see #8628

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r10475 r10476  
    4646
    4747    $s = $_GET['q']; // is this slashed already?
    48    
     48
    4949    if ( isset($_GET['tax']) )
    5050        $taxonomy = sanitize_title($_GET['tax']);
     
    6868    if ( !current_user_can( 'manage_options' ) )
    6969        die('-1');
    70    
    71     if ( isset($_GET['tested']) ) {
    72         if ( 1 == $_GET['tested'] )
     70
     71    if ( ini_get('zlib.output_compression') || 'ob_gzhandler' == ini_get('output_handler') ) {
     72        update_option('can_compress_scripts', 0);
     73        die('0');
     74    }
     75
     76    if ( isset($_GET['test']) ) {
     77        header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
     78        header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
     79        header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
     80        header( 'Pragma: no-cache' );
     81        header('Content-Type: application/x-javascript; charset=UTF-8');
     82        $force_gzip = ( defined('ENFORCE_GZIP') && ENFORCE_GZIP );
     83        $test_str = '"wpCompressionTest Lorem ipsum dolor sit amet consectetuer mollis sapien urna ut a. Eu nonummy condimentum fringilla tempor pretium platea vel nibh netus Maecenas. Hac molestie amet justo quis pellentesque est ultrices interdum nibh Morbi. Cras mattis pretium Phasellus ante ipsum ipsum ut sociis Suspendisse Lorem. Ante et non molestie. Porta urna Vestibulum egestas id congue nibh eu risus gravida sit. Ac augue auctor Ut et non a elit massa id sodales. Elit eu Nulla at nibh adipiscing mattis lacus mauris at tempus. Netus nibh quis suscipit nec feugiat eget sed lorem et urna. Pellentesque lacus at ut massa consectetuer ligula ut auctor semper Pellentesque. Ut metus massa nibh quam Curabitur molestie nec mauris congue. Volutpat molestie elit justo facilisis neque ac risus Ut nascetur tristique. Vitae sit lorem tellus et quis Phasellus lacus tincidunt nunc Fusce. Pharetra wisi Suspendisse mus sagittis libero lacinia Integer consequat ac Phasellus. Et urna ac cursus tortor aliquam Aliquam amet tellus volutpat Vestibulum. Justo interdum condimentum In augue congue tellus sollicitudin Quisque quis nibh."';
     84
     85         if ( 1 == $_GET['test'] ) {
     86            echo $test_str;
     87            die;
     88         } elseif ( 2 == $_GET['test'] ) {
     89            if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) {
     90                header('Content-Encoding: deflate');
     91                $out = gzdeflate( $test_str, 1 );
     92            } elseif ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') && function_exists('gzencode') ) {
     93                header('Content-Encoding: gzip');
     94                $out = gzencode( $test_str, 1 );
     95            } else {
     96                die('-1');
     97            }
     98            echo $out;
     99            die;
     100        } elseif ( 'no' == $_GET['test'] ) {
     101            update_option('can_compress_scripts', 0);
     102        } elseif ( 'yes' == $_GET['test'] ) {
    73103            update_option('can_compress_scripts', 1);
    74         elseif ( 0 == $_GET['tested'] )
    75             update_option('can_compress_scripts', 0);
    76     }
     104        }
     105    }
     106
    77107    die('0');
    78108    break;
     
    515545    else
    516546        die('0');
    517    
     547
    518548    $tags = get_terms( $taxonomy, array( 'number' => 45, 'orderby' => 'count', 'order' => 'DESC' ) );
    519549
  • trunk/wp-admin/includes/schema.php

    r10200 r10476  
    304304
    305305    // Delete unused options
    306     $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing', 'autosave_interval', 'deactivated_plugins');
     306    $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing', 'autosave_interval', 'deactivated_plugins', 'can_compress_scripts');
    307307    foreach ($unusedoptions as $option) :
    308308        delete_option($option);
  • trunk/wp-admin/includes/template.php

    r10451 r10476  
    18171817    $numposts = get_usernumposts( $user_object->ID );
    18181818    $checkbox = '';
    1819     // Check if the user for this row is editable 
     1819    // Check if the user for this row is editable
    18201820    if ( current_user_can( 'edit_user', $user_object->ID ) ) {
    1821         // Set up the user editing link 
     1821        // Set up the user editing link
    18221822        // TODO: make profile/user-edit determination a seperate function
    18231823        if ($current_user->ID == $user_object->ID) {
     
    18271827        }
    18281828        $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />";
    1829        
     1829
    18301830        // Set up the hover actions for this user
    18311831        $actions = array();
     
    18421842        }
    18431843        $edit .= '</div>';
    1844        
     1844
    18451845        // Set up the checkbox (because the user is editable, otherwise its empty)
    18461846        $checkbox = "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' />";
    1847        
     1847
    18481848    } else {
    18491849        $edit = '<strong>' . $user_object->user_login . '</strong>';
     
    19231923    $count = wp_count_comments();
    19241924    $index = '';
    1925    
     1925
    19261926    if ( 'moderated' == $status ) {
    19271927        $approved = "comment_approved = '0'";
     
    26162616}
    26172617
    2618  
     2618
    26192619/**
    26202620 * Print out <option> html elements for role selectors based on $wp_roles
     
    26312631    $p = '';
    26322632    $r = '';
    2633    
     2633
    26342634    $editable_roles = get_editable_roles();
    2635    
     2635
    26362636    foreach( $editable_roles as $role => $details ) {
    26372637        $name = translate_with_context($details['name']);
     
    34033403 * and sets an option with the result. Has no effect when the current user
    34043404 * is not an administrator. To run the test again the option 'can_compress_scripts'
    3405  * has to be deleted. 
     3405 * has to be deleted.
    34063406 *
    34073407 * @since 2.8.0
     
    34093409function compression_test() {
    34103410?>
    3411     <script type="text/javascript" src="load-scripts.php?test=1<?php echo ( defined('ENFORCE_GZIP') && ENFORCE_GZIP ) ? '&c=gzip' : ''; ?>"></script>
    34123411    <script type="text/javascript">
    34133412    /* <![CDATA[ */
    3414     (function() {
    3415         var x, test = typeof wpCompressionTest == 'undefined' ? 0 : 1;
    3416         if ( window.XMLHttpRequest ) {
    3417             x = new XMLHttpRequest();
    3418         } else {
    3419             try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
     3413    var testCompression = {
     3414        get : function(test) {
     3415            var x;
     3416            if ( window.XMLHttpRequest ) {
     3417                x = new XMLHttpRequest();
     3418            } else {
     3419                try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
     3420            }
     3421
     3422            if (x) {
     3423                x.onreadystatechange = function() {
     3424                    var r, h;
     3425                    if ( x.readyState == 4 ) {
     3426                        r = x.responseText.substr(0, 18);
     3427                        h = x.getResponseHeader('Content-Encoding');
     3428                        testCompression.check(r, h, test);
     3429                    }
     3430                }
     3431
     3432                x.open('GET', 'admin-ajax.php?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true);
     3433                x.send('');
     3434            }
     3435        },
     3436
     3437        check : function(r, h, test) {
     3438            if ( ! r && ! test )
     3439                this.get(1);
     3440
     3441            if ( 1 == test ) {
     3442                if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
     3443                    this.get('no');
     3444                else
     3445                    this.get(2);
     3446
     3447                return;
     3448            }
     3449
     3450            if ( 2 == test ) {
     3451                if ( '"wpCompressionTest' == r )
     3452                    this.get('yes');
     3453                else
     3454                    this.get('no');
     3455            }
    34203456        }
    3421    
    3422         if (x) {
    3423             x.open('GET', 'admin-ajax.php?action=wp-compression-test&tested='+test+'&'+(new Date()).getTime(), true);
    3424             x.send('');
    3425         }
    3426     })();
     3457    };
     3458    testCompression.check();
    34273459    /* ]]> */
    34283460    </script>
  • trunk/wp-admin/load-scripts.php

    r10466 r10476  
    8686}
    8787
    88 // Discard any buffers
    89 while ( @ob_end_clean() );
    90 
    91 if ( isset($_GET['test']) && 1 == $_GET['test'] ) {
    92     if ( ini_get('zlib.output_compression') || 'ob_gzhandler' == ini_get('output_handler') )
    93         exit('');
    94 
    95     $out = 'var wpCompressionTest = 1;';
    96     $force_gzip = ( isset($_GET['c']) && 'gzip' == $_GET['c'] );
    97 
    98     if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) {
    99         header('Content-Encoding: deflate');
    100         $out = gzdeflate( $out, 3 );
    101     } elseif ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') && function_exists('gzencode') ) {
    102         header('Content-Encoding: gzip');
    103         $out = gzencode( $out, 3 );
    104     } else {
    105         exit('');
    106     }
    107 
    108     header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
    109     header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
    110     header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
    111     header( 'Pragma: no-cache' );
    112     header( 'Content-Type: application/x-javascript; charset=UTF-8' );
    113     echo $out;
    114     exit;
    115 }
    116 
    117 $load = preg_replace( '/[^a-z0-9,_-]*/i', '', $_GET['load'] );
     88$load = preg_replace( '/[^a-z0-9,_-]+/i', '', $_GET['load'] );
    11889$load = explode(',', $load);
    11990
     
    143114header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT');
    144115header("Cache-Control: public, max-age=$expires_offset");
    145    
     116
    146117if ( $compress && ! ini_get('zlib.output_compression') && 'ob_gzhandler' != ini_get('output_handler') ) {
    147118    header('Vary: Accept-Encoding'); // Handle proxies
  • trunk/wp-admin/load-styles.php

    r10466 r10476  
    8989require(ABSPATH . '/wp-includes/version.php');
    9090
    91 // Discard any buffers
    92 while ( @ob_end_clean() );
    93 
    94 $load = preg_replace( '/[^a-z0-9,_-]*/i', '', $_GET['load'] );
     91$load = preg_replace( '/[^a-z0-9,_-]+/i', '', $_GET['load'] );
    9592$load = explode(',', $load);
    9693
     
    127124header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT');
    128125header("Cache-Control: public, max-age=$expires_offset");
    129    
     126
    130127if ( $compress && ! ini_get('zlib.output_compression') && 'ob_gzhandler' != ini_get('output_handler') ) {
    131128    header('Vary: Accept-Encoding'); // Handle proxies
  • trunk/wp-includes/js/tinymce/wp-tinymce.php

    r10372 r10476  
    22
    33$basepath = dirname(__FILE__);
    4 
    5 while ( @ob_end_clean() );
    64
    75function get_file($path) {
     
    2321header("Cache-Control: public, max-age=$expires_offset");
    2422
    25 if ( isset($_GET['c']) && 1 == $_GET['c'] && ! ini_get('zlib.output_compression') && false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') ) {
     23if ( isset($_GET['c']) && 1 == $_GET['c'] && false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') ) {
    2624    header('Content-Encoding: gzip');
    2725    echo get_file($basepath . '/wp-tinymce.js.gz');
  • trunk/wp-includes/script-loader.php

    r10457 r10476  
    617617
    618618    global $wp_scripts;
    619    
     619
    620620    if ( !is_a($wp_scripts, 'WP_Scripts') )
    621621        return array(); // no need to run if nothing is queued
    622    
     622
    623623    return print_head_scripts();
    624624}
     
    635635/**
    636636 * Wrapper for do_action('wp_enqueue_scripts')
    637  * 
     637 *
    638638 * Allows plugins to queue scripts for the front end using wp_enqueue_script().
    639639 * Runs first in wp_head() where all is_home(), is_page(), etc. functions are available.
     
    679679    global $concatenate_scripts, $compress_scripts, $compress_css;
    680680
     681    $compressed_output = ( ini_get('zlib.output_compression') || 'ob_gzhandler' == ini_get('output_handler') );
     682
    681683    if ( ! isset($concatenate_scripts) ) {
    682684        $concatenate_scripts = defined('CONCATENATE_SCRIPTS') ? CONCATENATE_SCRIPTS : true;
     
    687689    if ( ! isset($compress_scripts) ) {
    688690        $compress_scripts = defined('COMPRESS_SCRIPTS') ? COMPRESS_SCRIPTS : true;
    689         if ( $compress_scripts && ! get_option('can_compress_scripts') )
     691        if ( $compress_scripts && ( ! get_option('can_compress_scripts') || $compressed_output ) )
    690692            $compress_scripts = false;
    691693    }
     
    693695    if ( ! isset($compress_css) ) {
    694696        $compress_css = defined('COMPRESS_CSS') ? COMPRESS_CSS : true;
    695         if ( $compress_css && ! get_option('can_compress_scripts') )
     697        if ( $compress_css && ( ! get_option('can_compress_scripts') || $compressed_output ) )
    696698            $compress_css = false;
    697699    }
  • trunk/wp-includes/version.php

    r10219 r10476  
    1616 * @global int $wp_db_version
    1717 */
    18 $wp_db_version = 9872;
     18$wp_db_version = 9873;
    1919
    2020?>
Note: See TracChangeset for help on using the changeset viewer.