node.admin.inc 23.1 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Content administration and module settings user interface.
6 7
 */

8 9
use Drupal\Core\Database\Query\SelectInterface;

10
/**
11 12
 * Page callback: Form constructor for the permission rebuild confirmation form.
 *
13 14 15
 * @return array
 *   An array as expected by drupal_render().
 *
16
 * @see node_configure_rebuild_confirm_submit()
17
 * @see node_menu()
18
 * @ingroup forms
19 20
 */
function node_configure_rebuild_confirm() {
21
  return confirm_form(array(), t('Are you sure you want to rebuild the permissions on site content?'),
22
                  'admin/reports/status', t('This action rebuilds all permissions on site content, and may be a lengthy process. This action cannot be undone.'), t('Rebuild permissions'), t('Cancel'));
23 24 25
}

/**
26
 * Form submission handler for node_configure_rebuild_confirm().
27
 */
28
function node_configure_rebuild_confirm_submit($form, &$form_state) {
29
  node_access_rebuild(TRUE);
30
  $form_state['redirect'] = 'admin/reports/status';
31 32 33
}

/**
34
 * Implements hook_node_operations().
35 36 37 38
 */
function node_node_operations() {
  $operations = array(
    'publish' => array(
39
      'label' => t('Publish selected content'),
40
      'callback' => 'node_mass_update',
41
      'callback arguments' => array('updates' => array('status' => NODE_PUBLISHED)),
42 43
    ),
    'unpublish' => array(
44
      'label' => t('Unpublish selected content'),
45
      'callback' => 'node_mass_update',
46
      'callback arguments' => array('updates' => array('status' => NODE_NOT_PUBLISHED)),
47 48
    ),
    'promote' => array(
49
      'label' => t('Promote selected content to front page'),
50
      'callback' => 'node_mass_update',
51
      'callback arguments' => array('updates' => array('status' => NODE_PUBLISHED, 'promote' => NODE_PROMOTED)),
52 53
    ),
    'demote' => array(
54
      'label' => t('Demote selected content from front page'),
55
      'callback' => 'node_mass_update',
56
      'callback arguments' => array('updates' => array('promote' => NODE_NOT_PROMOTED)),
57 58
    ),
    'sticky' => array(
59
      'label' => t('Make selected content sticky'),
60
      'callback' => 'node_mass_update',
61
      'callback arguments' => array('updates' => array('status' => NODE_PUBLISHED, 'sticky' => NODE_STICKY)),
62 63
    ),
    'unsticky' => array(
64
      'label' => t('Make selected content not sticky'),
65
      'callback' => 'node_mass_update',
66
      'callback arguments' => array('updates' => array('sticky' => NODE_NOT_STICKY)),
67 68
    ),
    'delete' => array(
69
      'label' => t('Delete selected content'),
70 71 72 73 74 75 76
      'callback' => NULL,
    ),
  );
  return $operations;
}

/**
77 78 79
 * Lists node administration filters that can be applied.
 *
 * @return
80
 *   An associative array of filters.
81 82 83
 */
function node_filters() {
  // Regular filters
84 85 86
  $filters['status'] = array(
    'title' => t('status'),
    'options' => array(
87
      '[any]' => t('any'),
88 89 90 91 92 93 94
      'status-1' => t('published'),
      'status-0' => t('not published'),
      'promote-1' => t('promoted'),
      'promote-0' => t('not promoted'),
      'sticky-1' => t('sticky'),
      'sticky-0' => t('not sticky'),
    ),
95 96 97
  );
  // Include translation states if we have this module enabled
  if (module_exists('translation')) {
98 99 100 101
    $filters['status']['options'] += array(
      'translate-0' => t('Up to date translation'),
      'translate-1' => t('Outdated translation'),
    );
102 103
  }

104 105 106 107 108 109
  $filters['type'] = array(
    'title' => t('type'),
    'options' => array(
      '[any]' => t('any'),
    ) + node_type_get_names(),
  );
110

111
  // Language filter if language support is present.
112
  if (language_multilingual()) {
113
    $languages = language_list(LANGUAGE_ALL);
114
    foreach ($languages as $langcode => $language) {
115 116
      // Make locked languages appear special in the list.
      $language_options[$langcode] = $language->locked ? t('- @name -', array('@name' => $language->name)) : $language->name;
117
    }
118
    $filters['langcode'] = array(
119 120
      'title' => t('language'),
      'options' => array(
121
        '[any]' => t('- Any -'),
122
      ) + $language_options,
123
    );
124 125 126 127 128
  }
  return $filters;
}

/**
129
 * Applies filters for the node administration overview based on session.
130
 *
131
 * @param Drupal\Core\Database\Query\SelectInterface $query
132
 *   A SelectQuery to which the filters should be applied.
133
 */
134
function node_build_filter_query(SelectInterface $query) {
135
  // Build query
136 137
  $filter_data = isset($_SESSION['node_overview_filter']) ? $_SESSION['node_overview_filter'] : array();
  foreach ($filter_data as $index => $filter) {
138 139 140 141 142 143
    list($key, $value) = $filter;
    switch ($key) {
      case 'status':
        // Note: no exploitable hole as $key/$value have already been checked when submitted
        list($key, $value) = explode('-', $value, 2);
      case 'type':
144
      case 'langcode':
145
        $query->condition('n.' . $key, $value);
146
        break;
147 148 149 150 151
    }
  }
}

/**
152
 * Returns the node administration filters form array to node_admin_content().
153 154 155 156 157
 *
 * @see node_admin_nodes()
 * @see node_admin_nodes_submit()
 * @see node_admin_nodes_validate()
 * @see node_filter_form_submit()
158 159 160
 * @see node_multiple_delete_confirm()
 * @see node_multiple_delete_confirm_submit()
 *
161
 * @ingroup forms
162 163
 */
function node_filter_form() {
164
  $session = isset($_SESSION['node_overview_filter']) ? $_SESSION['node_overview_filter'] : array();
165 166 167
  $filters = node_filters();

  $i = 0;
168 169
  $form['filters'] = array(
    '#type' => 'fieldset',
170
    '#title' => t('Show only items where'),
171
    '#theme' => 'exposed_filters__node',
172 173 174
  );
  foreach ($session as $filter) {
    list($type, $value) = $filter;
175
    if ($type == 'term') {
176
      // Load term name from DB rather than search and parse options array.
177
      $value = module_invoke('taxonomy', 'term_load', $value);
178 179
      $value = $value->name;
    }
180
    elseif ($type == 'langcode') {
181
      $value = language_name($value);
182 183 184 185
    }
    else {
      $value = $filters[$type]['options'][$value];
    }
186
    $t_args = array('%property' => $filters[$type]['title'], '%value' => $value);
187
    if ($i++) {
188
      $form['filters']['current'][] = array('#markup' => t('and where %property is %value', $t_args));
189 190
    }
    else {
191
      $form['filters']['current'][] = array('#markup' => t('where %property is %value', $t_args));
192
    }
193
    if (in_array($type, array('type', 'langcode'))) {
194 195 196 197 198
      // Remove the option if it is already being filtered on.
      unset($filters[$type]);
    }
  }

199 200 201 202 203 204 205 206 207
  $form['filters']['status'] = array(
    '#type' => 'container',
    '#attributes' => array('class' => array('clearfix')),
    '#prefix' => ($i ? '<div class="additional-filters">' . t('and where') . '</div>' : ''),
  );
  $form['filters']['status']['filters'] = array(
    '#type' => 'container',
    '#attributes' => array('class' => array('filters')),
  );
208
  foreach ($filters as $key => $filter) {
209
    $form['filters']['status']['filters'][$key] = array(
210 211 212 213 214
      '#type' => 'select',
      '#options' => $filter['options'],
      '#title' => $filter['title'],
      '#default_value' => '[any]',
    );
215 216
  }

217
  $form['filters']['status']['actions'] = array(
218 219
    '#type' => 'actions',
    '#attributes' => array('class' => array('container-inline')),
220
  );
221 222 223 224
  $form['filters']['status']['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => count($session) ? t('Refine') : t('Filter'),
  );
225
  if (count($session)) {
226 227
    $form['filters']['status']['actions']['undo'] = array('#type' => 'submit', '#value' => t('Undo'));
    $form['filters']['status']['actions']['reset'] = array('#type' => 'submit', '#value' => t('Reset'));
228 229
  }

230
  $form['#attached']['library'][] = array('system', 'drupal.form');
231

232 233 234 235
  return $form;
}

