=== modified file 'modules/node/node.module' --- modules/node/node.module +++ modules/node/node.module @@ -910,13 +910,17 @@ function node_last_changed($nid) { */ function node_operations() { $operations = array( - 'approve' => array(t('Approve the selected posts'), 'UPDATE {node} SET status = 1 WHERE nid = %d'), - 'promote' => array(t('Promote the selected posts'), 'UPDATE {node} SET status = 1, promote = 1 WHERE nid = %d'), - 'sticky' => array(t('Make the selected posts sticky'), 'UPDATE {node} SET status = 1, sticky = 1 WHERE nid = %d'), - 'demote' => array(t('Demote the selected posts'), 'UPDATE {node} SET promote = 0 WHERE nid = %d'), - 'unpublish' => array(t('Unpublish the selected posts'), 'UPDATE {node} SET status = 0 WHERE nid = %d'), + 'approve' => array(t('Approve the selected posts'), array('query' => 'UPDATE {node} SET status = 1 WHERE nid = %d')), + 'promote' => array(t('Promote the selected posts'), array('query' => 'UPDATE {node} SET status = 1, promote = 1 WHERE nid = %d')), + 'sticky' => array(t('Make the selected posts sticky'), array('query' => 'UPDATE {node} SET status = 1, sticky = 1 WHERE nid = %d')), + 'demote' => array(t('Demote the selected posts'), array('query' => 'UPDATE {node} SET promote = 0 WHERE nid = %d')), + 'unpublish' => array(t('Unpublish the selected posts'), array('query' => 'UPDATE {node} SET status = 0 WHERE nid = %d')), 'delete' => array(t('Delete the selected posts'), '') ); + // Allow other modules to add mass operations + $extra = module_invoke_all('node_operations'); + $operations = array_merge($operations, $extra); + return $operations; } @@ -1089,16 +1093,47 @@ function node_filter_form_submit() { */ function node_admin_nodes_submit($form_id, $edit) { $operations = node_operations(); - if ($operations[$edit['operation']][1]) { + // Filter out unchecked nodes + $nodes = array_diff($edit['nodes'], array(0)); + $operation = $operations[$edit['operation']][1]; + // Database query operation. + if ($operation['query']) { // Flag changes - $operation = $operations[$edit['operation']][1]; - foreach ($edit['nodes'] as $nid => $value) { - if ($value) { - db_query($operation, $nid); - } + $query = $operation['query']; + foreach ($nodes as $nid) { + db_query($query, $nid); } drupal_set_message(t('The update has been performed.')); } + // Function callback operation. + elseif ($operation['callback']) { + $function = $operation['callback']; + if ($operation['callback arguments']) { + $args = array_merge(array($nodes), $operation['callback arguments']); + } + else { + $args = array($nodes); + } + call_user_func_array($function, $args); + drupal_set_message(t('The update has been performed.')); + } +} + +function node_node_operations() { + global $user; + $operations = array( + 'owner' => array(t('Change ownership to root user'), array('query' => 'UPDATE {node} SET uid = 1 WHERE nid = %d')), + 'print' => array(t('Print title & current user'), array('callback' => 'node_print_title', 'callback arguments' => array($user->name))), + ); + + return $operations; +} + +function node_print_title($nodes, $name) { + foreach ($nodes as $nid) { + $node = node_load($nid); + drupal_set_message("$name: $node->title"); + } } function node_admin_nodes_validate($form_id, $edit) {