Index: flag.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.inc,v
retrieving revision 1.1.2.7
diff -u -F^[^a-z]*function -r1.1.2.7 flag.inc
--- flag.inc	17 Aug 2008 16:20:07 -0000	1.1.2.7
+++ flag.inc	18 Aug 2008 17:48:39 -0000
@@ -441,6 +441,30 @@   function get_flag_action($content_id) 
     $flag_action['content_id'] = $content_id;
     return $flag_action;
   }
+  
+  /**
+   * @defgroup rules Rules integration
+   * @{
+   * Methods that can be overridden to support the Rules module.
+   */
+
+  /**
+   * Defines the Rules arguments involved in a flag event.
+   */
+  function rules_get_event_arguments_definition() {
+    return array();
+  }
+
+  /**
+   * Populates the Rules arguments involved in a flag event.
+   */
+  function rules_get_event_arguments($content_id) {
+    return array();
+  }
+
+  /**
+   * @} End of "defgroup rules".
+   */
 
   /**
    * Saves a flag to the database. It is a wrapper around update() and insert().
@@ -608,6 +632,21 @@   function get_flag_action($content_id) 
     $flag_action['content_url'] = _flag_url('node/' . $node->nid);
     return $flag_action;
   }
+
+  function rules_get_event_arguments_definition() {
+    return array(
+      'node' => array(
+        'type' => 'node',
+        'label' => t('flagged node'),
+      ),
+    );
+  }
+
+  function rules_get_event_arguments($content_id) {
+    return array(
+      'node' => $this->load_content($content_id),
+    );
+  }
 }
 
 /**
@@ -675,6 +714,27 @@   function get_flag_action($content_id) 
     $flag_action['content_url'] = _flag_url("node/$comment->nid/$comment->cid", "comment-$comment->cid");
     return $flag_action;
   }
+
+  function rules_get_event_arguments_definition() {
+    return array(
+      'comment' => array(
+        'type' => 'comment',
+        'label' => t('flagged comment'),
+      ),
+      'node' => array(
+        'type' => 'node',
+        'label' => t("the flagged comment's node"),
+      ),
+    );
+  }
+
+  function rules_get_event_arguments($content_id) {
+    $comment = $this->load_content($content_id);
+    return array(
+      'comment' => $comment,
+      'node' => node_load($comment->nid),
+    );
+  }
 }
 
 /**
@@ -746,6 +806,21 @@   function get_flag_action($content_id) 
     $flag_action['content_url'] = _flag_url('user/' . $user->uid);
     return $flag_action;
   }
+
+  function rules_get_event_arguments_definition() {
+    return array(
+      'user' => array(
+        'type' => 'user',
+        'label' => t('flagged user'),
+      ),
+    );
+  }
+
+  function rules_get_event_arguments($content_id) {
+    return array(
+      'user' => $this->load_content($content_id),
+    );
+  }
 }
 
 /**
Index: flag.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.module,v
retrieving revision 1.11.2.27
diff -u -F^[^a-z]*function -r1.11.2.27 flag.module
--- flag.module	17 Aug 2008 18:50:16 -0000	1.11.2.27
+++ flag.module	18 Aug 2008 17:48:41 -0000
@@ -683,6 +683,13 @@ function flag_flag($action, $flag, $cont
     }
 
   }
+
+  if (module_exists('rules')) {
+    $event_name = ($action == 'flag' ? 'flag_flagged_' : 'flag_unflagged_') . $flag->name;
+    $arguments = array('flagging_user' => $account);
+    $arguments += $flag->rules_get_event_arguments($content_id);
+    rules_invoke_event($event_name, $arguments);
+  }
 }
 
 /**
Index: flag.rules.inc
===================================================================
RCS file: flag.rules.inc
diff -N flag.rules.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ flag.rules.inc	18 Aug 2008 17:48:41 -0000
@@ -0,0 +1,42 @@
+<?php
+// $Id$
+
+/**
+ * @file flag.rules.inc
+ * Rules integration for the Flag module.
+ */
+
+/**
+ * Implementation of hook_rules_event_info().
+ */
+function flag_rules_event_info() {
+  $items = array();
+
+  $flags = flag_get_flags();
+  foreach ($flags as $flag) {
+
+    $arguments = array(
+      // First, define ubiquitous arguments.
+      'flagging_user' => array(
+        'type' => 'user',
+        'label' => t('flagging user'),
+      ),
+    );
+    // Then, define flag-specific arguments.
+    $arguments += $flag->rules_get_event_arguments_definition();
+
+    // For each flag we define two events.
+    $items['flag_flagged_' . $flag->name] = array(
+      'module' => 'Flag',
+      'label' => t('Flagged a @flag-type, using "@flag-title"', array('@flag-title' => $flag->get_title(), '@flag-type' => t($flag->content_type))),
+      'arguments' => $arguments,
+    );
+    $items['flag_unflagged_' . $flag->name] = array(
+      'module' => 'Flag',
+      'label' => t('Unflagged a @flag-type, using "@flag-title"', array('@flag-title' => $flag->get_title(), '@flag-type' => t($flag->content_type))),
+      'arguments' => $arguments,
+    );
+  }
+
+  return $items;
+}
