<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[12196] trunk/wp-admin:
  Fix pagination on the Unattached tab in the media library,
  show Attach in the &quot;Attached to&quot; column for orphan attachments</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12196">12196</a></dd>
<dt>Author</dt> <dd>azaozz</dd>
<dt>Date</dt> <dd>2009-11-17 03:08:38 +0000 (Tue, 17 Nov 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix pagination on the Unattached tab in the media library, show Attach in the &quot;Attached to&quot; column for orphan attachments</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminadminajaxphp">trunk/wp-admin/admin-ajax.php</a></li>
<li><a href="#trunkwpadmineditattachmentrowsphp">trunk/wp-admin/edit-attachment-rows.php</a></li>
<li><a href="#trunkwpadminjsmediadevjs">trunk/wp-admin/js/media.dev.js</a></li>
<li><a href="#trunkwpadminjsmediajs">trunk/wp-admin/js/media.js</a></li>
<li><a href="#trunkwpadminuploadphp">trunk/wp-admin/upload.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminadminajaxphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/admin-ajax.php (12195 => 12196)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/admin-ajax.php        2009-11-17 00:11:49 UTC (rev 12195)
+++ trunk/wp-admin/admin-ajax.php        2009-11-17 03:08:38 UTC (rev 12196)
</span><span class="lines">@@ -1206,7 +1206,7 @@
</span><span class="cx">         $search_terms = array_map('_search_terms_tidy', $matches[0]);
</span><span class="cx"> 
</span><span class="cx">         $searchand = $search = '';
</span><del>-        foreach( (array) $search_terms as $term) {
</del><ins>+        foreach ( (array) $search_terms as $term ) {
</ins><span class="cx">                 $term = addslashes_gpc($term);
</span><span class="cx">                 $search .= &quot;{$searchand}(($wpdb-&gt;posts.post_title LIKE '%{$term}%') OR ($wpdb-&gt;posts.post_content LIKE '%{$term}%'))&quot;;
</span><span class="cx">                 $searchand = ' AND ';
</span><span class="lines">@@ -1215,12 +1215,12 @@
</span><span class="cx">         if ( count($search_terms) &gt; 1 &amp;&amp; $search_terms[0] != $s )
</span><span class="cx">                 $search .= &quot; OR ($wpdb-&gt;posts.post_title LIKE '%{$term}%') OR ($wpdb-&gt;posts.post_content LIKE '%{$term}%')&quot;;
</span><span class="cx"> 
</span><del>-        $posts = $wpdb-&gt;get_results( &quot;SELECT ID, post_title, post_status, post_date FROM $wpdb-&gt;posts WHERE post_type = '$what' AND $search ORDER BY post_date_gmt DESC LIMIT 50&quot; );
</del><ins>+        $posts = $wpdb-&gt;get_results( &quot;SELECT ID, post_title, post_status, post_date FROM $wpdb-&gt;posts WHERE post_type = '$what' AND post_status IN ('draft', 'publish') AND ($search) ORDER BY post_date_gmt DESC LIMIT 50&quot; );
</ins><span class="cx"> 
</span><span class="cx">         if ( ! $posts )
</span><span class="cx">                 exit( __('No posts found.') );
</span><span class="cx"> 
</span><del>-        $html = '&lt;table class=&quot;widefat&quot; cellspacing=&quot;0&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th class=&quot;found-radio&quot;&gt;&lt;br /&gt;&lt;/th&gt;&lt;th&gt;'.__('Title').'&lt;/th&gt;&lt;th&gt;'.__('Time').'&lt;/th&gt;&lt;th&gt;'.__('Status').'&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;';
</del><ins>+        $html = '&lt;table class=&quot;widefat&quot; cellspacing=&quot;0&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th class=&quot;found-radio&quot;&gt;&lt;br /&gt;&lt;/th&gt;&lt;th&gt;'.__('Title').'&lt;/th&gt;&lt;th&gt;'.__('Date').'&lt;/th&gt;&lt;th&gt;'.__('Status').'&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;';
</ins><span class="cx">         foreach ( $posts as $post ) {
</span><span class="cx"> 
</span><span class="cx">                 switch ( $post-&gt;post_status ) {
</span><span class="lines">@@ -1235,7 +1235,7 @@
</span><span class="cx">                                 $stat = __('Pending Review');
</span><span class="cx">                                 break;
</span><span class="cx">                         case 'draft' :
</span><del>-                                $stat = __('Unpublished');
</del><ins>+                                $stat = __('Draft');
</ins><span class="cx">                                 break;
</span><span class="cx">                 }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadmineditattachmentrowsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit-attachment-rows.php (12195 => 12196)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit-attachment-rows.php        2009-11-17 00:11:49 UTC (rev 12195)
+++ trunk/wp-admin/edit-attachment-rows.php        2009-11-17 03:08:38 UTC (rev 12196)
</span><span class="lines">@@ -173,7 +173,8 @@
</span><span class="cx">                         &lt;?php
</span><span class="cx">                 } else {
</span><span class="cx">                         ?&gt;
</span><del>-                        &lt;td &lt;?php echo $attributes ?&gt;&gt;&amp;nbsp;&lt;/td&gt;
</del><ins>+                        &lt;td &lt;?php echo $attributes ?&gt;&gt;&lt;?php _e('(Unattached)'); ?&gt;&lt;br /&gt;
+                        &lt;a class=&quot;hide-if-no-js&quot; onclick=&quot;findPosts.open('media[]','&lt;?php echo $post-&gt;ID ?&gt;');return false;&quot; href=&quot;#the-list&quot;&gt;&lt;?php _e('Attach'); ?&gt;&lt;/a&gt;&lt;/td&gt;
</ins><span class="cx">                         &lt;?php
</span><span class="cx">                 }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminjsmediadevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/media.dev.js (12195 => 12196)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/media.dev.js        2009-11-17 00:11:49 UTC (rev 12195)
+++ trunk/wp-admin/js/media.dev.js        2009-11-17 03:08:38 UTC (rev 12196)
</span><span class="lines">@@ -31,7 +31,7 @@
</span><span class="cx">                                 _ajax_nonce: $('#_ajax_nonce').val()
</span><span class="cx">                         };
</span><span class="cx"> 
</span><del>-                        if ( $('#find-posts-pages:checked').val() ) {
</del><ins>+                        if ( $('#find-posts-pages').is(':checked') ) {
</ins><span class="cx">                                 post['pages'] = 1;
</span><span class="cx">                         } else {
</span><span class="cx">                                 post['posts'] = 1;
</span></span></pre></div>
<a id="trunkwpadminjsmediajs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/media.js (12195 => 12196)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/media.js        2009-11-17 00:11:49 UTC (rev 12195)
+++ trunk/wp-admin/js/media.js        2009-11-17 03:08:38 UTC (rev 12196)
</span><span class="lines">@@ -1 +1 @@
</span><del>-var findPosts;(function(a){findPosts={open:function(d,c){var b=document.documentElement.scrollTop||a(document).scrollTop();if(d&amp;&amp;c){a(&quot;#affected&quot;).attr(&quot;name&quot;,d).val(c)}a(&quot;#find-posts&quot;).show().draggable({handle:&quot;#find-posts-head&quot;}).css({top:b+50+&quot;px&quot;,left:&quot;50%&quot;,marginLeft:&quot;-250px&quot;});a(&quot;#find-posts-input&quot;).focus().keyup(function(f){if(f.which==27){findPosts.close()}});return false},close:function(){a(&quot;#find-posts-response&quot;).html(&quot;&quot;);a(&quot;#find-posts&quot;).draggable(&quot;destroy&quot;).hide()},send:function(){var b={ps:a(&quot;#find-posts-input&quot;).val(),action:&quot;find_posts&quot;,_ajax_nonce:a(&quot;#_ajax_nonce&quot;).val()};if(a(&quot;#find-posts-pages:checked&quot;).val()){b.pages=1}else{b.posts=1}a.ajax({type:&quot;POST&quot;,url:ajaxurl,data:b,success:function(c){findPosts.show(c)},error:function(c){findPosts.error(c)}})},show:function(b){if(typeof(b)==&quot;string&quot;){this.error({responseText:b});return}var c=wpAjax.parseAjaxResponse(b);if(c.errors){this.error({responseText:wpAjax.broken})}c=c.responses[0];a(&quot;#find-posts-response&quot;).html(c.data)},error:function(b){var c=b.statusText;if(b.responseText){c=b.responseText.replace(/&lt;.[^&lt;&gt;]*?&gt;/g,&quot;&quot;)}if(c){a(&quot;#find-posts-response&quot;).html(c)}}};a(document).ready(function(){a(&quot;#find-posts-submit&quot;).click(function(b){if(&quot;&quot;==a(&quot;#find-posts-response&quot;).html()){b.preventDefault()}});a(&quot;#doaction, #doaction2&quot;).click(function(b){a('select[name^=&quot;action&quot;]').each(function(){if(a(this).val()==&quot;attach&quot;){b.preventDefault();findPosts.open()}})})})})(jQuery);
</del><span class="cx">\ No newline at end of file
</span><ins>+var findPosts;(function(a){findPosts={open:function(d,c){var b=document.documentElement.scrollTop||a(document).scrollTop();if(d&amp;&amp;c){a(&quot;#affected&quot;).attr(&quot;name&quot;,d).val(c)}a(&quot;#find-posts&quot;).show().draggable({handle:&quot;#find-posts-head&quot;}).css({top:b+50+&quot;px&quot;,left:&quot;50%&quot;,marginLeft:&quot;-250px&quot;});a(&quot;#find-posts-input&quot;).focus().keyup(function(f){if(f.which==27){findPosts.close()}});return false},close:function(){a(&quot;#find-posts-response&quot;).html(&quot;&quot;);a(&quot;#find-posts&quot;).draggable(&quot;destroy&quot;).hide()},send:function(){var b={ps:a(&quot;#find-posts-input&quot;).val(),action:&quot;find_posts&quot;,_ajax_nonce:a(&quot;#_ajax_nonce&quot;).val()};if(a(&quot;#find-posts-pages&quot;).is(&quot;:checked&quot;)){b.pages=1}else{b.posts=1}a.ajax({type:&quot;POST&quot;,url:ajaxurl,data:b,success:function(c){findPosts.show(c)},error:function(c){findPosts.error(c)}})},show:function(b){if(typeof(b)==&quot;string&quot;){this.error({responseText:b});return}var c=wpAjax.parseAjaxResponse(b);if(c.errors){this.error({responseText:wpAjax.broken})}c=c.responses[0];a(&quot;#find-posts-response&quot;).html(c.data)},error:function(b){var c=b.statusText;if(b.responseText){c=b.responseText.replace(/&lt;.[^&lt;&gt;]*?&gt;/g,&quot;&quot;)}if(c){a(&quot;#find-posts-response&quot;).html(c)}}};a(document).ready(function(){a(&quot;#find-posts-submit&quot;).click(function(b){if(&quot;&quot;==a(&quot;#find-posts-response&quot;).html()){b.preventDefault()}});a(&quot;#doaction, #doaction2&quot;).click(function(b){a('select[name^=&quot;action&quot;]').each(function(){if(a(this).val()==&quot;attach&quot;){b.preventDefault();findPosts.open()}})})})})(jQuery);
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpadminuploadphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/upload.php (12195 => 12196)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/upload.php        2009-11-17 00:11:49 UTC (rev 12195)
+++ trunk/wp-admin/upload.php        2009-11-17 03:08:38 UTC (rev 12196)
</span><span class="lines">@@ -62,7 +62,7 @@
</span><span class="cx">                                 $location = $referer;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                $location = add_query_arg( array( 'detached' =&gt; 1, 'attached' =&gt; $attached ) , $location );
</del><ins>+                $location = add_query_arg( array( 'attached' =&gt; $attached ) , $location );
</ins><span class="cx">                 wp_redirect($location);
</span><span class="cx">                 exit;
</span><span class="cx">         }
</span><span class="lines">@@ -76,13 +76,14 @@
</span><span class="cx">         } elseif ( ( $_GET['action'] != -1 || $_GET['action2'] != -1 ) &amp;&amp; ( isset($_GET['media']) || isset($_GET['ids']) ) ) {
</span><span class="cx">                 $post_ids = isset($_GET['media']) ? $_GET['media'] : explode(',', $_GET['ids']);
</span><span class="cx">                 $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
</span><del>-        } else
</del><ins>+        } else {
</ins><span class="cx">                 wp_redirect($_SERVER['HTTP_REFERER']);
</span><ins>+        }
</ins><span class="cx"> 
</span><span class="cx">         $location = 'upload.php';
</span><span class="cx">         if ( $referer = wp_get_referer() ) {
</span><span class="cx">                 if ( false !== strpos($referer, 'upload.php') )
</span><del>-                        $location = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'message', 'ids'), $referer );
</del><ins>+                        $location = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted'), $referer );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         switch ( $doaction ) {
</span><span class="lines">@@ -118,7 +119,6 @@
</span><span class="cx">                         break;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        $location = remove_query_arg('posted', $location);
</del><span class="cx">         wp_redirect($location);
</span><span class="cx">         exit;
</span><span class="cx"> } elseif ( isset($_GET['_wp_http_referer']) &amp;&amp; ! empty($_GET['_wp_http_referer']) ) {
</span><span class="lines">@@ -134,16 +134,20 @@
</span><span class="cx"> 
</span><span class="cx"> if ( isset($_GET['detached']) ) {
</span><span class="cx"> 
</span><ins>+        $media_per_page = (int) get_user_option('upload_per_page');
+        if ( empty($media_per_page) )
+                $media_per_page = 20;
+
</ins><span class="cx">         if ( !empty($lost) ) {
</span><del>-                $start = ( $_GET['paged'] - 1 ) * 50;
-                $page_links_total = ceil(count($lost) / 50);
</del><ins>+                $start = ( (int) $_GET['paged'] - 1 ) * $media_per_page;
+                $page_links_total = ceil(count($lost) / $media_per_page);
</ins><span class="cx">                 $lost = implode(',', $lost);
</span><span class="cx"> 
</span><del>-                $orphans = $wpdb-&gt;get_results( &quot;SELECT * FROM $wpdb-&gt;posts WHERE post_type = 'attachment' AND ID IN ($lost) LIMIT $start, 50&quot; );
</del><ins>+                $orphans = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT * FROM $wpdb-&gt;posts WHERE post_type = 'attachment' AND ID IN (%s) LIMIT %d, %d&quot;, $lost, $start, $media_per_page ) );
</ins><span class="cx">         } else {
</span><del>-                $start = ( $_GET['paged'] - 1 ) * 25;
-                $orphans = $wpdb-&gt;get_results( &quot;SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb-&gt;posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent &lt; 1 LIMIT $start, 25&quot; );
-                $page_links_total = ceil($wpdb-&gt;get_var( &quot;SELECT FOUND_ROWS()&quot; ) / 25);
</del><ins>+                $start = ( (int) $_GET['paged'] - 1 ) * $media_per_page;
+                $orphans = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb-&gt;posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent &lt; 1 LIMIT %d, %d&quot;, $start, $media_per_page ) );
+                $page_links_total = ceil($wpdb-&gt;get_var( &quot;SELECT FOUND_ROWS()&quot; ) / $media_per_page);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         $post_mime_types = get_post_mime_types();
</span><span class="lines">@@ -429,7 +433,7 @@
</span><span class="cx"> &lt;/tbody&gt;
</span><span class="cx"> &lt;/table&gt;
</span><span class="cx"> 
</span><del>-&lt;?php find_posts_div();
</del><ins>+&lt;?php
</ins><span class="cx"> 
</span><span class="cx"> } else {
</span><span class="cx">         include( 'edit-attachment-rows.php' );
</span><span class="lines">@@ -466,6 +470,7 @@
</span><span class="cx"> 
</span><span class="cx"> &lt;br class=&quot;clear&quot; /&gt;
</span><span class="cx"> &lt;/div&gt;
</span><ins>+&lt;?php find_posts_div(); ?&gt;
</ins><span class="cx"> &lt;/form&gt;
</span><span class="cx"> &lt;br class=&quot;clear&quot; /&gt;
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>