<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[22869] trunk: Add a delete link to the media modal.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/22869">22869</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2012-11-27 15:50:59 +0000 (Tue, 27 Nov 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add a delete link to the media modal.

Props merty, nacin, koopersmith
fixes <a href="http://core.trac.wordpress.org/ticket/22524">#22524</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesajaxactionsphp">trunk/wp-admin/includes/ajax-actions.php</a></li>
<li><a href="#trunkwpincludescssmediaviewscss">trunk/wp-includes/css/media-views.css</a></li>
<li><a href="#trunkwpincludesjsmediamodelsjs">trunk/wp-includes/js/media-models.js</a></li>
<li><a href="#trunkwpincludesjsmediaviewsjs">trunk/wp-includes/js/media-views.js</a></li>
<li><a href="#trunkwpincludesmediaphp">trunk/wp-includes/media.php</a></li>
<li><a href="#trunkwpincludesscriptloaderphp">trunk/wp-includes/script-loader.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesajaxactionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/ajax-actions.php (22868 => 22869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/ajax-actions.php        2012-11-27 15:35:36 UTC (rev 22868)
+++ trunk/wp-admin/includes/ajax-actions.php        2012-11-27 15:50:59 UTC (rev 22869)
</span><span class="lines">@@ -1843,7 +1843,7 @@
</span><span class="cx">         if ( ! $id = absint( $_REQUEST['id'] ) )
</span><span class="cx">                 wp_send_json_error();
</span><span class="cx"> 
</span><del>-        check_ajax_referer( 'save-attachment', 'nonce' );
</del><ins>+        check_ajax_referer( 'update-post_' . $id, 'nonce' );
</ins><span class="cx"> 
</span><span class="cx">         if ( ! current_user_can( 'edit_post', $id ) )
</span><span class="cx">                 wp_send_json_error();
</span><span class="lines">@@ -1889,7 +1889,7 @@
</span><span class="cx">                 wp_send_json_error();
</span><span class="cx">         $attachment_data = $_REQUEST['attachments'][ $id ];
</span><span class="cx"> 
</span><del>-        check_ajax_referer( 'save-attachment', 'nonce' );
</del><ins>+        check_ajax_referer( 'update-post_' . $id, 'nonce' );
</ins><span class="cx"> 
</span><span class="cx">         if ( ! current_user_can( 'edit_post', $id ) )
</span><span class="cx">                 wp_send_json_error();
</span></span></pre></div>
<a id="trunkwpincludescssmediaviewscss"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/css/media-views.css (22868 => 22869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/css/media-views.css        2012-11-27 15:35:36 UTC (rev 22868)
+++ trunk/wp-includes/css/media-views.css        2012-11-27 15:50:59 UTC (rev 22869)
</span><span class="lines">@@ -1191,6 +1191,18 @@
</span><span class="cx">         float: left;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+.attachment-info .delete-attachment a {
+        color: red;
+        padding: 2px 4px;
+        margin: -2px -4px;
+        text-decoration: none;
+}
+
+.attachment-info .delete-attachment a:hover {
+        color: #fff;
+        background: red;
+}
+
</ins><span class="cx"> /**
</span><span class="cx">  * Attachment Display Settings
</span><span class="cx">  */
</span></span></pre></div>
<a id="trunkwpincludesjsmediamodelsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-models.js (22868 => 22869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-models.js        2012-11-27 15:35:36 UTC (rev 22868)
+++ trunk/wp-includes/js/media-models.js        2012-11-27 15:50:59 UTC (rev 22869)
</span><span class="lines">@@ -218,6 +218,11 @@
</span><span class="cx">          */
</span><span class="cx">         Attachment = media.model.Attachment = Backbone.Model.extend({
</span><span class="cx">                 sync: function( method, model, options ) {
</span><ins>+                        // If the attachment does not yet have an `id`, return an instantly
+                        // rejected promise. Otherwise, all of our requests will fail.
+                        if ( _.isUndefined( this.id ) )
+                                return $.Deferred().reject().promise();
+
</ins><span class="cx">                         // Overload the `read` request so Attachment.fetch() functions correctly.
</span><span class="cx">                         if ( 'read' === method ) {
</span><span class="cx">                                 options = options || {};
</span><span class="lines">@@ -237,7 +242,7 @@
</span><span class="cx">                                 options.data = _.extend( options.data || {}, {
</span><span class="cx">                                         action:  'save-attachment',
</span><span class="cx">                                         id:      this.id,
</span><del>-                                        nonce:   media.model.settings.saveAttachmentNonce,
</del><ins>+                                        nonce:   this.get('nonces').update,
</ins><span class="cx">                                         post_id: media.model.settings.postId
</span><span class="cx">                                 });
</span><span class="cx"> 
</span><span class="lines">@@ -252,6 +257,18 @@
</span><span class="cx">                                 }
</span><span class="cx"> 
</span><span class="cx">                                 return media.ajax( options );
</span><ins>+
+                        // Overload the `delete` request so attachments can be removed.
+                        // This will permanently delete an attachment.
+                        } else if ( 'delete' === method ) {
+                                options = options || {};
+                                options.context = this;
+                                options.data = _.extend( options.data || {}, {
+                                        action:   'delete-post',
+                                        id:       this.id,
+                                        _wpnonce: this.get('nonces')['delete']
+                                });
+                                return media.ajax( options );
</ins><span class="cx">                         }
</span><span class="cx">                 },
</span><span class="cx"> 
</span><span class="lines">@@ -270,7 +287,7 @@
</span><span class="cx"> 
</span><span class="cx">                         return media.post( 'save-attachment-compat', _.defaults({
</span><span class="cx">                                 id:      this.id,
</span><del>-                                nonce:   media.model.settings.saveAttachmentNonce,
</del><ins>+                                nonce:   this.get('nonces').update,
</ins><span class="cx">                                 post_id: media.model.settings.postId
</span><span class="cx">                         }, data ) ).done( function( resp, status, xhr ) {
</span><span class="cx">                                 model.set( model.parse( resp, xhr ), options );
</span></span></pre></div>
<a id="trunkwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-views.js (22868 => 22869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-views.js        2012-11-27 15:35:36 UTC (rev 22868)
+++ trunk/wp-includes/js/media-views.js        2012-11-27 15:50:59 UTC (rev 22869)
</span><span class="lines">@@ -3406,7 +3406,15 @@
</span><span class="cx">                         'change [data-setting]':          'updateSetting',
</span><span class="cx">                         'change [data-setting] input':    'updateSetting',
</span><span class="cx">                         'change [data-setting] select':   'updateSetting',
</span><del>-                        'change [data-setting] textarea': 'updateSetting'
</del><ins>+                        'change [data-setting] textarea': 'updateSetting',
+                        'click .delete-attachment':       'deleteAttachment'
+                },
+
+                deleteAttachment: function(event) {
+                        event.preventDefault();
+
+                        if ( confirm( l10n.warnDelete ) )
+                                this.model.destroy();
</ins><span class="cx">                 }
</span><span class="cx">         });
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (22868 => 22869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2012-11-27 15:35:36 UTC (rev 22868)
+++ trunk/wp-includes/media.php        2012-11-27 15:50:59 UTC (rev 22869)
</span><span class="lines">@@ -1327,6 +1327,10 @@
</span><span class="cx">                 'subtype'     =&gt; $subtype,
</span><span class="cx">                 'icon'        =&gt; wp_mime_type_icon( $attachment-&gt;ID ),
</span><span class="cx">                 'dateFormatted' =&gt; mysql2date( get_option('date_format'), $attachment-&gt;post_date ),
</span><ins>+                'nonces'      =&gt; array(
+                        'update' =&gt; wp_create_nonce( 'update-post_' . $attachment-&gt;ID ),
+                        'delete' =&gt; wp_create_nonce( 'delete-post_' . $attachment-&gt;ID ),
+                ),
</ins><span class="cx">         );
</span><span class="cx"> 
</span><span class="cx">         if ( $meta &amp;&amp; 'image' === $type ) {
</span><span class="lines">@@ -1452,6 +1456,7 @@
</span><span class="cx">                 'allMediaItems'      =&gt; __( 'All media items' ),
</span><span class="cx">                 'insertIntoPost'     =&gt; $hier ? __( 'Insert into page' ) : __( 'Insert into post' ),
</span><span class="cx">                 'uploadedToThisPost' =&gt; $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ),
</span><ins>+                'warnDelete' =&gt;      __( &quot;You are about to permanently delete this item.\n  'Cancel' to stop, 'OK' to delete.&quot; ),
</ins><span class="cx"> 
</span><span class="cx">                 // From URL
</span><span class="cx">                 'fromUrlTitle'       =&gt; __( 'From URL' ),
</span><span class="lines">@@ -1641,6 +1646,11 @@
</span><span class="cx">                                 &lt;# if ( 'image' === data.type &amp;&amp; ! data.uploading ) { #&gt;
</span><span class="cx">                                         &lt;div class=&quot;dimensions&quot;&gt;{{ data.width }} &amp;times; {{ data.height }}&lt;/div&gt;
</span><span class="cx">                                 &lt;# } #&gt;
</span><ins>+                                &lt;# if ( ! data.uploading ) { #&gt;
+                                        &lt;div class=&quot;delete-attachment&quot;&gt;
+                                                &lt;a href=&quot;#&quot;&gt;&lt;?php _e( 'Delete Permanently' ); ?&gt;&lt;/a&gt;
+                                        &lt;/div&gt;
+                                &lt;# } #&gt;
</ins><span class="cx">                         &lt;/div&gt;
</span><span class="cx">                         &lt;div class=&quot;compat-meta&quot;&gt;
</span><span class="cx">                                 &lt;# if ( data.compat &amp;&amp; data.compat.meta ) { #&gt;
</span></span></pre></div>
<a id="trunkwpincludesscriptloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/script-loader.php (22868 => 22869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/script-loader.php        2012-11-27 15:35:36 UTC (rev 22868)
+++ trunk/wp-includes/script-loader.php        2012-11-27 15:50:59 UTC (rev 22869)
</span><span class="lines">@@ -322,7 +322,6 @@
</span><span class="cx">         $scripts-&gt;add( 'media-models', &quot;/wp-includes/js/media-models$suffix.js&quot;, array( 'backbone', 'jquery' ), false, 1 );
</span><span class="cx">         did_action( 'init' ) &amp;&amp; $scripts-&gt;localize( 'media-models', '_wpMediaModelsL10n', array(
</span><span class="cx">                 'settings' =&gt; array(
</span><del>-                        'saveAttachmentNonce' =&gt; wp_create_nonce( 'save-attachment' ),
</del><span class="cx">                         'ajaxurl' =&gt; admin_url( 'admin-ajax.php', 'relative' ),
</span><span class="cx">                         'postId'  =&gt; 0,
</span><span class="cx">                 ),
</span></span></pre>
</div>
</div>

</body>
</html>