--- backup/api.module	2007-11-28 19:35:44.921875000 -0500
+++ api.module	2007-11-30 19:29:32.703125000 -0500
@@ -93,298 +93,309 @@ function api_get_branches() {
 
 /**
  * Implementation of hook_menu().
+ * Split into hook_menu() to exectute code on all pages and hook_init() to execute code on non-cached pages only. 
  */
-function api_menu($may_cache) {
+function api_menu() {
+
+
   $items = array();
-  $access = user_access('access API reference');
+  $access_callback = 'user_access';
+  $access_arguments = array('access API reference');
 
   $branches = api_get_branches();
   $default_branch = variable_get('api_default_branch', 'HEAD');
+    $items['api/function/%api'] = array(
+          'title' => 'Function',
+          'page callback' => 'api_page_function',
+          'access callback' => $access_callback,
+          'access arguments' => $access_arguments,
+          'page arguments' => array($default_branch, 2),
+          'type' => MENU_CALLBACK,
+        );
+    foreach ($branches as $branch) {
+      if (db_result(db_query("SELECT did FROM {api_documentation} WHERE object_name = '%s' AND branch_name = '%s' AND object_type = 'function'"))) {
+        $items['api/function/%api/'. $branch->branch_name] = array(
+          'title' => $branch->title,
+          'page callback' => 'api_page_function',
+          'access callback' => $access_callback,
+          'access arguments' => $access_arguments,
+          'page arguments' => array($branch->branch_name, 2),
+          'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
+        );
+      }
+    }
+
+    //$version = is_null(arg(3)) ? $default_branch : version_to_arg(arg(3));
+
+    $items['api/function/%api/%version/documentation'] = array(
+      'title' => 'View documentation',
+      'type' => MENU_DEFAULT_LOCAL_TASK,
+      'weight' => -10,
+    );
+
+    $items['api/function/%api/%version/references'] = array(
+      'title' => 'List references',
+      'page callback' => 'api_page_function_references',
+      'access callback' => $access_callback,
+      'access arguments' => $access_arguments,
+      'page arguments' => array(arg(3), arg(2)),
+      'type' => MENU_LOCAL_TASK,
+    );
 
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'api',
-      'title' => t('API reference'),
-      'access' => $access,
-      'callback' => 'api_page_branch',
-      'callback arguments' => array($default_branch),
-    );
-    $items[] = array(
-      'path' => 'api/functions',
-      'title' => t('Functions'),
-      'callback' => 'api_page_listing',
-      'access' => $access,
-      'callback arguments' => array($default_branch, 'function'),
+    $items['api/constant/%api'] = array(
+      'title' => 'Constant',
+      'page callback' => 'api_page_constant',
+      'access callback' => $access_callback,
+      'access arguments' => $access_arguments,
+      'page arguments' => array($default_branch, 2),
       'type' => MENU_CALLBACK,
     );
-    $items[] = array(
-      'path' => 'api/constants',
-      'title' => t('Constants'),
-      'callback' => 'api_page_listing',
-      'access' => $access,
-      'callback arguments' => array($default_branch, 'constant'),
+
+    foreach ($branches as $branch) {
+      if (db_result(db_query("SELECT did FROM {api_documentation} WHERE object_name = '%s' AND branch_name = '%s' AND object_type = 'constant'"))) {
+        $items['api/constant/%api/'. $branch->branch_name] = array(
+          'title' => $branch->title,
+          'page callback' => 'api_page_constant',
+          'access callback' => $access_callback,
+          'access arguments' => $access_arguments,
+          'page arguments' => array($branch->branch_name, 2),
+          'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
+        );
+      }
+    }
+
+
+
+    // The file path to the file makes determining the correct menu path a
+    // bit tricky.  We have to break off the beginning section of the path,
+    // then test the last part to see if it's a branch name, then build the
+    // filename/branch name from there.
+    $parts = $parts2 = explode('/', substr($_GET['q'], strlen('api/file/')));
+    $last = array_pop($parts2);
+    if ($last == 'source' || $last == 'documentation') {
+      $last = array_pop($parts2);
+    }
+    if (in_array($last, array_keys($branches))) {
+      $main_file_name = implode('/', $parts2);
+      $branch_name = $last;
+    }
+    else {
+      $main_file_name = implode('/', $parts);
+      $branch_name = $default_branch;
+    }
+
+    foreach ($branches as $branch) {
+      if ($branch->branch_name == $branch_name) {
+        $items['api/file/'. $main_file_name] = array(
+          'title' => basename($main_file_name),
+          'page callback' => 'api_page_file',
+          'access callback' => $access_callback,
+          'access arguments' => $access_arguments,
+          'page arguments' => array($branch->branch_name, $main_file_name),
+          'type' => MENU_CALLBACK,
+        );
+      }
+    // Check if file path has changed in different branches.
+      if ($file_name = db_result(db_query("SELECT file_name FROM {api_documentation} WHERE title = '%s' AND branch_name = '%s' AND object_type = 'file'"))) {
+        $items['api/file/'. $file_name .'/'. $branch->branch_name] = array(
+          'title' => $branch->title,
+          'page callback' => 'api_page_file',
+          'access callback' => $access_callback,
+          'access arguments' => $access_arguments,
+          'page arguments' => array($branch->branch_name, $file_name),
+          'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
+        );
+      }
+    }
+
+    $items['api/file/'. $main_file_name .'/'. $branch_name .'/documentation'] = array(
+      'title' => 'View documentation',
+      'type' => MENU_DEFAULT_LOCAL_TASK,
+      'weight' => -10,
+        );
+    $items['api/file/'. $main_file_name .'/'. $branch_name .'/source'] = array(
+      'title' => 'View source',
+      'page callback' => 'api_page_file_source',
+      'access callback' => $access_callback,
+      'access arguments' => $access_arguments,
+      'page arguments' => array($branch_name, $main_file_name),
+      'type' => MENU_LOCAL_TASK,
+    );
+
+    $items['api/group/%api'] = array(
+      'title' => 'Topic',
+      'page callback' => 'api_page_group',
+      'access callback' => $access_callback,
+      'access arguments' => $access_arguments,
+      'page arguments' => array($default_branch, 2),
       'type' => MENU_CALLBACK,
     );
-    $items[] = array(
-      'path' => 'api/file',
-      'title' => t('Files'),
-      'callback' => 'api_page_listing',
-      'access' => $access,
-      'callback arguments' => array($default_branch, 'file'),
+    
+    foreach ($branches as $branch) {
+      if (db_result(db_query("SELECT did FROM {api_documentation} WHERE object_name = '%s' AND branch_name = '%s' AND object_type = 'group'"))) {
+        $items['api/group/%api/'. $branch->branch_name] = array(
+          'title' => $branch->title,
+          'page callback' => 'api_page_group',
+          'access callback' => $access_callback,
+          'access arguments' => $access_arguments,
+          'page arguments' => array($branch->branch_name, 2),
+          'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
+        );
+      }
+    }      
+
+    $items['api/search'] = array(
+      'title' => 'Search',
+      'page callback' => 'api_search_listing',
+      'access callback' => $access_callback,
+      'access arguments' => $access_arguments,
       'type' => MENU_CALLBACK,
     );
-    $items[] = array(
-      'path' => 'api/files',
-      'title' => t('Files'),
-      'callback' => 'api_page_listing',
-      'access' => $access,
-      'callback arguments' => array($default_branch, 'file'),
+    
+    foreach ($branches as $branch) {
+      $items['api/search/'. $branch->branch_name .'/%api'] = array(
+        'title' => $branch->title,
+        'page callback' => 'api_search_listing',
+        'page arguments' => array($branch->branch_name, 3),
+        'access callback' => $access_callback,
+        'access arguments' => $access_arguments,
+        //'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
+        'type' => MENU_LOCAL_TASK,
+      );
+    }
+
+    return $items;
+}
+
+function api_init() {
+  $items = array();
+  $access_callback = 'user_access';
+  $access_arguments = array('access API reference');
+
+  $branches = api_get_branches();
+  $default_branch = variable_get('api_default_branch', 'HEAD');
+
+    $items['api'] = array(
+      'title' => 'API reference',
+      'access callback' => $access_callback,
+      'access arguments' => $access_arguments,
+      'page callback' => 'api_page_branch',
+      'page arguments' => array($default_branch),
+    );
+    $items['api/functions'] = array(
+      'title' => 'Functions',
+      'page callback' => 'api_page_listing',
+      'access callback' => $access_callback,
+      'access arguments' => $access_arguments,
+      'page arguments' => array($default_branch, 'function'),
+      'type' => MENU_CALLBACK,
+    );
+    $items['api/constants'] = array(
+      'title' => 'Constants',
+      'page callback' => 'api_page_listing',
+      'access callback' => $access_callback,
+      'access arguments' => $access_arguments,
+      'page arguments' => array($default_branch, 'constant'),
       'type' => MENU_CALLBACK,
     );
-    $items[] = array(
-      'path' => 'api/groups',
-      'title' => t('Topics'),
-      'callback' => 'api_page_listing',
-      'access' => $access,
-      'callback arguments' => array($default_branch, 'group'),
+    $items['api/file'] = array(
+      'title' => 'Files',
+      'page callback' => 'api_page_listing',
+      'access callback' => $access_callback,
+      'access arguments' => $access_arguments,
+      'page arguments' => array($default_branch, 'file'),
+      'type' => MENU_CALLBACK,
+    );
+    $items['api/files'] = array(
+      'title' => 'Files',
+      'page callback' => 'api_page_listing',
+      'access callback' => $access_callback,
+      'access arguments' => $access_arguments,
+      'page arguments' => array($default_branch, 'file'),
+      'type' => MENU_CALLBACK,
+    );
+    $items['api/groups'] = array(
+      'title' => 'Topics',
+      'page callback' => 'api_page_listing',
+      'access callback' => $access_callback,
+      'access arguments' => $access_arguments,
+      'page arguments' => array($default_branch, 'group'),
       'type' => MENU_CALLBACK,
     );
 
     foreach ($branches as $branch) {
-      $items[] = array(
-        'path' => 'api/'. $branch->branch_name,
+      $items['api/'. $branch->branch_name] = array(
         'title' => $branch->title,
-        'callback' => 'api_page_branch',
-        'access' => $access,
-        'callback arguments' => array($branch->branch_name),
+        'page callback' => 'api_page_branch',
+        'access callback' => $access_callback,
+        'access arguments' => $access_arguments,
+        'page arguments' => array($branch->branch_name),
         'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
       );
-      $items[] = array(
-        'path' => 'api/function_dump/'. $branch->branch_name,
-        'title' => t('Functions'),
-        'callback' => 'api_page_function_dump',
-        'access' => $access,
-        'callback arguments' => array($branch->branch_name),
+      $items['api/function_dump/'. $branch->branch_name] = array(
+        'title' => 'Functions',
+        'page callback' => 'api_page_function_dump',
+        'access callback' => $access_callback,
+        'access arguments' => $access_arguments,
+        'page arguments' => array($branch->branch_name),
         'type' => MENU_CALLBACK,
       );
-      $items[] = array(
-        'path' => 'api/functions/'. $branch->branch_name,
+      $items['api/functions/'. $branch->branch_name] = array(
         'title' => $branch->title,
-        'callback' => 'api_page_listing',
-        'access' => $access,
-        'callback arguments' => array($branch->branch_name, 'function'),
+        'page callback' => 'api_page_listing',
+        'access callback' => $access_callback,
+        'access arguments' => $access_arguments,
+        'page arguments' => array($branch->branch_name, 'function'),
         'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
       );
-      $items[] = array(
-        'path' => 'api/constants/'. $branch->branch_name,
+      $items['api/constants/'. $branch->branch_name] = array(
         'title' => $branch->title,
-        'callback' => 'api_page_listing',
-        'access' => $access,
-        'callback arguments' => array($branch->branch_name, 'constant'),
+        'page callback' => 'api_page_listing',
+        'access callback' => $access_callback,
+        'access arguments' => $access_arguments,
+        'page arguments' => array($branch->branch_name, 'constant'),
         'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
       );
-      $items[] = array(
-        'path' => 'api/files/'. $branch->branch_name,
+      $items['api/files/'. $branch->branch_name] = array(
         'title' => $branch->title,
-        'callback' => 'api_page_listing',
-        'access' => $access,
-        'callback arguments' => array($branch->branch_name, 'file'),
+        'page callback' => 'api_page_listing',
+        'access callback' => $access_callback,
+        'access arguments' => $access_arguments,
+        'page arguments' => array($branch->branch_name, 'file'),
         'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
       );
-      $items[] = array(
-        'path' => 'api/groups/'. $branch->branch_name,
+      $items['api/groups/'. $branch->branch_name] = array(
         'title' => $branch->title,
-        'callback' => 'api_page_listing',
-        'access' => $access,
-        'callback arguments' => array($branch->branch_name, 'group'),
+        'page callback' => 'api_page_listing',
+        'access callback' => $access_callback,
+        'access arguments' => $access_arguments,
+        'page arguments' => array($branch->branch_name, 'group'),
         'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
       );
     }
 
-    $items[] = array(
-      'path' => 'apis',
-      'title' => t('API search'),
-      'callback' => 'api_search_listing',
-      'access' => $access,
+    $items['apis'] = array(
+      'title' => 'API search',
+      'page callback' => 'api_search_listing',
+      'access callback' => $access_callback,
+      'access arguments' => $access_arguments,
       'type' => MENU_CALLBACK,
     );
-    $items[] = array('path' => 'api/autocomplete',
-        'callback' => 'api_autocomplete', 'access' => $access,
-        'type' => MENU_CALLBACK);
-    $items[] = array('path' => 'admin/settings/api',
-      'title' => t('API reference'),
-      'description' => t('Configure Drupal branches for documentation.'),
-      'access' => user_access('administer API reference'),
-      'callback' => 'api_page_admin');
-  }
-  else {
-    if (arg(0) == 'api') {
-      if (arg(1) == 'function' && is_string(arg(2))) {
-        $items[] = array(
-          'path' => 'api/function/'. arg(2),
-          'title' => t('Function'),
-          'callback' => 'api_page_function',
-          'access' => $access,
-          'callback arguments' => array($default_branch, arg(2)),
-          'type' => MENU_CALLBACK,
-        );
-        foreach ($branches as $branch) {
-          if (db_result(db_query("SELECT did FROM {api_documentation} WHERE object_name = '%s' AND branch_name = '%s' AND object_type = 'function'", arg(2), $branch->branch_name))) {
-            $items[] = array(
-              'path' => 'api/function/'. arg(2) .'/'. $branch->branch_name,
-              'title' => $branch->title,
-              'callback' => 'api_page_function',
-              'access' => $access,
-              'callback arguments' => array($branch->branch_name, arg(2)),
-              'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
-            );
-          }
-        }
-        $version = is_null(arg(3)) ? $default_branch : arg(3);
-        $items[] = array(
-          'path' => 'api/function/'. arg(2) .'/'. $version .'/documentation',
-          'title' => t('View documentation'),
-          'type' => MENU_DEFAULT_LOCAL_TASK,
-          'weight' => -10
-        );
-        $items[] = array(
-          'path' => 'api/function/'. arg(2) .'/'. $version .'/references',
-          'title' => t('List references'),
-          'callback' => 'api_page_function_references',
-          'access' => $access,
-          'callback arguments' => array(arg(3), arg(2)),
-          'type' => MENU_LOCAL_TASK,
-        );
-      }
-
-      if (arg(1) == 'constant' && is_string(arg(2))) {
-          $items[] = array(
-            'path' => 'api/constant/'. arg(2),
-            'title' => t('Constant'),
-            'callback' => 'api_page_constant',
-            'access' => $access,
-            'callback arguments' => array($default_branch, arg(2)),
-            'type' => MENU_CALLBACK,
-          );
-        foreach ($branches as $branch) {
-          if (db_result(db_query("SELECT did FROM {api_documentation} WHERE object_name = '%s' AND branch_name = '%s' AND object_type = 'constant'", arg(2), $branch->branch_name))) {
-            $items[] = array(
-              'path' => 'api/constant/'. arg(2) .'/'. $branch->branch_name,
-              'title' => $branch->title,
-              'callback' => 'api_page_constant',
-              'access' => $access,
-              'callback arguments' => array($branch->branch_name, arg(2)),
-              'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
-            );
-          }
-        }
-      }
-
-      if (arg(1) == 'file' && is_string(arg(2))) {
-        // The file path to the file makes determining the correct menu path a
-        // bit tricky.  We have to break off the beginning section of the path,
-        // then test the last part to see if it's a branch name, then build the
-        // filename/branch name from there.
-        $parts = $parts2 = explode('/', substr($_GET['q'], strlen('api/file/')));
-        $last = array_pop($parts2);
-        if ($last == 'source' || $last == 'documentation') {
-          $last = array_pop($parts2);
-        }
-        if (in_array($last, array_keys($branches))) {
-          $main_file_name = implode('/', $parts2);
-          $branch_name = $last;
-        }
-        else {
-          $main_file_name = implode('/', $parts);
-          $branch_name = $default_branch;
-        }
-
-        foreach ($branches as $branch) {
-          if ($branch->branch_name == $branch_name) {
-            $items[] = array(
-              'path' => 'api/file/'. $main_file_name,
-              'title' => basename($main_file_name),
-              'callback' => 'api_page_file',
-              'access' => $access,
-              'callback arguments' => array($branch->branch_name, $main_file_name),
-              'type' => MENU_CALLBACK,
-            );
-          }
-          // Check if file path has changed in different branches.
-          if ($file_name = db_result(db_query("SELECT file_name FROM {api_documentation} WHERE title = '%s' AND branch_name = '%s' AND object_type = 'file'", basename($main_file_name), $branch->branch_name))) {
-            $items[] = array(
-              'path' => 'api/file/'. $file_name .'/'. $branch->branch_name,
-              'title' => $branch->title,
-              'callback' => 'api_page_file',
-              'access' => $access,
-              'callback arguments' => array($branch->branch_name, $file_name),
-              'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
-            );
-          }
-        }
-        $items[] = array(
-          'path' => 'api/file/'. $main_file_name .'/'. $branch_name .'/documentation',
-          'title' => t('View documentation'),
-          'type' => MENU_DEFAULT_LOCAL_TASK,
-          'weight' => -10,
-        );
-        $items[] = array(
-          'path' => 'api/file/'. $main_file_name .'/'. $branch_name .'/source',
-          'title' => t('View source'),
-          'callback' => 'api_page_file_source',
-          'access' => $access,
-          'callback arguments' => array($branch_name, $main_file_name),
-          'type' => MENU_LOCAL_TASK,
-        );
-      }
-
-      if (arg(1) == 'group' && is_string(arg(2))) {
-        $items[] = array(
-          'path' => 'api/group/'. arg(2),
-          'title' => t('Topic'),
-          'callback' => 'api_page_group',
-          'access' => $access,
-          'callback arguments' => array($default_branch, arg(2)),
-          'type' => MENU_CALLBACK,
-        );
-        foreach ($branches as $branch) {
-          if (db_result(db_query("SELECT did FROM {api_documentation} WHERE object_name = '%s' AND branch_name = '%s' AND object_type = 'group'", arg(2), $branch->branch_name))) {
-            $items[] = array(
-              'path' => 'api/group/'. arg(2) .'/'. $branch->branch_name,
-              'title' => $branch->title,
-              'callback' => 'api_page_group',
-              'access' => $access,
-              'callback arguments' => array($branch->branch_name, arg(2)),
-              'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
-            );
-          }
-        }
-      }
-      
-      if (arg(1) == 'search' && is_string(arg(3))) {
-        $items[] = array(
-          'path' => 'api/search',
-          'title' => t('Search'),
-          'callback' => 'api_search_listing',
-          'access' => $access,
-          'type' => MENU_CALLBACK,
-        );
-        foreach ($branches as $branch) {
-          $items[] = array(
-            'path' => 'api/search/'. $branch->branch_name .'/'. arg(3),
-            'title' => $branch->title,
-            'callback' => 'api_search_listing',
-            'callback arguments' => array($branch->branch_name, arg(3)),
-            'access' => $access,
-            //'type' => ($branch->branch_name == $default_branch) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
-            'type' => MENU_LOCAL_TASK,
-          );
-        }
-      }
-    }
-  }
-
-  return $items;
+    $items['api/autocomplete'] = array(
+        'page callback' => 'api_autocomplete', 
+        'access callback' => $access_callback,
+        'access arguments' => $access_arguments,
+        'type' => MENU_CALLBACK,
+    );
+    $items['admin/settings/api'] = array(
+      'title' => 'API reference',
+      'description' => 'Configure Drupal branches for documentation.',
+      'access callback' => 'user_access',
+      'access arguments' => array('administer API reference'),
+      'page callback' => 'api_page_admin',
+    );
+  
+  return $items;  
 }
 
 /**
@@ -510,8 +521,8 @@ function api_search_form($branch) {
   return $form;
 }
 
-function api_search_form_submit($form_id, $form_values) {
-  return 'api/search/'. $form_values['branch_name'] .'/'. $form_values['search'];
+function api_search_form_submit($form, &$form_state) {
+  return 'api/search/'. $form_state['branch_name'] .'/'. $form_state['search'];
 }
 
 /**
@@ -526,12 +537,12 @@ function api_search_listing($branch_name
   drupal_set_title(t('API Search for &ldquo;%search&rdquo; in %branch', array('%search' => $search_text, '%branch' => $branch_name)));
 
   // Exact match.
-  $result = db_query("SELECT * FROM {api_documentation} WHERE branch_name = '%s' AND title = '%s'", $branch_name, $search_text);
-  $count = db_num_rows($result);
+  $result = db_query("SELECT COUNT(*) FROM {api_documentation} WHERE branch_name = '%s' AND title = '%s'", $branch_name, $search_text);
+  $count = db_result($result);
   if ($count != 1) {
     // Wildcard search.
     $result = db_query("SELECT * FROM {api_documentation} WHERE branch_name = '%s' AND title LIKE '%%%s%%'", $branch_name, $search_text);
-    $count = db_num_rows($result);
+    $count = db_result($result);
   }
 
   switch ($count) {
@@ -554,7 +565,7 @@ function api_search_listing($branch_name
  */
 function api_autocomplete($branch_name, $search) {
   $matches = array();
-  $result = db_query("SELECT title FROM {api_documentation} WHERE title LIKE '%%%s%%' AND branch_name = '%s' ORDER BY LENGTH(title) LIMIT 20", $search, $branch_name);
+  $result = db_query("SELECT title FROM {api_documentation} WHERE title LIKE '%%%s%%' AND branch_name = '%s' ORDER BY LENGTH(title)", 0, 20);
   while ($r = db_fetch_object($result)) {
     $matches[$r->title] = check_plain($r->title);
   }
@@ -1015,8 +1026,8 @@ function api_page_admin_form() {
   return $form;
 }
 
-function api_page_admin_form_submit($form_id, $form_values) {
-  foreach ($form_values['branches'] as $branch_name => $branch) {
+function api_page_admin_form_submit($form, &$form_state) {
+  foreach ($form_state['values']['branches'] as $branch_name => $branch) {
     if ($branch_name == 'new') {
       if ($branch['branch_name'] != '') {
         db_query("INSERT INTO {api_branch} (branch_name, title, directory) VALUES ('%s', '%s', '%s')", $branch['branch_name'], $branch['title'], $branch['directory']);
@@ -1047,12 +1058,12 @@ function api_page_admin_form_submit($for
   }
 
   //save the variable for default branch
-  if ($form_values['default_branch']) {
-    variable_set('api_default_branch', $form_values['default_branch']);
+  if ($form_state['default_branch']) {
+    variable_set('api_default_branch', $form_state['default_branch']);
   }
 
   // Save the variable for max files per cron.
-  variable_set('api_files_per_cron', $form_values['api_files_per_cron']);
+  variable_set('api_files_per_cron', $form_state['api_files_per_cron']);
 
   // We may have menu changes, so clear the menu cache for all users.
   cache_clear_all('*', 'cache_menu', TRUE);
@@ -1079,12 +1090,12 @@ function api_php_manual_index_form() {
   return $form;
 }
 
-function api_php_manual_index_form_submit($form_id, $form_values) {
+function api_php_manual_index_form_submit($form, &$form_state) {
   include_once(drupal_get_path('module', 'api') .'/parser.inc');
-  variable_set('api_php_funcsummary', $form_values['api_php_funcsummary']);
-  variable_set('api_php_funcpath', $form_values['api_php_funcpath']);
+  variable_set('api_php_funcsummary', $form_state['values']['api_php_funcsummary']);
+  variable_set('api_php_funcpath', $form_state['values']['api_php_funcpath']);
   db_query("DELETE FROM {api_documentation} WHERE branch_name = 'php'");
-  api_parse_php_manual($form_values['api_php_funcsummary']);
+  api_parse_php_manual($form_state['values']['api_php_funcsummary']);
   drupal_set_message(t('Manual pages scanned.'));
 }
 
@@ -1099,9 +1110,9 @@ function api_reindex_form() {
   return $form;
 }
 
-function api_reindex_form_submit($form_id, $form_values) {
+function api_reindex_form_submit($form, &$form_state) {
   db_query("UPDATE {api_file} SET modified = 52");
-  drupal_set_message(t('All files have been tagged for reindexing. The index will be rebuilt during the next few runs of !cron.', array('!cron' => l('cron.php', 'admin/logs/status/run-cron'))));
+  drupal_set_message(t('All files have been tagged for reindexing. The index will be rebuilt during the next few runs of !cron.', array('!cron' => l('cron.php', 'admin/reports/status/run-cron'))));
 }
 
 /**
@@ -1142,7 +1153,7 @@ function api_cron() {
   if ($files_scanned == 0) {
     $result = db_query("SELECT ad.file_name, ad.branch_name FROM {api_file} af LEFT JOIN {api_documentation} ad ON ad.did = af.did WHERE af.found = 0");
     while ($file = db_fetch_object($result)) {
-      watchdog('api', t('Removing %file', array('%file' => $file->file_name)));
+      watchdog('api', 'Removing %file', array('%file' => $file->file_name));
       $doc_result = db_query("SELECT ad.did FROM {api_documentation} ad WHERE ad.file_name = '%s' AND ad.branch_name = '%s'", $file->file_name, $file->branch_name);
       while ($doc = db_fetch_object($doc_result)) {
         db_query("DELETE FROM {api_documentation} WHERE did = %d", $doc->did);
