Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.856 diff -u -r1.856 common.inc --- includes/common.inc 23 Jan 2009 14:23:27 -0000 1.856 +++ includes/common.inc 26 Jan 2009 10:52:38 -0000 @@ -3456,6 +3456,9 @@ 'pager' => array( 'arguments' => array('tags' => array(), 'limit' => 10, 'element' => 0, 'parameters' => array()), ), + 'pager_range' => array( + 'arguments' => array('limit' => 10, 'element' => 0), + ), 'pager_first' => array( 'arguments' => array('text' => NULL, 'limit' => NULL, 'element' => 0, 'parameters' => array()), ), Index: includes/pager.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/pager.inc,v retrieving revision 1.64 diff -u -r1.64 pager.inc --- includes/pager.inc 12 Oct 2008 04:30:05 -0000 1.64 +++ includes/pager.inc 26 Jan 2009 10:52:38 -0000 @@ -91,6 +91,39 @@ } /** + * Get a description of the range of items presented by the pager (e.g. Items x + * of y of z). + * + * @param $limit + * The number of query results displayed per page. + * @param $element + * An optional integer to distinguish between multiple pagers on one page. + * @return + * A string containing the description, or an empty string if there are no + * items. + */ +function pager_describe_range($limit = 10, $element = 0) { + global $pager_page_array, $pager_total_items; + + // Prepare additional information about the current paging status. + if ($pager_total_items[$element] == 1) { + return t('1 item '); + } + elseif ($pager_total_items[$element] > 1) { + $from = $pager_page_array[$element] * $limit + 1; + $to = min(($pager_page_array[$element] + 1) * $limit, $pager_total_items[$element]); + if ($from == $to) { + return t('Item') . ' ' . $to . ' ' . t('of') . ' ' . $pager_total_items[$element] . ' '; + } + elseif ($pager_total_items[$element] <= $limit) { + return '' . $pager_total_items[$element] . ' ' . t('items '); + } + return t('Items') . ' ' . $from . '-' . $to . ' ' . t('of') . ' ' . $pager_total_items[$element] . ' '; + } + return ''; +} + +/** * Format a query pager. * * Menu callbacks that display paged query results should call theme('pager') to @@ -113,7 +146,7 @@ * @ingroup themeable */ function theme_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) { - global $pager_page_array, $pager_total; + global $pager_page_array, $pager_total, $pager_total_items; // Calculate various markers within this pager piece: // Middle is used to "center" pages around the current page. @@ -214,6 +247,17 @@ } } +/** + * Format pager ranges on the total number of items. + * + * @param $limit + * The number of query results displayed per page. + * @param $element + * An optional integer to distinguish between multiple pagers on one page. + */ +function theme_pager_range($limit = 10, $element = 0) { + return pager_describe_range($limit, $element); +} /** * @name Pager pieces Index: modules/search/search.module =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.module,v retrieving revision 1.283 diff -u -r1.283 search.module --- modules/search/search.module 4 Jan 2009 16:10:48 -0000 1.283 +++ modules/search/search.module 26 Jan 2009 10:52:38 -0000 @@ -134,6 +134,9 @@ 'file' => 'search.pages.inc', 'template' => 'search-results', ), + 'search_query' => array( + 'arguments' => array('text' => NULL) + ), ); } @@ -1325,3 +1328,15 @@ ); return $forms; } + +/** + * Formats the search query for display with a results page. + * + * @param $text + * The query text to format (plain-text). + * @return + * The formatted text (html). + */ +function theme_search_query($text) { + return t('for') . ' ' . check_plain($text) . ''; +} Index: modules/search/search.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.pages.inc,v retrieving revision 1.5 diff -u -r1.5 search.pages.inc --- modules/search/search.pages.inc 14 Apr 2008 17:48:41 -0000 1.5 +++ modules/search/search.pages.inc 26 Jan 2009 10:52:38 -0000 @@ -32,7 +32,7 @@ $results = search_data($keys, $type); if ($results) { - $results = theme('box', t('Search results'), $results); + $results = theme('box', NULL, $results); } else { $results = theme('box', t('Your search yielded no results'), search_help('search#noresults', drupal_help_arg())); @@ -59,11 +59,18 @@ * @see search-results.tpl.php */ function template_preprocess_search_results(&$variables) { + $path = arg(); + if ($path[0] === 'search' && isset($path[2])) { + $query = $path[2]; + // Add the search query back to the description. + $variables['search_query'] = theme('search_query', $query); + } $variables['search_results'] = ''; foreach ($variables['results'] as $result) { $variables['search_results'] .= theme('search_result', $result, $variables['type']); } - $variables['pager'] = theme('pager', NULL, 10, 0); + $variables['pager'] = theme('pager'); + $variables['pager_range'] = theme('pager_range'); // Provide alternate search results template. $variables['template_files'][] = 'search-results-' . $variables['type']; } Index: modules/search/search-results.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search-results.tpl.php,v retrieving revision 1.3 diff -u -r1.3 search-results.tpl.php --- modules/search/search-results.tpl.php 30 Dec 2008 16:43:18 -0000 1.3 +++ modules/search/search-results.tpl.php 26 Jan 2009 10:52:38 -0000 @@ -21,6 +21,9 @@ * @see template_preprocess_search_results() */ ?> +
+ +
Index: modules/simpletest/tests/pager.test =================================================================== RCS file: modules/simpletest/tests/pager.test diff -N modules/simpletest/tests/pager.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/simpletest/tests/pager.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,109 @@ + t('Pager range description'), + 'description' => t('Tests the pager range description function.'), + 'group' => t('Pager'), + ); + } + + /** + * Test pager description with no items. + */ + function testNoItems() { + $this->_testNoItems(0); + $this->_testNoItems(1); + } + + /** + * Test pager description with a total of one item. + */ + function testSingleItem() { + $this->_testSingleItem(0); + $this->_testSingleItem(1); + } + + /** + * Test pager description for a page showing only the last item. + */ + function testLastItem() { + $this->_testLastItem(0); + $this->_testLastItem(1); + } + + /** + * Test pager description for multiple items fitting a single page. + */ + function testSinglePage() { + $this->_testSinglePage(0); + $this->_testSinglePage(1); + } + + /** + * Test pager description with multiple pages. + */ + function testMultiplePages() { + $this->_testMultiplePages(0); + $this->_testMultiplePages(1); + } + + function _testNoItems($element) { + global $pager_page_array, $pager_total_items; + $pager_page_array[$element] = 0; // Current page. + $pager_total_items[$element] = 0; // Number items. + $description = pager_describe_range(10, $element); + $this->assertEqual($description, '', t('Got description "@description" for pager @element', array('@element' => $element, '@description' => $description))); + } + + function _testSingleItem($element) { + global $pager_page_array, $pager_total_items; + $pager_page_array[$element] = 0; // Current page. + $pager_total_items[$element] = 1; // Number items. + $description = pager_describe_range(10, $element); + $this->assertEqual($description, t('1 item'), t('Got description "@description" for pager @element', array('@element' => $element, '@description' => $description))); + } + + function _testLastItem($element) { + global $pager_page_array, $pager_total_items; + $pager_page_array[$element] = 1; // Current page. + $pager_total_items[$element] = 11; // Number items. + $description = pager_describe_range(10, $element); + $this->assertEqual($description, t('Item 11 of 11'), t('Got description "@description" for pager @element', array('@element' => $element, '@description' => $description))); + } + + function _testSinglePage($element) { + global $pager_page_array, $pager_total_items; + $pager_page_array[$element] = 0; // Current page. + $pager_total_items[$element] = 10; // Number items. + $description = pager_describe_range(10, $element); + $this->assertEqual($description, t('10 items'), t('Got description "@description" for pager @element', array('@element' => $element, '@description' => $description))); + } + + function _testMultiplePages($element) { + global $pager_page_array, $pager_total_items; + $pager_page_array[$element] = 0; // Current page. + $pager_total_items[$element] = 25; // Number items. + $description = pager_describe_range(10, $element); + $this->assertEqual($description, t('Items 1 - 10 of 25'), t('Got description "@description" for pager @element', array('@element' => $element, '@description' => $description))); + + $pager_page_array[$element] = 2; // Current page. + $description = pager_describe_range(10, $element); + $this->assertEqual($description, t('Items 21 - 25 of 25'), t('Got description "@description" for pager @element', array('@element' => $element, '@description' => $description))); + } +}