In the revision tab the usernames are themed, but in the diff inline block the usernames are not themed. I want this to work with Realname module.
Attached is a simple patch to fix this.

Comments

realityloop’s picture

Status: Needs review » Fixed

applied to dev

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

arvinsingla’s picture

Status: Closed (fixed) » Needs work
StatusFileSize
new18.4 KB

This patch has introduced an issue for users who aren't using the realname module. The theme_username function is generating markup which is being placed in the select box. Unfortunately the stock theme_username function for D6 does not take extra parameters so the array('plain' => TRUE) does nothing for users who don't have realname installed.

This will affect admin users and users with the "Access user profiles" permission. See pic attached

realityloop’s picture

Reverted.. feel free to supply a working patch

Hakaku’s picture

Couldn't you simply wrap it as such:

'@name' => module_exists('RealName')) ? $revision->name : theme('username', $revision, array('plain' => TRUE)),

(not sure if 'realname' should be lowercase)

alan d.’s picture

mitchell’s picture

Issue summary: View changes

Updated issue summary.

mitchell’s picture

Title: Theme username in block » RealName integration: theme username in block
Version: 6.x-2.x-dev » 7.x-3.x-dev
Assigned: magnus » Unassigned
Status: Needs work » Active
  • Bumping to 7.x-3.x branch.
  • Updated issue summary to link to RealName.
  • Updated title to reflect this is related to RealName project.
  • Marked issue in #6 as a duplicate.
  • Setting back to active, since patch in OP introduces errors.
hass’s picture

Normally in D7 we should use http://api.drupal.org/api/drupal/includes%21common.inc/function/format_u... for formating usernames and this will allow realname to hook into. This does not required any module_exists() conditions. I'm not sure about the html code. May required strip_tags().

alan d.’s picture

Status: Active » Needs review
StatusFileSize
new3.33 KB

This patch appears to handle all fields - tested using Name Field modules real name integration.

kscheirer’s picture

Status: Needs review » Needs work

format_username() says the code receiving this result is responsible for calling check_plain(). I don't think we need to pass in full $account objects, since the $revision objects have a name defined, and format_username() says

By default, the passed-in object's 'name' property is used if it exists
alan d.’s picture

Ah, but these didn't show correctly when testing when passing the node itself, even though this has both uid / name.

Can you confirm that these work with the RealName module is used? Maybe there is a bug in the Name Field modules implementation. I ran tests with the current user being author and anonymous authors on content too.

i.e. revert to one of these forms and try.

     $form['revision']['#options'][$revision->vid] = t('@revision by @name', array(
       '@revision' => format_date($revision->timestamp, 'short'),
       '@name' => format_username($revision),
     ));
# other general format
   $old_header = t('!date by !username', array(
     '!date' => l(format_date($old_node->revision_timestamp), "node/$node->nid/revisions/$old_node->vid/view", array('absolute' => 1)),
     '!username' => theme('username', array('account' => $node_revisions[$old_vid])),
   ));

But there is a issue with the patch with the first account load in diff_inline_form() - this should be $revision and not $node.

Related to check_plain(), can you expand on the issue please?

The code assumes that these are escaped by theme_username() by using "!".

+          '!username' => theme('username', array('account' => $account)))) . $revision_log,

As the string is escaped in theme_username() preprocesser template_preprocess_username()

  $name = $variables['name_raw'] = format_username($account);
  if (drupal_strlen($name) > 20) {
    $name = drupal_substr($name, 0, 15) . '...';
  }
  $variables['name'] = check_plain($name);

And the one line that uses format_username() uses "@" to escape the string.

+      '@name' => format_username($account),
alan d.’s picture

OK, sadly it looks like you need to handle a user_load() within hook_username_alter(). I'll re-roll tonight, but please let me know what you think I missed with the escaping of the code.

alan d.’s picture

Status: Needs work » Needs review
StatusFileSize
new911 bytes

Quick re-roll. The I fixed the Name Field module "bug" [imho, this function should be getting a loaded user entity only, but core mixes and matches depending on the area] and retested.

Patch is reduced to just the user inline block code and uses format_username().

kscheirer’s picture

Status: Needs review » Reviewed & tested by the community

This patch worked for me, the "inline differences" block shows realnames where before it was always just a user name. You were absolutely right about not needing to escape the format_username, @name is sufficient - sorry about that.

alan d.’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.