2007-05-03
Askaaron
Under certain circumstances it may occur, that DokuWiki creates invalid XHTML output for jpeg images - missing ALT attribute - if they contain no wiki title and the file itself does also not contain any caption.
Test:
1) Wiki code: {{image.jpg}}
2) image.jpg does not contain any caption
The problem is in inc/parser/xhtml.php, lines 993-1004:
if (!is_null($title)) {
$ret .= ' title="'.$this->_xmlEntities($title).'"';
$ret .= ' alt="'.$this->_xmlEntities($title).'"';
}elseif($ext == 'jpg' || $ext == 'jpeg'){
//try to use the caption from IPTC/EXIF
require_once(DOKU_INC.'inc/JpegMeta.php');
$jpeg =& new JpegMeta(mediaFN($src));
if($jpeg !== false) $cap = $jpeg->getTitle();
if($cap){
$ret .= ' title="'.$this->_xmlEntities($cap).'"';
$ret .= ' alt="'.$this->_xmlEntities($cap).'"';
}
}else{
$ret .= ' alt=""';
}
So - if there is no title, the the ALT attribute will be empty - OK.
BUT: If there is no title AND the image is jpeg, DokuWiki will try to use the caption in the image - and if there is no caption, the ALT attribute will be missing completely!
Solution:
Add an addition else branch for the case, that there is no caption in the jpeg image:
[...]
if($cap){
$ret .= ' title="'.$this->_xmlEntities($cap).'"';
$ret .= ' alt="'.$this->_xmlEntities($cap).'"';
}
else $ret .= ' alt=""';
[...]