### Eclipse Workspace Patch 1.0
#P drupal-HEAD
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:30:21 -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:30:21 -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 of @total', array('@to' => $to, '@total' => $pager_total_items[$element]));
+ }
+ elseif ($pager_total_items[$element] <= $limit) {
+ return t('@total items', array('@total' => $pager_total_items[$element]));
+ }
+ return t('Items @from - @to of @total', array('@from' => $from, '@to' => $to, '@total' => $pager_total_items[$element]));
+ }
+ return '';
+}
+
+/**
* Format a query pager.
*
* Menu callbacks that display paged query results should call theme('pager') to
@@ -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 '
';
+}
/**
* @name Pager pieces
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:45:52 -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()));
@@ -63,7 +63,8 @@
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:30:21 -0000
@@ -21,6 +21,7 @@
* @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)));
+ }
+}