### Eclipse Workspace Patch 1.0
#P Test Drupal 6
Index: modules/search/search.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/search/search.module,v
retrieving revision 1.225
diff -u -r1.225 search.module
--- modules/search/search.module 15 Jun 2007 22:00:30 -0000 1.225
+++ modules/search/search.module 17 Jun 2007 17:50:44 -0000
@@ -253,8 +253,6 @@
$form['#validate'] = array('search_admin_settings_validate');
- // Per module settings
- $form = array_merge($form, module_invoke_all('search', 'admin'));
return system_settings_form($form);
}
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.832
diff -u -r1.832 node.module
--- modules/node/node.module 17 Jun 2007 14:37:33 -0000 1.832
+++ modules/node/node.module 17 Jun 2007 17:50:43 -0000
@@ -1,5 +1,5 @@
%d ) OR (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d))', $last, $last_nid, $last, $last, $last));
- return array('remaining' => $remaining, 'total' => $total);
+ $excluded_types = variable_get('search_excluded_content_types', array());
- case 'admin':
- $form = array();
- // Output form for defining rank factor weights.
- $form['content_ranking'] = array('#type' => 'fieldset', '#title' => t('Content ranking'));
- $form['content_ranking']['#theme'] = 'node_search_admin';
- $form['content_ranking']['info'] = array('#value' => ''. t('The following numbers control which properties the content search should favor when ordering the results. Higher numbers mean more influence, zero means the property is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') .'');
-
- $ranking = array('node_rank_relevance' => t('Keyword relevance'),
- 'node_rank_recent' => t('Recently posted'));
- if (module_exists('comment')) {
- $ranking['node_rank_comments'] = t('Number of comments');
- }
- if (module_exists('statistics') && variable_get('statistics_count_content_views', 0)) {
- $ranking['node_rank_views'] = t('Number of views');
- }
-
- // Note: reversed to reflect that higher number = higher ranking.
- $options = drupal_map_assoc(range(0, 10));
- foreach ($ranking as $var => $title) {
- $form['content_ranking']['factors'][$var] = array('#title' => $title, '#type' => 'select', '#options' => $options, '#default_value' => variable_get($var, 5));
+ $args = array($last, $last_nid, $last, $last, $last);
+ $type_exclude = '';
+ if (!empty($excluded_types)) {
+ $type_exclude = 'n.type NOT IN('. implode(',', array_fill(0, count($excluded_types), "'%s'")) .') AND ';
+ $args = array_merge(array_values($excluded_types), $args);
}
- return $form;
+ $total = db_result(db_query("SELECT COUNT(*) FROM {node} n WHERE $type_exclude n.status = 1", $excluded_types));
+ $remaining = db_result(db_query("SELECT COUNT(*) FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE $type_exclude n.status = 1 AND ((GREATEST(n.created, n.changed, c.last_comment_timestamp) = %d AND n.nid > %d ) OR (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d))", $args));
+
+ return array('remaining' => $remaining, 'total' => $total);
case 'search':
// Build matching conditions
@@ -1002,6 +988,35 @@
}
/**
+ * Validate handler for search_admin_settings - added through hook_form_alter.
+ */
+function node_search_admin_settings_validate($form, &$form_state) {
+ $included_types = $form_state['values']['search_indexed_content_types'];
+ $new_excluded_types = drupal_map_assoc(array_diff(array_keys(node_get_types('names')), $included_types));
+ $old_excluded_types = variable_get('search_excluded_content_types', array());
+
+ // Wipe indexed data for the newly excluded content types
+ $newly_excluded = array_diff($new_excluded_types, $old_excluded_types);
+ if (!empty($newly_excluded)) {
+ $result = db_query('SELECT nid FROM {node} WHERE type IN('. implode(',', array_fill(0, count($newly_excluded), "'%s'")) .')', $newly_excluded);
+ while ($row = db_fetch_array($result)) {
+ search_wipe($row['nid'], 'node');
+ }
+ }
+
+ // If some content types were re-included, the whole index will need to be rebuilt.
+ $newly_included = array_diff($old_excluded_types, $new_excluded_types);
+ if (!empty($newly_included)) {
+ drupal_set_message(t('The index will be rebuilt.'));
+ search_wipe();
+ }
+
+ // What we actually store is the list of excluded content types.
+ unset($form_state['values']['search_indexed_content_types']);
+ $form_state['values']['search_excluded_content_types'] = $new_excluded_types;
+}
+
+/**
* Implementation of hook_user().
*/
function node_user($op, &$edit, &$user) {
@@ -1383,7 +1398,7 @@
}
$filters['type'] = array('title' => t('type'), 'options' => node_get_types('names'));
-
+
// The taxonomy filter
if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
$filters['category'] = array('title' => t('category'), 'options' => $taxonomy);
@@ -2543,12 +2558,19 @@
$last = variable_get('node_cron_last', 0);
$last_nid = variable_get('node_cron_last_nid', 0);
$limit = (int)variable_get('search_cron_limit', 100);
+ $excluded_types = variable_get('search_excluded_content_types', array());
// Store the maximum possible comments per thread (used for ranking by reply count)
variable_set('node_cron_comments_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}'))));
variable_set('node_cron_views_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(totalcount) FROM {node_counter}'))));
- $result = db_query_range('SELECT GREATEST(IF(c.last_comment_timestamp IS NULL, 0, c.last_comment_timestamp), n.changed) as last_change, n.nid FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND ((GREATEST(n.changed, c.last_comment_timestamp) = %d AND n.nid > %d) OR (n.changed > %d OR c.last_comment_timestamp > %d)) ORDER BY GREATEST(n.changed, c.last_comment_timestamp) ASC, n.nid ASC', $last, $last_nid, $last, $last, $last, 0, $limit);
+ $args = array($last, $last_nid, $last, $last, $last);
+ $type_exclude = '';
+ if (!empty($excluded_types)) {
+ $type_exclude = 'n.type NOT IN('. implode(',', array_fill(0, count($excluded_types), "'%s'")) .') AND ';
+ $args = array_merge(array_values($excluded_types), $args);
+ }
+ $result = db_query_range("SELECT GREATEST(IF(c.last_comment_timestamp IS NULL, 0, c.last_comment_timestamp), n.changed) as last_change, n.nid FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE $type_exclude n.status = 1 AND ((GREATEST(n.changed, c.last_comment_timestamp) = %d AND n.nid > %d) OR (n.changed > %d OR c.last_comment_timestamp > %d)) ORDER BY GREATEST(n.changed, c.last_comment_timestamp) ASC, n.nid ASC", $args, 0, $limit);
while ($node = db_fetch_object($result)) {
$last_change = $node->last_change;
@@ -2624,6 +2646,9 @@
// Node types:
$types = node_get_types('names');
+ foreach (variable_get('search_excluded_content_types', array()) as $excluded_type) {
+ unset($types[$excluded_type]);
+ }
$form['advanced']['type'] = array(
'#type' => 'checkboxes',
'#title' => t('Only of the type(s)'),
@@ -2640,6 +2665,48 @@
$form['#validate'][] = 'node_search_validate';
}
+ // Search settings form
+ elseif ($form_id == 'search_admin_settings') {
+ $form['content_indexing'] = array('#type' => 'fieldset', '#title' => t('Content indexing settings'));
+ $form['content_indexing']['info'] = array('#value' => ''. t('Changing the settings below can cause the site index to be rebuilt.') .'');
+
+ // Content indexing is opt-out : the actual setting is a list of
+ // excluded content types, so that newly added content types are
+ // indexed by default.
+ // However, to keep the UI simple, we let the user select the content
+ // types that should be indexed, and store the complement.
+ $excluded_types = variable_get('search_excluded_content_types', array());
+ $included_types = drupal_map_assoc(array_diff(array_keys(node_get_types('names')), $excluded_types));
+ $form['content_indexing']['search_indexed_content_types'] = array(
+ '#type' => 'checkboxes',
+ '#multiple' => TRUE,
+ '#title' => t('Indexed content types'),
+ '#options' => node_get_types('names'),
+ '#default_value' => $included_types,
+ '#description' => t('Unselect a content type to have it excluded from search results.
Excluding a content type will wipe the search index from the corresponding data.
Re-including a content type will cause the whole site index to be rebuilt.'),
+ );
+
+ // Output form for defining rank factor weights.
+ $form['content_ranking'] = array('#type' => 'fieldset', '#title' => t('Content ranking'));
+ $form['content_ranking']['#theme'] = 'node_search_admin';
+ $form['content_ranking']['info'] = array('#value' => ''. t('The following numbers control which properties the content search should favor when ordering the results. Higher numbers mean more influence, zero means the property is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') .'');
+
+ $ranking = array('node_rank_relevance' => t('Keyword relevance'),
+ 'node_rank_recent' => t('Recently posted'));
+ if (module_exists('comment')) {
+ $ranking['node_rank_comments'] = t('Number of comments');
+ }
+ if (module_exists('statistics') && variable_get('statistics_count_content_views', 0)) {
+ $ranking['node_rank_views'] = t('Number of views');
+ }
+
+ // Note: reversed to reflect that higher number = higher ranking.
+ $options = drupal_map_assoc(range(0, 10));
+ foreach ($ranking as $var => $title) {
+ $form['content_ranking']['factors'][$var] = array('#title' => $title, '#type' => 'select', '#options' => $options, '#default_value' => variable_get($var, 5));
+ }
+ $form['#validate'][] = 'node_search_admin_settings_validate';
+ }
}
/**
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.493
diff -u -r1.493 system.module
--- modules/system/system.module 17 Jun 2007 10:49:49 -0000 1.493
+++ modules/system/system.module 17 Jun 2007 17:50:46 -0000
@@ -1250,6 +1250,7 @@
* Add default buttons to a form and set its prefix
*/
function system_settings_form($form) {
+ $form['buttons'] = array('#weight' => 30);
$form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
$form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );