Ticket #24606: 24606.5.diff
File 24606.5.diff, 6.6 KB (added by , 11 years ago) |
---|
-
src/wp-includes/general-template.php
2438 2438 * @return array|string String of page links or array of page links. 2439 2439 */ 2440 2440 function paginate_links( $args = '' ) { 2441 global $wp_rewrite; 2442 2443 $pagenum_link = html_entity_decode( get_pagenum_link() ); 2444 $query_args = array(); 2445 $url_parts = explode( '?', $pagenum_link ); 2446 2447 if ( isset( $url_parts[1] ) ) { 2448 wp_parse_str( $url_parts[1], $query_args ); 2449 } 2450 2451 $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link ); 2452 $pagenum_link = trailingslashit( $pagenum_link ) . '%_%'; 2453 2454 $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : ''; 2455 $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?page=%#%'; 2456 2441 2457 $defaults = array( 2442 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)2443 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number2458 'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below) 2459 'format' => $format, // ?page=%#% : %#% is replaced by the page number 2444 2460 'total' => 1, 2445 2461 'current' => 0, 2446 2462 'show_all' => false, … … 2476 2492 $r = ''; 2477 2493 $page_links = array(); 2478 2494 $dots = false; 2479 $base = str_replace( '%_%', $args['format'], $args['base'] );2480 2495 2481 2496 if ( $args['prev_next'] && $current && 1 < $current ) : 2482 $link = str_replace( '%#%', $current - 1, $base ); 2497 $link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] ); 2498 $link = str_replace( '%#%', $current - 1, $link ); 2483 2499 if ( $add_args ) 2484 2500 $link = add_query_arg( $add_args, $link ); 2485 2501 $link .= $args['add_fragment']; … … 2499 2515 $dots = true; 2500 2516 else : 2501 2517 if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : 2502 $link = str_replace( '%#%', $n, $base ); 2518 $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] ); 2519 $link = str_replace( '%#%', $n, $link ); 2503 2520 if ( $add_args ) 2504 2521 $link = add_query_arg( $add_args, $link ); 2505 2522 $link .= $args['add_fragment']; … … 2514 2531 endif; 2515 2532 endfor; 2516 2533 if ( $args['prev_next'] && $current && ( $current < $total || -1 == $total ) ) : 2517 $link = str_replace( '%#%', $current + 1, $base ); 2534 $link = str_replace( '%_%', $args['format'], $args['base'] ); 2535 $link = str_replace( '%#%', $current + 1, $link ); 2518 2536 if ( $add_args ) 2519 2537 $link = add_query_arg( $add_args, $link ); 2520 2538 $link .= $args['add_fragment']; -
tests/phpunit/tests/general/paginateLinks.php
6 6 7 7 function test_defaults() { 8 8 $expected =<<<EXPECTED 9 <a class='page-numbers' href=' '>1</a>9 <a class='page-numbers' href='http://example.org/'>1</a> 10 10 <span class="page-numbers dots">…</span> 11 <a class='page-numbers' href=' ?page=50'>50</a>11 <a class='page-numbers' href='http://example.org/?page=50'>50</a> 12 12 EXPECTED; 13 13 14 14 $links = paginate_links( array( 'total' => 50 ) ); … … 17 17 18 18 function test_format() { 19 19 $expected =<<<EXPECTED 20 <a class='page-numbers' href=' '>1</a>20 <a class='page-numbers' href='http://example.org/'>1</a> 21 21 <span class="page-numbers dots">…</span> 22 <a class='page-numbers' href=' /page/50/'>50</a>22 <a class='page-numbers' href='http://example.org/page/50/'>50</a> 23 23 EXPECTED; 24 24 25 $links = paginate_links( array( 'total' => 50, 'format' => ' /page/%#%/' ) );25 $links = paginate_links( array( 'total' => 50, 'format' => 'page/%#%/' ) ); 26 26 $this->assertEquals( $expected, $links ); 27 27 } 28 28 29 29 function test_prev_next_false() { 30 30 $expected =<<<EXPECTED 31 <a class='page-numbers' href=' '>1</a>31 <a class='page-numbers' href='http://example.org/'>1</a> 32 32 <span class='page-numbers current'>2</span> 33 <a class='page-numbers' href=' ?page=3'>3</a>34 <a class='page-numbers' href=' ?page=4'>4</a>33 <a class='page-numbers' href='http://example.org/?page=3'>3</a> 34 <a class='page-numbers' href='http://example.org/?page=4'>4</a> 35 35 <span class="page-numbers dots">…</span> 36 <a class='page-numbers' href=' ?page=50'>50</a>36 <a class='page-numbers' href='http://example.org/?page=50'>50</a> 37 37 EXPECTED; 38 38 39 39 $links = paginate_links( array( 'total' => 50, 'prev_next' => false, 'current' => 2 ) ); … … 42 42 43 43 function test_prev_next_true() { 44 44 $expected =<<<EXPECTED 45 <a class="prev page-numbers" href=" ">« Previous</a>46 <a class='page-numbers' href=' '>1</a>45 <a class="prev page-numbers" href="http://example.org/">« Previous</a> 46 <a class='page-numbers' href='http://example.org/'>1</a> 47 47 <span class='page-numbers current'>2</span> 48 <a class='page-numbers' href=' ?page=3'>3</a>49 <a class='page-numbers' href=' ?page=4'>4</a>48 <a class='page-numbers' href='http://example.org/?page=3'>3</a> 49 <a class='page-numbers' href='http://example.org/?page=4'>4</a> 50 50 <span class="page-numbers dots">…</span> 51 <a class='page-numbers' href=' ?page=50'>50</a>52 <a class="next page-numbers" href=" ?page=3">Next »</a>51 <a class='page-numbers' href='http://example.org/?page=50'>50</a> 52 <a class="next page-numbers" href="http://example.org/?page=3">Next »</a> 53 53 EXPECTED; 54 54 55 55 $links = paginate_links( array( 'total' => 50, 'prev_next' => true, 'current' => 2 ) ); … … 95 95 ) ); 96 96 97 97 // It's supposed to link to page 1: 98 $this->assertTag( array( 'tag' => 'a', 'attributes' => array( 'href' => ' ?page=1' ) ), $links[0] );99 $this->assertTag( array( 'tag' => 'a', 'attributes' => array( 'href' => ' ?page=1' ) ), $links[1] );98 $this->assertTag( array( 'tag' => 'a', 'attributes' => array( 'href' => 'http://example.org/' ) ), $links[0] ); 99 $this->assertTag( array( 'tag' => 'a', 'attributes' => array( 'href' => 'http://example.org/' ) ), $links[1] ); 100 100 101 101 // It's not supposed to have an empty href. 102 102 $this->assertNotTag( array( 'tag' => 'a', 'attributes' => array( 'class' => 'prev page-numbers', 'href' => '' ) ), $links[0] ); … … 112 112 ) ); 113 113 114 114 $this->assertTag( array( 'tag' => 'span', 'attributes' => array( 'class' => 'current' ) ), $links[0] ); 115 $this->assertTag( array( 'tag' => 'a', 'attributes' => array( 'href' => ' ?page=2' ) ), $links[1] );115 $this->assertTag( array( 'tag' => 'a', 'attributes' => array( 'href' => 'http://example.org/?page=2' ) ), $links[1] ); 116 116 } 117 117 118 118 }