--- /home/sseverin/drupal/path_redirect-5.x-1.x/path_redirect.module	2008-01-19 13:51:06.000000000 -0600
+++ path_redirect.module	2008-01-20 18:48:31.000000000 -0600
@@ -7,14 +7,13 @@ if (module_exists('workflow_ng')) {
 
 /**
  * Implementation of hook_help
- *
  */
 function path_redirect_help($section) {
   switch ($section) {
-    case 'admin/build/path_redirect':
+    case 'admin/build/path-redirect':
       return t("<p>Here you can set up URL redirecting for this site. Any existing or non-existing path within this site can redirect to any internal or external URL. </p>");
-    case 'admin/build/path_redirect/'. arg(2):
-    case 'admin/build/path_redirect/edit/'. arg(3):
+    case 'admin/build/path-redirect/'. arg(2):
+    case 'admin/build/path-redirect/edit/'. arg(3):
       return t("<p>The <strong>from</strong> path must be an internal Drupal path in the form of 'node/123', 'admin/logs', or 'taxonomy/term/123'. The <strong>to</strong> path can be either an internal Drupal path as above or a complete external URL such as http://www.example.com/. Furthermore, the <strong>to</strong> path may contain query arguments (such as 'page=2') and fragment anchors, to make it possible to redirect to 'admin/user?page=1#help'. Most redirects will not contain queries or anchors.</p>");
   }
 }
@@ -24,7 +23,6 @@ function path_redirect_help($section) {
  *
  * Early checking of URL requested.
  * If a match is found, user is redirected using drupal_goto()
- *
  */
 function path_redirect_init() {
   // see if this page has a redirect path
@@ -55,39 +53,44 @@ function path_redirect_menu($may_cache) 
   $items = array();
   if ($may_cache) {
     $items[] = array(
-      'path' => 'admin/build/path_redirect',
+      'path' => 'admin/build/path-redirect',
       'title' => t('URL redirects'),
       'access' => $access,
       'callback' => 'path_redirect_admin',
       'description' => t('Redirect users from one URL to another.'),
     );
     $items[] = array(
-      'path' => 'admin/build/path_redirect/list',
+      'path' => 'admin/build/path-redirect/list',
       'title' => t('List'),
       'access' => $access,
       'weight' => -3,
       'type' => MENU_DEFAULT_LOCAL_TASK,
     );
     $items[] = array(
-      'path' => 'admin/build/path_redirect/new',
+      'path' => 'admin/build/path-redirect/add',
       'title' => t('Add redirect'),
       'access' => $access,
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('path_redirect_edit'),
       'weight' => 2,
       'type' => MENU_LOCAL_TASK,
     );
-  }
-  else {
-    if (arg(0) == 'admin' && arg(1) == 'build' && arg(2) == 'path_redirect' && arg(3) == 'edit') {
-      $items[] = array(
-        'path' => 'admin/build/path_redirect/edit',
-        'title' => t('Edit'),
-        'access' => $access,
-        'callback' => 'path_redirect_admin',
-        'type' => MENU_LOCAL_TASK,
-        'weight' => 9,
-      );
-    }
-
+    $items[] = array(
+      'path' => 'admin/build/path-redirect/edit',
+      'title' => t('Edit'),
+      'access' => $access,
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('path_redirect_edit'),
+      'type' => MENU_CALLBACK,
+    );
+    $items[] = array(
+      'path' => 'admin/build/path-redirect/delete',
+      'title' => t('Delete'),
+      'access' => $access,
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('path_redirect_delete_confirm'),
+      'type' => MENU_CALLBACK,
+    );
   }
   return $items;
 }
@@ -100,38 +103,9 @@ function path_redirect_perm() {
 }
 
 /**
- * Callback for administration pages
- *
- * @param $rid
- *  redirect id
- * @param $op
- *  operation: delete
- * @return
- *  themed output for page
+ * Render a list of redirects for the main admin page.
  */
-function path_redirect_admin($rid = FALSE, $op = FALSE) {
-  if ($rid) {
-    $breadcrumbs = array(l(t('Home'), '/'), l(t('Administer'), 'admin'), l(t('URL redirects'), 'admin/build/path_redirect'));
-    if ($rid == 'new') {
-      drupal_set_breadcrumb($breadcrumbs);
-      return drupal_get_form('path_redirect_edit');
-    }
-    else {
-      $rid = db_escape_string($rid);
-      $redirect = path_redirect_load($rid);
-      if ($redirect && $op != 'delete') {
-        drupal_set_breadcrumb($breadcrumbs);
-        return drupal_get_form('path_redirect_edit', $redirect);
-      }
-      elseif ($redirect && $op == 'delete') {
-        return drupal_get_form('path_redirect_delete_confirm', $redirect);
-      }
-      else {
-        drupal_not_found();
-      }
-    }
-  }
-
+function path_redirect_admin($rid = FALSE) {
   $header = array(
     array('data' => t('From'), 'field' => 'path', 'sort' => 'asc'),
     array('data' => t('To'), 'field' => 'redirect'),
@@ -141,7 +115,7 @@ function path_redirect_admin($rid = FALS
 
   $result = pager_query('SELECT rid, path, redirect, query, fragment, type FROM {path_redirect}'. tablesort_sql($header), 50);
   $count = db_num_rows($result);
-  $types = path_redirect_error_list();
+  $types = path_redirect_status_codes();
   while ($r = db_fetch_object($result)) {
     $path = $r->path;
     $redirect = $r->redirect;
@@ -152,8 +126,8 @@ function path_redirect_admin($rid = FALS
       check_url($redirect . $query . $fragment),
       $types[$r->type]['title'],
       array('data' => l(t('test'), $r->path, array())),
-      array('data' => l(t('edit'), 'admin/build/path_redirect/edit/'. $r->rid)),
-      array('data' => l(t('delete'), 'admin/build/path_redirect/edit/'. $r->rid .'/delete')),
+      array('data' => l(t('edit'), 'admin/build/path-redirect/edit/'. $r->rid)),
+      array('data' => l(t('delete'), 'admin/build/path-redirect/delete/'. $r->rid)),
     );
   }
 
@@ -162,21 +136,40 @@ function path_redirect_admin($rid = FALS
   }
 
   $output = theme('table', $header, $rows, array('class' => 'path-redirects'));
-  $output .= '<p>'. l(t('Add new redirect'), 'admin/build/path_redirect/new') .'</p>';
+  $output .= '<p>'. l(t('Add new redirect'), 'admin/build/path-redirect/add') .'</p>';
   $output .= theme('pager');
 
   return $output;
 }
 
-function path_redirect_edit($edit = array('path' => '', 'redirect' => '', 'query' => '', 'fragment' => '', 'type' => '301', 'rid' => NULL)) {
+/**
+ * Callback for add and edit pages.
+ *
+ * @return
+ *   A form for drupal_get_form.
+ */
+function path_redirect_edit($rid = FALSE) {
+  if ($rid) {
+    $redirect = path_redirect_load($rid);
+    $output = path_redirect_edit_form($redirect);
+  }
+  else {
+    $output = path_redirect_edit_form();
+  }
+  return $output;
+}
+
+function path_redirect_edit_form($edit = array('path' => '', 'redirect' => '', 'query' => '', 'fragment' => '', 'type' => '301', 'rid' => NULL)) {
   $default_type = 301;
 
   $form['path'] = array(
     '#type' => 'textfield',
     '#title' => t('From'),
     '#description' => t('Enter a Drupal path or path alias to redirect. Query strings <em>?foo=bar</em> and fragment anchors <em>#baz</em> are <strong>not</strong> allowed.'),
+    '#size' => 50,
     '#maxlength' => 255,
     '#default_value' => $edit['path'],
+    '#field_prefix' => url(NULL, NULL, NULL, TRUE) . (variable_get('clean_url', 0) ? '' : '?q='),
   );
 
   $form['redirect'] = array(
@@ -227,7 +220,7 @@ function path_redirect_edit($edit = arra
     '#collapsed' => ($edit['type'] == $default_type),
   );
 
-  foreach (path_redirect_error_list() as $key => $info) {
+  foreach (path_redirect_status_codes() as $key => $info) {
     $form['type'][]['type'] = array(
       '#type' => 'radio',
       '#title' => $info['title'],
@@ -264,7 +257,7 @@ function path_redirect_edit_validate($fo
     // The "from" path should not conflict with another redirect
     $result = path_redirect_load(NULL, preg_replace('/[?#].*/', '', $form_values['path']));
     if ($result && (!$form_values['rid'] || ($form_values['rid'] !== $result['rid']))) {
-      $path_error .= ' '. t('The <strong>from</strong> path you entered is already redirected. You can <a href="@edit-page">edit this redirect</a> instead.', array('@edit-page' => url('admin/build/path_redirect/edit/'. $result['rid'])));
+      $path_error .= ' '. t('The <strong>from</strong> path you entered is already redirected. You can <a href="@edit-page">edit this redirect</a> instead.', array('@edit-page' => url('admin/build/path-redirect/edit/'. $result['rid'])));
     }
     // Check that the "from" path is valid and contains no # or ?
     if (strstr($form_values['path'], '#')) {
@@ -304,7 +297,7 @@ function path_redirect_edit_validate($fo
 function path_redirect_edit_submit($form_id, &$form_values) {
   path_redirect_save($form_values);
   drupal_set_message(t('Redirect has been saved.'));
-  drupal_goto('admin/build/path_redirect');
+  drupal_goto('admin/build/path-redirect');
 }
 
 function path_redirect_save($edit) {
@@ -369,19 +362,19 @@ function path_redirect_delete($from = NU
   return $result;
 }
 
-function path_redirect_delete_confirm($redirect) {
+function path_redirect_delete_confirm($rid) {
   $form['rid'] = array(
     '#type' => 'value',
-    '#value' => check_plain($redirect['rid']),
+    '#value' => check_plain($rid),
   );
-  $redirect = path_redirect_load($redirect['rid']);
-  return confirm_form($form, t('Are you sure you want to delete the redirect from %path to %redirect?', array('%path' => $redirect['path'], '%redirect' => $redirect['redirect'])), 'admin/build/path_redirect', NULL, t('Delete it!'), t('Cancel'));
+  $redirect = path_redirect_load($rid);
+  return confirm_form($form, t('Are you sure you want to delete the redirect from %path to %redirect?', array('%path' => $redirect['path'], '%redirect' => $redirect['redirect'])), 'admin/build/path-redirect', NULL, t('Delete it!'), t('Cancel'));
 }
 
 function path_redirect_delete_confirm_submit($form_id, $form_values) {
   path_redirect_delete(NULL, NULL, $form_values['rid']);
   drupal_set_message(t('Redirect item has been deleted.'));
-  drupal_goto('admin/build/path_redirect');
+  drupal_goto('admin/build/path-redirect');
 }
 
 /**
@@ -419,11 +412,11 @@ function path_redirect_goto($path = '', 
 }
 
 /**
- * Return an array of 300-range error codes
+ * Return an array of 300-range status codes
  * placed here for clarity
  */
-function path_redirect_error_list() {
-  $errors = array(
+function path_redirect_status_codes() {
+  $codes = array(
     300 => array('title' => t('300 Multiple Choices'), 'description' => t('The request is ambiguous and needs clarification as to which resource was requested.')),
     301 => array('title' => t('301 Moved Permanently'), 'description' => t('Moved Permanently. The resource has permanently moved elsewhere, the response indicates where it has gone to. <strong>Recommended.</strong>')),
     302 => array('title' => t('302 Found'), 'description' => t('The resource has temporarily moved elsewhere, the response indicates where it is at present. <strong>This is Drupal\'s default redirect type.</strong>')),
@@ -433,5 +426,5 @@ function path_redirect_error_list() {
     307 => array('title' => t('307 Temporary Redirect'), 'description' => t('The resource has temporarily moved elsewhere, the response indicates where it is at present. Client should still use this URL.')),
   );
 
-  return $errors;
+  return $codes;
 }
