=== modified file 'wikitools.module' --- wikitools.module 2008-04-02 11:48:19 +0000 +++ wikitools.module 2008-04-09 11:52:45 +0000 @@ -122,6 +122,18 @@ t('The options Node Creation, Node Search and Automatic Redirect work only if a wiki path is set or if freelinking hijacking is enabled. They take the page name from the path after the wiki path, i.e. wikipath/Page Name, or the page name of a freelinking link, i.e. freelinking/Page Name.') .'
  • '. t('The option Automatic Redirect works only if node revisions are created.') .'
  • ', ); + $form['wikitools_404_type'] = array( + '#type' => 'checkboxes', + '#title' => t('Wiki 404 type'), + '#description' => t('Select the 404 (page not found) type for all pages under the wiki path.'), + '#multiple' => TRUE, + '#options' => array( + 'Link to search' => t('Link to search'), + 'Link to creation' => t('Link to creation'), + 'Creation form' => t('Creation form'), + ), + '#default_value' => wikitools_404(), + ); $form['wikitools_disallowed_characters'] = array( '#type' => 'textfield', '#title' => t('Disallowed characters in titles'), @@ -239,6 +251,16 @@ } /** + * What 404 error settings are set? + */ +function wikitools_404($value = NULL) { + if (is_null($value)) { + return variable_get('wikitools_404_type', array('Link to search', 'Creation form')); + } + variable_set('wikitools_404_type', $values); +} + +/** * String of characters which are not allowed in a wiki page title. */ function wikitools_disallowed_characters($value = NULL) { @@ -440,10 +462,38 @@ // Single match for title. $node = current($found_nodes); if ($subpage) { - drupal_goto("node/$node->nid/$subpage"); + $url = "node/$node->nid/$subpage"; } else { - drupal_goto("node/$node->nid"); + $url = "node/$node->nid"; + } + // HACK: Force rebuilding of menu. This is necessary because of the + // way menu entries are added in Drupal 5.x for specific nodes. + global $_menu; + $_menu = NULL; + // Set query path so that we look like we are coming to $url. + menu_set_active_item($url); + // Generate the node. + $output = menu_execute_active_handler(); + + // If handling sub-pages in the URL, rewrite the tab links to reflect + // the wiki path. + if (wikitools_subpages_handling() == 'url') { + $orig = "node/$node->nid"; + $dest = wikitools_wikilink_drupal_path($page_name); + + // HACK: Rewrite stuff on the $_menu global. This is necessary under + // Drupal 5.x because we can't intercept the template variables like + // we can under Drupal 6.x. + $local_tasks = menu_get_local_tasks(); + $pid = menu_get_active_nontask_item(); + foreach ($local_tasks[$pid]['children'] as $mid) { + $_menu['items'][$mid]['path'] = str_replace($orig, $dest, $_menu['items'][$mid]['path']); + } + // change the main entry itself + $_menu['items'][$pid]['path'] = str_replace($orig, $dest, $_menu['items'][$pid]['path']); + // to reset the get_menu_item() static variable cache. + menu_get_item(NULL, NULL, TRUE); } } else if (count($found_nodes) > 1) { @@ -587,7 +637,13 @@ * title of new node */ function wikitools_create_url($type, $title) { - return url("node/add/$type", 'edit[title]='. urlencode($title)); + if (is_object($type)) { + $type_url_str = str_replace('_', '-', $type->type); + } + else { + $type_url_str = str_replace('_', '-', $type); + } + return url("node/add/$type_url_str", 'edit[title]='. urlencode($title)); } /** @@ -656,7 +712,7 @@ $node = node_load($info->nid); $output .= node_view($node, TRUE, FALSE, FALSE); } - $output .= theme('wikitools_search_notice' ,$page_name); + $output .= theme('wikitools_search_notice', $page_name); if (!wikitools_enforce_unique_titles()) { $output .= theme('wikitools_create_notice', $page_name); } @@ -668,15 +724,23 @@ $node = current($moved_nodes); $output .= '

    '. t('The new page name is !new_name', array('!new_name' => l($node->title, "node/$node->nid"))) .'

    '; // Todo: show all moved pages - $output .= theme('wikitools_search_notice' ,$page_name); + $output .= theme('wikitools_search_notice', $page_name); $output .= theme('wikitools_create_notice', $page_name); return $output; } function theme_wikitools_page_does_not_exist($page_name) { $output = '

    '. t('The page %page_name does not exist.', array('%page_name' => $page_name)) .'

    '; - $output .= theme('wikitools_search_notice' ,$page_name); - $output .= theme('wikitools_create_notice', $page_name); + $settings = wikitools_404(); + if ($settings['Link to search']) { + $output .= theme('wikitools_search_notice', $page_name); + } + if ($settings['Link to creation']) { + $output .= theme('wikitools_create_notice', $page_name); + } + if ($settings['Creation form']) { + $output .= theme('wikitools_create', $page_name); + } return $output; } @@ -707,3 +771,28 @@ } return $output; } + +function theme_wikitools_create($page_name) { + $node_types = wikitools_node_types(); + $form = array(); + $output = ''; + if (wikitools_node_creation() && count($node_types)) { + $output .= '

    '. t('You can create the page as:') .'

    '; + // 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'); + $type = node_get_types('type', $type); + if (node_access('create', $type->type)) { + $output .= '
    '. $type->name .''; + $output .= node_add($type->type); + $output .= '
    '; + } + } + // Some of the callbacks could have set the page title, so we reset it. + drupal_set_title('Page does not exist: '. $page_name); + } + return $output; +}