<!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>[22882] trunk/wp-includes: When editing a plain, legacy [gallery] shortcode, ensure we are sorting its contents using menu_order.</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/22882">22882</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2012-11-27 23:20:12 +0000 (Tue, 27 Nov 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>When editing a plain, legacy [gallery] shortcode, ensure we are sorting its contents using menu_order.
When attachments are sorted, we convert the shortcode to [gallery ids=""], as before.
props koopersmith.
fixes <a href="http://core.trac.wordpress.org/ticket/22608">#22608</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesjsmediaeditorjs">trunk/wp-includes/js/media-editor.js</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>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesjsmediaeditorjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-editor.js (22881 => 22882)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-editor.js        2012-11-27 23:07:41 UTC (rev 22881)
+++ trunk/wp-includes/js/media-editor.js        2012-11-27 23:20:12 UTC (rev 22882)
</span><span class="lines">@@ -157,7 +157,8 @@
</span><span class="cx">                                 icontag: 'dt',
</span><span class="cx">                                 captiontag: 'dd',
</span><span class="cx">                                 columns: 3,
</span><del>-                                size: 'thumbnail'
</del><ins>+                                size: 'thumbnail',
+                                orderby: 'menu_order ID'
</ins><span class="cx">                         },
</span><span class="cx">
</span><span class="cx">                         attachments: function( shortcode ) {
</span><span class="lines">@@ -170,12 +171,17 @@
</span><span class="cx">                                 if ( result )
</span><span class="cx">                                         return result;
</span><span class="cx">
</span><del>-                                attrs = shortcode.attrs.named;
</del><ins>+                                // Fill the default shortcode attributes.
+                                attrs = _.defaults( shortcode.attrs.named, wp.media.gallery.defaults );
</ins><span class="cx">                                 args = _.pick( attrs, 'orderby', 'order' );
</span><span class="cx">
</span><span class="cx">                                 args.type = 'image';
</span><span class="cx">                                 args.perPage = -1;
</span><span class="cx">
</span><ins>+                                // Map the `orderby` attribute to the corresponding model property.
+                                if ( ! attrs.orderby || /^menu_order(?: ID)?$/i.test( attrs.orderby ) )
+                                        args.orderby = 'menuOrder';
+
</ins><span class="cx">                                 // Map the `ids` param to the correct query args.
</span><span class="cx">                                 if ( attrs.ids ) {
</span><span class="cx">                                         args.post__in = attrs.ids.split(',');
</span><span class="lines">@@ -204,14 +210,21 @@
</span><span class="cx">
</span><span class="cx">                         shortcode: function( attachments ) {
</span><span class="cx">                                 var props = attachments.props.toJSON(),
</span><del>-                                        attrs = _.pick( props, 'include', 'exclude', 'orderby', 'order' ),
</del><ins>+                                        attrs = _.pick( props, 'orderby', 'order' ),
</ins><span class="cx">                                         shortcode, clone;
</span><span class="cx">
</span><span class="cx">                                 if ( attachments.gallery )
</span><span class="cx">                                         _.extend( attrs, attachments.gallery.toJSON() );
</span><span class="cx">
</span><ins>+                                // Convert all gallery shortcodes to use the `ids` property.
+                                // Ignore `post__in` and `post__not_in`; the attachments in
+                                // the collection will already reflect those properties.
</ins><span class="cx">                                 attrs.ids = attachments.pluck('id');
</span><span class="cx">
</span><ins>+                                // Copy the `parent` post ID.
+                                if ( props.parent )
+                                        attrs.id = props.parent;
+
</ins><span class="cx">                                 // If the `ids` attribute is set and `orderby` attribute
</span><span class="cx">                                 // is the default value, clear it for cleaner output.
</span><span class="cx">                                 if ( attrs.ids && 'post__in' === attrs.orderby )
</span><span class="lines">@@ -272,7 +285,12 @@
</span><span class="cx">                                         selection.props.unset('orderby');
</span><span class="cx">                                 });
</span><span class="cx">
</span><del>-                                return wp.media({
</del><ins>+                                // Destroy the previous gallery frame.
+                                if ( this.frame )
+                                        this.frame.dispose();
+
+                                // Store the current gallery frame.
+                                this.frame = wp.media({
</ins><span class="cx">                                         frame: 'post',
</span><span class="cx">                                         state: 'gallery-edit',
</span><span class="cx">                                         title: wp.media.view.l10n.editGalleryTitle,
</span><span class="lines">@@ -280,6 +298,8 @@
</span><span class="cx">                                         multiple: true,
</span><span class="cx">                                         selection: selection
</span><span class="cx">                                 });
</span><ins>+
+                                return this.frame;
</ins><span class="cx">                         }
</span><span class="cx">                 };
</span><span class="cx">         }());
</span></span></pre></div>
<a id="trunkwpincludesjsmediamodelsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-models.js (22881 => 22882)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-models.js        2012-11-27 23:07:41 UTC (rev 22881)
+++ trunk/wp-includes/js/media-models.js        2012-11-27 23:20:12 UTC (rev 22882)
</span><span class="lines">@@ -659,18 +659,20 @@
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 orderby: {
</span><del>-                        allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in' ],
</del><ins>+                        allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ],
</ins><span class="cx">                         valuemap: {
</span><span class="cx">                                 'id': 'ID',
</span><del>-                                'uploadedTo': 'parent'
</del><ins>+                                'uploadedTo': 'parent',
+                                'menuOrder': 'menu_order ID'
</ins><span class="cx">                         }
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 propmap: {
</span><del>-                        'search': 's',
-                        'type': 'post_mime_type',
-                        'parent': 'post_parent',
-                        'perPage': 'posts_per_page'
</del><ins>+                        'search': 's',
+                        'type': 'post_mime_type',
+                        'parent': 'post_parent',
+                        'perPage': 'posts_per_page',
+                        'menuOrder': 'menu_order'
</ins><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 // Caches query objects so queries can be easily reused.
</span></span></pre></div>
<a id="trunkwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-views.js (22881 => 22882)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-views.js        2012-11-27 23:07:41 UTC (rev 22881)
+++ trunk/wp-includes/js/media-views.js        2012-11-27 23:20:12 UTC (rev 22882)
</span><span class="lines">@@ -2898,7 +2898,9 @@
</span><span class="cx">                         all: {
</span><span class="cx">                                 text: l10n.allMediaItems,
</span><span class="cx">                                 props: {
</span><del>-                                        parent: null
</del><ins>+                                        parent: null,
+                                        orderby: 'date',
+                                        order: 'DESC'
</ins><span class="cx">                                 },
</span><span class="cx">                                 priority: 10
</span><span class="cx">                         },
</span><span class="lines">@@ -2906,7 +2908,9 @@
</span><span class="cx">                         uploaded: {
</span><span class="cx">                                 text: l10n.uploadedToThisPost,
</span><span class="cx">                                 props: {
</span><del>-                                        parent: media.view.settings.postId
</del><ins>+                                        parent: media.view.settings.postId,
+                                        orderby: 'menuOrder',
+                                        order: 'ASC'
</ins><span class="cx">                                 },
</span><span class="cx">                                 priority: 20
</span><span class="cx">                         }
</span><span class="lines">@@ -2921,8 +2925,10 @@
</span><span class="cx">                                 filters[ key ] = {
</span><span class="cx">                                         text: text,
</span><span class="cx">                                         props: {
</span><del>-                                                type: key,
-                                                parent: null
</del><ins>+                                                type: key,
+                                                parent: null,
+                                                orderby: 'date',
+                                                order: 'DESC'
</ins><span class="cx">                                         }
</span><span class="cx">                                 };
</span><span class="cx">                         });
</span><span class="lines">@@ -2930,8 +2936,10 @@
</span><span class="cx">                         filters.all = {
</span><span class="cx">                                 text: l10n.allMediaItems,
</span><span class="cx">                                 props: {
</span><del>-                                        type: null,
-                                        parent: null
</del><ins>+                                        type: null,
+                                        parent: null,
+                                        orderby: 'date',
+                                        order: 'DESC'
</ins><span class="cx">                                 },
</span><span class="cx">                                 priority: 10
</span><span class="cx">                         };
</span><span class="lines">@@ -2939,8 +2947,10 @@
</span><span class="cx">                         filters.uploaded = {
</span><span class="cx">                                 text: l10n.uploadedToThisPost,
</span><span class="cx">                                 props: {
</span><del>-                                        type: null,
-                                        parent: media.view.settings.postId
</del><ins>+                                        type: null,
+                                        parent: media.view.settings.postId,
+                                        orderby: 'menuOrder',
+                                        order: 'ASC'
</ins><span class="cx">                                 },
</span><span class="cx">                                 priority: 20
</span><span class="cx">                         };
</span></span></pre></div>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (22881 => 22882)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2012-11-27 23:07:41 UTC (rev 22881)
+++ trunk/wp-includes/media.php        2012-11-27 23:20:12 UTC (rev 22882)
</span><span class="lines">@@ -1254,7 +1254,7 @@
</span><span class="cx">                 'multipart' => true,
</span><span class="cx">                 'urlstream_upload' => true,
</span><span class="cx">         );
</span><del>-        
</del><ins>+
</ins><span class="cx">         // Multi-file uploading doesn't currently work in iOS Safari,
</span><span class="cx">         // single-file allows the built-in camera to be used as source for images
</span><span class="cx">         if ( wp_is_mobile() )
</span><span class="lines">@@ -1327,6 +1327,7 @@
</span><span class="cx">                 'uploadedTo' => $attachment->post_parent,
</span><span class="cx">                 'date' => strtotime( $attachment->post_date_gmt ) * 1000,
</span><span class="cx">                 'modified' => strtotime( $attachment->post_modified_gmt ) * 1000,
</span><ins>+                'menuOrder' => $attachment->menu_order,
</ins><span class="cx">                 'mime' => $attachment->post_mime_type,
</span><span class="cx">                 'type' => $type,
</span><span class="cx">                 'subtype' => $subtype,
</span></span></pre>
</div>
</div>
</body>
</html>