=== modified file 'wikitools.module' --- wikitools.module 2008-04-02 11:48:19 +0000 +++ wikitools.module 2008-04-23 13:34:17 +0000 @@ -23,6 +23,60 @@ */ /** + * Implementation of hook_init + * + * Early checking of URL requested. + * If a wiki node is refered to by "node/$node->nid", the user is + * redirected using drupal_goto() + * + * This code was lifted graciously from the path_redirect module. + */ +function wikitools_init() { + // find the path (usually $_GET['q']) + $path = substr(request_uri(), strlen($GLOBALS['base_path'])); + if (preg_match('/^\?q=/', $path)) { + $path = preg_replace(array('/^\?q=/', '/&/'), array('', '?'), $path, 1); + } + if (preg_match('/^node\/(\d+)$/', $path, $matches)) { + $node = node_load($matches[1]); + if (wikitools_type_affected($node->type)) { + $redirect = wikitools_wikilink_drupal_path($node->title); + } + } + + // do the redirect if we've managed to locate a wikilink + if ($redirect) { + if (function_exists('drupal_goto')) { + // if there's a result found, do the redirect + unset($_REQUEST['destination']); + drupal_goto($redirect); + } + else { + // page caching is turned on so drupal_goto() (common.inc) hasn't been loaded + global $base_url; + $url = $base_url .'/'. $redirect; + + // Remove newlines from the URL to avoid header injection attacks. + $url = str_replace(array("\n", "\r"), '', $url); + + // Before the redirect, allow modules to react to the end of the page request. + bootstrap_invoke_all('exit'); + + // Even though session_write_close() is registered as a shutdown function, we + // need all session data written to the database before redirecting. + session_write_close(); + + header('Location: '. $url, TRUE, 302); + + // The "Location" header sends a REDIRECT status code to the http + // daemon. In some cases this can go wrong, so we make sure none + // of the code below the drupal_goto() call gets executed when we redirect. + exit(); + } + } +} + +/** * Implementation of hook_menu(). */ function wikitools_menu($may_cache) { @@ -122,6 +176,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 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 +805,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 .= ''; + } + } + // 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; +}