function diff_node_revisions in Diff 5.2
Same name and namespace in other branches
- 5 diff.module \diff_node_revisions()
- 6.2 diff.pages.inc \diff_node_revisions()
- 6 diff.module \diff_node_revisions()
- 7.3 diff.pages.inc \diff_node_revisions()
- 7.2 diff.pages.inc \diff_node_revisions()
Input form to select two revisions.
Parameters
$node: Node whose revisions are displayed for selection.
1 string reference to 'diff_node_revisions'
- diff_diffs_overview in ./
diff.module - Generate an overview table of older revisions of a node and provide an input form to select two revisions for a comparison.
File
- ./
diff.module, line 146
Code
function diff_node_revisions(&$node) {
global $form_values;
$form = array();
$form['nid'] = array(
'#type' => 'hidden',
'#value' => $node->nid,
);
$revision_list = node_revision_list($node);
if (count($revision_list) > REVISION_LIST_SIZE) {
// If the list of revisions is longer than the number shown on one page split the array.
$page = isset($_GET['page']) ? $_GET['page'] : '0';
$revision_chunks = array_chunk(node_revision_list($node), REVISION_LIST_SIZE);
$revisions = $revision_chunks[$page];
// Set up global pager variables as would 'pager_query' do.
// These variables are then used in the theme('pager') call later.
global $pager_page_array, $pager_total, $pager_total_items;
$pager_total_items[0] = count($revision_list);
$pager_total[0] = ceil(count($revision_list) / REVISION_LIST_SIZE);
$pager_page_array[0] = max(0, min($page, (int) $pager_total[0] - 1));
}
else {
$revisions = $revision_list;
}
$revert_permission = FALSE;
if ((user_access('revert revisions') || user_access('administer nodes')) && node_access('update', $node)) {
$revert_permission = TRUE;
}
$delete_permission = FALSE;
if (user_access('administer nodes')) {
$delete_permission = TRUE;
}
foreach ($revisions as $revision) {
$operations = array();
$revision_ids[$revision->vid] = '';
if ($revision->current_vid > 0) {
$form['info'][$revision->vid] = array(
'#value' => t('!date by !username', array(
'!date' => l(format_date($revision->timestamp, 'small'), "node/{$node->nid}"),
'!username' => theme('username', $revision),
)) . ($revision->log != '' ? '<p class="revision-log">' . filter_xss($revision->log) . '</p>' : ''),
);
}
else {
$form['info'][$revision->vid] = array(
'#value' => t('!date by !username', array(
'!date' => l(format_date($revision->timestamp, 'small'), "node/{$node->nid}/revisions/{$revision->vid}/view"),
'!username' => theme('username', $revision),
)) . ($revision->log != '' ? '<p class="revision-log">' . filter_xss($revision->log) . '</p>' : ''),
);
if ($revert_permission) {
$operations[] = array(
'#value' => l(t('revert'), "node/{$node->nid}/revisions/{$revision->vid}/revert"),
);
}
if ($delete_permission) {
$operations[] = array(
'#value' => l(t('delete'), "node/{$node->nid}/revisions/{$revision->vid}/delete"),
);
}
// Set a dummy, even if the user has no permission for the other
// operations, so that we can check if the operations array is
// empty to know if the row denotes the current revision.
$operations[] = array();
}
$form['operations'][$revision->vid] = $operations;
}
$new_vid = key($revision_ids);
next($revision_ids);
$old_vid = key($revision_ids);
$form['diff']['old'] = array(
'#type' => 'radios',
'#options' => $revision_ids,
'#default_value' => $old_vid,
);
$form['diff']['new'] = array(
'#type' => 'radios',
'#options' => $revision_ids,
'#default_value' => $new_vid,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Show diff'),
);
if (count($revision_list) > REVISION_LIST_SIZE) {
$form['#suffix'] = theme('pager', NULL, REVISION_LIST_SIZE, 0);
}
return $form;
}