Révision 661d64c9
Ajouté par Assos Assos il y a plus de 7 ans
drupal7/sites/all/modules/diff/diff.module | ||
---|---|---|
39 | 39 |
case 'admin/help#diff': |
40 | 40 |
$output = '<p>' . t('The Diff module replaces the normal <em>Revisions</em> node tab. Diff enhances the listing of revisions with an option to view the differences between any two content revisions. Access to this feature is controlled with the <em>View revisions</em> permission. The feature can be disabled for an entire content type on the content type configuration page. Diff also provides an optional <em>View changes</em> button while editing a node.') . '</p>'; |
41 | 41 |
return $output; |
42 |
|
|
42 | 43 |
case 'node/%/revisions/%/view': |
43 | 44 |
// The translated strings should match node_help('node/%/revisions'). |
44 | 45 |
return '<p>' . t('Revisions allow you to track differences between multiple versions of your content, and revert back to older versions.') . '</p>'; |
46 |
|
|
45 | 47 |
case 'node/%/revisions/view/%/%': |
46 | 48 |
return '<p>' . t('Comparing two revisions:') . '</p>'; |
49 |
|
|
47 | 50 |
} |
48 | 51 |
} |
49 | 52 |
|
... | ... | |
104 | 107 |
'page callback' => 'diff_latest', |
105 | 108 |
'page arguments' => array(1), |
106 | 109 |
'type' => MENU_LOCAL_TASK, |
107 |
'access callback' => 'diff_node_revision_access', |
|
108 |
'access arguments' => array(1), |
|
110 |
'access arguments' => array('access content'), |
|
109 | 111 |
'tab_parent' => 'node/%/revisions/view', |
110 | 112 |
'file' => 'diff.pages.inc', |
111 | 113 |
); |
... | ... | |
152 | 154 |
); |
153 | 155 |
|
154 | 156 |
$items['admin/config/content/diff/entities/node'] = array( |
155 |
'title' => 'Node', |
|
157 |
'title' => 'Nodes', |
|
158 |
'description' => 'Node comparison settings.', |
|
156 | 159 |
'type' => MENU_DEFAULT_LOCAL_TASK, |
157 | 160 |
'weight' => -10, |
158 | 161 |
); |
162 |
$items['admin/config/content/diff/entities/user'] = array( |
|
163 |
'title' => 'Users', |
|
164 |
'description' => 'User diff settings.', |
|
165 |
'file' => 'diff.admin.inc', |
|
166 |
'page callback' => 'drupal_get_form', |
|
167 |
'page arguments' => array('diff_admin_global_entity_settings', 'user'), |
|
168 |
'access arguments' => array('administer site configuration'), |
|
169 |
'type' => MENU_LOCAL_TASK, |
|
170 |
); |
|
159 | 171 |
|
160 | 172 |
return $items; |
161 | 173 |
} |
... | ... | |
197 | 209 |
return $may_revision_this_type && _node_revision_access($node, $op); |
198 | 210 |
} |
199 | 211 |
|
212 |
/** |
|
213 |
* Implements hook_permission(). |
|
214 |
*/ |
|
215 |
function diff_permission() { |
|
216 |
return array( |
|
217 |
'diff view changes' => array( |
|
218 |
'title' => t('Access %view button', array('%view' => t('View changes'))), |
|
219 |
'description' => t('Controls access to the %view button when editing content.', array('%view' => t('View changes'))), |
|
220 |
), |
|
221 |
); |
|
222 |
} |
|
223 |
|
|
200 | 224 |
/** |
201 | 225 |
* Implements hook_hook_info(). |
202 | 226 |
*/ |
... | ... | |
238 | 262 |
} |
239 | 263 |
} |
240 | 264 |
|
265 |
/** |
|
266 |
* Returns a list of all the existing revision numbers. |
|
267 |
* |
|
268 |
* Clone of node_revision_list() with revision status included. This would be |
|
269 |
* an additional join in Drupal 8.x to the {node_field_revision} table. |
|
270 |
* |
|
271 |
* @param object $node |
|
272 |
* The node object. |
|
273 |
* |
|
274 |
* @return array |
|
275 |
* An associative array keyed by node revision number. |
|
276 |
*/ |
|
277 |
function diff_node_revision_list($node) { |
|
278 |
$revisions = array(); |
|
279 |
$result = db_query('SELECT r.vid, r.title, r.log, r.uid, n.vid AS current_vid, r.status AS status, r.timestamp, u.name FROM {node_revision} r LEFT JOIN {node} n ON n.vid = r.vid INNER JOIN {users} u ON u.uid = r.uid WHERE r.nid = :nid ORDER BY r.vid DESC', array(':nid' => $node->nid)); |
|
280 |
foreach ($result as $revision) { |
|
281 |
$revisions[$revision->vid] = $revision; |
|
282 |
} |
|
283 |
|
|
284 |
return $revisions; |
|
285 |
} |
|
286 |
|
|
241 | 287 |
/** |
242 | 288 |
* Implements hook_block_info(). |
243 | 289 |
*/ |
... | ... | |
287 | 333 |
$enabled_types = variable_get('diff_show_diff_inline_node_bundles', array()); |
288 | 334 |
if (!empty($enabled_types[$node->type])) { |
289 | 335 |
$block = array(); |
290 |
$revisions = node_revision_list($node); |
|
336 |
$revisions = diff_node_revision_list($node);
|
|
291 | 337 |
if (count($revisions) > 1) { |
292 | 338 |
$block['subject'] = t('Highlight changes'); |
293 | 339 |
$block['content'] = drupal_get_form('diff_inline_form', $node, $revisions); |
... | ... | |
302 | 348 |
*/ |
303 | 349 |
function diff_node_view_alter(&$build) { |
304 | 350 |
$node = $build['#node']; |
305 |
if (user_access('view revisions') && in_array($node->type, variable_get('diff_show_diff_inline_node_bundles', array()))) { |
|
351 |
if (user_access('view revisions') && in_array($node->type, variable_get('diff_show_diff_inline_node_bundles', array()), TRUE)) {
|
|
306 | 352 |
// Ugly but cheap way to check that we are viewing a node's revision page. |
307 | 353 |
if (arg(2) === 'revisions' && arg(3) === $node->vid) { |
308 | 354 |
module_load_include('inc', 'diff', 'diff.pages'); |
... | ... | |
320 | 366 |
function diff_form_node_form_alter(&$form, $form_state) { |
321 | 367 |
// Add a 'View changes' button on the node edit form. |
322 | 368 |
$node = $form['#node']; |
323 |
if (variable_get('diff_show_preview_changes_node_' . $node->type, TRUE) && !empty($node->nid)) { |
|
369 |
if (variable_get('diff_show_preview_changes_node_' . $node->type, TRUE) |
|
370 |
&& user_access('diff view changes') |
|
371 |
&& !empty($node->nid)) { |
|
324 | 372 |
$form['actions']['preview_changes'] = array( |
325 | 373 |
'#type' => 'submit', |
326 | 374 |
'#value' => t('View changes'), |
... | ... | |
347 | 395 |
'#title' => t('Show <em>View changes</em> button on node edit form'), |
348 | 396 |
'#weight' => 10, |
349 | 397 |
'#default_value' => variable_get('diff_show_preview_changes_node_' . $type->type, TRUE), |
398 |
'#description' => t('You can refine access using the "!perm" permission.', array( |
|
399 |
'!perm' => t('Access %view button', array('%view' => t('View changes'))), |
|
400 |
)), |
|
350 | 401 |
); |
351 | 402 |
$form['diff']['diff_enable_revisions_page_node'] = array( |
352 | 403 |
'#type' => 'checkbox', |
... | ... | |
430 | 481 |
$changes = theme('table__diff__preview', array( |
431 | 482 |
'header' => $header, |
432 | 483 |
'rows' => $rows, |
433 |
'attributes' => array('class' => 'diff'),
|
|
484 |
'attributes' => array('class' => array('diff')),
|
|
434 | 485 |
'colgroups' => _diff_default_cols(), |
435 | 486 |
'sticky' => FALSE, |
436 | 487 |
)); |
... | ... | |
440 | 491 |
$form_state['rebuild'] = TRUE; |
441 | 492 |
} |
442 | 493 |
|
494 |
/** |
|
495 |
* Implementation of hook_features_pipe_COMPONENT_alter(). |
|
496 |
*/ |
|
497 |
function diff_features_pipe_node_alter(&$pipe, $data, $export) { |
|
498 |
if (!empty($data)) { |
|
499 |
$variables = array( |
|
500 |
'diff_show_preview_changes_node', |
|
501 |
'diff_enable_revisions_page_node', |
|
502 |
'diff_view_mode_preview_node', |
|
503 |
); |
|
504 |
foreach ($data as $node_type) { |
|
505 |
foreach ($variables as $variable_name) { |
|
506 |
$pipe['variable'][] = $variable_name . '_' . $node_type; |
|
507 |
} |
|
508 |
} |
|
509 |
} |
|
510 |
} |
|
511 |
|
|
443 | 512 |
/** |
444 | 513 |
* Implements hook_theme(). |
445 | 514 |
*/ |
... | ... | |
483 | 552 |
* The source string to compare from. |
484 | 553 |
* @param string $b |
485 | 554 |
* The target string to compare to. |
486 |
* @param boolean $show_header
|
|
555 |
* @param bool $show_header |
|
487 | 556 |
* Display diff context headers. For example, "Line x". |
488 | 557 |
* @param array $line_stats |
489 | 558 |
* This structure tracks line numbers across multiple calls to DiffFormatter. |
... | ... | |
621 | 690 |
} |
622 | 691 |
return $attachments; |
623 | 692 |
} |
693 |
|
|
694 |
/** |
|
695 |
* Implements hook_entity_diff() on behalf of the Node module. |
|
696 |
*/ |
|
697 |
function node_entity_diff($old_node, $new_node, $context) { |
|
698 |
$result = array(); |
|
699 |
if ($context['entity_type'] == 'node') { |
|
700 |
module_load_include('inc', 'diff', 'includes/node'); |
|
701 |
$options = variable_get('diff_additional_options_node', array('title' => 'title')); |
|
702 |
foreach (node_entity_diff_options('node') as $key => $option_label) { |
|
703 |
if (!empty($options[$key])) { |
|
704 |
$func = '_node_entity_diff_additional_options_' . $key; |
|
705 |
$result[$key] = $func($old_node, $new_node, $context); |
|
706 |
} |
|
707 |
} |
|
708 |
} |
|
709 |
return $result; |
|
710 |
} |
|
711 |
|
|
712 |
/** |
|
713 |
* Implements hook_entity_diff_options() on behalf of the Node module. |
|
714 |
*/ |
|
715 |
function node_entity_diff_options($entity_type) { |
|
716 |
if ($entity_type == 'node') { |
|
717 |
$options = array( |
|
718 |
'title' => t('Title field'), |
|
719 |
// Author field is either the owner or revision creator, neither capture |
|
720 |
// a change in the author field. |
|
721 |
'author' => t('Author'), |
|
722 |
'revision_author' => t('Revision author'), |
|
723 |
'type' => t('Node type'), |
|
724 |
'publishing_flags' => t('Publishing options'), |
|
725 |
// More fields that currently can not be tracked. |
|
726 |
'created' => t('Created date'), |
|
727 |
'changed' => t('Updated date'), |
|
728 |
'revision_timestamp' => t('Revision timestamp'), |
|
729 |
); |
|
730 |
if (module_exists('comment')) { |
|
731 |
$options['comment'] = t('Comment setting'); |
|
732 |
} |
|
733 |
return $options; |
|
734 |
} |
|
735 |
} |
|
736 |
|
|
737 |
/** |
|
738 |
* Implements hook_entity_diff() on behalf of the User module. |
|
739 |
*/ |
|
740 |
function user_entity_diff($old_user, $new_user, $context) { |
|
741 |
$result = array(); |
|
742 |
if ($context['entity_type'] == 'user') { |
|
743 |
module_load_include('inc', 'diff', 'includes/user'); |
|
744 |
$options = variable_get('diff_additional_options_user', array( |
|
745 |
'name' => 'name', |
|
746 |
'mail' => 'mail', |
|
747 |
'status' => 'status', |
|
748 |
)); |
|
749 |
foreach (user_entity_diff_options('user') as $key => $option_label) { |
|
750 |
if (!empty($options[$key])) { |
|
751 |
$func = '_user_entity_diff_additional_options_' . $key; |
|
752 |
$result[$key] = $func($old_user, $new_user, $context); |
|
753 |
} |
|
754 |
} |
|
755 |
} |
|
756 |
return $result; |
|
757 |
} |
|
758 |
|
|
759 |
/** |
|
760 |
* Implements hook_entity_diff_options() on behalf of the User module. |
|
761 |
*/ |
|
762 |
function user_entity_diff_options($entity_type) { |
|
763 |
if ($entity_type == 'user') { |
|
764 |
$options = array( |
|
765 |
'name' => t('Username'), |
|
766 |
'mail' => t('E-mail address'), |
|
767 |
'roles' => t('Roles'), |
|
768 |
'status' => t('Status'), |
|
769 |
'timezone' => t('Time zone'), |
|
770 |
'password' => t('Password Hash'), |
|
771 |
); |
|
772 |
return $options; |
|
773 |
} |
|
774 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules