Comments

ralt’s picture

Status: Active » Needs review
StatusFileSize
new656 bytes

Patch attached.

Status: Needs review » Needs work

The last submitted patch, adding-author-attribute-to-submitted-by-link-1184472-1.patch, failed testing.

ralt’s picture

Hmf. Stupid mistake.

ralt’s picture

Status: Needs work » Needs review
ralt’s picture

Issue tags: +Drupal SEO
aspilicious’s picture

Issue tags: +html5

If I'm correct this is html5 only? Adding a tag.

ralt’s picture

Actually, the rel attribute can already be used in XHTML 1.1.

Just like rel=external (widely used), which's been added officially in HTML5, it can already be used in HTML4. Thus, it is not HTML5 only.

Everett Zufelt’s picture

Is rel=author valid xhtml 1.0?

What about when user is rendered outside of an authoring context? Does Who's online, or Who's new, use the same preprocess for User?

ralt’s picture

rel="author" is not xhtml 1.0 strict valid, rel="nofollow" isn't either (both are xhtml 1.0 transitional valid, though). But having better SEO (and the link in the first post indicates that Google will work with this attribute) is still a better way to go (if you don't think so, then remove the nofollow...).

I didn't think about having it rendered outside of the authoring context. I do think that Who's new/online use the same preprocess. I don't see a way to separate them, though :/. Any idea?

ralt’s picture

Alright, found a solution. This may look like a dirty solution, but template_preprocess_username() only has one argument : &$variables. So it is not possible to add any option. A cleaner way would be to change the signature of this function so that I can add an option correctly. But it just doesn't look like right to me.

Everett Zufelt’s picture

Drupal 8 will be html5, but is also going to need to be able to fallback to valid xhtml 1.0, so however we add this, we are going to need to make sure it is easily removed.

Have you looked at either:

1. What can be done in hook_preprocess_node(), where the name is being used in the context of authorship
2. adding a boolean variable to $variables that can be set to true when the username is being rendered in an authorship context

ralt’s picture

rel="author" is exactly the same as rel="nofollow", used a lot in D7 already. Having a fallback is not necessary.

1. The patch at #10 actually changes template_preprocess_node(), this is what you meant by "hook_preprocess_node" ?
2. Good idea, this is what the attached patch does. It does look cleaner.

Status: Needs review » Needs work

The last submitted patch, adding-author-attribute-to-submitted-by-link-1184472-11.patch, failed testing.

ralt’s picture

Status: Needs work » Needs review
StatusFileSize
new1.65 KB

I think I see why it's failing. Posting patch fixing this.

Status: Needs review » Needs work

The last submitted patch, adding-author-to-submitted-by-link-1184472-13.patch, failed testing.

ralt’s picture

Status: Needs work » Needs review
StatusFileSize
new0 bytes

...

ralt’s picture

The not 0 bytes file... (it sure is hard with my new pc ;()

Status: Needs review » Needs work

The last submitted patch, adding-author-to-submitted-by-link-1184472-15.patch, failed testing.

ralt’s picture

Hm. The tests failed are these lines :

    $this->assertNoText($comment1->subject, t('Comment not found in block.'));
    $this->assertText($comment2->subject, t('Comment found in block.'));
    $this->assertTrue(strpos($this->drupalGetContent(), $comment3->comment) < strpos($this->drupalGetContent(), $comment2->subject), t('Comments were ordered correctly in block.'));

$comment1, $comment2 and $comment3 were created this way :

    $comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName());
    $comment2 = $this->postComment($this->node, $this->randomName(), $this->randomName());
    $comment3 = $this->postComment($this->node, $this->randomName());

I just don't see how my patch affects this. Any help?

aspilicious’s picture

Status: Needs work » Needs review
aspilicious’s picture

Thats a broken test

droplet’s picture

+++ b/includes/theme.incundefined
@@ -2576,8 +2576,15 @@ function template_preprocess_username(&$variables) {
+    // If we are in authorship context
...
+      // Adding attributes for the link to local user

redundant comment?

12 days to next Drupal core point release.

Everett Zufelt’s picture

I haven't read through the comments, just the patch. I'm not sure why we are adding a line to set title twice?

+    if (isset($variables['authorship'])) {
+      // Adding attributes for the link to local user
+      $variables['link_attributes'] = array('title' => t('View user profile.'), 'rel' => 'author');
+    }
+    else {
+      $variables['link_attributes'] = array('title' => t('View user profile.'));
+    }

This should be:

+    $variables['link_attributes']['title'] = t('View user profile.');
+    if (isset($variables['authorship'])) {
+      $variables['link_attributes']['rel'] = 'author';
+    }
ralt’s picture

Hello,

@22 : Why is that a redundant comment ? I may add a comma after the first line to avoid any ambiguity ?

@23 : I didn't know I could use this syntax. But yeah, it is indeed a better way to go if this works.

I cannot change the patch yet, will do that ASAP.

robloach’s picture

Issue tags: +Novice

:-)