/**
236 237 238 239 240 241 242
 * Form submission handler for node_filter_form().
 *
 * @see node_admin_content()
 * @see node_admin_nodes()
 * @see node_admin_nodes_submit()
 * @see node_admin_nodes_validate()
 * @see node_filter_form()
243 244
 * @see node_multiple_delete_confirm()
 * @see node_multiple_delete_confirm_submit()
245 246 247 248 249 250
 */
function node_filter_form_submit($form, &$form_state) {
  $filters = node_filters();
  switch ($form_state['values']['op']) {
    case t('Filter'):
    case t('Refine'):
251 252 253
      // Apply every filter that has a choice selected other than 'any'.
      foreach ($filters as $filter => $options) {
        if (isset($form_state['values'][$filter]) && $form_state['values'][$filter] != '[any]') {
254
          $_SESSION['node_overview_filter'][] = array($filter, $form_state['values'][$filter]);
255 256 257 258 259 260 261
        }
      }
      break;
    case t('Undo'):
      array_pop($_SESSION['node_overview_filter']);
      break;
    case t('Reset'):
262
      $_SESSION['node_overview_filter'] = array();
263 264 265 266
      break;
  }
}

267
/**
268
 * Updates all nodes in the passed-in array with the passed-in field values.
269
 *
270 271 272
 * IMPORTANT NOTE: This function is intended to work when called from a form
 * submission handler. Calling it outside of the form submission process may not
 * work correctly.
273 274 275 276
 *
 * @param array $nodes
 *   Array of node nids to update.
 * @param array $updates
277 278
 *   Array of key/value pairs with node field names and the value to update that
 *   field to.
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
 */
function node_mass_update($nodes, $updates) {
  // We use batch processing to prevent timeout when updating a large number
  // of nodes.
  if (count($nodes) > 10) {
    $batch = array(
      'operations' => array(
        array('_node_mass_update_batch_process', array($nodes, $updates))
      ),
      'finished' => '_node_mass_update_batch_finished',
      'title' => t('Processing'),
      // We use a single multi-pass operation, so the default
      // 'Remaining x of y operations' message will be confusing here.
      'progress_message' => '',
      'error_message' => t('The update has encountered an error.'),
      // The operations do not live in the .module file, so we need to
      // tell the batch engine which file to load before calling them.
296
      'file' => drupal_get_path('module', 'node') . '/node.admin.inc',
297 298 299 300
    );
    batch_set($batch);
  }
  else {
301
    foreach ($nodes as $nid) {
302 303 304 305 306 307 308
      _node_mass_update_helper($nid, $updates);
    }
    drupal_set_message(t('The update has been performed.'));
  }
}

/**
309 310 311 312 313 314 315
 * Updates individual nodes when fewer than 10 are queued.
 *
 * @param $nid
 *   ID of node to update.
 * @param $updates
 *   Associative array of updates.
 *
316 317 318
 * @return object
 *   An updated node object.
 *
319
 * @see node_mass_update()
320 321
 */
function _node_mass_update_helper($nid, $updates) {
322
  $node = node_load($nid, TRUE);
323 324
  // For efficiency manually save the original node before applying any changes.
  $node->original = clone $node;
325 326 327
  foreach ($updates as $name => $value) {
    $node->$name = $value;
  }
328
  $node->save();
329 330 331 332
  return $node;
}

/**
333
 * Executes a batch operation for node_mass_update().
334 335 336 337 338 339 340
 *
 * @param array $nodes
 *   An array of node IDs.
 * @param array $updates
 *   Associative array of updates.
 * @param array $context
 *   An array of contextual key/values.
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
 */
function _node_mass_update_batch_process($nodes, $updates, &$context) {
  if (!isset($context['sandbox']['progress'])) {
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['max'] = count($nodes);
    $context['sandbox']['nodes'] = $nodes;
  }

  // Process nodes by groups of 5.
  $count = min(5, count($context['sandbox']['nodes']));
  for ($i = 1; $i <= $count; $i++) {
    // For each nid, load the node, reset the values, and save it.
    $nid = array_shift($context['sandbox']['nodes']);
    $node = _node_mass_update_helper($nid, $updates);

    // Store result for post-processing in the finished callback.
357
    $context['results'][] = l($node->label(), 'node/' . $node->nid);
358 359 360 361 362 363 364 365 366 367 368 369 370

    // Update our progress information.
    $context['sandbox']['progress']++;
  }

  // Inform the batch engine that we are not finished,
  // and provide an estimation of the completion level we reached.
  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  }
}

