? wikitools6_subpages.patch
Index: wikitools.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wikitools/wikitools.module,v
retrieving revision 1.4.2.1
diff -u -p -r1.4.2.1 wikitools.module
--- wikitools.module	22 Feb 2008 16:46:14 -0000	1.4.2.1
+++ wikitools.module	22 Feb 2008 17:42:10 -0000
@@ -138,6 +138,13 @@ function wikitools_admin_settings() {
     '#default_value' => wikitools_hijack_freelinking(),
     '#description' => t('If you activate this option, the links of the freelinking filter will be processed by the wikitools module rather than the freelinking module. When active, a link to <em>freelinking/Page Name</em> behaves exactly as a link to <em>wikipath/Page Name</em>.'),
   );
+  $form['wikitools_url_subpages'] = array(
+    '#type' => 'textfield',
+    '#title' => t('URL subpages'),
+    '#description' => t('A list of available subpages. These subpages can be appended to a URL below the wiki path and the user will be redirected to the specific subpage of the node. For example if you go to <em>wiki/Page_name/edit</em> you will be redirected to the edit page (if the page is found).'),
+    '#default_value' => implode(", ", wikitools_url_subpages()),
+  );
+
   $form = system_settings_form($form);
   // Rebuild the menu after updating the settings.
   $form['#submit'][] = 'menu_rebuild';
@@ -293,6 +300,16 @@ function wikitools_hijack_freelinking($v
   variable_set('wikitools_hijack_freelinking', $value);
 }
 
+/**
+ * Array of URL subpages.
+ */
+function wikitools_url_subpages($value = NULL) {
+  if (is_null($value)) {
+    return preg_split("/[\s,]+/", variable_get('wikitools_url_subpages', 'edit, delete, view, revisions'));
+  }
+  variable_set('wikitools_url_subpages', implode(", ", $value));
+}
+
 /*
  * Operations
  */
@@ -309,13 +326,16 @@ function wikitools_handle_request() {
   else {
     $i = 1;
   }
-  if (arg($i)) {
+  $args = explode('/', $_GET['q']);
+  $action = NULL;
+  if (isset($args[$i])) {
     // Save the path arguments after the wiki path as page name and put the slashes back.
-    $page_name = arg($i++);
-    while (arg($i)) {
-      $page_name .= '/'. arg($i);
-      $i++;
+    // Be sure we remove any subpages that are added to the end of the page name
+    if (count($args)-$i > 1 && in_array(end($args), wikitools_url_subpages())) {
+      $action = end($args);
+      array_pop($args);
     }
+    $page_name = implode('/', array_slice($args, $i));
   }
   else {
     // Use default page title if only wiki path is entered.
@@ -344,7 +364,12 @@ function wikitools_handle_request() {
     if (count($found_nodes) == 1) {
       // Single match for title.
       $node = current($found_nodes);
-      drupal_goto("node/$node->nid");
+      if ($action) {
+        drupal_goto("node/$node->nid/$action");
+      }
+      else {
+        drupal_goto("node/$node->nid");
+      }
     }
     else if (count($found_nodes) > 1) {
       // Multiple match for title.
@@ -429,6 +454,10 @@ function wikitools_node_validate($node) 
         }
       }
     }
+    $title_parts = explode('/', $node->title);
+    if (count($title_parts) > 1 && in_array(end($title_parts), wikitools_url_subpages())) {
+      form_set_error('title', t('The title cannot end with %string', array('%string' => '/' . end($title_parts))));
+    }
   }
 }
 
