This issue is a follow up from a comment from effulgentsia #493030-146: RDF #1: core RDF module. It takes advantage of theme_rdf_template_variable_wrapper() which was added in the end to the main RDF patch but as effulgentsia pointed out was not used everywhere it could be. theme_rdf_template_variable_wrapper() wraps the output of theme_username with the relevant RDFa markup. It also makes the RDFa markup for the username consistent across all the cases on nodes and comments:
- registered user with public profile
- registered user with private profile
- anonymous users.
No API change, simply making the code more simple and consistent by reusing the existing theme functions. It also simplifies the RDFa constructs markup which is output in the HTML.
Comment | File | Size | Author |
---|---|---|---|
#15 | 614444_comment_rdfa_14.patch | 15.42 KB | scor |
#13 | 614444_comment_rdfa_13.patch | 15.16 KB | scor |
#12 | 614444_comment_rdfa_12.patch | 8.7 KB | effulgentsia |
#11 | 614444_comment_rdfa_11.patch | 8.28 KB | effulgentsia |
#10 | 614444_comment_rdfa_4.patch | 6.3 KB | scor |
Comments
Comment #1
scor CreditAttribution: scor commentedComment #2
sunI guess the condition should be empty(), not !empty().
Also, you cannot use functions in empty(). What you want is probably:
Please test > 0 here.
Strange indentation.
huh? Can the 'rel' attribute really take multiple values?
The "homepage" property actually belongs to anonymous users only and to comment module only.
Is it a good idea to add it to the RDF mapping for users?
I'm on crack. Are you, too?
Comment #3
scor CreditAttribution: scor commentedThanks Sun for reviewing this!
In fact we want to override the rdf_mapping of the account object, because it contains the rdf_mapping of a node/comment and not the rdf_mapping of the user. The logic behind $account is flawed and obscure so that's why we need this. You have a point though, re the function in empty. I'll reroll a patch which first loads the user object and then checks whether it contains rdf_mapping, and add the other fixes too.
yes, it's like the class attribute. You might wonder why RDFa is targeting this tag? rel is one of the 5 existing XHTML tags that RDFa reuses to add semantics (see a list of tags used by RDFa). So in the end, we want to generate markup like:
<a href="http://example.com/" rel="nofollow foaf:homepage" property="foaf:name">Somebody Anonymous</a>
I've left a @todo in the patch about fixing theme_username() to allow that.
Excellent remark. Originally I thought of creating a user bundle for the anonymous user in the comment module. What do you think of the idea? Regardless, both solutions would work, it's just a matter of deciding what's the clean way of doing it.
Comment #4
effulgentsia CreditAttribution: effulgentsia commentedEven with the comments which are nice, it's still confusing (maybe, it's just me; I still can't seem to wrap my head around how RDF actually works). I wonder if #585838: Consider a generic $entity->user property will end up helping make this less weird.
For the benefit of other reviewers, as I understand it, this is the main benefit of this patch. This current code in HEAD is some weird RDF trickery and it would be nice to see this go away. However, the cost of having this go away is the extra code added to rdf_preprocess_node() and rdf_preprocess_comment(). In my opinion, the code added in those functions make more sense than the code being removed, so I'm in favor of this. However, from a markup standpoint, this results in an extra span tag around the comment and node author. It's a span wrapper that only gets rendered if the rdf module is enabled, and a themer has access to it via the 'rdf_template_variable_wrapper' theme hook, so it's about as harmless as it can be, but the question needs to be asked: does anyone consider an extra span wrapper to be worse than the RDF trickery needed to avoid it? I don't, but I'm not sure I'm the best judge of that.
Given how template_preprocess_username() currently is, this code makes sense. But yes, we might want to make changes to template_preprocess_username() to take into account that "rel" can be an array and can have semantic meaning in addition to a hint for search spiders.
I'm on crack. Are you, too?
Comment #5
scor CreditAttribution: scor commentedI've incorporated sun's and effulgentsia's feedback.
The particular piece of code you are referring has not much to do with RDF itself, but is simply to fetch the mapping of the user being rendered. I've changed the comment, let me know if it makes more sense.
Comment #6
effulgentsia CreditAttribution: effulgentsia commentedThanks! It's getting cleaner and clearer.
The line above this is $account = $variables['account'], so I'm not clear why you need to user_load() both.
This review is powered by Dreditor.
Comment #7
effulgentsia CreditAttribution: effulgentsia commentedAs mentioned in the @todo of this patch, the work here uncovered a shortcoming in theme_username() preprocessing. See #623592: Fix theme_username() preprocessing to work with attributes that are arrays.
Comment #8
scor CreditAttribution: scor commentedright, this is just some old cruft. I removed the second call to user_load().
Comment #9
effulgentsia CreditAttribution: effulgentsia commentedOk, now I understand. So, we don't actually need anything from $variables['account'] because it's a fake account object. Instead, we want the real account object for the user, so:
$account = user_load($variables['uid']);
if ($account) {
$rdf_mapping = $account->rdf_mapping;
}
s/$account->homepage/$variables['homepage']/
This review is powered by Dreditor.
Comment #10
scor CreditAttribution: scor commentedAs a measure of precaution, we keep as much information as possible from the original $variables in case it would have been added/modified by some other preprocess function (the homepage value for example is not available in the object given by user_load). I have added a comment to mention this to prevent confusion. I also fixed the second comment.
Comment #11
effulgentsia CreditAttribution: effulgentsia commentedYes, I wasn't suggesting changing $variables['account'], but setting the local $account variable to the object needed. We don't want to assume that user_load() will succeed; it might return FALSE, in which case, accessing a property will trigger a warning. I hope this patch helps clarify.
This patch also includes minor cleanup and the necessary change to template_preprocess_username() and template_process_username().
Comment #12
effulgentsia CreditAttribution: effulgentsia commentedThis patch includes a small polish that supports the possibility that earlier hook_preprocess_username() implementations added to the attributes that can be arrays, and that rdf should add to these rather than clobber them. The use-case for this would be esoteric, because these are RDFa specific attributes, but who knows what other doctypes people might want to work with, and perhaps some of those doctypes re-purpose these attributes the way that RDFa re-purposes the "rel" attribute.
@sun: since you're the only subscriber to this issue other than scor and me, can you RTBC this, or provide feedback, or suggest who else should review it? Thanks.
Comment #13
scor CreditAttribution: scor commentedgreat improvments effulgentsia! thanks. This patch adds tests to cover all the use cases of this improved logic for rdf_preprocess_username().
Comment #14
sunI think we're missing a "regardless of" before "whether" here.
"senseless"? Example?
s/Enabled/Enable/
1? Isn't this a constant as well?
Wrong indentation here.
Let's write HTML tags always uppercase.
This really screams for a clean-up. Why do we have a template variable with the term "template_variable" in it? Shouldn't we also consider to build a single $variables['rdf'] array that contains the keys 'attributes' + 'attributes_array' keyed by other variables - or similar?
Doesn't belong into this issue, so let's create a follow-up for that and link to it here.
Not sure why we wouldn't want to overload the existing variable when we have to load the full user account anyway. Of course, the user should always be fully loaded in the first place, but that's a different issue... ;)
So, yeah, not sure why we don't pass on the "proper" data if we have to load it anyway.
Docs-only issue: Why is the user name considered literal, if we have a mapping for the user name?
Or what exactly is meant by "literal"? ;)
I'm on crack. Are you, too?
Comment #15
scor CreditAttribution: scor commented> "senseless"? Example?
I've rewritten the comments. Please check if that makes more sense. I don't know of any example, but themers might need to target an
<a>
tag only, we never know and we don't want to prevent them from doing so.> 1? Isn't this a constant as well?
Fixed in the scope of this patch. comment.test is full of these errors and would deserve a review of its own. I have created #628764: comment.test does not implement setCommentPreview() correctly for a start.
> Let's write HTML tags always uppercase.
you mean A or SPAN? is that part of the coding standards?
> This really screams for a clean-up. Why do we have a template
> variable with the term "template_variable" in it? Shouldn't we also
> consider to build a single $variables['rdf'] array that contains the
> keys 'attributes' + 'attributes_array' keyed by other variables - or similar?
agreed, let's not block this patch for this and let's take it in a follow up issue.
> Not sure why we wouldn't want to overload the existing variable when we have to load the full user account anyway. Of course, the user should always be fully loaded in the first place, but that's a different issue... ;)
Do you mean something like
?
> Or what exactly is meant by "literal"? ;)
Literal is in the RDF sense here, we're not linking to a node (RDF resource) but to a literal/string. In RDFa, the property attribute is used to make the relation to a string (here the name of the user, as opposed to the user as an entity). See the caption of the diagram in this section of the RDFa primer. Would "string" make more sense? If so let's create a specific issue for this docs related change, because literal is used elsewhere in the rdf module.
Comment #16
sunHrm, no, I actually meant
i.e. load the full user account, use it onwards, but also provide it to others.
Additionally, we don't have to user_load() again, if $variables['account'] is a full user object already.
However, I'm trying to figure out whether we have any indicator for that...
This review is powered by Dreditor.
Comment #17
scor CreditAttribution: scor commented@sun we didn't implement this for 2 reasons:
1. the data passed to rdf_preprocess_username() might have already been altered by some other preprocess function (though I'm not sure it would be logic to change the user data at this level but some themers might do that). Therefore if you reload the user over it you lose these changes.
2. you're overriding $variable['account'] which contains data about the node whose author's username is being rendered (yes, I know, 'account' contains data about the node :/ ). If you override it I'm not sure how the other template functions triggered afterwards will react with this new 'user' data if they are expecting the usual node data to be there. I'm not sure it is safe to do that at this point in time, and I'd rather isolate our logic from this obscure data object.
This problem should be fixed outside this patch. The variables passed to MODULE_preprocess_username() should be cleaned up at a higher stage, before this hook is invoked. I don't think it's up to the preprocess functions to fix the parameters they are given as input.
Comment #18
Anonymous (not verified) CreditAttribution: Anonymous commentedRDFa markup looks good.
All the above issues except for overloading the variable can be handled in the documentation issue, #623684: Improve documentation of rdf module
The variable issue is outside the scope of this patch. As scor says, overriding $variable['account'] could have an impact on subsequent function calls, so unless this is handled at a higher level, it should be left as is.
Comment #19
effulgentsia CreditAttribution: effulgentsia commentedThis looks good to me (I didn't review the tests in detail, but the code changes look good). I agree that we need two follow-up issues outside the scope of this patch: 1) The whole $account parameter passed to theme('username') being a pseudo-account object, and where, if anywhere it's appropriate to replace it with the result of a user_load() -- wherever is the right place to do that, I'm pretty confident that it's not in the rdf module. 2) Cleaning up the naming convention for $variables['rdf_template_variable_attributes_array'] (for reference, this name was introduced in http://drupal.org/node/493030#comment-2168566).
I'd still like @sun to give his approval before we mark it RTBC. What do you think, sun? Do you have any concerns that haven't been adequately addressed?
Comment #20
sunI'm fine with this patch. user_load() is cached now, and since we have this issue since like forever, there's no reason to hold off this patch. ;)
Please link to the two (unrelated) follow-up issues in here.
Comment #21
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks!
Comment #22
effulgentsia CreditAttribution: effulgentsia commentedAs requested, linking to #633642: Rename $variables['rdf_template_variable_attributes_array'] to something sane. Will add link to other follow-up issue regarding $variables['account'] when it's posted.
Comment #23
effulgentsia CreditAttribution: effulgentsia commentedAnd the other one: #633652: What should $variables['account'] within theme_username() be?