Table of Contents
Switching to XHTML 1.0 Strict
DokuWikis default doctype is XHTML 1.0 Transitional and its default content-type “text/html”. But with the 2006-03-09 release much attention was paid to making it as strict as possible.
See also how to switch to XHTML 5.
If you want to switch to XHTML 1.0 Strict and/or to a application/xhtml+xml content-type, here is what to do:
Doctype
If you only want to change the Doctype, just change each Doctype declaration from
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
to
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
in
- ./lib/tpl/<template>/main.php
- ./lib/tpl/<template>/detail.php
- ./lib/tpl/<template>/mediamanager.php
- ./inc/actions.php inside
if($act == 'export_xhtml'){
for the “export_html” mode
Content-type
Changing the doctype to XHTML 1.0 Strict without adjusting the content-type can make sense. But often you would want to change the content-type as well.
As many user agents cannot yet handle a document served as “application/xhtml+xml” (eg. the IE), it is good practice to use content negotiation. So, in all files mentioned above (main.php, etc.) you can put something like this:
<?php if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") || stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator") ) { header("Content-type: application/xhtml+xml"); header("Vary: Accept"); echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"; echo " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"; } else { header("Content-type: text/html"); echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"; echo " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; } ?>
Or you can find other solutions searching the web that suits your purpose better.
The test for W3C_Validator is recommended since the validator currently doesn't use content negotiation. The vary header avoids problems where a proxy server otherwise might serve a cached xml version to a non xml compliant browser.
Entities
Another (quite big) issue that has to be taken care of, if you decide to switch to an xml content-type, concerns entities.
In XML no other named entities than <
, >
, "
and &
should be used (otherwise it may lead to parsing errors, ie. the page won't be displayed at all). In the case of DokuWiki I recommend to replace each visible named entity to its utf-8 character; and each non-visible named entity (like
) to its numeric entity (preferably decimal).
That is the trickier part of converting to Strict. Maybe someone can write a script that does that!?
Problems with the latest release (2009-02-14)
Invalid elements
There are few spots where some invalid elements are used deliberately:
target=“_blank”
is used in the link to open the media manager (which you can see when you have JavaScript turned off) and in the media manager itself to “view original file”autocomplete=“off”
is used once in the config manager
Unfortunately align
is used every time an image is used (although a corresponding class is also used). This was done to have images aligned in feeds as well. I filed a bug report for the improper use of "align" a while ago.
JavaScript errors
There are quite a few JavaScript errors (documented in the bug tracker as well) when using DokuWiki with a strict Doctype.
Warning on "hidden" scripts
“XML parsers are permitted to silently remove the contents of comments. Therefore, you should not use comments to “hide” scripts or style sheets.”
<script type="text/javascript" charset="utf-8" ><!--//--><![CDATA[//><!-- [...]
Which raises the question: Is it better to think about the past or the future?
What else?
You should also be aware of the fact that plugins, templates, etc. may not take care of strictness at all! So, if your DokuWiki installation uses any of these enhancements, you should make sure they produce strict xhtml.
Further reading
A good starting point is this page.
Differences to Switching to XHTML 1.1
As far as it comes to XHTML 1.1, if it is XHTML 1.0 strict there is a pretty good chance that is is valid XHTML 1.1. The biggest point of XHTML 1.1 is that they (W3C) disallowed the transition XHTML. To make your wiki XHTML 1.1 conform use the trick noted above but replace the DTD with:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
Sean Farrell sean [dot] farrell [at] digital [dash] egg [dot] org
To pass the validator check you have to:
- delete the lang attribute from html element in the above mentioned pages
- remove all the occurence of the attribute name occuring on a and map elements. Search for things like name=“fn__'.$id.'”, i said like , at least in inc/parser/xhtml.php