'.t('The recent changes module offers a page which shows all recent changes on nodes. The page can be viewed by anyone with the view revisions permission. If you have the diff module installed, a link to the diff-view will be offered in the table.').'

'; return $output; break; } } /** * Implementation of hook_menu(). */ function recent_changes_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array( 'title' => t('Recent changes'), 'path' => 'recent_changes', 'callback' => 'recent_changes_view', 'access' => user_access('view revisions'), 'type' => MENU_NORMAL_ITEM ); } return $items; } /** * Menu callback which displays a list of recent changes. */ function recent_changes_view() { theme_add_style(drupal_get_path('module', 'recent_changes').'/recent_changes.css'); $output = ''; if (recent_changes_show_filter()) { $form = recent_changes_filter(); $output .= drupal_get_form('recent_changes_filter', $form); } // Use submitted values if filter form was used. if ($_REQUEST['op'] == t('Filter')) { $show_comments = check_plain($_REQUEST['edit']['recent_changes_show_comments']); $node_type = check_plain($_REQUEST['edit']['recent_changes_show_node_type']); } else { $show_comments = recent_changes_show_comments(); $node_type = ''; } $header = array( '', // operations '', // time t('Type'), t('Title'), t('User'), t('Log'), ); $rows = array(); $node_type_query = ''; if ($node_type) { $node_type_query = " WHERE n.type = '$node_type'"; } $revisions_query = "SELECT n.type, r.nid, r.vid, 0 AS cid, r.title, r.timestamp, r.log, r.uid, u.name FROM {node_revisions} r LEFT JOIN {node} n ON r.nid = n.nid LEFT JOIN {users} u ON r.uid = u.uid$node_type_query"; if (module_exist('comment') && $show_comments) { $comments_query = "SELECT n.type, c.nid, 0 AS vid, c.cid, n.title, c.timestamp, c.subject AS log, c.uid, c.name FROM {comments} c LEFT JOIN {node} n ON c.nid = n.nid$node_type_query"; $sql = "($revisions_query) UNION ALL ($comments_query) ORDER BY timestamp DESC"; } else { $sql = "$revisions_query ORDER BY timestamp DESC"; } if ($node_type) { $count_sql = "SELECT (SELECT COUNT(*) FROM {node_revisions} r JOIN {node} n ON r.nid = n.nid $node_type_query) + (SELECT COUNT(*) FROM {comments} c LEFT JOIN {node} n ON c.nid = n.nid $node_type_query)"; } else { /*$count_sql = "SELECT (SELECT COUNT(*) FROM {node_revisions}) + (SELECT COUNT(*) FROM {comments})"*/; $count_sql = "SELECT COUNT(*) FROM {node_revisions}"; } $result = pager_query($sql, RECENT_CHANGES_COUNT, 0, $count_sql); $day = -1; $has_revisions = array(); while ($change = db_fetch_object($result)) { // Check if day changed and if yes output the new day. $current_day = format_date($change->timestamp, 'custom', 'z'); if ($day != $current_day) { $day = $current_day; $rows[] = array( array( 'data' => format_date($change->timestamp, 'custom', 'D, j F Y'), 'colspan' => '6', 'class' => 'date' ) ); } $is_comment = ($change->cid != 0); if ($is_comment) { // Format the row if the change is a comment $rows[] = array( l('(comment)', "node/$change->nid", null, null, "comment-$change->cid"), format_date($change->timestamp, 'custom', 'H:i'), $change->type, l($change->title, "node/$change->nid"), theme('username', $change), filter_xss($change->log), ); } else { // Format the row if the change is a node revision // Check if that node has any revisions at all and cache the result. if (!isset($has_revisions[$change->nid])) { $has_revisions[$change->nid] = db_result(db_query('SELECT COUNT(*) FROM {node_revisions} WHERE nid=%d', $change->nid)) > 1; } $old_node = db_fetch_object(db_query('SELECT vid, title FROM {node_revisions} WHERE nid=%d AND vid<%d ORDER BY vid DESC LIMIT 1', $change->nid, $change->vid)); $operations = ''; // Add a link to the diff between the current version and the one before that. if (module_exist('diff')) { if ($old_node->vid) { $operations .= l('(diff)', "node/$change->nid/revisions/view/$old_node->vid/$change->vid").' '; } else { $operations = '(diff) '; } } // Add a link to the revisions history of the node. if ($has_revisions[$change->nid]) { $operations .= l('(hist)', "node/$change->nid/revisions"); } else { $operations .= '(hist)'; } $special = ''; if ($old_node->vid == 0) { // The node is new. $special = 'new '; } elseif ($old_node->title != $change->title) { // The node title changed. $special = 'moved '; } $rows[] = array( $operations, format_date($change->timestamp, 'custom', 'H:i'), $change->type, $special . l($change->title, "node/$change->nid"), theme('username', $change), filter_xss($change->log), ); } } $output .= theme('table', $header, $rows, array('class' => 'recent-changes')); $output .= theme('pager', NULL, RECENT_CHANGES_COUNT, 0); return $output; } /** * Form for input filter. */ function recent_changes_filter() { $form = array(); $form['#attributes'] = array('class' => 'inline'); if (module_exist('comment')) { $form['recent_changes_show_comments'] = array( '#type' => 'checkbox', '#title' => t('Show comments'), '#default_value' => isset($_REQUEST['edit']['form_id']) ? isset($_REQUEST['edit']['recent_changes_show_comments']) : recent_changes_show_comments(), ); } // node type $node_types = array('' => 'all node types'); $node_types = array_merge($node_types, node_get_types('names')); $form['recent_changes_show_node_type'] = array( '#type' => 'select', '#default_value' => isset($_REQUEST['edit']['recent_changes_show_node_type']) ? $_REQUEST['edit']['recent_changes_show_node_type'] : '', '#options' => $node_types, ); $form['submit'] = array( '#type' => 'button', '#value' => t('Filter') ); return $form; } /** * Is the filter form shown on the recent changes page? */ function recent_changes_show_filter() { return variable_get('recent_changes_show_filter', true); } /** * Are comments shown by default? */ function recent_changes_show_comments() { return variable_get('recent_changes_show_comments', true); }