jcnventura’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

The way it's now, I don't think it's future-proof enough..

Instead of

$variables['authorship'] = true;

it should be something like:

$variables['username_rel'] = 'author';

That way, you can actually set the rel tag to something other than 'author' simply by setting the value to something else.. Drupal could even start to support XFN natively :)

And it needs a test..

ralt’s picture

Status: Needs work » Needs review
StatusFileSize
new1.38 KB

Fixed #22, #23 and #26. About the tests, what should I test? That the variable exists?

rickmanelius’s picture

Status: Needs review » Needs work

I think I see a problem in #27. $variables for hook_preprocess_node is different than the variables for hook_preprocess_username. So while you're setting $variables['username_rel'], that key is not available when you're checking it in the hook_preprocess_username.

The only way I'm able to get rel="author" to show up is to remove the if statement altogether, undermining the ability to set the author attribute in the specific, applicable instances.

I'm trying to think if there is another way to do this...

rickmanelius’s picture

There seems to be an issue of context... and I'm not sure how easy it'll be to for the theme_link theme to know that context at the block level.

ralt’s picture

Actually, the rel="author" tag should not appear anywhere else than in node's context. This tag is there to show, on a content page, who is the author of this content. This is not there to say "hey, this guy is a user". That's why I think we do not have to extend the tag to the block level.

Everett Zufelt’s picture

Agree with #30. rel=author is only applicable in an authoring context, e.g. the display of a node.

Everett Zufelt’s picture

@ralt

I expect that testing that the attribute exists, and is set to author is a reasonable test.

rickmanelius’s picture

Ralt. I totally understand when it's only in the node itself. What I found in my digging is that the function used to render said link has no idea if it's being rendered within a node versus some other page element.

Case in point. I applied your patch and then went to a node with the "who's online" block to the left. In the patch, it's using node_preprocess to add an key to the $variables array and then using the variable to check in the username preprocess function to determine if we're in the node.

The problem is that nodes $variable array is not the same passed to the username function, and thus that if control statement returns false everytime based on my testing.

I totally understand the context when it should be added. What I'm trying to figure out is the best way to pass the hook_preprocess_username the variable necessary to alert it that it's within a node and thus should use the rel="author" tag.

jcnventura’s picture

Status: Needs work » Needs review
StatusFileSize
new1.39 KB

@Ralt: nice to adopt the definition I suggested, but the objective is to use the content of the variable also...

$variables['link_attributes']['rel'] = $variables['username_rel'];

Or else, you gain nothing from changing it from the previous 'true' value.

I've slightly modified your patch to make it even more extensible. Notice the use of an array, so that more than one rel value can be set (i.e. rel="author me").

Status: Needs review » Needs work
Issue tags: -Needs tests, -Novice, -Drupal SEO, -html5

The last submitted patch, adding-author-to-submitted-by-link-1187442-33.patch, failed testing.

jcnventura’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
Issue tags: +Needs tests, +Novice, +Drupal SEO, +html5

The last submitted patch, adding-author-to-submitted-by-link-1187442-33.patch, failed testing.

oriol_e9g’s picture

Status: Needs work » Needs review
StatusFileSize
new1.39 KB

Only #34 reroll

ralt’s picture

Status: Needs review » Needs work

@jcnventura : Oh nice, I didn't understand what you meant indeed :)

@rickmanelius : I'm not sure I've understood what you said. I don't have time yet to dive deeper into that. I guess I'll see the problem when I'll write the tests.

rickmanelius’s picture

My point was that the variables being set in template_node_preprocess are not made available in template_preprocess_username and thus it may never validate as true and add the rel="author" information.

But I'll check against #38 to see if there was another way around this based on the suggestions of jcnventura

rickmanelius’s picture

#37 does not work because the template_preprocess_username does not have the $variables['username_rel'] variable passed to it.

ralt’s picture

I totally see what you mean.

I can think of two ways for solving this.

  1. Adding a node_preprocess_username() function to node.module. This seems overkill and not "deep" enough to me, but this is a solution.
  2. Adding the attribute in template_process_username() in theme.inc. I think we're after template_preprocess_node() and so we can use &$variables. This is to be confirmed, though.
robloach’s picture

Status: Needs work » Needs review
StatusFileSize
new2.45 KB
robloach’s picture

StatusFileSize
new1.88 KB

Here's a fixed patch.... Would be good to clean those functions up though, they're so gross to work with.

ralt’s picture

Thanks Rob Loach ! Couldn't think of this way :-)

Also, what do you mean by cleaning up those functions ? Except for the fact that they're comment-verbose, I don't see anything wrong... (after your patch)

