X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/11be8dc178e77d0b46189bbd8e33a216a9b90942..refs/tags/wordpress-2.8:/wp-admin/includes/post.php diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 17816216..c7acf915 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -319,9 +319,9 @@ function bulk_edit_posts( $post_data = null ) { */ function get_default_post_to_edit() { if ( !empty( $_REQUEST['post_title'] ) ) - $post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] )); + $post_title = esc_html( stripslashes( $_REQUEST['post_title'] )); else if ( !empty( $_REQUEST['popuptitle'] ) ) { - $post_title = wp_specialchars( stripslashes( $_REQUEST['popuptitle'] )); + $post_title = esc_html( stripslashes( $_REQUEST['popuptitle'] )); $post_title = funky_javascript_fix( $post_title ); } else { $post_title = ''; @@ -329,16 +329,16 @@ function get_default_post_to_edit() { $post_content = ''; if ( !empty( $_REQUEST['content'] ) ) - $post_content = wp_specialchars( stripslashes( $_REQUEST['content'] )); + $post_content = esc_html( stripslashes( $_REQUEST['content'] )); else if ( !empty( $post_title ) ) { - $text = wp_specialchars( stripslashes( urldecode( $_REQUEST['text'] ) ) ); + $text = esc_html( stripslashes( urldecode( $_REQUEST['text'] ) ) ); $text = funky_javascript_fix( $text); - $popupurl = clean_url($_REQUEST['popupurl']); + $popupurl = esc_url($_REQUEST['popupurl']); $post_content = ''.$post_title.''."\n$text"; } if ( !empty( $_REQUEST['excerpt'] ) ) - $post_excerpt = wp_specialchars( stripslashes( $_REQUEST['excerpt'] )); + $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] )); else $post_excerpt = ''; @@ -346,6 +346,7 @@ function get_default_post_to_edit() { $post->post_name = ''; $post->post_author = ''; $post->post_date = ''; + $post->post_date_gmt = ''; $post->post_password = ''; $post->post_status = 'draft'; $post->post_type = 'post'; @@ -397,30 +398,42 @@ function get_post_to_edit( $id ) { } /** - * {@internal Missing Short Description}} + * Determine if a post exists based on title, content, and date * * @since unknown * - * @param unknown_type $title - * @param unknown_type $content - * @param unknown_type $post_date - * @return unknown + * @param string $title Post title + * @param string $content Optional post content + * @param string $date Optional post date + * @return int Post ID if post exists, 0 otherwise. */ -function post_exists($title, $content = '', $post_date = '') { +function post_exists($title, $content = '', $date = '') { global $wpdb; - $title = stripslashes($title); - $content = stripslashes($content); - $post_date = stripslashes($post_date); + $post_title = stripslashes( sanitize_post_field( 'post_title', $title, 0, 'db' ) ); + $post_content = stripslashes( sanitize_post_field( 'post_content', $content, 0, 'db' ) ); + $post_date = stripslashes( sanitize_post_field( 'post_date', $date, 0, 'db' ) ); - if (!empty ($post_date)) - $post_date = $wpdb->prepare("AND post_date = %s", $post_date); + $query = "SELECT ID FROM $wpdb->posts WHERE 1=1"; + $args = array(); - if (!empty ($title)) - return $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title = %s $post_date", $title) ); - else - if (!empty ($content)) - return $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_content = %s $post_date", $content) ); + if ( !empty ( $date ) ) { + $query .= ' AND post_date = %s'; + $args[] = $post_date; + } + + if ( !empty ( $title ) ) { + $query .= ' AND post_title = %s'; + $args[] = $post_title; + } + + if ( !empty ( $content ) ) { + $query .= 'AND post_content = %s'; + $args[] = $post_content; + } + + if ( !empty ( $args ) ) + return $wpdb->get_var( $wpdb->prepare($query, $args) ); return 0; } @@ -664,10 +677,13 @@ function update_meta( $meta_id, $meta_key, $meta_value ) { if ( in_array($meta_key, $protected) ) return false; + if ( '' === trim( $meta_value ) ) + return false; + $post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $meta_id) ); wp_cache_delete($post_id, 'post_meta'); - $meta_value = maybe_serialize( stripslashes( $meta_value )); + $meta_value = maybe_serialize( stripslashes( $meta_value ) ); $meta_id = (int) $meta_id; $data = compact( 'meta_key', 'meta_value' ); @@ -743,7 +759,7 @@ function _relocate_children( $old_ID, $new_ID ) { global $wpdb; $old_ID = (int) $old_ID; $new_ID = (int) $new_ID; - return $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = %d WHERE post_parent = %d", $new_ID, $old_ID) ); + return $wpdb->update($wpdb->posts, array('post_parent' => $new_ID), array('post_parent' => $old_ID) ); } /** @@ -774,11 +790,11 @@ function wp_edit_posts_query( $q = false ) { $q['m'] = isset($q['m']) ? (int) $q['m'] : 0; $q['cat'] = isset($q['cat']) ? (int) $q['cat'] : 0; $post_stati = array( // array( adj, noun ) - 'publish' => array(__('Published'), __('Published posts'), __ngettext_noop('Published (%s)', 'Published (%s)')), - 'future' => array(__('Scheduled'), __('Scheduled posts'), __ngettext_noop('Scheduled (%s)', 'Scheduled (%s)')), - 'pending' => array(__('Pending Review'), __('Pending posts'), __ngettext_noop('Pending Review (%s)', 'Pending Review (%s)')), - 'draft' => array(__('Draft'), _c('Drafts|manage posts header'), __ngettext_noop('Draft (%s)', 'Drafts (%s)')), - 'private' => array(__('Private'), __('Private posts'), __ngettext_noop('Private (%s)', 'Private (%s)')), + 'publish' => array(_x('Published', 'post'), __('Published posts'), _n_noop('Published (%s)', 'Published (%s)')), + 'future' => array(_x('Scheduled', 'post'), __('Scheduled posts'), _n_noop('Scheduled (%s)', 'Scheduled (%s)')), + 'pending' => array(_x('Pending Review', 'post'), __('Pending posts'), _n_noop('Pending Review (%s)', 'Pending Review (%s)')), + 'draft' => array(_x('Draft', 'post'), _x('Drafts', 'manage posts header'), _n_noop('Draft (%s)', 'Drafts (%s)')), + 'private' => array(_x('Private', 'post'), __('Private posts'), _n_noop('Private (%s)', 'Private (%s)')), ); $post_stati = apply_filters('post_stati', $post_stati); @@ -802,7 +818,12 @@ function wp_edit_posts_query( $q = false ) { $orderby = 'date'; } - wp("post_type=post&what_to_show=posts$post_status_q&posts_per_page=15&order=$order&orderby=$orderby"); + $posts_per_page = get_user_option('edit_per_page'); + if ( empty($posts_per_page) ) + $posts_per_page = 15; + $posts_per_page = apply_filters('edit_posts_per_page', $posts_per_page); + + wp("post_type=post&$post_status_q&posts_per_page=$posts_per_page&order=$order&orderby=$orderby"); return array($post_stati, $avail_post_stati); } @@ -838,11 +859,14 @@ function wp_edit_attachments_query( $q = false ) { $q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0; $q['post_type'] = 'attachment'; $q['post_status'] = 'any'; - $q['posts_per_page'] = 15; + $media_per_page = get_user_option('upload_per_page'); + if ( empty($media_per_page) ) + $media_per_page = 20; + $q['posts_per_page'] = $media_per_page; $post_mime_types = array( // array( adj, noun ) - 'image' => array(__('Images'), __('Manage Images'), __ngettext_noop('Image (%s)', 'Images (%s)')), - 'audio' => array(__('Audio'), __('Manage Audio'), __ngettext_noop('Audio (%s)', 'Audio (%s)')), - 'video' => array(__('Video'), __('Manage Video'), __ngettext_noop('Video (%s)', 'Video (%s)')), + 'image' => array(__('Images'), __('Manage Images'), _n_noop('Image (%s)', 'Images (%s)')), + 'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio (%s)', 'Audio (%s)')), + 'video' => array(__('Video'), __('Manage Video'), _n_noop('Video (%s)', 'Video (%s)')), ); $post_mime_types = apply_filters('post_mime_types', $post_mime_types); @@ -871,7 +895,7 @@ function postbox_classes( $id, $page ) { $current_user = wp_get_current_user(); if ( $closed = get_user_option('closedpostboxes_'.$page, 0, false ) ) { if ( !is_array( $closed ) ) return ''; - return in_array( $id, $closed )? 'if-js-closed' : ''; + return in_array( $id, $closed )? 'closed' : ''; } else { return ''; } @@ -903,13 +927,15 @@ function get_sample_permalink($id, $title=null, $name = null) { $post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID); } + $post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent); + // If the user wants to set a new name -- override the current one // Note: if empty name is supplied -- use the title instead, see #6072 if (!is_null($name)) { $post->post_name = sanitize_title($name? $name : $title, $post->ID); } - $post->filter = 'sample'; + $post->filter = 'sample'; $permalink = get_permalink($post, true); @@ -943,12 +969,22 @@ function get_sample_permalink($id, $title=null, $name = null) { * @param unknown_type $new_slug * @return unknown */ -function get_sample_permalink_html($id, $new_title=null, $new_slug=null) { +function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { $post = &get_post($id); list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug); - if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) { - return ''; + if ( 'publish' == $post->post_status ) + $view_post = 'post' == $post->post_type ? __('View Post') : __('View Page'); + + if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) { + $return = '' . __('Permalink:') . "\n" . '' . $permalink . "\n"; + if ( current_user_can( 'manage_options' ) ) + $return .= '' . __('Change Permalinks') . "\n"; + if ( isset($view_post) ) + $return .= "$view_post\n"; + + return $return; } + $title = __('Click to edit this part of the permalink'); if (function_exists('mb_strlen')) { if (mb_strlen($post_name) > 30) { @@ -963,10 +999,16 @@ function get_sample_permalink_html($id, $new_title=null, $new_slug=null) { $post_name_abridged = $post_name; } } - $post_name_html = ''.$post_name_abridged.''.$post_name.''; + + $post_name_html = '' . $post_name_abridged . ''; $display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink); + $view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink); $return = '' . __('Permalink:') . "\n" . '' . $display_link . "\n"; - $return .= '' . __('Edit') . "\n"; + $return .= '' . __('Edit') . "\n"; + $return .= '' . $post_name . "\n"; + if ( isset($view_post) ) + $return .= "$view_post\n"; + return $return; } @@ -1039,6 +1081,9 @@ function wp_create_post_autosave( $post_id ) { return wp_update_post( $new_autosave ); } + // _wp_put_post_revision() expects unescaped. + $_POST = stripslashes_deep($_POST); + // Otherwise create the new autosave as a special post revision return _wp_put_post_revision( $_POST, true ); } @@ -1107,20 +1152,24 @@ function post_preview() { /** * Adds the TinyMCE editor used on the Write and Edit screens. * - * Has option to output a trimmed down version used in Press This. - * * @package WordPress * @since 2.7 + * + * TinyMCE is loaded separately from other Javascript by using wp-tinymce.php. It outputs concatenated + * and optionaly pre-compressed version of the core and all default plugins. Additional plugins are loaded + * directly by TinyMCE using non-blocking method. Custom plugins can be refreshed by adding a query string + * to the URL when queueing them with the mce_external_plugins filter. + * + * @param bool $teeny optional Output a trimmed down version used in Press This. */ function wp_tiny_mce( $teeny = false ) { + global $concatenate_scripts, $compress_scripts, $tinymce_version; + if ( ! user_can_richedit() ) return; $baseurl = includes_url('js/tinymce'); - $mce_css = $baseurl . '/wordpress.css'; - $mce_css = apply_filters('mce_css', $mce_css); - $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1 /* @@ -1135,7 +1184,7 @@ function wp_tiny_mce( $teeny = false ) { $plugins = apply_filters( 'teeny_mce_plugins', array('safari', 'inlinepopups', 'media', 'autosave', 'fullscreen') ); $ext_plugins = ''; } else { - $plugins = array( 'safari', 'inlinepopups', 'autosave', 'spellchecker', 'paste', 'wordpress', 'media', 'fullscreen', 'wpeditimage', 'wpgallery' ); + $plugins = array( 'safari', 'inlinepopups', 'spellchecker', 'paste', 'wordpress', 'media', 'fullscreen', 'wpeditimage', 'wpgallery', 'tabfocus' ); /* The following filter takes an associative array of external plugins for TinyMCE in the form 'plugin_name' => 'url'. @@ -1146,7 +1195,7 @@ function wp_tiny_mce( $teeny = false ) { */ $mce_external_plugins = apply_filters('mce_external_plugins', array()); - $ext_plugins = "\n"; + $ext_plugins = ''; if ( ! empty($mce_external_plugins) ) { /* @@ -1239,8 +1288,8 @@ function wp_tiny_mce( $teeny = false ) { // TinyMCE init settings $initArray = array ( - 'mode' => 'none', - 'onpageload' => 'switchEditors.edInit', + 'mode' => 'specific_textareas', + 'editor_selector' => 'theEditor', 'width' => '100%', 'theme' => 'advanced', 'skin' => 'wp_theme', @@ -1261,19 +1310,21 @@ function wp_tiny_mce( $teeny = false ) { 'convert_urls' => false, 'apply_source_formatting' => false, 'remove_linebreaks' => true, - 'paste_convert_middot_lists' => true, - 'paste_remove_spans' => true, - 'paste_remove_styles' => true, 'gecko_spellcheck' => true, 'entities' => '38,amp,60,lt,62,gt', 'accessibility_focus' => true, - 'tab_focus' => ':prev,:next', - 'content_css' => "$mce_css", + 'tabfocus_elements' => 'major-publishing-actions', + 'media_strict' => false, 'save_callback' => 'switchEditors.saveCallback', 'wpeditimage_disable_captions' => $no_captions, 'plugins' => "$plugins" ); + $mce_css = trim(apply_filters('mce_css', ''), ' ,'); + + if ( ! empty($mce_css) ) + $initArray['content_css'] = "$mce_css"; + // For people who really REALLY know what they're doing with TinyMCE // You can modify initArray to add, remove, change elements of the config before tinyMCE.init // Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through "tiny_mce_before_init". @@ -1284,9 +1335,26 @@ function wp_tiny_mce( $teeny = false ) { $initArray = apply_filters('tiny_mce_before_init', $initArray); } - $language = $initArray['language']; + if ( empty($initArray['theme_advanced_buttons3']) && !empty($initArray['theme_advanced_buttons4']) ) { + $initArray['theme_advanced_buttons3'] = $initArray['theme_advanced_buttons4']; + $initArray['theme_advanced_buttons4'] = ''; + } - $ver = apply_filters('tiny_mce_version', '3101'); + if ( ! isset($concatenate_scripts) ) + script_concat_settings(); + + $language = $initArray['language']; + $zip = $compress_scripts ? 1 : 0; + + /** + * Deprecated + * + * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE. + * These plugins can be refreshed by appending query string to the URL passed to mce_external_plugins filter. + * If the plugin has a popup dialog, a query string can be added to the button action that opens it (in the plugin's code). + */ + $version = apply_filters('tiny_mce_version', ''); + $version = 'ver=' . $tinymce_version . $version; if ( 'en' != $language ) include_once(ABSPATH . WPINC . '/js/tinymce/langs/wp-langs.php'); @@ -1302,52 +1370,35 @@ function wp_tiny_mce( $teeny = false ) { tinyMCEPreInit = { base : "", suffix : "", - query : "ver=", + query : "", mceInit : {}, - - go : function() { - var t = this, sl = tinymce.ScriptLoader, ln = t.mceInit.language, th = t.mceInit.theme, pl = t.mceInit.plugins; - - sl.markDone(t.base + '/langs/' + ln + '.js'); - - sl.markDone(t.base + '/themes/' + th + '/langs/' + ln + '.js'); - sl.markDone(t.base + '/themes/' + th + '/langs/' + ln + '_dlg.js'); - - tinymce.each(pl.split(','), function(n) { - if (n && n.charAt(0) != '-') { - sl.markDone(t.base + '/plugins/' + n + '/langs/' + ln + '.js'); - sl.markDone(t.base + '/plugins/' + n + '/langs/' + ln + '_dlg.js'); - } - }); - }, - - load_ext : function(url,lang) { - var sl = tinymce.ScriptLoader; - - sl.markDone(url + '/langs/' + lang + '.js'); - sl.markDone(url + '/langs/' + lang + '_dlg.js'); - } + load_ext : function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');} }; /* ]]> */ - - + +\n"; + else + echo "\n"; + + if ( 'en' != $language && isset($lang) ) + echo "\n"; + else + echo "\n"; +?> + +/* + +tinyMCEPreInit.go(); - +(function(){var t=tinyMCEPreInit,sl=tinymce.ScriptLoader,ln=t.mceInit.language,th=t.mceInit.theme,pl=t.mceInit.plugins;sl.markDone(t.base+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'_dlg.js');tinymce.each(pl.split(','),function(n){if(n&&n.charAt(0)!='-'){sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'.js');sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'_dlg.js');}});})(); - -