Index: xmlsitemap/xmlsitemap.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/xmlsitemap/xmlsitemap/Attic/xmlsitemap.module,v
retrieving revision 1.1.2.137
diff -u -p -r1.1.2.137 xmlsitemap.module
--- xmlsitemap/xmlsitemap.module	16 Jun 2009 14:10:43 -0000	1.1.2.137
+++ xmlsitemap/xmlsitemap.module	17 Jun 2009 14:26:35 -0000
@@ -40,6 +40,26 @@ if (!defined('REQUEST_TIME')) {
  */
 define('XMLSITEMAP_LINK_DISABLED', 1);
 
+/**
+ * The maximum number of links in one sitemap chunk file.
+ */
+define('XMLSITEMAP_MAX_SITEMAP_LINKS', 50000);
+
+/**
+ * The maximum filesize of a sitemap chunk file.
+ */
+define('XMLSITEMAP_MAX_SITEMAP_FILESIZE', 10485760);
+
+/**
+ * The maximum number of links in one sitemap index file.
+ */
+define('XMLSITEMAP_MAX_SITEMAP_INDEX_LINKS', 1000);
+
+/**
+ * The default number of links in one sitemap chunk file.
+ */
+define('XMLSITEMAP_DEFAULT_SITEMAP_LINKS', 1000);
+
 /*****************************************************************************
  * Drupal hooks.
  ****************************************************************************/
@@ -129,7 +149,7 @@ function xmlsitemap_menu() {
     'type' => MENU_CALLBACK,
     'file' => 'xmlsitemap.pages.inc',
   );
-  $chunk_size = variable_get('xmlsitemap_chunk_size', 1000);
+  $chunk_size = variable_get('xmlsitemap_chunk_size', XMLSITEMAP_DEFAULT_SITEMAP_LINKS);
   $link_count = xmlsitemap_link_count();
   if ($link_count > $chunk_size) {
     for ($chunk = 0; $chunk < $link_count / $chunk_size; ++$chunk) {
@@ -269,6 +289,15 @@ function xmlsitemap_link_count() {
 }
 
 /**
+ * Return the number of chunk files.
+ */
+function xmlsitemap_chunk_count() {
+  $link_count = xmlsitemap_link_count();
+  $chunk_size = variable_get('xmlsitemap_chunk_size', XMLSITEMAP_DEFAULT_SITEMAP_LINKS);
+  return ceil($link_count / $chunk_size);
+}
+
+/**
  * Return an array of sitemap priority options.
  *
  * @param $option
Index: xmlsitemap/xmlsitemap.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/xmlsitemap/xmlsitemap/Attic/xmlsitemap.pages.inc,v
retrieving revision 1.1.2.40
diff -u -p -r1.1.2.40 xmlsitemap.pages.inc
--- xmlsitemap/xmlsitemap.pages.inc	16 Jun 2009 14:20:17 -0000	1.1.2.40
+++ xmlsitemap/xmlsitemap.pages.inc	17 Jun 2009 14:26:35 -0000
@@ -25,13 +25,31 @@
  */
 function xmlsitemap_output($chunk = NULL) {
   global $user;
-  $chunk_size = variable_get('xmlsitemap_chunk_size', 1000);
+  $chunk_size = variable_get('xmlsitemap_chunk_size', XMLSITEMAP_DEFAULT_SITEMAP_LINKS);
   $link_count = xmlsitemap_link_count();
-  if (($link_count / $chunk_size) > 1000) {
-    $chunk_size = (integer) $link_count / 1000;
-    if ($chunk_size != variable_get('xmlsitemap_chunk_size', 1000)) {
-      variable_set('xmlsitemap_chunk_size', $chunk_size);
+  $chunk_count = xmlsitemap_chunk_count();
+  // A sitemap may only have a set number of index links (links to other sitemap
+  // files) and a set number of site links in each of the "other" sitemap files.
+  // This code adjusts the number of site links specified by the user if the
+  // set number of index links has been reached but will not set that number
+  // greater than the set number of site links in a file.
+  if ($chunk_count > XMLSITEMAP_MAX_SITEMAP_INDEX_LINKS &&
+    $chunk_size < XMLSITEMAP_MAX_SITEMAP_LINKS) {
+    // Determine the number of chunks we are over the maximum index links.
+    $chunk_adjust = $chunk_count - XMLSITEMAP_MAX_SITEMAP_INDEX_LINKS;
+    // Determine the number of links to adjust the chunk size.
+    $chunk_adjust = $chunk_adjust * $chunk_size;
+    if (($chunk_size + $chunk_adjust) <= XMLSITEMAP_MAX_SITEMAP_LINKS) {
+      $chunk_size += $chunk_adjust;
     }
+    else {
+      $chunk_size = XMLSITEMAP_MAX_SITEMAP_LINKS;
+    }
+    variable_set('xmlsitemap_chunk_size', $chunk_size);
+    watchdog('xmlsitemap', t('Chunk size has been updated to %d.', $chunk_size));
+  }
+  elseif($chunk_count > XMLSITEMAP_MAX_SITEMAP_INDEX_LINKS) {
+    watchdog('xmlsitemap', t('The maximum number of allowed links has been reached.'), WATCHDOG_ERROR);
   }
   if (isset($chunk) && !is_numeric($chunk)) {
     drupal_not_found();