Maybe you could explain more what you meant?

kathyh’s picture

StatusFileSize
new1.92 KB

Updated for #22336: Move all core Drupal files under a /core folder to improve usability and upgrades - reviewed with patch applied and noted use of rel="author".

Status: Needs review » Needs work

The last submitted patch, username_link-1184472-46.patch, failed testing.

kathyh’s picture

Status: Needs work » Needs review
StatusFileSize
new1.92 KB

renaming patch - I don't know why this is failing - works on localhost.

The last submitted patch, username-link-1184472-46.patch, failed testing.

kathyh’s picture

Status: Needs work » Needs review
StatusFileSize
new1.96 KB

resubmitting patch (this has wrong EOL conversion). stumped - am curious what the fix would be.

Status: Needs review » Needs work

The last submitted patch, username-link-1184472-50.patch, failed testing.

cosmicdreams’s picture

Assigned: Unassigned » cosmicdreams
Status: Needs review » Needs work

I'll take a look after turkey. If I can't knock it out this weekend I'll unassign.

bleen’s picture

Status: Needs work » Needs review
StatusFileSize
new2.05 KB

This should fix it ...

robloach’s picture

Status: Needs review » Reviewed & tested by the community

Yup! That does it.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 8.x. Thanks.

Status: Fixed » Closed (fixed)

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

ereq’s picture

Hello, where do you upload this file?

klonos’s picture

Status: Closed (fixed) » Active

Can this be backported to D7? If not, how does one achieve the same thing? ...in the theme level perhaps? Is there any contrib D7 module that takes care of it?

PS: I might be asking this question here for D7, but I'm sure people would want to know the same for D6 too.

bleen’s picture

this definitely *could* be back-ported ... but I suspect that Dries/Webchick would consider that an API change (albeit minor) and wouldnt agree to commit it

If you want to achieve something like this in D7 you could always write a mytheme_preprocess_node(&$variabels) function & mytheme_preprocess_username(&$variables) function in your template.php file and then just follow the same basic idea as the patch in #53

klonos’s picture

Thanx Alexander. ...still digesting your pointers :/

Any chance for someone to provide a code snippet ready to go in the template.php file (or a D7 contrib module perhaps)?

bleen’s picture

UNTESTED, but something like this should work (put it in template.php):

function mytheme_preprocess_node(&$variables) {
  $variables['name'] = theme('username', array(
    'account' => $node,
    'link_attributes' => array('rel' => 'author'),
  ));
}

function mytheme_preprocess_username(&$variables) {
   if ($variables['uid'] && $variables['profile_access']) {
     // We are linking to a local user.
    $variables['link_attributes']['title'] = t('View user profile.');
   }
   elseif (!empty($account->homepage)) {
    $variables['link_attributes']['rel'] = 'nofollow';
   }
}
klonos’s picture

...well sticking the two functions at the end of the core Garland theme's template.tpl (renaming mytheme_* to garland_* and removing the wrapping php tag of course) simply gives me a WSOD :/

klonos’s picture

...garland already has a garland_preprocess_node function, so I moved the code from the one you provided in it. That got rid of the WSOD. Also had to change &$variables to &$vars. After making sure I cleared caches, still Google's Rich Snippets Testing Tool sees no authorship markup in my pages.

klonos’s picture

...and inspecting the link:

<a class="username" title="View user profile." href="/my-site/el/user/1">admin</a>

klonos’s picture

...here it is:

Notice: Undefined variable: node in garland_preprocess_node() (line 123 of /var/www/my-site/themes/garland/template.php).

line 123 is 'account' => $node, of course.

Don't know why this didn't come up before with all the page refreshes & cache purging :?

klonos’s picture

...garland_preprocess_node

function garland_preprocess_node(&$vars) {
  $vars['submitted'] = $vars['date'] . ' — ' . $vars['name'];
  $vars['name'] = theme('username', array(
    'account' => $node,
    'link_attributes' => array('rel' => 'author'),
  ));
}

...moving the line so that $vars['submitted'] is set after $vars['name']

function garland_preprocess_node(&$vars) {
  $vars['name'] = theme('username', array(
    'account' => $node,
    'link_attributes' => array('rel' => 'author'),
  ));
  $vars['submitted'] = $vars['date'] . ' — ' . $vars['name'];
}

Now the submitted info when the node is rendered replaces the actual username link with plain text "Anonymous (not verified)":

Fri, 02/10/2012 - 18:07 — Anonymous (not verified)

Will try to get some sleep and fight this a bit more once my brain is back in place :p ...I'll probably open a new support request against D7 so I don't add noise here any more - sorry people.

bleen’s picture

Status: Active » Closed (fixed)
klonos’s picture

SamuelChris’s picture

thanks for this info , helpful me