Index: flag.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.inc,v
retrieving revision 1.1.2.16
diff -u -F^[^a-z]*function -r1.1.2.16 flag.inc
--- flag.inc	15 Sep 2008 11:25:21 -0000	1.1.2.16
+++ flag.inc	19 Sep 2008 11:56:08 -0000
@@ -821,6 +821,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'),
@@ -913,6 +914,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'),
@@ -1006,6 +1008,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: includes/flag.views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/includes/Attic/flag.views.inc,v
retrieving revision 1.1.2.3
diff -u -F^[^a-z]*function -r1.1.2.3 flag.views.inc
--- includes/flag.views.inc	16 Sep 2008 15:21:19 -0000	1.1.2.3
+++ includes/flag.views.inc	19 Sep 2008 11:56:08 -0000
@@ -23,12 +23,19 @@ function flag_views_handlers() {
         'parent' => 'views_handler_relationship',
         'file' => 'flag_handler_relationships.inc',
       ),
+      'flag_handler_relationship_user_content' => array(
+        'parent' => 'views_handler_relationship',
+        'file' => 'flag_handler_relationships.inc',
+      ),
       'flag_handler_field_ops' => array(
         'parent' => 'views_handler_field',
       ),
       'flag_handler_filter_flagged' => array(
         'parent' => 'views_handler_filter_boolean_operator',
       ),
+      'flag_handler_argument_content_id' => (
+        'parent' => 'views_handler_argument_numeric',
+      ),
     ),
   );
 }
@@ -70,6 +77,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',
+    )
+  );
+
   // Specialized is null/is not null filter.
   $data['flag_content']['flagged'] = array(
     'title' => t('Flagged'),
@@ -151,6 +167,19 @@ 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's flagged content"),
+    'help' => t('Limit results to users that have flagged certain content.'),
+    'relationship' => array(
+      'base' => 'flag_content',
+      'base field' => 'uid',
+      'relationship field' => 'uid',
+      'handler' => 'flag_handler_relationship_user_content',
+      'label' => t('user flagged content'),
+    ),
+  );
 }
 
 /**
Index: includes/flag_handler_argument_content_id.inc
===================================================================
RCS file: includes/flag_handler_argument_content_id.inc
diff -N includes/flag_handler_argument_content_id.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ includes/flag_handler_argument_content_id.inc	19 Sep 2008 11:56:08 -0000
@@ -0,0 +1,38 @@
+<?php
+// $Id$
+
+/**
+ * Handler to accept an argument of the content ID of any object.
+ *
+ * @ingroup views
+ */
+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;
+  }
+}
Index: includes/flag_handler_relationships.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/includes/Attic/flag_handler_relationships.inc,v
retrieving revision 1.1.2.3
diff -u -F^[^a-z]*function -r1.1.2.3 flag_handler_relationships.inc
--- includes/flag_handler_relationships.inc	18 Sep 2008 15:47:55 -0000	1.1.2.3
+++ includes/flag_handler_relationships.inc	19 Sep 2008 11:56:09 -0000
@@ -142,3 +142,47 @@   function query() {
     parent::query();
   }
 }
+
+/**
+ * Specialized relationship handler associating flags and users.
+ *
+ * @ingroup views
+ */
+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() {
+    $flag = flag_get_flag($this->options['flag']);
+    $this->definition['extra'][] = array(
+      'field' => 'fid',
+      'value' => $flag->fid,
+      'numeric' => TRUE,
+    );
+    parent::query();
+  }
+}
+
