See roadmap on enabling RDFa in Drupal 7.

This first patch implements a simple RDF namespace registry which is serialized in the XHTML output. Only garland has been modified for now, changes can be applied to the other themes once this patch has matured enough. In case of conflicting prefixes, it displays an error which targets module developers. No security measure needs to be taken when outputting the namespaces since the prefixes and URIs come from the modules only (no direct user input).

Some common namespaces are defined in system.module.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx’s picture

The rdf_get_namespaces and the proposed structure is not something I am very happy with. If modules are to define arbitrary prefixes ( they are totally arbitrary arent they? ) then why should any module define the prefix? Why not just

  foreach (module_invoke_all('rdf_namespace') as $uri) {
    $xml_rdf_namespaces[] = 'xmlns:' . sprintf('%x', crc32($uri)) . '="' . $uri . '"';
  }

Edit: even if I am wrong, checking whether other modules have defined things, and producing an error totally should not be there -- why include code that is only relevant at coding time for every single request Drupal serves? Or to put it more succint, we do not babysit broken code.

Dries’s picture

Status: Needs review » Needs work

1. The GRDDL one could use more documentation for those not familiar with it. They might wonder why it is singled-out.

2. The hook is called _rdf_namespaces() (plural) but the documentation uses _rdf_namespace() (singular).

scor’s picture

@chx:
prefixes are used to make the URIs shorter in the annotated the XHTML code. There is generally a convention used for prefixes. For instance 'dc' is used for http://purl.org/dc/elements/1.1/
As a result I can write in the body of the page:

<li property="dc:creator">Joe</li>

where dc:creator is the URI http://purl.org/dc/elements/1.1/creator
Please read http://groups.drupal.org/node/16597 for general overview

module developers could potentially override the prefixes defined by core with a different URI, it's the reason why I had added this check.

scor’s picture

Status: Needs work » Needs review

@Dries:
1. will do
2. the hook in the patch is hook_rdf_namespace() (singular). which documentation line are refering to? I don't see what you mean.

chx’s picture

I understand the logic for the shorthands but still -- that getter is not what Drupal does, just use module_invoke_all and be done. if two modules define the same, too bad.

moshe weitzman’s picture

I agree with chx. That check is not at all conventional in drupal.

chx’s picture

2. The hook is called _rdf_namespaces() (plural) but the documentation uses _rdf_namespace() (singular). <= No, the hook is singular, his getter is plural but the next patch wont have the getter I am quite sure of that :)

Dries’s picture

Glad we're all on the same page. Hehe. ;-)

scor’s picture

FileSize
3.58 KB

much simplified patch addressing the comments above, without the getter and with some more doc on GRDDL.

chx’s picture

Status: Needs review » Needs work

This is going to be something great. Are we going to add RDF prefixes to node titles and bodies besides theme item list? Please do in a next patch.

I see that you added space to be flush with the wall of variables a few lines up but that's an exception to the rule and a s you can see for node a line below, once the wall is finished so is the spacing so please remove the extra spaces from theme.inc. Just $variables['rdf_namespaces'] = implode(' ', $xml_rdf_namespaces); please. Even more, why not use a \n and a few spaces to implode on? It can't hurt to make the HTML source make readable... otherwise the <html> line will be too long. Sorry for being so picky with this patch.

scor’s picture

FileSize
3.58 KB

Are we going to add RDF prefixes to node titles and bodies besides theme item list?

yes, of course, in other separate patches.

Originally I found the xml namespaces to be too verbose that's why I kept them on the same line. The attached patch adds \n and indents the namespaces with 2 spaces. also fixed the wall of variable issue.

Sorry for being so picky with this patch.

That's fine, I can be picky at times too :)

chx’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch failed testing.

scor’s picture

FileSize
3.58 KB

rerolling the patch from #11.

lilou’s picture

Status: Needs work » Needs review
pwolanin’s picture

Status: Needs review » Needs work

We need to cover other page tpl files and also non-tpl themes. Probably the hook invocation should, for this reason, be moved out to a helper function.

Also, will a normal browser slow down its page load to try to fetch all those name-space documents? Stephane tells me he thinks FF does not fetch all these, but we should verify this and/or find documentation about it to be sure.

Also, the RDFa doctype is "XHTML 1.1 and RDFa". Our existing doctypes are XHTML 1.0 Transitional or Strict. Will using this RDFa doctype make Drupal less likely/able to validate and possibly break theme functions?

pwolanin’s picture

Status: Needs work » Needs review
FileSize
8.13 KB

here's a patch that covers other page.tpl.php files, but there are still unanswered questions about the DOCTYPE in my mind.

Also, some sources suggest such a document should have an XML declaration at the top like

<?xml version="1.0" encoding="UTF-8"?>
scor’s picture

re the XML declaration at the top, the RDFa syntax specification says:

An XML declaration like the one above is not required in all XML documents. XHTML document authors SHOULD use XML declarations in all their documents. XHTML document authors MUST use an XML declaration when the character encoding of the document is other than the default UTF-8 or UTF-16 and no encoding is specified by a higher-level protocol.

Drupal output UTF-8 by default, and specifies <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> in common.inc so in my opinion it's not necessary.

Peter asked me on IRC whether the namespaces at the top of the page would slow down the browsers which might try to fetch these URIs. This is not the case. In theory these namespaces don't even need to exist on the web: they are used as common ids across websites. In practice they are often dereferencable in order to provide some information on the vocabulary terms and promote reuse of vocabularies.

Dries’s picture

Status: Needs review » Needs work

