diff -uNr wikitools.orig/wikitools.module wikitools/wikitools.module --- wikitools.orig/wikitools.module 2008-02-25 18:56:24.000000000 -0300 +++ wikitools/wikitools.module 2009-05-18 00:33:19.575288505 -0300 @@ -275,6 +275,53 @@ */ /** + * Get the page name and determine the subpage. + */ +function wikitools_get_page_name() { + + // Create list of path parts. + $args = explode('/', $_GET['q']); + + // Calculate index of first path argument after wiki path. + if (arg(0) != 'freelinking') { + $i = count(explode('/', wikitools_wiki_path())); + } + else { + $i = 1; + } + + // Determine subpage. + $subpage = NULL; + if (wikitools_subpages_handling() == 'query') { + // Check if a query string is in the URL with a valid subpage + if (isset($_GET[wikitools_subpages_query_string()])) { + $subpage = $_GET[wikitools_subpages_query_string()]; + if (!in_array($subpage, wikitools_subpages())) { + $subpage = NULL; + } + } + } + elseif (wikitools_subpages_handling() == 'url') { + // Check if there are more than one part, and if the last one is a valid subpage. + if (count($args)-$i > 1 && in_array(end($args), wikitools_subpages())) { + $subpage = end($args); + array_pop($args); + } + } + + // Determine page name. + if (isset($args[$i])) { + $page_name = wikitools_decode_page_name(implode('/', array_slice($args, $i))); + } + else { + // Use default page title if only wiki path is entered. + $page_name = wikitools_main_page_title(); + } + + return array($page_name,$subpage); +} + +/** * Decode page name given via URL. */ function wikitools_decode_page_name($encoded_page_name) { @@ -450,6 +497,15 @@ // Node is new. if (isset($_GET['edit'])) { $form['title']['#default_value'] = urldecode($_GET['edit']['title']); + list($page_name,$subpage) = wikitools_get_page_name(); + if (wikitools_treat_underscore_as_space()) { + $page_name = str_replace(' ', '_', $page_name); + } + if (wikitools_treat_dash_as_space()) { + $page_name = str_replace(' ', '-', $page_name); + } + $form['path']['path']['#default_value'] = wikitools_wiki_path() . '/' . $page_name; + $form['path']['#collapsed'] = 0; } } } diff -uNr wikitools.orig/wikitools.pages.inc wikitools/wikitools.pages.inc --- wikitools.orig/wikitools.pages.inc 2009-03-25 16:16:56.000000000 -0300 +++ wikitools/wikitools.pages.inc 2009-05-18 00:33:19.575288505 -0300 @@ -12,44 +12,7 @@ function wikitools_handle_request() { $output = ''; - // Create list of path parts. - $args = explode('/', $_GET['q']); - - // Calculate index of first path argument after wiki path. - if (arg(0) != 'freelinking') { - $i = count(explode('/', wikitools_wiki_path())); - } - else { - $i = 1; - } - - // Determine subpage. - $subpage = NULL; - if (wikitools_subpages_handling() == 'query') { - // Check if a query string is in the URL with a valid subpage - if (isset($_GET[wikitools_subpages_query_string()])) { - $subpage = $_GET[wikitools_subpages_query_string()]; - if (!in_array($subpage, wikitools_subpages())) { - $subpage = NULL; - } - } - } - elseif (wikitools_subpages_handling() == 'url') { - // Check if there are more than one part, and if the last one is a valid subpage. - if (count($args)-$i > 1 && in_array(end($args), wikitools_subpages())) { - $subpage = end($args); - array_pop($args); - } - } - - // Determine page name. - if (isset($args[$i])) { - $page_name = wikitools_decode_page_name(implode('/', array_slice($args, $i))); - } - else { - // Use default page title if only wiki path is entered. - $page_name = wikitools_main_page_title(); - } + list($page_name,$subpage) = wikitools_get_page_name(); // Don't do anything if no node types are active or no page name is available $node_types = wikitools_node_types();