? css.revisions.patch
Index: css.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/css/css.install,v
retrieving revision 1.1
diff -u -r1.1 css.install
--- css.install	2 Nov 2008 15:16:09 -0000	1.1
+++ css.install	19 Jan 2009 10:59:21 -0000
@@ -1,6 +1,6 @@
 <?php
 // $Id: css.install,v 1.1 2008/11/02 15:16:09 fax8 Exp $
-/*
+/**
  * Implementation of hook_install
  */
 function css_install() {
@@ -8,12 +8,40 @@
     case 'mysql':
     case 'mysqli':
       db_query("CREATE TABLE {css} (
+          vid int(10) unsigned NOT NULL default '0',
           nid int(10) unsigned NOT NULL default '0',
           css text NULL default NULL,
-          PRIMARY KEY (nid)
+          PRIMARY KEY (vid)
         ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
       break;
     case 'pgsql':
+      // TODO: support pgsql
     break;
   }
-}
\ No newline at end of file
+}
+
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function css_uninstall() {
+  db_query('DROP TABLE {css}');
+}
+
+
+/**
+ * Adds support for node versions
+*/
+function css_update_1() {
+  $ret = array();
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {css} ADD vid int(10) unsigned NOT NULL default '0' FIRST");
+      $ret[] = update_sql('UPDATE {css} SET vid = nid');
+      $ret[] = update_sql('ALTER TABLE {css} DROP PRIMARY KEY, ADD PRIMARY KEY ( `vid` )');
+      break;
+  }
+  return $ret;
+}
+
Index: css.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/css/css.module,v
retrieving revision 1.3.2.5
diff -u -r1.3.2.5 css.module
--- css.module	26 Dec 2008 16:34:32 -0000	1.3.2.5
+++ css.module	19 Jan 2009 10:59:21 -0000
@@ -10,16 +10,8 @@
  * @updated to Drupal 5 by Christopher Skauss <christopher skauss at gmail dot com>
  * @modified drupal 5 Version by Whispero
  *
- * To store this extra information, we need an auxiliary database table.
+ * See DB schema in css.install.
  *
- * Database definition:
- * @code
-   CREATE TABLE css (
-      nid int(10) unsigned NOT NULL default '0',
-      css text NULL default NULL,
-      PRIMARY KEY (nid)
-    )
- * @endcode
  */
 
 /**
@@ -103,7 +95,7 @@
 function css_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
   if (variable_get('css__'. $node->type, FALSE)) { // check that CSS editing is enabled for the given node type
     switch ($op) {
-
+      
       // Controls for valid input data
       case 'validate':
         // Check for potentially malicious tags
@@ -116,15 +108,22 @@
       // Now that the form has been properly completed, it is time to commit the new
       // data to the database.
       case 'insert':
-        db_query('INSERT INTO {css} (nid, css) VALUES (%d, "%s")', $node->nid, $node->css_css);
+        if(!empty($node->css_css)) { // if we have some css rules we insert it into the DB
+          db_query('INSERT INTO {css} (vid,nid, css) VALUES (%d, %d, "%s")', $node->vid, $node->nid, $node->css_css);
+        }
         break;
 
       // If the form was called to edit an existing node rather than create a new
       // one, this operation gets called instead. We use a DELETE then INSERT rather
       // than an UPDATE just in case the rating didn't exist for some reason.
       case 'update':
-        db_query('DELETE FROM {css} WHERE nid = %d', $node->nid);
-        db_query('INSERT INTO {css} (nid, css) VALUES (%d, "%s")', $node->nid, $node->css_css);
+        if ($node->revision) { //If a new node revision is being added then insert a new row.
+          db_query('INSERT INTO {css} (vid,nid, css) VALUES (%d, %d, "%s")', $node->vid, $node->nid, $node->css_css);
+        }
+        else {
+          db_query('DELETE FROM {css} WHERE vid = %d', $node->vid);
+          db_query('INSERT INTO {css} (vid, nid, css) VALUES (%d, %d, "%s")', $node->vid, $node->nid, $node->css_css);
+        }
         break;
 
       // If the node is being deleted, we need this opportunity to clean up after
@@ -132,11 +131,15 @@
       case 'delete':
         db_query('DELETE FROM {css} WHERE nid = %d', $node->nid);
         break;
+        
+      case 'delete revision':
+        db_query('DELETE FROM {css} WHERE vid = %d', $node->vid);
+        break;
 
       // Now we need to take care of loading one of the extended nodes from the
       // database. An array containing our extra field needs to be returned.
       case 'load':
-        $object = db_fetch_object(db_query('SELECT css FROM {css} WHERE nid = %d', $node->nid));
+        $object = db_fetch_object(db_query('SELECT css FROM {css} WHERE vid = %d', $node->vid));
         return array('css_css' => $object->css);
         break;
 
@@ -154,7 +157,7 @@
           }
         }
         else {
-          theme('css_import', $node->nid);
+          theme('css_import', $node->vid);
         }
         break;
     }
@@ -165,11 +168,11 @@
  * Return the css attached to the node
  * Last-Modified header is set to let browsers cache the css.
  */
-function css_get($nid = 0) {
-  if (is_numeric($nid) && $nid > 0) {
-    $object = db_fetch_object(db_query('SELECT css, changed FROM {css} c, {node} n WHERE n.nid = %d AND n.nid = c.nid', $nid));
+function css_get($vid = 0) {
+  if (is_numeric($vid) && $vid > 0) {
+    $object = db_fetch_object(db_query('SELECT css, timestamp FROM {css} c, {node_revisions} nr WHERE nr.vid = %d AND nr.vid = c.vid', $vid));
     if($object) {
-      $date = gmdate('D, d M Y H:i:s', $object->changed) .' GMT';
+      $date = gmdate('D, d M Y H:i:s', $object->timestamp) .' GMT';
       header("Last-Modified: $date");
       drupal_set_header('Content-Type: text/css; charset=utf-8');
       print(css_sanitize($object->css));
@@ -209,12 +212,12 @@
  * We use a theme function for this to let themers able
  * to customize the behaviour of importing.
  */
-function theme_css_import($nid) {
+function theme_css_import($vid) {
   // let's link the CSS file to the HTML:
-  //   we use $path = '?q=css/get/' . $nid as without ?q= the hook would be called only when clean urls are enabled (mod_rewrite active)
+  //   we use $path = '?q=css/get/' . $vid as without ?q= the hook would be called only when clean urls are enabled (mod_rewrite active)
   //   we use $type = theme as we want to be parsed after module rules, so that we can override module defined rules
   //   we use $preprocess = FALSE as we don't want to cache the CSS rules.
-  drupal_add_css('?q=css/get/' . $nid, 'theme', 'all', FALSE);
+  drupal_add_css('?q=css/get/' . $vid, 'theme', 'all', FALSE);
 }
 
 