I've committed this patch to CVS HEAD. Oh my!

I'm marking it 'code needs work' because we'll want to update the theme upgrade instructions in the handbook. Could you update those, scor (or someone else)? Once updated, please mark this issue as 'fixed' so we can move onto the next one.

Keep up the good work, folks.

killes@www.drop.org’s picture

Status: Needs work » Needs review
FileSize
1.38 KB

The patch had a typo for the chameleon theme:

+ $putput .= " $rdf_namespaces>\n";

scor’s picture

Status: Needs review » Needs work

fixing more typos at the moment, and improving the documentation, patch coming in the next minutes.

scor’s picture

Status: Needs work » Needs review
FileSize
3.05 KB

fix typos and improve documentation.

keith.smith’s picture

Status: Needs review » Needs work

Excellent!

+ * Return a string containing RDF namespaces for the html tag of an XHTML page.

We usually capitalize HTML.

-  // RDFa annotatates XHTML with RDF data, while GRDDL provides
+  // RDFa allows to annotate XHTML pages with RDF data, while GRDDL provides

"allows to annotate" is still weird, though annotate is spelled correctly. What about "RDFa allows annotation of XHTML pages with RDF data..."

scor’s picture

@keith: thanks for the feedback. "We usually capitalize HTML. " -> here we don't mean the HTML language, but the html tag <html> which is spelt in lower case per XHTML standards.

fixed "RDFa allows annotation of XHTML pages with RDF data..."

keith.smith’s picture

Status: Needs work » Reviewed & tested by the community

Looks good to me.

keith.smith’s picture

Status: Reviewed & tested by the community » Needs work

Actually, as scor and I discussed on #drupal, this would be even more clear if we just put <> brackets around html.

"Return a string containing RDF namespaces for the tag of an XHTML page."

scor’s picture

Status: Needs work » Needs review
FileSize
3.06 KB

here is the patch

keith.smith’s picture

Status: Needs review » Reviewed & tested by the community

Those brackets make all the difference. Thanks!

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

xmacinfo’s picture

Title: RDF namespace registry » RDF namespace registry (white space in the head tag)
Status: Fixed » Active

There are white-space issues in the tag with this fix.

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"
  >

The closing ">" is sent to the next line with 2 spaces in front of it.

scor’s picture

Status: Active » Postponed (maintainer needs more info)

the double space it there to indent the namespaces. I cannot reproduce exactly what you pasted above, since there should be a list of namespaces in the html tag. Can you elaborate please?

drewish’s picture

i tried running HEAD's front page through http://validator.w3.org/check and it didn't seem to care about the white space but it did give the following errors:

Error Line 3, Column 62: there is no attribute "lang".
…mlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"

Error Line 14, Column 55: value of fixed attribute "xmlns:xsi" not equal to default.

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance#"

perhaps that should be moved into a new issue?

scor’s picture

xmacinfo’s picture

Hi!

I'm running a bare-bone Drupal CVS install updated so see the results of this commit.

When I do a view source I get this:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"
  >

The last ">" character is sent to a new line with 2 spaces before it.

Normally we would expect no space between the last attribute and the closing ">" character:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">

xmacinfo’s picture

Status: Postponed (maintainer needs more info) » Fixed

Ok. Now I see alll namespaces.

Forgot to update.php.

Cheers.

scor’s picture

Title: RDF namespace registry (white space in the head tag) » RDF namespace registry
Status: Fixed » Needs review
FileSize
745 bytes

re #32: in fact we don't need xsi which is used for rather specific use cases. This patch removes it. It also removes the # in the end of the xsd prefix to match with the official XML Schema namespace.

Dries’s picture

Status: Needs review » Fixed

Committed to CVS. Thanks!

xmacinfo’s picture

Title: RDF namespace registry » RDF namespace registry (Add a changelog entry)
Status: Fixed » Active

Great. Please add an entry in the changelog file.

From my point of view it looks like a big change since I'll have to modify the way I do themes.

Cheers.

webchick’s picture

Issue tags: +RDF

Bump. Need those docs. I'd add them myself, but I don't quite grok what the heck this patch has enabled. :)

webchick’s picture

Status: Active » Needs work
scor’s picture

It's best to wait for more RDF patches to land as the bigger RDF picture might slightly change (and the RDF docs as a result). This patch doesn't enable much on its own, but simply prepares Drupal for the next patches.

drewish’s picture

scor, we're trying to keep the documentation current for each UNSTABLE release. if changes happen to the next release then they'd be documented in that section. when the final release occurs we'll distill it all down to one set of docs.

drewish’s picture

So it looks like this really needs a couple of things:

  • A patch for the CHANGELOG.txt file
  • An entry in the theme update guide as per xmacinfo's comment in #38
scor’s picture

FileSize
682 bytes

How about:

- Added RDF support:
    * Modules can declare RDF namespaces which are serialized in the <html> tag
      for RDFa support.
scor’s picture

re #38: I added an entry to Converting 6.x themes to 7.x

catch’s picture

Status: Needs work » Reviewed & tested by the community

CHANGELOG.txt entry looks good to me - we can add more later.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Great! :) Thanks!

Status: Fixed » Closed (fixed)

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

JohnAlbin’s picture

Status: Closed (fixed) » Needs work

You guys didn't add the variables to modules/system/page.tpl.php.

JohnAlbin’s picture

Status: Needs work » Closed (fixed)

webchick opened a follow-up issue in #387218: Default page.tpl.php needs to print RDF variables. So let's go fix it over there. :-)