From 3d0435bb582c0db60907b9d2ce398b7c2763923f Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 12 Mar 2008 05:50:07 +0000 Subject: [PATCH] Attachment editing from mdawaffe. fixes #6181 git-svn-id: http://svn.automattic.com/wordpress/trunk@7262 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/css/colors-classic.css | 2 +- wp-admin/css/colors-fresh.css | 2 +- wp-admin/css/media.css | 104 +++++++++++++++--------- wp-admin/edit-attachment-rows.php | 2 +- wp-admin/includes/media.php | 126 ++++++++++++++++++----------- wp-admin/js/common.js | 5 ++ wp-admin/media.php | 87 ++++++++++++++++++++ wp-includes/js/wp-ajax-response.js | 5 +- wp-includes/js/wp-lists.js | 7 +- wp-includes/link-template.php | 30 ++++--- wp-includes/script-loader.php | 6 +- 11 files changed, 269 insertions(+), 107 deletions(-) create mode 100644 wp-admin/media.php diff --git a/wp-admin/css/colors-classic.css b/wp-admin/css/colors-classic.css index 602fddcb9..4251f15d6 100644 --- a/wp-admin/css/colors-classic.css +++ b/wp-admin/css/colors-classic.css @@ -533,7 +533,7 @@ input.readonly { color: #cfebf6; } -div#media-upload-error, .file-error, .required abbr, .widget-control-remove:hover, .delete:hover { +div#media-upload-error, .file-error, abbr.required, .widget-control-remove:hover, .delete:hover { color: #f00; } diff --git a/wp-admin/css/colors-fresh.css b/wp-admin/css/colors-fresh.css index 2b4c17ff5..62e5d8afe 100644 --- a/wp-admin/css/colors-fresh.css +++ b/wp-admin/css/colors-fresh.css @@ -510,7 +510,7 @@ input.readonly { color: #555; } -div#media-upload-error, .file-error, .required abbr, .widget-control-remove:hover, .delete:hover { +div#media-upload-error, .file-error, abbr.required, .widget-control-remove:hover, .delete:hover { color: #f00; } diff --git a/wp-admin/css/media.css b/wp-admin/css/media.css index e461d20fe..a5b354ef6 100644 --- a/wp-admin/css/media.css +++ b/wp-admin/css/media.css @@ -36,13 +36,16 @@ form { margin: 0 0 0.5em 0; } +th { position: relative; } + .media-upload-form label.form-help, td.help { font-style: italic; font-weight: normal; } -.media-upload-form p { - margin: 0 1em 1em 0; +.media-upload-form p.help { + margin: 0; + padding: 0; } .media-upload-form fieldset { @@ -57,12 +60,8 @@ form { .align .field label { display: inline; padding: 0 0 0 28px; - margin: 0 0; + margin: 0 1em 0 0; } -.align .field input { - margin-left: 15px; -} - .image-align-none-label { background: url(../images/align-none.png) no-repeat center left; } @@ -87,31 +86,13 @@ tr.image-size label { display: inline; margin: 0 1em 0 0; } -tr.image-size td.field { - text-align: center; -} .pinkynail { max-width: 40px; max-height: 40px; } -#media-items { - border-width: 1px; - border-style: solid; - border-bottom: none; - width: 623px; -} -.media-item { - border-bottom-width: 1px; - border-bottom-style: solid; - width: 623px; - position: relative; - min-height: 36px; -} .filename { - line-height: 36px; - margin-left: 50px; - z-index: 2; + display: none; } button.dismiss { position: absolute; @@ -148,21 +129,26 @@ button.dismiss { height: 32px; max-width: 40px; } -.describe { - border-top-width: 1px; - border-top-style: solid; - padding: 5px; - width: 100%; - clear: both; + +tbody.media-item-info tr { + background-color: transparent; } +tbody.media-item-info th, tbody.media-item-info td { + border: none; + margin: 0; +} + +.form-table tbody.media-item-info { + border: 8px solid #fff; +} + .describe.startopen, .describe.startclosed { display: none; } -.required abbr { +abbr.required { text-decoration: none; border: none; } - .describe label { display: inline; } @@ -196,13 +182,57 @@ button.dismiss { z-index: 3; height: 36px; } -tr.align td.field { - text-align: center; -} .hidden { height: 0px; width: 0px; overflow: hidden; border: none; +} + +/* Specific to Uploader */ + +#media-upload .media-upload-form p { + margin: 0 1em 1em 0; +} +#media-upload p.help { + font-style: italic; + font-weight: normal; +} +#media-upload tr.image-size td.field { + text-align: center; +} +#media-upload #media-items { + border-width: 1px; + border-style: solid; + border-bottom: none; + width: 623px; +} + +#media-upload .media-item { + border-bottom-width: 1px; + border-bottom-style: solid; + width: 623px; + position: relative; + min-height: 36px; +} +#media-upload .filename { + display: block; + line-height: 36px; + margin-left: 50px; + z-index: 2; +} +#media-upload .describe { + border-top-width: 1px; + border-top-style: solid; + padding: 5px; + width: 100%; + clear: both; +} +#media-upload .describe th.label { + padding-top: .5em; + text-align: left; +} +#media-upload tr.align td.field { + text-align: center; } \ No newline at end of file diff --git a/wp-admin/edit-attachment-rows.php b/wp-admin/edit-attachment-rows.php index a7eb91db0..817f218d9 100644 --- a/wp-admin/edit-attachment-rows.php +++ b/wp-admin/edit-attachment-rows.php @@ -46,7 +46,7 @@ foreach($posts_columns as $column_name=>$column_display_name) { case 'media': ?> -
+
ID))); ?> ID); ?> diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index b538ee458..76a547305 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -484,6 +484,11 @@ function image_attachment_fields_to_edit($form_fields, $post) { add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2); +function media_single_attachment_fields_to_edit( $form_fields, $post ) { + unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']); + return $form_fields; +} + function image_attachment_fields_to_save($post, $attachment) { if ( substr($post['post_mime_type'], 0, 5) == 'image' ) { if ( strlen(trim($post['post_title'])) == 0 ) { @@ -548,7 +553,7 @@ function get_attachment_fields_to_edit($post, $errors = null) { 'label' => __('Link URL'), 'input' => 'html', 'html' => " - +
@@ -604,13 +609,17 @@ function get_media_items( $post_id, $errors ) { return ''; foreach ( $attachments as $id => $attachment ) - if ( $item = get_media_item($id, isset($errors[$id]) ? $errors[$id] : null) ) + if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) ) $output .= "\n
$item
\n
"; return $output; } -function get_media_item( $attachment_id, $errors = null, $send = true, $delete = true ) { +function get_media_item( $attachment_id, $args = null ) { + $default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true ); + $args = wp_parse_args( $args, $default_args ); + extract( $args, EXTR_SKIP ); + global $post_mime_types; if ( ( $attachment_id = intval($attachment_id) ) && $thumb_url = get_attachment_icon_src( $attachment_id ) ) $thumb_url = $thumb_url[0]; @@ -643,20 +652,31 @@ function get_media_item( $attachment_id, $errors = null, $send = true, $delete = $form_fields = get_attachment_fields_to_edit($post, $errors); - $class = empty($errors) ? 'startclosed' : 'startopen'; + if ( $toggle ) { + $class = empty($errors) ? 'startclosed' : 'startopen'; + $toggle_links = " + $toggle_on + $toggle_off"; + } else { + $class = 'form-table'; + $toggle_links = ''; + } + $item = " $type - $toggle_on - $toggle_off + $toggle_links
$filename
- +
+ - + - + - \n"; + + + \n"; $defaults = array( 'input' => 'text', @@ -671,7 +691,7 @@ function get_media_item( $attachment_id, $errors = null, $send = true, $delete = if ( $delete ) $delete = "" . __('Delete') . ""; if ( ( $send || $delete ) && !isset($form_fields['buttons']) ) - $form_fields['buttons'] = array('tr' => "\t\t\n"); + $form_fields['buttons'] = array('tr' => "\t\t\n"); $hidden_fields = array(); @@ -692,8 +712,11 @@ function get_media_item( $attachment_id, $errors = null, $send = true, $delete = continue; } - $required = $field['required'] ? '*' : ''; - $item .= "\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n"; $extra_rows = array(); @@ -709,10 +734,6 @@ function get_media_item( $attachment_id, $errors = null, $send = true, $delete = foreach ( array_unique((array) $field['errors']) as $error ) $extra_rows['error'][] = $error; - if ( !empty($field['helps']) ) - foreach ( array_unique((array) $field['helps']) as $help ) - $extra_rows['help'][] = $help; - if ( !empty($field['extra_rows']) ) foreach ( $field['extra_rows'] as $class => $rows ) foreach ( (array) $rows as $html ) @@ -720,11 +741,11 @@ function get_media_item( $attachment_id, $errors = null, $send = true, $delete = foreach ( $extra_rows as $class => $rows ) foreach ( $rows as $html ) - $item .= "\t\t\n"; + $item .= "\t\t\n"; } if ( !empty($form_fields['_final']) ) - $item .= "\t\t\n"; + $item .= "\t\t\n"; $item .= "\t
$filename
$post->post_mime_type
$post->post_mime_type
" . mysql2date($post->post_date, get_option('time_format')) . "
" . apply_filters('media_meta', '', $post) . "
" . apply_filters('media_meta', '', $post) . "
$send $delete
$send $delete
$required"; + $required = $field['required'] ? '*' : ''; + $class = $id; + $class .= $field['required'] ? ' form-required' : ''; + + $item .= "\t\t
"; if ( !empty($field[$field['input']]) ) $item .= $field[$field['input']]; elseif ( $field['input'] == 'textarea' ) { @@ -701,6 +724,8 @@ function get_media_item( $attachment_id, $errors = null, $send = true, $delete = } else { $item .= ""; } + if ( !empty($field['helps']) ) + $item .= "

" . join( "

\n

", array_unique((array) $field['helps']) ) . '

'; $item .= "
$html
$html
{$form_fields['_final']}
{$form_fields['_final']}
\n"; foreach ( $hidden_fields as $name => $value ) @@ -1037,19 +1058,22 @@ function type_form_image() { return ' - - + - - + - + - - + - + @@ -1075,18 +1099,22 @@ function type_form_audio() { return '
* + + * +
* + + * +
' . __('Alternate text, e.g. "The Mona Lisa"') . '
' . __('Alternate text, e.g. "The Mona Lisa"') . '
@@ -1062,7 +1086,7 @@ function type_form_image() {
- - + - - + - + - + @@ -1099,18 +1127,22 @@ function type_form_video() { return '
* + + * +
* + + * +
' . __('Link text, e.g. "Still Alive by Jonathan Coulton"') . '
' . __('Link text, e.g. "Still Alive by Jonathan Coulton"') . '
- - + - - + - + - + @@ -1123,18 +1155,22 @@ function type_form_file() { return '
* + + * +
* + + * +
' . __('Link text, e.g. "Lucy on YouTube"') . '
' . __('Link text, e.g. "Lucy on YouTube"') . '
- - + - - + - + - + diff --git a/wp-admin/js/common.js b/wp-admin/js/common.js index 2abefd83b..9f05e55f5 100644 --- a/wp-admin/js/common.js +++ b/wp-admin/js/common.js @@ -4,4 +4,9 @@ addLoadEvent( function() { // Reveal jQuery('.wp-no-js-hidden').removeClass( 'wp-no-js-hidden' ); + + // Basic form validation + if ( ( 'undefined' != typeof wpAjax ) && jQuery.isFunction( wpAjax.validateForm ) ) { + jQuery('form').submit( function() { return wpAjax.validateForm( jQuery(this) ); } ); + } }); diff --git a/wp-admin/media.php b/wp-admin/media.php new file mode 100644 index 000000000..bd64104a8 --- /dev/null +++ b/wp-admin/media.php @@ -0,0 +1,87 @@ +

$message

\n"; + +?> + +
+ +

+ +
+
+
+ false, 'send' => false, 'delete' => false, 'errors' => $errors ) ); ?> +
+
+ +

+ + + + +

+ + +
+ + diff --git a/wp-includes/js/wp-ajax-response.js b/wp-includes/js/wp-ajax-response.js index 28ba769b4..419777371 100644 --- a/wp-includes/js/wp-ajax-response.js +++ b/wp-includes/js/wp-ajax-response.js @@ -50,7 +50,8 @@ wpAjax = jQuery.extend( { else if ( 0 === x ) { return !re.html('

' + this.broken + '

'); } return true; }, - invalidateForm: function( jQ ) { - jQ.addClass( 'form-invalid' ).change( function() { jQuery(this).removeClass( 'form-invalid' ); } ); + validateForm: function( selector ) { + selector = jQuery( selector ); + return !selector.find('.form-required').andSelf().filter('.form-required:has(:input[value=""]), .form-required:input[value=""]').addClass( 'form-invalid' ).change( function() { jQuery(this).removeClass( 'form-invalid' ); } ).size(); } }, wpAjax || { noPerm: 'You do not have permission to do that.', broken: 'AJAX is teh b0rked.' } ); diff --git a/wp-includes/js/wp-lists.js b/wp-includes/js/wp-lists.js index 3fc0ecf23..e0c5b25a5 100644 --- a/wp-includes/js/wp-lists.js +++ b/wp-includes/js/wp-lists.js @@ -70,11 +70,8 @@ var wpList = { s.nonce = wpList.nonce(e,s); var es = $('#' + s.element + ' :input').not('[name=_ajax_nonce], [name=_wpnonce], [name=action]'); - var required = $('#' + s.element + ' .form-required:has(:input[value=""]), #' + s.element + ' .form-required:input[value=""]'); - if ( required.size() ) { - wpAjax.invalidateForm( required ); - return false; - } + var valid = wpAjax.validateForm( '#' + s.element ); + if ( !valid ) { return false; } s.data = $.param( $.extend( { _ajax_nonce: s.nonce, action: s.action }, wpAjax.unserialize( cls[4] || '' ) ) ); var formData = $.isFunction(es.fieldSerialize) ? es.fieldSerialize() : es.serialize(); diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index c191668a4..029aa2bd8 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -439,21 +439,31 @@ function get_search_comments_feed_link($search_query = '', $feed = '') { } function get_edit_post_link( $id = 0 ) { - $post = &get_post( $id ); + if ( !$post = &get_post( $id ) ) + return; - if ( $post->post_type == 'page' ) { + switch ( $post->post_type ) : + case 'page' : if ( !current_user_can( 'edit_page', $post->ID ) ) return; - $file = 'page'; - } else { + $var = 'post'; + break; + case 'attachment' : + if ( !current_user_can( 'edit_post', $post->ID ) ) + return; + $file = 'media'; + $var = 'attachment_id'; + break; + default : if ( !current_user_can( 'edit_post', $post->ID ) ) return; - $file = 'post'; - } - - return apply_filters( 'get_edit_post_link', get_bloginfo( 'wpurl' ) . '/wp-admin/' . $file . '.php?action=edit&post=' . $post->ID, $post->ID ); + $var = 'post'; + break; + endswitch; + + return apply_filters( 'get_edit_post_link', get_bloginfo( 'wpurl' ) . "/wp-admin/$file.php?action=edit&$var=$post->ID", $post->ID ); } function edit_post_link( $link = 'Edit This', $before = '', $after = '' ) { @@ -462,13 +472,9 @@ function edit_post_link( $link = 'Edit This', $before = '', $after = '' ) { if ( $post->post_type == 'page' ) { if ( !current_user_can( 'edit_page', $post->ID ) ) return; - - $file = 'page'; } else { if ( !current_user_can( 'edit_post', $post->ID ) ) return; - - $file = 'post'; } $link = '' . $link . ''; diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index f615a38bf..a5fac3a50 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -41,13 +41,13 @@ class WP_Scripts { $this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6'); - $this->add( 'wp-ajax-response', '/wp-includes/js/wp-ajax-response.js', array('jquery'), '20080229' . mt_rand() ); + $this->add( 'wp-ajax-response', '/wp-includes/js/wp-ajax-response.js', array('jquery'), '20080312' ); $this->localize( 'wp-ajax-response', 'wpAjax', array( 'noPerm' => 'You do not have permission to do that.', 'broken' => 'AJAX is teh b0rked.' ) ); - $this->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080221' . mt_rand()); + $this->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080312' ); $this->add( 'wp-ajax', '/wp-includes/js/wp-ajax.js', array('prototype'), '20070306'); $this->localize( 'wp-ajax', 'WPAjaxL10n', array( @@ -57,7 +57,7 @@ class WP_Scripts { 'whoaText' => __("Slow down, I'm still sending your data!") ) ); - $this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20080228' . mt_rand()); + $this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20080312' ); $this->localize( 'wp-lists', 'wpListL10n', array( 'url' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php' ) );
* + + * +
* + + * +
' . __('Link text, e.g. "Ransom Demands (PDF)"') . '
' . __('Link text, e.g. "Ransom Demands (PDF)"') . '