Index: modules/contact/contact.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/contact/contact.module,v
retrieving revision 1.128
diff -u -p -r1.128 contact.module
--- modules/contact/contact.module	26 Sep 2009 00:13:19 -0000	1.128
+++ modules/contact/contact.module	8 Oct 2009 17:06:18 -0000
@@ -105,6 +105,21 @@ function contact_menu() {
 }
 
 /**
+ * Implement hook_theme().
+ */
+function contact_theme() {
+  return array(
+    'contact_link' => array(
+      'arguments' => array(
+        'account' => NULL,
+        'text' => '',
+        'image' => FALSE,
+      ),
+    ),
+  );
+}
+
+/**
  * Determine permission to a user's personal contact form.
  */
 function _contact_personal_tab_access($account) {
@@ -202,3 +217,31 @@ function contact_form_user_admin_setting
     '#default_value' => 1,
   );
 }
+
+/**
+ * Theme a link to a user's contact page.
+ *
+ * @param $account
+ *   The user account being contacted.
+ * @param $text
+ *   The text or HTML to use in the link.
+ * @param $html
+ *   A boolean that is TRUE if parameter $text is HTML.
+ * @return
+ *   The themed link to the user's contact page.
+ */
+function theme_contact_link(stdClass $account, $text, $html) {
+  global $user;
+
+  if (_contact_personal_tab_access($account)) {
+    if (!$text) {
+      $text = t('Contact');
+      $html = FALSE;
+    }
+    $attributes = array(
+      'title' => t('Contact @username', array('@username' => $account->name)),
+      'html' => $html,
+    );
+    return l($text, 'user/'. $account->uid . '/contact', array('attributes' => $attributes));
+  }
+}
