WordPress.org

Make WordPress Core

Changeset 12196


Ignore:
Timestamp:
11/17/2009 03:08:38 AM (9 years ago)
Author:
azaozz
Message:

Fix pagination on the Unattached tab in the media library, show Attach in the "Attached to" column for orphan attachments

Location:
trunk/wp-admin
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r12130 r12196  
    12071207
    12081208    $searchand = $search = '';
    1209     foreach( (array) $search_terms as $term) {
     1209    foreach ( (array) $search_terms as $term ) {
    12101210        $term = addslashes_gpc($term);
    12111211        $search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))";
     
    12161216        $search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
    12171217
    1218     $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" );
     1218    $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" );
    12191219
    12201220    if ( ! $posts )
    12211221        exit( __('No posts found.') );
    12221222
    1223     $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>';
     1223    $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>';
    12241224    foreach ( $posts as $post ) {
    12251225
     
    12361236                break;
    12371237            case 'draft' :
    1238                 $stat = __('Unpublished');
     1238                $stat = __('Draft');
    12391239                break;
    12401240        }
  • trunk/wp-admin/edit-attachment-rows.php

    r12162 r12196  
    174174        } else {
    175175            ?>
    176             <td <?php echo $attributes ?>>&nbsp;</td>
     176            <td <?php echo $attributes ?>><?php _e('(Unattached)'); ?><br />
     177            <a class="hide-if-no-js" onclick="findPosts.open('media[]','<?php echo $post->ID ?>');return false;" href="#the-list"><?php _e('Attach'); ?></a></td>
    177178            <?php
    178179        }
  • trunk/wp-admin/js/media.dev.js

    r10943 r12196  
    3232            };
    3333
    34             if ( $('#find-posts-pages:checked').val() ) {
     34            if ( $('#find-posts-pages').is(':checked') ) {
    3535                post['pages'] = 1;
    3636            } else {
  • trunk/wp-admin/js/media.js

    r10943 r12196  
    1 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);
     1var 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);
  • trunk/wp-admin/upload.php

    r12162 r12196  
    6363        }
    6464
    65         $location = add_query_arg( array( 'detached' => 1, 'attached' => $attached ) , $location );
     65        $location = add_query_arg( array( 'attached' => $attached ) , $location );
    6666        wp_redirect($location);
    6767        exit;
     
    7777        $post_ids = isset($_GET['media']) ? $_GET['media'] : explode(',', $_GET['ids']);
    7878        $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
    79     } else
     79    } else {
    8080        wp_redirect($_SERVER['HTTP_REFERER']);
     81    }
    8182
    8283    $location = 'upload.php';
    8384    if ( $referer = wp_get_referer() ) {
    8485        if ( false !== strpos($referer, 'upload.php') )
    85             $location = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'message', 'ids'), $referer );
     86            $location = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted'), $referer );
    8687    }
    8788
     
    119120    }
    120121
    121     $location = remove_query_arg('posted', $location);
    122122    wp_redirect($location);
    123123    exit;
     
    135135if ( isset($_GET['detached']) ) {
    136136
     137    $media_per_page = (int) get_user_option('upload_per_page');
     138    if ( empty($media_per_page) )
     139        $media_per_page = 20;
     140
    137141    if ( !empty($lost) ) {
    138         $start = ( $_GET['paged'] - 1 ) * 50;
    139         $page_links_total = ceil(count($lost) / 50);
     142        $start = ( (int) $_GET['paged'] - 1 ) * $media_per_page;
     143        $page_links_total = ceil(count($lost) / $media_per_page);
    140144        $lost = implode(',', $lost);
    141145
    142         $orphans = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'attachment' AND ID IN ($lost) LIMIT $start, 50" );
     146        $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 ) );
    143147    } else {
    144         $start = ( $_GET['paged'] - 1 ) * 25;
    145         $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" );
    146         $page_links_total = ceil($wpdb->get_var( "SELECT FOUND_ROWS()" ) / 25);
     148        $start = ( (int) $_GET['paged'] - 1 ) * $media_per_page;
     149        $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 ) );
     150        $page_links_total = ceil($wpdb->get_var( "SELECT FOUND_ROWS()" ) / $media_per_page);
    147151    }
    148152
     
    430434</table>
    431435
    432 <?php find_posts_div();
     436<?php
    433437
    434438} else {
     
    467471<br class="clear" />
    468472</div>
     473<?php find_posts_div(); ?>
    469474</form>
    470475<br class="clear" />
Note: See TracChangeset for help on using the changeset viewer.