? wikitools5_subpages.patch
Index: wikitools.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wikitools/wikitools.module,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 wikitools.module
--- wikitools.module	22 Feb 2008 16:42:16 -0000	1.1.2.4
+++ wikitools.module	22 Feb 2008 17:53:36 -0000
@@ -134,6 +134,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()),
+  );
+
   return system_settings_form($form);
 }
 
@@ -301,6 +308,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
  */
@@ -310,15 +327,23 @@ function wikitools_hijack_freelinking($v
  * This function is called if a page without an alias is called below the wiki path.
  */
 function wikitools_handle_request() {
-  // Calculate index of first path argument after wiki path.
-  $i = count(explode('/',wikitools_wiki_path()));
-  if (arg($i)) {
+  // Calculate index of first path argument after wiki path if specific position wasn't passed in.
+  if (arg(0) != 'freelinking') {
+    $i = count(explode('/', wikitools_wiki_path()));
+  }
+  else {
+    $i = 1;
+  }
+  $args = explode('/', $_GET['q']);
+  $subpage = 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())) {
+      $subpage = end($args);
+      array_pop($args);
     }
+    $page_name = implode('/', array_slice($args, $i));
   }
   else {
     // Use default page title if only wiki path is entered.
@@ -348,7 +373,12 @@ function wikitools_handle_request() {
     if (count($found_nodes) == 1) {
       // Single match for title.
       $node = current($found_nodes);
-      drupal_goto("node/$node->nid");
+      if ($subpage) {
+        drupal_goto("node/$node->nid/$subpage");
+      }
+      else {
+        drupal_goto("node/$node->nid");
+      }
     }
     else if (count($found_nodes) > 1) {
       // Multiple match for title.
@@ -433,6 +463,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))));
+    }
   }
 }
 
