cvs diff -u -N (in directory C:\CVS\drupalpatch)
? block-module.patch
? bootstrap.patch
? comment-module_0.patch
? drupal-module.patch
? forum-module_0.patch
? node_access_alias.patch
? noderev.patch
? poll_polled2.patch
? profile-module.patch
? pushbutton-header.patch
? statistics-module_0.patch
? stefan.patch
? system-module.patch
? taxonomy.patch
? taxorss.patch
? theme_settings.patch
? upload.patch
? user-module.patch
cvs diff: Diffing .
cvs diff: Diffing database
cvs diff: Diffing includes
Index: includes/pager.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/pager.inc,v
retrieving revision 1.42
diff -u -r1.42 pager.inc
--- includes/pager.inc	31 Mar 2005 09:25:33 -0000	1.42
+++ includes/pager.inc	24 May 2005 01:05:20 -0000
@@ -49,7 +49,7 @@
  * @ingroup database
  */
 function pager_query($query, $limit = 10, $element = 0, $count_query = NULL) {
-  global $pager_from_array, $pager_total;
+  global $pager_from_array, $pager_total, $pager_total_items;
   $from = $_GET['from'];
 
   // Substitute in query arguments.
@@ -68,13 +68,24 @@
   // Convert comma-separated $from to an array, used by other functions.
   $pager_from_array = explode(',', $from);
 
+  // We calculate the total of pages as ceil(items / limit).
+  // For example, for limit = 10:
+  // items =  0 => total = 0
+  // items =  5 => total = 1
+  // items = 10 => total = 1
+  // items = 11 => total = 2
+  // items = 20 => total = 2
+  // items = 21 => total = 3
   if (count($args)) {
-    $pager_total[$element] = db_result(db_query($count_query, $args));
-    return db_query_range($query, $args, (int)$pager_from_array[$element], (int)$limit);
+    $pager_total_items[$element] = db_result(db_query($count_query, $args));
+    $pager_total[$element] = ceil($pager_total_items[$element] / $limit);
+    $pager_from_array[$element] = max(0, min($pager_total[$element]));
+    return db_query_range($query, $args, $pager_from_array[$element]*$limit, $limit);
   }
   else {
-    $pager_total[$element] = db_result(db_query($count_query));
-    return db_query_range($query, (int)$pager_from_array[$element], (int)$limit);
+    $pager_total_items[$element] = db_result(db_query($count_query));
+    $pager_total[$element] = ceil($pager_total_items[$element] / $limit);
+    return db_query_range($query, $pager_from_array[$element]*$limit, $limit);
   }
 }
 
@@ -101,7 +112,7 @@
   global $pager_total;
   $output = '';
 
