RDF namespace registry (Add a changelog entry)

scor - November 11, 2008 - 16:05
Project:Drupal
Version:7.x-dev
Component:theme system
Category:feature request
Priority:normal
Assigned:scor
Status:closed
Issue tags:RDF
Description

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.

AttachmentSize
rdfa_ns_registry.patch5.89 KB
Testbed results
rdfa_ns_registry.patchfailedFailed: Failed to apply patch. Detailed results

#1

chx - November 11, 2008 - 18:40

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

<?php
 
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.

#2

Dries - November 11, 2008 - 21:01
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).

#3

scor - November 11, 2008 - 21:01
Status:needs work» needs review

@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:

<?php
<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.

#4

scor - November 11, 2008 - 21:07

@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.

#5

chx - November 11, 2008 - 21:28

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.

#6

moshe weitzman - November 12, 2008 - 02:44

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

#7

chx - November 12, 2008 - 03:47

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 :)

#8

Dries - November 12, 2008 - 08:28

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

#9

scor - November 12, 2008 - 13:06

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

AttachmentSize
rdfa_ns_registry2.patch 3.58 KB
Testbed results
rdfa_ns_registry2.patchfailedFailed: Failed to apply patch. Detailed results

#10

chx - November 12, 2008 - 15:14
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.

#11

scor - November 12, 2008 - 15:52

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 :)

AttachmentSize
rdfa_ns_registry3.patch 3.58 KB

#12

chx - November 12, 2008 - 18:49
Status:needs work» needs review

#13

System Message - November 16, 2008 - 22:00
Status:needs review» needs work

The last submitted patch failed testing.

#14

scor - November 16, 2008 - 22:44

rerolling the patch from #11.

AttachmentSize
rdfa_ns_registry3.2.patch 3.58 KB
Testbed results
rdfa_ns_registry3.2.patchfailedFailed: Failed to apply patch. Detailed results

#15

lilou - November 17, 2008 - 04:32
Status:needs work» needs review

Test failure : #335122: Test clean HEAD after every commit

#16

pwolanin - November 18, 2008 - 17:13
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?

#17

pwolanin - November 18, 2008 - 18:27
Status:needs work» needs review

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"?>

AttachmentSize
rdfa_ns_registry-332980-17.patch 8.13 KB
Testbed results
rdfa_ns_registry-332980-17.patchfailedFailed: Failed to apply patch. a href=http://testing.drupal.org/pifr/file/1/rdfa_ns_registry-332980-17.patchDetailed results/a

#18

scor - November 19, 2008 - 14:39

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.

#19

Dries - November 22, 2008 - 13:56
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.

#20

killes@www.drop.org - November 22, 2008 - 15:26
Status:needs work» needs review

The patch had a typo for the chameleon theme:

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

AttachmentSize
chameleon_typo.patch 1.38 KB
Testbed results
chameleon_typo.patchfailedFailed: Failed to apply patch. Detailed results

#21

scor - November 22, 2008 - 16:14
Status:needs review» needs work

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

#22

scor - November 22, 2008 - 17:05
Status:needs work» needs review

fix typos and improve documentation.

AttachmentSize
rdfa_ns_registry-332980-18.patch 3.05 KB

#23

keith.smith - November 22, 2008 - 17:16
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..."

#24

scor - November 22, 2008 - 17:35

@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..."

AttachmentSize
rdfa_ns_registry-332980-19.patch 3.05 KB
Testbed results
rdfa_ns_registry-332980-19.patchfailedFailed: Failed to apply patch. Detailed results

#25

keith.smith - November 22, 2008 - 17:54
Status:needs work» reviewed & tested by the community

Looks good to me.

#26

keith.smith - November 22, 2008 - 19:27
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."

#27

scor - November 22, 2008 - 19:38
Status:needs work» needs review

here is the patch

AttachmentSize
rdfa_ns_registry-332980-20.patch 3.06 KB
Testbed results
rdfa_ns_registry-332980-20.patchfailedFailed: Failed to apply patch. Detailed results

#28

keith.smith - November 22, 2008 - 20:05
Status:needs review» reviewed & tested by the community

Those brackets make all the difference. Thanks!

#29

Dries - November 23, 2008 - 16:54
Status:reviewed & tested by the community» fixed

Committed to CVS HEAD. Thanks.

#30

xmacinfo - November 23, 2008 - 20:48
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.

#31

scor - November 24, 2008 - 10:19
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?

#32

drewish - November 24, 2008 - 11:59

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?

#33

scor - November 24, 2008 - 13:12

see #338429: XHTML 1.1 compatibility (RDFa) for the lang issue.

#34

xmacinfo - November 24, 2008 - 15:30

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">

#35

xmacinfo - November 24, 2008 - 15:36
Status:postponed (maintainer needs more info)» fixed

Ok. Now I see alll namespaces.

Forgot to update.php.

Cheers.

#36

scor - November 24, 2008 - 16:21
Title:RDF namespace registry (white space in the head tag)» RDF namespace registry
Status:fixed» needs review

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.

AttachmentSize
rdfa_xmlns_xsi_fix.patch 745 bytes
Testbed results
rdfa_xmlns_xsi_fix.patchre-testing

#37

Dries - November 24, 2008 - 22:10
Status:needs review» fixed

Committed to CVS. Thanks!

#38

xmacinfo - November 25, 2008 - 01:46
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.

#39

webchick - January 15, 2009 - 06:24

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

#40

webchick - January 15, 2009 - 06:24
Status:active» needs work

#41

scor - January 15, 2009 - 09:26

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.

#42

drewish - January 15, 2009 - 17:05

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.

#43

drewish - January 15, 2009 - 18:06

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

#44

scor - January 15, 2009 - 19:09

How about:

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

AttachmentSize
rdf_changelog.patch 682 bytes

#45

scor - January 15, 2009 - 19:49

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

#46

catch - January 16, 2009 - 16:57
Status:needs work» reviewed & tested by the community

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

#47

webchick - January 16, 2009 - 17:36
Status:reviewed & tested by the community» fixed

Great! :) Thanks!

#48

System Message - January 30, 2009 - 17:40
Status:fixed» closed

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

#49

JohnAlbin - February 24, 2009 - 17:21
Status:closed» needs work

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

#50

JohnAlbin - March 1, 2009 - 20:37
Status:needs work» closed

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. :-)

 
 

Drupal is a registered trademark of Dries Buytaert.