/**
371
 * Reports the 'finished' status of batch operation for node_mass_update().
372 373 374 375 376 377 378 379
 *
 * @param bool $success
 *   A boolean indicating whether the batch mass update operation successfully
 *   concluded.
 * @param int $results
 *   The number of nodes updated via the batch mode process.
 * @param array $operations
 *   An array of function calls (not used in this function).
380 381 382 383 384 385 386 387
 */
function _node_mass_update_batch_finished($success, $results, $operations) {
  if ($success) {
    drupal_set_message(t('The update has been performed.'));
  }
  else {
    drupal_set_message(t('An error occurred and processing did not complete.'), 'error');
    $message = format_plural(count($results), '1 item successfully processed:', '@count items successfully processed:');
388
    $message .= theme('item_list', array('items' => $results));
389 390 391 392
    drupal_set_message($message);
  }
}

393
/**
394 395 396 397 398 399 400 401
 * Page callback: Form constructor for the content administration form.
 *
 * @see node_admin_nodes()
 * @see node_admin_nodes_submit()
 * @see node_admin_nodes_validate()
 * @see node_filter_form()
 * @see node_filter_form_submit()
 * @see node_menu()
402 403
 * @see node_multiple_delete_confirm()
 * @see node_multiple_delete_confirm_submit()
404
 * @ingroup forms
405
 */
406
function node_admin_content($form, $form_state) {
407
  if (isset($form_state['values']['operation']) && $form_state['values']['operation'] == 'delete') {
408
    return node_multiple_delete_confirm($form, $form_state, array_filter($form_state['values']['nodes']));
409
  }
410
  $form['filter'] = node_filter_form();
411
  $form['#submit'][] = 'node_filter_form_submit';
412
  $form['admin'] = node_admin_nodes();
413 414 415 416

  return $form;
}

417
/**
418 419 420 421 422 423
 * Returns the admin form object to node_admin_content().
 *
 * @see node_admin_nodes_submit()
 * @see node_admin_nodes_validate()
 * @see node_filter_form()
 * @see node_filter_form_submit()
424 425 426
 * @see node_multiple_delete_confirm()
 * @see node_multiple_delete_confirm_submit()
 *
427
 * @ingroup forms
428
 */
429
function node_admin_nodes() {
430
  $admin_access = user_access('administer nodes');
431

432
  // Build the 'Update options' form.
433 434
  $form['options'] = array(
    '#type' => 'fieldset',
435
    '#title' => t('Update options'),
436
    '#attributes' => array('class' => array('container-inline')),
437
    '#access' => $admin_access,
438 439 440
    '#attached' => array (
      'css' => array(drupal_get_path('module', 'node') . '/node.admin.css'),
    ),
441 442 443 444 445
  );
  $options = array();
  foreach (module_invoke_all('node_operations') as $operation => $array) {
    $options[$operation] = $array['label'];
  }
446 447
  $form['options']['operation'] = array(
    '#type' => 'select',
448 449
    '#title' => t('Operation'),
    '#title_display' => 'invisible',
450 451 452
    '#options' => $options,
    '#default_value' => 'approve',
  );
453 454 455
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
456
    '#validate' => array('node_admin_nodes_validate'),
457
    '#submit' => array('node_admin_nodes_submit'),
458 459
  );

460 461
  // Enable language column and filter if multiple languages are enabled.
  $multilingual = language_multilingual();
462 463 464

  // Build the sortable table header.
  $header = array(
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
    'title' => array(
      'data' => t('Title'),
      'field' => 'n.title',
    ),
    'type' => array(
      'data' => t('Content type'),
      'field' => 'n.type',
      'class' => array(RESPONSIVE_PRIORITY_MEDIUM),
    ),
    'author' => array(
      'data' => t('Author'),
      'class' => array(RESPONSIVE_PRIORITY_LOW),
    ),
    'status' => array(
      'data' => t('Status'),
      'field' => 'n.status',
    ),
    'changed' => array(
      'data' => t('Updated'),
      'field' => 'n.changed',
      'sort' => 'desc',
      'class' => array(RESPONSIVE_PRIORITY_LOW)
    ,)
488
  );
