Index: flag.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.inc,v
retrieving revision 1.1.2.1
diff -u -F^[^a-z]*function -r1.1.2.1 flag.inc
--- flag.inc	6 Jul 2008 08:22:08 -0000	1.1.2.1
+++ flag.inc	21 Jul 2008 17:59:25 -0000
@@ -273,6 +273,26 @@   function delete() {
     db_query('DELETE FROM {flag_types} WHERE fid = %d', $this->fid);
     db_query('DELETE FROM {flag_counts} WHERE fid = %d', $this->fid);
   }
+
+  /**
+   * Renders a flag/unflag link. This is a wrapper around theme('flag') that,
+   * in Drupal 6, easily channels the call to the right template file.
+   *
+   * For parameters docmentation, see theme_flag().
+   */
+  function theme($action, $content_id, $after_flagging = FALSE) {
+    return theme($this->theme_suggestions(), $this, $action, $content_id, $after_flagging);
+  }
+
+  /**
+   * Provides an array of possible themes to try for a given flag.
+   */
+  function theme_suggestions() {
+    $suggestions = array();
+    $suggestions[] = 'flag_' . $this->name;
+    $suggestions[] = 'flag';
+    return $suggestions;
+  }
 }
 
 /**
Index: flag.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/flag.js,v
retrieving revision 1.6.2.5
diff -u -F^[^a-z]*function -r1.6.2.5 flag.js
--- flag.js	22 Jun 2008 09:35:15 -0000	1.6.2.5
+++ flag.js	21 Jul 2008 17:59:25 -0000
@@ -8,7 +8,7 @@
      */
     function flipLink(element, settings) {
       // If this is a 'flag this' link...
-      if ($(element).is('.flag')) {
+      if ($(element).is('.flag-action')) {
         // ...then turn it into an 'unflag this' link;
         var newHtml = settings.unflag;
       }
@@ -115,10 +115,8 @@     function getLinkSettings(element) {
     }
 
     // On load, bind the click behavior for all links on the page.
-    for (flagName in Drupal.settings.flag.flags) {
-      $('a.flag-' + flagName).click(function() {
-        return flagClick(this, getLinkSettings(this));
-      });
-    }
+    $('a.flag').click(function() {
+      return flagClick(this, getLinkSettings(this));
+    });
   // Intentional extra indention.
 }
Index: flag.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/flag.module,v
retrieving revision 1.11.2.15
diff -u -F^[^a-z]*function -r1.11.2.15 flag.module
--- flag.module	17 Jul 2008 06:46:53 -0000	1.11.2.15
+++ flag.module	21 Jul 2008 17:59:27 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: flag.module,v 1.11.2.15 2008/07/17 06:46:53 mooffie Exp $
+// $Id: flag.module,v 1.11.2.14 2008/07/15 01:58:09 mooffie Exp $
 
 include_once dirname(__FILE__) .'/flag.inc';
 
@@ -129,12 +129,6 @@ function flag_content_enabled($flag, $co
 }
 
 /**
- * Helper function for adding the JavaScript behaviour.
- */
-function flag_add_js($nid, $flag_name, $flag_html, $unflag_html) {
-}
-
-/**
  * Processes the various flag labels for display. This means token replacements
  * and language translation.
  *
@@ -218,10 +212,11 @@ function flag_link($type, $object = NULL
     // Token replacements.
     $flag = flag_process_labels($flag, $type, $id, array('flag_short', 'flag_long', 'flag_message'), array('teaser' => $teaser));
 
+    $is_flagged = isset($flag_status[$flag->name]);
     // The flag links are actually fully rendered theme functions.
     // The HTML attribute is set to TRUE to allow whatever the themer desires.
     $links['flag-'. $flag->name] = array(
-      'title' => theme('flag', $flag, $type, $id, isset($flag_status[$flag->name])),
+      'title' => $flag->theme($is_flagged ? 'unflag' : 'flag', $id),
       'html' => TRUE,
     );
   }
@@ -805,12 +800,14 @@ function flag_mail($key, &$message, $par
  * Implementation of hook_theme().
  */
 function flag_theme() {
+  $path = drupal_get_path('module', 'flag') .'/theme';
+
   return array(
     'flag' => array(
-      'arguments' => array('flag' => NULL, 'content_type' => NULL, 'content_id' => NULL, 'is_flagged' => NULL),
-    ),
-    'flag_link' => array(
-      'arguments' => array('flag' => NULL, 'content_type' => NULL, 'content_id' => NULL, 'action' => NULL, 'after_flagging' => NULL),
+      'arguments' => array('flag' => NULL, 'action' => NULL, 'content_id' => NULL, 'after_flagging' => FALSE),
+      'template' => 'flag',
+      'pattern' => 'flag_',
+      'path' => $path,
     ),
     'flag_token_help' => array(
       'arguments' => array('types' => NULL, 'prefix' => NULL, 'suffix' => NULL),
@@ -822,18 +819,59 @@ function flag_theme() {
 }
 
 /**
- * Theme an entire flag link, including JavaScript behaviors.
+ * Theme an individual link and a message after the link is marked.
  *
  * @param $flag
  *   The flag object.
- * @param $content_type
- *   The type of content being flagged. Usually "node".
+ * @param $action
+ *   Which link to show: either "flag" or "unflag".
  * @param $content_id
  *   The ID of the content being flagged.
- * @param $is_flagged
- *   Boolean value of the current status of the flag being output.
+ * @param $after_flagging
+ *   This function is called for both the link both before and after being
+ *   flagged. If displaying to the user immediately after flagging, this value
+ *   will be boolean TRUE. This is usually used in conjunction with immedate
+ *   JavaScript-based toggling of flags.
+ */
+// function theme_flag(...) {
+//   // This function doesn't exist for Drupal 6. This stub exists so that we can document the parameters.
+// }
+
+/**
+ * A preprocess function for our theme('flag'). It generates the
+ * variables needed there.
+ *
+ * See 'flag.tpl.php' for documentation for these variables.
+ *
+ * Note: The Drupal 5 version of this module calls this function directly.
+ */
+function template_preprocess_flag(&$variables) {
+  // Some typing shotcuts:
+  $flag =& $variables['flag'];
+  $action = $variables['action'];
+
+  // Add the JS portion to the page. But be careful: _flag_add_js() calls
+  // this function back, to generate links to store in some JS array, so we guard
+  // against recursion.
+  if (!$variables['after_flagging']) {
+    _flag_add_js($flag, $action, $variables['content_id']);
+  }
+
+  $variables['link_href'] = check_url(url("flag/$action/$flag->name/$flag->content_type/$variables[content_id]", array('query' => drupal_get_destination())));
+  $variables['link_text'] = $flag->{$action .'_short'};
+  $variables['link_title'] = strip_tags($flag->{$action .'_long'});
+  $variables['flag_name_css'] = str_replace('_', '-', $flag->name);
+  $variables['last_action'] = ($action == 'flag' ? 'unflagged' : 'flagged');
+  if ($variables['after_flagging']) {
+    $inverse_action = ($action == 'flag' ? 'unflag' : 'flag');
+    $variables['message_text'] = $flag->{$inverse_action .'_message'};
+  }
+}
+
+/**
+ * Helper function for adding the JavaScript behaviour.
  */
-function theme_flag($flag, $content_type, $content_id, $is_flagged) {
+function _flag_add_js(&$flag, $action, $content_id) {
   static $added_flags, $js_added;
 
   // Add initial JS/CSS to the page.
@@ -845,41 +883,12 @@ function theme_flag($flag, $content_type
   }
 
   // Add JavaScript copies of the links so we can swap them out when the user clicks.
-  if (!(isset($added_flags[$flag->name][$content_type][$content_id]))) {
-    $flag_html = theme('flag_link', $flag, $content_type, $content_id, 'flag', TRUE);
-    $unflag_html = theme('flag_link', $flag, $content_type, $content_id, 'unflag', TRUE);
-    drupal_add_js(array('flag' => array('flags' => array($flag->name => array($content_type .'_'. $content_id => array('flag' => $flag_html, 'unflag' => $unflag_html))))), 'setting');
-    $added_flags[$flag->name][$content_type][$content_id] = TRUE;
+  if (!(isset($added_flags[$flag->name][$flag->content_type][$content_id]))) {
+    $flag_html = $flag->theme('flag', $content_id, TRUE);
+    $unflag_html = $flag->theme('unflag', $content_id, TRUE);
+    drupal_add_js(array('flag' => array('flags' => array($flag->name => array($flag->content_type .'_'. $content_id => array('flag' => $flag_html, 'unflag' => $unflag_html))))), 'setting');
+    $added_flags[$flag->name][$flag->content_type][$content_id] = TRUE;
   }
-
-  return theme('flag_link', $flag, $content_type, $content_id, $is_flagged ? 'unflag' : 'flag');
-}
-
-/**
- * Theme an individual link and a message after the link is marked.
- *
- * @param $flag
- *   The flag object.
- * @param $content_type
- *   The type of content being flagged. Usually "node".
- * @param $content_id
- *   The ID of the content being flagged.
- * @param $action
- *   Either "flag" or "unflag".
- * @param $after_flagging
- *   This function is called for both the link both before and after being
- *   flagged. If displaying to the user immediately after flagging, this value
- *   will be boolean TRUE. This is usually used in conjunction with immedate
- *   JavaScript-based toggling of flags.
- */
-function theme_flag_link($flag, $content_type, $content_id, $action, $after_flagging = FALSE) {
-  $output = '<span class="flag-wrapper">';
-  $output .= l($flag->{$action .'_short'}, 'flag/'. $action .'/'. $flag->name .'/'. $content_type .'/'. $content_id, array('query' => drupal_get_destination(), 'attributes' => array('title' => $flag->{$action .'_long'}, 'class' => $action .' flag-'. $flag->name . ($after_flagging ? ($action == 'flag' ? ' unflagged' : ' flagged') : ''))));
-  if ($after_flagging) {
-    $output .= '<span class="flag-message flag-'. $action .'-message">'. $flag->{($action == 'flag' ? 'unflag' : 'flag') .'_message'} .'</span>';
-  }
-  $output .= '</span>';
-  return $output;
 }
 
 /**
@@ -1153,6 +1162,7 @@ function flag_create_link($flag_name, $c
 
   $flag = flag_process_labels($flag, $flag->content_type, $content_id, array('flag_short', 'flag_long', 'flag_message'));
   $flag_status = flag_get_user_flags($flag->content_type, $content_id);
-  return theme('flag', $flag, $flag->content_type, $content_id, isset($flag_status[$flag->name]));
+  $is_flagged = isset($flag_status[$flag->name]);
+  return $flag->theme($is_flagged ? 'unflag' : 'flag', $content_id);
 }
 
Index: flag.views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/flag.views.inc,v
retrieving revision 1.6.2.4
diff -u -F^[^a-z]*function -r1.6.2.4 flag.views.inc
--- flag.views.inc	14 Jul 2008 03:22:50 -0000	1.6.2.4
+++ flag.views.inc	21 Jul 2008 17:59:27 -0000
@@ -381,7 +381,7 @@   function render($values) {
 
     // Token replacements.
     $flag = flag_process_labels($flag, $flag->content_type, $content_id, array('flag_short', 'flag_long', 'flag_message'));
-    return theme('flag', $flag, $flag->content_type, $content_id, $is_flagged);
+    return $flag->theme($is_flagged ? 'unflag' : 'flag', $content_id);
   }
 }
 
