Skip to content
Snippets Groups Projects
Commit baaf319c authored by Dries Buytaert's avatar Dries Buytaert
Browse files

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

parent e828470b
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -524,7 +524,7 @@ function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) { ...@@ -524,7 +524,7 @@ function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) {
$node->body = str_replace('<!--break-->', '', $node->body); $node->body = str_replace('<!--break-->', '', $node->body);
if ($node->log != '' && !$teaser && $node->moderate) { 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 // The 'view' hook can be implemented to overwrite the default function
...@@ -585,7 +585,7 @@ function node_show($node, $cid) { ...@@ -585,7 +585,7 @@ function node_show($node, $cid) {
* Implementation of hook_perm(). * Implementation of hook_perm().
*/ */
function node_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) { ...@@ -1270,51 +1270,41 @@ function node_types_configure($type = NULL) {
function node_revision_overview($node) { function node_revision_overview($node) {
drupal_set_title(t('Revisions for %title', array('%title' => check_plain($node->title)))); 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); $revisions = node_revision_list($node);
$i = 0; $i = 0;
$rows = array(); $rows = array();
$roll_back_permission = FALSE; $revert_permission = FALSE;
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)) {
$roll_back_permission = TRUE; $revert_permission = TRUE;
} }
$delete_permission = FALSE; $delete_permission = FALSE;
if (user_access('administer nodes')) { if (user_access('administer nodes')) {
$delete_permission = TRUE; $delete_permission = TRUE;
} }
foreach ($revisions as $revision) { foreach ($revisions as $revision) {
$row = array();
$operations = array();
if ($revision->current_vid > 0) { if ($revision->current_vid > 0) {
$current_row = array( $row[] = array('data' => t('%date by %username', array('%date' => l(format_date($revision->timestamp, 'small'), "node/$node->nid"), '%username' => theme('username', $revision)))
array('data' => ++$i .' '. t('(current)'), 'rowspan' => ($revision->log != '') ? 2 : 1), . (($revision->log != '') ? '<p class="revision-log">'. check_plain($revision->log) .'</p>' : ''),
theme('username', $revision), 'class' => 'revision-current');
check_plain($revision->title), $operations[] = array('data' => theme('placeholder', t('current revision')), 'class' => 'revision-current', 'colspan' => 2);
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, '');
} }
else { else {
$current_row = array( $row[] = t('%date by %username', array('%date' => l(format_date($revision->timestamp, 'small'), "node/$node->nid/revisions/$revision->vid/view"), '%username' => theme('username', $revision)))
array('data' => ++$i, 'rowspan' => ($revision->log != '') ? 2 : 1), . (($revision->log != '') ? '<p class="revision-log">'. check_plain($revision->log) .'</p>' : '');
theme('username', $revision), if ($revert_permission) {
check_plain($revision->title), $operations[] = l(t('revert'), "node/$node->nid/revisions/$revision->vid/revert");
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");
} }
if ($delete_permission) { 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); $output .= theme('table', $header, $rows);
...@@ -1322,22 +1312,23 @@ function node_revision_overview($node) { ...@@ -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; global $user;
$node = node_load($nid, $revision); $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) { if ($node->vid) {
$node->revision = 1; $node->revision = 1;
$node->log = t('Copy of the revision from %date.', array('%date' => theme('placeholder', format_date($node->revision_timestamp)))); $node->log = t('Copy of the revision from %date.', array('%date' => theme('placeholder', format_date($node->revision_timestamp))));
$new_node = node_save($node); $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 { 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'); drupal_goto('node/'. $nid .'/revisions');
} }
...@@ -1377,7 +1368,7 @@ function node_revision_delete($nid, $revision) { ...@@ -1377,7 +1368,7 @@ function node_revision_delete($nid, $revision) {
*/ */
function node_revision_list($node) { function node_revision_list($node) {
$revisions = array(); $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)) { while ($revision = db_fetch_object($result)) {
$revisions[] = $revision; $revisions[] = $revision;
} }
...@@ -1973,8 +1964,8 @@ function node_revisions() { ...@@ -1973,8 +1964,8 @@ function node_revisions() {
} }
drupal_not_found(); drupal_not_found();
break; break;
case 'rollback': case 'revert':
node_revision_rollback(arg(1), arg(3)); node_revision_revert(arg(1), arg(3));
break; break;
case 'delete': case 'delete':
node_revision_delete(arg(1), arg(3)); node_revision_delete(arg(1), arg(3));
......
...@@ -524,7 +524,7 @@ function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) { ...@@ -524,7 +524,7 @@ function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) {
$node->body = str_replace('<!--break-->', '', $node->body); $node->body = str_replace('<!--break-->', '', $node->body);
if ($node->log != '' && !$teaser && $node->moderate) { 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 // The 'view' hook can be implemented to overwrite the default function
...@@ -585,7 +585,7 @@ function node_show($node, $cid) { ...@@ -585,7 +585,7 @@ function node_show($node, $cid) {
* Implementation of hook_perm(). * Implementation of hook_perm().
*/ */
function node_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) { ...@@ -1270,51 +1270,41 @@ function node_types_configure($type = NULL) {
function node_revision_overview($node) { function node_revision_overview($node) {
drupal_set_title(t('Revisions for %title', array('%title' => check_plain($node->title)))); 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); $revisions = node_revision_list($node);
$i = 0; $i = 0;
$rows = array(); $rows = array();
$roll_back_permission = FALSE; $revert_permission = FALSE;
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)) {
$roll_back_permission = TRUE; $revert_permission = TRUE;
} }
$delete_permission = FALSE; $delete_permission = FALSE;
if (user_access('administer nodes')) { if (user_access('administer nodes')) {
$delete_permission = TRUE; $delete_permission = TRUE;
} }
foreach ($revisions as $revision) { foreach ($revisions as $revision) {
$row = array();
$operations = array();
if ($revision->current_vid > 0) { if ($revision->current_vid > 0) {
$current_row = array( $row[] = array('data' => t('%date by %username', array('%date' => l(format_date($revision->timestamp, 'small'), "node/$node->nid"), '%username' => theme('username', $revision)))
array('data' => ++$i .' '. t('(current)'), 'rowspan' => ($revision->log != '') ? 2 : 1), . (($revision->log != '') ? '<p class="revision-log">'. check_plain($revision->log) .'</p>' : ''),
theme('username', $revision), 'class' => 'revision-current');
check_plain($revision->title), $operations[] = array('data' => theme('placeholder', t('current revision')), 'class' => 'revision-current', 'colspan' => 2);
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, '');
} }
else { else {
$current_row = array( $row[] = t('%date by %username', array('%date' => l(format_date($revision->timestamp, 'small'), "node/$node->nid/revisions/$revision->vid/view"), '%username' => theme('username', $revision)))
array('data' => ++$i, 'rowspan' => ($revision->log != '') ? 2 : 1), . (($revision->log != '') ? '<p class="revision-log">'. check_plain($revision->log) .'</p>' : '');
theme('username', $revision), if ($revert_permission) {
check_plain($revision->title), $operations[] = l(t('revert'), "node/$node->nid/revisions/$revision->vid/revert");
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");
} }
if ($delete_permission) { 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); $output .= theme('table', $header, $rows);
...@@ -1322,22 +1312,23 @@ function node_revision_overview($node) { ...@@ -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; global $user;
$node = node_load($nid, $revision); $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) { if ($node->vid) {
$node->revision = 1; $node->revision = 1;
$node->log = t('Copy of the revision from %date.', array('%date' => theme('placeholder', format_date($node->revision_timestamp)))); $node->log = t('Copy of the revision from %date.', array('%date' => theme('placeholder', format_date($node->revision_timestamp))));
$new_node = node_save($node); $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 { 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'); drupal_goto('node/'. $nid .'/revisions');
} }
...@@ -1377,7 +1368,7 @@ function node_revision_delete($nid, $revision) { ...@@ -1377,7 +1368,7 @@ function node_revision_delete($nid, $revision) {
*/ */
function node_revision_list($node) { function node_revision_list($node) {
$revisions = array(); $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)) { while ($revision = db_fetch_object($result)) {
$revisions[] = $revision; $revisions[] = $revision;
} }
...@@ -1973,8 +1964,8 @@ function node_revisions() { ...@@ -1973,8 +1964,8 @@ function node_revisions() {
} }
drupal_not_found(); drupal_not_found();
break; break;
case 'rollback': case 'revert':
node_revision_rollback(arg(1), arg(3)); node_revision_revert(arg(1), arg(3));
break; break;
case 'delete': case 'delete':
node_revision_delete(arg(1), arg(3)); node_revision_delete(arg(1), arg(3));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment