You are here

function revision_deletion_auto_form in Revision Deletion 6

Same name and namespace in other branches
  1. 5 revision_deletion.module \revision_deletion_auto_form()

Get the list of revisions to auto-delete.

Return value

array containing objects of all revisions.

2 string references to 'revision_deletion_auto_form'
revision_deletion_menu in ./revision_deletion.module
Implementation of hook_menu().
revision_deletion_settings_page in ./revision_deletion.module

File

./revision_deletion.module, line 455
Node Revision Deletion, written by Greg Holsclaw

Code

function revision_deletion_auto_form() {
  drupal_add_css(drupal_get_path('module', 'revision_deletion') . '/revision_deletion.css');
  $form = array();
  $show_conditional = variable_get('revision_delete_list_show_conditional', 1);
  $form['header'] = array(
    '#type' => 'value',
    '#value' => array(
      t('Delete'),
      t('Title'),
      t('Revision ID'),
      t('User'),
      t('Date/Time'),
      t('Type'),
      t('Status'),
    ),
  );
  if ($show_conditional) {
    $form['header']['#value'][] = t('Notes');
  }
  $form['header']['#value'][] = t('Operations');
  $node_types = node_get_types('names');
  $revs = revision_deletion_get_list();
  $prev_nid = 0;
  foreach ($revs as $rev) {
    $vid = $rev->vid;

    // Get user names.
    if (!isset($accounts[$rev->uid])) {
      $acct = user_load(array(
        'uid' => $rev->uid,
      ));
      $accounts[$rev->uid] = theme('username', $acct);
    }

    // Make first title a link to the node.
    $t = '';
    if ($prev_nid != $rev->nid) {
      $t = l($rev->title, 'node/' . $rev->nid, array(
        'title' => t('view !type', array(
          '!type' => $rev->type,
        )),
      ));
      $form['ops'][$vid] = array(
        '#value' => l(t('list revisions'), 'admin/content/revision_deletion/node/' . $rev->nid),
      );
    }

    // Make vid a link to the revision.
    $v = l($rev->vid, 'node/' . $rev->nid . '/revisions/' . $rev->vid . '/view', array(
      'title' => t('view revision'),
    ));

    // Build form elements.
    $form['select'][$vid] = array(
      '#type' => 'checkbox',
      '#default_value' => $rev->select,
      '#disabled' => $vid == $rev->current,
      '#return_value' => array(
        'action' => 'delete',
        'vid' => $vid,
        'nid' => $rev->nid,
        'title' => $rev->title,
        'type' => $rev->type,
      ),
    );
    $form['class'][$vid] = array(
      '#value' => $rev->class,
    );
    $form['title'][$vid] = array(
      '#value' => $t,
    );
    $form['vid'][$vid] = array(
      '#value' => $v,
    );
    $form['user'][$vid] = array(
      '#value' => $accounts[$rev->uid],
    );
    $form['timestamp'][$vid] = array(
      '#value' => format_date($rev->timestamp, 'small'),
    );
    $form['type'][$vid] = array(
      '#value' => $node_types[$rev->type],
    );

    // @TODO: Find free icons for status.
    $form['status'][$vid] = array(
      '#value' => $rev->status ? t('Published') : t('Unpublished'),
    );
    $form['msg'][$vid] = array(
      '#value' => $rev->msgs,
    );
    $form['log'][$vid] = array(
      '#value' => $rev->log,
    );
    $prev_nid = $rev->nid;
  }

  // Add the button and some explanatory text.
  $interval = variable_get('revision_delete_freq', 0);
  $last_update = variable_get('revision_delete_cron', 0);
  $age = variable_get('revision_delete_age', 2419200);
  $keep_current = variable_get('revision_delete_list_keep_current', 1209600);
  $keep_original = variable_get('revision_delete_list_keep_original', 0);
  $keep_date_last = variable_get('revision_delete_list_keep_date_last', 0);
  $form['description'] = array(
    '#value' => '<div class="description">' . t('Click the title to view the current content; click the revision ID to view the revision. Clicking on the "Run Revision Deletion" button will delete all of the selected revisions, even if they are shown on other pages.') . '</div>',
  );

  // Build some informational messages.
  // The values are already 'sanitized.'
  $info_texts = array();
  if ($interval == 0) {
    $auto_msg = t('Automatic deletion is not currently scheduled.');
  }
  else {
    $auto_msg = t('Automatic deletion is scheduled to run every !interval.', array(
      '!interval' => format_interval($interval),
    ));
    if ($last_update) {
      $auto_msg .= ' ' . t('It was last run !last_update_time (!last_update_ago ago).', array(
        '!last_update_time' => format_date($last_update, 'large'),
        '!last_update_ago' => format_interval(time() - $last_update),
      ));
    }
    else {
      $auto_msg .= ' ' . t('It has not yet run automatically.');
    }
  }
  if ($keep_current > 0) {
    $info_texts[] = t('If the current revision was created less than !current_age ago, the next older revision will be kept.', array(
      '!current_age' => format_interval($keep_current),
    ));
  }
  if ($keep_original) {
    $info_texts[] = t('The original revision will be kept.');
  }
  if ($keep_date_last) {
    $info_texts[] = t('The last revision for each date will be kept.');
  }
  if ($age > 0) {
    $info_texts[] = t('It will delete revisions that are older than !age_interval.', array(
      '!age_interval' => format_interval($age),
    ));
  }
  $form['info'] = array(
    '#type' => 'markup',
    '#value' => '<div class="info">' . $auto_msg . '<h5>' . t('Selection Rules') . '</h5>' . theme('item_list', $info_texts) . '</div>',
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Run Revision Deletion'),
  );
  $form['pager'] = array(
    '#value' => theme('pager', array(), $limit),
  );

  // Reuse the other form's submit handler.
  $form['#submit'][] = 'revision_deletion_list_form_submit';
  return $form;
}