Index: flag.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.inc,v
retrieving revision 1.1.2.8
diff -u -F^[^a-z]*function -r1.1.2.8 flag.inc
--- flag.inc	22 Aug 2008 06:09:18 -0000	1.1.2.8
+++ flag.inc	25 Aug 2008 07:27:43 -0000
@@ -644,6 +644,7 @@   function get_views_info() {
     return array(
       'views table' => 'node',
       'join field' => 'nid',
+      'title field' => 'title',
       'title' => t('Node flag'),
       'help' => t('Limit results to only those nodes flagged by a certain flag; Or display information about the flag set on a node.'),
       'counter title' => t('Node flag counter'),
@@ -734,6 +735,7 @@   function get_views_info() {
     return array(
       'views table' => 'comments',
       'join field' => 'cid',
+      'title field' => 'subject',
       'title' => t('Comment flag'),
       'help' => t('Limit results to only those comments flagged by a certain flag; Or display information about the flag set on a comment.'),
       'counter title' => t('Comment flag counter'),
@@ -827,6 +829,7 @@   function get_views_info() {
     return array(
       'views table' => 'users',
       'join field' => 'uid',
+      'title field' => 'name',
       'title' => t('User flag'),
       'help' => t('Limit results to only those users flagged by a certain flag; Or display information about the flag set on a user.'),
       'counter title' => t('User flag counter'),
Index: flag.views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.views.inc,v
retrieving revision 1.6.2.10
diff -u -F^[^a-z]*function -r1.6.2.10 flag.views.inc
--- flag.views.inc	22 Aug 2008 06:09:18 -0000	1.6.2.10
+++ flag.views.inc	25 Aug 2008 07:27:45 -0000
@@ -26,6 +26,15 @@ function flag_views_data() {
     ),
   );
 
+  // Argument for content ID, used for "Who's flagged this" views.
+  $data['flag_content']['content_id'] = array(
+    'title' => t('Content ID'),
+    'help' => t('The unique ID of the object that has been flagged.'),
+    'argument' => array(
+      'handler' => 'flag_handler_argument_content_id',
+    )
+  );
+
   $data['flag_content']['timestamp'] = array(
     'title' => t('Flagged time'),
     'help' => t('Display the time the content was flagged by a user.'),
@@ -125,6 +134,20 @@ function flag_views_data_alter(&$data) {
     );
   }
 
+  // Add a relationship for the user that flagged any type of content.
+  $data['users']['flag_user_content_rel'] = array(
+    'group' => t('Flags'),
+    'title' => t('User flagged content'),
+    'help' => t('Limit results to users that have flagged certain content.'),
+    'real field' => 'uid',
+    'relationship' => array(
+      'base' => 'flag_content',
+      'field' => 'uid',
+      'handler' => 'flag_handler_relationship_user_content',
+      'label' => t('user flagged content'),
+    ),
+  );
+
 }
 
 /**
@@ -341,6 +364,66 @@   function query() {
 }
 
 /**
+ * Specialized relationship handler associating flags and users.
+ */
+class flag_handler_relationship_user_content extends views_handler_relationship {
+
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['flag'] = array('default' => flag_views_flag_default(NULL));
+    $options['required'] = array('default' => 1);
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['label']['#description'] .= ' '. t('Including name of the selected flag helps identify this relationship.');
+
+    $form['flag'] = flag_views_flag_config_form('radios', NULL, $this->options['flag']);
+    $form['flag']['#title'] = t('Flagged');
+
+    $form['required']['#title'] = t('Include only users who have flagged content.');
+    $form['required']['#description'] = t('If checked, only users that have flagged any content with this flag will be included.');
+  }
+
+  function admin_summary() {
+    return $this->options['flag'];
+  }
+
+  /**
+   * Called to implement a relationship in a query.
+   */
+  function query() {
+    // Figure out what base table this relationship brings to the party.
+    $join = new views_join();
+    $join->definition = array(
+      'table' => 'flag_content',
+      'field' => 'uid',
+      'left_table' => 'users',
+      'left_field' => 'uid',
+    );
+
+    if (!empty($this->options['required'])) {
+      $join->definition['type'] = 'INNER';
+    }
+
+    $flag = flag_get_flag($this->options['flag']);
+    $join->definition['extra'] = array(
+      array(
+        'field' => 'fid',
+        'value' => $flag->fid,
+        'numeric' => TRUE,
+      ),
+    );
+
+    $join->construct();
+
+    $alias = $join->definition['table'] . '_' . $join->definition['left_table'];
+    $this->alias = $this->query->add_relationship($alias, $join, 'flag_content', $this->relationship);
+  }
+}
+
+/**
  * Views field handler for the Flag operations links (flag/unflag).
  */
 class flag_handler_field_ops extends views_handler_field {
@@ -477,6 +560,40 @@   function query() {
 }
 
 /**
+ * Handler to accept an argument of the content ID of any object.
+ */
+class flag_handler_argument_content_id extends views_handler_argument_numeric {
+
+  /**
+   * Returns the flag object associated with our argument.
+   *
+   * An argument is in some relationship. This function reaches out for this
+   * relationship and reads its 'flag' option, which holds the flag name.
+   */
+  function get_flag() {
+    $flag_name = $this->view->relationship[$this->options['relationship']]->options['flag'];
+    return flag_get_flag($flag_name);
+  }
+
+  /**
+   * Override the behavior of title(). Get the title of the appropriate objects.
+   */
+  function title_query() {
+    $flag = $this->get_flag();
+    $views_info = $flag->get_views_info();
+
+    $titles = array();
+    $placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
+
+    $result = db_query("SELECT o.". $views_info['title field'] ." FROM {". $views_info['views table'] ."} o WHERE o.". $views_info['join field'] ." IN ($placeholders)", $this->value);
+    while ($title = db_fetch_object($result)) {
+      $titles[] = check_plain($title->$views_info['title field']);
+    }
+    return $titles;
+  }
+}
+
+/**
  * Implementation of hook_views_default_views()
  */
 function flag_views_default_views() {
