root/trunk/wp-includes/script-loader.php

Revision 9114, 19.7 kB (checked in by azaozz, 3 days ago)

Use no-js reply on error in comment-reply.js, see #7635

  • Property svn:eol-style set to native
Line 
1 <?php
2 /**
3  * WordPress scripts and styles default loader.
4  *
5  * Most of the functionality that existed here was moved to
6  * {@link http://backpress.automattic.com/ BackPress}. WordPress themes and
7  * plugins will only be concerned about the filters and actions set in this
8  * file.
9  *
10  * @package WordPress
11  */
12
13 /** BackPress: WordPress Dependencies Class */
14 require( ABSPATH . WPINC . '/class.wp-dependencies.php' );
15
16 /** BackPress: WordPress Scripts Class */
17 require( ABSPATH . WPINC . '/class.wp-scripts.php' );
18
19 /** BackPress: WordPress Scripts Functions */
20 require( ABSPATH . WPINC . '/functions.wp-scripts.php' );
21
22 /** BackPress: WordPress Styles Class */
23 require( ABSPATH . WPINC . '/class.wp-styles.php' );
24
25 /** BackPress: WordPress Styles Functions */
26 require( ABSPATH . WPINC . '/functions.wp-styles.php' );
27
28 /**
29  * Setup WordPress scripts to load by default for Administration Panels.
30  *
31  * Localizes a few of the scripts.
32  *
33  * @since 2.6.0
34  *
35  * @param object $scripts WP_Scripts object.
36  */
37 function wp_default_scripts( &$scripts ) {
38     global $current_user;
39
40     if (!$guessurl = site_url())
41         $guessurl = wp_guess_url();
42
43     $userid = isset($current_user) ? $current_user->ID : 0;
44     $scripts->base_url = $guessurl;
45     $scripts->default_version = get_bloginfo( 'version' );
46
47     $scripts->add( 'common', '/wp-admin/js/common.js', array('jquery', 'user-settings'), '20081001' );
48     $scripts->add( 'sack', '/wp-includes/js/tw-sack.js', false, '1.6.1' );
49
50     $scripts->add( 'quicktags', '/wp-includes/js/quicktags.js', false, '20080823' );
51     $scripts->localize( 'quicktags', 'quicktagsL10n', array(
52         'quickLinks' => __('(Quick Links)'),
53         'wordLookup' => __('Enter a word to look up:'),
54         'dictionaryLookup' => attribute_escape(__('Dictionary lookup')),
55         'lookup' => attribute_escape(__('lookup')),
56         'closeAllOpenTags' => attribute_escape(__('Close all open tags')),
57         'closeTags' => attribute_escape(__('close tags')),
58         'enterURL' => __('Enter the URL'),
59         'enterImageURL' => __('Enter the URL of the image'),
60         'enterImageDescription' => __('Enter a description of the image')
61     ) );
62
63     $scripts->add( 'colorpicker', '/wp-includes/js/colorpicker.js', array('prototype'), '3517' );
64
65     // Modify this version when tinyMCE plugins are changed.
66     function mce_version() {
67         return '20080930';
68     }
69     add_filter( 'tiny_mce_version', 'mce_version' );
70
71     $scripts->add( 'editor', '/wp-admin/js/editor.js', false, mce_version() );
72
73     $scripts->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6');
74
75     $scripts->add( 'wp-ajax-response', '/wp-includes/js/wp-ajax-response.js', array('jquery'), '20080316' );
76     $scripts->localize( 'wp-ajax-response', 'wpAjax', array(
77         'noPerm' => __('You do not have permission to do that.'),
78         'broken' => __('An unidentified error has occurred.')
79     ) );
80
81     $scripts->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080701' );
82
83     $scripts->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20080729' );
84     $scripts->localize( 'wp-lists', 'wpListL10n', array(
85         'url' => admin_url('admin-ajax.php')
86     ) );
87
88     $scripts->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/scriptaculous.js', array('prototype'), '1.8.0');
89     $scripts->add( 'scriptaculous-builder', '/wp-includes/js/scriptaculous/builder.js', array('scriptaculous-root'), '1.8.0');
90     $scripts->add( 'scriptaculous-dragdrop', '/wp-includes/js/scriptaculous/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.8.0');
91     $scripts->add( 'scriptaculous-effects', '/wp-includes/js/scriptaculous/effects.js', array('scriptaculous-root'), '1.8.0');
92     $scripts->add( 'scriptaculous-slider', '/wp-includes/js/scriptaculous/slider.js', array('scriptaculous-effects'), '1.8.0');
93     $scripts->add( 'scriptaculous-sound', '/wp-includes/js/scriptaculous/sound.js', array( 'scriptaculous-root' ), '1.8.0' );
94     $scripts->add( 'scriptaculous-controls', '/wp-includes/js/scriptaculous/controls.js', array('scriptaculous-root'), '1.8.0');
95     $scripts->add( 'scriptaculous', '', array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls'), '1.8.0');
96
97     $scripts->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop'), '20070118');
98
99     $scripts->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.2.6');
100     $scripts->add( 'jquery-form', '/wp-includes/js/jquery/jquery.form.js', array('jquery'), '2.02');
101     $scripts->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.js', array('jquery'), '2.0-4561');
102     $scripts->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2' );
103     $scripts->add( 'suggest', '/wp-includes/js/jquery/suggest.js', array('jquery'), '1.1b');
104     $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20');
105     $scripts->add( 'jquery-hotkeys', '/wp-includes/js/jquery/jquery.hotkeys.js', array('jquery'), '0.0.2' );
106     $scripts->add( 'jquery-table-hotkeys', '/wp-includes/js/jquery/jquery.table-hotkeys.js', array('jquery', 'jquery-hotkeys'), '20081001' );
107     $scripts->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array('jquery'), '3.1-20080430');
108     $scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.0.2-20080430');
109     $scripts->add( 'swfupload-degrade', '/wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js', array('swfupload'), '2.0.2');
110     $scripts->localize( 'swfupload-degrade', 'uploadDegradeOptions', array(
111         'is_lighttpd_before_150' => is_lighttpd_before_150(),
112     ) );
113     $scripts->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2.0.2');
114     $scripts->add( 'swfupload-handlers', '/wp-includes/js/swfupload/handlers.js', array('swfupload'), '2.0.2-20080407');
115     // these error messages came from the sample swfupload js, they might need changing.
116     $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', array(
117             'queue_limit_exceeded' => __('You have attempted to queue too many files.'),
118             'file_exceeds_size_limit' => sprintf(__('This file is too big. Your php.ini upload_max_filesize is %s.'), @ini_get('upload_max_filesize')),
119             'zero_byte_file' => __('This file is empty. Please try another.'),
120             'invalid_filetype' => __('This file type is not allowed. Please try another.'),
121             'default_error' => __('An error occurred in the upload. Please try again later.'),
122             'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'),
123             'upload_limit_exceeded' => __('You may only upload 1 file.'),
124             'http_error' => __('HTTP error.'),
125             'upload_failed' => __('Upload failed.'),
126             'io_error' => __('IO error.'),
127             'security_error' => __('Security error.'),
128             'file_cancelled' => __('File cancelled.'),
129             'upload_stopped' => __('Upload stopped.'),
130             'dismiss' => __('Dismiss'),
131             'crunching' => __('Crunching&hellip;'),
132             'deleted' => __('Deleted'),
133     ) );
134
135     $scripts->add( 'jquery-ui-core', '/wp-includes/js/jquery/ui.core.js', array('jquery'), '1.5.2' );
136     $scripts->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery-ui-core'), '1.5.2' );
137     $scripts->add( 'jquery-ui-sortable', '/wp-includes/js/jquery/ui.sortable.js', array('jquery-ui-core'), '1.5.2' );
138     $scripts->add( 'jquery-ui-draggable', '/wp-includes/js/jquery/ui.draggable.js', array('jquery-ui-core'), '1.5.2' );
139     $scripts->add( 'jquery-ui-resizable', '/wp-includes/js/jquery/ui.resizable.js', array('jquery-ui-core'), '1.5.2' );
140     $scripts->add( 'jquery-ui-dialog', '/wp-includes/js/jquery/ui.dialog.js', array('jquery-ui-resizable', 'jquery-ui-draggable'), '1.5.2' );
141
142     $scripts->add( 'comment-reply', '/wp-includes/js/comment-reply.js', false, '20081009');
143
144     if ( is_admin() ) {
145         $scripts->add( 'ajaxcat', '/wp-admin/js/cat.js', array( 'wp-lists' ), '20071101' );
146         $scripts->localize( 'ajaxcat', 'catL10n', array(
147             'add' => attribute_escape(__('Add')),
148             'how' => __('Separate multiple categories with commas.')
149         ) );
150         $scripts->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists', 'columns', 'settings-box'), '20080925' );
151         $scripts->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists', 'columns', 'settings-box'), '20080925' );
152         $scripts->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' );
153         $scripts->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20080824' );
154         $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
155             'empty' => __('Strength indicator'),
156             'short' => __('Very weak'),
157             'bad' => __('Weak'),
158             'good' => __('Medium'),
159             'strong' => __('Strong')
160         ) );
161         $scripts->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists', 'jquery-ui-resizable', 'quicktags', 'columns', 'settings-box'), '20081007' );
162         $scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
163             'pending' => __('%i% pending'), // must look like: "# blah blah"
164             'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
165             'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last']),
166         ) );
167         $scripts->add( 'admin-users', '/wp-admin/js/users.js', array('wp-lists', 'columns', 'settings-box'), '20080925' );
168         $scripts->add( 'admin-forms', '/wp-admin/js/forms.js', array('jquery'), '20080729');
169         $scripts->add( 'xfn', '/wp-admin/js/xfn.js', false, '3517' );
170         $scripts->add( 'upload', '/wp-admin/js/upload.js', array('jquery'), '20070518' );
171         $scripts->add( 'postbox', '/wp-admin/js/postbox.js', array('jquery-ui-sortable'), '20080723' );
172         $scripts->localize( 'postbox', 'postboxL10n', array(
173             'requestFile' => admin_url('admin-ajax.php'),
174         ) );
175         $scripts->add( 'slug', '/wp-admin/js/slug.js', array('jquery'), '20080208' );
176         $scripts->localize( 'slug', 'slugL10n', array(
177             'requestFile' => admin_url('admin-ajax.php'),
178             'save' => __('Save'),
179             'cancel' => __('Cancel'),
180         ) );
181         $scripts->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug', 'settings-box'), '20080925' );
182         $scripts->localize( 'post', 'postL10n', array(
183             'tagsUsed' =>  __('Tags used on this post:'),
184             'add' => attribute_escape(__('Add')),
185             'addTag' => attribute_escape(__('Add new tag')),
186             'separate' => __('Separate tags with commas'),
187             'cancel' => __('Cancel'),
188             'edit' => __('Edit'),
189         ) );
190         $scripts->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox', 'settings-box'), '20080925' );
191         $scripts->localize( 'page', 'postL10n', array(
192             'cancel' => __('Cancel'),
193             'edit' => __('Edit'),
194         ) );
195         $scripts->add( 'link', '/wp-admin/js/link.js', array('jquery-ui-tabs', 'wp-lists', 'postbox', 'settings-box'), '20080925' );
196         $scripts->add( 'comment', '/wp-admin/js/comment.js', array('postbox'), '20080219' );
197         $scripts->localize( 'comment', 'commentL10n', array(
198             'cancel' => __('Cancel'),
199             'edit' => __('Edit'),
200         ) );
201         $scripts->add( 'admin-gallery', '/wp-admin/js/gallery.js', array( 'jquery-ui-sortable' ), '20080709' );
202         $scripts->add( 'media-upload', '/wp-admin/js/media-upload.js', array( 'thickbox' ), '20080723' );
203         $scripts->localize( 'upload', 'uploadL10n', array(
204             'browseTitle' => attribute_escape(__('Browse your files')),
205             'back' => __('&laquo; Back'),
206             'directTitle' => attribute_escape(__('Direct link to file')),
207             'edit' => __('Edit'),
208             'thumb' => __('Thumbnail'),
209             'full' => __('Full size'),
210             'icon' => __('Icon'),
211             'title' => __('Title'),
212             'show' => __('Show:'),
213             'link' => __('Link to:'),
214             'file' => __('File'),
215             'page' => __('Page'),
216             'none' => __('None'),
217             'editorText' => attribute_escape(__('Send to editor &raquo;')),
218             'insert' => __('Insert'),
219             'urlText' => __('URL'),
220             'desc' => __('Description'),
221             'deleteText' => attribute_escape(__('Delete File')),
222             'saveText' => attribute_escape(__('Save &raquo;')),
223             'confirmText' => __("Are you sure you want to delete the file '%title%'?\nClick ok to delete or cancel to go back.")
224         ) );
225         $scripts->add( 'admin-widgets', '/wp-admin/js/widgets.js', array( 'interface' ), '20080503' );
226         $scripts->localize( 'admin-widgets', 'widgetsL10n', array(
227             'add' => __('Add'),
228             'edit' => __('Edit'),
229             'cancel' => __('Cancel'),
230         ));
231
232         $scripts->add( 'word-count', '/wp-admin/js/word-count.js', array( 'jquery' ), '20080423' );
233         $scripts->localize( 'word-count', 'wordCountL10n', array(
234             'count' => __('Word count: %d')
235         ));
236
237         $scripts->add( 'wp-gears', '/wp-admin/js/wp-gears.js', false, '20080905' );
238         $scripts->localize( 'wp-gears', 'wpGearsL10n', array(
239             'updateCompleted' => __('Update completed.'),
240             'error' => __('Error:')
241         ));
242
243         $scripts->add( 'theme-preview', '/wp-admin/js/theme-preview.js', array( 'thickbox', 'jquery' ), '20080625' );
244
245         $scripts->add( 'inline-edit-post', '/wp-admin/js/inline-edit-post.js', array( 'jquery', 'jquery-form', 'suggest' ), '20081007' );
246         $scripts->localize( 'inline-edit-post', 'inlineEditL10n', array(
247             'edit' => __('Double-click to edit'),
248             'error' => __('Error while saving the changes.')
249         ) );
250
251         $scripts->add( 'inline-edit-tax', '/wp-admin/js/inline-edit-tax.js', array( 'jquery', 'jquery-form' ), '20081007' );
252         $scripts->localize( 'inline-edit-tax', 'inlineEditL10n', array(
253             'edit' => __('Double-click to edit'),
254             'error' => __('Error while saving the changes.')
255         ) );
256
257         $scripts->add( 'plugin-install', '/wp-admin/js/plugin-install.js', array( 'thickbox', 'jquery' ), '20080803' );
258         $scripts->localize( 'plugin-install', 'plugininstallL10n', array(
259             'plugin_information' => __('Plugin Information:')
260         ) );
261
262         $scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array('jquery'), '1.2' );
263
264         $scripts->add( 'user-settings', '/wp-admin/js/user-settings.js', array(), '20080829' );
265         $scripts->localize( 'user-settings', 'userSettings', array(
266             'url' => SITECOOKIEPATH,
267             'uid' => $userid,
268             'time' => time()
269         ) );
270
271         $scripts->add( 'posts', '/wp-admin/js/posts.js', array('columns', 'settings-box'), '20080925' );
272         $scripts->add( 'pages', '/wp-admin/js/pages.js', array('columns', 'settings-box'), '20080925' );
273         $scripts->add( 'links', '/wp-admin/js/links.js', array('columns', 'settings-box'), '20080925' );
274         $scripts->add( 'media', '/wp-admin/js/media.js', array('columns', 'settings-box'), '20080925' );
275
276         $scripts->add( 'columns', '/wp-admin/js/columns.js', false, '20080910' );
277         $scripts->localize( 'columns', 'columnsL10n', array(
278             'requestFile' => admin_url('admin-ajax.php'),
279         ) );
280
281         $scripts->add( 'settings-box', '/wp-admin/js/settings-box.js', array( 'jquery' ), '20080925' );
282
283         $scripts->add( 'dashboard', '/wp-admin/js/dashboard.js', array( 'jquery', 'admin-comments', 'postbox', 'settings-box' ), '20081008' );
284     }
285 }
286
287 /**
288  * Assign default styles to $styles object.
289  *
290  * Nothing is returned, because the $styles parameter is passed by reference.
291  * Meaning that whatever object is passed will be updated without having to
292  * reassign the variable that was passed back to the same value. This saves
293  * memory.
294  *
295  * Adding default styles is not the only task, it also assigns the base_url
296  * property, the default version, and text direction for the object.
297  *
298  * @since 2.6.0
299  *
300  * @param object $styles
301  */
302
303 function wp_default_styles( &$styles ) {
304     // This checks to see if site_url() returns something and if it does not
305     // then it assigns $guess_url to wp_guess_url(). Strange format, but it works.
306     if ( ! $guessurl = site_url() )
307         $guessurl = wp_guess_url();
308     $styles->base_url = $guessurl;
309     $styles->default_version = get_bloginfo( 'version' );
310     $styles->text_direction = 'rtl' == get_bloginfo( 'text_direction' ) ? 'rtl' : 'ltr';
311
312     $rtl_styles = array( 'global', 'colors', 'dashboard', 'ie', 'install', 'login', 'media', 'theme-editor', 'upload', 'widgets', 'press-this', 'press-this-ie' );
313
314     $styles->add( 'wp-admin', '/wp-admin/wp-admin.css', array(), '20081008' );
315     $styles->add_data( 'wp-admin', 'rtl', '/wp-admin/rtl.css' );
316
317     $styles->add( 'ie', '/wp-admin/css/ie.css' );
318     $styles->add_data( 'ie', 'conditional', 'gte IE 6' );
319
320     $styles->add( 'colors', true ); // Register "meta" stylesheet for admin colors
321     $styles->add( 'colors-fresh', '/wp-admin/css/colors-fresh.css' ); // for login.php.  Is there a better way?
322     $styles->add_data( 'colors-fresh', 'rtl', true );
323
324     $styles->add( 'global', '/wp-admin/css/global.css', array(), '20081001' );
325     $styles->add( 'media', '/wp-admin/css/media.css', array(), '20080709' );
326     $styles->add( 'widgets', '/wp-admin/css/widgets.css' );
327     $styles->add( 'dashboard', '/wp-admin/css/dashboard.css', array(), '20081008' );
328     $styles->add( 'install', '/wp-admin/css/install.css', array(), '20080708' );
329     $styles->add( 'theme-editor', '/wp-admin/css/theme-editor.css' );
330     $styles->add( 'press-this', '/wp-admin/css/press-this.css', array(), '20080922' );
331     $styles->add( 'press-this-ie', '/wp-admin/css/press-this-ie.css', array(), '20080915' );
332     $styles->add_data( 'press-this-ie', 'conditional', 'gte IE 6' );
333     $styles->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.css', array(), '20080613' );
334     $styles->add( 'login', '/wp-admin/css/login.css' );
335     $styles->add( 'plugin-install', '/wp-admin/css/plugin-install.css' );
336     $styles->add( 'farbtastic', '/wp-admin/css/farbtastic.css', array(), '1.2' );
337
338     foreach ( $rtl_styles as $rtl_style )
339         $styles->add_data( $rtl_style, 'rtl', true );
340 }
341
342 /**
343  * Reorder JavaScript scripts array to place prototype before jQuery.
344  *
345  * @since 2.3.1
346  *
347  * @param array $js_array JavaScript scripst array
348  * @return array Reordered array, if needed.
349  */
350
351 function wp_prototype_before_jquery( $js_array ) {
352     if ( false === $jquery = array_search( 'jquery', $js_array ) )
353         return $js_array;
354
355