Commit baaf319c authored by Dries's avatar Dries

- Patch #42072 by m3avrck: improved the revision overview screen.

parent e828470b
......@@ -524,7 +524,7 @@ function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) {
$node->body = str_replace('<!--break-->', '', $node->body);
if ($node->log != '' && !$teaser && $node->moderate) {
$node->body .= '<div class="log"><div class="title">'. t('Log') .':</div>'. $node->log .'</div>';
$node->body .= '<div class="log"><div class="title">'. t('Log') .':</div>'. check_plain($node->log) .'</div>';
}
// The 'view' hook can be implemented to overwrite the default function
......@@ -585,7 +585,7 @@ function node_show($node, $cid) {
* Implementation of hook_perm().
*/
function node_perm() {
return array('administer nodes', 'access content', 'view revisions', 'roll back revisions');
return array('administer nodes', 'access content', 'view revisions', 'revert revisions');
}
/**
......@@ -1270,51 +1270,41 @@ function node_types_configure($type = NULL) {
function node_revision_overview($node) {
drupal_set_title(t('Revisions for %title', array('%title' => check_plain($node->title))));
$header = array('', t('Author'), t('Title'), t('Date'), array('colspan' => '3', 'data' => t('Operations')));
$header = array(t('Revision'), array('data' => t('Operations'), 'colspan' => 2));
$revisions = node_revision_list($node);
$i = 0;
$rows = array();
$roll_back_permission = FALSE;
if ((user_access('roll back revisions') || user_access('administer nodes')) && node_access('update', $node)) {
$roll_back_permission = TRUE;
$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) {
$row = array();
$operations = array();
if ($revision->current_vid > 0) {
$current_row = array(
array('data' => ++$i .' '. t('(current)'), 'rowspan' => ($revision->log != '') ? 2 : 1),
theme('username', $revision),
check_plain($revision->title),
format_date($revision->timestamp, 'small'),
l(t('view'), "node/$node->nid"));
if (node_access('update', $node)) {
$current_row[] = l(t('edit'), "node/$node->nid/edit");
}
$rows[] = array_pad($current_row, 7, '');
$row[] = array('data' => 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">'. check_plain($revision->log) .'</p>' : ''),
'class' => 'revision-current');
$operations[] = array('data' => theme('placeholder', t('current revision')), 'class' => 'revision-current', 'colspan' => 2);
}
else {
$current_row = array(
array('data' => ++$i, 'rowspan' => ($revision->log != '') ? 2 : 1),
theme('username', $revision),
check_plain($revision->title),
format_date($revision->timestamp, 'small'),
l(t('view'), "node/$node->nid/revisions/$revision->vid/view"));
if ($roll_back_permission) {
$current_row[] = l(t('set active'), "node/$node->nid/revisions/$revision->vid/rollback");
$row[] = 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">'. check_plain($revision->log) .'</p>' : '');
if ($revert_permission) {
$operations[] = l(t('revert'), "node/$node->nid/revisions/$revision->vid/revert");
}
if ($delete_permission) {
$current_row[] = l(t('delete'), "node/$node->nid/revisions/$revision->vid/delete");
$operations[] = l(t('delete'), "node/$node->nid/revisions/$revision->vid/delete");
}
$rows[] = array_pad($current_row, 7, '');
}
if ($revision->log != '') {
$rows[] = array(array('data' => $revision->log, 'colspan' => 7));
}
$rows[] = array_merge($row, $operations);
}
$output .= theme('table', $header, $rows);
......@@ -1322,22 +1312,23 @@ function node_revision_overview($node) {
}
/**
* Roll back to the revision with the specified revision number.
* Revert to the revision with the specified revision number.
*/
function node_revision_rollback($nid, $revision) {
function node_revision_revert($nid, $revision) {
global $user;
$node = node_load($nid, $revision);
if ((user_access('roll back revisions') || user_access('administer nodes')) && node_access('update', $node)) {
if ((user_access('revert revisions') || user_access('administer nodes')) && node_access('update', $node)) {
if ($node->vid) {
$node->revision = 1;
$node->log = t('Copy of the revision from %date.', array('%date' => theme('placeholder', format_date($node->revision_timestamp))));
$new_node = node_save($node);
drupal_set_message(t('%title has been rolled back to the revision from %revision-date', array('%revision-date' => theme('placeholder', format_date($node->revision_timestamp)), '%title' => theme('placeholder', check_plain($node->title)))));
drupal_set_message(t('%title has been reverted back to the revision from %revision-date', array('%revision-date' => theme('placeholder', format_date($node->revision_timestamp)), '%title' => theme('placeholder', check_plain($node->title)))));
watchdog('content', t('%type: reverted %title revision %revision.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $revision))));
}
else {
drupal_set_message(t('You tried to roll back to an invalid revision.'), 'error');
drupal_set_message(t('You tried to revert to an invalid revision.'), 'error');
}
drupal_goto('node/'. $nid .'/revisions');
}
......@@ -1377,7 +1368,7 @@ function node_revision_delete($nid, $revision) {
*/
function node_revision_list($node) {
$revisions = array();
$result = db_query('SELECT r.vid, r.title, r.log, r.uid, n.vid AS current_vid, r.timestamp, u.name FROM {node_revisions} r LEFT JOIN {node} n ON n.vid = r.vid INNER JOIN {users} u ON u.uid = r.uid WHERE r.nid = %d ORDER BY r.timestamp ASC', $node->nid);
$result = db_query('SELECT r.vid, r.title, r.log, r.uid, n.vid AS current_vid, r.timestamp, u.name FROM {node_revisions} r LEFT JOIN {node} n ON n.vid = r.vid INNER JOIN {users} u ON u.uid = r.uid WHERE r.nid = %d ORDER BY r.timestamp DESC', $node->nid);
while ($revision = db_fetch_object($result)) {
$revisions[] = $revision;
}
......@@ -1973,8 +1964,8 @@ function node_revisions() {
}
drupal_not_found();
break;
case 'rollback':
node_revision_rollback(arg(1), arg(3));
case 'revert':
node_revision_revert(arg(1), arg(3));
break;
case 'delete':
node_revision_delete(arg(1), arg(3));
......
......@@ -524,7 +524,7 @@ function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) {
$node->body = str_replace('<!--break-->', '', $node->body);
if ($node->log != '' && !$teaser && $node->moderate) {
$node->body .= '<div class="log"><div class="title">'. t('Log') .':</div>'. $node->log .'</div>';
$node->body .= '<div class="log"><div class="title">'. t('Log') .':</div>'. check_plain($node->log) .'</div>';
}
// The 'view' hook can be implemented to overwrite the default function
......@@ -585,7 +585,7 @@ function node_show($node, $cid) {
* Implementation of hook_perm().
*/
function node_perm() {
return array('administer nodes', 'access content', 'view revisions', 'roll back revisions');
return array('administer nodes', 'access content', 'view revisions', 'revert revisions');
}
/**
......@@ -1270,51 +1270,41 @@ function node_types_configure($type = NULL) {
function node_revision_overview($node) {
drupal_set_title(t('Revisions for %title', array('%title' => check_plain($node->title))));
$header = array('', t('Author'), t('Title'), t('Date'), array('colspan' => '3', 'data' => t('Operations')));
$header = array(t('Revision'), array('data' => t('Operations'), 'colspan' => 2));
$revisions = node_revision_list($node);
$i = 0;
$rows = array();
$roll_back_permission = FALSE;
if ((user_access('roll back revisions') || user_access('administer nodes')) && node_access('update', $node)) {
$roll_back_permission = TRUE;
$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) {
$row = array();
$operations = array();
if ($revision->current_vid > 0) {
$current_row = array(
array('data' => ++$i .' '. t('(current)'), 'rowspan' => ($revision->log != '') ? 2 : 1),
theme('username', $revision),
check_plain($revision->title),
format_date($revision->timestamp, 'small'),
l(t('view'), "node/$node->nid"));
if (node_access('update', $node)) {
$current_row[] = l(t('edit'), "node/$node->nid/edit");
}
$rows[] = array_pad($current_row, 7, '');
$row[] = array('data' => 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">'. check_plain($revision->log) .'</p>' : ''),
'class' => 'revision-current');
$operations[] = array('data' => theme('placeholder', t('current revision')), 'class' => 'revision-current', 'colspan' => 2);
}
else {
$current_row = array(
array('data' => ++$i, 'rowspan' => ($revision->log != '') ? 2 : 1),
theme('username', $revision),
check_plain($revision->title),
format_date($revision->timestamp, 'small'),
l(t('view'), "node/$node->nid/revisions/$revision->vid/view"));
if ($roll_back_permission) {
$current_row[] = l(t('set active'), "node/$node->nid/revisions/$revision->vid/rollback");
$row[] = 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">'. check_plain($revision->log) .'</p>' : '');
if ($revert_permission) {
$operations[] = l(t('revert'), "node/$node->nid/revisions/$revision->vid/revert");
}
if ($delete_permission) {
$current_row[] = l(t('delete'), "node/$node->nid/revisions/$revision->vid/delete");
$operations[] = l(t('delete'), "node/$node->nid/revisions/$revision->vid/delete");
}
$rows[] = array_pad($current_row, 7, '');
}
if ($revision->log != '') {
$rows[] = array(array('data' => $revision->log, 'colspan' => 7));
}
$rows[] = array_merge($row, $operations);
}
$output .= theme('table', $header, $rows);
......@@ -1322,22 +1312,23 @@ function node_revision_overview($node) {
}
/**
* Roll back to the revision with the specified revision number.
* Revert to the revision with the specified revision number.
*/
function node_revision_rollback($nid, $revision) {
function node_revision_revert($nid, $revision) {
global $user;
$node = node_load($nid, $revision);
if ((user_access('roll back revisions') || user_access('administer nodes')) && node_access('update', $node)) {
if ((user_access('revert revisions') || user_access('administer nodes')) && node_access('update', $node)) {
if ($node->vid) {
$node->revision = 1;
$node->log = t('Copy of the revision from %date.', array('%date' => theme('placeholder', format_date($node->revision_timestamp))));
$new_node = node_save($node);
drupal_set_message(t('%title has been rolled back to the revision from %revision-date', array('%revision-date' => theme('placeholder', format_date($node->revision_timestamp)), '%title' => theme('placeholder', check_plain($node->title)))));
drupal_set_message(t('%title has been reverted back to the revision from %revision-date', array('%revision-date' => theme('placeholder', format_date($node->revision_timestamp)), '%title' => theme('placeholder', check_plain($node->title)))));
watchdog('content', t('%type: reverted %title revision %revision.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title), '%revision' => theme('placeholder', $revision))));
}
else {
drupal_set_message(t('You tried to roll back to an invalid revision.'), 'error');
drupal_set_message(t('You tried to revert to an invalid revision.'), 'error');
}
drupal_goto('node/'. $nid .'/revisions');
}
......@@ -1377,7 +1368,7 @@ function node_revision_delete($nid, $revision) {
*/
function node_revision_list($node) {
$revisions = array();
$result = db_query('SELECT r.vid, r.title, r.log, r.uid, n.vid AS current_vid, r.timestamp, u.name FROM {node_revisions} r LEFT JOIN {node} n ON n.vid = r.vid INNER JOIN {users} u ON u.uid = r.uid WHERE r.nid = %d ORDER BY r.timestamp ASC', $node->nid);
$result = db_query('SELECT r.vid, r.title, r.log, r.uid, n.vid AS current_vid, r.timestamp, u.name FROM {node_revisions} r LEFT JOIN {node} n ON n.vid = r.vid INNER JOIN {users} u ON u.uid = r.uid WHERE r.nid = %d ORDER BY r.timestamp DESC', $node->nid);
while ($revision = db_fetch_object($result)) {
$revisions[] = $revision;
}
......@@ -1973,8 +1964,8 @@ function node_revisions() {
}
drupal_not_found();
break;
case 'rollback':
node_revision_rollback(arg(1), arg(3));
case 'revert':
node_revision_revert(arg(1), arg(3));
break;
case 'delete':
node_revision_delete(arg(1), arg(3));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment