<!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 "Attached to" 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 "Attached to" 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 .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))";
</span><span class="cx">                 $searchand = ' AND ';
</span><span class="lines">@@ -1215,12 +1215,12 @@
</span><span class="cx">         if ( count($search_terms) > 1 && $search_terms[0] != $s )
</span><span class="cx">                 $search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
</span><span class="cx">
</span><del>-        $posts = $wpdb->get_results( "SELECT ID, post_title, post_status, post_date FROM $wpdb->posts WHERE post_type = '$what' AND $search ORDER BY post_date_gmt DESC LIMIT 50" );
</del><ins>+        $posts = $wpdb->get_results( "SELECT ID, post_title, post_status, post_date FROM $wpdb->posts WHERE post_type = '$what' AND post_status IN ('draft', 'publish') AND ($search) ORDER BY post_date_gmt DESC LIMIT 50" );
</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 = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th>'.__('Time').'</th><th>'.__('Status').'</th></tr></thead><tbody>';
</del><ins>+        $html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th>'.__('Date').'</th><th>'.__('Status').'</th></tr></thead><tbody>';
</ins><span class="cx">         foreach ( $posts as $post ) {
</span><span class="cx">
</span><span class="cx">                 switch ( $post->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">                         <?php
</span><span class="cx">                 } else {
</span><span class="cx">                         ?>
</span><del>-                        <td <?php echo $attributes ?>>&nbsp;</td>
</del><ins>+                        <td <?php echo $attributes ?>><?php _e('(Unattached)'); ?><br />
+                        <a class="hide-if-no-js" onclick="findPosts.open('media[]','<?php echo $post->ID ?>');return false;" href="#the-list"><?php _e('Attach'); ?></a></td>
</ins><span class="cx">                         <?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&&c){a("#affected").attr("name",d).val(c)}a("#find-posts").show().draggable({handle:"#find-posts-head"}).css({top:b+50+"px",left:"50%",marginLeft:"-250px"});a("#find-posts-input").focus().keyup(function(f){if(f.which==27){findPosts.close()}});return false},close:function(){a("#find-posts-response").html("");a("#find-posts").draggable("destroy").hide()},send:function(){var b={ps:a("#find-posts-input").val(),action:"find_posts",_ajax_nonce:a("#_ajax_nonce").val()};if(a("#find-posts-pages:checked").val()){b.pages=1}else{b.posts=1}a.ajax({type:"POST",url:ajaxurl,data:b,success:function(c){findPosts.show(c)},error:function(c){findPosts.error(c)}})},show:function(b){if(typeof(b)=="string"){this.error({responseText:b});return}var c=wpAjax.parseAjaxResponse(b);if(c.errors){this.error({responseText:wpAjax.broken})}c=c.responses[0];a("#find-posts-response").html(c.data)},error:function(b){var c=b.statusText;if(b.responseText){c=b.responseText.replace(/<.[^<>]*?>/g,"")}if(c){a("#find-posts-response").html(c)}}};a(document).ready(function(){a("#find-posts-submit").click(function(b){if(""==a("#find-posts-response").html()){b.preventDefault()}});a("#doaction, #doaction2").click(function(b){a('select[name^="action"]').each(function(){if(a(this).val()=="attach"){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&&c){a("#affected").attr("name",d).val(c)}a("#find-posts").show().draggable({handle:"#find-posts-head"}).css({top:b+50+"px",left:"50%",marginLeft:"-250px"});a("#find-posts-input").focus().keyup(function(f){if(f.which==27){findPosts.close()}});return false},close:function(){a("#find-posts-response").html("");a("#find-posts").draggable("destroy").hide()},send:function(){var b={ps:a("#find-posts-input").val(),action:"find_posts",_ajax_nonce:a("#_ajax_nonce").val()};if(a("#find-posts-pages").is(":checked")){b.pages=1}else{b.posts=1}a.ajax({type:"POST",url:ajaxurl,data:b,success:function(c){findPosts.show(c)},error:function(c){findPosts.error(c)}})},show:function(b){if(typeof(b)=="string"){this.error({responseText:b});return}var c=wpAjax.parseAjaxResponse(b);if(c.errors){this.error({responseText:wpAjax.broken})}c=c.responses[0];a("#find-posts-response").html(c.data)},error:function(b){var c=b.statusText;if(b.responseText){c=b.responseText.replace(/<.[^<>]*?>/g,"")}if(c){a("#find-posts-response").html(c)}}};a(document).ready(function(){a("#find-posts-submit").click(function(b){if(""==a("#find-posts-response").html()){b.preventDefault()}});a("#doaction, #doaction2").click(function(b){a('select[name^="action"]').each(function(){if(a(this).val()=="attach"){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' => 1, 'attached' => $attached ) , $location );
</del><ins>+                $location = add_query_arg( array( 'attached' => $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 ) && ( 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']) && ! 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->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'attachment' AND ID IN ($lost) LIMIT $start, 50" );
</del><ins>+                $orphans = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_type = 'attachment' AND ID IN (%s) LIMIT %d, %d", $lost, $start, $media_per_page ) );
</ins><span class="cx">         } else {
</span><del>-                $start = ( $_GET['paged'] - 1 ) * 25;
-                $orphans = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1 LIMIT $start, 25" );
-                $page_links_total = ceil($wpdb->get_var( "SELECT FOUND_ROWS()" ) / 25);
</del><ins>+                $start = ( (int) $_GET['paged'] - 1 ) * $media_per_page;
+                $orphans = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1 LIMIT %d, %d", $start, $media_per_page ) );
+                $page_links_total = ceil($wpdb->get_var( "SELECT FOUND_ROWS()" ) / $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"> </tbody>
</span><span class="cx"> </table>
</span><span class="cx">
</span><del>-<?php find_posts_div();
</del><ins>+<?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"> <br class="clear" />
</span><span class="cx"> </div>
</span><ins>+<?php find_posts_div(); ?>
</ins><span class="cx"> </form>
</span><span class="cx"> <br class="clear" />
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>