Ticket #7011: 7011.diff

File 7011.diff, 47.2 KB (added by mdawaffe, 5 years ago)
  • wp-includes/default-filters.php

     
    175175add_action('do_robots', 'do_robots'); 
    176176add_action('sanitize_comment_cookies', 'sanitize_comment_cookies'); 
    177177add_action('admin_print_scripts', 'wp_print_scripts', 20); 
     178add_action('admin_print_styles', 'wp_print_styles', 20); 
    178179add_action('init', 'smilies_init', 5); 
    179180add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 ); 
    180181add_action( 'shutdown', 'wp_ob_end_flush_all', 1); 
  • wp-includes/functions.wp-scripts.php

     
     1<?php 
     2 
     3/** 
     4 * Prints script tags in document head 
     5 * 
     6 * Called by admin-header.php and by wp_head hook. Since it is called by wp_head on every page load, 
     7 * the function does not instantiate the WP_Scripts object unless script names are explicitly passed. 
     8 * Does make use of already instantiated $wp_scripts if present. 
     9 * Use provided wp_print_scripts hook to register/enqueue new scripts. 
     10 * 
     11 * @see WP_Scripts::print_scripts() 
     12 */ 
     13function wp_print_scripts( $handles = false ) { 
     14        do_action( 'wp_print_scripts' ); 
     15        if ( '' === $handles ) // for wp_head 
     16                $handles = false; 
     17 
     18        global $wp_scripts; 
     19        if ( !is_a($wp_scripts, 'WP_Scripts') ) { 
     20                if ( !$handles ) 
     21                        return array(); // No need to instantiate if nothing's there. 
     22                else 
     23                        $wp_scripts = new WP_Scripts(); 
     24        } 
     25 
     26        return $wp_scripts->do_items( $handles ); 
     27} 
     28 
     29function wp_register_script( $handle, $src, $deps = array(), $ver = false ) { 
     30        global $wp_scripts; 
     31        if ( !is_a($wp_scripts, 'WP_Scripts') ) 
     32                $wp_scripts = new WP_Scripts(); 
     33 
     34        $wp_scripts->add( $handle, $src, $deps, $ver ); 
     35} 
     36 
     37/** 
     38 * Localizes a script 
     39 * 
     40 * Localizes only if script has already been added 
     41 * 
     42 * @see WP_Script::localize() 
     43 */ 
     44function wp_localize_script( $handle, $object_name, $l10n ) { 
     45        global $wp_scripts; 
     46        if ( !is_a($wp_scripts, 'WP_Scripts') ) 
     47                return false; 
     48 
     49        return $wp_scripts->localize( $handle, $object_name, $l10n ); 
     50} 
     51 
     52function wp_deregister_script( $handle ) { 
     53        global $wp_scripts; 
     54        if ( !is_a($wp_scripts, 'WP_Scripts') ) 
     55                $wp_scripts = new WP_Scripts(); 
     56 
     57        $wp_scripts->remove( $handle ); 
     58} 
     59 
     60/** 
     61 * Equeues script 
     62 * 
     63 * Registers the script if src provided (does NOT overwrite) and enqueues. 
     64 * 
     65 * @see WP_Script::add(), WP_Script::enqueue() 
     66*/ 
     67function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false ) { 
     68        global $wp_scripts; 
     69        if ( !is_a($wp_scripts, 'WP_Scripts') ) 
     70                $wp_scripts = new WP_Scripts(); 
     71 
     72        if ( $src ) { 
     73                $_handle = explode('?', $handle); 
     74                $wp_scripts->add( $_handle[0], $src, $deps, $ver ); 
     75        } 
     76        $wp_scripts->enqueue( $handle ); 
     77} 
  • wp-includes/class.wp-styles.php

     
     1<?php 
     2 
     3class WP_Styles extends WP_Dependencies { 
     4        var $base_url; 
     5        var $default_version; 
     6 
     7        function __construct() { 
     8                do_action_ref_array( 'wp_default_styles', array(&$this) ); 
     9        } 
     10 
     11        function do_item( $handle ) { 
     12                if ( !parent::do_item($handle) ) 
     13                        return false; 
     14 
     15                $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; 
     16                if ( isset($this->args[$handle]) ) 
     17                        $ver .= '&amp;' . $this->args[$handle]; 
     18 
     19                if ( isset($this->registered[$handle]->args) ) 
     20                        $media = attribute_escape( $this->registered[$handle]->args ); 
     21                else 
     22                        $media = 'all'; 
     23 
     24                $src = $this->registered[$handle]->src; 
     25                if ( !preg_match('|^https?://|', $src) ) { 
     26                        $src = $this->base_url . $src; 
     27                } 
     28 
     29                $src = add_query_arg('ver', $ver, $src); 
     30                $src = clean_url(apply_filters( 'style_loader_src', $src )); 
     31 
     32                echo "<link rel='stylesheet' href='$src' type='text/css' media='$media' />\n"; 
     33 
     34                // Could do something with $this->registered[$handle]->extra here to print out extra CSS rules 
     35//              echo "<style type='text/css'>\n"; 
     36//              echo "/* <![CDATA[ */\n"; 
     37//              echo "/* ]]> */\n"; 
     38//              echo "</style>\n"; 
     39 
     40                return true; 
     41        } 
     42 
     43        function all_deps( $handles, $recursion = false ) { 
     44                $r = parent::all_deps( $handles, $recursion ); 
     45                if ( !$recursion ) 
     46                        $this->to_do = apply_filters( 'print_styles_array', $this->to_do ); 
     47                return $r; 
     48        } 
     49} 
  • wp-includes/class.wp-dependencies.php

     
     1<?php 
     2 
     3class WP_Dependencies { 
     4        var $registered = array(); 
     5        var $queue = array(); 
     6        var $to_do = array(); 
     7        var $done = array(); 
     8        var $args = array(); 
     9 
     10        function WP_Dependencies() { 
     11                $args = func_get_args(); 
     12                call_user_func_array( array(&$this, '__construct'), $args ); 
     13        } 
     14 
     15        function __construct() {} 
     16 
     17        /** 
     18         * Do the dependencies 
     19         * 
     20         * Process the items passed to it or the queue.  Processes all dependencies. 
     21         * 
     22         * @param mixed handles (optional) items to be processed.  (void) processes queue, (string) process that item, (array of strings) process those items 
     23         * @return array Items that have been processed 
     24         */ 
     25        function do_items( $handles = false ) { 
     26                // Print the queue if nothing is passed.  If a string is passed, print that script.  If an array is passed, print those scripts. 
     27                $handles = false === $handles ? $this->queue : (array) $handles; 
     28                $this->all_deps( $handles ); 
     29 
     30                foreach( $this->to_do as $handle ) { 
     31                        if ( !in_array($handle, $this->done) && isset($this->registered[$handle]) ) { 
     32                                if ( $this->registered[$handle]->src ) { // Else it defines a group. 
     33                                        $this->do_item( $handle ); 
     34                                } 
     35                                $this->done[] = $handle; 
     36                        } 
     37                } 
     38 
     39                $this->to_do = array(); 
     40                return $this->done; 
     41        } 
     42 
     43        function do_item( $handle ) { 
     44                return isset($this->registered[$handle]); 
     45        } 
     46 
     47        /** 
     48         * Determines dependencies 
     49         * 
     50         * Recursively builds array of items to process taking dependencies into account.  Does NOT catch infinite loops. 
     51         * 
     52 
     53         * @param mixed handles Accepts (string) dep name or (array of strings) dep names 
     54         * @param bool recursion Used internally when function calls itself 
     55         */ 
     56        function all_deps( $handles, $recursion = false ) { 
     57                if ( !$handles = (array) $handles ) 
     58                        return false; 
     59 
     60                foreach ( $handles as $handle ) { 
     61                        $handle = explode('?', $handle); 
     62                        if ( isset($handle[1]) ) 
     63                                $this->args[$handle[0]] = $handle[1]; 
     64                        $handle = $handle[0]; 
     65 
     66                        if ( isset($this->to_do[$handle]) ) // Already grobbed it and its deps 
     67                                continue; 
     68 
     69                        $keep_going = true; 
     70                        if ( !isset($this->registered[$handle]) ) 
     71                                $keep_going = false; // Script doesn't exist 
     72                        elseif ( $this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)) ) 
     73                                $keep_going = false; // Script requires deps which don't exist (not a necessary check.  efficiency?) 
     74                        elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true ) ) 
     75                                $keep_going = false; // Script requires deps which don't exist 
     76 
     77                        if ( !$keep_going ) { // Either script or its deps don't exist. 
     78                                if ( $recursion ) 
     79                                        return false; // Abort this branch. 
     80                                else 
     81                                        continue; // We're at the top level.  Move on to the next one. 
     82                        }                                        
     83 
     84                        $this->to_do[$handle] = true; 
     85                } 
     86 
     87                if ( !$recursion ) // at the end 
     88                        $this->to_do = array_keys( $this->to_do ); 
     89                return true; 
     90        } 
     91 
     92        /** 
     93         * Adds item 
     94         * 
     95         * Adds the item only if no item of that name already exists 
     96         * 
     97         * @param string handle Script name 
     98         * @param string src Script url 
     99         * @param array deps (optional) Array of script names on which this script depends 
     100         * @param string ver (optional) Script version (used for cache busting) 
     101         * @return array Hierarchical array of dependencies 
     102         */ 
     103        function add( $handle, $src, $deps = array(), $ver = false, $args = null ) { 
     104                if ( isset($this->registered[$handle]) ) 
     105                        return false; 
     106                $this->registered[$handle] = new _WP_Dependency( $handle, $src, $deps, $ver, $args ); 
     107                return true; 
     108        } 
     109 
     110        /** 
     111         * Adds extra data 
     112         * 
     113         * Adds data only if script has already been added 
     114         * 
     115         * @param string handle Script name 
     116         * @param string data_name Name of object in which to store extra data 
     117         * @param array data Array of extra data 
     118         * @return bool success 
     119         */ 
     120        function add_data( $handle, $data_name, $data ) { 
     121                if ( !isset($this->registered[$handle]) ) 
     122                        return false; 
     123                return $this->registered[$handle]->add_data( $data_name, $data ); 
     124        } 
     125 
     126        function remove( $handles ) { 
     127                foreach ( (array) $handles as $handle ) 
     128                        unset($this->registered[$handle]); 
     129        } 
     130 
     131        function enqueue( $handles ) { 
     132                foreach ( (array) $handles as $handle ) { 
     133                        $handle = explode('?', $handle); 
     134                        if ( !in_array($handle[0], $this->queue) && isset($this->registered[$handle[0]]) ) { 
     135                                $this->queue[] = $handle[0]; 
     136                                if ( isset($handle[1]) ) 
     137                                        $this->args[$handle[0]] = $handle[1]; 
     138                        } 
     139                } 
     140        } 
     141 
     142        function dequeue( $handles ) { 
     143                foreach ( (array) $handles as $handle ) 
     144                        unset( $this->queue[$handle] ); 
     145        } 
     146 
     147        function query( $handle, $list = 'registered' ) { // registered, queue, done, to_do 
     148                switch ( $list ) : 
     149                case 'registered': 
     150                case 'scripts': // back compat 
     151                        if ( isset($this->registered[$handle]) ) 
     152                                return $this->registered[$handle]; 
     153                        break; 
     154                case 'to_print': // back compat 
     155                case 'printed': // back compat 
     156                        if ( 'to_print' == $list ) 
     157                                $list = 'to_do'; 
     158                        else 
     159                                $list = 'printed'; 
     160                default: 
     161                        if ( in_array($handle, $this->$list) ) 
     162                                return true; 
     163                        break; 
     164                endswitch; 
     165                return false; 
     166        } 
     167 
     168} 
     169 
     170class _WP_Dependency { 
     171        var $handle; 
     172        var $src; 
     173        var $deps = array(); 
     174        var $ver = false; 
     175        var $args = null; 
     176 
     177        var $extra = array(); 
     178 
     179        function _WP_Dependency() { 
     180                @list($this->handle, $this->src, $this->deps, $this->ver, $this->args) = func_get_args(); 
     181                if ( !is_array($this->deps) ) 
     182                        $this->deps = array(); 
     183                if ( !$this->ver ) 
     184                        $this->ver = false; 
     185        } 
     186 
     187        function add_data( $name, $data ) { 
     188                if ( !is_scalar($name) ) 
     189                        return false; 
     190                $this->extra[$name] = $data; 
     191                return true; 
     192        } 
     193} 
  • wp-includes/functions.wp-styles.php

     
     1<?php 
     2 
     3function wp_print_styles( $handles = false ) { 
     4        do_action( 'wp_print_styles' ); 
     5        if ( '' === $handles ) // for wp_head 
     6                $handles = false; 
     7 
     8        global $wp_styles; 
     9        if ( !is_a($wp_styles, 'WP_Styles') ) { 
     10                if ( !$handles ) 
     11                        return array(); // No need to instantiate if nothing's there. 
     12                else 
     13                        $wp_stlyes = new WP_Styles(); 
     14        } 
     15 
     16        return $wp_styles->do_items( $handles ); 
     17} 
     18 
     19function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = false ) { 
     20        global $wp_styles; 
     21        if ( !is_a($wp_styles, 'WP_Styles') ) 
     22                $wp_styles = new WP_Styles(); 
     23 
     24        $wp_styles->add( $handle, $src, $deps, $ver, $media ); 
     25} 
     26 
     27function wp_deregister_style( $handle ) { 
     28        global $wp_styles; 
     29        if ( !is_a($wp_styles, 'WP_Styles') ) 
     30                $wp_styles = new WP_Styles(); 
     31 
     32        $wp_styles->remove( $handle ); 
     33} 
     34 
     35function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = false ) { 
     36        global $wp_styles; 
     37        if ( !is_a($wp_styles, 'WP_Styles') ) 
     38                $wp_styles = new WP_Styles(); 
     39 
     40        if ( $src ) { 
     41                $_handle = explode('?', $handle); 
     42                $wp_styles->add( $_handle[0], $src, $deps, $ver, $media ); 
     43        } 
     44        $wp_styles->enqueue( $handle ); 
     45} 
  • wp-includes/class.wp-scripts.php

     
     1<?php 
     2 
     3class WP_Scripts extends WP_Dependencies { 
     4        var $base_url; // Full URL with trailing slash 
     5        var $default_version; 
     6 
     7        function __construct() { 
     8                do_action_ref_array( 'wp_default_scripts', array(&$this) ); 
     9        } 
     10 
     11        /** 
     12         * Prints scripts 
     13         * 
     14         * Prints the scripts passed to it or the print queue.  Also prints all necessary dependencies. 
     15         * 
     16         * @param mixed handles (optional) Scripts to be printed.  (void) prints queue, (string) prints that script, (array of strings) prints those scripts. 
     17         * @return array Scripts that have been printed 
     18         */ 
     19        function print_scripts( $handles = false ) { 
     20                return $this->do_items( $handles ); 
     21        } 
     22 
     23        function print_scripts_l10n( $handle ) { 
     24                if ( empty($this->registered[$handle]->extra['l10n']) || empty($this->registered[$handle]->extra['l10n'][0]) || !is_array($this->registered[$handle]->extra['l10n'][1]) ) 
     25                        return false; 
     26 
     27                $object_name = $this->registered[$handle]->extra['l10n'][0]; 
     28 
     29                echo "<script type='text/javascript'>\n"; 
     30                echo "/* <![CDATA[ */\n"; 
     31                echo "\t$object_name = {\n"; 
     32                $eol = ''; 
     33                foreach ( $this->registered[$handle]->extra['l10n'][1] as $var => $val ) { 
     34                        echo "$eol\t\t$var: \"" . js_escape( $val ) . '"'; 
     35                        $eol = ",\n"; 
     36                } 
     37                echo "\n\t}\n"; 
     38                echo "/* ]]> */\n"; 
     39                echo "</script>\n"; 
     40 
     41                return true; 
     42        } 
     43 
     44        function do_item( $handle ) { 
     45                if ( !parent::do_item($handle) ) 
     46                        return false; 
     47 
     48                $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; 
     49                if ( isset($this->args[$handle]) ) 
     50                        $ver .= '&amp;' . $this->args[$handle]; 
     51 
     52                $src = $this->registered[$handle]->src; 
     53                if ( !preg_match('|^https?://|', $src) ) { 
     54                        $src = $this->base_url . $src; 
     55                } 
     56 
     57                $src = add_query_arg('ver', $ver, $src); 
     58                $src = clean_url(apply_filters( 'script_loader_src', $src )); 
     59 
     60                $this->print_scripts_l10n( $handle ); 
     61 
     62                echo "<script type='text/javascript' src='$src'></script>\n"; 
     63 
     64                return true; 
     65        } 
     66 
     67        /** 
     68         * Localizes a script 
     69         * 
     70         * Localizes only if script has already been added 
     71         * 
     72         * @param string handle Script name 
     73         * @param string object_name Name of JS object to hold l10n info 
     74         * @param array l10n Array of JS var name => localized string 
     75         * @return bool Successful localization 
     76         */ 
     77        function localize( $handle, $object_name, $l10n ) { 
     78                if ( !$object_name || !$l10n ) 
     79                        return false; 
     80                return $this->add_data( $handle, 'l10n', array( $object_name, $l10n ) ); 
     81        } 
     82 
     83        function all_deps( $handles, $recursion = false ) { 
     84                $r = parent::all_deps( $handles, $recursion ); 
     85                if ( !$recursion ) 
     86                        $this->to_do = apply_filters( 'print_scripts_array', $this->to_do ); 
     87                return $r; 
     88        } 
     89} 
  • wp-includes/script-loader.php

     
    11<?php 
    2 class WP_Scripts { 
    3         var $scripts = array(); 
    4         var $queue = array(); 
    5         var $to_print = array(); 
    6         var $printed = array(); 
    7         var $args = array(); 
    82 
    9         function WP_Scripts() { 
    10                 $this->default_scripts(); 
    11         } 
     3require( ABSPATH . WPINC . '/class.wp-dependencies.php' ); 
     4require( ABSPATH . WPINC . '/class.wp-scripts.php' ); 
     5require( ABSPATH . WPINC . '/functions.wp-scripts.php' ); 
     6require( ABSPATH . WPINC . '/class.wp-styles.php' ); 
     7require( ABSPATH . WPINC . '/functions.wp-styles.php' ); 
    128 
    13         function default_scripts() { 
    14                 $this->add( 'common', '/wp-admin/js/common.js', array('jquery'), '20080318' ); 
    15                 $this->add( 'sack', '/wp-includes/js/tw-sack.js', false, '1.6.1' ); 
     9function wp_default_scripts( $scripts ) { 
     10        $scripts->base_url = get_option( 'siteurl' ); 
     11        $scripts->default_version = get_bloginfo( 'version' ); 
    1612 
    17                 $this->add( 'quicktags', '/wp-includes/js/quicktags.js', false, '3958' ); 
    18                 $this->localize( 'quicktags', 'quicktagsL10n', array( 
    19                         'quickLinks' => __('(Quick Links)'), 
    20                         'wordLookup' => __('Enter a word to look up:'), 
    21                         'dictionaryLookup' => attribute_escape(__('Dictionary lookup')), 
    22                         'lookup' => attribute_escape(__('lookup')), 
    23                         'closeAllOpenTags' => attribute_escape(__('Close all open tags')), 
    24                         'closeTags' => attribute_escape(__('close tags')), 
    25                         'enterURL' => __('Enter the URL'), 
    26                         'enterImageURL' => __('Enter the URL of the image'), 
    27                         'enterImageDescription' => __('Enter a description of the image') 
    28                 ) ); 
     13        $scripts->add( 'common', '/wp-admin/js/common.js', array('jquery'), '20080318' ); 
     14        $scripts->add( 'sack', '/wp-includes/js/tw-sack.js', false, '1.6.1' ); 
    2915 
    30                 $this->add( 'colorpicker', '/wp-includes/js/colorpicker.js', array('prototype'), '3517' ); 
     16        $scripts->add( 'quicktags', '/wp-includes/js/quicktags.js', false, '3958' ); 
     17        $scripts->localize( 'quicktags', 'quicktagsL10n', array( 
     18                'quickLinks' => __('(Quick Links)'), 
     19                'wordLookup' => __('Enter a word to look up:'), 
     20                'dictionaryLookup' => attribute_escape(__('Dictionary lookup')), 
     21                'lookup' => attribute_escape(__('lookup')), 
     22                'closeAllOpenTags' => attribute_escape(__('Close all open tags')), 
     23                'closeTags' => attribute_escape(__('close tags')), 
     24                'enterURL' => __('Enter the URL'), 
     25                'enterImageURL' => __('Enter the URL of the image'), 
     26                'enterImageDescription' => __('Enter a description of the image') 
     27        ) ); 
    3128 
    32                 // Let a plugin replace the visual editor 
    33                 $visual_editor = apply_filters('visual_editor', array('tiny_mce')); 
    34                 $this->add( 'editor', false, $visual_editor, '20080321' ); 
     29        $scripts->add( 'colorpicker', '/wp-includes/js/colorpicker.js', array('prototype'), '3517' ); 
    3530 
    36                 $this->add( 'editor_functions', '/wp-admin/js/editor.js', false, '20080325' ); 
     31        // Let a plugin replace the visual editor 
     32        $visual_editor = apply_filters('visual_editor', array('tiny_mce')); 
     33        $scripts->add( 'editor', false, $visual_editor, '20080321' ); 
    3734 
    38                 // Modify this version when tinyMCE plugins are changed. 
    39                 $mce_version = apply_filters('tiny_mce_version', '20080423'); 
    40                 $this->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('editor_functions'), $mce_version ); 
     35        $scripts->add( 'editor_functions', '/wp-admin/js/editor.js', false, '20080325' ); 
    4136 
    42                 $this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6'); 
     37        // Modify this version when tinyMCE plugins are changed. 
     38        $mce_version = apply_filters('tiny_mce_version', '20080423'); 
     39        $scripts->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('editor_functions'), $mce_version ); 
    4340 
    44                 $this->add( 'wp-ajax-response', '/wp-includes/js/wp-ajax-response.js', array('jquery'), '20080316' ); 
    45                 $this->localize( 'wp-ajax-response', 'wpAjax', array( 
    46                         'noPerm' => __('You do not have permission to do that.'), 
    47                         'broken' => __('An unidentified error has occurred.') 
    48                 ) ); 
     41        $scripts->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6'); 
    4942 
    50                 $this->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080508' ); 
     43        $scripts->add( 'wp-ajax-response', '/wp-includes/js/wp-ajax-response.js', array('jquery'), '20080316' ); 
     44        $scripts->localize( 'wp-ajax-response', 'wpAjax', array( 
     45                'noPerm' => __('You do not have permission to do that.'), 
     46                'broken' => __('An unidentified error has occurred.') 
     47        ) ); 
    5148 
    52                 $this->add( 'wp-ajax', '/wp-includes/js/wp-ajax.js', array('prototype'), '20070306'); 
    53                 $this->localize( 'wp-ajax', 'WPAjaxL10n', array( 
    54                         'defaultUrl' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', 
    55                         'permText' => __("You do not have permission to do that."), 
    56                         'strangeText' => __("Something strange happened.  Try refreshing the page."), 
    57                         'whoaText' => __("Slow down, I'm still sending your data!") 
    58                 ) ); 
     49        $scripts->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080508' ); 
    5950 
    60                 $this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20080411' ); 
    61                 $this->localize( 'wp-lists', 'wpListL10n', array( 
    62                         'url' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php' 
    63                 ) ); 
     51        $scripts->add( 'wp-ajax', '/wp-includes/js/wp-ajax.js', array('prototype'), '20070306'); 
     52        $scripts->localize( 'wp-ajax', 'WPAjaxL10n', array( 
     53                'defaultUrl' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', 
     54                'permText' => __("You do not have permission to do that."), 
     55                'strangeText' => __("Something strange happened.  Try refreshing the page."), 
     56                'whoaText' => __("Slow down, I'm still sending your data!") 
     57        ) ); 
    6458 
    65                 $this->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/scriptaculous.js', array('prototype'), '1.8.0'); 
    66                 $this->add( 'scriptaculous-builder', '/wp-includes/js/scriptaculous/builder.js', array('scriptaculous-root'), '1.8.0'); 
    67                 $this->add( 'scriptaculous-dragdrop', '/wp-includes/js/scriptaculous/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.8.0'); 
    68                 $this->add( 'scriptaculous-effects', '/wp-includes/js/scriptaculous/effects.js', array('scriptaculous-root'), '1.8.0'); 
    69                 $this->add( 'scriptaculous-slider', '/wp-includes/js/scriptaculous/slider.js', array('scriptaculous-effects'), '1.8.0'); 
    70                 $this->add( 'scriptaculous-sound', '/wp-includes/js/scriptaculous/sound.js', array( 'scriptaculous-root' ), '1.8.0' ); 
    71                 $this->add( 'scriptaculous-controls', '/wp-includes/js/scriptaculous/controls.js', array('scriptaculous-root'), '1.8.0'); 
    72                 $this->add( 'scriptaculous', '', array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls'), '1.8.0'); 
     59        $scripts->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20080411' ); 
     60        $scripts->localize( 'wp-lists', 'wpListL10n', array( 
     61                'url' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php' 
     62        ) ); 
    7363 
    74                 $this->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop'), '20070118'); 
     64        $scripts->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/scriptaculous.js', array('prototype'), '1.8.0'); 
     65        $scripts->add( 'scriptaculous-builder', '/wp-includes/js/scriptaculous/builder.js', array('scriptaculous-root'), '1.8.0'); 
     66        $scripts->add( 'scriptaculous-dragdrop', '/wp-includes/js/scriptaculous/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.8.0'); 
     67        $scripts->add( 'scriptaculous-effects', '/wp-includes/js/scriptaculous/effects.js', array('scriptaculous-root'), '1.8.0'); 
     68        $scripts->add( 'scriptaculous-slider', '/wp-includes/js/scriptaculous/slider.js', array('scriptaculous-effects'), '1.8.0'); 
     69        $scripts->add( 'scriptaculous-sound', '/wp-includes/js/scriptaculous/sound.js', array( 'scriptaculous-root' ), '1.8.0' ); 
     70        $scripts->add( 'scriptaculous-controls', '/wp-includes/js/scriptaculous/controls.js', array('scriptaculous-root'), '1.8.0'); 
     71        $scripts->add( 'scriptaculous', '', array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls'), '1.8.0'); 
    7572 
    76                 $this->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.2.3'); 
    77                 $this->add( 'jquery-form', '/wp-includes/js/jquery/jquery.form.js', array('jquery'), '2.02'); 
    78                 $this->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.js', array('jquery'), '2.0-4561'); 
    79                 $this->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2' ); 
    80                 $this->add( 'dimensions', '/wp-includes/js/jquery/jquery.dimensions.min.js', array('jquery'), '1.1.2'); 
    81                 $this->add( 'suggest', '/wp-includes/js/jquery/suggest.js', array('dimensions'), '1.1'); 
    82                 $this->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20'); 
    83                 $this->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array('jquery'), '3.1-20080430'); 
    84                 $this->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.0.2-20080430'); 
    85                 $this->add( 'swfupload-degrade', '/wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js', array('swfupload'), '2.0.2'); 
    86                 $this->localize( 'swfupload-degrade', 'uploadDegradeOptions', array( 
    87                         'is_lighttpd_before_150' => is_lighttpd_before_150(), 
    88                 ) ); 
    89                 $this->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2.0.2'); 
    90                 $this->add( 'swfupload-handlers', '/wp-includes/js/swfupload/handlers.js', array('swfupload'), '2.0.2-20080407'); 
    91                 // these error messages came from the sample swfupload js, they might need changing. 
    92                 $this->localize( 'swfupload-handlers', 'swfuploadL10n', array( 
    93                                 'queue_limit_exceeded' => __('You have attempted to queue too many files.'), 
    94                                 'file_exceeds_size_limit' => sprintf(__('This file is too big. Your php.ini upload_max_filesize is %s.'), @ini_get('upload_max_filesize')), 
    95                                 'zero_byte_file' => __('This file is empty. Please try another.'), 
    96                                 'invalid_filetype' => __('This file type is not allowed. Please try another.'), 
    97                                 'default_error' => __('An error occurred in the upload. Please try again later.'), 
    98                                 'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'), 
    99                                 'upload_limit_exceeded' => __('You may only upload 1 file.'), 
    100                                 'http_error' => __('HTTP error.'), 
    101                                 'upload_failed' => __('Upload failed.'), 
    102                                 'io_error' => __('IO error.'), 
    103                                 'security_error' => __('Security error.'), 
    104                                 'file_cancelled' => __('File cancelled.'), 
    105                                 'upload_stopped' => __('Upload stopped.'), 
    106                                 'dismiss' => __('Dismiss'), 
    107                                 'crunching' => __('Crunching&hellip;'), 
    108                                 'deleted' => __('Deleted'), 
    109                 ) ); 
     73        $scripts->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop'), '20070118'); 
    11074 
    111                 $this->add( 'jquery-ui-core', '/wp-includes/js/jquery/ui.core.js', array('jquery'), '1.5b4' ); 
    112                 $this->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery-ui-core'), '1.5b4' ); 
     75        $scripts->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.2.3'); 
     76        $scripts->add( 'jquery-form', '/wp-includes/js/jquery/jquery.form.js', array('jquery'), '2.02'); 
     77        $scripts->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.js', array('jquery'), '2.0-4561'); 
     78        $scripts->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2' ); 
     79        $scripts->add( 'dimensions', '/wp-includes/js/jquery/jquery.dimensions.min.js', array('jquery'), '1.1.2'); 
     80        $scripts->add( 'suggest', '/wp-includes/js/jquery/suggest.js', array('dimensions'), '1.1'); 
     81        $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20'); 
     82        $scripts->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array('jquery'), '3.1-20080430'); 
     83        $scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.0.2-20080430'); 
     84        $scripts->add( 'swfupload-degrade', '/wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js', array('swfupload'), '2.0.2'); 
     85        $scripts->localize( 'swfupload-degrade', 'uploadDegradeOptions', array( 
     86                'is_lighttpd_before_150' => is_lighttpd_before_150(), 
     87        ) ); 
     88        $scripts->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2.0.2'); 
     89        $scripts->add( 'swfupload-handlers', '/wp-includes/js/swfupload/handlers.js', array('swfupload'), '2.0.2-20080407'); 
     90        // these error messages came from the sample swfupload js, they might need changing. 
     91        $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', array( 
     92                        'queue_limit_exceeded' => __('You have attempted to queue too many files.'), 
     93                        'file_exceeds_size_limit' => sprintf(__('This file is too big. Your php.ini upload_max_filesize is %s.'), @ini_get('upload_max_filesize')), 
     94                        'zero_byte_file' => __('This file is empty. Please try another.'), 
     95                        'invalid_filetype' => __('This file type is not allowed. Please try another.'), 
     96                        'default_error' => __('An error occurred in the upload. Please try again later.'), 
     97                        'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'), 
     98                        'upload_limit_exceeded' => __('You may only upload 1 file.'), 
     99                        'http_error' => __('HTTP error.'), 
     100                        'upload_failed' => __('Upload failed.'), 
     101                        'io_error' => __('IO error.'), 
     102                        'security_error' => __('Security error.'), 
     103                        'file_cancelled' => __('File cancelled.'), 
     104                        'upload_stopped' => __('Upload stopped.'), 
     105                        'dismiss' => __('Dismiss'), 
     106                        'crunching' => __('Crunching&hellip;'), 
     107                        'deleted' => __('Deleted'), 
     108        ) ); 
    113109 
    114                 if ( is_admin() ) { 
    115                         $this->add( 'ajaxcat', '/wp-admin/js/cat.js', array( 'wp-lists' ), '20071101' ); 
    116                         $this->localize( 'ajaxcat', 'catL10n', array( 
    117                                 'add' => attribute_escape(__('Add')), 
    118                                 'how' => __('Separate multiple categories with commas.') 
    119                         ) ); 
    120                         $this->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20071031' ); 
    121                         $this->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists'), '20071031' ); 
    122                         $this->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' ); 
    123                         $this->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20070405' ); 
    124                         $this->localize( 'password-strength-meter', 'pwsL10n', array( 
    125                                 'short' => __('Too short'), 
    126                                 'bad' => __('Bad'), 
    127                                 'good' => __('Good'), 
    128                                 'strong' => __('Strong') 
    129                         ) ); 
    130                         $this->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists'), '20080311' ); 
    131                         $this->localize( 'admin-comments', 'adminCommentsL10n', array( 
    132                                 'pending' => __('%i% pending') // must look like: "# blah blah" 
    133                         ) ); 
    134                         $this->add( 'admin-users', '/wp-admin/js/users.js', array('wp-lists'), '20070823' ); 
    135                         $this->add( 'admin-forms', '/wp-admin/js/forms.js', false, '20080401'); 
    136                         $this->add( 'xfn', '/wp-admin/js/xfn.js', false, '3517' ); 
    137                         $this->add( 'upload', '/wp-admin/js/upload.js', array('jquery'), '20070518' ); 
    138                         $this->add( 'postbox', '/wp-admin/js/postbox.js', array('jquery'), '20080128' ); 
    139                         $this->localize( 'postbox', 'postboxL10n', array( 
    140                                 'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', 
    141                         ) ); 
    142                         $this->add( 'slug', '/wp-admin/js/slug.js', array('jquery'), '20080208' ); 
    143                         $this->localize( 'slug', 'slugL10n', array( 
    144                                 'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', 
    145                                 'save' => __('Save'), 
    146                                 'cancel' => __('Cancel'), 
    147                         ) ); 
    148                         $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080519' ); 
    149                         $this->localize( 'post', 'postL10n', array( 
    150                                 'tagsUsed' =>  __('Tags used on this post:'), 
    151                                 'add' => attribute_escape(__('Add')), 
    152                                 'addTag' => attribute_escape(__('Add new tag')), 
    153                                 'separate' => __('Separate tags with commas'), 
    154                                 'cancel' => __('Cancel'), 
    155                                 'edit' => __('Edit'), 
    156                         ) ); 
    157                         $this->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox'), '20080318' ); 
    158                         $this->localize( 'page', 'postL10n', array( 
    159                                 'cancel' => __('Cancel'), 
    160                                 'edit' => __('Edit'), 
    161                         ) ); 
    162                         $this->add( 'link', '/wp-admin/js/link.js', array('jquery-ui-tabs', 'wp-lists', 'postbox'), '20080131' ); 
    163                         $this->add( 'comment', '/wp-admin/js/comment.js', array('postbox'), '20080219' ); 
    164                         $this->localize( 'comment', 'commentL10n', array( 
    165                                         'cancel' => __('Cancel'), 
    166                                         'edit' => __('Edit'), 
    167                                 ) ); 
    168                         $this->add( 'media-upload', '/wp-admin/js/media-upload.js', false, '20080430' ); 
    169                         $this->localize( 'upload', 'uploadL10n', array( 
    170                                 'browseTitle' => attribute_escape(__('Browse your files')), 
    171                                 'back' => __('&laquo; Back'), 
    172                                 'directTitle' => attribute_escape(__('Direct link to file')), 
    173                                 'edit' => __('Edit'), 
    174                                 'thumb' => __('Thumbnail'), 
    175                                 'full' => __('Full size'), 
    176                                 'icon' => __('Icon'), 
    177                                 'title' => __('Title'), 
    178                                 'show' => __('Show:'), 
    179                                 'link' => __('Link to:'), 
    180                                 'file' => __('File'), 
    181                                 'page' => __('Page'), 
    182                                 'none' => __('None'), 
    183                                 'editorText' => attribute_escape(__('Send to editor &raquo;')), 
    184                                 'insert' => __('Insert'), 
    185                                 'urlText' => __('URL'), 
    186                                 'desc' => __('Description'), 
    187                                 'deleteText' => attribute_escape(__('Delete File')), 
    188                                 'saveText' => attribute_escape(__('Save &raquo;')), 
    189                                 'confirmText' => __("Are you sure you want to delete the file '%title%'?\nClick ok to delete or cancel to go back.") 
    190                         ) ); 
    191                         $this->add( 'admin-widgets', '/wp-admin/js/widgets.js', array( 'interface' ), '20080503' ); 
    192                         $this->localize( 'admin-widgets', 'widgetsL10n', array( 
    193                                 'add' => __('Add'), 
    194                                 'edit' => __('Edit'), 
    195                                 'cancel' => __('Cancel'), 
    196                         )); 
     110        $scripts->add( 'jquery-ui-core', '/wp-includes/js/jquery/ui.core.js', array('jquery'), '1.5b4' ); 
     111        $scripts->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery-ui-core'), '1.5b4' ); 
    197112 
    198                         $this->add( 'word-count', '/wp-admin/js/word-count.js', array( 'jquery' ), '20080423' ); 
    199                         $this->localize( 'word-count', 'wordCountL10n', array( 
    200                                 'count' => __('Word count: %d') 
    201                         )); 
    202                          
    203                         $this->add( 'wp-gears', '/wp-admin/js/wp-gears.js', false, '20080511' ); 
    204                         $this->localize( 'wp-gears', 'wpGearsL10n', array( 
    205                                 'updateCompleted' => __('Update completed.'), 
    206                                 'error' => __('Error:') 
    207                         )); 
    208                          
    209                         $this->add( 'theme-preview', '/wp-admin/js/theme-preview.js', array( 'thickbox', 'dimensions' ), '20080515' ); 
    210                 } 
    211         } 
     113        if ( is_admin() ) { 
     114                $scripts->add( 'ajaxcat', '/wp-admin/js/cat.js', array( 'wp-lists' ), '20071101' ); 
     115                $scripts->localize( 'ajaxcat', 'catL10n', array( 
     116                        'add' => attribute_escape(__('Add')), 
     117                        'how' => __('Separate multiple categories with commas.') 
     118                ) ); 
     119                $scripts->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20071031' ); 
     120                $scripts->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists'), '20071031' ); 
     121                $scripts->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' ); 
     122                $scripts->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20070405' ); 
     123                $scripts->localize( 'password-strength-meter', 'pwsL10n', array( 
     124                        'short' => __('Too short'), 
     125                        'bad' => __('Bad'), 
     126                        'good' => __('Good'), 
     127                        'strong' => __('Strong') 
     128                ) ); 
     129                $scripts->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists'), '20080311' ); 
     130                $scripts->localize( 'admin-comments', 'adminCommentsL10n', array( 
     131                        'pending' => __('%i% pending') // must look like: "# blah blah" 
     132                ) ); 
     133                $scripts->add( 'admin-users', '/wp-admin/js/users.js', array('wp-lists'), '20070823' ); 
     134                $scripts->add( 'admin-forms', '/wp-admin/js/forms.js', false, '20080401'); 
     135                $scripts->add( 'xfn', '/wp-admin/js/xfn.js', false, '3517' ); 
     136                $scripts->add( 'upload', '/wp-admin/js/upload.js', array('jquery'), '20070518' ); 
     137                $scripts->add( 'postbox', '/wp-admin/js/postbox.js', array('jquery'), '20080128' ); 
     138                $scripts->localize( 'postbox', 'postboxL10n', array( 
     139                        'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', 
     140                ) ); 
     141                $scripts->add( 'slug', '/wp-admin/js/slug.js', array('jquery'), '20080208' ); 
     142                $scripts->localize( 'slug', 'slugL10n', array( 
     143                        'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', 
     144                        'save' => __('Save'), 
     145                        'cancel' => __('Cancel'), 
     146                ) ); 
     147                $scripts->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080519' ); 
     148                $scripts->localize( 'post', 'postL10n', array( 
     149                        'tagsUsed' =>  __('Tags used on this post:'), 
     150                        'add' => attribute_escape(__('Add')), 
     151                        'addTag' => attribute_escape(__('Add new tag')), 
     152                        'separate' => __('Separate tags with commas'), 
     153                        'cancel' => __('Cancel'), 
     154                        'edit' => __('Edit'), 
     155                ) ); 
     156                $scripts->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox'), '20080318' ); 
     157                $scripts->localize( 'page', 'postL10n', array( 
     158                        'cancel' => __('Cancel'), 
     159                        'edit' => __('Edit'), 
     160                ) ); 
     161                $scripts->add( 'link', '/wp-admin/js/link.js', array('jquery-ui-tabs', 'wp-lists', 'postbox'), '20080131' ); 
     162                $scripts->add( 'comment', '/wp-admin/js/comment.js', array('postbox'), '20080219' ); 
     163                $scripts->localize( 'comment', 'commentL10n', array( 
     164                        'cancel' => __('Cancel'), 
     165                        'edit' => __('Edit'), 
     166                ) ); 
     167                $scripts->add( 'media-upload', '/wp-admin/js/media-upload.js', false, '20080430' ); 
     168                $scripts->localize( 'upload', 'uploadL10n', array( 
     169                        'browseTitle' => attribute_escape(__('Browse your files')), 
     170                        'back' => __('&laquo; Back'), 
     171                        'directTitle' => attribute_escape(__('Direct link to file')), 
     172                        'edit' => __('Edit'), 
     173                        'thumb' => __('Thumbnail'), 
     174                        'full' => __('Full size'), 
     175                        'icon' => __('Icon'), 
     176                        'title' => __('Title'), 
     177                        'show' => __('Show:'), 
     178                        'link' => __('Link to:'), 
     179                        'file' => __('File'), 
     180                        'page' => __('Page'), 
     181                        'none' => __('None'), 
     182                        'editorText' => attribute_escape(__('Send to editor &raquo;')), 
     183                        'insert' => __('Insert'), 
     184                        'urlText' => __('URL'), 
     185                        'desc' => __('Description'), 
     186                        'deleteText' => attribute_escape(__('Delete File')), 
     187                        'saveText' => attribute_escape(__('Save &raquo;')), 
     188                        'confirmText' => __("Are you sure you want to delete the file '%title%'?\nClick ok to delete or cancel to go back.") 
     189                ) ); 
     190                $scripts->add( 'admin-widgets', '/wp-admin/js/widgets.js', array( 'interface' ), '20080503' ); 
     191                $scripts->localize( 'admin-widgets', 'widgetsL10n', array( 
     192                        'add' => __('Add'), 
     193                        'edit' => __('Edit'), 
     194                        'cancel' => __('Cancel'), 
     195                )); 
    212196 
    213         /** 
    214          * Prints script tags 
    215          * 
    216          * Prints the scripts passed to it or the print queue.  Also prints all necessary dependencies. 
    217          * 
    218          * @param mixed handles (optional) Scripts to be printed.  (void) prints queue, (string) prints that script, (array of strings) prints those scripts. 
    219          * @return array Scripts that have been printed 
    220          */ 
    221         function print_scripts( $handles = false ) { 
    222                 global $wp_db_version; 
    223  
    224                 // Print the queue if nothing is passed.  If a string is passed, print that script.  If an array is passed, print those scripts. 
    225                 $handles = false === $handles ? $this->queue : (array) $handles; 
    226                 $this->all_deps( $handles ); 
    227  
    228                 $to_print = apply_filters( 'print_scripts_array', array_keys($this->to_print) ); 
    229  
    230                 foreach( $to_print as $handle ) { 
    231                         if ( !in_array($handle, $this->printed) && isset($this->scripts[$handle]) ) { 
    232                                 if ( $this->scripts[$handle]->src ) { // Else it defines a group. 
    233                                         $ver = $this->scripts[$handle]->ver ? $this->scripts[$handle]->ver : $wp_db_version; 
    234                                         if ( isset($this->args[$handle]) ) 
    235                                                 $ver .= '&amp;' . $this->args[$handle]; 
    236                                         $src = 0 === strpos($this->scripts[$handle]->src, 'http://') ? $this->scripts[$handle]->src : get_option( 'siteurl' ) . $this->scripts[$handle]->src; 
    237                                         $src = $this->scripts[$handle]->src; 
    238  
    239                                         if (!preg_match('|^https?://|', $src)) { 
    240                                                 $src = get_option('siteurl') . $src; 
    241                                         } 
    242  
    243                                         $src = add_query_arg('ver', $ver, $src); 
    244                                         $src = clean_url(apply_filters( 'script_loader_src', $src )); 
    245                                         $this->print_scripts_l10n( $handle ); 
    246                                         echo "<script type='text/javascript' src='$src'></script>\n"; 
    247                                 } 
    248                                 $this->printed[] = $handle; 
    249                         } 
    250                 } 
    251  
    252                 $this->to_print = array(); 
    253                 return $this->printed; 
     197                $scripts->add( 'word-count', '/wp-admin/js/word-count.js', array( 'jquery' ), '20080423' ); 
     198                $scripts->localize( 'word-count', 'wordCountL10n', array( 
     199                        'count' => __('Word count: %d') 
     200                )); 
     201                 
     202                $scripts->add( 'wp-gears', '/wp-admin/js/wp-gears.js', false, '20080511' ); 
     203                $scripts->localize( 'wp-gears', 'wpGearsL10n', array( 
     204                        'updateCompleted' => __('Update completed.'), 
     205                        'error' => __('Error:') 
     206                )); 
     207                 
     208                $scripts->add( 'theme-preview', '/wp-admin/js/theme-preview.js', array( 'thickbox', 'dimensions' ), '20080515' ); 
    254209        } 
    255  
    256         function print_scripts_l10n( $handle ) { 
    257                 if ( empty($this->scripts[$handle]->l10n_object) || empty($this->scripts[$handle]->l10n) || !is_array($this->scripts[$handle]->l10n) ) 
    258                         return; 
    259  
    260                 $object_name = $this->scripts[$handle]->l10n_object; 
    261  
    262                 echo "<script type='text/javascript'>\n"; 
    263                 echo "/* <![CDATA[ */\n"; 
    264                 echo "\t$object_name = {\n"; 
    265                 $eol = ''; 
    266                 foreach ( $this->scripts[$handle]->l10n as $var => $val ) { 
    267                         echo "$eol\t\t$var: \"" . js_escape( $val ) . '"'; 
    268                         $eol = ",\n"; 
    269                 } 
    270                 echo "\n\t}\n"; 
    271                 echo "/* ]]> */\n"; 
    272                 echo "</script>\n"; 
    273         } 
    274  
    275         /** 
    276          * Determines dependencies of scripts 
    277          * 
    278          * Recursively builds array of scripts to print taking dependencies into account.  Does NOT catch infinite loops. 
    279          * 
    280          * @param mixed handles Accepts (string) script name or (array of strings) script names 
    281          * @param bool recursion Used internally when function calls itself 
    282          */ 
    283         function all_deps( $handles, $recursion = false ) { 
    284                 if ( !$handles = (array) $handles ) 
    285                         return false; 
    286  
    287                 foreach ( $handles as $handle ) { 
    288                         $handle = explode('?', $handle); 
    289                         if ( isset($handle[1]) ) 
    290                                 $this->args[$handle[0]] = $handle[1]; 
    291                         $handle = $handle[0]; 
    292  
    293                         if ( isset($this->to_print[$handle]) ) // Already grobbed it and its deps 
    294                                 continue; 
    295  
    296                         $keep_going = true; 
    297                         if ( !isset($this->scripts[$handle]) ) 
    298                                 $keep_going = false; // Script doesn't exist 
    299                         elseif ( $this->scripts[$handle]->deps && array_diff($this->scripts[$handle]->deps, array_keys($this->scripts)) ) 
    300                                 $keep_going = false; // Script requires deps which don't exist (not a necessary check.  efficiency?) 
    301                         elseif ( $this->scripts[$handle]->deps && !$this->all_deps( $this->scripts[$handle]->deps, true ) ) 
    302                                 $keep_going = false; // Script requires deps which don't exist 
    303  
    304                         if ( !$keep_going ) { // Either script or its deps don't exist. 
    305                                 if ( $recursion ) 
    306                                         return false; // Abort this branch. 
    307                                 else 
    308                                         continue; // We're at the top level.  Move on to the next one. 
    309                         } 
    310  
    311                         $this->to_print[$handle] = true; 
    312                 } 
    313  
    314                 return true; 
    315         } 
    316  
    317         /** 
    318          * Adds script 
    319          * 
    320          * Adds the script only if no script of that name already exists 
    321          * 
    322          * @param string handle Script name 
    323          * @param string src Script url 
    324          * @param array deps (optional) Array of script names on which this script depends 
    325          * @param string ver (optional) Script version (used for cache busting) 
    326          * @return array Hierarchical array of dependencies 
    327          */ 
    328         function add( $handle, $src, $deps = array(), $ver = false ) { 
    329                 if ( isset($this->scripts[$handle]) ) 
    330                         return false; 
    331                 $this->scripts[$handle] = new _WP_Script( $handle, $src, $deps, $ver ); 
    332                 return true; 
    333         } 
    334  
    335         /** 
    336          * Localizes a script 
    337          * 
    338          * Localizes only if script has already been added 
    339          * 
    340          * @param string handle Script name 
    341          * @param string object_name Name of JS object to hold l10n info 
    342          * @param array l10n Array of JS var name => localized string 
    343          * @return bool Successful localization 
    344          */ 
    345         function localize( $handle, $object_name, $l10n ) { 
    346                 if ( !isset($this->scripts[$handle]) ) 
    347                         return false; 
    348                 return $this->scripts[$handle]->localize( $object_name, $l10n ); 
    349         } 
    350  
    351         function remove( $handles ) { 
    352                 foreach ( (array) $handles as $handle ) 
    353                         unset($this->scripts[$handle]); 
    354         } 
    355  
    356         function enqueue( $handles ) { 
    357                 foreach ( (array) $handles as $handle ) { 
    358                         $handle = explode('?', $handle); 
    359                         if ( !in_array($handle[0], $this->queue) && isset($this->scripts[$handle[0]]) ) { 
    360                                 $this->queue[] = $handle[0]; 
    361                                 if ( isset($handle[1]) ) 
    362                                         $this->args[$handle[0]] = $handle[1]; 
    363                         } 
    364                 } 
    365         } 
    366  
    367         function dequeue( $handles ) { 
    368                 foreach ( (array) $handles as $handle ) 
    369                         unset( $this->queue[$handle] ); 
    370         } 
    371  
    372         function query( $handle, $list = 'scripts' ) { // scripts, queue, or printed 
    373                 switch ( $list ) : 
    374                 case 'scripts': 
    375                         if ( isset($this->scripts[$handle]) ) 
    376                                 return $this->scripts[$handle]; 
    377                         break; 
    378                 default: 
    379                         if ( in_array($handle, $this->$list) ) 
    380                                 return true; 
    381                         break; 
    382                 endswitch; 
    383                 return false; 
    384         } 
    385  
    386210} 
    387211 
    388 class _WP_Script { 
    389         var $handle; 
    390         var $src; 
    391         var $deps = array(); 
    392         var $ver = false; 
    393         var $l10n_object = ''; 
    394         var $l10n = array(); 
    395  
    396         function _WP_Script() { 
    397                 @list($this->handle, $this->src, $this->deps, $this->ver) = func_get_args(); 
    398                 if ( !is_array($this->deps) ) 
    399                         $this->deps = array(); 
    400                 if ( !$this->ver ) 
    401                         $this->ver = false; 
    402         } 
    403  
    404         function localize( $object_name, $l10n ) { 
    405                 if ( !$object_name || !is_array($l10n) ) 
    406                         return false; 
    407                 $this->l10n_object = $object_name; 
    408                 $this->l10n = $l10n; 
    409                 return true; 
    410         } 
    411 } 
    412  
    413 /** 
    414  * Prints script tags in document head 
    415  * 
    416  * Called by admin-header.php and by wp_head hook. Since it is called by wp_head on every page load, 
    417  * the function does not instantiate the WP_Scripts object unless script names are explicitly passed. 
    418  * Does make use of already instantiated $wp_scripts if present. 
    419  * Use provided wp_print_scripts hook to register/enqueue new scripts. 
    420  * 
    421  * @see WP_Scripts::print_scripts() 
    422  */ 
    423 function wp_print_scripts( $handles = false ) { 
    424         do_action( 'wp_print_scripts' ); 
    425         if ( '' === $handles ) // for wp_head 
    426                 $handles = false; 
    427  
    428         global $wp_scripts; 
    429         if ( !is_a($wp_scripts, 'WP_Scripts') ) { 
    430                 if ( !$handles ) 
    431                         return array(); // No need to instantiate if nothing's there. 
    432                 else 
    433                         $wp_scripts = new WP_Scripts(); 
    434         } 
    435  
    436         return $wp_scripts->print_scripts( $handles ); 
    437 } 
    438  
    439 function wp_register_script( $handle, $src, $deps = array(), $ver = false ) { 
    440         global $wp_scripts; 
    441         if ( !is_a($wp_scripts, 'WP_Scripts') ) 
    442                 $wp_scripts = new WP_Scripts(); 
    443  
    444         $wp_scripts->add( $handle, $src, $deps, $ver ); 
    445 } 
    446  
    447 /** 
    448  * Localizes a script 
    449  * 
    450  * Localizes only if script has already been added 
    451  * 
    452  * @see WP_Script::localize() 
    453  */ 
    454 function wp_localize_script( $handle, $object_name, $l10n ) { 
    455         global $wp_scripts; 
    456         if ( !is_a($wp_scripts, 'WP_Scripts') ) 
    457                 return false; 
    458  
    459         return $wp_scripts->localize( $handle, $object_name, $l10n ); 
    460 } 
    461  
    462 function wp_deregister_script( $handle ) { 
    463         global $wp_scripts; 
    464         if ( !is_a($wp_scripts, 'WP_Scripts') ) 
    465                 $wp_scripts = new WP_Scripts(); 
    466  
    467         $wp_scripts->remove( $handle ); 
    468 } 
    469  
    470 /** 
    471  * Equeues script 
    472  * 
    473  * Registers the script if src provided (does NOT overwrite) and enqueues. 
    474  * 
    475  * @see WP_Script::add(), WP_Script::enqueue() 
    476 */ 
    477 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false ) { 
    478         global $wp_scripts; 
    479         if ( !is_a($wp_scripts, 'WP_Scripts') ) 
    480                 $wp_scripts = new WP_Scripts(); 
    481  
    482         if ( $src ) { 
    483                 $_handle = explode('?', $handle); 
    484                 $wp_scripts->add( $_handle[0], $src, $deps, $ver ); 
    485         } 
    486         $wp_scripts->enqueue( $handle ); 
    487 } 
    488  
    489212function wp_prototype_before_jquery( $js_array ) { 
    490213        if ( false === $jquery = array_search( 'jquery', $js_array ) ) 
    491214                return $js_array; 
     
    515238        ) ); 
    516239} 
    517240 
     241add_action( 'wp_default_scripts', 'wp_default_scripts' ); 
    518242add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); 
    519243add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' ); 
    520  
    521 ?> 
  • wp-admin/admin-header.php

     
    4545<?php if ( ($parent_file != 'link-manager.php') && ($parent_file != 'options-general.php') && $ie6_no_scrollbar ) : ?> 
    4646<style type="text/css">* html { overflow-x: hidden; }</style> 
    4747<?php endif; 
    48 if ( isset($page_hook) ) 
     48 
     49if ( isset($page_hook) ) { 
    4950        do_action('admin_print_scripts-' . $page_hook); 
    50 else if ( isset($plugin_page) ) 
     51        do_action('admin_print_styles-' . $page_hook); 
     52        do_action('admin_head-' . $page_hook); 
     53} else if ( isset($plugin_page) ) { 
    5154        do_action('admin_print_scripts-' . $plugin_page); 
    52 else if ( isset($pagenow) ) 
     55        do_action('admin_print_styles-' . $plugin_page); 
     56        do_action('admin_head-' . $plugin_page); 
     57} else if ( isset($pagenow) ) { 
    5358        do_action('admin_print_scripts-' . $pagenow); 
     59        do_action('admin_print_styles-' . $pagenow); 
     60        do_action('admin_head-' . $pagenow); 
     61} 
    5462do_action('admin_print_scripts'); 
     63do_action('admin_print_styles'); 
     64do_action('admin_head'); 
    5565 
    56 if ( isset($page_hook) ) 
    57         do_action('admin_head-' . $page_hook); 
    58 else if ( isset($plugin_page) ) 
    59         do_action('admin_head-' . $plugin_page); 
    60 else if ( isset($pagenow) ) 
    61         do_action('admin_head-' . $pagenow); 
    62 do_action('admin_head'); 
    6366?> 
    6467</head> 
    6568<body class="wp-admin <?php echo apply_filters( 'admin_body_class', '' ); ?>">