diff -up -r wikitools.admin.inc wikitools.admin.inc --- wikitools.admin.inc 2011-01-23 13:16:50.000000000 -0500 +++ wikitools.admin.inc 2011-01-23 13:16:30.000000000 -0500 @@ -9,14 +9,14 @@ /** * Callback for wikitools settings form. */ -function wikitools_admin_settings() { +function wikitools_admin_settings($form, &$form_state) { $form = array(); list($select_query, $count_query, $arguments) = _wikitools_duplicate_nodes_query(); if ($count_query) { - $duplicates_exist = db_result(db_query($count_query, $arguments)); + $duplicates_exist = db_query($count_query, $arguments)->fetchField(); if ($duplicates_exist) { - drupal_set_message(t('Nodes with duplicate titles exist in your wiki. To clear up this issue, visit the duplicate titles page.', + drupal_set_message(t('Nodes with duplicate titles exist in your wiki. To clear up this issue, visit the duplicate titles page.', array('!url' => url('admin/content/wikitools'))), 'warning'); } } @@ -26,7 +26,7 @@ function wikitools_admin_settings() { '#title' => t('Wiki path'), '#default_value' => wikitools_wiki_path(), '#description' => t('The drupal path for the wiki. Do not include a trailing slash. Leave empty to disable the wiki path.'), - '#field_prefix' => url(NULL, array('absolute' => FALSE)) . (variable_get('clean_url', 0) ? '' : '?q=') + '#field_prefix' => url(NULL, array('absolute' => FALSE)) . (variable_get('clean_url', 0) ? '' : '?q='), ); $form['wikitools_main_page_title'] = array( '#type' => 'textfield', @@ -37,7 +37,7 @@ function wikitools_admin_settings() { $form['wikitools_node_types'] = array( '#type' => 'checkboxes', '#title' => t('Wiki node types'), - '#options' => node_get_types('names'), + '#options' => node_type_get_names(), '#default_value' => wikitools_node_types(), '#multiple' => TRUE, '#description' => t('Select the node types which will be affected by the specified options. If you select multiple node types, all nodes of these types will be searched for when a wikipath is entered. If a wikipage doesn\'t exist, an option to create any of these types will be given.'), @@ -55,10 +55,10 @@ function wikitools_admin_settings() { 'dash as space' => t('Treat dashes as spaces when looking for node titles.'), ), '#default_value' => wikitools_options(), - '#description' => '', + '#description' => '', ); $form['wikitools_404_type'] = array( '#type' => 'checkboxes', @@ -127,14 +127,14 @@ function wikitools_page_duplicates() { // Grab all nodes that have the same title $result = pager_query($select_query, $nodes_per_page, 0, $count_query, $arguments); - while ($node = db_fetch_object($result)) { + foreach ($result as $node) { $output .= node_view(node_load($node->nid), 1); $found_nodes = TRUE; } } if ($found_nodes) { - $output .= theme('pager', NULL, $nodes_per_page); + $output .= theme('pager', array('tags' => NULL)); } // Return a nice listing of all the duplicate nodes @@ -160,11 +160,10 @@ function _wikitools_duplicate_nodes_quer } // Grab all nodes that have the same title - $node_types_placeholders = db_placeholders($node_types, 'varchar'); - $from_part = 'FROM {node} n1, {node} n2 WHERE LOWER('. $n1_title .') = LOWER('. $n2_title .') AND n1.nid != n2.nid AND n1.type IN('. $node_types_placeholders .') AND n2.type IN('. $node_types_placeholders .')'; + $from_part = 'FROM {node} n1, {node} n2 WHERE LOWER(' . $n1_title . ') = LOWER(' . $n2_title . ') AND n1.nid != n2.nid AND n1.type IN(:type) AND n2.type IN(:type)'; $select_query = 'SELECT DISTINCT(n1.nid), n1.title ' . $from_part . ' ORDER BY n1.title ASC'; $count_query = 'SELECT COUNT(DISTINCT(n1.nid)) ' . $from_part; - return array($select_query, $count_query, array_merge($node_types, $node_types)); + return array($select_query, $count_query, array(':type' => $node_types)); } return array(NULL, NULL, NULL); } diff -up -r wikitools.info wikitools.info --- wikitools.info 2011-01-23 13:16:50.000000000 -0500 +++ wikitools.info 2011-01-23 13:16:30.000000000 -0500 @@ -1,10 +1,14 @@ ; $Id: wikitools.info,v 1.4 2007/12/31 23:35:06 cwgordon7 Exp $ name = Wikitools description = Provides helper functionality to have wiki-like behaviour. -core = "6.x" +core = 7.x ; Information added by drupal.org packaging script on 2010-11-12 version = "6.x-1.x-dev" -core = "6.x" +core = 7.x project = "wikitools" datestamp = "1289565051" + +files[] = wikitools.admin.inc +files[] = wikitools.module +files[] = wikitools.pages.inc diff -up -r wikitools.module wikitools.module --- wikitools.module 2011-01-23 13:16:50.000000000 -0500 +++ wikitools.module 2011-01-23 13:16:30.000000000 -0500 @@ -7,18 +7,18 @@ */ /** - * Implementation of hook_help(). + * Implements hook_help(). */ function wikitools_help($path, $arg) { switch ($path) { case 'admin/help#wikitools': - $output = '

'. t('The wikitools module allows you to set several options for your content to get a more wiki-like behaviour.') .'

'; + $output = '

' . t('The wikitools module allows you to set several options for your content to get a more wiki-like behaviour.') . '

'; return $output; - case 'admin/settings/wikitools': - $output = '

'. t('Below you can configure the settings for the wikitools module. The "wiki path" will be the path that will redirect you to the wiki page with the appropriate title; only the wiki node types selected can be accesssed from the wiki path. Choose from the other options to determine the behavior of the wiki path.') .'

'; + case 'admin/config/wikitools': + $output = '

' . t('Below you can configure the settings for the wikitools module. The "wiki path" will be the path that will redirect you to the wiki page with the appropriate title; only the wiki node types selected can be accesssed from the wiki path. Choose from the other options to determine the behavior of the wiki path.') . '

'; return $output; case 'admin/content/wikitools': - $output = '

'. t('Wikitools allows restrictions on node titles so that all new created nodes have guaranteed unique titles. Titles of nodes that were created before it was included in this option, however, are not guaranteed to have unique page titles. This page lists all nodes that have duplicate page titles, so that their titles may be changed to be unique.') .'

'; + $output = '

' . t('Wikitools allows restrictions on node titles so that all new created nodes have guaranteed unique titles. Titles of nodes that were created before it was included in this option, however, are not guaranteed to have unique page titles. This page lists all nodes that have duplicate page titles, so that their titles may be changed to be unique.') . '

'; return $output; } } @@ -28,11 +28,11 @@ function wikitools_help($path, $arg) { */ /** - * Implementation of hook_menu(). + * Implements hook_menu(). */ function wikitools_menu() { $items = array(); - $items['admin/settings/wikitools'] = array( + $items['admin/config/wikitools'] = array( 'title' => t('Wikitools'), 'description' => t('Settings for wiki-like behaviour.'), 'access arguments' => array('administer site configuration'), @@ -103,7 +103,7 @@ function wikitools_node_types($value = N static $node_types = NULL; if (is_null($node_types)) { $node_types = array(); - foreach(variable_get('wikitools_node_types', array()) as $type => $active) { + foreach (variable_get('wikitools_node_types', array()) as $type => $active) { if ($active) { $node_types[$type] = $type; } @@ -301,7 +301,7 @@ function wikitools_create_url($type, $ti * title to search for */ function wikitools_search_url($title) { - return url('search/node/'. $title); + return url('search/node/' . $title); } /** @@ -327,17 +327,17 @@ function wikitools_wikilink_url($title, */ function wikitools_wikilink_drupal_path($title) { if ($wiki_path = wikitools_wiki_path()) { - return $wiki_path .'/'. wikitools_encode_page_name($title); + return $wiki_path . '/' . wikitools_encode_page_name($title); } elseif (wikitools_hijack_freelinking()) { - return 'freelinking/'. wikitools_encode_page_name($title); + return 'freelinking/' . wikitools_encode_page_name($title); } else { // Neither wikitools nor freelinking will handle the link. // Try to find a node with the given name and link directly to the first match. - $result = db_query("SELECT nid, type FROM {node} WHERE LOWER(title) = LOWER('%s')", $title); + $result = db_query("SELECT nid, type FROM {node} WHERE LOWER(title) = LOWER(:title)", array(':title' => $title)); $found_nodes = array(); - while ($node = db_fetch_object($result)) { + foreach ($result as $node) { if (wikitools_type_affected($node->type)) { return "node/$node->nid"; } @@ -346,15 +346,9 @@ function wikitools_wikilink_drupal_path( } /** - * Implementation of hook_nodeapi(). + * Implements hook_nodeapi(). */ -function wikitools_nodeapi(&$node, $op, $form = NULL, $a4 = NULL) { - switch ($op) { - case 'validate': - wikitools_node_validate($node); - break; - } -} +function wikitools_nodeapi_OLD(&$node, $op, $form = NULL, $a4 = NULL) { } /** * Validate check of node edit form. @@ -364,24 +358,12 @@ function wikitools_node_validate($node) // Check for unique titles. if (wikitools_enforce_unique_titles()) { // Build node type condition. - $types_clause = NULL; - foreach(wikitools_node_types() as $type) { - if ($types_clause) { - $types_clause .= ",'" . db_escape_string($type) . "'"; - } - else { - $types_clause = "type IN ('" . db_escape_string($type) . "'"; - } - } - // There is at least one node type, so this will always be well-formed. - $types_clause .= ')'; - - $nid = db_result(db_query("SELECT nid FROM {node} WHERE LOWER(title) = LOWER('%s') AND $types_clause", $node->title)); + $nid = db_query("SELECT nid FROM {node} WHERE LOWER(title) = LOWER(:title) AND type IN (:types)", array(':title' => $node->title, ':types' => wikitools_node_types()))->fetchField(); if (!$nid && wikitools_treat_underscore_as_space()) { - $nid = db_result(db_query("SELECT nid FROM {node} WHERE LOWER(REPLACE(title, '_', ' ')) = LOWER(REPLACE('%s', '_', ' ')) AND $types_clause", $node->title)); + $nid = db_query("SELECT nid FROM {node} WHERE LOWER(REPLACE(title, '_', ' ')) = LOWER(REPLACE(:title, '_', ' ')) AND type IN (:types)", array(':title' => $node->title, ':types' => wikitools_node_types()))->fetchField(); } if (!$nid && wikitools_treat_dash_as_space()) { - $nid = db_result(db_query("SELECT nid FROM {node} WHERE LOWER(REPLACE(title, '-', ' ')) = LOWER(REPLACE('%s', '-', ' ')) AND $types_clause", $node->title)); + $nid = db_query("SELECT nid FROM {node} WHERE LOWER(REPLACE(title, '-', ' ')) = LOWER(REPLACE(:title, '-', ' ')) AND type IN (:types)", array(':title' => $node->title, ':types' => wikitools_node_types()))->fetchField(); } // It is only an error if the node which already exists is not the currently edited node. if ($nid && $nid != $node->nid) { @@ -408,11 +390,11 @@ function wikitools_node_validate($node) } /** - * Implementation of hook_form_alter(). + * Implements hook_form_alter(). */ function wikitools_form_alter(&$form, $form_state, $form_id) { // Check if it is a node editing form of an affected type. - if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) { + if (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id) { if (wikitools_type_affected($form['type']['#value'])) { if ($form['nid']['#value']) { // Node is edited. @@ -433,32 +415,32 @@ function wikitools_form_alter(&$form, $f } /** - * Implementation of hook_theme(). + * Implements hook_theme(). */ function wikitools_theme() { return array( 'wikitools_page_found' => array( - 'arguments' => array('page_name' => NULL, 'found_nodes' => NULL), + 'variables' => array('page_name' => NULL, 'found_nodes' => NULL), 'file' => 'wikitools.pages.inc', ), 'wikitools_page_moved' => array( - 'arguments' => array('page_name' => NULL, 'moved_nodes' => NULL), + 'variables' => array('page_name' => NULL, 'moved_nodes' => NULL), 'file' => 'wikitools.pages.inc', ), 'wikitools_page_does_not_exist' => array( - 'arguments' => array('page_name' => NULL), + 'variables' => array('page_name' => NULL), 'file' => 'wikitools.pages.inc', ), 'wikitools_search_notice' => array( - 'arguments' => array('page_name' => NULL), + 'variables' => array('page_name' => NULL), 'file' => 'wikitools.pages.inc', ), 'wikitools_create_notice' => array( - 'arguments' => array('page_name' => NULL), + 'variables' => array('page_name' => NULL), 'file' => 'wikitools.pages.inc', ), 'wikitools_create' => array( - 'arguments' => array('page_name' => NULL), + 'variables' => array('page_name' => NULL), 'file' => 'wikitools.pages.inc', ), ); diff -up -r wikitools.pages.inc wikitools.pages.inc --- wikitools.pages.inc 2011-01-23 13:16:50.000000000 -0500 +++ wikitools.pages.inc 2011-01-23 13:16:36.000000000 -0500 @@ -36,7 +36,7 @@ function wikitools_handle_request() { } 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())) { + if (count($args) -$i > 1 && in_array(end($args), wikitools_subpages())) { $subpage = end($args); array_pop($args); } @@ -55,11 +55,12 @@ function wikitools_handle_request() { $node_types = wikitools_node_types(); if (count($node_types) && $page_name) { // Try to find the current page with this name, limit the query by node types - $params = $node_types; - $params[] = $page_name; - $result = db_query("SELECT nid, type FROM {node} WHERE type IN (". db_placeholders($node_types, 'varchar') .") AND LOWER(title) = LOWER('%s')", $params); + $result = db_query("SELECT nid, type FROM {node} WHERE type IN (:type) AND LOWER(title) = LOWER(:title)", array( + ':type' => $node_types, + 'title' => $page_name, + )); $found_nodes = array(); - while ($node = db_fetch_object($result)) { + foreach ($result as $node) { if (wikitools_type_affected($node->type)) { $found_nodes[] = $node; } @@ -76,14 +77,14 @@ function wikitools_handle_request() { } else if (count($found_nodes) > 1) { // Multiple match for title. - drupal_set_title(t('Page found: %page', array('%page' => $page_name))); - $output .= theme('wikitools_page_found', $page_name, $found_nodes); + drupal_set_title(t('Page found: %page', array('%page' => $page_name)), PASS_THROUGH); + $output .= theme('wikitools_page_found', array('page_name' => $page_name, 'found_nodes' => $found_nodes)); } else { // No match for title. Try to find an old page with this name - $result = db_query("SELECT n.nid, n.type, n.title FROM {node} n LEFT JOIN {node_revisions} r ON n.nid = r.nid WHERE LOWER(r.title) = LOWER('%s') ORDER BY n.vid DESC", $page_name); + $result = db_query("SELECT n.nid, n.type, n.title FROM {node} n LEFT JOIN {node_revision} r ON n.nid = r.nid WHERE LOWER(r.title) = LOWER(:title) ORDER BY n.vid DESC", array(':title' => $page_name)); $moved_nodes = array(); - while ($node = db_fetch_object($result)) { + foreach ($result as $node) { if (wikitools_type_affected($node->type)) { $moved_nodes[] = $node; } @@ -94,12 +95,12 @@ function wikitools_handle_request() { drupal_goto("node/$node->nid"); } else if (count($moved_nodes) > 0) { - drupal_set_title(t('Page moved: %page', array('%page' => $page_name))); - $output = theme('wikitools_page_moved', $page_name, $moved_nodes); + drupal_set_title(t('Page moved: %page', array('%page' => $page_name)), PASS_THROUGH); + $output = theme('wikitools_page_moved', array('page_name' => $page_name, 'moved_nodes' => $moved_nodes)); } else { - drupal_set_title(t('Page does not exist: %page', array('%page' => $page_name))); - $output = theme('wikitools_page_does_not_exist', $page_name); + drupal_set_title(t('Page does not exist: %page', array('%page' => $page_name)), PASS_THROUGH); + $output = theme('wikitools_page_does_not_exist', array('page_name' => $page_name)); } } } @@ -116,91 +117,123 @@ function wikitools_handle_request() { * @ingroup themeable */ -function theme_wikitools_page_found($page_name, $found_nodes) { - $output = '

'. t('Multiple pages have this name:') .'

'; +/** + * @todo Please document this function. + * @see http://drupal.org/node/1354 + */ +function theme_wikitools_page_found($variables) { + $page_name = $variables['page_name']; + $found_nodes = $variables['found_nodes']; + $output = '

' . t('Multiple pages have this name:') . '

'; foreach ($found_nodes as $info) { $node = node_load($info->nid); $output .= node_view($node, TRUE, FALSE, FALSE); } - $output .= theme('wikitools_search_notice', $page_name); + $output .= theme('wikitools_search_notice', array('page_name' => $page_name)); if (!wikitools_enforce_unique_titles()) { - $output .= theme('wikitools_create_notice', $page_name); + $output .= theme('wikitools_create_notice', array('page_name' => $page_name)); } return $output; } -function theme_wikitools_page_moved($page_name, $moved_nodes) { - $output = '

'. t('The page %page_name has been moved.', array('%page_name' => $page_name)) .'

'; +/** + * @todo Please document this function. + * @see http://drupal.org/node/1354 + */ +function theme_wikitools_page_moved($variables) { + $page_name = $variables['page_name']; + $moved_nodes = $variables['moved_nodes']; + $output = '

' . t('The page %page_name has been moved.', array('%page_name' => $page_name)) . '

'; $node = current($moved_nodes); - $output .= '

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

'; + $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_create_notice', $page_name); + $output .= theme('wikitools_search_notice', array('page_name' => $page_name)); + $output .= theme('wikitools_create_notice', array('page_name' => $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)) .'

'; +/** + * @todo Please document this function. + * @see http://drupal.org/node/1354 + */ +function theme_wikitools_page_does_not_exist($variables) { + $page_name = $variables['page_name']; + $output = '

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

'; $settings = wikitools_404(); if (!empty($settings['Link to search'])) { - $output .= theme('wikitools_search_notice', $page_name); + $output .= theme('wikitools_search_notice', array('page_name' => $page_name)); } if (!empty($settings['Link to creation'])) { - $output .= theme('wikitools_create_notice', $page_name); + $output .= theme('wikitools_create_notice', array('page_name' => $page_name)); } if (!empty($settings['Creation form'])) { - $output .= theme('wikitools_create', $page_name); + $output .= theme('wikitools_create', array('page_name' => $page_name)); } return $output; } -function theme_wikitools_search_notice($page_name) { +/** + * @todo Please document this function. + * @see http://drupal.org/node/1354 + */ +function theme_wikitools_search_notice($variables) { + $page_name = $variables['page_name']; $output = ''; if (module_exists('search') && user_access('search content') && wikitools_node_search()) { - $output .= '

'. t('You can search for %page_name', array('@url' => wikitools_search_url($page_name), '%page_name' => $page_name)) .'

'; + $output .= '

' . t('You can search for %page_name', array('@url' => wikitools_search_url($page_name), '%page_name' => $page_name)) . '

'; } return $output; } -function theme_wikitools_create_notice($page_name) { +/** + * @todo Please document this function. + * @see http://drupal.org/node/1354 + */ +function theme_wikitools_create_notice($variables) { + $page_name = $variables['page_name']; $output = ''; $node_types = wikitools_node_types(); if (wikitools_node_creation() && count($node_types)) { $create = ''; $count = 0; foreach ($node_types as $type) { - $type = node_get_types('type', $type); + $type = node_type_get_type($type); if (node_access('create', $type->type)) { - $create .= '
'. $type->name .'
'; - $create .= '
'. filter_xss_admin($type->description) .'
'; + $create .= '
' . $type->name . '
'; + $create .= '
' . filter_xss_admin($type->description) . '
'; } } if ($create) { - $output .= '

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

'; - $output .= '
'. $create .'
'; + $output .= '

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

'; + $output .= '
' . $create . '
'; } } return $output; } -function theme_wikitools_create($page_name) { +/** + * @todo Please document this function. + * @see http://drupal.org/node/1354 + */ +function theme_wikitools_create($variables) { + $page_name = $variables['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:') .'

'; + $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); + $type = node_type_get_type($type); if (node_access('create', $type->type)) { - $output .= '
'. $type->name .''; - if ($router_item = menu_get_item('node/add/'. str_replace('_', '-', $type->type))) { + $output .= '
' . $type->name . ''; + if ($router_item = menu_get_item('node/add/' . str_replace('_', '-', $type->type))) { if ($router_item['file']) { - require_once($router_item['file']); + require_once DRUPAL_ROOT . '/' . $router_item['file']; } $output .= call_user_func_array($router_item['page_callback'], $router_item['page_arguments']); } @@ -208,7 +241,7 @@ function theme_wikitools_create($page_na } } // Some of the callbacks could have set the page title, so we reset it. - drupal_set_title(t('Page does not exist: %page', array('%page' => $page_name))); + drupal_set_title(t('Page does not exist: %page', array('%page' => $page_name)), PASS_THROUGH); } return $output; }