commit 76e2e7c3c67fc47eae4b1040e925e614d764f206
Author: Assos Assos <assos+forge@centrale-marseille.fr>
Date:   Wed May 7 22:33:54 2014 +0200

    Weekly update of contrib modules

diff --git a/drupal7/sites/all/modules/flag/flag.api.php b/drupal7/sites/all/modules/flag/flag.api.php
index a37805da..9b8cbfe2 100644
--- a/drupal7/sites/all/modules/flag/flag.api.php
+++ b/drupal7/sites/all/modules/flag/flag.api.php
@@ -58,11 +58,11 @@ function hook_flag_type_info_alter(&$definitions) {
  */
 function hook_flag_default_flags() {
   $flags = array();
-  $flags['bookmarks'] = array (
+  $flags['bookmarks'] = array(
     'entity_type' => 'node',
     'title' => 'Bookmarks',
     'global' => FALSE,
-    'types' => array (
+    'types' => array(
       0 => 'article',
       1 => 'blog',
     ),
@@ -75,7 +75,7 @@ function hook_flag_default_flags() {
     'unflag_denied_text' => '',
     'link_type' => 'toggle',
     'weight' => 0,
-    'show_in_links' => array (
+    'show_in_links' => array(
       'full' => TRUE,
       'token' => FALSE,
     ),
@@ -90,10 +90,22 @@ function hook_flag_default_flags() {
   return $flags;
 }
 
+/**
+ * Alter the definition of default flags.
+ *
+ * @param array &$flags
+ *   An array keyed by flag machine name containing flag definitions.
+ */
+function hook_flag_default_flags_alter(&$flags) {
+  if (!empty($flags['bookmark'])) {
+    $flags['bookmark']['title'] = 'Bananana Bookmark';
+  }
+}
+
 /**
  * Allow modules to alter a flag when it is initially loaded.
  *
- * @see flag_get_flags().
+ * @see flag_get_flags()
  */
 function hook_flag_alter(&$flag) {
 
@@ -183,7 +195,7 @@ function hook_flag_validate($action, $flag, $entity_id, $account, $skip_permissi
       $count = count($flags[$flag->name]);
       if ($count >= 2) {
         // Users may flag only 2 nodes with this flag.
-        return(array('access-denied' => t('You may only flag 2 nodes with the test flag.')));
+        return (array('access-denied' => t('You may only flag 2 nodes with the test flag.')));
       }
     }
   }
diff --git a/drupal7/sites/all/modules/flag/flag.info b/drupal7/sites/all/modules/flag/flag.info
index 242d5416..bd6db1bb 100644
--- a/drupal7/sites/all/modules/flag/flag.info
+++ b/drupal7/sites/all/modules/flag/flag.info
@@ -29,9 +29,9 @@ files[] = includes/views/flag_handler_relationships.inc
 files[] = includes/views/flag_plugin_argument_validate_flaggability.inc
 files[] = tests/flag.test
 
-; Information added by Drupal.org packaging script on 2014-03-18
-version = "7.x-3.4"
+; Information added by Drupal.org packaging script on 2014-05-03
+version = "7.x-3.5"
 core = "7.x"
 project = "flag"
-datestamp = "1395128956"
+datestamp = "1399113834"
 
diff --git a/drupal7/sites/all/modules/flag/flag.info.inc b/drupal7/sites/all/modules/flag/flag.info.inc
index 69bbb5c7..890e624d 100644
--- a/drupal7/sites/all/modules/flag/flag.info.inc
+++ b/drupal7/sites/all/modules/flag/flag.info.inc
@@ -1,7 +1,8 @@
 <?php
 
 /**
- * @file Contains Entity API property information.
+ * @file
+ * Contains Entity API property information.
  */
 
 /**
diff --git a/drupal7/sites/all/modules/flag/flag.install b/drupal7/sites/all/modules/flag/flag.install
index 1932e4d2..5e2063a9 100644
--- a/drupal7/sites/all/modules/flag/flag.install
+++ b/drupal7/sites/all/modules/flag/flag.install
@@ -113,7 +113,7 @@ function flag_schema() {
         'not null' => TRUE,
         'default' => 0,
         'disp-size' => 11,
-      )
+      ),
     ),
     'primary key' => array('flagging_id'),
     'unique keys' => array(
@@ -121,7 +121,12 @@ function flag_schema() {
     ),
     'indexes' => array(
       'entity_type_uid_sid' => array('entity_type', 'uid', 'sid'),
-      'entity_type_entity_id_uid_sid' => array('entity_type', 'entity_id', 'uid', 'sid'),
+      'entity_type_entity_id_uid_sid' => array(
+        'entity_type',
+        'entity_id',
+        'uid',
+        'sid',
+      ),
       'entity_id_fid' => array('entity_id', 'fid'),
     ),
   );
@@ -190,7 +195,7 @@ function flag_schema() {
         'not null' => TRUE,
         'default' => 0,
         'disp-size' => 11,
-      )
+      ),
     ),
     'primary key' => array('fid', 'entity_id'),
     'indexes' => array(
@@ -296,7 +301,11 @@ function flag_update_6200() {
 function flag_update_6201() {
   // Remove "content type" from one key, see http://drupal.org/node/612602.
   db_drop_unique_key('flag_content', 'fid_content_type_content_id_uid');
-  db_add_unique_key('flag_content', 'fid_content_id_uid', array('fid', 'content_id', 'uid'));
+  db_add_unique_key('flag_content', 'fid_content_id_uid', array(
+    'fid',
+    'content_id',
+    'uid',
+  ));
 
   // Add a count index, see http://drupal.org/node/489610.
   db_add_index('flag_counts', 'count', array('count'));
@@ -311,11 +320,25 @@ function flag_update_6202() {
   db_drop_index('flag_content', 'content_type_uid');
 
   // Add the column.
-  db_add_field('flag_content', 'sid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
+  db_add_field('flag_content', 'sid', array(
+    'type' => 'int',
+    'unsigned' => TRUE,
+    'not null' => TRUE,
+    'default' => 0,
+  ));
 
   // Re-add the removed keys.
-  db_add_unique_key('flag_content', 'fid_content_id_uid_sid', array('fid', 'content_id', 'uid', 'sid'));
-  db_add_index('flag_content', 'content_type_uid_sid', array('content_type', 'uid', 'sid'));
+  db_add_unique_key('flag_content', 'fid_content_id_uid_sid', array(
+    'fid',
+    'content_id',
+    'uid',
+    'sid',
+  ));
+  db_add_index('flag_content', 'content_type_uid_sid', array(
+    'content_type',
+    'uid',
+    'sid',
+  ));
 }
 
 /**
@@ -357,14 +380,25 @@ function flag_update_6206() {
     db_drop_unique_key('flag_content', 'content_type_content_id_uid_sid');
   }
 
-  db_add_index('flag_content', 'content_type_content_id_uid_sid', array('content_type', 'content_id', 'uid', 'sid'));
+  db_add_index('flag_content', 'content_type_content_id_uid_sid', array(
+    'content_type',
+    'content_id',
+    'uid',
+    'sid',
+  ));
 }
 
 /**
  * Adds column last_updated to flag_counts table.
  */
 function flag_update_6207() {
-  db_add_field('flag_counts', 'last_updated', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-size' => 11), array('indexes' => array('last_updated' => array('last_updated'))));
+  db_add_field('flag_counts', 'last_updated', array(
+    'type' => 'int',
+    'unsigned' => TRUE,
+    'not null' => TRUE,
+    'default' => 0,
+    'disp-size' => 11),
+    array('indexes' => array('last_updated' => array('last_updated'))));
 }
 
 /**
@@ -482,7 +516,12 @@ function flag_update_7303() {
       ),
       'indexes' => array(
         'entity_type_uid_sid' => array('entity_type', 'uid', 'sid'),
-        'entity_type_content_id_uid_sid' => array('entity_type', 'content_id', 'uid', 'sid'),
+        'entity_type_content_id_uid_sid' => array(
+          'entity_type',
+          'content_id',
+          'uid',
+          'sid',
+        ),
         'content_id_fid' => array('content_id', 'fid'),
       ),
     )
@@ -510,7 +549,12 @@ function flag_update_7303() {
         'fid_entity_id_uid_sid' => array('fid', 'entity_id', 'uid', 'sid'),
       ),
       'indexes' => array(
-        'entity_type_entity_id_uid_sid' => array('entity_type', 'entity_id', 'uid', 'sid'),
+        'entity_type_entity_id_uid_sid' => array(
+          'entity_type',
+          'entity_id',
+          'uid',
+          'sid',
+        ),
         'entity_id_fid' => array('entity_id', 'fid'),
       ),
     )
@@ -569,7 +613,7 @@ function flag_update_7304() {
       'indexes' => array(
         'fid_entity_type' => array('fid', 'entity_type'),
         'entity_type_content_id' => array('entity_type', 'content_id'),
-      )
+      ),
     )
   );
 
@@ -671,7 +715,8 @@ function flag_update_7306() {
     }
 
     // Update show_on_comment and show_on_entity properties to use new view
-    // mode settings. Since the old logic was to show on all view modes, do that.
+    // mode settings. Since the old logic was to show on all view modes, do
+    // that.
     if (!empty($flag->show_on_entity) || !empty($flag->show_on_comment)) {
       if ($entity_info = entity_get_info($flag->entity_type)) {
         foreach ($entity_info['view modes'] as $view_mode => $value) {
diff --git a/drupal7/sites/all/modules/flag/flag.module b/drupal7/sites/all/modules/flag/flag.module
index ca06c2cc..76f9e5f8 100644
--- a/drupal7/sites/all/modules/flag/flag.module
+++ b/drupal7/sites/all/modules/flag/flag.module
@@ -160,14 +160,15 @@ function flagging_save($flagging) {
 // @todo: flag_reset_flag():
 // - it should delete the flaggings.
 // - (it has other issues; see http://drupal.org/node/894992.)
-// - (is problematic: it might not be possible to delete all data in a single page request.)
+// - (is problematic: it might not be possible to delete all data in a single
+//   page request.)
 
 // @todo: Discuss: Note that almost all functions/identifiers dealing with
 // flaggings *aren't* prefixed by "flag_". For example:
-//  - The menu argument is %flagging, not %flag_flagging.
-//  - The entity type is "flagging", not "flag_flagging".
-// On the one hand this succinct version is readable and nice. On the other hand, it isn't
-// very "correct".
+// - The menu argument is %flagging, not %flag_flagging.
+// - The entity type is "flagging", not "flag_flagging".
+// On the one hand this succinct version is readable and nice. On the other
+// hand, it isn't very "correct".
 
 /**
  * Implements hook_entity_query_alter().
@@ -182,7 +183,8 @@ function flag_entity_query_alter(EntityFieldQuery $query) {
 
   // Alter only flagging queries with bundle conditions.
   if (isset($conditions['entity_type']) && $conditions['entity_type']['value'] == 'flagging' && isset($conditions['bundle'])) {
-    $query->addTag('flagging_flag_names'); // Add tag to alter query.
+    // Add tag to alter query.
+    $query->addTag('flagging_flag_names');
     // Make value and operator of the bundle condition accessible
     // in hook_query_TAG_alter.
     $query->addMetaData('flag_name_value', $conditions['bundle']['value']);
@@ -253,7 +255,8 @@ function flag_menu() {
   );
 
   $items[FLAG_ADMIN_PATH . '/manage/%flag'] = array(
-    'load arguments' => array(TRUE), // Allow for disabled flags.
+    // Allow for disabled flags.
+    'load arguments' => array(TRUE),
     'page callback' => 'drupal_get_form',
     'page arguments' => array('flag_form', FLAG_ADMIN_PATH_START + 1),
     'access callback' => 'user_access',
@@ -265,7 +268,8 @@ function flag_menu() {
     'title arguments' => array(FLAG_ADMIN_PATH_START + 1),
   );
   $items[FLAG_ADMIN_PATH . '/manage/%flag/edit'] = array(
-    'load arguments' => array(TRUE), // Allow for disabled flags.
+    // Allow for disabled flags.
+    'load arguments' => array(TRUE),
     'title' => 'Edit flag',
     'type' => MENU_DEFAULT_LOCAL_TASK,
     'weight' => -10,
@@ -289,7 +293,8 @@ function flag_menu() {
     'type' => MENU_CALLBACK,
   );
   $items[FLAG_ADMIN_PATH . '/manage/%flag/update'] = array(
-    'load arguments' => array(TRUE), // Allow for disabled flags.
+    // Allow for disabled flags.
+    'load arguments' => array(TRUE),
     'title' => 'Update',
     'page callback' => 'flag_update_page',
     'page arguments' => array(FLAG_ADMIN_PATH_START + 1),
@@ -416,9 +421,11 @@ function flag_help($path, $arg) {
     case FLAG_ADMIN_PATH:
       $output = '<p>' . t('This page lists all the <em>flags</em> that are currently defined on this system.') . '</p>';
       return $output;
+
     case FLAG_ADMIN_PATH . '/add':
       $output = '<p>' . t('Select the type of flag to create. An individual flag can only affect one type of object. This cannot be changed once the flag is created.') . '</p>';
       return $output;
+
     case FLAG_ADMIN_PATH . '/manage/%/fields':
       // Get the existing link types that provide a flagging form.
       $link_types = flag_get_link_types();
@@ -572,10 +579,10 @@ function flag_get_types() {
 function flag_create_handler($entity_type) {
   $definition = flag_fetch_definition($entity_type);
   if (isset($definition) && class_exists($definition['handler'])) {
-    $handler = new $definition['handler'];
+    $handler = new $definition['handler']();
   }
   else {
-    $handler = new flag_broken;
+    $handler = new flag_broken();
   }
   $handler->entity_type = $entity_type;
   $handler->construct();
@@ -662,7 +669,7 @@ function flag_field_extra_fields() {
         $extra[$flag->entity_type][$bundle_name]['form']['flag'] = array(
           'label' => t('Flags'),
           'description' => t('Checkboxes for toggling flags'),
-          'weight' => 10
+          'weight' => 10,
         );
       }
 
@@ -730,7 +737,7 @@ function flag_form_node_type_form_alter(&$form, &$form_state, $form_id) {
  * Warning: will not work on entity types that are not fieldable, as this relies
  * on a field module hook.
  *
- * @see flag_field_attach_submit().
+ * @see flag_field_attach_submit()
  */
 function flag_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
   list($id) = entity_extract_ids($entity_type, $entity);
@@ -839,7 +846,7 @@ function flag_field_attach_form($entity_type, $entity, &$form, &$form_state, $la
 /**
  * Implements hook_field_attach_submit().
  *
- * @see flag_field_attach_form().
+ * @see flag_field_attach_form()
  */
 function flag_field_attach_submit($entity_type, $entity, $form, &$form_state) {
   // This is invoked for each flag_field_attach_form(), but possibly more than
@@ -877,7 +884,7 @@ function flag_field_attach_update($entity_type, $entity) {
 /**
  * Shared saving routine between flag_field_attach_insert/update().
  *
- * @see flag_field_attach_form().
+ * @see flag_field_attach_form()
  */
 function flag_field_attach_save($entity_type, $entity) {
   list($id) = entity_extract_ids($entity_type, $entity);
@@ -918,13 +925,14 @@ function flag_contextual_links_view_alter(&$element, $items) {
 
       list($entity_id) = entity_extract_ids($entity_type, $entity);
       if (!$flag->access($entity_id) && (!$flag->is_flagged($entity_id) || !$flag->access($entity_id, 'flag'))) {
-        // User has no permission to use this flag or flag does not apply to this
-        // object. The link is not skipped if the user has "flag" access but
-        // not "unflag" access (this way the unflag denied message is shown).
+        // User has no permission to use this flag or flag does not apply to
+        // this object. The link is not skipped if the user has "flag" access
+        // but not "unflag" access (this way the unflag denied message is
+        // shown).
         continue;
       }
 
-      $element['#links']['flag-'. $name] = array(
+      $element['#links']['flag-' . $name] = array(
         'title' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id),
         'html' => TRUE,
       );
@@ -981,7 +989,7 @@ function flag_entity_view($entity, $type, $view_mode, $langcode) {
     // The pseudofield output.
     if ($flag->show_as_field) {
       $entity->content['flag_' . $flag->name] = array(
-       '#markup' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id, array('needs_wrapping_element' => TRUE)),
+        '#markup' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id, array('needs_wrapping_element' => TRUE)),
       );
     }
   }
@@ -1359,8 +1367,9 @@ function flag_flag_trigger($action, $flag, $entity_id, $account, $flagging) {
   $object = $flag->fetch_entity($entity_id);
 
   // Generic "all flags" actions.
-  foreach (trigger_get_assigned_actions('flag_' . $action)  as $aid => $action_info) {
-    // The 'if ($aid)' is a safeguard against http://drupal.org/node/271460#comment-886564
+  foreach (trigger_get_assigned_actions('flag_' . $action) as $aid => $action_info) {
+    // The 'if ($aid)' is a safeguard against
+    // http://drupal.org/node/271460#comment-886564
     if ($aid) {
       actions_do($aid, $object, $context);
     }
@@ -1559,7 +1568,7 @@ function template_preprocess_flag(&$variables) {
   $flag =& $variables['flag'];
   $action = $variables['action'];
   $entity_id = $variables['entity_id'];
-  $errors = join('<br />', $variables['errors']);
+  $errors = implode('<br />', $variables['errors']);
   $flag_css_name = str_replace('_', '-', $flag->name);
 
   // Generate the link URL.
@@ -1629,7 +1638,8 @@ function template_preprocess_flag(&$variables) {
       $variables['message_classes_array'][] = 'flag-' . $variables['status'] . '-message';
       $variables['message_text'] = $flag->get_label($inverse_action . '_message', $entity_id);
       $variables['flag_classes_array'][] = $variables['status'];
-      // By default we make our JS code remove, after a few seconds, only success messages.
+      // By default we make our JS code remove, after a few seconds, only
+      // success messages.
       $variables['message_classes_array'][] = 'flag-auto-remove';
     }
   }
@@ -1725,7 +1735,7 @@ function flag_get_entity_flag_counts($flag, $entity_type) {
       ->countQuery()
       ->execute()
       ->fetchField();
-    $counts[$flag->name][$entity_type] =  $result;
+    $counts[$flag->name][$entity_type] = $result;
   }
 
   return $counts[$flag->name][$entity_type];
@@ -1894,7 +1904,14 @@ function flag_get_flags($entity_type = NULL, $content_subtype = NULL, $account =
     $query = db_select('flag', 'f');
     $query->leftJoin('flag_types', 'fn', 'fn.fid = f.fid');
     $result = $query
-      ->fields('f', array('fid', 'entity_type', 'name', 'title', 'global', 'options'))
+      ->fields('f', array(
+        'fid',
+        'entity_type',
+        'name',
+        'title',
+        'global',
+        'options',
+      ))
       ->fields('fn', array('type'))
       ->execute();
     foreach ($result as $row) {
@@ -1919,7 +1936,8 @@ function flag_get_flags($entity_type = NULL, $content_subtype = NULL, $account =
         // Ensure overridden flags are associated with their parent module.
         $flags[$name]->module = $default_flag->module;
 
-        // Update the flag with any properties that are "locked" by the code version.
+        // Update the flag with any properties that are "locked" by the code
+        // version.
         if (isset($default_flag->locked)) {
           $flags[$name]->locked = $default_flag->locked;
           foreach ($default_flag->locked as $property) {
@@ -1988,32 +2006,39 @@ function flag_get_default_flags($include_disabled = FALSE) {
   $default_flags = array();
   $flag_status = variable_get('flag_default_flag_status', array());
 
+  $default_flags_info = array();
   foreach (module_implements('flag_default_flags') as $module) {
     $function = $module . '_flag_default_flags';
     foreach ($function() as $flag_name => $flag_info) {
       // Backward compatibility: old exported default flags have their names
-      // in $flag_info instead, so we use the += operator to not overwrite it.
-      $flag_info += array(
+      // in $flag_info instead, so we use the + operator to not overwrite it.
+      $default_flags_info[$flag_name] = $flag_info + array(
         'name' => $flag_name,
         'module' => $module,
       );
-      $flag = flag_flag::factory_by_array($flag_info);
+    }
+  }
 
-      // Disable flags that are not at the current API version.
-      if (!$flag->is_compatible()) {
-        $flag->status = FALSE;
-      }
+  // Allow modules to alter definitions using hook_flag_default_flags_alter().
+  drupal_alter('flag_default_flags', $default_flags_info);
 
-      // Add flags that have been enabled.
-      if ((!isset($flag_status[$flag->name]) && (!isset($flag->status) || $flag->status)) || !empty($flag_status[$flag->name])) {
-        $flag->status = TRUE;
-        $default_flags[$flag->name] = $flag;
-      }
-      // Add flags that have been disabled.
-      elseif ($include_disabled) {
-        $flag->status = FALSE;
-        $default_flags[$flag->name] = $flag;
-      }
+  foreach ($default_flags_info as $flag_info) {
+    $flag = flag_flag::factory_by_array($flag_info);
+
+    // Disable flags that are not at the current API version.
+    if (!$flag->is_compatible()) {
+      $flag->status = FALSE;
+    }
+
+    // Add flags that have been enabled.
+    if ((!isset($flag_status[$flag->name]) && (!isset($flag->status) || $flag->status)) || !empty($flag_status[$flag->name])) {
+      $flag->status = TRUE;
+      $default_flags[$flag->name] = $flag;
+    }
+    // Add flags that have been disabled.
+    elseif ($include_disabled) {
+      $flag->status = FALSE;
+      $default_flags[$flag->name] = $flag;
     }
   }
 
@@ -2067,11 +2092,15 @@ function flag_get_flag_flagging_data($flag_name) {
  * @return
  *   If returning a single item's flags (that is, when $entity_id isn't NULL),
  *   an array of the structure
- *   [flag_name] => (flagging_id => [flagging_id], uid => [uid], entity_id => [entity_id], timestamp => [timestamp], ...)
+ *   [flag_name] => (
+ *     flagging_id => [flagging_id],
+ *     uid => [uid],
+ *     entity_id => [entity_id],
+ *     timestamp => [timestamp],
+ *     ...)
  *
  *   If returning all items' flags, an array of arrays for each flag:
  *   [flag_name] => [entity_id] => Object from above.
- *
  */
 function flag_get_user_flags($entity_type, $entity_id = NULL, $uid = NULL, $sid = NULL) {
   $flagged_content = &drupal_static(__FUNCTION__);
@@ -2250,10 +2279,10 @@ function flag_trim_flag($flag, $account, $cutoff_size, $trim_newest, $permission
     $query->orderBy('timestamp', 'ASC');
   }
   else {
-    $query->orderBy('timestamp', 'DESC') ;
+    $query->orderBy('timestamp', 'DESC');
   }
 
-  // Execute the query
+  // Execute the query.
   $result = $query->execute();
 
   $i = 1;
@@ -2289,7 +2318,7 @@ function flag_reset_flag($flag, $entity_id = NULL) {
   }
   module_invoke_all('flag_reset', $flag, $entity_id, $rows);
 
-  $query = db_delete('flagging')->condition('fid' , $flag->fid);
+  $query = db_delete('flagging')->condition('fid', $flag->fid);
   // Update the flag_counts table.
   $count_query = db_delete('flag_counts')->condition('fid', $flag->fid);
   if ($entity_id) {
@@ -2608,6 +2637,6 @@ function flag_properties_get_flagging_users($entity, array $options, $name, $ent
  * @ingroup callbacks
  */
 function flag_properties_get_user_sid($entity, array $options, $name, $entity_type, $property_info) {
-  $sid =  flag_get_sid($entity->uid, FALSE);
+  $sid = flag_get_sid($entity->uid, FALSE);
   return $sid;
 }
diff --git a/drupal7/sites/all/modules/flag/flag.rules.inc b/drupal7/sites/all/modules/flag/flag.rules.inc
index ba0b2c66..60abc450 100644
--- a/drupal7/sites/all/modules/flag/flag.rules.inc
+++ b/drupal7/sites/all/modules/flag/flag.rules.inc
@@ -81,7 +81,7 @@ class FlagRulesUIClass extends RulesDataUI implements RulesDataDirectInputFormIn
       '#required' => empty($info['optional']),
       '#multiple' => FALSE,
       '#default_value' => $settings[$name],
-      '#empty' => t('There is no suiting flag available.')
+      '#empty' => t('There is no suiting flag available.'),
     );
     return $form;
   }
@@ -375,9 +375,10 @@ function flag_rules_action_info() {
       'access callback' => 'flag_rules_integration_access',
     );
   }
-  // For backward compatibility sake. This was the original name of the 'fetch node by user'.
+  // For backward compatibility sake. This was the original name of the
+  // 'fetch node by user'.
   $items['flag_fetch_entity_by_user'] = $items['flag_fetch_node_by_user'];
-  $items['flag_fetch_entity_by_user']['label'] .= ' '. t('(Legacy)');
+  $items['flag_fetch_entity_by_user']['label'] .= ' ' . t('(Legacy)');
   return $items;
 }
 
@@ -424,19 +425,23 @@ function flag_rules_action_fetch_users($flag, $entity) {
 }
 
 /**
- * Base action implementation: Fetch entities who were flagged a user.
+ * Base action implementation: Fetch entities flagged by a user.
  */
 function flag_rules_action_fetch_entity_by_user($flag, $entity) {
-  $user = entity_metadata_wrapper('user', $entity);
-  $sid = $user->flag_sid->value();
   $query = db_select('flagging', 'fc')
     ->fields('fc', array('entity_id'))
     ->condition('entity_type', $flag->entity_type)
-    ->condition('uid', $user->uid->value())
     ->condition('fid', $flag->fid);
-  // Filter out any bad session ids and any users that aren't anonymous.
-  if (!empty($sid) && $sid != -1) {
-    $query->condition('sid', $sid);
+  // For global flags the user parameter is ignored, so we add the
+  // extra 'uid' condition when the flag is NOT global.
+  if (!$flag->global) {
+    $user = entity_metadata_wrapper('user', $entity);
+    $sid = $user->flag_sid->value();
+    $query = $query->condition('uid', $user->uid->value());
+    // Filter out any bad session ids and any users that aren't anonymous.
+    if (!empty($sid) && $sid != -1) {
+      $query->condition('sid', $sid);
+    }
   }
   $result = $query->execute();
   $flagged = $result->fetchCol();
@@ -469,7 +474,8 @@ function flag_rules_get_flag_types() {
 }
 
 /**
- * Base action implementation: Fetch count of flags for a particular entity type.
+ * Base action implementation: Fetch count of flags for a particular entity
+ * type.
  *
  * During a flagging, the current flagging will be included in the count.
  * During an unflagging, the current flagging being removed will not yet have
@@ -509,7 +515,7 @@ function flag_rules_condition_info() {
             'type' => 'flag',
             'label' => t('Flag'),
             'flag_type' => $type,
-            'description' => t('The flag to check for.')
+            'description' => t('The flag to check for.'),
           ),
           $type => array(
             'type' => $type,
@@ -545,7 +551,7 @@ function flag_rules_condition_info() {
             'type' => 'flag',
             'label' => t('Flag'),
             'flag_type' => $type,
-            'description' => t('The flag to check for.')
+            'description' => t('The flag to check for.'),
           ),
           $type => array(
             'type' => $type,
@@ -566,7 +572,8 @@ function flag_rules_condition_info() {
 }
 
 /**
- * Options list callback for the operator parameter of the flagging threshold condition.
+ * Options list callback for the operator parameter of the flagging threshold
+ * condition.
  */
 function flag_rules_condition_threshold_operator_options() {
   return array(
@@ -588,10 +595,10 @@ function flag_rules_condition_threshold($flag, $entity, $number, $operator = '='
   $count = $flag->get_count($flag->get_entity_id($entity));
 
   switch ($operator) {
-    case '>' : return $count >  $number;
+    case '>': return $count > $number;
     case '>=': return $count >= $number;
-    case '=' : return $count == $number;
-    case '<' : return $count <  $number;
+    case '=': return $count == $number;
+    case '<': return $count < $number;
     case '<=': return $count <= $number;
   }
 }
diff --git a/drupal7/sites/all/modules/flag/flag.tokens.inc b/drupal7/sites/all/modules/flag/flag.tokens.inc
index cae4d88a..77a06c55 100644
--- a/drupal7/sites/all/modules/flag/flag.tokens.inc
+++ b/drupal7/sites/all/modules/flag/flag.tokens.inc
@@ -123,6 +123,7 @@ function flag_tokens($type, $tokens, array $data = array(), array $options = arr
         case 'name':
           $replacements[$original] = $sanitize ? check_plain($flag->name) : $flag->name;
           break;
+
         case 'title':
           $replacements[$original] = $sanitize ? check_plain($flag->get_title()) : $flag->get_title();
           break;
@@ -149,18 +150,23 @@ function flag_tokens($type, $tokens, array $data = array(), array $options = arr
         case 'action':
           $replacements[$original] = $action->action;
           break;
+
         case 'entity-url':
           $replacements[$original] = $sanitize ? check_url($action->entity_url) : $action->entity_url;
           break;
+
         case 'entity-title':
           $replacements[$original] = $sanitize ? check_plain($action->entity_title) : $action->entity_title;
           break;
+
         case 'entity-type':
           $replacements[$original] = $action->entity_type;
           break;
+
         case 'entity-id':
           $replacements[$original] = $action->entity_id;
           break;
+
         case 'count':
           $replacements[$original] = $action->count;
           break;
diff --git a/drupal7/sites/all/modules/flag/flag_actions.info b/drupal7/sites/all/modules/flag/flag_actions.info
index 2d8f51bc..5e50d49e 100644
--- a/drupal7/sites/all/modules/flag/flag_actions.info
+++ b/drupal7/sites/all/modules/flag/flag_actions.info
@@ -7,9 +7,9 @@ configure = admin/structure/flags/actions
 
 files[] = flag.install
 files[] = flag_actions.module
-; Information added by Drupal.org packaging script on 2014-03-18
-version = "7.x-3.4"
+; Information added by Drupal.org packaging script on 2014-05-03
+version = "7.x-3.5"
 core = "7.x"
 project = "flag"
-datestamp = "1395128956"
+datestamp = "1399113834"
 
diff --git a/drupal7/sites/all/modules/flag/flag_actions.module b/drupal7/sites/all/modules/flag/flag_actions.module
index f4c3aedf..4870e617 100644
--- a/drupal7/sites/all/modules/flag/flag_actions.module
+++ b/drupal7/sites/all/modules/flag/flag_actions.module
@@ -379,7 +379,7 @@ function theme_flag_actions_add_form($variables) {
   $fieldset = array(
     '#type' => 'fieldset',
     '#title' => t('Add a new flag action'),
-    '#children' => '<div class="container-inline">'. drupal_render($form['flag']) . drupal_render($form['submit']) .'</div>',
+    '#children' => '<div class="container-inline">' . drupal_render($form['flag']) . drupal_render($form['submit']) . '</div>',
     '#parents' => array('add_action'),
     '#attributes' => array(),
     '#groups' => array('add_action' => array()),
@@ -397,7 +397,6 @@ function theme_flag_actions_add_form($variables) {
  *   If editing an action, an action ID must be passed in.
  * @param $flag_name
  *   If adding a new action to a flag, a flag name must be specified.
- *
  */
 function flag_actions_form($form, &$form_state, $aid = NULL, $flag_name = NULL) {
   // This is a multistep form. Get the callback value if set and continue.
@@ -422,7 +421,7 @@ function flag_actions_form($form, &$form_state, $aid = NULL, $flag_name = NULL)
 
   $form['new'] = array(
     '#type' => 'value',
-    '#value' => isset($callback) ? FALSE: TRUE,
+    '#value' => isset($callback) ? FALSE : TRUE,
   );
 
   if (!isset($callback)) {
@@ -430,7 +429,7 @@ function flag_actions_form($form, &$form_state, $aid = NULL, $flag_name = NULL)
 
     $actions = $flag->get_valid_actions();
     $options = array();
-    foreach($actions as $key => $action) {
+    foreach ($actions as $key => $action) {
       $options[$key] = $action['label'];
     }
 
@@ -449,7 +448,7 @@ function flag_actions_form($form, &$form_state, $aid = NULL, $flag_name = NULL)
   }
   elseif (!isset($action)) {
     $actions = $flag->get_valid_actions();
-    $action = (object)$actions[$callback];
+    $action = (object) $actions[$callback];
     $action->parameters = array();
     $action->event = 'flag';
     $action->threshold = 10;
@@ -512,7 +511,7 @@ function flag_actions_form($form, &$form_state, $aid = NULL, $flag_name = NULL)
   }
 
   // Merge in the standard flag action form.
-  $action_form = $callback .'_form';
+  $action_form = $callback . '_form';
   $edit = array();
   if (function_exists($action_form)) {
     $edit += $action->parameters;
@@ -524,7 +523,7 @@ function flag_actions_form($form, &$form_state, $aid = NULL, $flag_name = NULL)
   }
 
   // Add a few customizations to existing flag actions.
-  $flag_actions_form = 'flag_actions_'. $callback .'_form';
+  $flag_actions_form = 'flag_actions_' . $callback . '_form';
   if (function_exists($flag_actions_form)) {
     $flag_actions_form($form, $flag, $edit);
   }
diff --git a/drupal7/sites/all/modules/flag/flag_bookmark/flag_bookmark.info b/drupal7/sites/all/modules/flag/flag_bookmark/flag_bookmark.info
index 82fa37fe..8ecf9c38 100644
--- a/drupal7/sites/all/modules/flag/flag_bookmark/flag_bookmark.info
+++ b/drupal7/sites/all/modules/flag/flag_bookmark/flag_bookmark.info
@@ -4,9 +4,9 @@ core = 7.x
 dependencies[] = flag
 package = Flags
 
-; Information added by Drupal.org packaging script on 2014-03-18
-version = "7.x-3.4"
+; Information added by Drupal.org packaging script on 2014-05-03
+version = "7.x-3.5"
 core = "7.x"
 project = "flag"
-datestamp = "1395128956"
+datestamp = "1399113834"
 
diff --git a/drupal7/sites/all/modules/flag/flag_bookmark/flag_bookmark.install b/drupal7/sites/all/modules/flag/flag_bookmark/flag_bookmark.install
index 284784a7..62646125 100644
--- a/drupal7/sites/all/modules/flag/flag_bookmark/flag_bookmark.install
+++ b/drupal7/sites/all/modules/flag/flag_bookmark/flag_bookmark.install
@@ -13,7 +13,7 @@
  */
 function flag_bookmark_enable() {
   // Load the flag API in case we want to use it when enabling.
-  include_once(drupal_get_path('module', 'flag') . '/flag.module');
+  include_once drupal_get_path('module', 'flag') . '/flag.module';
 
   if (!flag_get_flags()) {
     // Install a demonstration flag only if no flag exists. This is to prevent
@@ -21,24 +21,24 @@ function flag_bookmark_enable() {
     // flag is overwritten or re-created.
     $flag = flag_flag::factory_by_entity_type('node');
     $configuration = array(
-        'name' => 'bookmarks',
-        'global' => 0,
-        'show_in_links' => array(
-          'full' => 1,
-          'teaser' => 1,
-        ),
-        'show_on_form' => 1,
-        // The following UI labels aren't wrapped in t() because they are written
-        // to the DB in English. They are passed to t() later, thus allowing for
-        // multilingual sites.
-        'title' => 'Bookmarks',
-        'flag_short' => 'Bookmark this',
-        'flag_long' => 'Add this post to your bookmarks',
-        'flag_message' => 'This post has been added to your bookmarks',
-        'unflag_short' => 'Unbookmark this',
-        'unflag_long' => 'Remove this post from your bookmarks',
-        'unflag_message' => 'This post has been removed from your bookmarks',
-        'types' => _flag_bookmark_install_get_suggested_node_types(),
+      'name' => 'bookmarks',
+      'global' => 0,
+      'show_in_links' => array(
+        'full' => 1,
+        'teaser' => 1,
+      ),
+      'show_on_form' => 1,
+      // The following UI labels aren't wrapped in t() because they are written
+      // to the DB in English. They are passed to t() later, thus allowing for
+      // multilingual sites.
+      'title' => 'Bookmarks',
+      'flag_short' => 'Bookmark this',
+      'flag_long' => 'Add this post to your bookmarks',
+      'flag_message' => 'This post has been added to your bookmarks',
+      'unflag_short' => 'Unbookmark this',
+      'unflag_long' => 'Remove this post from your bookmarks',
+      'unflag_message' => 'This post has been removed from your bookmarks',
+      'types' => _flag_bookmark_install_get_suggested_node_types(),
     );
     $flag->form_input($configuration);
     $flag->save();
@@ -53,7 +53,8 @@ function flag_bookmark_enable() {
 }
 
 /**
- * Returns some node types to which the demonstration 'bookmarks' flag will apply.
+ * Returns some node types to which the demonstration 'bookmarks' flag will
+ * apply.
  */
 function _flag_bookmark_install_get_suggested_node_types() {
   $preferred = array('article', 'story', 'forum', 'blog');
@@ -64,4 +65,3 @@ function _flag_bookmark_install_get_suggested_node_types() {
   }
   return $existing;
 }
-
diff --git a/drupal7/sites/all/modules/flag/includes/flag.actions.inc b/drupal7/sites/all/modules/flag/includes/flag.actions.inc
index f414431e..c9209718 100644
--- a/drupal7/sites/all/modules/flag/includes/flag.actions.inc
+++ b/drupal7/sites/all/modules/flag/includes/flag.actions.inc
@@ -15,7 +15,7 @@ function flag_trigger_info() {
         'label' => t('Object has been flagged with any flag'),
       ),
       'flag_unflag' => array(
-        'label' => t('Object has been unflagged with any flag')
+        'label' => t('Object has been unflagged with any flag'),
       ),
     ),
   );
diff --git a/drupal7/sites/all/modules/flag/includes/flag.admin.inc b/drupal7/sites/all/modules/flag/includes/flag.admin.inc
index 190ceb77..3ed0e26d 100644
--- a/drupal7/sites/all/modules/flag/includes/flag.admin.inc
+++ b/drupal7/sites/all/modules/flag/includes/flag.admin.inc
@@ -77,10 +77,10 @@ function theme_flag_admin_listing($variables) {
 
   foreach ($flags as $flag) {
     $ops = array(
-      'flags_edit' =>  array('title' => t('edit'), 'href' => $flag->admin_path('edit')),
-      'flags_fields' =>  array('title' => t('manage fields'), 'href' => $flag->admin_path('fields')),
-      'flags_delete' =>  array('title' => t('delete'), 'href' => $flag->admin_path('delete')),
-      'flags_export' =>  array('title' => t('export'), 'href' => $flag->admin_path('export')),
+      'flags_edit' => array('title' => t('edit'), 'href' => $flag->admin_path('edit')),
+      'flags_fields' => array('title' => t('manage fields'), 'href' => $flag->admin_path('fields')),
+      'flags_delete' => array('title' => t('delete'), 'href' => $flag->admin_path('delete')),
+      'flags_export' => array('title' => t('export'), 'href' => $flag->admin_path('export')),
     );
     if (!module_exists('field_ui')) {
       unset($ops['flags_fields']);
@@ -116,7 +116,13 @@ function theme_flag_admin_listing($variables) {
   if (count($flags) > 1) {
     $header[] = t('Weight');
   }
-  $header = array_merge($header, array(t('Flag type'), t('Roles'), t('Entity bundles'), t('Global?'), t('Operations')));
+  $header = array_merge($header, array(
+    t('Flag type'),
+    t('Roles'),
+    t('Entity bundles'),
+    t('Global?'),
+    t('Operations'),
+  ));
   $output .= theme('table', array(
     'header' => $header,
     'rows' => $rows,
@@ -142,7 +148,11 @@ function theme_flag_admin_listing_disabled($variables) {
       $ops = array();
       if (!$flag->is_compatible()) {
         $flag_updates_needed = TRUE;
-        $ops['flags_update'] = array('title' => '<strong>' . t('update code') . '</strong>', 'href' => $flag->admin_path('update'), 'html' => TRUE);
+        $ops['flags_update'] = array(
+          'title' => '<strong>' . t('update code') . '</strong>',
+          'href' => $flag->admin_path('update'),
+          'html' => TRUE,
+        );
       }
       else {
         $ops['flags_enable'] = array('title' => t('enable'), 'href' => $flag->admin_path('edit'));
@@ -163,7 +173,12 @@ function theme_flag_admin_listing_disabled($variables) {
   }
 
   if (!empty($rows)) {
-    $header = array(t('Disabled Flags'), t('Module'), t('Flag type'), t('Operations'));
+    $header = array(
+      t('Disabled Flags'),
+      t('Module'),
+      t('Flag type'),
+      t('Operations'),
+    );
     $output .= theme('table', array('header' => $header, 'rows' => $rows));
   }
 
@@ -379,17 +394,17 @@ function flag_form($form, &$form_state, $flag) {
     '#title' => t('Token replacement'),
     '#type' => 'fieldset',
     '#description' =>
-      '<p>' . t('The above six texts may contain any of the tokens listed below. For example, <em>"Flag link text"</em> could be entered as:') . '</p>' .
-      theme('item_list', array(
-        'items' => array(
-          t('Add &lt;em&gt;[node:title]&lt;/em&gt; to your favorites'),
-          t('Add this [node:type] to your favorites'),
-          t('Vote for this proposal ([node:flag-vote-count] people have already done so)'),
-        ),
-        'attributes' => array('class' => 'token-examples'),
-      )) .
-      '<p>' . t('These tokens will be replaced with the appropriate fields from the node (or user, or comment).') . '</p>' .
-      theme('flag_tokens_browser', array('types' => $flag->get_labels_token_types())),
+    '<p>' . t('The above six texts may contain any of the tokens listed below. For example, <em>"Flag link text"</em> could be entered as:') . '</p>' .
+    theme('item_list', array(
+      'items' => array(
+        t('Add &lt;em&gt;[node:title]&lt;/em&gt; to your favorites'),
+        t('Add this [node:type] to your favorites'),
+        t('Vote for this proposal ([node:flag-vote-count] people have already done so)'),
+      ),
+      'attributes' => array('class' => 'token-examples'),
+    )) .
+    '<p>' . t('These tokens will be replaced with the appropriate fields from the node (or user, or comment).') . '</p>' .
+    theme('flag_tokens_browser', array('types' => $flag->get_labels_token_types())),
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
   );
diff --git a/drupal7/sites/all/modules/flag/includes/flag.cookie_storage.inc b/drupal7/sites/all/modules/flag/includes/flag.cookie_storage.inc
index 856f582e..07a3dfea 100644
--- a/drupal7/sites/all/modules/flag/includes/flag.cookie_storage.inc
+++ b/drupal7/sites/all/modules/flag/includes/flag.cookie_storage.inc
@@ -2,7 +2,7 @@
 
 /**
  * @file
- *   Contains the FlagCookieStorage class.
+ * Contains the FlagCookieStorage class.
  */
 
 /**
diff --git a/drupal7/sites/all/modules/flag/includes/flag.export.inc b/drupal7/sites/all/modules/flag/includes/flag.export.inc
index 539899c3..64f7f465 100644
--- a/drupal7/sites/all/modules/flag/includes/flag.export.inc
+++ b/drupal7/sites/all/modules/flag/includes/flag.export.inc
@@ -15,7 +15,8 @@
  *   in hook_flag_default_flags().
  */
 function flag_export_flags($flags = array(), $module = '', $indent = '') {
-  module_load_include('inc', 'features', 'features.export'); // For features_var_export() (optional).
+  // For features_var_export() (optional).
+  module_load_include('inc', 'features', 'features.export');
   $output = $indent . '$flags = array();' . "\n";
   foreach ($flags as $item) {
     if (is_object($item)) {
@@ -269,7 +270,7 @@ function flag_update_export(&$flag) {
     if (substr($class, 0, 11) == 'FlagUpdate_') {
       // @todo: change this to work with the static class when we drop support
       // for PHP 5.2: see commit d5b517.
-      $update_handler = new $class;
+      $update_handler = new $class();
       // Cast to string, as decimals as array keys seem to be rounded down to
       // ints, WTF PHP?
       $version = (string) $update_handler->old_api_version;
@@ -364,7 +365,8 @@ class FlagUpdate_3 {
     }
 
     // Update show_on_comment and show_on_entity properties to use new view
-    // mode settings. Since the old logic was to show on all view modes, do that.
+    // mode settings. Since the old logic was to show on all view modes, do
+    // that.
     if (!empty($flag->show_on_entity) || !empty($flag->show_on_comment)) {
       if ($entity_info = entity_get_info($flag->entity_type)) {
         foreach ($entity_info['view modes'] as $view_mode => $value) {
diff --git a/drupal7/sites/all/modules/flag/includes/flag.pages.inc b/drupal7/sites/all/modules/flag/includes/flag.pages.inc
index 0bb21ce6..611f4413 100644
--- a/drupal7/sites/all/modules/flag/includes/flag.pages.inc
+++ b/drupal7/sites/all/modules/flag/includes/flag.pages.inc
@@ -93,7 +93,7 @@ function flag_confirm($form, &$form_state, $action, $flag, $entity_id) {
 
   $question = $flag->get_label($action . '_confirmation', $entity_id);
   $path = isset($_GET['destination']) ? $_GET['destination'] : '<front>';
-  $yes = $flag->get_label($action . '_short', $entity_id);
+  $yes = strip_tags($flag->get_label($action . '_short', $entity_id));
 
   if ($action == 'flag') {
     // If the action 'flag', we're potentially about to create a new
@@ -101,11 +101,41 @@ function flag_confirm($form, &$form_state, $action, $flag, $entity_id) {
     $flagging = $flag->new_flagging($entity_id);
     field_attach_form('flagging', $flagging, $form, $form_state);
     $form['#flagging'] = $flagging;
+
+    // Take the same approach as Core entity forms: shove all the entity
+    // properties into the form as values so that entity_form_field_validate()
+    // can build a pseudoentity from $form_values in the validate handler.
+    foreach (array(
+      'flag_name',
+      'entity_type',
+      'entity_id',
+      'uid',
+    ) as $key) {
+      $form[$key] = array(
+        '#type' => 'value',
+        '#value' => isset($flagging->$key) ? $flagging->$key : NULL,
+      );
+    }
   }
 
   return confirm_form($form, $question, $path, '', $yes);
 }
 
+/**
+ * Validate handler for the flag confirm form.
+ *
+ * Validate any Field API fields on the Flagging.
+ *
+ * @see flag_confirm()
+ */
+function flag_confirm_validate($form, &$form_state) {
+  // Only validate the entity fields when we're saving an entity.
+  $action = $form_state['values']['action'];
+  if ($action == 'flag') {
+    entity_form_field_validate('flagging', $form, $form_state);
+  }
+}
+
 /**
  * Submit handler for the flag confirm form.
  *
diff --git a/drupal7/sites/all/modules/flag/includes/flag/flag_comment.inc b/drupal7/sites/all/modules/flag/includes/flag/flag_comment.inc
index 58b15fc5..70560239 100644
--- a/drupal7/sites/all/modules/flag/includes/flag/flag_comment.inc
+++ b/drupal7/sites/all/modules/flag/includes/flag/flag_comment.inc
@@ -2,7 +2,7 @@
 
 /**
  * @file
- *   Contains the flag_comment class.
+ * Contains the flag_comment class.
  */
 
 /**
diff --git a/drupal7/sites/all/modules/flag/includes/flag/flag_entity.inc b/drupal7/sites/all/modules/flag/includes/flag/flag_entity.inc
index 8b7fa5ad..b356472e 100644
--- a/drupal7/sites/all/modules/flag/includes/flag/flag_entity.inc
+++ b/drupal7/sites/all/modules/flag/includes/flag/flag_entity.inc
@@ -2,7 +2,7 @@
 
 /**
  * @file
- *   Contains the flag_entity class.
+ * Contains the flag_entity class.
  */
 
 /**
@@ -58,7 +58,8 @@ class flag_entity extends flag_flag {
     }
     // Select the first display option by default if this is a new flag.
     if (empty($this->fid)) {
-      $first_view_mode = reset(array_keys($entity_view_modes));
+      $first_view_mode_keys = array_keys($entity_view_modes);
+      $first_view_mode = reset($first_view_mode_keys);
       $defaults[$first_view_mode] = $first_view_mode;
     }
 
@@ -159,6 +160,37 @@ class flag_entity extends flag_flag {
     );
   }
 
+  /**
+   * Invoke a Rules event in reaction to a flagging or unflagging.
+   *
+   * @param $action
+   *   Either 'flag' or 'unflag'.
+   * @param $flagging
+   *  The flagging entity that is to be removed.
+   * @param $entity_id
+   *  The entity ID of entity being unflagged.
+   * @param $account
+   *  The account performing the unflagging.
+   */
+  protected function invoke_rules_event($action, $flagging, $entity_id, $account) {
+    switch ($action) {
+      case 'flag':
+        $event_name = 'flag_flagged_' . $this->name;
+        break;
+      case 'unflag':
+        $event_name = 'flag_unflagged_' . $this->name;
+        break;
+    }
+
+    $variables = array(
+      'flag' => $this,
+      'flagged_' . $this->entity_type => $entity_id,
+      'flagging_user' => $account,
+      'flagging' => $flagging,
+    );
+    rules_invoke_event_by_args($event_name, $variables);
+  }
+
   /**
    * Returns the entity id, if it already exists.
    */
diff --git a/drupal7/sites/all/modules/flag/includes/flag/flag_flag.inc b/drupal7/sites/all/modules/flag/includes/flag/flag_flag.inc
index 44e7a7a1..aa9b5b2d 100644
--- a/drupal7/sites/all/modules/flag/includes/flag/flag_flag.inc
+++ b/drupal7/sites/all/modules/flag/includes/flag/flag_flag.inc
@@ -2,13 +2,14 @@
 
 /**
  * @file
- *  Contains the flag_flag class.
- *  Flag type classes use an object oriented style inspired by that
- *  of Views 2.
+ * Contains the flag_flag class.
+ * Flag type classes use an object oriented style inspired by that
+ * of Views 2.
  */
 
 /**
- * This abstract class represents a flag, or, in Views 2 terminology, "a handler".
+ * This abstract class represents a flag, or, in Views 2 terminology,
+ * "a handler".
  *
  * This is the base class for all flag implementations. Notable derived
  * classes are flag_node and flag_comment.
@@ -29,8 +30,8 @@
  * - flag_flag::factory_by_array(), creates a flag handler from a configuration
  *   array. This is used by flag_get_default_flags() and the flag import form.
  * - flag_flag::factory_by_entity_type(), creates an empty flag handler for the
- *   given entity type. This is used when a new or dummy flag handler is required
- *   and there is no configuration yet.
+ *   given entity type. This is used when a new or dummy flag handler is
+ *   required and there is no configuration yet.
  *
  * The factory methods in turn all call the low-level function
  * flag_create_handler(), which obtains the correct handler for the flag, or if
@@ -94,7 +95,8 @@ class flag_flag {
   );
 
   /**
-   * An associative array containing textual errors that may be created during validation.
+   * An associative array containing textual errors that may be created during
+   * validation.
    *
    * The array keys should reflect the type of error being set. At this time,
    * the only "special" behavior related to the array keys is that
@@ -103,7 +105,7 @@ class flag_flag {
    *
    * @var array
    */
-  var $errors = array();
+  public $errors = array();
 
   /**
    * Creates a flag from a database row. Returns it.
@@ -135,7 +137,8 @@ class flag_flag {
     }
 
     if (!empty($row->type)) {
-      // The loop loading from the database should further populate this property.
+      // The loop loading from the database should further populate this
+      // property.
       $flag->types[] = $row->type;
     }
 
@@ -189,7 +192,8 @@ class flag_flag {
       'unflag_long' => '',
       'unflag_message' => '',
       'unflag_denied_text' => '',
-      // The link type used by the flag, as defined in hook_flag_link_type_info().
+      // The link type used by the flag, as defined in
+      // hook_flag_link_type_info().
       'link_type' => 'toggle',
       'weight' => 0,
     );
@@ -245,7 +249,8 @@ class flag_flag {
    */
   function form_input($form_values) {
     // Load the form fields indiscriminately unto the flag (we don't care about
-    // stray FormAPI fields because we aren't touching unknown properties anyway.
+    // stray FormAPI fields because we aren't touching unknown properties
+    // anyway).
     foreach ($form_values as $field => $value) {
       $this->$field = $value;
     }
@@ -626,18 +631,18 @@ class flag_flag {
    *   TRUE if the flag is enabled for this type and subtype.
    */
   function access_entity_enabled($entity_type, $content_subtype = NULL) {
-   $entity_type_matches = ($this->entity_type == $entity_type);
-   $sub_type_matches = FALSE;
-   if (!isset($content_subtype) || !count($this->types)) {
-     // Subtype automatically matches if we're not asked about it,
-     // or if the flag applies to all subtypes.
-     $sub_type_matches = TRUE;
-   }
-   else {
-     $sub_type_matches = in_array($content_subtype, $this->types);
-   }
-   return $entity_type_matches && $sub_type_matches;
- }
+    $entity_type_matches = ($this->entity_type == $entity_type);
+    $sub_type_matches = FALSE;
+    if (!isset($content_subtype) || !count($this->types)) {
+      // Subtype automatically matches if we're not asked about it,
+      // or if the flag applies to all subtypes.
+      $sub_type_matches = TRUE;
+    }
+    else {
+      $sub_type_matches = in_array($content_subtype, $this->types);
+    }
+    return $entity_type_matches && $sub_type_matches;
+  }
 
   /**
    * Determine whether the flag should show a flag link in entity links.
@@ -685,6 +690,10 @@ class flag_flag {
    *   - to update field data an existing flagging. The $action parameter should
    *     be set to 'flag'. The Flagging entity will need to be loaded first with
    *     flagging_load().
+   *  As with Drupal core API functions for saving entities, no validation of
+   *  Field API fields is performed here. It is the responsibility of the caller
+   *  to take care of Field API validation, using either
+   *  field_attach_form_validate() or field_attach_validate().
    *
    * @return
    *   FALSE if some error occured (e.g., user has no permission, flag isn't
@@ -695,9 +704,6 @@ class flag_flag {
     if (!isset($account)) {
       $account = $GLOBALS['user'];
     }
-    if (!$account) {
-      return FALSE;
-    }
 
     // Check access and applicability.
     if (!$skip_permission_check) {
@@ -736,112 +742,47 @@ class flag_flag {
       }
     }
 
-    // Set our uid and sid to the flagging object.
+    // @todo: Discuss: Core wraps everything in a try { }, should we?
+
+    $existing_flagging_id = $this->_is_flagged($entity_id, $uid, $sid);
+    $flagged = (bool) $existing_flagging_id;
+
+    // Ensure we have a Flagging entity and it is correctly formed.
     if (isset($flagging)) {
+      // We were given a Flagging entity.
+      // Ensure that it has the uid and sid that we were also given.
       $flagging->uid = $uid;
       $flagging->sid = $sid;
-    }
 
-    // @todo: Discuss: Should we call field_attach_validate()? None of the
-    // entities in core does this (fields entered through forms are already
-    // validated).
-    //
-    // @todo: Discuss: Core wraps everything in a try { }, should we?
+      // This is an ugly hack to preserve previous behaviour.
+      $flagging->given_as_parameter = TRUE;
+    }
+    else {
+      // We were not given a Flagging entity.
+      if ($flagged) {
+        // Load the existing Flagging entity.
+        $flagging = flagging_load($existing_flagging_id);
+      }
+      else {
+        // Construct a new Flagging entity to flag with.
+        $flagging = $this->new_flagging($entity_id, $uid, $sid);
+      }
+    }
 
     // Perform the flagging or unflagging of this flag.
-    $existing_flagging_id = $this->_is_flagged($entity_id, $uid, $sid);
-    $flagged = (bool) $existing_flagging_id;
     if ($action == 'unflag') {
-      if ($this->uses_anonymous_cookies()) {
-        $this->_unflag_anonymous($entity_id);
-      }
       if ($flagged) {
-        if (!isset($flagging)) {
-          $flagging = flagging_load($existing_flagging_id);
-        }
-        $transaction = db_transaction();
-        try {
-          // Note the order: We decrease the count first so hooks have accurate
-          // data, then invoke hooks, then delete the flagging entity.
-          $this->_decrease_count($entity_id);
-          module_invoke_all('flag_unflag', $this, $entity_id, $account, $flagging);
-          // Invoke Rules event.
-          if (module_exists('rules')) {
-            $event_name = 'flag_unflagged_' . $this->name;
-            // We only support flags on entities.
-            if (entity_get_info($this->entity_type)) {
-              $variables = array(
-                'flag' => $this,
-                'flagged_' . $this->entity_type => $entity_id,
-                'flagging_user' => $account,
-                'flagging' => $flagging,
-              );
-              rules_invoke_event_by_args($event_name, $variables);
-            }
-          }
-          $this->_delete_flagging($flagging);
-          $this->_unflag($entity_id, $flagging->flagging_id);
-        }
-        catch (Exception $e) {
-          $transaction->rollback();
-          watchdog_exception('flag', $e);
-          throw $e;
-        }
+        $this->flagging_delete($flagging, $entity_id, $account);
       }
+      // We do nothing in the case of an attempt to unflag something that isn't
+      // actually flagged.
     }
     elseif ($action == 'flag') {
-      if ($this->uses_anonymous_cookies()) {
-        $this->_flag_anonymous($entity_id);
-      }
-
-      // By definition there is no flagging entity yet, but we may have been
-      // passed one in to save.
-      if (!isset($flagging)) {
-        // Construct a new flagging object if we weren't passed one.
-        $flagging = $this->new_flagging($entity_id, $uid, $sid);
-      }
-
-      // Invoke hook_entity_presave().
-      // In the case that we have been passed in a flagging entity to update,
-      // this is technically still a presave, even though the {flagging} table
-      // itself is not changed.
-      module_invoke_all('entity_presave', $flagging, 'flagging');
-
       if (!$flagged) {
-        // The entity is unflagged.
-
-        // Save the flagging entity (just our table).
-        $this->_flag($flagging);
-        $this->_increase_count($entity_id);
-        // We're writing out a flagging entity even when we aren't passed one
-        // (e.g., when flagging via JavaScript toggle links); in this case
-        // Field API will assign the fields their default values.
-        $this->_insert_flagging($flagging);
-        module_invoke_all('flag_flag', $this, $entity_id, $account, $flagging);
-        // Invoke Rules event.
-        if (module_exists('rules')) {
-          $event_name = 'flag_flagged_' . $this->name;
-          // We only support flags on entities.
-          if (entity_get_info($this->entity_type)) {
-            $variables = array(
-              'flag' => $this,
-              'flagged_' . $this->entity_type => $entity_id,
-              'flagging_user' => $account,
-              'flagging' => $this->get_flagging($entity_id, $account->uid),
-            );
-            rules_invoke_event_by_args($event_name, $variables);
-          }
-        }
+        $this->flagging_insert($flagging, $entity_id, $account);
       }
       else {
-        // Nothing to do. Item is already flagged.
-        //
-        // Except in the case a $flagging object is one that was passed in: in
-        // this case we're being requested to update the flagging. This occurs,
-        // for example, when the user updates the flagging entity form.
-        if (!empty($flagging->flagging_id)) {
-          $this->_update_flagging($flagging);
-        }
+        $this->flagging_update($flagging, $entity_id, $account);
       }
     }
 
@@ -849,37 +790,159 @@ class flag_flag {
   }
 
   /**
-   * The entity CRUD methods _{insert,update,delete}_flagging() are for private
-   * use by the flag() method.
+   * Create a new Flagging to flag an entity.
    *
-   * The reason programmers should not call them directly is because a flagging
-   * operation is also accompanied by some bookkeeping (calling hooks, updating
-   * counters) or access control. These tasks are handled by the flag() method.
+   * @param $flagging
+   *  The flagging entity that is to be removed.
+   * @param $entity_id
+   *  The entity ID of entity being unflagged.
+   * @param $account
+   *  The account performing the unflagging.
    */
-  private function _insert_flagging($flagging) {
+  private function flagging_insert($flagging, $entity_id, $account) {
+    if ($this->uses_anonymous_cookies()) {
+      $this->_flag_anonymous($entity_id);
+    }
+
+    // Invoke presave hooks.
     field_attach_presave('flagging', $flagging);
+    // Invoke hook_entity_presave().
+    module_invoke_all('entity_presave', $flagging, 'flagging');
+
+    // Set the timestamp.
+    $flagging->timestamp = REQUEST_TIME;
+
+    // Save the flagging entity.
+    drupal_write_record('flagging', $flagging);
+
+    // Clear various caches; we don't want code running after us to report
+    // wrong counts or false flaggings.
+    drupal_static_reset('flag_get_user_flags');
+    drupal_static_reset('flag_get_entity_flags');
+    // Despite being named in the same pattern as the count API functions, these
+    // query the {flagging} table, so are reset here.
+    drupal_static_reset('flag_get_entity_flag_counts');
+    drupal_static_reset('flag_get_user_flag_counts');
+
+    $this->_increase_count($entity_id);
+    // We're writing out a flagging entity even when we aren't passed one
+    // (e.g., when flagging via JavaScript toggle links); in this case
+    // Field API will assign the fields their default values.
+
+    // Invoke insert hooks.
     field_attach_insert('flagging', $flagging);
     // Invoke hook_entity_insert().
     module_invoke_all('entity_insert', $flagging, 'flagging');
+
+    module_invoke_all('flag_flag', $this, $entity_id, $account, $flagging);
+    // Invoke Rules event.
+    if (module_exists('rules')) {
+      $this->invoke_rules_event('flag', $flagging, $entity_id, $account);
+    }
   }
-  private function _update_flagging($flagging) {
+
+  /**
+   * Invoke a Rules event in reaction to a flagging or unflagging.
+   *
+   * @param $action
+   *   Either 'flag' or 'unflag'.
+   * @param $flagging
+   *  The flagging entity that is to be removed.
+   * @param $entity_id
+   *  The entity ID of entity being unflagged.
+   * @param $account
+   *  The account performing the unflagging.
+   */
+  protected function invoke_rules_event($action, $flagging, $entity_id, $account) {
+    // We only support flags on entities: do nothing in this class.
+    // See flag_entity::invoke_rules_event().
+    return;
+  }
+
+  /**
+   * Update a Flagging.
+   *
+   * @param $flagging
+   *  The flagging entity that is to be removed.
+   * @param $entity_id
+   *  The entity ID of entity being unflagged.
+   * @param $account
+   *  The account performing the unflagging.
+   */
+  private function flagging_update($flagging, $entity_id, $account) {
+    // Invoke presave hooks.
+    // This is technically still a presave, even though the {flagging} table
+    // itself is not changed.
     field_attach_presave('flagging', $flagging);
-    field_attach_update('flagging', $flagging);
-    // Update the cache.
-    entity_get_controller('flagging')->resetCache();
-    // Invoke hook_entity_update().
-    // Since there are no fields on the {flagging} table that can be
-    // meaningfully changed, we don't perform an update on it. However, this
-    // technically still counts as updating the flagging entity, since we update
-    // its fields.
-    module_invoke_all('entity_update', $flagging, 'flagging');
+    // Invoke hook_entity_presave().
+    module_invoke_all('entity_presave', $flagging, 'flagging');
+
+    // This check exists solely to preserve previous behaviour with re-flagging.
+    // TODO: consider removing it.
+    if (!empty($flagging->given_as_parameter)) {
+      field_attach_update('flagging', $flagging);
+      // Update the cache.
+      entity_get_controller('flagging')->resetCache();
+      // Invoke hook_entity_update().
+      // Since there are no fields on the {flagging} table that can be
+      // meaningfully changed, we don't perform an update on it. However, this
+      // technically still counts as updating the flagging entity, since we update
+      // its fields.
+      module_invoke_all('entity_update', $flagging, 'flagging');
+    }
   }
-  private function _delete_flagging($flagging) {
-    field_attach_delete('flagging', $flagging);
-    // Remove from the cache.
-    entity_get_controller('flagging')->resetCache();
-    // Invoke hook_entity_delete().
-    module_invoke_all('entity_delete', $flagging, 'flagging');
+
+  /**
+   * Unflag an entity by deleting a Flagging.
+   *
+   * @param $flagging
+   *  The flagging entity that is to be removed.
+   * @param $entity_id
+   *  The entity ID of entity being unflagged.
+   * @param $account
+   *  The account performing the unflagging.
+   */
+  private function flagging_delete($flagging, $entity_id, $account) {
+    if ($this->uses_anonymous_cookies()) {
+      $this->_unflag_anonymous($entity_id);
+    }
+
+    $transaction = db_transaction();
+    try {
+      // Note the order: We decrease the count first so hooks have accurate
+      // data, then invoke hooks, then delete the flagging entity.
+      $this->_decrease_count($entity_id);
+      module_invoke_all('flag_unflag', $this, $entity_id, $account, $flagging);
+      // Invoke Rules event.
+      if (module_exists('rules')) {
+        $this->invoke_rules_event('unflag', $flagging, $entity_id, $account);
+      }
+
+      // Invoke hook_entity_delete().
+      module_invoke_all('entity_delete', $flagging, 'flagging');
+      // Delete field data.
+      field_attach_delete('flagging', $flagging);
+
+      // Delete the flagging entity.
+      db_delete('flagging')->condition('flagging_id', $flagging->flagging_id)->execute();
+
+      // Remove from the cache.
+      entity_get_controller('flagging')->resetCache();
+
+      // Clear various caches; we don't want code running after us to report
+      // wrong counts or false flaggings.
+      drupal_static_reset('flag_get_user_flags');
+      drupal_static_reset('flag_get_entity_flags');
+      // Despite being named in the same pattern as the count API functions, these
+      // query the {flagging} table, so are reset here.
+      drupal_static_reset('flag_get_entity_flag_counts');
+      drupal_static_reset('flag_get_user_flag_counts');
+    }
+    catch (Exception $e) {
+      $transaction->rollback();
+      watchdog_exception('flag', $e);
+      throw $e;
+    }
   }
 
   /**
@@ -986,54 +1049,6 @@ class flag_flag {
       ->fetchField();
   }
 
-  /**
-   * A low-level method to flag an object.
-   *
-   * You probably shouldn't call this raw private method: call the flag()
-   * function instead.
-   *
-   * @param
-   *   The flagging record.
-   *
-   * @private
-   */
-  function _flag($flagging) {
-    // Set the timestamp.
-    $flagging->timestamp = REQUEST_TIME;
-
-    drupal_write_record('flagging', $flagging);
-
-    // Clear various caches; we don't want code running after us to report
-    // wrong counts or false flaggings.
-    drupal_static_reset('flag_get_user_flags');
-    drupal_static_reset('flag_get_entity_flags');
-    // Despite being named in the same pattern as the count API functions, these
-    // query the {flagging} table, so are reset here.
-    drupal_static_reset('flag_get_entity_flag_counts');
-    drupal_static_reset('flag_get_user_flag_counts');
-  }
-
-  /**
-   * A low-level method to unflag an object.
-   *
-   * You probably shouldn't call this raw private method: call the flag()
-   * function instead.
-   *
-   * @private
-   */
-  function _unflag($entity_id, $flagging_id) {
-    db_delete('flagging')->condition('flagging_id', $flagging_id)->execute();
-
-    // Clear various caches; we don't want code running after us to report
-    // wrong counts or false flaggings.
-    drupal_static_reset('flag_get_user_flags');
-    drupal_static_reset('flag_get_entity_flags');
-    // Despite being named in the same pattern as the count API functions, these
-    // query the {flagging} table, so are reset here.
-    drupal_static_reset('flag_get_entity_flag_counts');
-    drupal_static_reset('flag_get_user_flag_counts');
-  }
-
   /**
    * Increases the flag count for an object and clears the static counts cache.
    *
@@ -1043,7 +1058,7 @@ class flag_flag {
    *   The amount of counts to increasing. Defaults to 1.
    *
    * @private
-  */
+   */
   function _increase_count($entity_id, $number = 1) {
     db_merge('flag_counts')
       ->key(array(
@@ -1076,7 +1091,7 @@ class flag_flag {
    *   The amount of counts to decrease. Defaults to 1.
    *
    * @private
-  */
+   */
   function _decrease_count($entity_id, $number = 1) {
     // Delete rows with count 0, for data consistency and space-saving.
     // Done before the db_update() to prevent out-of-bounds errors on "count".
@@ -1164,6 +1179,7 @@ class flag_flag {
    * @param $entity_id
    *   The ID in whose context to interpret tokens. If not given, only global
    *   tokens will be substituted.
+   *
    * @return
    *   The processed label.
    */
@@ -1511,8 +1527,8 @@ class flag_flag {
    * @param $variables = array()
    *  An array of further variables to pass to theme('flag'). For the full list
    *  of parameters, see flag.tpl.php. Of particular interest:
-   *  - after_flagging: Set to TRUE if this flag link is being displayed as the result
-   *    of a flagging action.
+   *  - after_flagging: Set to TRUE if this flag link is being displayed as the
+   *    result of a flagging action.
    *  - errors: An array of error messages.
    *
    * @return
diff --git a/drupal7/sites/all/modules/flag/includes/flag/flag_node.inc b/drupal7/sites/all/modules/flag/includes/flag/flag_node.inc
index 0b04d02a..005c7564 100644
--- a/drupal7/sites/all/modules/flag/includes/flag/flag_node.inc
+++ b/drupal7/sites/all/modules/flag/includes/flag/flag_node.inc
@@ -2,7 +2,7 @@
 
 /**
  * @file
- *   Contains the flag_node class.
+ * Contains the flag_node class.
  */
 
 /**
@@ -89,6 +89,7 @@ class flag_node extends flag_entity {
    *
    * @param $entity_id
    *   The nid for the content.
+   *
    * @return
    *   The tnid if available, the nid otherwise.
    */
diff --git a/drupal7/sites/all/modules/flag/includes/flag/flag_user.inc b/drupal7/sites/all/modules/flag/includes/flag/flag_user.inc
index 72dc2019..7ebbe6fc 100644
--- a/drupal7/sites/all/modules/flag/includes/flag/flag_user.inc
+++ b/drupal7/sites/all/modules/flag/includes/flag/flag_user.inc
@@ -2,7 +2,7 @@
 
 /**
  * @file
- *   Contains the flag_user class.
+ * Contains the flag_user class.
  */
 
 /**
diff --git a/drupal7/sites/all/modules/flag/includes/views/flag.views_convert.inc b/drupal7/sites/all/modules/flag/includes/views/flag.views_convert.inc
index ed8910df..206d5ca7 100644
--- a/drupal7/sites/all/modules/flag/includes/views/flag.views_convert.inc
+++ b/drupal7/sites/all/modules/flag/includes/views/flag.views_convert.inc
@@ -57,6 +57,7 @@ function flag_views_convert($display, $type, &$view, $field, $id) {
           $new_rel = 'flag_content_rel';
           $flag_content_rel_user = 'current';
           break;
+
         case 'count':
           $new_field = array(
             'label' => $field['label'],
@@ -67,6 +68,7 @@ function flag_views_convert($display, $type, &$view, $field, $id) {
           );
           $new_rel = 'flag_counts_rel';
           break;
+
         case 'name':
           $new_field = array(
             'label' => $field['label'],
@@ -95,6 +97,7 @@ function flag_views_convert($display, $type, &$view, $field, $id) {
           // Remove the old filter.
           $view->set_item('default', $type, $id, NULL);
           break;
+
         case 'timestamp':
           $new_field = array(
             'operator' => $field['operator'],
@@ -109,6 +112,7 @@ function flag_views_convert($display, $type, &$view, $field, $id) {
           $new_rel = 'flag_content_rel';
           drupal_set_message(t('Flag is not able to convert the <em>Flagged time</em> filter. It\'s value is currently empty, but needs to be populated to work properly.'), 'warning');
           break;
+
         case 'count':
           $new_field = array(
             'operator' => $field['operator'],
@@ -151,6 +155,7 @@ function flag_views_convert($display, $type, &$view, $field, $id) {
           );
           $new_rel = 'flag_counts_rel';
           break;
+
         case 'timestamp':
           $new_field = array(
             'order' => $field['sortorder'],
diff --git a/drupal7/sites/all/modules/flag/includes/views/flag_handler_argument_entity_id.inc b/drupal7/sites/all/modules/flag/includes/views/flag_handler_argument_entity_id.inc
index f5d3b1a0..21ccf8a8 100644
--- a/drupal7/sites/all/modules/flag/includes/views/flag_handler_argument_entity_id.inc
+++ b/drupal7/sites/all/modules/flag/includes/views/flag_handler_argument_entity_id.inc
@@ -27,12 +27,13 @@ class flag_handler_argument_entity_id extends views_handler_argument_numeric {
    */
   function title_query() {
     if (!($flag = $this->get_flag())) {
-      return array(); // Error message is printed by get_flag().
+      // Error message is printed by get_flag().
+      return array();
     }
     $views_info = $flag->get_views_info();
 
     $titles = array();
-    $placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
+    $placeholders = implode(', ', array_fill(0, count($this->value), '%d'));
 
     $result = db_select($views_info['views table'], 'o')
       ->fields('o', array($views_info['title field']))
diff --git a/drupal7/sites/all/modules/flag/includes/views/flag_handler_field_ops.inc b/drupal7/sites/all/modules/flag/includes/views/flag_handler_field_ops.inc
index 58830f11..125af26d 100644
--- a/drupal7/sites/all/modules/flag/includes/views/flag_handler_field_ops.inc
+++ b/drupal7/sites/all/modules/flag/includes/views/flag_handler_field_ops.inc
@@ -35,7 +35,8 @@ class flag_handler_field_ops extends views_handler_field {
   function get_parent_relationship() {
     $parent = $this->view->relationship[$this->options['relationship']]->options['relationship'];
     if (!$parent || $parent == 'none') {
-      return NULL; // Base query table.
+      // Base query table.
+      return NULL;
     }
     else {
       return $this->view->relationship[$parent]->alias;
@@ -66,7 +67,8 @@ class flag_handler_field_ops extends views_handler_field {
    */
   function query() {
     if (!($flag = $this->get_flag())) {
-      return; // Error message is printed in render().
+      // Error message is printed in render().
+      return;
     }
     $info = $flag->get_views_info();
     $parent = $this->get_parent_relationship();
@@ -128,7 +130,8 @@ class flag_handler_field_ops extends views_handler_field {
    */
   function pre_render(&$values) {
     if (!($flag = $this->get_flag())) {
-      return; // Error message is printed in render().
+      // Error message is printed in render().
+      return;
     }
 
     $ids = array();
@@ -144,7 +147,8 @@ class flag_handler_field_ops extends views_handler_field {
 
   function render($values) {
     if (!($flag = $this->get_flag())) {
-      return t('Missing flag'); // get_flag() itself will print a more detailed message.
+      // get_flag() itself will print a more detailed message.
+      return t('Missing flag');
     }
 
     $entity_id = $values->{$this->aliases['entity_id']};
diff --git a/drupal7/sites/all/modules/flag/includes/views/flag_handler_filter_flagged.inc b/drupal7/sites/all/modules/flag/includes/views/flag_handler_filter_flagged.inc
index d22c40bb..494859fe 100644
--- a/drupal7/sites/all/modules/flag/includes/views/flag_handler_filter_flagged.inc
+++ b/drupal7/sites/all/modules/flag/includes/views/flag_handler_filter_flagged.inc
@@ -21,7 +21,11 @@ class flag_handler_filter_flagged extends views_handler_filter_boolean_operator
     parent::options_form($form, $form_state);
     $form['value']['#type'] = 'radios';
     $form['value']['#title'] = t('Status');
-    $form['value']['#options'] = array(1 => t('Flagged'), 0 => t('Not flagged'), 'All' => t('All'));
+    $form['value']['#options'] = array(
+      1 => t('Flagged'),
+      0 => t('Not flagged'),
+      'All' => t('All'),
+    );
     $form['value']['#default_value'] = empty($this->options['value']) ? '0' : $this->options['value'];
     $form['value']['#description'] = '<p>' . t('This filter is only needed if the relationship used has the "Include only flagged content" option <strong>unchecked</strong>. Otherwise, this filter is useless, because all records are already limited to flagged content.') . '</p><p>' . t('By choosing <em>Not flagged</em>, it is possible to create a list of content <a href="@unflagged-url">that is specifically not flagged</a>.', array('@unflagged-url' => 'http://drupal.org/node/299335')) . '</p>';
   }
diff --git a/drupal7/sites/all/modules/flag/includes/views/flag_handler_relationships.inc b/drupal7/sites/all/modules/flag/includes/views/flag_handler_relationships.inc
index 9a7c9644..0ee05fc1 100644
--- a/drupal7/sites/all/modules/flag/includes/views/flag_handler_relationships.inc
+++ b/drupal7/sites/all/modules/flag/includes/views/flag_handler_relationships.inc
@@ -264,4 +264,3 @@ class flag_handler_relationship_user_content extends flag_handler_relationship {
     parent::query();
   }
 }
-
diff --git a/drupal7/sites/all/modules/flag/includes/views/flag_handler_sort_flagged.inc b/drupal7/sites/all/modules/flag/includes/views/flag_handler_sort_flagged.inc
index 63c27875..54fdd37f 100644
--- a/drupal7/sites/all/modules/flag/includes/views/flag_handler_sort_flagged.inc
+++ b/drupal7/sites/all/modules/flag/includes/views/flag_handler_sort_flagged.inc
@@ -14,7 +14,8 @@ class flag_handler_sort_flagged extends views_handler_sort {
 
   /**
    * Provide a list of options for the default sort form.
-   * Should be overridden by classes that don't override sort_form
+   *
+   * Should be overridden by classes that don't override sort_form.
    */
   function sort_options() {
     return array(
diff --git a/drupal7/sites/all/modules/flag/includes/views/flag_plugin_argument_validate_flaggability.inc b/drupal7/sites/all/modules/flag/includes/views/flag_plugin_argument_validate_flaggability.inc
index f6534126..7cd52691 100644
--- a/drupal7/sites/all/modules/flag/includes/views/flag_plugin_argument_validate_flaggability.inc
+++ b/drupal7/sites/all/modules/flag/includes/views/flag_plugin_argument_validate_flaggability.inc
@@ -66,8 +66,9 @@ class flag_plugin_argument_validate_flaggability extends views_plugin_argument_v
   }
 
   /**
-   * Returns form #options for the flags. Returns empty array if no flags were
-   * found.
+   * Returns form #options for the flags.
+   *
+   * Returns empty array if no flags were found.
    */
   function flags_options() {
     $flags = flag_get_flags($this->flag_type);
@@ -96,8 +97,9 @@ class flag_plugin_argument_validate_flaggability extends views_plugin_argument_v
   }
 
   /**
-   * Declares all tests. This scheme makes it easy for derived classes to add
-   * and remove tests.
+   * Declares all tests.
+   *
+   * This scheme makes it easy for derived classes to add and remove tests.
    */
   function tests_info($which = NULL) {
     return array(
@@ -130,7 +132,8 @@ class flag_plugin_argument_validate_flaggability extends views_plugin_argument_v
     if ($flag_name == '*relationship*') {
       // Pick the first flag mentioned in the relationships.
       foreach ($this->view->relationship as $id => $handler) {
-        // Note: we can't do $handler->field, because the relationship handler's init() may overwrite it.
+        // Note: we can't do $handler->field, because the relationship handler's
+        // init() may overwrite it.
         if (strpos($handler->options['field'], 'flag') !== FALSE && !empty($handler->options['flag'])) {
           $flag = flag_get_flag($handler->options['flag']);
           if ($flag && $flag->entity_type == $this->flag_type) {
@@ -198,7 +201,8 @@ class flag_plugin_argument_validate_flaggability extends views_plugin_argument_v
   }
 
   function test_flagged($ids, $flag) {
-    // view_break_phrase() is guaranteed to return only integers, so this is SQL safe.
+    // view_break_phrase() is guaranteed to return only integers, so this is SQL
+    // safe.
     $flattened_ids = implode(',', $ids);
     return $this->_test_by_sql("SELECT entity_id FROM {flag_counts} WHERE fid = :fid AND entity_id IN ($flattened_ids) AND count > 0", array(':fid' => $flag->fid));
   }
@@ -206,7 +210,7 @@ class flag_plugin_argument_validate_flaggability extends views_plugin_argument_v
   function test_flagged_by_current_user($ids, $flag) {
     global $user;
     if (!$user->uid) {
-      // Anonymous user
+      // Anonymous user.
       return array();
     }
     $flattened_ids = implode(',', $ids);
@@ -223,4 +227,3 @@ class flag_plugin_argument_validate_flaggability extends views_plugin_argument_v
     return $passed;
   }
 }
-
diff --git a/drupal7/sites/all/modules/flag/plugins/access/flag_is_flagged/flag_is_flagged.inc b/drupal7/sites/all/modules/flag/plugins/access/flag_is_flagged/flag_is_flagged.inc
index 720e612d..0f6e0433 100644
--- a/drupal7/sites/all/modules/flag/plugins/access/flag_is_flagged/flag_is_flagged.inc
+++ b/drupal7/sites/all/modules/flag/plugins/access/flag_is_flagged/flag_is_flagged.inc
@@ -31,7 +31,7 @@ function flag_flag_is_flagged_access_get_children($plugin, $parent) {
 
   foreach ($entities as $entity_type => $info) {
     if (entity_type_supports($entity_type, 'view')) {
-      $plugin['title'] =  t('@entity_type is flagged', array('@entity_type' => $info['label']));
+      $plugin['title'] = t('@entity_type is flagged', array('@entity_type' => $info['label']));
       $plugin['keyword'] = $entity_type;
       $plugin['name'] = $parent . ':' . $entity_type;
       $plugin['required context'] = new ctools_context_required(t('Entity'), $entity_type);
@@ -103,7 +103,7 @@ function flag_flag_is_flagged_access_check($conf, $context) {
 }
 
 /**
- * Provide a summary description based upon the specified context
+ * Provide a summary description based upon the specified context.
  */
 function flag_flag_is_flagged_access_summary($conf, $context) {
   $flag = flag_get_flag($conf['flag_name']);
diff --git a/drupal7/sites/all/modules/flag/tests/flag.test b/drupal7/sites/all/modules/flag/tests/flag.test
index 60e4344e..3f8ac338 100644
--- a/drupal7/sites/all/modules/flag/tests/flag.test
+++ b/drupal7/sites/all/modules/flag/tests/flag.test
@@ -43,7 +43,7 @@ class FlagFlaggingCRUDTestCase extends FlagTestCaseBase {
    */
   public static function getInfo() {
     return array(
-      'name' => 'Flagging CRUD',
+      'name' => 'CRUD API',
       'description' => 'Basic CRUD operations on flagging entities.',
       'group' => 'Flag',
     );
@@ -216,14 +216,14 @@ class FlagFlaggingCRUDTestCase extends FlagTestCaseBase {
  * Test Flag admin UI.
  */
 class FlagAdminTestCase extends FlagTestCaseBase {
-  var $_flag = FALSE;
+  public $_flag = FALSE;
 
   /**
    * Implements getInfo().
    */
   public static function getInfo() {
     return array(
-      'name' => 'Flag admin tests',
+      'name' => 'Admin UI',
       'description' => 'Add, edit and delete flags.',
       'group' => 'Flag',
     );
@@ -235,7 +235,7 @@ class FlagAdminTestCase extends FlagTestCaseBase {
   function setUp() {
     parent::setUp('flag');
 
-    // Create and login user
+    // Create and login user.
     $admin_user = $this->drupalCreateUser(array('access administration pages', 'administer flags'));
     $this->drupalLogin($admin_user);
   }
@@ -277,7 +277,13 @@ class FlagAdminTestCase extends FlagTestCaseBase {
     $saved = $edit;
     $saved['roles'] = array('flag' => array(2), 'unflag' => array(2));
     $saved['types'] = array('page');
-    $saved['show_in_links'] = array('full' => 0, 'teaser' => 0, 'rss' => 0, 'search_index' => 0, 'search_result' => 0);
+    $saved['show_in_links'] = array(
+      'full' => 0,
+      'teaser' => 0,
+      'rss' => 0,
+      'search_index' => 0,
+      'search_result' => 0,
+    );
     unset($saved['roles[flag][2]'], $saved['roles[unflag][2]'], $saved['types[article]'], $saved['types[page]'], $saved['show_in_links[full]'], $saved['show_in_links[teaser]'], $saved['show_in_links[rss]'], $saved['show_in_links[search_index]'], $saved['show_in_links[search_result]']);
 
     $this->drupalPost(FLAG_ADMIN_PATH . '/add/node', $edit, t('Save flag'));
@@ -299,7 +305,7 @@ class FlagAdminTestCase extends FlagTestCaseBase {
     $permissions = user_role_permissions(user_roles());
     foreach ($saved['roles'] as $action => $rids) {
       foreach ($rids as $rid) {
-        $permission_string = "$action ". $saved['name'];
+        $permission_string = "$action " . $saved['name'];
         $this->assertTrue(isset($permissions[$rid][$permission_string]), t('Permission %perm set for flag.', array(
           '%perm' => $permission_string,
         )));
@@ -331,7 +337,13 @@ class FlagAdminTestCase extends FlagTestCaseBase {
     $saved = $edit;
     $saved['roles'] = array('flag' => array(2), 'unflag' => array(2));
     $saved['types'] = array('article');
-    $saved['show_in_links'] = array('full' => TRUE, 'teaser' => TRUE, 'rss' => 0, 'search_index' => 0, 'search_result' => 0);
+    $saved['show_in_links'] = array(
+      'full' => TRUE,
+      'teaser' => TRUE,
+      'rss' => 0,
+      'search_index' => 0,
+      'search_result' => 0,
+    );
     unset($saved['roles[flag][2]'], $saved['roles[unflag][2]'], $saved['types[article]'], $saved['types[page]'], $saved['show_in_links[full]'], $saved['show_in_links[teaser]'], $saved['show_in_links[rss]'], $saved['show_in_links[search_index]'], $saved['show_in_links[search_result]']);
 
     $this->drupalPost(FLAG_ADMIN_PATH . '/manage/' . $flag->name, $edit, t('Save flag'));
@@ -358,7 +370,7 @@ class FlagAdminTestCase extends FlagTestCaseBase {
 
     foreach ($saved['roles'] as $action => $rids) {
       foreach ($rids as $rid) {
-        $permission_string = "$action ". $saved['name'];
+        $permission_string = "$action " . $saved['name'];
         $this->assertTrue(isset($permissions[$rid][$permission_string]), t('Permission %perm set for flag.', array(
           '%perm' => $permission_string,
         )));
@@ -385,7 +397,7 @@ class FlagAccessFormTestCase extends FlagTestCaseBase {
    */
   public static function getInfo() {
     return array(
-      'name' => 'Flag access: entity forms',
+      'name' => 'Access to flags via entity forms',
       'description' => 'Access to flag and unflag entities via entity forms.',
       'group' => 'Flag',
     );
@@ -439,7 +451,7 @@ class FlagAccessFormTestCase extends FlagTestCaseBase {
 
     $this->drupalGet('node/add/article');
 
-    // Check that the flag form element cannot be seen
+    // Check that the flag form element cannot be seen.
     $this->assertNoText('Flag this item', t('Flag form element was not found.'));
 
     // Have the user create a node.
@@ -481,7 +493,7 @@ class FlagEntityTokensTestCase extends FlagTestCaseBase {
    */
   public static function getInfo() {
     return array(
-      'name' => 'Flag: Entity tokens',
+      'name' => 'Entity tokens',
       'description' => 'Tokens for flag count on entities.',
       'group' => 'Flag',
     );
@@ -636,7 +648,7 @@ class FlagAccessLinkTestCase extends FlagTestCaseBase {
    */
   public static function getInfo() {
     return array(
-      'name' => 'Flag access tests',
+      'name' => 'Access to flags via basic link',
       'description' => 'Access to flag and unflag entities using the basic link.',
       'group' => 'Flag',
     );
@@ -762,7 +774,7 @@ class FlagLinkTypeConfirmTestCase extends DrupalWebTestCase {
    */
   public static function getInfo() {
     return array(
-      'name' => 'Flag confirm link tests',
+      'name' => 'Confirm form',
       'description' => 'Flag confirm form link type.',
       'group' => 'Flag',
     );
@@ -784,7 +796,7 @@ class FlagLinkTypeConfirmTestCase extends DrupalWebTestCase {
       'types' => array(
         0 => 'article',
       ),
-      'flag_short' => 'Flag this item',
+      'flag_short' => 'Flag <em>this</em> item',
       'flag_long' => '',
       'flag_message' => 'You have flagged this item.',
       'unflag_short' => 'Unflag this item',
@@ -838,10 +850,21 @@ class FlagLinkTypeConfirmTestCase extends DrupalWebTestCase {
     // Look at our node.
     $this->drupalGet('node/' . $this->nid);
 
-    $this->assertLink($this->flag_data['flag_short'], 0, 'The flag link appears on the page');
+    $flag_short_label = strip_tags($this->flag_data['flag_short']);
+
+    $this->assertRaw($this->flag_data['flag_short'], 'The flag text, including HTML, appears on the page.');
+
+    // assertLink() appears to have interesting problems dealing with an A
+    // element which contains other tags. However, the xpath it uses appears to
+    // be fine with being given just the portion of the link text that comes
+    // before the interior tag.
+    // Fortunately, there will be no other text on the page that matches 'Flag'.
+    $this->assertLink('Flag', 0, 'The flag link appears on the page.');
 
     // Click the link to flag the node.
-    $this->clickLink($this->flag_data['flag_short']);
+    // clickLink() has the same problem, as it uses the same xpath expression as
+    // assertLink().
+    $this->clickLink('Flag');
 
     $this->assertUrl('flag/confirm/flag/test_flag/' . $this->nid, array(
       'query' => array(
@@ -851,8 +874,10 @@ class FlagLinkTypeConfirmTestCase extends DrupalWebTestCase {
 
     $this->assertText($this->flag_data['flag_confirmation'], 'The flag confirmation text appears as the confirmation page title.');
 
+    $this->assertPattern('@<input [^>]* value="' . $flag_short_label . '" [^>]*>@', 'The flag text, excluding HTML, is shown in the button.');
+
     // Click the button to confirm the flagging.
-    $this->drupalPost(NULL, array(), $this->flag_data['flag_short']);
+    $this->drupalPost(NULL, array(), $flag_short_label);
 
     $this->assertText($this->flag_data['flag_message'], 'The flag message appears once the item has been flagged.');
     $this->assertLink($this->flag_data['unflag_short'], 0, 'The unflag link appears once the item has been flagged.');
@@ -894,7 +919,7 @@ class FlagHookFlagAccessTestCase extends FlagTestCaseBase {
    */
   public static function getInfo() {
     return array(
-      'name' => 'Flag hook_flag_access() tests',
+      'name' => 'hook_flag_access()',
       'description' => 'Checks the ability of modules to use hook_flag_access().',
       'group' => 'Flag',
     );
@@ -1002,7 +1027,8 @@ class FlagHookFlagAccessTestCase extends FlagTestCaseBase {
   }
 
   /**
-   * Verifies that the user sees the flag if a module returns TRUE (Allow) to override default access check.
+   * Verifies that the user sees the flag if a module returns TRUE (Allow) to
+   * override default access check.
    */
   function testFlagAccessAllowOverride() {
     variable_set('FlagHookFlagAccessTestCaseMode', 'allow');
@@ -1026,7 +1052,8 @@ class FlagHookFlagAccessTestCase extends FlagTestCaseBase {
   }
 
   /**
-   * Verifies that the user does not see the flag if a module returns FALSE (Deny).
+   * Verifies that the user does not see the flag if a module returns FALSE
+   * (Deny).
    */
   function testFlagAccessDeny() {
     variable_set('FlagHookFlagAccessTestCaseMode', 'deny');
@@ -1041,6 +1068,83 @@ class FlagHookFlagAccessTestCase extends FlagTestCaseBase {
 
 }
 
+/**
+ * Test use of fields on flagging entities.
+ */
+class FlagFlaggingFieldTestCase extends FlagTestCaseBase {
+
+  /**
+   * Implements getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Flagging fields',
+      'description' => 'Fields on Flagging entities.',
+      'group' => 'Flag',
+    );
+  }
+
+  /**
+   * Implements setUp().
+   */
+  function setUp() {
+    parent::setUp('flag', 'flag_fields_test');
+  }
+
+  function testFlaggingFields() {
+    $this->assertTrue(1);
+
+    $flag_user = $this->drupalCreateUser(array(
+      'flag flag_fields_test_flag',
+      'unflag flag_fields_test_flag',
+    ));
+    $this->drupalLogin($flag_user);
+
+    $node = $this->drupalCreateNode();
+
+    $this->drupalGet('node/' . $node->nid);
+
+    $this->clickLink('Flag with the test flag');
+
+    // Try to fail the form validation by providing something non-numeric.
+    // This validation is only present in the widget validation: this is a core
+    // bug, but lets us test widget validation works correctly until it's fixed.
+    $edit = array(
+      'flag_fields_test_integer[und][0][value]' => 'banana',
+    );
+    $this->drupalPost(NULL, $edit, 'Flag with the test flag');
+
+    $this->assertText("Only numbers are allowed in Test integer.", "Form validation correctly failed the input.");
+
+    // Try to fail the form validation by a number that's out of bounds.
+    $edit = array(
+      'flag_fields_test_integer[und][0][value]' => 12,
+    );
+    $this->drupalPost(NULL, $edit, 'Flag with the test flag');
+
+    $this->assertText("Test integer: the value may be no greater than 11.", "Form validation correctly failed the input.");
+
+    $edit = array(
+      'flag_fields_test_integer[und][0][value]' => 6,
+    );
+    $this->drupalPost(NULL, $edit, 'Flag with the test flag');
+
+    $this->assertUrl('node/' . $node->nid, array(), "The flagging form submission succeeded.");
+
+    // Try to load the flagging, querying for the field value.
+    $query = new EntityFieldQuery();
+    $query->entityCondition('entity_type', 'flagging')
+      ->entityCondition('bundle', 'flag_fields_test_flag')
+      ->propertyCondition('entity_id', $node->nid)
+      ->fieldCondition('flag_fields_test_integer', 'value', 6);
+
+    $result = $query->execute();
+
+    $this->assertEqual(count($result['flagging']), 1, "The Flagging entity was found with the correct field values.");
+  }
+
+}
+
 /**
  * Test use of EntityFieldQueries with flagging entities.
  */
@@ -1050,8 +1154,8 @@ class FlagEntityFieldQueryTestCase extends FlagTestCaseBase {
    * Implements getInfo().
    */
   public static function getInfo() {
-     return array(
-      'name' => 'Flagging Entity Field Query Extension',
+    return array(
+      'name' => 'Entity Field Query',
       'description' => 'Entity Field Query for flagging entities.',
       'group' => 'Flag',
     );
@@ -1099,7 +1203,12 @@ class FlagEntityFieldQueryTestCase extends FlagTestCaseBase {
     $this->flag3 = $this->createFlag($flag_data);
 
     // Create test user who can flag and unflag.
-    $this->flag_unflag_user = $this->drupalCreateUser(array('flag test_flag_1', 'unflag test_flag_1', 'flag test_flag_2', 'unflag test_flag_2'));
+    $this->flag_unflag_user = $this->drupalCreateUser(array(
+      'flag test_flag_1',
+      'unflag test_flag_1',
+      'flag test_flag_2',
+      'unflag test_flag_2',
+    ));
     $this->drupalLogin($this->flag_unflag_user);
 
   }
@@ -1108,7 +1217,7 @@ class FlagEntityFieldQueryTestCase extends FlagTestCaseBase {
    * Test use of EntityFieldQuery with flagging entities.
    */
   function testEntityFieldQuery() {
-     $node_settings = array(
+    $node_settings = array(
       'title' => $this->randomName(),
       'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32)))),
       'uid' => 1,
@@ -1150,8 +1259,8 @@ class FlagHookInvocationsTestCase extends FlagTestCaseBase {
    * Implements getInfo().
    */
   public static function getInfo() {
-     return array(
-      'name' => 'Flag hook invocations',
+    return array(
+      'name' => 'Hook invocations',
       'description' => 'Invocation of flag and entity hooks and rules during flagging and unflagging.',
       'group' => 'Flag',
     );
@@ -1217,12 +1326,9 @@ class FlagHookInvocationsTestCase extends FlagTestCaseBase {
 
     // Check the parameters received by hook_entity_presave().
     // Param 0: $flagging.
-    // There is a bug with what is passed to entity hooks; for now, just check
-    // the things that do get passed.
-    // See https://drupal.org/node/2196055.
     $this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->flag_name, $flag->name, "The Flagging entity passed to hook_entity_presave() has the expected flag name property.");
-    //$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->fid, $flag->fid);
-    //$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->entity_type, 'node');
+    $this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->fid, $flag->fid, "The Flagging entity passed to hook_entity_presave() has the expected fid property.");
+    $this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->entity_type, 'node', "The Flagging entity passed to hook_entity_presave() has the expected entity type property.");
     $this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->entity_id, $node->nid, "The Flagging entity passed to hook_entity_presave() has the expected entity ID property.");
     $this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->uid, $this->flag_unflag_user->uid, "The Flagging entity passed to hook_entity_presave() has the expected uid property.");
     // Param 1: $entity_type.
@@ -1240,10 +1346,9 @@ class FlagHookInvocationsTestCase extends FlagTestCaseBase {
 
     // Check the parameters received by hook_entity_insert().
     // Param 0: $flagging.
-    // See https://drupal.org/node/2196055.
     $this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->flag_name, $flag->name, "The Flagging entity passed to hook_entity_insert() has the expected flag name property.");
-    //$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->fid, $flag->fid);
-    //$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->entity_type, 'node');
+    $this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->fid, $flag->fid, "The Flagging entity passed to hook_entity_insert() has the expected fid property.");
+    $this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->entity_type, 'node', "The Flagging entity passed to hook_entity_insert() has the expected entity type property.");
     $this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->entity_id, $node->nid, "The Flagging entity passed to hook_entity_insert() has the expected entity ID property.");
     $this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->uid, $this->flag_unflag_user->uid, "The Flagging entity passed to hook_entity_insert() has the expected uid property.");
     $this->assertTrue(!empty($hook_data_variable['hook_entity_insert']['parameters'][0]->flagging_id), "The Flagging entity passed to hook_entity_insert() has the flagging ID set.");
@@ -1287,10 +1392,9 @@ class FlagHookInvocationsTestCase extends FlagTestCaseBase {
     // Param 2: $account.
     $this->assertEqual($hook_data_variable['hook_flag_flag']['parameters'][2]->uid, $this->flag_unflag_user->uid, "The user account is passed to hook_flag_flag().");
     // Param 3: $flagging.
-    // See https://drupal.org/node/2196055.
     $this->assertEqual($hook_data_variable['hook_flag_flag']['parameters'][3]->flag_name, $flag->name, "The Flagging entity passed to hook_flag_flag() has the expected flag name property.");
-    //$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][3]->fid, $flag->fid);
-    //$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][3]->entity_type, 'node');
+    $this->assertEqual($hook_data_variable['hook_flag_flag']['parameters'][3]->fid, $flag->fid, "The Flagging entity passed to hook_flag_flag() has the expected fid property.");
+    $this->assertEqual($hook_data_variable['hook_flag_flag']['parameters'][3]->entity_type, 'node', "The Flagging entity passed to hook_flag_flag() has the expected entity type property.");
     $this->assertEqual($hook_data_variable['hook_flag_flag']['parameters'][3]->entity_id, $node->nid, "The Flagging entity passed to hook_flag_flag() has the expected entity ID property.");
     $this->assertEqual($hook_data_variable['hook_flag_flag']['parameters'][3]->uid, $this->flag_unflag_user->uid, "The Flagging entity passed to hook_flag_flag() has the expected uid property.");
 
@@ -1359,9 +1463,6 @@ class FlagHookInvocationsTestCase extends FlagTestCaseBase {
 
     // Check the parameters received by hook_entity_presave().
     // Param 0: $flagging.
-    // There is a bug with what is passed to entity hooks; for now, just check
-    // the things that do get passed.
-    // See https://drupal.org/node/2196055.
     $this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->flag_name, $flag->name, "The Flagging entity passed to hook_entity_presave() has the expected flag name property.");
     //$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->fid, $flag->fid);
     //$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][0]->entity_type, 'node');
@@ -1401,10 +1502,9 @@ class FlagHookInvocationsTestCase extends FlagTestCaseBase {
 
     // Check the parameters received by hook_entity_update().
     // Param 0: $flagging.
-    // See https://drupal.org/node/2196055.
     $this->assertEqual($hook_data_variable['hook_entity_update']['parameters'][0]->flag_name, $flag->name, "The Flagging entity passed to hook_entity_update() has the expected flag name property.");
-    //$this->assertEqual($hook_data_variable['hook_entity_update']['parameters'][0]->fid, $flag->fid);
-    //$this->assertEqual($hook_data_variable['hook_entity_update']['parameters'][0]->entity_type, 'node');
+    $this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->fid, $flag->fid, "The Flagging entity passed to hook_entity_presave() has the expected fid property.");
+    $this->assertEqual($hook_data_variable['hook_entity_presave']['parameters'][0]->entity_type, 'node', "The Flagging entity passed to hook_entity_presave() has the expected entity type property.");
     $this->assertEqual($hook_data_variable['hook_entity_update']['parameters'][0]->entity_id, $node->nid, "The Flagging entity passed to hook_entity_update() has the expected entity ID property.");
     $this->assertEqual($hook_data_variable['hook_entity_update']['parameters'][0]->uid, $this->flag_unflag_user->uid, "The Flagging entity passed to hook_entity_update() has the expected uid property.");
     $this->assertTrue(!empty($hook_data_variable['hook_entity_update']['parameters'][0]->flagging_id), "The Flagging entity passed to hook_entity_update() has the flagging ID set.");
@@ -1467,10 +1567,9 @@ class FlagHookInvocationsTestCase extends FlagTestCaseBase {
     // Param 2: $account.
     $this->assertEqual($hook_data_variable['hook_flag_unflag']['parameters'][2]->uid, $this->flag_unflag_user->uid, "The user account is passed to hook_flag_unflag().");
     // Param 3: $flagging.
-    // See https://drupal.org/node/2196055.
     $this->assertEqual($hook_data_variable['hook_flag_unflag']['parameters'][3]->flag_name, $flag->name, "The Flagging entity passed to hook_flag_unflag() has the expected flag name property.");
-    //$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][3]->fid, $flag->fid);
-    //$this->assertEqual($hook_data_variable['hook_entity_insert']['parameters'][3]->entity_type, 'node');
+    $this->assertEqual($hook_data_variable['hook_flag_unflag']['parameters'][3]->fid, $flag->fid, "The Flagging entity passed to hook_entity_presave() has the expected fid property.");
+    $this->assertEqual($hook_data_variable['hook_flag_unflag']['parameters'][3]->entity_type, 'node', "The Flagging entity passed to hook_entity_presave() has the expected entity type property.");
     $this->assertEqual($hook_data_variable['hook_flag_unflag']['parameters'][3]->entity_id, $node->nid, "The Flagging entity passed to hook_flag_unflag() has the expected entity ID property.");
     $this->assertEqual($hook_data_variable['hook_flag_unflag']['parameters'][3]->uid, $this->flag_unflag_user->uid, "The Flagging entity passed to hook_flag_unflag() has the expected uid property.");
 
@@ -1511,10 +1610,9 @@ class FlagHookInvocationsTestCase extends FlagTestCaseBase {
 
     // Check the parameters received by hook_entity_delete().
     // Param 0: $flagging.
-    // See https://drupal.org/node/2196055.
     $this->assertEqual($hook_data_variable['hook_entity_delete']['parameters'][0]->flag_name, $flag->name, "The Flagging entity passed to hook_entity_delete() has the expected flag name property.");
-    //$this->assertEqual($hook_data_variable['hook_entity_delete']['parameters'][0]->fid, $flag->fid);
-    //$this->assertEqual($hook_data_variable['hook_entity_delete']['parameters'][0]->entity_type, 'node');
+    $this->assertEqual($hook_data_variable['hook_entity_delete']['parameters'][0]->fid, $flag->fid, "The Flagging entity passed to hook_entity_presave() has the expected fid property.");
+    $this->assertEqual($hook_data_variable['hook_entity_delete']['parameters'][0]->entity_type, 'node', "The Flagging entity passed to hook_entity_presave() has the expected entity type property.");
     $this->assertEqual($hook_data_variable['hook_entity_delete']['parameters'][0]->entity_id, $node->nid, "The Flagging entity passed to hook_entity_delete() has the expected entity ID property.");
     $this->assertEqual($hook_data_variable['hook_entity_delete']['parameters'][0]->uid, $this->flag_unflag_user->uid, "The Flagging entity passed to hook_entity_delete() has the expected uid property.");
     $this->assertTrue(!empty($hook_data_variable['hook_entity_delete']['parameters'][0]->flagging_id), "The Flagging entity passed to hook_entity_delete() has the flagging ID set.");
diff --git a/drupal7/sites/all/modules/flag/tests/flag_fields_test/flag_fields_test.info b/drupal7/sites/all/modules/flag/tests/flag_fields_test/flag_fields_test.info
new file mode 100644
index 00000000..0b5d9dc5
--- /dev/null
+++ b/drupal7/sites/all/modules/flag/tests/flag_fields_test/flag_fields_test.info
@@ -0,0 +1,12 @@
+name = Flag Fields Test
+description = Test module for fields on Flagging entities.
+dependencies[] = flag
+core = 7.x
+hidden = TRUE
+
+; Information added by Drupal.org packaging script on 2014-05-03
+version = "7.x-3.5"
+core = "7.x"
+project = "flag"
+datestamp = "1399113834"
+
diff --git a/drupal7/sites/all/modules/flag/tests/flag_fields_test/flag_fields_test.install b/drupal7/sites/all/modules/flag/tests/flag_fields_test/flag_fields_test.install
new file mode 100644
index 00000000..ee4376c6
--- /dev/null
+++ b/drupal7/sites/all/modules/flag/tests/flag_fields_test/flag_fields_test.install
@@ -0,0 +1,67 @@
+<?php
+
+/**
+ * @file flag_fields_test.install
+ * Contains install hooks.
+ */
+
+/**
+ * Implements hook_install().
+ */
+function flag_fields_test_install() {
+  // Add a number field to the flagging.
+  $field = array(
+    'field_name' => 'flag_fields_test_integer',
+    'type' => 'number_integer',
+    'cardinality' => '1',
+    'settings' => array(),
+  );
+  field_create_field($field);
+
+  $instance = array(
+    'field_name' => 'flag_fields_test_integer',
+    'entity_type' => 'flagging',
+    'bundle' => 'flag_fields_test_flag',
+    'label' => 'Test integer',
+    'widget' => array(
+      'weight' => 0,
+      'type' => 'number',
+      'module' => 'number',
+      'active' => 0,
+      'settings' => array(),
+    ),
+    'settings' => array(
+      'min' => '',
+      'max' => '11',
+      'prefix' => '',
+      'suffix' => '',
+      'user_register_form' => FALSE,
+    ),
+    'display' => array(
+      'default' => array(
+        'label' => 'above',
+        'type' => 'number_integer',
+        'settings' => array(
+          'thousand_separator' => ' ',
+          'decimal_separator' => '.',
+          'scale' => 0,
+          'prefix_suffix' => TRUE,
+        ),
+        'module' => 'number',
+        'weight' => 1,
+      ),
+    ),
+  );
+  field_create_instance($instance);
+}
+
+/**
+ * Implements hook_uninstall().
+ *
+ * Not needed for testing, but useful for when developing tests as it allows
+ * use of Devel module's reinstall tool.
+ */
+function flag_fields_test_uninstall() {
+  // Delete our fields.
+  field_delete_field('flag_fields_test_integer');
+}
diff --git a/drupal7/sites/all/modules/flag/tests/flag_fields_test/flag_fields_test.module b/drupal7/sites/all/modules/flag/tests/flag_fields_test/flag_fields_test.module
new file mode 100644
index 00000000..cf64a80d
--- /dev/null
+++ b/drupal7/sites/all/modules/flag/tests/flag_fields_test/flag_fields_test.module
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * @file flag_fields_test.module
+ * Test module for fields on flagging entities.
+ */
+
+/**
+ * Implements hook_flag_default_flags().
+ */
+function flag_fields_test_flag_default_flags() {
+  $flags = array();
+  // Exported flag: "Flag fields test".
+  $flags['flag_fields_test_flag'] = array(
+    'entity_type' => 'node',
+    'title' => 'Flag fields test',
+    'global' => 1,
+    'types' => array(),
+    'flag_short' => 'Flag with the test flag',
+    'flag_long' => '',
+    'flag_message' => '',
+    'unflag_short' => 'Unflag',
+    'unflag_long' => '',
+    'unflag_message' => '',
+    'unflag_denied_text' => '',
+    'link_type' => 'confirm',
+    'weight' => -15,
+    'show_in_links' => array(
+      'full' => 'full',
+      'teaser' => 'teaser',
+      'rss' => 0,
+      'token' => 0,
+      'revision' => 0,
+    ),
+    'show_as_field' => 0,
+    'show_on_form' => 0,
+    'access_author' => '',
+    'show_contextual_link' => 0,
+    'i18n' => 0,
+    'flag_confirmation' => 'Confirm flagging this node',
+    'unflag_confirmation' => 'Confirm unflagging this node',
+    'api_version' => 3,
+  );
+  return $flags;
+}
diff --git a/drupal7/sites/all/modules/flag/tests/flag_hook_test/flag_hook_test.info b/drupal7/sites/all/modules/flag/tests/flag_hook_test/flag_hook_test.info
index 976b585f..730e4027 100644
--- a/drupal7/sites/all/modules/flag/tests/flag_hook_test/flag_hook_test.info
+++ b/drupal7/sites/all/modules/flag/tests/flag_hook_test/flag_hook_test.info
@@ -5,9 +5,9 @@ dependencies[] = rules
 core = 7.x
 hidden = TRUE
 
-; Information added by Drupal.org packaging script on 2014-03-18
-version = "7.x-3.4"
+; Information added by Drupal.org packaging script on 2014-05-03
+version = "7.x-3.5"
 core = "7.x"
 project = "flag"
-datestamp = "1395128956"
+datestamp = "1399113834"
 
diff --git a/drupal7/sites/all/modules/flag/tests/flag_hook_test/flag_hook_test.module b/drupal7/sites/all/modules/flag/tests/flag_hook_test/flag_hook_test.module
index 688f801b..732af512 100644
--- a/drupal7/sites/all/modules/flag/tests/flag_hook_test/flag_hook_test.module
+++ b/drupal7/sites/all/modules/flag/tests/flag_hook_test/flag_hook_test.module
@@ -106,11 +106,11 @@ function flag_hook_test_entity_delete($entity, $type) {
  */
 function flag_hook_test_flag_default_flags() {
   $flags = array();
-  $flags['flag_hook_test_flag'] = array (
+  $flags['flag_hook_test_flag'] = array(
     'entity_type' => 'node',
     'title' => 'Test Flag',
     'global' => FALSE,
-    'types' => array (
+    'types' => array(
       0 => 'article',
     ),
     'flag_short' => 'Flag this',
@@ -122,7 +122,7 @@ function flag_hook_test_flag_default_flags() {
     'unflag_denied_text' => 'You may not unflag this item',
     'link_type' => 'normal',
     'weight' => 0,
-    'show_in_links' => array (
+    'show_in_links' => array(
       'full' => TRUE,
       'teaser' => TRUE,
     ),
diff --git a/drupal7/sites/all/modules/flag/tests/flagaccesstest/flagaccesstest.info b/drupal7/sites/all/modules/flag/tests/flagaccesstest/flagaccesstest.info
index 0d801a71..9cc1635e 100644
--- a/drupal7/sites/all/modules/flag/tests/flagaccesstest/flagaccesstest.info
+++ b/drupal7/sites/all/modules/flag/tests/flagaccesstest/flagaccesstest.info
@@ -5,9 +5,9 @@ dependencies[] = flag
 package = Flags
 hidden = TRUE
 
-; Information added by Drupal.org packaging script on 2014-03-18
-version = "7.x-3.4"
+; Information added by Drupal.org packaging script on 2014-05-03
+version = "7.x-3.5"
 core = "7.x"
 project = "flag"
-datestamp = "1395128956"
+datestamp = "1399113834"
 
diff --git a/drupal7/sites/all/modules/flag/theme/flag.tpl.php b/drupal7/sites/all/modules/flag/theme/flag.tpl.php
index 60a31139..3ef95aac 100644
--- a/drupal7/sites/all/modules/flag/theme/flag.tpl.php
+++ b/drupal7/sites/all/modules/flag/theme/flag.tpl.php
@@ -2,28 +2,33 @@
 
 /**
  * @file
- * Default theme implementation to display a flag link, and a message after the action
- * is carried out.
+ * Default theme implementation to display a flag link, and a message after the
+ * action is carried out.
  *
  * Available variables:
  *
  * - $flag: The flag object itself. You will only need to use it when the
  *   following variables don't suffice.
- * - $flag_name_css: The flag name, with all "_" replaced with "-". For use in 'class'
- *   attributes.
- * - $flag_classes: A space-separated list of CSS classes that should be applied to the link.
+ * - $flag_name_css: The flag name, with all "_" replaced with "-". For use in
+ *   'class' attributes.
+ * - $flag_classes: A space-separated list of CSS classes that should be applied
+ *   to the link.
  *
- * - $action: The action the link is about to carry out, either "flag" or "unflag".
+ * - $action: The action the link is about to carry out, either "flag" or
+ *   "unflag".
  * - $status: The status of the item; either "flagged" or "unflagged".
  *
  * - $link_href: The URL for the flag link.
  * - $link_text: The text to show for the link.
  * - $link_title: The title attribute for the link.
  *
- * - $message_text: The long message to show after a flag action has been carried out.
- * - $message_classes: A space-separated list of CSS classes that should be applied to
+ * - $message_text: The long message to show after a flag action has been
+ *   carried out.
+ * - $message_classes: A space-separated list of CSS classes that should be
+ *   applied to
  *   the message.
- * - $after_flagging: This template is called for the link both before and after being
+ * - $after_flagging: This template is called for 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.
@@ -35,8 +40,8 @@
  * - flag--name.tpl.php
  * - flag--link-type.tpl.php
  *
- * NOTE: This template spaces out the <span> tags for clarity only. When doing some
- * advanced theming you may have to remove all the whitespace.
+ * NOTE: This template spaces out the <span> tags for clarity only. When doing
+ * some advanced theming you may have to remove all the whitespace.
  */
 ?>
 <?php if ($needs_wrapping_element): ?>
diff --git a/drupal7/sites/all/modules/rules/includes/rules.core.inc b/drupal7/sites/all/modules/rules/includes/rules.core.inc
index 24d85c63..5dbc332d 100644
--- a/drupal7/sites/all/modules/rules/includes/rules.core.inc
+++ b/drupal7/sites/all/modules/rules/includes/rules.core.inc
@@ -1622,7 +1622,7 @@ abstract class RulesAbstractPlugin extends RulesPlugin {
   public function dependencies() {
     $modules = array_flip(parent::dependencies());
     $modules += array_flip((array) $this->__call('dependencies'));
-    return array_keys($modules + (isset($this->info['module']) ? array($this->info['module'] => 1) : array()));
+    return array_keys($modules + (!empty($this->info['module']) ? array($this->info['module'] => 1) : array()));
   }
 
   public function executeByArgs($args = array()) {
diff --git a/drupal7/sites/all/modules/rules/modules/data.eval.inc b/drupal7/sites/all/modules/rules/modules/data.eval.inc
index 6b9a95af..9fbbb7a0 100644
--- a/drupal7/sites/all/modules/rules/modules/data.eval.inc
+++ b/drupal7/sites/all/modules/rules/modules/data.eval.inc
@@ -294,6 +294,7 @@ function rules_action_data_create_info_alter(&$element_info, RulesAbstractPlugin
         $element_info['parameter']['param_' . $property] = array_intersect_key($property_info, array_flip(array('type', 'label', 'allow null')));
         if (empty($property_info['required'])) {
           $element_info['parameter']['param_' . $property]['optional'] = TRUE;
+          $element_info['parameter']['param_' . $property]['allow null'] = TRUE;
         }
       }
     }
@@ -366,6 +367,20 @@ function rules_condition_data_list_contains($list, $item, $settings, $state) {
   return in_array($item, $list);
 }
 
+/**
+* Condition: List count comparison.
+*/
+function rules_condition_data_list_count_is($list, $op = '==', $value) {
+  switch ($op) {
+    case '==':
+      return count($list) == $value;
+    case '<';
+      return count($list) < $value;
+    case '>';
+      return count($list) > $value;
+  }
+}
+
 /**
  * Condition: Data value is empty.
  */
diff --git a/drupal7/sites/all/modules/rules/modules/data.rules.inc b/drupal7/sites/all/modules/rules/modules/data.rules.inc
index 412586f9..96caae23 100644
--- a/drupal7/sites/all/modules/rules/modules/data.rules.inc
+++ b/drupal7/sites/all/modules/rules/modules/data.rules.inc
@@ -555,6 +555,32 @@ function rules_data_condition_info() {
         'form_alter' => 'rules_data_list_form_alter',
       ),
     ),
+    'list_count_is' => array(
+      'label' => t('List count comparison'),
+      'parameter' => array(
+        'list' => array(
+          'type' => 'list',
+          'label' => t('List to check'),
+          'description' => t('A multi value data element to have its count compared, specified by using a data selector, eg node:author:roles.'),
+        ),
+        'op' => array(
+          'type' => 'text',
+          'label' => t('Operator'),
+          'description' => t('The comparison operator.'),
+          'optional' => TRUE,
+          'default value' => '==',
+          'options list' => 'rules_condition_data_list_count_is_operator_options',
+          'restriction' => 'input',
+        ),
+        'value' => array(
+          'type' => 'integer',
+          'label' => t('Count'),
+          'description' => t('The count to compare the data count with.'),
+        ),
+      ),
+      'group' => t('Data'),
+      'base' => 'rules_condition_data_list_count_is',
+    ),
     'text_matches'  => array(
       'label' => t('Text comparison'),
       'parameter' => array(
@@ -719,6 +745,17 @@ function rules_data_selector_options_list(RulesAbstractPlugin $element) {
   }
 }
 
+/**
+ * Options list callback for condition list_count_is.
+ */
+function rules_condition_data_list_count_is_operator_options() {
+  return array(
+    '==' => t('equals'),
+    '<' => t('is lower than'),
+    '>' => t('is greater than'),
+  );
+}
+
 /**
  * @}
  */
diff --git a/drupal7/sites/all/modules/rules/modules/rules_core.rules.inc b/drupal7/sites/all/modules/rules/modules/rules_core.rules.inc
index 39fff93e..d4215fa2 100644
--- a/drupal7/sites/all/modules/rules/modules/rules_core.rules.inc
+++ b/drupal7/sites/all/modules/rules/modules/rules_core.rules.inc
@@ -120,6 +120,12 @@ function rules_rules_core_data_info() {
       'group' => t('Entity'),
       'is wrapped' => TRUE,
     ),
+    'ip_address' => array(
+      'label' => t('IP Address'),
+      'parent' => 'text',
+      'ui class' => 'RulesDataUIIPAddress',
+      'token type' => 'rules_text',
+    ),
   );
   foreach (entity_get_info() as $type => $info) {
     if (!empty($info['label'])) {
diff --git a/drupal7/sites/all/modules/rules/modules/system.eval.inc b/drupal7/sites/all/modules/rules/modules/system.eval.inc
index a27225f9..0de887c1 100644
--- a/drupal7/sites/all/modules/rules/modules/system.eval.inc
+++ b/drupal7/sites/all/modules/rules/modules/system.eval.inc
@@ -150,6 +150,17 @@ function rules_mail($key, &$message, $params) {
   $message['body'][] = $params['message'];
 }
 
+/**
+ * Action: Block an IP address.
+ */
+function rules_action_block_ip($ip_address = NULL) {
+  if (empty($ip_address)) {
+    $ip_address = ip_address();
+  }
+  db_insert('blocked_ips')->fields(array('ip' => $ip_address))->execute();
+  watchdog('rules', 'Banned IP address %ip', array('%ip' => $ip_address));
+}
+
 /**
  * A class implementing a rules input evaluator processing tokens.
  */
diff --git a/drupal7/sites/all/modules/rules/modules/system.rules.inc b/drupal7/sites/all/modules/rules/modules/system.rules.inc
index fcd4f808..2df01a3a 100644
--- a/drupal7/sites/all/modules/rules/modules/system.rules.inc
+++ b/drupal7/sites/all/modules/rules/modules/system.rules.inc
@@ -242,6 +242,21 @@ function rules_system_action_info() {
       'base' => 'rules_action_mail_to_users_of_role',
       'access callback' => 'rules_system_integration_access',
     ),
+    'block_ip' => array(
+      'label' => t('Block IP address'),
+      'group' => t('System'),
+      'parameter' => array(
+        'ip_address' => array(
+          'type' => 'ip_address',
+          'label' => t('IP address'),
+          'description' => t('If not provided, the IP address of the current user will be used.'),
+          'optional' => TRUE,
+          'default value' => NULL,
+        ),
+      ),
+      'base' => 'rules_action_block_ip',
+      'access callback' => 'rules_system_integration_access',
+    ),
   );
 }
 
diff --git a/drupal7/sites/all/modules/rules/modules/user.eval.inc b/drupal7/sites/all/modules/rules/modules/user.eval.inc
index d7bb8231..a990bfb9 100644
--- a/drupal7/sites/all/modules/rules/modules/user.eval.inc
+++ b/drupal7/sites/all/modules/rules/modules/user.eval.inc
@@ -103,6 +103,7 @@ function rules_action_user_unblock($account) {
 function rules_action_user_send_account_email($account, $email_type) {
   // If we received an authenticated user account...
   if (!empty($account->uid)) {
+    module_load_include('inc', 'rules', 'modules/user.rules');
     $types = rules_user_account_email_options_list();
 
     // Attempt to send the account e-mail.
diff --git a/drupal7/sites/all/modules/rules/rules.info b/drupal7/sites/all/modules/rules/rules.info
index adb9856f..84d21d4f 100644
--- a/drupal7/sites/all/modules/rules/rules.info
+++ b/drupal7/sites/all/modules/rules/rules.info
@@ -22,9 +22,9 @@ files[] = ui/ui.plugins.inc
 dependencies[] = entity_token
 dependencies[] = entity
 
-; Information added by drupal.org packaging script on 2013-10-29
-version = "7.x-2.6"
+; Information added by Drupal.org packaging script on 2014-05-02
+version = "7.x-2.7"
 core = "7.x"
 project = "rules"
-datestamp = "1383063052"
+datestamp = "1399041230"
 
diff --git a/drupal7/sites/all/modules/rules/rules.module b/drupal7/sites/all/modules/rules/rules.module
index d2ff900c..84900f2d 100644
--- a/drupal7/sites/all/modules/rules/rules.module
+++ b/drupal7/sites/all/modules/rules/rules.module
@@ -4,11 +4,14 @@
  * @file Rules engine module
  */
 
+// Include our hook implementations early, as they can be called even before
+// hook_init().
+require_once dirname(__FILE__) . '/modules/events.inc';
+
 /**
  * Implements hook_init().
  */
 function rules_init() {
-  module_load_include('inc', 'rules', 'modules/events');
   rules_invoke_event('init');
 }
 
diff --git a/drupal7/sites/all/modules/rules/rules.rules.inc b/drupal7/sites/all/modules/rules/rules.rules.inc
index fcd3c94c..3beb76eb 100644
--- a/drupal7/sites/all/modules/rules/rules.rules.inc
+++ b/drupal7/sites/all/modules/rules/rules.rules.inc
@@ -10,7 +10,6 @@
  */
 foreach (rules_core_modules() as $module) {
   module_load_include('inc', 'rules', "modules/$module.rules");
-  module_load_include('inc', 'rules', 'modules/events');
 }
 
 /**
diff --git a/drupal7/sites/all/modules/rules/rules_admin/rules_admin.info b/drupal7/sites/all/modules/rules/rules_admin/rules_admin.info
index d8d731b6..c2382e02 100644
--- a/drupal7/sites/all/modules/rules/rules_admin/rules_admin.info
+++ b/drupal7/sites/all/modules/rules/rules_admin/rules_admin.info
@@ -6,9 +6,9 @@ files[] = rules_admin.module
 files[] = rules_admin.inc
 dependencies[] = rules
 
-; Information added by drupal.org packaging script on 2013-10-29
-version = "7.x-2.6"
+; Information added by Drupal.org packaging script on 2014-05-02
+version = "7.x-2.7"
 core = "7.x"
 project = "rules"
-datestamp = "1383063052"
+datestamp = "1399041230"
 
diff --git a/drupal7/sites/all/modules/rules/rules_i18n/rules_i18n.info b/drupal7/sites/all/modules/rules/rules_i18n/rules_i18n.info
index 6e006fc7..4a311312 100644
--- a/drupal7/sites/all/modules/rules/rules_i18n/rules_i18n.info
+++ b/drupal7/sites/all/modules/rules/rules_i18n/rules_i18n.info
@@ -7,9 +7,9 @@ core = 7.x
 files[] = rules_i18n.i18n.inc
 files[] = rules_i18n.rules.inc
 files[] = rules_i18n.test
-; Information added by drupal.org packaging script on 2013-10-29
-version = "7.x-2.6"
+; Information added by Drupal.org packaging script on 2014-05-02
+version = "7.x-2.7"
 core = "7.x"
 project = "rules"
-datestamp = "1383063052"
+datestamp = "1399041230"
 
diff --git a/drupal7/sites/all/modules/rules/rules_scheduler/includes/rules_scheduler.views_default.inc b/drupal7/sites/all/modules/rules/rules_scheduler/includes/rules_scheduler.views_default.inc
index cdb06fb9..de345f2f 100644
--- a/drupal7/sites/all/modules/rules/rules_scheduler/includes/rules_scheduler.views_default.inc
+++ b/drupal7/sites/all/modules/rules/rules_scheduler/includes/rules_scheduler.views_default.inc
@@ -86,7 +86,7 @@ function rules_scheduler_views_default_views() {
   $handler->display->display_options['fields']['config']['field'] = 'config';
   $handler->display->display_options['fields']['config']['alter']['alter_text'] = 0;
   $handler->display->display_options['fields']['config']['alter']['make_link'] = 1;
-  $handler->display->display_options['fields']['config']['alter']['path'] = 'admin/config/workflow/rules/config/[config]';
+  $handler->display->display_options['fields']['config']['alter']['path'] = 'admin/config/workflow/rules/components/manage/[config]';
   $handler->display->display_options['fields']['config']['alter']['absolute'] = 0;
   $handler->display->display_options['fields']['config']['alter']['trim'] = 0;
   $handler->display->display_options['fields']['config']['alter']['word_boundary'] = 1;
@@ -163,7 +163,7 @@ function rules_scheduler_views_default_views() {
     t('No tasks have been scheduled.'),
     t('Tid'),
     t('Component name'),
-    t('admin/config/workflow/rules/config/[config]'),
+    t('admin/config/workflow/rules/components/manage/[config]'),
     t('Scheduled date'),
     t('User provided identifier'),
     t('Operations'),
diff --git a/drupal7/sites/all/modules/rules/rules_scheduler/rules_scheduler.info b/drupal7/sites/all/modules/rules/rules_scheduler/rules_scheduler.info
index 65463e74..5b66f537 100644
--- a/drupal7/sites/all/modules/rules/rules_scheduler/rules_scheduler.info
+++ b/drupal7/sites/all/modules/rules/rules_scheduler/rules_scheduler.info
@@ -13,9 +13,9 @@ files[] = includes/rules_scheduler.views_default.inc
 files[] = includes/rules_scheduler.views.inc
 files[] = includes/rules_scheduler_views_filter.inc
 
-; Information added by drupal.org packaging script on 2013-10-29
-version = "7.x-2.6"
+; Information added by Drupal.org packaging script on 2014-05-02
+version = "7.x-2.7"
 core = "7.x"
 project = "rules"
-datestamp = "1383063052"
+datestamp = "1399041230"
 
diff --git a/drupal7/sites/all/modules/rules/rules_scheduler/rules_scheduler.install b/drupal7/sites/all/modules/rules/rules_scheduler/rules_scheduler.install
index 982dcf77..202c861a 100644
--- a/drupal7/sites/all/modules/rules/rules_scheduler/rules_scheduler.install
+++ b/drupal7/sites/all/modules/rules/rules_scheduler/rules_scheduler.install
@@ -144,12 +144,14 @@ function rules_scheduler_update_7203() {
  * Rename rules_scheduler.state into rules_scheduler.data.
  */
 function rules_scheduler_update_7204() {
-  db_change_field('rules_scheduler', 'state', 'data', array(
-    'type' => 'text',
-    'not null' => FALSE,
-    'serialize' => TRUE,
-    'description' => 'The whole, serialized evaluation data.',
-  ));
+  if (db_field_exists('rules_scheduler', 'state')) {
+    db_change_field('rules_scheduler', 'state', 'data', array(
+      'type' => 'text',
+      'not null' => FALSE,
+      'serialize' => TRUE,
+      'description' => 'The whole, serialized evaluation data.',
+    ));
+  }
 }
 
 /**
diff --git a/drupal7/sites/all/modules/rules/rules_scheduler/rules_scheduler.module b/drupal7/sites/all/modules/rules/rules_scheduler/rules_scheduler.module
index d3350322..b74973d5 100644
--- a/drupal7/sites/all/modules/rules/rules_scheduler/rules_scheduler.module
+++ b/drupal7/sites/all/modules/rules/rules_scheduler/rules_scheduler.module
@@ -40,6 +40,11 @@ function rules_scheduler_cron_queue_info() {
  */
 function rules_scheduler_run_task(array $task) {
   try {
+    // BC support for tasks that have been already queued, before update
+    // rules_scheduler_update_7204() ran.
+    if (isset($task['state'])) {
+      $task['data'] = $task['state'];
+    }
     rules_scheduler_task_handler($task)->runTask();
   }
   catch (RulesEvaluationException $e) {
@@ -189,10 +194,13 @@ function rules_scheduler_queue_tasks() {
  * Implements hook_rules_config_delete().
  */
 function rules_scheduler_rules_config_delete($rules_config) {
-  // Delete all tasks scheduled for this config.
-  db_delete('rules_scheduler')
-    ->condition('config', $rules_config->name)
-    ->execute();
+  // Only react on real delete, not revert.
+  if (!$rules_config->hasStatus(ENTITY_IN_CODE)) {
+    // Delete all tasks scheduled for this config.
+    db_delete('rules_scheduler')
+      ->condition('config', $rules_config->name)
+      ->execute();
+  }
 }
 
 /**
diff --git a/drupal7/sites/all/modules/rules/rules_scheduler/tests/rules_scheduler_test.info b/drupal7/sites/all/modules/rules/rules_scheduler/tests/rules_scheduler_test.info
index a9fc9d32..df1405b2 100644
--- a/drupal7/sites/all/modules/rules/rules_scheduler/tests/rules_scheduler_test.info
+++ b/drupal7/sites/all/modules/rules/rules_scheduler/tests/rules_scheduler_test.info
@@ -5,9 +5,9 @@ core = 7.x
 files[] = rules_scheduler_test.inc
 hidden = TRUE
 
-; Information added by drupal.org packaging script on 2013-10-29
-version = "7.x-2.6"
+; Information added by Drupal.org packaging script on 2014-05-02
+version = "7.x-2.7"
 core = "7.x"
 project = "rules"
-datestamp = "1383063052"
+datestamp = "1399041230"
 
diff --git a/drupal7/sites/all/modules/rules/tests/rules_test.info b/drupal7/sites/all/modules/rules/tests/rules_test.info
index 42373b4d..c87a8f96 100644
--- a/drupal7/sites/all/modules/rules/tests/rules_test.info
+++ b/drupal7/sites/all/modules/rules/tests/rules_test.info
@@ -6,9 +6,9 @@ files[] = rules_test.rules.inc
 files[] = rules_test.rules_defaults.inc
 hidden = TRUE
 
-; Information added by drupal.org packaging script on 2013-10-29
-version = "7.x-2.6"
+; Information added by Drupal.org packaging script on 2014-05-02
+version = "7.x-2.7"
 core = "7.x"
 project = "rules"
-datestamp = "1383063052"
+datestamp = "1399041230"
 
diff --git a/drupal7/sites/all/modules/rules/ui/ui.data.inc b/drupal7/sites/all/modules/rules/ui/ui.data.inc
index 8ee91f01..f99486b3 100644
--- a/drupal7/sites/all/modules/rules/ui/ui.data.inc
+++ b/drupal7/sites/all/modules/rules/ui/ui.data.inc
@@ -300,6 +300,23 @@ class RulesDataUIInteger extends RulesDataUIText {
   }
 }
 
+/**
+ * UI for IP addresses.
+ */
+class RulesDataUIIPAddress extends RulesDataUIText {
+
+  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
+    $form = parent::inputForm($name, $info, $settings, $element);
+    if (empty($info['options list'])) {
+      $form[$name]['#type'] = 'textfield';
+      $form[$name]['#description'] = t('If not provided, the IP address of the current user will be used.');
+    }
+    $form[$name]['#element_validate'][] = 'rules_ui_element_ip_address_validate';
+    $form[$name]['#rows'] = 1;
+    return $form;
+  }
+}
+
 /**
  * UI for boolean data.
  */
diff --git a/drupal7/sites/all/modules/rules/ui/ui.forms.inc b/drupal7/sites/all/modules/rules/ui/ui.forms.inc
index b81fb39e..b01e0f53 100644
--- a/drupal7/sites/all/modules/rules/ui/ui.forms.inc
+++ b/drupal7/sites/all/modules/rules/ui/ui.forms.inc
@@ -684,6 +684,16 @@ function rules_ui_element_decimal_validate($element, &$form_state) {
   }
 }
 
+/**
+ * FAPI callback to validate an IP address.
+ */
+function rules_ui_element_ip_address_validate($element, &$form_state) {
+  $value = $element['#value'];
+  if ($value != '' && !filter_var($value, FILTER_VALIDATE_IP)) {
+    form_error($element, t('%name is not a valid IP address.', array('%name' => $element['#title'])));
+  }
+}
+
 /**
  * FAPI validation of a date element. Makes sure the specified date format is
  * correct and converts date values specifiy a fixed (= non relative) date to
