~ubuntu-branches/debian/sid/wordpress/sid

« back to all changes in this revision

Viewing changes to wp-includes/query.php

  • Committer: Package Import Robot
  • Author(s): Raphaël Hertzog, Raphaël Hertzog, Martin Bagge / brother
  • Date: 2012-06-16 01:19:20 UTC
  • mfrom: (1.2.22)
  • Revision ID: package-import@ubuntu.com-20120616011920-ivqcktmjehq4gpal
Tags: 3.4+dfsg-1
* New upstream release. Closes: #677534

[ Raphaël Hertzog ]
* [a1c0409] Refresh and update all patches to correctly apply on version
  3.4.
* [3804496] Update debian/missing-sources/ to match the current versions of
  embedded javascript and flash files.
* [185b051] Drop the old "default" theme (and its French translation)
* [966ce6c] Grab latest translations
* [1983326] Update Standards-Version to 3.9.3 (no change).
* [29c48b6] Increase debhelper compat level to 9.
* [73e16d0] Replace debian/dh_linktree by the packaged version.
* [359b660] Update debian/wordpress.linktrees to match latest developments.
* [645b650] Let setup-mysql lowercase the FQDN since the configuration
  scheme expects this. Thanks to Chris Butler <chrisb@debian.org> for the
  report (Closes: #658395)
* [5433e90] Fix setup-mysql to avoid creating /srv/www with restricted
  permissions (Closes: #616400)
* [dd2ef1d] Move back wp-config.php to /usr/share/wordpress/ since it's only
  a dispatcher to the real configuration file (Closes: #592502)
* [b602372] Improve wp-config.php so that WordPress works behind an https
  reverse-proxy.
* [ba0b729] Entirely update and rewrite README.debian. (Closes: #575985,
  #639980)
* [683a908] Update wp-config.php to not redefine constants which have
  already been set.  Thanks to Richard van den Berg <richard@vdberg.org> for
  the report. (Closes: #613283)
* [315eb68] Let wordpress-l10n depend on the same version than wordpress.
  (Closes: #623557)
* [a6d0b9f] Default configuration now sets WP_CONTENT_DIR to
  /var/lib/wordpress/wp-content. And the package provides this new directory
  appropriately setup with write rights to www-data on blogs.dir and
  uploads. themes and plugins are root-owned directories with symlinks
  pointing back to the default themes and plugins. (Closes: #675469)
* [4db98c6] Update setup-mysql to use WP_CONTENT_DIR (and no longer use
  $upload_dir). (Closes: #658508)
* [a1970da] Extend debian/wordpress.linktrees to cover swfobject.js.
* [8d46dab] Use dpkg-maintscript-helper to drop obsolete
  /etc/wordpress/wp-config.php

[ Martin Bagge / brother ]
* [56d0a34] Improve the setup script to be able to use a remote MySQL
  server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
        return $wp_query->get($var);
28
28
}
29
29
 
30
 
 
31
30
/**
32
 
 * Retrieve the currently-queried object.  Wrapper for $wp_query->get_queried_object()
 
31
 * Retrieve the currently-queried object. Wrapper for $wp_query->get_queried_object()
33
32
 *
34
33
 * @uses WP_Query::get_queried_object
35
34
 *
728
727
}
729
728
 
730
729
/*
731
 
 * The Loop.  Post loop control.
 
730
 * The Loop. Post loop control.
732
731
 */
733
732
 
734
733
/**
1261
1260
        var $query_vars_hash = false;
1262
1261
 
1263
1262
        /**
1264
 
         * Whether query vars have changed since the initial parse_query() call.  Used to catch modifications to query vars made
 
1263
         * Whether query vars have changed since the initial parse_query() call. Used to catch modifications to query vars made
1265
1264
         * via pre_get_posts hooks.
1266
1265
         *
1267
1266
         * @since 3.1.1
1454
1453
                if ( '' !== $qv['minute'] ) $qv['minute'] = absint($qv['minute']);
1455
1454
                if ( '' !== $qv['second'] ) $qv['second'] = absint($qv['second']);
1456
1455
 
1457
 
                // Compat.  Map subpost to attachment.
 
1456
                // Compat. Map subpost to attachment.
1458
1457
                if ( '' != $qv['subpost'] )
1459
1458
                        $qv['attachment'] = $qv['subpost'];
1460
1459
                if ( '' != $qv['subpost_id'] )
1477
1476
                        $this->is_page = true;
1478
1477
                        $this->is_single = false;
1479
1478
                } else {
1480
 
                // Look for archive queries.  Dates, categories, authors, search, post type archives.
 
1479
                // Look for archive queries. Dates, categories, authors, search, post type archives.
1481
1480
 
1482
1481
                        if ( !empty($qv['s']) ) {
1483
1482
                                $this->is_search = true;
1625
1624
                }
1626
1625
 
1627
1626
                if ( '' != $qv['pagename'] ) {
1628
 
                        $this->queried_object =& get_page_by_path($qv['pagename']);
 
1627
                        $this->queried_object = get_page_by_path($qv['pagename']);
1629
1628
                        if ( !empty($this->queried_object) )
1630
1629
                                $this->queried_object_id = (int) $this->queried_object->ID;
1631
1630
                        else
2181
2180
                        if ( !empty($q['sentence']) ) {
2182
2181
                                $q['search_terms'] = array($q['s']);
2183
2182
                        } else {
2184
 
                                preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $q['s'], $matches);
 
2183
                                preg_match_all('/".*?("|$)|((?<=[\r\n\t ",+])|^)[^\r\n\t ",+]+/', $q['s'], $matches);
2185
2184
                                $q['search_terms'] = array_map('_search_terms_tidy', $matches[0]);
2186
2185
                        }
2187
2186
                        $n = !empty($q['exact']) ? '' : '%';
2312
2311
 
2313
2312
                // MIME-Type stuff for attachment browsing
2314
2313
 
2315
 
                if ( isset($q['post_mime_type']) && '' != $q['post_mime_type'] ) {
2316
 
                        $table_alias = $post_status_join ? $wpdb->posts : '';
2317
 
                        $whichmimetype = wp_post_mime_type_where($q['post_mime_type'], $table_alias);
2318
 
                }
 
2314
                if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] )
 
2315
                        $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $wpdb->posts );
2319
2316
 
2320
2317
                $where .= $search . $whichauthor . $whichmimetype;
2321
2318
 
2346
2343
 
2347
2344
                                switch ( $orderby ) {
2348
2345
                                        case 'menu_order':
 
2346
                                                $orderby = "$wpdb->posts.menu_order";
2349
2347
                                                break;
2350
2348
                                        case 'ID':
2351
2349
                                                $orderby = "$wpdb->posts.ID";
2449
2447
                        }
2450
2448
                        if ( !empty($r_status) ) {
2451
2449
                                if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) )
2452
 
                                        $statuswheres[] = "($wpdb->posts.post_author = $user_ID " .  "AND (" . join( ' OR ', $r_status ) . "))";
 
2450
                                        $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $r_status ) . "))";
2453
2451
                                else
2454
2452
                                        $statuswheres[] = "(" . join( ' OR ', $r_status ) . ")";
2455
2453
                        }
2456
2454
                        if ( !empty($p_status) ) {
2457
2455
                                if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) )
2458
 
                                        $statuswheres[] = "($wpdb->posts.post_author = $user_ID " .  "AND (" . join( ' OR ', $p_status ) . "))";
 
2456
                                        $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $p_status ) . "))";
2459
2457
                                else
2460
2458
                                        $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")";
2461
2459
                        }
2477
2475
                                $where .= " OR $wpdb->posts.post_status = '$state'";
2478
2476
                        }
2479
2477
 
2480
 
                        if ( is_admin() ) {
 
2478
                        if ( $this->is_admin ) {
2481
2479
                                // Add protected states that should show in the admin all list.
2482
2480
                                $admin_all_states = get_post_stati( array('protected' => true, 'show_in_admin_all_list' => true) );
2483
2481
                                foreach ( (array) $admin_all_states as $state )
2510
2508
                // Paging
2511
2509
                if ( empty($q['nopaging']) && !$this->is_singular ) {
2512
2510
                        $page = absint($q['paged']);
2513
 
                        if ( empty($page) )
 
2511
                        if ( !$page )
2514
2512
                                $page = 1;
2515
2513
 
2516
2514
                        if ( empty($q['offset']) ) {
2517
 
                                $pgstrt = '';
2518
2515
                                $pgstrt = ($page - 1) * $q['posts_per_page'] . ', ';
2519
 
                                $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
2520
2516
                        } else { // we're ignoring $page and using 'offset'
2521
2517
                                $q['offset'] = absint($q['offset']);
2522
2518
                                $pgstrt = $q['offset'] . ', ';
2523
 
                                $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
2524
2519
                        }
 
2520
                        $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
2525
2521
                }
2526
2522
 
2527
2523
                // Comments feeds
2564
2560
 
2565
2561
                $pieces = array( 'where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits' );
2566
2562
 
2567
 
                // Apply post-paging filters on where and join.  Only plugins that
 
2563
                // Apply post-paging filters on where and join. Only plugins that
2568
2564
                // manipulate paging queries should use these hooks.
2569
2565
                if ( !$q['suppress_filters'] ) {
2570
2566
                        $where          = apply_filters_ref_array( 'posts_where_paged', array( $where, &$this ) );
2581
2577
                                $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : '';
2582
2578
                }
2583
2579
 
2584
 
                // Announce current selection parameters.  For use by caching plugins.
 
2580
                // Announce current selection parameters. For use by caching plugins.
2585
2581
                do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join );
2586
2582
 
2587
 
                // Filter again for the benefit of caching plugins.  Regular plugins should use the hooks above.
 
2583
                // Filter again for the benefit of caching plugins. Regular plugins should use the hooks above.
2588
2584
                if ( !$q['suppress_filters'] ) {
2589
2585
                        $where          = apply_filters_ref_array( 'posts_where_request',               array( $where, &$this ) );
2590
2586
                        $groupby        = apply_filters_ref_array( 'posts_groupby_request',             array( $groupby, &$this ) );
2609
2605
                if ( !$q['no_found_rows'] && !empty($limits) )
2610
2606
                        $found_rows = 'SQL_CALC_FOUND_ROWS';
2611
2607
 
2612
 
                $this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
2613
 
                if ( !$q['suppress_filters'] )
2614
 
                        $this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) );
 
2608
                $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
 
2609
 
 
2610
                if ( !$q['suppress_filters'] ) {
 
2611
                        $this->request = apply_filters_ref_array( 'posts_request', array( $this->request, &$this ) );
 
2612
                }
2615
2613
 
2616
2614
                if ( 'ids' == $q['fields'] ) {
2617
2615
                        $this->posts = $wpdb->get_col($this->request);
2629
2627
                        return $r;
2630
2628
                }
2631
2629
 
2632
 
                $this->posts = $wpdb->get_results($this->request);
2633
 
 
2634
 
                // Raw results filter.  Prior to status checks.
 
2630
                $split_the_query = ( $old_request == $this->request && "$wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );
 
2631
                $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this );
 
2632
 
 
2633
                if ( $split_the_query ) {
 
2634
                        // First get the IDs and then fill in the objects
 
2635
 
 
2636
                        $this->request = "SELECT $found_rows $distinct $wpdb->posts.ID FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
 
2637
 
 
2638
                        $this->request = apply_filters( 'posts_request_ids', $this->request, $this );
 
2639
 
 
2640
                        $ids = $wpdb->get_col( $this->request );
 
2641
 
 
2642
                        if ( $ids ) {
 
2643
                                $this->set_found_posts( $q, $limits );
 
2644
 
 
2645
                                _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
 
2646
 
 
2647
                                $this->posts = array_map( 'get_post', $ids );
 
2648
                        } else {
 
2649
                                $this->found_posts = $this->max_num_pages = 0;
 
2650
                                $this->posts = array();
 
2651
                        }
 
2652
                } else {
 
2653
                        $this->posts = $wpdb->get_results( $this->request );
 
2654
                        $this->set_found_posts( $q, $limits );
 
2655
                }
 
2656
 
 
2657
                // Raw results filter. Prior to status checks.
2635
2658
                if ( !$q['suppress_filters'] )
2636
2659
                        $this->posts = apply_filters_ref_array('posts_results', array( $this->posts, &$this ) );
2637
2660
 
2648
2671
                        $this->comment_count = count($this->comments);
2649
2672
                }
2650
2673
 
2651
 
                if ( !$q['no_found_rows'] && !empty($limits) ) {
2652
 
                        $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) );
2653
 
                        $this->found_posts = $wpdb->get_var( $found_posts_query );
2654
 
                        $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
2655
 
                        $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);
2656
 
                }
2657
 
 
2658
2674
                // Check post status to determine if post should be displayed.
2659
2675
                if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
2660
2676
                        $status = get_post_status($this->posts[0]);
2683
2699
                                }
2684
2700
                        }
2685
2701
 
2686
 
                        if ( $this->is_preview && current_user_can( $edit_cap, $this->posts[0]->ID ) )
 
2702
                        if ( $this->is_preview && $this->posts && current_user_can( $edit_cap, $this->posts[0]->ID ) )
2687
2703
                                $this->posts[0] = apply_filters_ref_array('the_preview', array( $this->posts[0], &$this ));
2688
2704
                }
2689
2705
 
2700
2716
                                        array_splice($this->posts, $i, 1);
2701
2717
                                        // Move to front, after other stickies
2702
2718
                                        array_splice($this->posts, $sticky_offset, 0, array($sticky_post));
2703
 
                                        // Increment the sticky offset.  The next sticky will be placed at this offset.
 
2719
                                        // Increment the sticky offset. The next sticky will be placed at this offset.
2704
2720
                                        $sticky_offset++;
2705
2721
                                        // Remove post from sticky posts array
2706
2722
                                        $offset = array_search($sticky_post->ID, $sticky_posts);
2757
2773
                return $this->posts;
2758
2774
        }
2759
2775
 
 
2776
        function set_found_posts( $q, $limits ) {
 
2777
                global $wpdb;
 
2778
 
 
2779
                if ( $q['no_found_rows'] || empty( $limits ) )
 
2780
                        return;
 
2781
 
 
2782
                $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );
 
2783
                $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
 
2784
 
 
2785
                $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] );
 
2786
        }
 
2787
 
2760
2788
        /**
2761
2789
         * Set up the next post and iterate current post index.
2762
2790
         *
2929
2957
                if ( isset($this->queried_object) )
2930
2958
                        return $this->queried_object;
2931
2959
 
2932
 
                $this->queried_object = NULL;
 
2960
                $this->queried_object = null;
2933
2961
                $this->queried_object_id = 0;
2934
2962
 
2935
2963
                if ( $this->is_category || $this->is_tag || $this->is_tax ) {
2953
2981
                        $this->queried_object = get_post_type_object( $this->get('post_type') );
2954
2982
                } elseif ( $this->is_posts_page ) {
2955
2983
                        $page_for_posts = get_option('page_for_posts');
2956
 
                        $this->queried_object = & get_page( $page_for_posts );
 
2984
                        $this->queried_object = get_page( $page_for_posts );
2957
2985
                        $this->queried_object_id = (int) $this->queried_object->ID;
2958
2986
                } elseif ( $this->is_singular && !is_null($this->post) ) {
2959
2987
                        $this->queried_object = $this->post;
3195
3223
                return (bool) $this->is_date;
3196
3224
        }
3197
3225
 
3198
 
 
3199
3226
        /**
3200
3227
         * Is the query for a day archive?
3201
3228
         *
3593
3620
 
3594
3621
        return true;
3595
3622
}
3596
 
?>