Page callback: Generates an overview table of older revisions of a node.
object $node: A node object.
array An array as expected by drupal_render().
function node_revision_overview($node) {
drupal_set_title(t('Revisions for %title', array(
'%title' => $node
->label(),
)), PASS_THROUGH);
$header = array(
t('Revision'),
t('Operations'),
);
$revisions = node_revision_list($node);
$rows = array();
$type = $node->type;
$revert_permission = FALSE;
if ((user_access("revert {$type} revisions") || user_access('revert all revisions') || user_access('administer nodes')) && node_access('update', $node)) {
$revert_permission = TRUE;
}
$delete_permission = FALSE;
if ((user_access("delete {$type} revisions") || user_access('delete all revisions') || user_access('administer nodes')) && node_access('delete', $node)) {
$delete_permission = TRUE;
}
foreach ($revisions as $revision) {
$row = array();
$type = $node->type;
if ($revision->current_vid > 0) {
$row[] = array(
'data' => t('!date by !username', array(
'!date' => l(format_date($revision->timestamp, 'short'), "node/{$node->nid}"),
'!username' => theme('username', array(
'account' => $revision,
)),
)) . ($revision->log != '' ? '<p class="revision-log">' . filter_xss($revision->log) . '</p>' : ''),
'class' => array(
'revision-current',
),
);
$row[] = array(
'data' => drupal_placeholder(t('current revision')),
'class' => array(
'revision-current',
),
);
}
else {
$row[] = t('!date by !username', array(
'!date' => l(format_date($revision->timestamp, 'short'), "node/{$node->nid}/revisions/{$revision->vid}/view"),
'!username' => theme('username', array(
'account' => $revision,
)),
)) . ($revision->log != '' ? '<p class="revision-log">' . filter_xss($revision->log) . '</p>' : '');
if ($revert_permission) {
$links['revert'] = array(
'title' => t('revert'),
'href' => "node/{$node->nid}/revisions/{$revision->vid}/revert",
);
}
if ($delete_permission) {
$links['delete'] = array(
'title' => t('delete'),
'href' => "node/{$node->nid}/revisions/{$revision->vid}/delete",
);
}
$row[] = array(
'data' => array(
'#type' => 'operations',
'#links' => $links,
),
);
}
$rows[] = $row;
}
$build['node_revisions_table'] = array(
'#theme' => 'table',
'#rows' => $rows,
'#header' => $header,
'#attached' => array(
'css' => array(
drupal_get_path('module', 'node') . '/node.admin.css',
),
),
);
return $build;
}