-  if ($pager_total[$element] > $limit) {
+  if ($pager_total[$element] > 1) {
     $output .= '<div id="pager" class="container-inline">';
     $output .= theme('pager_first', ($tags[0] ? $tags[0] : t('first page')), $limit, $element, $attributes);
     $output .= theme('pager_previous', ($tags[1] ? $tags[1] : t('previous page')), $limit, $element, 1, $attributes);
@@ -141,8 +152,9 @@
   global $pager_from_array;
   $output = '<div class="pager-first">';
 
-  if ($pager_from_array[$element]) {
-    $output .= '<a href="'. pager_link(pager_load_array(0, $element, $pager_from_array), $element, $attributes) .'">'. $text .'</a>';
+  // If we are anywhere but the first page
+  if ($pager_from_array[$element] > 0) {
+    $output .= theme('pager_link', $text, pager_load_array(0, $element, $pager_from_array), $element, $attributes);
   }
   else {
     $output .= ' ';
@@ -172,12 +184,17 @@
 function theme_pager_previous($text, $limit, $element = 0, $interval = 1, $attributes = array()) {
   global $pager_from_array;
   $output = '<div class="pager-previous">';
-  $from_new = pager_load_array(((int)$pager_from_array[$element] - ((int)$limit * (int)$interval)), $element, $pager_from_array);
-  if ($from_new[$element] < 1) {
-    $output .= theme('pager_first', $text, $limit, $element, $attributes);
-  }
-  else {
-    $output .= '<a href="'. pager_link($from_new, $element, $attributes) .'">'. $text .'</a>';
+  // If we are anywhere but the first page
+  if ($pager_from_array[$element] > 0) {
+    $from_new = pager_load_array($pager_from_array[$element] - $interval, $element, $pager_from_array);
+    // If the previous page is the first page, mark the link as such.
+    if ($from_new[$element] == 0) {
+      $output .= theme('pager_first', $text, $limit, $element, $attributes);
+    }
+    // The previous page is not the first page.
+    else {
+      $output .= theme('pager_link', $text, $from_new, $element, $attributes);
+    }
   }
   $output .= '</div>';
   return $output;
@@ -204,9 +221,17 @@
 function theme_pager_next($text, $limit, $element = 0, $interval = 1, $attributes = array()) {
   global $pager_from_array, $pager_total;
   $output = '<div class="pager-next">';
-  $from_new = pager_load_array(((int)$pager_from_array[$element] + ((int)$limit * (int)$interval)), $element, $pager_from_array);
-  if ($from_new[$element] < $pager_total[$element]) {
-    $output .= '<a href="'. pager_link($from_new, $element, $attributes) .'">'. $text .'</a>';
+  // If we are anywhere but the last page
+  if ($pager_from_array[$element] < ($pager_total[$element] - 1)) {
+    $from_new = pager_load_array($pager_from_array[$element] + $interval, $element, $pager_from_array);
+    // If the next page is the last page, mark the link as such.
+    if ($from_new[$element] == ($pager_total[$element] - 1)) {
+      $output .= theme('pager_last', $text, $limit, $element, $attributes);
+    }
+    // The next page is not the last page.
+    else {
+      $output .= theme('pager_link', $text, $from_new, $element, $attributes);
+    }
   }
   else {
     $output .= ' ';
@@ -235,13 +260,9 @@
   global $pager_from_array, $pager_total;
 
   $output = '<div class="pager-last">';
-  $last_num = (($pager_total[$element] % $limit) ? ($pager_total[$element] % $limit) : $limit);
-  $from_new = pager_load_array(($pager_total[$element] - $last_num), $element, $pager_from_array);
-  if ($from_new[$element] < ($pager_from_array[$element] + $limit)) {
-    $output .= theme('pager_next', $text, $limit, $element, 1, $attributes);
-  }
-  else if (($from_new[$element] > $pager_from_array[$element]) && ($from_new[$element] > 0) && ($from_new[$element] < $pager_total[$element])) {
-    $output .= '<a href="'. pager_link($from_new, $element, $attributes) .'">'. $text .'</a>';
+  // If we are anywhere but the last page
+  if ($pager_from_array[$element] < ($pager_total[$element] - 1)) {
+    $output .= theme('pager_link', $text, pager_load_array($pager_total[$element] - 1, $element, $pager_from_array), $element, $attributes);
   }
   else {
     $output .= ' ';
@@ -265,11 +286,14 @@
  * @ingroup themeable
  */
 function theme_pager_detail($limit, $element = 0, $format = '%d through %d of %d.') {
-  global $pager_from_array, $pager_total;
+  global $pager_from_array, $pager_total, $pager_total_items;
 
   $output = '<div class="pager-detail">';
-  if ($pager_total[$element] > (int)$pager_from_array[$element] + 1) {
-    $output .= sprintf($format, (int)$pager_from_array[$element] + 1, ((int)$pager_from_array[$element] + $limit <= $pager_total[$element] ? (int)$pager_from_array[$element] + $limit : $pager_total[$element]), $pager_total[$element]);
+  if ($pager_total[$element] > 1) {
+    $output .= sprintf($format,
+                       $pager_from_array[$element] * $limit + 1,
+                       min($pager_total_items[$element], ($pager_from_array[$element] + 1) * $limit),
+                       $pager_total_items[$element]);
   }
   $output .= '</div>';
 
@@ -300,33 +324,22 @@
   $output = '<div class="pager-list">';
   // Calculate various markers within this pager piece:
   // Middle is used to "center" pages around the current page.
-  $pager_middle = ceil((int)$quantity / 2);
-  // offset adds "offset" second page
-  $pager_offset = (int)$pager_from_array[$element] % (int)$limit;
+  $pager_middle = ceil($quantity / 2);
   // current is the page we are currently paged to
-  if (($pager_current = (ceil(($pager_from_array[$element] + 1) / $limit))) < 1) {
-    $pager_current = 1;
-  }
+  $pager_current = $pager_from_array[$element] + 1;
   // first is the first page listed by this pager piece (re quantity)
-  $pager_first = (int)$pager_current - (int)$pager_middle + 1;
+  $pager_first = $pager_current - $pager_middle + 1;
   // last is the last page listed by this pager piece (re quantity)
-  $pager_last = (int)$pager_current + (int)$quantity - (int)$pager_middle;
-  // max is the maximum number of pages content can is divided into
-  if (!$pager_max = (ceil($pager_total[$element] / $limit))) {
-    $pager_max = 1;
-  }
-  if ((int)$pager_offset) {
-    // adjust for offset second page
-    $pager_max++;
-    $pager_current++;
-  }
+  $pager_last = $pager_current + $quantity - $pager_middle;
+  // max is the maximum page number
+  $pager_max = $pager_total[$element];
   // End of marker calculations.
 
   // Prepare for generation loop.
-  $i = (int)$pager_first;
+  $i = $pager_first;
   if ($pager_last > $pager_max) {
     // Adjust "center" if at end of query.
-    $i = $i + (int)($pager_max - $pager_last);
+    $i = $i + ($pager_max - $pager_last);
     $pager_last = $pager_max;
   }
   if ($i <= 0) {
@@ -364,9 +377,6 @@
 
   return $output;
 }
-/**
- * @} End of "Pager pieces".
- */
 
 /**
  * Format a link to a specific query result page.
@@ -380,7 +390,7 @@
  * @return
  *   An HTML string that generates the link.
  */
-function pager_link($from_new, $element, $attributes = array()) {
+function theme_pager_link($from_new, $element, $attributes = array()) {
   $q = $_GET['q'];
   $from = array_key_exists('from', $_GET) ? $_GET['from'] : '';
 
@@ -396,9 +406,18 @@
     $url = url($q, 'from='. implode($from_new, ','));
   }
 
-  return check_url($url);
+  return '<a href="'. check_url($url) .'">'. check_plain($text) .'</a>';
 }
+/**
+ * @} End of "Pager pieces".
+ */
 
+/**
+ * Helper function
+ *
+ * Copies $old_array to $new_array and sets $new_array[$element] = $value
+ * Fills in $new_array[0 .. $element - 1] = 0
+ */
 function pager_load_array($value, $element, $old_array) {
   $new_array = $old_array;
   // Look for empty elements.
cvs diff: Diffing .
cvs diff: Diffing database
cvs diff: Diffing includes
Index: includes/pager.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/pager.inc,v
retrieving revision 1.42
diff -u -r1.42 pager.inc
--- includes/pager.inc	31 Mar 2005 09:25:33 -0000	1.42
+++ includes/pager.inc	24 May 2005 01:12:03 -0000
@@ -49,7 +49,7 @@
  * @ingroup database
  */
 function pager_query($query, $limit = 10, $element = 0, $count_query = NULL) {
-  global $pager_from_array, $pager_total;
+  global $pager_from_array, $pager_total, $pager_total_items;
   $from = $_GET['from'];
 
   // Substitute in query arguments.
@@ -68,13 +68,24 @@
   // Convert comma-separated $from to an array, used by other functions.
   $pager_from_array = explode(',', $from);
 
+  // We calculate the total of pages as ceil(items / limit).
+  // For example, for limit = 10:
+  // items =  0 => total = 0
+  // items =  5 => total = 1
+  // items = 10 => total = 1
+  // items = 11 => total = 2
+  // items = 20 => total = 2
+  // items = 21 => total = 3
   if (count($args)) {
-    $pager_total[$element] = db_result(db_query($count_query, $args));
-    return db_query_range($query, $args, (int)$pager_from_array[$element], (int)$limit);
+    $pager_total_items[$element] = db_result(db_query($count_query, $args));
+    $pager_total[$element] = ceil($pager_total_items[$element] / $limit);
+    $pager_from_array[$element] = max(0, min($pager_total[$element]));
+    return db_query_range($query, $args, $pager_from_array[$element]*$limit, $limit);
   }
   else {
-    $pager_total[$element] = db_result(db_query($count_query));
-    return db_query_range($query, (int)$pager_from_array[$element], (int)$limit);
+    $pager_total_items[$element] = db_result(db_query($count_query));
+    $pager_total[$element] = ceil($pager_total_items[$element] / $limit);
+    return db_query_range($query, $pager_from_array[$element]*$limit, $limit);
   }
 }
 
@@ -101,7 +112,7 @@
   global $pager_total;
   $output = '';
 
-  if ($pager_total[$element] > $limit) {
+  if ($pager_total[$element] > 1) {
     $output .= '<div id="pager" class="container-inline">';
     $output .= theme('pager_first', ($tags[0] ? $tags[0] : t('first page')), $limit, $element, $attributes);
     $output .= theme('pager_previous', ($tags[1] ? $tags[1] : t('previous page')), $limit, $element, 1, $attributes);
@@ -141,8 +152,9 @@
   global $pager_from_array;
   $output = '<div class="pager-first">';
 
-  if ($pager_from_array[$element]) {
-    $output .= '<a href="'. pager_link(pager_load_array(0, $element, $pager_from_array), $element, $attributes) .'">'. $text .'</a>';
+  // If we are anywhere but the first page
+  if ($pager_from_array[$element] > 0) {
+    $output .= theme('pager_link', $text, pager_load_array(0, $element, $pager_from_array), $element, $attributes);
   }
   else {
     $output .= ' ';
@@ -172,12 +184,17 @@
 function theme_pager_previous($text, $limit, $element = 0, $interval = 1, $attributes = array()) {
   global $pager_from_array;
   $output = '<div class="pager-previous">';
-  $from_new = pager_load_array(((int)$pager_from_array[$element] - ((int)$limit * (int)$interval)), $element, $pager_from_array);
-  if ($from_new[$element] < 1) {
-    $output .= theme('pager_first', $text, $limit, $element, $attributes);
-  }
-  else {
-    $output .= '<a href="'. pager_link($from_new, $element, $attributes) .'">'. $text .'</a>';
+  // If we are anywhere but the first page
+  if ($pager_from_array[$element] > 0) {
+    $from_new = pager_load_array($pager_from_array[$element] - $interval, $element, $pager_from_array);
+    // If the previous page is the first page, mark the link as such.
+    if ($from_new[$element] == 0) {
+      $output .= theme('pager_first', $text, $limit, $element, $attributes);
+    }
+    // The previous page is not the first page.
+    else {
+      $output .= theme('pager_link', $text, $from_new, $element, $attributes);
+    }
   }
   $output .= '</div>';
   return $output;
@@ -204,9 +221,17 @@
 function theme_pager_next($text, $limit, $element = 0, $interval = 1, $attributes = array()) {
   global $pager_from_array, $pager_total;
   $output = '<div class="pager-next">';
-  $from_new = pager_load_array(((int)$pager_from_array[$element] + ((int)$limit * (int)$interval)), $element, $pager_from_array);
-  if ($from_new[$element] < $pager_total[$element]) {
-    $output .= '<a href="'. pager_link($from_new, $element, $attributes) .'">'. $text .'</a>';
+  // If we are anywhere but the last page
+  if ($pager_from_array[$element] < ($pager_total[$element] - 1)) {
+    $from_new = pager_load_array($pager_from_array[$element] + $interval, $element, $pager_from_array);
+    // If the next page is the last page, mark the link as such.
+    if ($from_new[$element] == ($pager_total[$element] - 1)) {
+      $output .= theme('pager_last', $text, $limit, $element, $attributes);
+    }
+    // The next page is not the last page.
+    else {
+      $output .= theme('pager_link', $text, $from_new, $element, $attributes);
+    }
   }
   else {
     $output .= ' ';
@@ -235,13 +260,9 @@
   global $pager_from_array, $pager_total;
 
   $output = '<div class="pager-last">';
-  $last_num = (($pager_total[$element] % $limit) ? ($pager_total[$element] % $limit) : $limit);
-  $from_new = pager_load_array(($pager_total[$element] - $last_num), $element, $pager_from_array);
-  if ($from_new[$element] < ($pager_from_array[$element] + $limit)) {
-    $output .= theme('pager_next', $text, $limit, $element, 1, $attributes);
-  }
-  else if (($from_new[$element] > $pager_from_array[$element]) && ($from_new[$element] > 0) && ($from_new[$element] < $pager_total[$element])) {
-    $output .= '<a href="'. pager_link($from_new, $element, $attributes) .'">'. $text .'</a>';
+  // If we are anywhere but the last page
+  if ($pager_from_array[$element] < ($pager_total[$element] - 1)) {
+    $output .= theme('pager_link', $text, pager_load_array($pager_total[$element] - 1, $element, $pager_from_array), $element, $attributes);
   }
   else {
     $output .= ' ';
@@ -265,11 +286,14 @@
  * @ingroup themeable
  */
 function theme_pager_detail($limit, $element = 0, $format = '%d through %d of %d.') {
-  global $pager_from_array, $pager_total;
+  global $pager_from_array, $pager_total, $pager_total_items;
 
   $output = '<div class="pager-detail">';
-  if ($pager_total[$element] > (int)$pager_from_array[$element] + 1) {
-    $output .= sprintf($format, (int)$pager_from_array[$element] + 1, ((int)$pager_from_array[$element] + $limit <= $pager_total[$element] ? (int)$pager_from_array[$element] + $limit : $pager_total[$element]), $pager_total[$element]);
+  if ($pager_total[$element] > 1) {
+    $output .= sprintf($format,
+                       $pager_from_array[$element] * $limit + 1,
+                       min($pager_total_items[$element], ($pager_from_array[$element] + 1) * $limit),
+                       $pager_total_items[$element]);
   }
   $output .= '</div>';
 
@@ -300,36 +324,25 @@
   $output = '<div class="pager-list">';
   // Calculate various markers within this pager piece:
   // Middle is used to "center" pages around the current page.
-  $pager_middle = ceil((int)$quantity / 2);
-  // offset adds "offset" second page
-  $pager_offset = (int)$pager_from_array[$element] % (int)$limit;
+  $pager_middle = ceil($quantity / 2);
   // current is the page we are currently paged to
-  if (($pager_current = (ceil(($pager_from_array[$element] + 1) / $limit))) < 1) {
-    $pager_current = 1;
-  }
+  $pager_current = $pager_from_array[$element] + 1;
   // first is the first page listed by this pager piece (re quantity)
-  $pager_first = (int)$pager_current - (int)$pager_middle + 1;
+  $pager_first = $pager_current - $pager_middle + 1;
   // last is the last page listed by this pager piece (re quantity)
-  $pager_last = (int)$pager_current + (int)$quantity - (int)$pager_middle;
-  // max is the maximum number of pages content can is divided into
-  if (!$pager_max = (ceil($pager_total[$element] / $limit))) {
-    $pager_max = 1;
-  }
-  if ((int)$pager_offset) {
-    // adjust for offset second page
-    $pager_max++;
-    $pager_current++;
-  }
+  $pager_last = $pager_current + $quantity - $pager_middle;
+  // max is the maximum page number
+  $pager_max = $pager_total[$element];
   // End of marker calculations.
 
   // Prepare for generation loop.
-  $i = (int)$pager_first;
+  $i = $pager_first;
   if ($pager_last > $pager_max) {
     // Adjust "center" if at end of query.
-    $i = $i + (int)($pager_max - $pager_last);
+    $i = $i + ($pager_max - $pager_last);
     $pager_last = $pager_max;
   }
-  if ($i <= 0) {
+  if ($i < 1) {
     // Adjust "center" if at start of query.
     $pager_last = $pager_last + (1 - $i);
     $i = 1;
@@ -337,7 +350,7 @@
   // End of generation loop preparation.
 
   // When there is more than one page, create the pager list.
-  if ($i != $pager_max) {
+  if ($i < $pager_max) {
     $output .= $text;
     if ($i > 1) {
       $output .= '<div class="pager-list-dots-left">... </div>';
@@ -364,9 +377,6 @@
 
   return $output;
 }
-/**
- * @} End of "Pager pieces".
- */
 
 /**
  * Format a link to a specific query result page.
@@ -380,7 +390,7 @@
  * @return
  *   An HTML string that generates the link.
  */
-function pager_link($from_new, $element, $attributes = array()) {
+function theme_pager_link($text, $from_new, $element, $attributes = array()) {
   $q = $_GET['q'];
   $from = array_key_exists('from', $_GET) ? $_GET['from'] : '';
 
@@ -396,9 +406,18 @@
     $url = url($q, 'from='. implode($from_new, ','));
   }
 
-  return check_url($url);
+  return '<a href="'. check_url($url) .'">'. check_plain($text) .'</a>';
 }
+/**
+ * @} End of "Pager pieces".
+ */
 
+/**
+ * Helper function
+ *
+ * Copies $old_array to $new_array and sets $new_array[$element] = $value
+ * Fills in $new_array[0 .. $element - 1] = 0
+ */
 function pager_load_array($value, $element, $old_array) {
   $new_array = $old_array;
   // Look for empty elements.
