Commit f969b391 authored by catch's avatar catch

Issue #1227942 by Rob Loach, cweagans, tstoeckler, xjm: Rename...

Issue #1227942 by Rob Loach, cweagans, tstoeckler, xjm: Rename format_username() now that it's in user.module.
parent 39326b2c
......@@ -1484,7 +1484,7 @@ function drupal_unpack($obj, $field = 'data') {
* variable text such as user names or link URLs into translated text. Variable
* substitution looks like this:
* @code
* $text = t("@name's blog", array('@name' => format_username($account)));
* $text = t("@name's blog", array('@name' => user_format_name($account)));
* @endcode
* Basically, you can put variables like @name into your string, and t() will
* substitute their sanitized values at translation time. (See the
......
......@@ -176,7 +176,7 @@ function contact_mail($key, &$message, $params) {
'!subject' => $params['subject'],
'!category' => isset($params['category']['category']) ? $params['category']['category'] : '',
'!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)),
'!sender-name' => format_username($params['sender']),
'!sender-name' => user_format_name($params['sender']),
'!sender-url' => $params['sender']->uid ? url('user/' . $params['sender']->uid, array('absolute' => TRUE, 'language' => $language)) : $params['sender']->mail,
);
......@@ -196,7 +196,7 @@ function contact_mail($key, &$message, $params) {
case 'user_mail':
case 'user_copy':
$variables += array(
'!recipient-name' => format_username($params['recipient']),
'!recipient-name' => user_format_name($params['recipient']),
'!recipient-edit-url' => url('user/' . $params['recipient']->uid . '/edit', array('absolute' => TRUE, 'language' => $language)),
);
$message['subject'] .= t('[!site-name] !subject', $variables, array('langcode' => $language->langcode));
......
......@@ -69,7 +69,7 @@ function contact_site_form($form, &$form_state) {
'#type' => 'textfield',
'#title' => t('Your name'),
'#maxlength' => 255,
'#default_value' => $user->uid ? format_username($user) : '',
'#default_value' => $user->uid ? user_format_name($user) : '',
'#required' => TRUE,
);
$form['mail'] = array(
......@@ -195,7 +195,7 @@ function contact_personal_form($form, &$form_state, $recipient) {
drupal_exit();
}
drupal_set_title(t('Contact @username', array('@username' => format_username($recipient))), PASS_THROUGH);
drupal_set_title(t('Contact @username', array('@username' => user_format_name($recipient))), PASS_THROUGH);
if (!$user->uid) {
$form['#attached']['library'][] = array('system', 'jquery.cookie');
......@@ -211,7 +211,7 @@ function contact_personal_form($form, &$form_state, $recipient) {
'#type' => 'textfield',
'#title' => t('Your name'),
'#maxlength' => 255,
'#default_value' => $user->uid ? format_username($user) : '',
'#default_value' => $user->uid ? user_format_name($user) : '',
'#required' => TRUE,
);
$form['mail'] = array(
......
......@@ -1083,7 +1083,7 @@ class FileTokenReplaceTestCase extends FileFieldTestCase {
$tests['[file:url]'] = check_plain(file_create_url($file->uri));
$tests['[file:timestamp]'] = format_date($file->timestamp, 'medium', '', NULL, $language->langcode);
$tests['[file:timestamp:short]'] = format_date($file->timestamp, 'short', '', NULL, $language->langcode);
$tests['[file:owner]'] = check_plain(format_username($this->admin_user));
$tests['[file:owner]'] = check_plain(user_format_name($this->admin_user));
$tests['[file:owner:uid]'] = $file->uid;
// Test to make sure that we generated something for each token.
......
......@@ -2273,9 +2273,9 @@ class NodeTokenReplaceTestCase extends DrupalWebTestCase {
$tests['[node:language]'] = check_plain($node->language);
$tests['[node:url]'] = url('node/' . $node->nid, $url_options);
$tests['[node:edit-url]'] = url('node/' . $node->nid . '/edit', $url_options);
$tests['[node:author]'] = check_plain(format_username($account));
$tests['[node:author]'] = check_plain(user_format_name($account));
$tests['[node:author:uid]'] = $node->uid;
$tests['[node:author:name]'] = check_plain(format_username($account));
$tests['[node:author:name]'] = check_plain(user_format_name($account));
$tests['[node:created:since]'] = format_interval(REQUEST_TIME - $node->created, 2, $language->langcode);
$tests['[node:changed:since]'] = format_interval(REQUEST_TIME - $node->changed, 2, $language->langcode);
......@@ -2292,7 +2292,7 @@ class NodeTokenReplaceTestCase extends DrupalWebTestCase {
$tests['[node:body]'] = $node->body[$node->language][0]['value'];
$tests['[node:summary]'] = $node->body[$node->language][0]['summary'];
$tests['[node:language]'] = $node->language;
$tests['[node:author:name]'] = format_username($account);
$tests['[node:author:name]'] = user_format_name($account);
foreach ($tests as $input => $expected) {
$output = token_replace($input, array('node' => $node), array('language' => $language, 'sanitize' => FALSE));
......
......@@ -158,7 +158,7 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr
// Default values for the chained tokens handled below.
case 'author':
$account = user_load($node->uid);
$name = format_username($account);
$name = user_format_name($account);
$replacements[$original] = $sanitize ? check_plain($name) : $name;
break;
......
......@@ -27,7 +27,7 @@ function openid_authentication_page() {
* Menu callback; Manage OpenID identities for the specified user.
*/
function openid_user_identities($account) {
drupal_set_title(format_username($account));
drupal_set_title(user_format_name($account));
drupal_add_css(drupal_get_path('module', 'openid') . '/openid.css');
// Check to see if we got a response
......
......@@ -116,7 +116,7 @@ function _php_filter_tips($filter, $format, $long = FALSE) {
<pre>
global $user;
if ($user->uid) {
print t(\'Welcome @name! Thank you for visiting.\', array(\'@name\' => format_username($user)));
print t(\'Welcome @name! Thank you for visiting.\', array(\'@name\' => user_format_name($user)));
}
else {
print t(\'Welcome visitor! Thank you for visiting.\');
......
......@@ -75,7 +75,7 @@ function statistics_user_tracker() {
l(t('details'), "admin/reports/access/$log->aid"));
}
drupal_set_title(format_username($account));
drupal_set_title(user_format_name($account));
$build['statistics_table'] = array(
'#theme' => 'table',
'#header' => $header,
......
......@@ -2024,7 +2024,7 @@ function hook_mail($key, &$message, $params) {
$context = $params['context'];
$variables = array(
'%site_name' => variable_get('site_name', 'Drupal'),
'%username' => format_username($account),
'%username' => user_format_name($account),
);
if ($context['hook'] == 'taxonomy') {
$entity = $params['entity'];
......@@ -3776,28 +3776,6 @@ function hook_url_outbound_alter(&$path, &$options, $original_path) {
}
}
/**
* 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));
}
}
/**
* Provide replacement values for placeholder tokens.
*
......
......@@ -250,7 +250,7 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a
case 'owner':
$account = user_load($file->uid);
$name = format_username($account);
$name = user_format_name($account);
$replacements[$original] = $sanitize ? check_plain($name) : $name;
break;
}
......
......@@ -221,7 +221,7 @@ function toolbar_view() {
if ($user->uid) {
$links = array(
'account' => array(
'title' => t('Hello <strong>@username</strong>', array('@username' => format_username($user))),
'title' => t('Hello <strong>@username</strong>', array('@username' => user_format_name($user))),
'href' => 'user',
'html' => TRUE,
'attributes' => array('title' => t('User account')),
......
......@@ -18,7 +18,7 @@ function tracker_page($account = NULL, $set_title = FALSE) {
// 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(format_username($account));
drupal_set_title(user_format_name($account));
}
}
else {
......
......@@ -170,6 +170,28 @@ function hook_user_cancel_methods_alter(&$methods) {
);
}
/**
* Alter the username that is displayed for a user.
*
* Called by user_format_name() 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 user_format_name() will return.
*
* @param $account
* The account object passed to user_format_name().
*
* @see user_format_name()
*/
function hook_user_format_name_alter(&$name, $account) {
// Display the user's uid instead of name.
if (isset($account->uid)) {
$name = t('User !uid', array('!uid' => $account->uid));
}
}
/**
* Add mass user operations.
*
......
......@@ -194,10 +194,10 @@ function user_uri($user) {
* @return
* The name of the user.
*
* @see format_username
* @see user_format_name()
*/
function user_label($entity_type, $entity) {
return format_username($entity);
return user_format_name($entity);
}
/**
......@@ -898,7 +898,7 @@ function user_search_execute($keys = NULL, $conditions = NULL) {
$results = array();
foreach ($accounts as $account) {
$result = array(
'title' => format_username($account),
'title' => user_format_name($account),
'link' => url('user/' . $account->uid, array('absolute' => TRUE)),
);
if (user_access('administer users')) {
......@@ -1376,9 +1376,10 @@ function user_preprocess_block(&$variables) {
*
* 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).
* may override this by implementing
* hook_user_format_name_alter(&$name, $account).
*
* @see hook_username_alter()
* @see hook_user_format_name_alter()
*
* @param $account
* The account object for the user whose name is to be formatted.
......@@ -1388,9 +1389,9 @@ function user_preprocess_block(&$variables) {
* this result must ensure that check_plain() is called on it before it is
* printed to the page.
*/
function format_username($account) {
function user_format_name($account) {
$name = !empty($account->name) ? $account->name : variable_get('anonymous', t('Anonymous'));
drupal_alter('username', $name, $account);
drupal_alter('user_format_name', $name, $account);
return $name;
}
......@@ -1426,7 +1427,7 @@ function template_preprocess_user_picture(&$variables) {
$filepath = variable_get('user_picture_default', '');
}
if (isset($filepath)) {
$alt = t("@user's picture", array('@user' => format_username($account)));
$alt = t("@user's picture", array('@user' => user_format_name($account)));
// If the image does not have a valid Drupal scheme (for eg. HTTP),
// don't load image styles.
if (module_exists('image') && file_valid_uri($filepath) && $style = variable_get('user_picture_style', '')) {
......@@ -1471,7 +1472,7 @@ function template_preprocess_username(&$variables) {
// unsanitized version, in case other preprocess 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_raw'] = format_username($account);
$name = $variables['name_raw'] = user_format_name($account);
if (drupal_strlen($name) > 20) {
$name = drupal_substr($name, 0, 15) . '...';
}
......@@ -1983,7 +1984,7 @@ function user_menu_title() {
* Menu item title callback - use the user name.
*/
function user_page_title($account) {
return is_object($account) ? format_username($account) : '';
return is_object($account) ? user_format_name($account) : '';
}
/**
......
......@@ -914,7 +914,7 @@ class UserPictureTestCase extends DrupalWebTestCase {
// 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' => format_username($this->user)));
$alt = t("@user's picture", array('@user' => user_format_name($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"));
......@@ -1914,7 +1914,7 @@ class UserTokenReplaceTestCase extends DrupalWebTestCase {
// Generate and test sanitized tokens.
$tests = array();
$tests['[user:uid]'] = $account->uid;
$tests['[user:name]'] = check_plain(format_username($account));
$tests['[user:name]'] = check_plain(user_format_name($account));
$tests['[user:mail]'] = check_plain($account->mail);
$tests['[user:url]'] = url("user/$account->uid", $url_options);
$tests['[user:edit-url]'] = url("user/$account->uid/edit", $url_options);
......@@ -1922,7 +1922,7 @@ class UserTokenReplaceTestCase extends DrupalWebTestCase {
$tests['[user:last-login:short]'] = format_date($account->login, 'short', '', NULL, $language->langcode);
$tests['[user:created]'] = format_date($account->created, 'medium', '', NULL, $language->langcode);
$tests['[user:created:short]'] = format_date($account->created, 'short', '', NULL, $language->langcode);
$tests['[current-user:name]'] = check_plain(format_username($global_account));
$tests['[current-user:name]'] = check_plain(user_format_name($global_account));
// Test to make sure that we generated something for each token.
$this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.'));
......@@ -1933,9 +1933,9 @@ class UserTokenReplaceTestCase extends DrupalWebTestCase {
}
// Generate and test unsanitized tokens.
$tests['[user:name]'] = format_username($account);
$tests['[user:name]'] = user_format_name($account);
$tests['[user:mail]'] = $account->mail;
$tests['[current-user:name]'] = format_username($global_account);
$tests['[current-user:name]'] = user_format_name($global_account);
foreach ($tests as $input => $expected) {
$output = token_replace($input, array('user' => $account), array('language' => $language, 'sanitize' => FALSE));
......
......@@ -85,7 +85,7 @@ function user_tokens($type, $tokens, array $data = array(), array $options = arr
break;
case 'name':
$name = format_username($account);
$name = user_format_name($account);
$replacements[$original] = $sanitize ? check_plain($name) : $name;
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment