? wikitools_og.patch
Index: wikitools.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wikitools/Attic/wikitools.admin.inc,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 wikitools.admin.inc
--- wikitools.admin.inc	20 Sep 2009 16:02:10 -0000	1.1.2.3
+++ wikitools.admin.inc	6 Dec 2010 02:52:48 -0000
@@ -50,6 +50,7 @@ function wikitools_admin_settings() {
       'node search' => t('Node Search: Let users search for nodes when they type in a node name which does not exist.'),
       'auto redirect' => t('Automatic Redirect: If a title of a moved page is entered, redirect automatically.'),
       'unique titles' => t('Unique Titles: Enforce that titles of new nodes are different from existing ones.'),
+      'unique titles og' => t('Unique Titles OG: Enforce that titles of new nodes are different from existing ones within a group.'),
       'move protection' => t('Move Protection: Disallow change of node titles for users without <em>administer nodes</em> permission.'),
       'underscore as space' => t('Treat underscores as spaces when looking for node titles.'),
       'dash as space' => t('Treat dashes as spaces when looking for node titles.'),
Index: wikitools.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wikitools/wikitools.module,v
retrieving revision 1.4.2.13
diff -u -p -r1.4.2.13 wikitools.module
--- wikitools.module	18 Jun 2009 04:25:27 -0000	1.4.2.13
+++ wikitools.module	6 Dec 2010 02:52:48 -0000
@@ -149,7 +149,7 @@ function wikitools_disallowed_characters
  * Various wikitool options.
  */
 function wikitools_options() {
-  return variable_get('wikitools_options', drupal_map_assoc(array('node creation', 'node search', 'unique titles', 'underscore as space')));
+  return variable_get('wikitools_options', drupal_map_assoc(array('node creation', 'node search', 'unique titles', 'unique titles og', 'underscore as space')));
 }
 
 /**
@@ -193,6 +193,14 @@ function wikitools_enforce_unique_titles
 }
 
 /**
+ * Are unique titles enforced per og?
+ */
+function wikitools_enforce_unique_titles_og() {
+  $options = wikitools_options();
+  return !empty($options['unique titles og']);
+}
+
+/**
  * Are underscore characters treated as spaces?
  */
 function wikitools_treat_underscore_as_space() {
@@ -362,26 +370,34 @@ function wikitools_nodeapi(&$node, $op, 
 function wikitools_node_validate($node) {
   if (wikitools_type_affected($node->type)) {
     // Check for unique titles.
-    if (wikitools_enforce_unique_titles()) {
+    if (wikitools_enforce_unique_titles() || wikitools_enforce_unique_titles_og()) {
       // Build node type condition.
-      $types_clause = NULL;
+      $where_clause = NULL;
+      $join = NULL;
       foreach(wikitools_node_types() as $type) {
-        if ($types_clause) {
-          $types_clause .= ",'" . db_escape_string($type) . "'";
+        if ($where_clause) {
+          $where_clause .= ",'" . db_escape_string($type) . "'";
         }
         else {
-          $types_clause = "type IN ('" . db_escape_string($type) . "'";
+          $where_clause = "node.type IN ('" . db_escape_string($type) . "'";
         }
       }
       // There is at least one node type, so this will always be well-formed.
-      $types_clause .= ')';
+      $where_clause .= ')';
+
+      // Limit unique title check to current group.
+      if (wikitools_enforce_unique_titles_og()) {
+        $group = og_get_group_context();
+        $join = 'LEFT JOIN {og_ancestry} ON node.nid = og_ancestry.nid';
+        $where_clause .= ' AND og_ancestry.group_nid = ' . $group->nid;
+      }
 
-      $nid = db_result(db_query("SELECT nid FROM {node} WHERE LOWER(title) = LOWER('%s') AND $types_clause", $node->title));
+      $nid = db_result(db_query("SELECT node.nid FROM {node} $join WHERE LOWER(node.title) = LOWER('%s') AND $where_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', '_', ' ')) AND $types_clause", $node->title));
+        $nid = db_result(db_query("SELECT node.nid FROM {node} $join WHERE LOWER(REPLACE(node.title, '_', ' ')) = LOWER(REPLACE('%s', '_', ' ')) AND $where_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', '-', ' ')) AND $types_clause", $node->title));
+        $nid = db_result(db_query("SELECT node.nid FROM {node} $join WHERE LOWER(REPLACE(node.title, '-', ' ')) = LOWER(REPLACE('%s', '-', ' ')) AND $where_clause", $node->title));
       }
       // It is only an error if the node which already exists is not the currently edited node.
       if ($nid && $nid != $node->nid) {
