Index: wikitools.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wikitools/wikitools.module,v
retrieving revision 1.4
diff -u -p -r1.4 wikitools.module
--- wikitools.module	31 Dec 2007 23:35:06 -0000	1.4
+++ wikitools.module	20 Feb 2008 21:44:07 -0000
@@ -43,10 +43,17 @@ function wikitools_menu() {
       'type' => MENU_CALLBACK
     );
   }
+  return $items;
+}
+
+/**
+ * Implementation of hook_menu_alter().
+ */
+function wikitools_menu_alter(&$callbacks) {
   // Override the callback for node deletion if the delete protection option is set.
   if (wikitools_delete_protection()) {
     // Hijack delete callback and call custom handler.
-    $items['node/%node/delete'] = array(
+    $callbacks['node/%node/delete'] = array(
       'title' => t('Delete'), 
       'page callback' => 'wikitools_delete_protection_delete_confirm',
       'page arguments' => array(1),
@@ -58,13 +65,12 @@ function wikitools_menu() {
   }
   // Only hijack freelinking path if an argument is specified, otherwise let the freelinking page show.
   if (wikitools_hijack_freelinking()) {
-    $items['freelinking/%'] = array(
+    $callbacks['freelinking/%'] = array(
       'page callback' => 'wikitools_handle_request',
       'access arguments' => array('access content'),
       'type' => MENU_CALLBACK
     );
   }
-  return $items;
 }
 
 /**
@@ -124,9 +130,10 @@ function wikitools_admin_settings() {
       'Link to creation' => t('Link to creation'),
       'Creation form' => t('Creation form'),
     ),
+    '#size' => 3,
     '#default_value' => wikitools_404(),
   );
-  $form['title_disallowed_characters'] = array(
+  $form['wikitools_disallowed_characters'] = array(
     '#type' => 'textfield',
     '#title' => t('Disallowed characters in titles'),
     '#description' => t('A list of characters which are not allowed in the title of a wiki page. This setting is important for the wikilink feature to work. Set it so that your input syntax will not be confused by titles. Make sure you don\'t enter a space character unless you really want to disallow spaces in titles. Leave empty to disable this feature.'),
@@ -417,12 +424,25 @@ function wikitools_nodeapi(&$node, $op, 
 function wikitools_node_validate($node) {
   if (wikitools_type_affected($node->type)) {
     if (wikitools_enforce_unique_titles()) {
-      $nid = db_result(db_query("SELECT nid FROM {node} WHERE LOWER(title) = LOWER('%s')", $node->title));
+      // Build node type condition.
+      $types_clause = NULL;
+      foreach(wikitools_node_types() as $type) {
+        if ($types_clause) {
+          $types_clause .= ",'" . db_escape_string($type) . "'";
+        }
+        else {
+          $types_clause = "type IN ('" . db_escape_string($type) . "'";
+        }
+      }
+      // There is at least one node type, so this will always be well-formed.
+      $types_clause .= ')';
+
+      $nid = db_result(db_query("SELECT nid FROM {node} WHERE LOWER(title) = LOWER('%s') AND $types_clause", $node->title));
       if (!$nid && wikitools_treat_underscore_as_space()) {
-        $nid = db_result(db_query("SELECT nid FROM {node} WHERE LOWER(REPLACE(title, '_', ' ')) = LOWER(REPLACE('%s', '_', ' '))", $node->title));
+        $nid = db_result(db_query("SELECT nid FROM {node} WHERE LOWER(REPLACE(title, '_', ' ')) = LOWER(REPLACE('%s', '_', ' ')) AND $types_clause", $node->title));
       }
       if (!$nid && wikitools_treat_dash_as_space()) {
-        $nid = db_result(db_query("SELECT nid FROM {node} WHERE LOWER(REPLACE(title, '-', ' ')) = LOWER(REPLACE('%s', '-', ' '))", $node->title));
+        $nid = db_result(db_query("SELECT nid FROM {node} WHERE LOWER(REPLACE(title, '-', ' ')) = LOWER(REPLACE('%s', '-', ' ')) AND $types_clause", $node->title));
       }
       // It is only an error if the node which alredy exists is not the currently edited node.
       if ($nid && $nid != $node->nid) {
@@ -649,20 +669,25 @@ function theme_wikitools_create($page_na
   $form = array();
   $output = '';
   if (wikitools_node_creation() && count($node_types)) {
+    $output .= '<p>'. t('You can create the page as:') .'</p>';
+    // Collapse the forms initially if there are more than one.
+    $collapsed = count($node_types) > 1 ? ' collapsed' : '';
+    // The form_alter hooks excpects the preset title in the GET array, so we put it there.
+    $_GET['edit']['title'] = $page_name;
     foreach ($node_types as $type) {
-	  drupal_add_js('misc/collapse.js');
+      drupal_add_js('misc/collapse.js');
       $type = node_get_types('type', $type);
       if (node_access('create', $type->type)) {
-	    $output .= '<p>'. t('You can create the page as:') .'</p>';
-        $output .= '<fieldset class="collapsible"><legend>'. $type->name .'</legend>';
-		if ($router_item = menu_get_item('node/add/'. $type->type)) {
+        $output .= '<fieldset class="collapsible' . $collapsed . '"><legend>'. $type->name .'</legend>';
+        if ($router_item = menu_get_item('node/add/'. $type->type)) {
           if ($router_item['file']) {
             require_once($router_item['file']);
           }
           $output .= call_user_func_array($router_item['page_callback'], $router_item['page_arguments']);
-		}
+        }
+        $output .= '</fieldset>';
       }
     }
   }
   return $output;
-}
\ No newline at end of file
+}
