I imagine this would be a separate module - the ability to send an admin the diff of the newest and previous revision for a node. Does anyone have ideas for starting points or another module that may already be on the way to doing this?


#32 diff-token-00.patch2.5 KBsmokris
Members fund testing for the Drupal project. Drupal Association Learn more


moshe weitzman’s picture

yeah, thats a killer feature that we should offer in this module. i'm pretty sure the plumbing is there for this in diffEngine.php

toemaz’s picture

+1 for this feature.

matt_paz’s picture

Might be nice to represent diff data in RSS as well ... for wikis?

moshe weitzman’s picture

We also need a specification for whom the diffs should be sent to? Is this a hook for subscription module? Do folks sign up for this? How do folks see this working?

Ian Ward’s picture

I like the idea of subscriptions, so it could be one a node by node basis, along with a permission to be able to subscribe to diff via email, or this is just the same permission as the ability to see a diff.

Also, I recently heard the question "where can I go and subscribe to see all the changes that happened just on one book - or all the revisions?" which makes me think, it would be nice to be able to subscribe to diff-by-email on a per-book basis, as another idea or matter of scope for the subscription idea.

Leeteq’s picture

A diff-RSS would be very nice. That could in itself be distributed by email through external "tools".
Should have a permission setting so that only desired roles such as CM or moderator could use this.
I can think of several situations that suggest having the possibility to limit this by role.

Leeteq’s picture

Hmmm, more a subscriptions-module feature or the like, perhaps, but come to think of this:

It should be possible for each user to set how often such emails are received.
If so, then several diffs might happen inbetween the previous and current email...
Wouldn't that mean that the diff module needs to check which is the last one received, and make the diff from there?
Do we need a way to receive each revision diff, or only the comparison between the last one and the current one?

What if the user has visited and viewed some diffs online meanwhile, should that be tracked and taken into account?

coderintherye’s picture

I am in need of this feature and am currently working on it. My implementation idea was to simply try to create a token with the latest diff. The token could then be put into Notifications/messages. I'm trying out calling the _diff_body_rows function directly, but haven't quite figured out how I am supposed to pass the parameters. Anyone else working on this or have more ideas?

aristedes’s picture

