Index: pathauto.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.inc,v
retrieving revision 1.45.2.1
diff -u -p -r1.45.2.1 pathauto.inc
--- pathauto.inc	21 Mar 2009 00:28:54 -0000	1.45.2.1
+++ pathauto.inc	14 Oct 2009 14:59:00 -0000
@@ -220,7 +220,7 @@ function pathauto_cleanstring($string, $
  *   The name of your module (e.g., 'node').
  * @param $op
  *   Operation being performed on the content being aliased
- *   ('insert', 'update', or 'bulkupdate').
+ *   ('insert', 'update', 'return', or 'bulkupdate').
  * @param $placeholders
  *   An array whose keys consist of the translated placeholders
  *   which appear in patterns (e.g., t('[title]')) and values are the
@@ -317,6 +317,11 @@ function pathauto_create_alias($module, 
     }
   }
 
+  // Return the generated alias if requested.
+  if ($op == 'return') {
+    return $alias;
+  }
+
   // If $pid is NULL, a new alias is created - otherwise, the existing
   // alias for the designated src is replaced
   _pathauto_set_alias($src, $alias, $module, $entity_id, $pid, $verbose, $old_alias, $language);
Index: pathauto.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.module,v
retrieving revision 1.118.2.5
diff -u -p -r1.118.2.5 pathauto.module
--- pathauto.module	25 Sep 2009 16:06:23 -0000	1.118.2.5
+++ pathauto.module	14 Oct 2009 14:59:00 -0000
@@ -263,47 +263,68 @@ function pathauto_nodeapi(&$node, $op, $
  * into the path module's fieldset in the node form.
  */
 function pathauto_form_alter(&$form, $form_state, $form_id) {
-  // Only do this for node forms
-  if (isset($form['#id']) && ($form['#id'] == 'node-form') && arg(0) == 'node') {
+  // Process only node forms.
+  if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
     $node = $form['#node'];
+    $pattern = FALSE;
 
-    // See if there is a pathauto pattern or default applicable
+    // Find if there is an automatic alias pattern for this node type.
     if (isset($form['language'])) {
       $language = isset($form['language']['#value']) ? $form['language']['#value'] : $form['language']['#default_value'];
       $pattern = trim(variable_get('pathauto_node_'. $form['type']['#value'] .'_'. $language .'_pattern', ''));
     }
-    if (empty($pattern)) {
+    if (!$pattern) {
       $pattern = trim(variable_get('pathauto_node_'. $form['type']['#value'] .'_pattern', ''));
-      if (empty($pattern)) {
+      if (!$pattern) {
         $pattern = trim(variable_get('pathauto_node_pattern', ''));
       }
     }
-    // If there is a pattern AND the user is allowed to create aliases AND the path textbox is present on this form
-    if (!empty($pattern) && user_access('create url aliases') && isset($form['path']['path'])) {
-      $output = t('An alias will be generated for you. If you wish to create your own alias below, untick this option.');
-      if (user_access('administer pathauto')) {
-        $output .= t(' To control the format of the generated aliases, see the Pathauto settings.', array('@pathauto' => url('admin/build/path/pathauto')));
+
+    // If there is a pattern, show the automatic alias checkbox.
+    if ($pattern) {
+      if (!isset($node->pathauto_perform_alias)) {
+        if (isset($node->nid)) {
+          // If this is not a new node, compare it's current alias to the
+          // alias that would be genereted by pathauto. If they are the same,
+          // then keep the automatic alias enabled.
+          _pathauto_include();
+          $placeholders = pathauto_get_placeholders('node', $node);
+          $pathauto_alias = pathauto_create_alias('node', 'return', $placeholders, "node/{$node->nid}", $node->nid, $node->type, $node->language);
+          $node->pathauto_perform_alias = isset($node->path) && $node->path == $pathauto_alias;
+        }
+        else {
+          // If this is a new node, enable the automatic alias.
+          $node->pathauto_perform_alias = TRUE;
+        }
       }
 
+      // Add JavaScript that will disable the path textfield when the automatic
+      // alias checkbox is checked.
       drupal_add_js(drupal_get_path('module', 'pathauto') .'/pathauto.js');
-      $form['path']['#collapsed'] = FALSE;
 
       $form['path']['pathauto_perform_alias'] = array(
         '#type' => 'checkbox',
         '#title' => t('Automatic alias'),
-        '#default_value' => isset($node->pathauto_perform_alias) ? $node->pathauto_perform_alias : TRUE,
-        '#description' => $output,
+        '#default_value' => $node->pathauto_perform_alias,
+        '#description' => t('An alias will be generated for you. If you wish to create your own alias below, uncheck this option.'),
         '#weight' => -1,
       );
 
-      if (!empty($node->pathauto_perform_alias) && !empty($node->old_alias) && $node->path == '') {
+      if (user_access('administer pathauto')) {
+        $form['path']['pathauto_perform_alias']['#description'] .= ' '. t('To control the format of the generated aliases, see the automated alias settings.', array('@pathauto' => url('admin/build/path/pathauto')));
+      }
+
+      if ($node->pathauto_perform_alias && !empty($node->old_alias) && empty($node->path)) {
         $form['path']['path']['#default_value'] = $node->old_alias;
         $node->path = $node->old_alias;
       }
 
-      //For Pathauto to remember the old alias and prevent the Path-module from deleteing it when Pathauto wants to preserve it
+      // For Pathauto to remember the old alias and prevent the Path-module from deleteing it when Pathauto wants to preserve it
       if (isset($node->path)) {
-        $form['path']['old_alias'] = array('#type' => 'value', '#value' => $node->path);
+        $form['path']['old_alias'] = array(
+          '#type' => 'value',
+          '#value' => $node->path,
+        );
       }
     }
   }