You are here

function diff_node_revisions in Diff 7.3

Same name and namespace in other branches
  1. 5.2 diff.module \diff_node_revisions()
  2. 5 diff.module \diff_node_revisions()
  3. 6.2 diff.pages.inc \diff_node_revisions()
  4. 6 diff.module \diff_node_revisions()
  5. 7.2 diff.pages.inc \diff_node_revisions()

Input form to select two revisions.

1 string reference to 'diff_node_revisions'
diff_diffs_overview in ./diff.pages.inc
Menu callback - an overview table of older revisions.

File

./diff.pages.inc, line 35
Menu callbacks for hook_menu().

Code

function diff_node_revisions($form, $form_state, $node) {
  $form['nid'] = array(
    '#type' => 'hidden',
    '#value' => $node->nid,
  );
  $revision_list = diff_node_revision_list($node);
  $revision_count = count($revision_list);
  if ($revision_count > 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($revision_list, 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] = $revision_count;
    $pager_total[0] = ceil($revision_count / 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('delete revisions') || user_access('administer nodes')) && node_access('delete', $node)) {
    $delete_permission = TRUE;
  }
  foreach ($revisions as $revision) {
    $operations = array();
    $revision_ids[$revision->vid] = '';
    $revision_log = $revision->log != '' ? '<p class="revision-log">' . filter_xss($revision->log) . '</p>' : '';
    if ($revision->current_vid > 0) {
      $form['info'][$revision->vid] = array(
        '#markup' => t('!date by !username', array(
          '!date' => l(format_date($revision->timestamp, 'small'), "node/{$node->nid}"),
          '!username' => theme('username', array(
            'account' => $revision,
          )),
        )) . $revision_log,
        '#revision' => $revision,
      );
    }
    else {
      $diff_date = l(format_date($revision->timestamp, 'small'), "node/{$node->nid}/revisions/{$revision->vid}/view");
      $form['info'][$revision->vid] = array(
        '#markup' => t('!date by !username', array(
          '!date' => $diff_date,
          '!username' => theme('username', array(
            'account' => $revision,
          )),
        )) . $revision_log,
        '#revision' => $revision,
      );
      if ($revert_permission) {
        $operations[] = array(
          '#markup' => l(t('Revert'), "node/{$node->nid}/revisions/{$revision->vid}/revert"),
        );
      }
      if ($delete_permission) {
        $operations[] = array(
          '#markup' => 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('Compare'),
  );
  if ($revision_count > REVISION_LIST_SIZE) {
    $form['#suffix'] = theme('pager');
  }
  $form['#attached'] = diff_build_attachments(TRUE);
  return $form;
}