Index: taxonomy.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/diff/taxonomy.inc,v
retrieving revision 1.3
diff -u -F^f -r1.3 taxonomy.inc
--- taxonomy.inc	5 Mar 2008 21:03:17 -0000	1.3
+++ taxonomy.inc	31 Mar 2009 17:35:42 -0000
@@ -9,41 +9,59 @@ function taxonomy_diff(&$old_node, &$new
   // TODO: make taxonomy by category not only by whole taxonomy?
   $old_taxonomy = array();
   $new_taxonomy = array();
-  if($old_node->taxonomy) {
+  if ($old_node->taxonomy) {
     foreach($old_node->taxonomy as $term) {
-      $old_taxonomy[] = $term->name;
+      $vocab = taxonomy_get_vocabulary($term->vid);
+      $old_taxonomy[] = $vocab->name .' -> '. $term->name;
     }
   }
   if ($new_node->taxonomy) {
     foreach($new_node->taxonomy as $id => $entry) {
-      if (is_array($entry)) {
-        // During editing the taxonomy is built up as a list of vocabulary ids as keys
-        // and a list of term ids per array entry.
+      if (is_object($entry)) {
+        // When diffing revisions, taxonomy is an array of term objects.
+        // Currently, there's no way to diff revisions because taxonomy isn't versioned,
+        // but we build the list anyway.
+        $vocab = taxonomy_get_vocabulary($entry->vid);
+        $new_taxonomy[] = $vocab->name .' -> '. $entry->name;
+      }
+      else if (is_array($entry)) {
+        // During editing, taxonomy will be an array for multi-select and
+        // freetagging vocabularies.
         if (is_numeric($id)) {
+          // A multi-select taxonomy is built up as a list of vocabulary ids as keys and
+          // a list of term ids per array entry.
           foreach($entry as $tid) {
             $term = taxonomy_get_term($tid);
-            $new_taxonomy[] = $term->name;
+            $vocab = taxonomy_get_vocabulary($term->vid);
+            $new_taxonomy[] = $vocab->name .' -> '. $term->name;
           }
         }
-        else {
-          // If the id is not numeric than it has to be 'tags' which denotes freetagging
-          // vocabularies. These are stored as an array which map the vocabulary id to
+        else if ($id == 'tags') {
+          // A freetagging vocabulary is stored as an array which maps a vocabulary id to
           // a string of terms.
-          foreach($entry as $taglist) {
-            // The regular expression is taken from taxonomy.module.
-            preg_match_all('%(?:^|,\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x', $taglist, $matches);
-            foreach($matches[1] as $term) {
-              $new_taxonomy[] = $term;
-            }
+          // This regular expression is taken from taxonomy.module.
+          preg_match_all('%(?:^|,\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x', current($entry), $matches);
+          $vocab = taxonomy_get_vocabulary(key($entry));
+          sort($matches[1]);
+          foreach($matches[1] as $term) {
+            $new_taxonomy[] = $vocab->name .' -> '. $term;
           }
         }
       }
       else {
-        // Not during editing the taxonomy list is a list of terms.
-        $new_taxonomy[] = $entry->name;
+        // During editing, a single-select taxonomy is built up as a list of vocabulary ids as keys
+        // with term ids per array entry.
+        $vocab = taxonomy_get_vocabulary($id);
+        $term = taxonomy_get_term($entry);
+        $new_taxonomy[] = $vocab->name .' -> '. $term->name;
       }
     }
   }
+
+  // Make sure terms are in a consistent order for the diff.
+  sort($old_taxonomy);
+  sort($new_taxonomy);
+
   $result['taxonomy'] = array(
     '#name' => t('Taxonomy'),
     '#old' => $old_taxonomy,
