Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.1009 diff -u -p -r1.1009 common.inc --- includes/common.inc 9 Oct 2009 00:59:54 -0000 1.1009 +++ includes/common.inc 9 Oct 2009 01:24:00 -0000 @@ -1302,14 +1302,14 @@ function fix_gpc_magic() { * check_plain, to escape HTML characters. Use this for any output that's * displayed within a Drupal page. * @code - * drupal_set_title($title = t("@name's blog", array('@name' => $account->name)), PASS_THROUGH); + * drupal_set_title($title = t("@name's blog", array('@name' => format_username($account))), PASS_THROUGH); * @endcode * * - %variable, which indicates that the string should be HTML escaped and * highlighted with theme_placeholder() which shows up by default as * emphasized. * @code - * $message = t('%name-from sent %name-to an e-mail.', array('%name-from' => $user->name, '%name-to' => $account->name)); + * $message = t('%name-from sent %name-to an e-mail.', array('%name-from' => format_username($user), '%name-to' => format_username($account))); * @endcode * * When using t(), try to put entire sentences and strings in one t() call. @@ -2321,6 +2321,33 @@ function _format_date_callback(array $ma } /** + * Format a username. + * + * By default, the passed in object's 'name' property is used if it exists, or + * else, the site-defined value for the 'anonymous' variable. However, a module + * may override this by implementing hook_username_alter(&$name, $account). + * + * @see hook_username_alter() + * + * @param $account + * The account object for the user whose name is to be formatted. + * + * @return + * An unsanitized string with the username to display. The code receiving + * this result must ensure that check_plain() is called on it before it is + * printed to the page. + */ +function format_username($account) { + $name = !empty($account->name) ? $account->name : variable_get('anonymous', t('Anonymous')); + // Faster than drupal_alter(), and format_username() gets called a lot. + foreach (module_implements('username_alter') as $module) { + $function = $module . '_username_alter'; + $function($name, $account); + } + return $name; +} + +/** * @} End of "defgroup format". */ Index: includes/theme.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.inc,v retrieving revision 1.532 diff -u -p -r1.532 theme.inc --- includes/theme.inc 9 Oct 2009 00:59:54 -0000 1.532 +++ includes/theme.inc 9 Oct 2009 01:24:00 -0000 @@ -1905,12 +1905,17 @@ function template_preprocess_username(&$ else { $variables['uid'] = (int)$account->uid; } - if (empty($account->name)) { - $variables['name'] = variable_get('anonymous', t('Anonymous')); - } - else { - $variables['name'] = $account->name; + + // Set the name to a formatted name that is safe for printing and + // that won't break tables by being too long. Keep an unshortened, + // unsanitized version, in case other preproces functions want to implement + // their own shortening logic or add markup. If they do so, they must ensure + // that $variables['name'] is safe for printing. + $name = $variables['name_unsafe'] = format_username($account); + if (drupal_strlen($name) > 20) { + $name = drupal_substr($name, 0, 15) . '...'; } + $variables['name'] = check_plain($name); $variables['profile_access'] = user_access('access user profiles'); $variables['link_attributes'] = array(); @@ -1929,12 +1934,6 @@ function template_preprocess_username(&$ $variables['link_options']['html'] = TRUE; // Set a default class. $variables['attributes_array'] = array('class' => array('username')); - // Shorten the name when it is too long or it will break many tables. - if (drupal_strlen($variables['name']) > 20) { - $variables['name'] = drupal_substr($variables['name'], 0, 15) . '...'; - } - // Make sure name is safe for use in the theme function. - $variables['name'] = check_plain($variables['name']); } /** @@ -2138,7 +2137,7 @@ function template_preprocess_html(&$vari else { $variables['classes_array'][] = 'no-sidebars'; } - + // Populate the body classes. if ($suggestions = template_page_suggestions(arg(), 'page')) { foreach ($suggestions as $suggestion) { @@ -2182,7 +2181,7 @@ function template_preprocess_html(&$vari } } $variables['head_title'] = implode(' | ', $head_title); - + // Populate the page template suggestions. if ($suggestions = template_page_suggestions(arg(), 'html')) { $variables['template_files'] = $suggestions; Index: modules/blog/blog.module =================================================================== RCS file: /cvs/drupal/drupal/modules/blog/blog.module,v retrieving revision 1.336 diff -u -p -r1.336 blog.module --- modules/blog/blog.module 9 Oct 2009 00:59:55 -0000 1.336 +++ modules/blog/blog.module 9 Oct 2009 01:24:01 -0000 @@ -27,7 +27,7 @@ function blog_user_view($account) { $account->content['summary']['blog'] = array( '#type' => 'user_profile_item', '#title' => t('Blog'), - '#markup' => l(t('View recent blog entries'), "blog/$account->uid", array('attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => $account->name))))), + '#markup' => l(t('View recent blog entries'), "blog/$account->uid", array('attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => format_username($account)))))), '#attributes' => array('class' => array('blog')), ); } @@ -60,7 +60,7 @@ function blog_form($node, $form_state) { function blog_view($node, $build_mode) { if ((bool)menu_get_object()) { // Breadcrumb navigation. - drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('Blogs'), 'blog'), l(t("!name's blog", array('!name' => $node->name)), 'blog/' . $node->uid))); + drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('Blogs'), 'blog'), l(t("!name's blog", array('!name' => format_username($node))), 'blog/' . $node->uid))); } return $node; } @@ -72,9 +72,9 @@ function blog_node_view($node, $build_mo if ($build_mode != 'rss') { if ($node->type == 'blog' && arg(0) != 'blog' || arg(1) != $node->uid) { $links['blog_usernames_blog'] = array( - 'title' => t("!username's blog", array('!username' => $node->name)), + 'title' => t("!username's blog", array('!username' => format_username($node))), 'href' => "blog/$node->uid", - 'attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => $node->name))), + 'attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => format_username($node)))), ); $node->content['links']['blog'] = array( '#theme' => 'links', Index: modules/blog/blog.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/blog/blog.pages.inc,v retrieving revision 1.23 diff -u -p -r1.23 blog.pages.inc --- modules/blog/blog.pages.inc 9 Oct 2009 00:59:55 -0000 1.23 +++ modules/blog/blog.pages.inc 9 Oct 2009 01:24:01 -0000 @@ -12,7 +12,7 @@ function blog_page_user($account) { global $user; - drupal_set_title($title = t("@name's blog", array('@name' => $account->name)), PASS_THROUGH); + drupal_set_title($title = t("@name's blog", array('@name' => format_username($account))), PASS_THROUGH); $items = array(); @@ -123,7 +123,7 @@ function blog_feed_user($account) { ->execute() ->fetchCol(); - $channel['title'] = t("!name's blog", array('!name' => $account->name)); + $channel['title'] = t("!name's blog", array('!name' => format_username($account))); $channel['link'] = url('blog/' . $account->uid, array('absolute' => TRUE)); node_feed($nids, $channel); Index: modules/blog/blog.test =================================================================== RCS file: /cvs/drupal/drupal/modules/blog/blog.test,v retrieving revision 1.18 diff -u -p -r1.18 blog.test --- modules/blog/blog.test 22 Aug 2009 00:58:52 -0000 1.18 +++ modules/blog/blog.test 9 Oct 2009 01:24:01 -0000 @@ -38,7 +38,7 @@ class BlogTestCase extends DrupalWebTest $this->drupalGet('blog/' . $this->big_user->uid); $this->assertResponse(200); - $this->assertTitle(t("@name's blog", array('@name' => $this->big_user->name)) . ' | Drupal', t('Blog title was displayed')); + $this->assertTitle(t("@name's blog", array('@name' => format_username($this->big_user))) . ' | Drupal', t('Blog title was displayed')); $this->assertText(t('You are not allowed to post a new blog entry.'), t('No new entries can be posted without the right permission')); } @@ -50,8 +50,8 @@ class BlogTestCase extends DrupalWebTest $this->drupalGet('blog/' . $this->own_user->uid); $this->assertResponse(200); - $this->assertTitle(t("@name's blog", array('@name' => $this->own_user->name)) . ' | Drupal', t('Blog title was displayed')); - $this->assertText(t('!author has not created any blog entries.', array('!author' => $this->own_user->name)), t('Users blog displayed with no entries')); + $this->assertTitle(t("@name's blog", array('@name' => format_username($this->own_user))) . ' | Drupal', t('Blog title was displayed')); + $this->assertText(t('@author has not created any blog entries.', array('@author' => format_username($this->own_user))), t('Users blog displayed with no entries')); } /** @@ -139,7 +139,7 @@ class BlogTestCase extends DrupalWebTest $this->drupalGet('node/' . $node->nid); $this->assertResponse(200); $this->assertTitle($node->title . ' | Drupal', t('Blog node was displayed')); - $this->assertText(t('Home ' . $crumb . ' Blogs ' . $crumb . ' @name' . $quote . 's blog', array('@name' => $node_user->name)), t('Breadcrumbs were displayed')); + $this->assertText(t('Home ' . $crumb . ' Blogs ' . $crumb . ' @name' . $quote . 's blog', array('@name' => format_username($node_user))), t('Breadcrumbs were displayed')); // View blog edit node. $this->drupalGet('node/' . $node->nid . '/edit'); @@ -180,7 +180,7 @@ class BlogTestCase extends DrupalWebTest // Confirm the recent blog entries link goes to the user's blog page. $this->clickLink('View recent blog entries'); - $this->assertTitle(t("@name's blog | Drupal", array('@name' => $user->name)), t('View recent blog entries link target was correct')); + $this->assertTitle(t("@name's blog | Drupal", array('@name' => format_username($user))), t('View recent blog entries link target was correct')); // Confirm a blog page was displayed. $this->drupalGet('blog'); @@ -191,7 +191,7 @@ class BlogTestCase extends DrupalWebTest // Confirm a blog page was displayed per user. $this->drupalGet('blog/' . $user->uid); - $this->assertTitle(t("@name's blog | Drupal", array('@name' => $user->name)), t('User blog node was displayed')); + $this->assertTitle(t("@name's blog | Drupal", array('@name' => format_username($user))), t('User blog node was displayed')); // Confirm a blog feed was displayed. $this->drupalGet('blog/feed'); @@ -199,6 +199,6 @@ class BlogTestCase extends DrupalWebTest // Confirm a blog feed was displayed per user. $this->drupalGet('blog/' . $user->uid . '/feed'); - $this->assertTitle(t("@name's blog", array('@name' => $user->name)), t('User blog feed was displayed')); + $this->assertTitle(t("@name's blog", array('@name' => format_username($user))), t('User blog feed was displayed')); } } Index: modules/comment/comment.tokens.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.tokens.inc,v retrieving revision 1.2 diff -u -p -r1.2 comment.tokens.inc --- modules/comment/comment.tokens.inc 30 Sep 2009 18:37:30 -0000 1.2 +++ modules/comment/comment.tokens.inc 9 Oct 2009 01:24:01 -0000 @@ -151,7 +151,7 @@ function comment_tokens($type, $tokens, break; case 'name': - $name = ($comment->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $comment->name; + $name = format_username($comment); $replacements[$original] = $sanitize ? filter_xss($name) : $name; break; @@ -189,7 +189,7 @@ function comment_tokens($type, $tokens, // Default values for the chained tokens handled below. case 'author': - $replacements[$original] = $sanitize ? filter_xss($comment->name) : $comment->name; + $replacements[$original] = $sanitize ? filter_xss(format_username($comment)) : format_username($comment); break; case 'parent': Index: modules/contact/contact.module =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.module,v retrieving revision 1.129 diff -u -p -r1.129 contact.module --- modules/contact/contact.module 9 Oct 2009 00:54:33 -0000 1.129 +++ modules/contact/contact.module 9 Oct 2009 01:24:01 -0000 @@ -178,8 +178,8 @@ function contact_mail($key, &$message, $ $user = $params['user']; $account = $params['account']; $message['subject'] .= '[' . variable_get('site_name', 'Drupal') . '] ' . $params['subject']; - $message['body'][] = "$account->name,"; - $message['body'][] = t("!name (!name-url) has sent you a message via your contact form (!form-url) at !site.", array('!name' => $user->name, '!name-url' => url("user/$user->uid", array('absolute' => TRUE, 'language' => $language)), '!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)), '!site' => variable_get('site_name', 'Drupal')), array('langcode' => $language->language)); + $message['body'][] = format_username($account) . ','; + $message['body'][] = t("!name (!name-url) has sent you a message via your contact form (!form-url) at !site.", array('!name' => format_username($user), '!name-url' => url("user/$user->uid", array('absolute' => TRUE, 'language' => $language)), '!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)), '!site' => variable_get('site_name', 'Drupal')), array('langcode' => $language->language)); $message['body'][] = t("If you don't want to receive such e-mails, you can change your settings at !url.", array('!url' => url("user/$account->uid", array('absolute' => TRUE, 'language' => $language))), array('langcode' => $language->language)); $message['body'][] = t('Message:', array(), array('langcode' => $language->language)); $message['body'][] = $params['message']; Index: modules/contact/contact.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.pages.inc,v retrieving revision 1.28 diff -u -p -r1.28 contact.pages.inc --- modules/contact/contact.pages.inc 9 Oct 2009 00:59:56 -0000 1.28 +++ modules/contact/contact.pages.inc 9 Oct 2009 01:24:01 -0000 @@ -54,7 +54,7 @@ function contact_site_form() { '#type' => 'textfield', '#title' => t('Your name'), '#maxlength' => 255, - '#default_value' => $user->uid ? $user->name : '', + '#default_value' => format_username($user), '#required' => TRUE, ); $form['mail'] = array( @@ -161,7 +161,7 @@ function contact_personal_page($account) $output = t("You cannot send more than %number messages in @interval. Please try again later.", array('%number' => variable_get('contact_threshold_limit', 3), '@interval' => format_interval(variable_get('contact_threshold_window', 3600)))); } else { - drupal_set_title($account->name); + drupal_set_title(format_username($account)); $output = drupal_get_form('contact_personal_form', $account); } Index: modules/node/node.tokens.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.tokens.inc,v retrieving revision 1.3 diff -u -p -r1.3 node.tokens.inc --- modules/node/node.tokens.inc 30 Sep 2009 18:37:30 -0000 1.3 +++ modules/node/node.tokens.inc 9 Oct 2009 01:24:02 -0000 @@ -172,7 +172,7 @@ function node_tokens($type, $tokens, arr // Default values for the chained tokens handled below. case 'author': - $name = ($node->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $node->name; + $name = format_username($node); $replacements[$original] = $sanitize ? filter_xss($name) : $name; break; Index: modules/openid/openid.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/openid/openid.pages.inc,v retrieving revision 1.22 diff -u -p -r1.22 openid.pages.inc --- modules/openid/openid.pages.inc 21 Sep 2009 06:44:14 -0000 1.22 +++ modules/openid/openid.pages.inc 9 Oct 2009 01:24:02 -0000 @@ -28,7 +28,7 @@ function openid_authentication_page() { * Menu callback; Manage OpenID identities for the specified user. */ function openid_user_identities($account) { - drupal_set_title($account->name); + drupal_set_title(format_username($account)); drupal_add_css(drupal_get_path('module', 'openid') . '/openid.css'); // Check to see if we got a response @@ -54,8 +54,8 @@ function openid_user_identities($account } $build['openid_table'] = array( - '#theme' => 'table', - '#header' => $header, + '#theme' => 'table', + '#header' => $header, '#rows' => $rows, ); $build['openid_user_add'] = drupal_get_form('openid_user_add'); Index: modules/php/php.module =================================================================== RCS file: /cvs/drupal/drupal/modules/php/php.module,v retrieving revision 1.21 diff -u -p -r1.21 php.module --- modules/php/php.module 28 Sep 2009 22:22:54 -0000 1.21 +++ modules/php/php.module 9 Oct 2009 01:24:02 -0000 @@ -105,7 +105,7 @@ print t(\'Welcome visitor! Thank you for
global $user; if ($user->uid) { - print t(\'Welcome @name! Thank you for visiting.\', array(\'@name\' => $user->name)); + print t(\'Welcome @name! Thank you for visiting.\', array(\'@name\' => format_username($user))); } else { print t(\'Welcome visitor! Thank you for visiting.\'); Index: modules/profile/profile.module =================================================================== RCS file: /cvs/drupal/drupal/modules/profile/profile.module,v retrieving revision 1.277 diff -u -p -r1.277 profile.module --- modules/profile/profile.module 9 Oct 2009 01:00:02 -0000 1.277 +++ modules/profile/profile.module 9 Oct 2009 01:24:02 -0000 @@ -202,7 +202,7 @@ function profile_block_view($delta = '') } if ($output) { - $block['subject'] = t('About %name', array('%name' => $account->name)); + $block['subject'] = t('About %name', array('%name' => format_username($account))); $block['content'] = $output; return $block; } Index: modules/statistics/statistics.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/statistics/statistics.pages.inc,v retrieving revision 1.17 diff -u -p -r1.17 statistics.pages.inc --- modules/statistics/statistics.pages.inc 9 Oct 2009 01:00:04 -0000 1.17 +++ modules/statistics/statistics.pages.inc 9 Oct 2009 01:24:02 -0000 @@ -44,8 +44,8 @@ function statistics_node_tracker() { drupal_set_title($node->title); $build['statistics_table'] = array( - '#theme' => 'table', - '#header' => $header, + '#theme' => 'table', + '#header' => $header, '#rows' => $rows ); $build['statistics_pager'] = array('#theme' => 'pager'); @@ -83,10 +83,10 @@ function statistics_user_tracker() { $rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 3)); } - drupal_set_title($account->name); + drupal_set_title(format_username($account)); $build['statistics_table'] = array( - '#theme' => 'table', - '#header' => $header, + '#theme' => 'table', + '#header' => $header, '#rows' => $rows ); $build['statistics_pager'] = array('#theme' => 'pager'); Index: modules/system/system.api.php =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.api.php,v retrieving revision 1.80 diff -u -p -r1.80 system.api.php --- modules/system/system.api.php 1 Oct 2009 13:16:17 -0000 1.80 +++ modules/system/system.api.php 9 Oct 2009 01:24:02 -0000 @@ -1077,7 +1077,7 @@ function hook_mail($key, &$message, $par $context = $params['context']; $variables = array( '%site_name' => variable_get('site_name', 'Drupal'), - '%username' => $account->name, + '%username' => format_username($account), ); if ($context['hook'] == 'taxonomy') { $object = $params['object']; @@ -2362,5 +2362,27 @@ function hook_action_info_alter(&$action } /** + * Alter the username that is displayed for a user. + * + * Called by format_username() to allow modules to alter the username that's + * displayed. Can be used to ensure user privacy in situations where + * $account->name is too revealing. + * + * @param &$name + * The string that format_username() will return. + * + * @param $account + * The account object passed to format_username(). + * + * @see format_username() + */ +function hook_username_alter(&$name, $account) { + // Display the user's uid instead of name. + if (isset($account->uid)) { + $name = t('User !uid', array('!uid' => $account->uid)); + } +} + +/** * @} End of "addtogroup hooks". */ Index: modules/system/system.test =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.test,v retrieving revision 1.81 diff -u -p -r1.81 system.test --- modules/system/system.test 3 Oct 2009 19:16:04 -0000 1.81 +++ modules/system/system.test 9 Oct 2009 01:24:03 -0000 @@ -1196,9 +1196,9 @@ class TokenReplaceTestCase extends Drupa $source .= '[bogus:token]'; // Nonexistent token, should be untouched $target = check_plain($node->title); - $target .= check_plain($account->name); + $target .= check_plain(format_username($account)); $target .= format_interval(REQUEST_TIME - $node->created, 2, $language->language); - $target .= check_plain($user->name); + $target .= check_plain(format_username($user)); $target .= '[user:name]'; $target .= format_date(REQUEST_TIME, 'short', '', NULL, $language->language); $target .= '[bogus:token]'; @@ -1210,7 +1210,7 @@ class TokenReplaceTestCase extends Drupa // passed properly through the call stack and being handled correctly by a 'known' // token, [node:title]. $this->assertFalse(strcmp($target, $result), t('Basic placeholder tokens replaced.')); - + $raw_tokens = array('title' => '[node:title]'); $generated = token_generate('node', $raw_tokens, array('node' => $node)); $this->assertFalse(strcmp($generated['[node:title]'], check_plain($node->title)), t('Token sanitized.')); Index: modules/system/system.tokens.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.tokens.inc,v retrieving revision 1.3 diff -u -p -r1.3 system.tokens.inc --- modules/system/system.tokens.inc 2 Oct 2009 14:49:10 -0000 1.3 +++ modules/system/system.tokens.inc 9 Oct 2009 01:24:03 -0000 @@ -51,7 +51,7 @@ function system_token_info() { $site['url-brief'] = array( 'name' => t("URL (brief)"), 'description' => t("The URL of the site's front page without the protocol."), - ); + ); $site['login-url'] = array( 'name' => t("Login page"), 'description' => t("The URL of the site's login page."), @@ -186,7 +186,7 @@ function system_tokens($type, $tokens, a break; case 'url-brief': - $replacements[$original] = preg_replace('!^https?://!', '', url('', $url_options)); + $replacements[$original] = preg_replace('!^https?://!', '', url(' ', $url_options)); break; case 'login-url': @@ -293,7 +293,7 @@ function system_tokens($type, $tokens, a case 'owner': $account = user_load($file->uid); - $replacements[$original] = $sanitize ? filter_xss($user->name) : $user->name; + $replacements[$original] = $sanitize ? filter_xss(format_username($user)) : format_username($user); break; } } Index: modules/toolbar/toolbar.module =================================================================== RCS file: /cvs/drupal/drupal/modules/toolbar/toolbar.module,v retrieving revision 1.13 diff -u -p -r1.13 toolbar.module --- modules/toolbar/toolbar.module 15 Sep 2009 20:50:48 -0000 1.13 +++ modules/toolbar/toolbar.module 9 Oct 2009 01:24:03 -0000 @@ -32,7 +32,7 @@ function toolbar_theme($existing, $type, /** * Implement hook_page_build(). - * + * * Add admin toolbar to the page_top region automatically. */ function toolbar_page_build(&$page) { @@ -89,7 +89,7 @@ function toolbar_build() { '#theme' => 'links', '#links' => array( 'account' => array( - 'title' => t('Hello @username', array('@username' => $user->name)), + 'title' => t('Hello @username', array('@username' => format_username($user))), 'href' => 'user', 'html' => TRUE, ), @@ -168,7 +168,7 @@ function toolbar_menu_navigation_links($ /** * Checks whether an item is in the active trail. * - * Useful when using a menu generated by menu_tree_all_data() which does + * Useful when using a menu generated by menu_tree_all_data() which does * not set the 'in_active_trail' flag on items. * * @todo Index: modules/tracker/tracker.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/tracker/tracker.pages.inc,v retrieving revision 1.26 diff -u -p -r1.26 tracker.pages.inc --- modules/tracker/tracker.pages.inc 9 Oct 2009 01:00:06 -0000 1.26 +++ modules/tracker/tracker.pages.inc 9 Oct 2009 01:24:03 -0000 @@ -19,7 +19,7 @@ function tracker_page($account = NULL, $ // When viewed from user/%user/track, display the name of the user // as page title -- the tab title remains Track so this needs to be done // here and not in the menu definition. - drupal_set_title($account->name); + drupal_set_title(format_username($account)); } } else { Index: modules/user/user.api.php =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.api.php,v retrieving revision 1.13 diff -u -p -r1.13 user.api.php --- modules/user/user.api.php 22 Sep 2009 07:50:16 -0000 1.13 +++ modules/user/user.api.php 9 Oct 2009 01:24:03 -0000 @@ -353,7 +353,7 @@ function hook_user_view($account) { $account->content['summary']['blog'] = array( '#type' => 'user_profile_item', '#title' => t('Blog'), - '#markup' => l(t('View recent blog entries'), "blog/$account->uid", array('attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => $account->name))))), + '#markup' => l(t('View recent blog entries'), "blog/$account->uid", array('attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => format_username($account)))))), '#attributes' => array('class' => array('blog')), ); } @@ -405,7 +405,7 @@ function hook_user_role_update($role) { * Inform other modules that a user role has been deleted. * * This hook allows you act when a user role has been deleted. - * If your module stores references to roles, it's recommended that you + * If your module stores references to roles, it's recommended that you * implement this hook and delete existing instances of the deleted role * in your module database tables. * Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.1057 diff -u -p -r1.1057 user.module --- modules/user/user.module 9 Oct 2009 01:00:07 -0000 1.1057 +++ modules/user/user.module 9 Oct 2009 01:24:03 -0000 @@ -813,7 +813,7 @@ function user_search_execute($keys = NUL ->limit(15) ->execute(); foreach ($result as $account) { - $find[] = array('title' => $account->name . ' (' . $account->mail . ')', 'link' => url('user/' . $account->uid, array('absolute' => TRUE))); + $find[] = array('title' => format_username($account) . ' (' . $account->mail . ')', 'link' => url('user/' . $account->uid, array('absolute' => TRUE))); } return $find; } @@ -1119,7 +1119,7 @@ function template_preprocess_user_pictur $filepath = variable_get('user_picture_default', ''); } if (isset($filepath)) { - $alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous')))); + $alt = t("@user's picture", array('@user' => format_username($account))); if (module_exists('image') && $style = variable_get('user_picture_style', '')) { $variables['user_picture'] = theme('image_style', array('style_name' => $style, 'path' => $filepath, 'alt' => $alt, 'title' => $alt, 'attributes' => array(), 'getsize' => FALSE)); } @@ -1473,7 +1473,7 @@ function user_uid_optional_to_arg($arg) * Menu item title callback - use the user name. */ function user_page_title($account) { - return $account->name; + return format_username($account); } /** @@ -2057,7 +2057,7 @@ function _user_cancel($edit, $account, $ * The user account of the profile being viewed. * * To theme user profiles, copy modules/user/user-profile.tpl.php - * to your theme directory, and edit it as instructed in that file's comments. + * to your theme directory, and edit it as instructed in that file's comments. * * @param $account * A user object. @@ -2072,7 +2072,7 @@ function user_build($account) { $build = $account->content; // We don't need duplicate rendering info in account->content. unset($account->content); - + $build += array( '#theme' => 'user_profile', '#account' => $account, Index: modules/user/user.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.pages.inc,v retrieving revision 1.57 diff -u -p -r1.57 user.pages.inc --- modules/user/user.pages.inc 29 Sep 2009 15:31:17 -0000 1.57 +++ modules/user/user.pages.inc 9 Oct 2009 01:24:03 -0000 @@ -213,7 +213,7 @@ function template_preprocess_user_profil * Menu callback; Present the form to edit a given user or profile category. */ function user_edit($account, $category = 'account') { - drupal_set_title($account->name); + drupal_set_title(format_username($account)); return drupal_get_form('user_profile_form', $account, $category); } Index: modules/user/user.test =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.test,v retrieving revision 1.62 diff -u -p -r1.62 user.test --- modules/user/user.test 19 Sep 2009 10:54:35 -0000 1.62 +++ modules/user/user.test 9 Oct 2009 01:24:03 -0000 @@ -9,16 +9,16 @@ class UserRegistrationTestCase extends D 'group' => 'User' ); } - + function testRegistrationWithEmailVerification() { // Require e-mail verification. variable_set('user_email_verification', TRUE); - + // Set registration to administrator only. variable_set('user_register', 0); $this->drupalGet('user/register'); $this->assertResponse(403, t('Registration page is inaccessible when only administrators can create accounts.')); - + // Allow registration by site visitors without administrator approval. variable_set('user_register', 1); $edit = array(); @@ -28,7 +28,7 @@ class UserRegistrationTestCase extends D $this->assertText(t('Your password and further instructions have been sent to your e-mail address.'), t('User registered successfully.')); $new_user = reset(user_load_multiple(array(), array('name' => $name, 'mail' => $mail))); $this->assertTrue($new_user->status, t('New account is active after registration.')); - + // Allow registration by site visitors, but require administrator approval. variable_set('user_register', 2); $edit = array(); @@ -38,17 +38,17 @@ class UserRegistrationTestCase extends D $new_user = reset(user_load_multiple(array(), array('name' => $name, 'mail' => $mail))); $this->assertFalse($new_user->status, t('New account is blocked until approved by an administrator.')); } - + function testRegistrationWithoutEmailVerification() { // Don't require e-mail verification. variable_set('user_email_verification', FALSE); - + // Allow registration by site visitors without administrator approval. variable_set('user_register', 1); $edit = array(); $edit['name'] = $name = $this->randomName(); $edit['mail'] = $mail = $edit['name'] . '@example.com'; - + // Try entering a mismatching password. $edit['pass[pass1]'] = '99999.0'; $edit['pass[pass2]'] = '99999'; @@ -62,7 +62,7 @@ class UserRegistrationTestCase extends D $new_user = reset(user_load_multiple(array(), array('name' => $name, 'mail' => $mail))); $this->assertText(t('Registration successful. You are now logged in.'), t('Users are logged in after registering.')); $this->drupalLogout(); - + // Allow registration by site visitors, but require administrator approval. variable_set('user_register', 2); $edit = array(); @@ -72,7 +72,7 @@ class UserRegistrationTestCase extends D $edit['pass[pass2]'] = $pass; $this->drupalPost('user/register', $edit, t('Create new account')); $this->assertText(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.'), t('Users are notified of pending approval')); - + // Try to login before administrator approval. $auth = array( 'name' => $name, @@ -90,7 +90,7 @@ class UserRegistrationTestCase extends D ); $this->drupalPost('user/' . $new_user->uid . '/edit', $edit, t('Save')); $this->drupalLogout(); - + // Login after administrator approval. $this->drupalPost('user/login', $auth, t('Log in')); $this->assertText(t('Member for'), t('User can log in after administrator approval.')); @@ -99,21 +99,21 @@ class UserRegistrationTestCase extends D function testRegistrationDefaultValues() { // Allow registration by site visitors without administrator approval. variable_set('user_register', 1); - + // Don't require e-mail verification. variable_set('user_email_verification', FALSE); - + // Set the default timezone to Brussels. variable_set('configurable_timezones', 1); variable_set('date_default_timezone', 'Europe/Brussels'); - + $edit = array(); $edit['name'] = $name = $this->randomName(); $edit['mail'] = $mail = $edit['name'] . '@example.com'; $edit['pass[pass1]'] = $new_pass = $this->randomName(); $edit['pass[pass2]'] = $new_pass; $this->drupalPost('user/register', $edit, t('Create new account')); - + // Check user fields. $new_user = reset(user_load_multiple(array(), array('name' => $name, 'mail' => $mail))); $this->assertEqual($new_user->name, $name, t('Username matches.')); @@ -701,7 +701,7 @@ class UserPictureTestCase extends Drupal // user's profile page. $text = t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $test_dim)); $this->assertRaw($text, t('Image was resized.')); - $alt = t("@user's picture", array('@user' => $this->user->name)); + $alt = t("@user's picture", array('@user' => format_username($this->user))); $style = variable_get('user_picture_style', ''); $this->assertRaw(image_style_url($style, $pic_path), t("Image is displayed in user's edit page")); Index: modules/user/user.tokens.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.tokens.inc,v retrieving revision 1.2 diff -u -p -r1.2 user.tokens.inc --- modules/user/user.tokens.inc 30 Sep 2009 18:37:30 -0000 1.2 +++ modules/user/user.tokens.inc 9 Oct 2009 01:24:03 -0000 @@ -86,7 +86,7 @@ function user_tokens($type, $tokens, arr break; case 'name': - $name = ($account->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $account->name; + $name = format_username($account); $replacements[$original] = $sanitize ? filter_xss($name) : $name; break;