Can I suggest that making this diff module work with the 'token' module (http://drupal.org/node/307140) and/or the 'rules' module would do everything that is needed for most people.

For example, this would allow the diff of a page to be automatically emailed to an administrator when that page is modified.

Very useful.

moshe weitzman’s picture

Thats a great idea, but token has performance issues and this would make it worse.

coderintherye’s picture

Hey, so I have a module that I developed which uses the Diff module to create a diff-to-email functionality. It does this by creating a token, and then I use the token in my notifications. I haven't got CVS access yet, so for those who are still interested in this let me know and I can post it up somewhere for you. Obviously, it is still in development, but for now it does the trick quite nicely. Perhaps, moshe could better explain the reasons for not including this, I haven't noticed any performance issues, but I run a small site, but either way if it is a stand-alone or incorporated doesn't make too much difference.

Owen Barton’s picture

@anarchman - I agree token module is the most streamlined from the point of view of using with notifications module. I can see the potential performance issues - but there may be some way to resolve them (and the likely token API in Drupal 7 would also resolve them).

Could you perhaps post your code to this ticket? Ideally as a patch (see http://drupal.org/patch/create) but just a zip/tarball if that doesn't work. This is something I will likely be working on in the next week or so and it would be nice to have a starting point.

mErilainen’s picture

+1, subcribing

coderintherye’s picture

I will create a patch later, but this is using an older version so I need to update and see if it still works. The basic code itself is simple, just create a module with the code below and also add a line to your token.module under the switch ($type) statement in the function token_token_values where all the values are and add this:

$values['node-diff']    = difftoken_tokenize();

That went on line 68 for me. (I know there is a better way to do this but dont have time for it just at this moment.

So then I created difftoken.module with the following code:

// $Id: difftoken.module,v 0.1 2008/10/15 12:00:00 kevin Exp $

function difftoken_tokenize() {
  $it = 0;
  $node_id = arg(1);
  if (is_numeric($node_id)) {
    $node = node_load($node_id);
	$revision_list = node_revision_list($node); 
	foreach ($revision_list as $revision) {
      if ($it == 0) {
		$new_vid = $revision->vid;
	  if ($it == 1) {
		$old_vid = $revision->vid;
	  if (++$it == 3) {
  $diff_token = diff_diffs_show(&$node, $old_vid, $new_vid);
  return $diff_token;

Again, this is just a hack and not the proper way to do things, it needs some formatting on the HTML, I actually just convert it to plain text in my version I am using, but hopefully I can come back to this in a couple of weeks.

dakebusi’s picture


I'm quite new to Drupal, so maybe this is a stupid question: how do I create the difftoken module? Besides copying the code you give to difftoken.module, where should I put it? Should I create a new folder in the modules directory? How do I enable it?

Thanks, I'd really like to have this feature working on my site.

dakebusi’s picture

Ok, I've gone through the custom module tutorial and I've created my difftoken.module. It works great, and everytime a page is modified I get an email notifying me about it. However, I only miss one thing now. In the generated mail, there is no link to the diff.css stylesheet, and thus, the difference table does not show any colors. How should I tell drupal to include the CSS file?

smithmb’s picture

I'd love to see this too.

coderintherye’s picture


A little late here, but you can use

drupal_add_css ('myfile.css');

in your module and that should do it.

coderintherye’s picture

I'm willing to code this up into a module, since I need to improve what I currently have going anyways.

The way I deliver the Diff is to

1) Put a user reference field on a node
2) Use actions to send an e-mail to the user selected in that field whenever the node is edited/updated.
3) The e-mail uses the 'diff token' to insert the diff between the latest revisions.
4) The layout of the e-mail is administered either through messaging or notifications or another platform.

There are problems with the format if you are in Drupal 5, I had to add in the the drupal_to_text functionality from D6, but the end question is, what format should the e-mail be sent in? Probably somewhere there should be a menu option to choose whether plain-text or MIME or HTML, etc.

The key question here is should this functionality go into the Diff module itself or go into a separate module?

jct’s picture

I was exploring doing this using the Notifications & Messaging framework which, given a token, might allow the one to create both a plain-text or MIME option in the messaging template.

This would be an awesome addition!

tim.plunkett’s picture

Version: 5.x-2.x-dev » 6.x-2.x-dev


coderintherye’s picture

So what I need is one of the maintainers to state whether or not this should go into Diff or should be its own module...

Aren Cambre’s picture

Title: Diff-to-email functionality » Diff module should support Token

I am going to be bold and say that the best resolution to this problem, within the scope of the Diff module, is to integrate it with Token. Once that is done, then any number of other modules can easily extract revision diffs and handle appropriately.

For example, the Rules module could handle this once #315067: Investigate html formatting features and #501722: HTML mail actions for Rules are resolved.

(Title includes reference to Diff module because I am going to cite this issue in some other issues.)

coderintherye’s picture

Well, glad we are rescuing this issue from the dead. Please post back here the resolution, because the functionality is obviously needed, but I don't want to put another module on d.o. if we can get this worked into Token or Diff.

coderintherye’s picture

So what is the holdup here. Do we need a patch for integrating this into Token? Do we need to start another bug request in Token and close this as duplicate?

bwinett’s picture

+1, subscribing

Aren Cambre’s picture

#25: Don't close this as dup unless it is found that no modifications are required of diff.

steeph’s picture


coderintherye’s picture

Well, I'm still willing to code on this, but we really need some clear course of action.

The linked to issues in #23 are resolved now, so does that mean we can move towards using Rules?

itserich’s picture

Token integration would save us a lot of time, we have public content and it is hard to track changes.

A Rule triggered email containing changes would help.

For now, Recent Changes RSS Feed helps admins monitor the site: http://drupal.org/project/recent_changes

RSS does require one simple patch: http://drupal.org/node/1015138

TommyK’s picture


smokris’s picture

Status: Active » Needs review
2.5 KB

The attached patch modifies diff.module to provide a "[diff]" token (for the "node" token type), whose value is the (HTML-rendered) difference between the current node version and the previous version.

Suitable for use in, for example, Messaging & Notifications templates.

Any chance this could be committed to diff-6.x-2.x-dev?

steeph’s picture

Works for me, but with no colors. So in large paragraphs it's still hard to find small changes.

smokris’s picture

In my "Notifications for Node Updates" Message Template, I just added <style></style> at the top of the template, and pasted the content of diff/diff.css inside --- this causes the colors to show up just fine. Not sure offhand if there's a better way to include CSS in Message Templates.

steeph’s picture

I think it should also work with Echo, or am I wrong here? I can't seem to get it work. Can you tell me where exactly in the tpl file to put the style tag? It gets removed when the mail is sent.

smokris’s picture

My email notifications are sent using http://drupal.org/project/messaging. I just visited Administration > Messaging & Notifications > Message templates > Notifications for node updates, and pasted the CSS rules there.

I also had already enabled the PHPMailer Send method (enable the "Messaging PHPMailer" module; configure under Administration > Messaging & Notifications > Messaging settings > Send methods, and used the "Full HTML" input format).

BarisW’s picture

Very, very cool. Would this patch be hard to port to D7?

Alan D.’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
Status: Needs review » Needs work

Development should start at the latest branch, but it should be trivial to paste this code into diff.tokens.inc and to get it working.

tim.plunkett’s picture

Issue tags: +needs backport to D6

Fixing tags

Alan D.’s picture

I can not patch against 7.x-2.x with the work that I am doing, so I either really need git access to push out a 7.x-3.x branch or you can find this in the sandbox project (Diff developmental version 7.x-2.x branch).

This is fairly raw. It has two tokens, node:diff and node:diff-markdown (Markdowned is the HTML less or restricted HTML version). Testers required. Report issues in that project space unless this gets committed into Diff main project.

Alan D.’s picture

Status: Needs work » Needs review

There is a version of this in the new branch, 7.x-3.0-alpha1 or 7.x-3.0-dev. This needs better testing to see if there are any issues to resolve.

My personally testing involved a dpm() wrapped around the token replacement, so this may need work for production.

mitchell’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Status: Needs review » Active

@Alan D.: I tried a couple of combinations in Rules to show a diff when a node is updated, but I couldn't figure out how to get it to work. Setting back to active since more specific instructions or discussion would be a big help.

AFAICT from reading diff.tokens.inc, it is restricted to two specific revisions and, also, additional tokens would need to be hardcoded but might not work with Views or Rules. It's possible that #1371916: Restructure around the Entity / Field system may offer a valid solution to this.

Alan D.’s picture

Status: Active » Fixed

Diff 3.x only has the two tokens [node:diff] and [node:diff-markdown]. These only show the diff of the current and previous revisions. This was the scope of this issue and is about the limit of support that I would be comfortable within the Diff module itself.

I'm closing this as there have been no issues reported since July when this was added to the 3.x branch. Please reopen if you have issues (or you have a patch to backport to 6.x-2.x), or open a new issues to extend the scope.

Personally I'm not sure on how you would get Rules to parse a token supported string directly. Modules like Node Notify, etc, support token templates for the subject / body fields within the email. For these it is simple as placing the two tokens into the body field.

Status: Fixed » Closed (fixed)
Issue tags: -needs backport to D6

Automatically closed -- issue fixed for 2 weeks with no activity.