489
  if ($multilingual) {
490
    $header['language_name'] = array('data' => t('Language'), 'field' => 'n.langcode', 'class' => array(RESPONSIVE_PRIORITY_LOW));
491 492 493
  }
  $header['operations'] = array('data' => t('Operations'));

494 495
  $query = db_select('node', 'n')
    ->extend('Drupal\Core\Database\Query\PagerSelectExtender')
496
    ->extend('Drupal\Core\Database\Query\TableSortExtender');
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
  node_build_filter_query($query);

  if (!user_access('bypass node access')) {
    // If the user is able to view their own unpublished nodes, allow them
    // to see these in addition to published nodes. Check that they actually
    // have some unpublished nodes to view before adding the condition.
    if (user_access('view own unpublished content') && $own_unpublished = db_query('SELECT nid FROM {node} WHERE uid = :uid AND status = :status', array(':uid' => $GLOBALS['user']->uid, ':status' => 0))->fetchCol()) {
      $query->condition(db_or()
        ->condition('n.status', 1)
        ->condition('n.nid', $own_unpublished, 'IN')
      );
    }
    else {
      // If not, restrict the query to published nodes.
      $query->condition('n.status', 1);
    }
  }
  $nids = $query
    ->fields('n',array('nid'))
    ->limit(50)
    ->orderByHeader($header)
518
    ->addTag('node_access')
519 520 521 522 523
    ->execute()
    ->fetchCol();
  $nodes = node_load_multiple($nids);

  // Prepare the list of nodes.
524
  $languages = language_list(LANGUAGE_ALL);
525
  $destination = drupal_get_destination();
526 527
  $options = array();
  foreach ($nodes as $node) {
528
    $l_options = $node->langcode != LANGUAGE_NOT_SPECIFIED && isset($languages[$node->langcode]) ? array('language' => $languages[$node->langcode]) : array();
529
    $options[$node->nid] = array(
530 531 532
      'title' => array(
        'data' => array(
          '#type' => 'link',
533
          '#title' => $node->label(),
534 535 536 537 538
          '#href' => 'node/' . $node->nid,
          '#options' => $l_options,
          '#suffix' => ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed))),
        ),
      ),
539
      'type' => check_plain(node_get_type_label($node)),
540
      'author' => theme('username', array('account' => $node)),
541
      'status' => $node->status ? t('published') : t('not published'),
542 543
      'changed' => format_date($node->changed, 'short'),
    );
544
    if ($multilingual) {
545
      $options[$node->nid]['language_name'] = language_name($node->langcode);
546
    }
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
    // Build a list of all the accessible operations for the current node.
    $operations = array();
    if (node_access('update', $node)) {
      $operations['edit'] = array(
        'title' => t('edit'),
        'href' => 'node/' . $node->nid . '/edit',
        'query' => $destination,
      );
    }
    if (node_access('delete', $node)) {
      $operations['delete'] = array(
        'title' => t('delete'),
        'href' => 'node/' . $node->nid . '/delete',
        'query' => $destination,
      );
    }
    $options[$node->nid]['operations'] = array();
    if (count($operations) > 1) {
      // Render an unordered list of operations links.
      $options[$node->nid]['operations'] = array(
        'data' => array(
568 569
          '#type' => 'operations',
          '#subtype' => 'node',
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
          '#links' => $operations,
        ),
      );
    }
    elseif (!empty($operations)) {
      // Render the first and only operation as a link.
      $link = reset($operations);
      $options[$node->nid]['operations'] = array(
        'data' => array(
          '#type' => 'link',
          '#title' => $link['title'],
          '#href' => $link['href'],
          '#options' => array('query' => $link['query']),
        ),
      );
    }
  }

  // Only use a tableselect when the current user is able to perform any
  // operations.
  if ($admin_access) {
    $form['nodes'] = array(
      '#type' => 'tableselect',
      '#header' => $header,
      '#options' => $options,
      '#empty' => t('No content available.'),
596
    );
597
  }
598 599 600 601 602 603
  // Otherwise, use a simple table.
  else {
    $form['nodes'] = array(
      '#theme' => 'table',
      '#header' => $header,
      '#rows' => $options,
604
      '#empty' => t('No content available.'),
605 606 607
    );
  }

608
  $form['pager'] = array('#markup' => theme('pager'));
609 610 611
  return $form;
}

612
/**
613
 * Form validation handler for node_admin_nodes().
614
 *
615 616
 * Checks whether any nodes have been selected to perform the chosen 'Update
 * option' on.
617 618 619 620 621
 *
 * @see node_admin_nodes()
 * @see node_admin_nodes_submit()
 * @see node_filter_form()
 * @see node_filter_form_submit()
622 623
 * @see node_multiple_delete_confirm()
 * @see node_multiple_delete_confirm_submit()
624 625
 */
function node_admin_nodes_validate($form, &$form_state) {
626 627
  // Error if there are no items to select.
  if (!is_array($form_state['values']['nodes']) || !count(array_filter($form_state['values']['nodes']))) {
628 629 630 631 632
    form_set_error('', t('No items selected.'));
  }
}

/**
633 634 635
 * Form submission handler for node_admin_nodes().
 *
 * Executes the chosen 'Update option' on the selected nodes.
636
 *
637 638 639 640
 * @see node_admin_nodes()
 * @see node_admin_nodes_validate()
 * @see node_filter_form()
 * @see node_filter_form_submit()
641 642
 * @see node_multiple_delete_confirm()
 * @see node_multiple_delete_confirm_submit()
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
 */
function node_admin_nodes_submit($form, &$form_state) {
  $operations = module_invoke_all('node_operations');
  $operation = $operations[$form_state['values']['operation']];
  // Filter out unchecked nodes
  $nodes = array_filter($form_state['values']['nodes']);
  if ($function = $operation['callback']) {
    // Add in callback arguments if present.
    if (isset($operation['callback arguments'])) {
      $args = array_merge(array($nodes), $operation['callback arguments']);
    }
    else {
      $args = array($nodes);
    }
    call_user_func_array($function, $args);

659
    cache_invalidate(array('content' => TRUE));
660 661
  }
  else {
662
    // We need to rebuild the form to go to a second step. For example, to
663 664 665 666 667
    // show the confirmation form for the deletion of nodes.
    $form_state['rebuild'] = TRUE;
  }
}

668 669 670 671 672 673 674 675
/**
 * Multiple node deletion confirmation form for node_admin_content().
 *
 * @see node_admin_nodes()
 * @see node_admin_nodes_submit()
 * @see node_admin_nodes_validate()
 * @see node_filter_form()
 * @see node_filter_form_submit()
676
 * @see node_multiple_delete_confirm_submit()
677
 * @ingroup forms
678
 */
679
function node_multiple_delete_confirm($form, &$form_state, $nodes) {
680 681 682
  $form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
  // array_filter returns only elements with TRUE values
  foreach ($nodes as $nid => $value) {
683
    $title = db_query('SELECT title FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchField();
684 685 686 687
    $form['nodes'][$nid] = array(
      '#type' => 'hidden',
      '#value' => $nid,
      '#prefix' => '<li>',
688
      '#suffix' => check_plain($title) . "</li>\n",
689
    );
690 691 692
  }
  $form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
  $form['#submit'][] = 'node_multiple_delete_confirm_submit';
693 694
  $confirm_question = format_plural(count($nodes),
                                  'Are you sure you want to delete this item?',
695
                                  'Are you sure you want to delete these items?');
696
  return confirm_form($form,
697
                    $confirm_question,
698
                    'admin/content', t('This action cannot be undone.'),
699
                    t('Delete'), t('Cancel'));
700 701
}

702 703 704 705 706 707 708 709
/**
 * Form submission handler for node_multiple_delete_confirm().
 *
 * @see node_admin_nodes()
 * @see node_admin_nodes_submit()
 * @see node_admin_nodes_validate()
 * @see node_filter_form()
 * @see node_filter_form_submit()
710
 * @see node_multiple_delete_confirm()
711
 */
712 713
function node_multiple_delete_confirm_submit($form, &$form_state) {
  if ($form_state['values']['confirm']) {
714 715 716
    node_delete_multiple(array_keys($form_state['values']['nodes']));
    $count = count($form_state['values']['nodes']);
    watchdog('content', 'Deleted @count posts.', array('@count' => $count));
717
    drupal_set_message(format_plural($count, 'Deleted 1 post.', 'Deleted @count posts.'));
718
  }
719
  $form_state['redirect'] = 'admin/content';
720
}