summaryrefslogtreecommitdiff
path: root/inc/parser/xhtml.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/parser/xhtml.php')
-rw-r--r--inc/parser/xhtml.php141
1 files changed, 101 insertions, 40 deletions
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index 5c0353688..f1703111e 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -28,6 +28,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
/** @var array A stack of section edit data */
protected $sectionedits = array();
+ var $date_at = ''; // link pages and media against this revision
/** @var int last section edit id, used by startSectionEdit */
protected $lastsecid = 0;
@@ -58,10 +59,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
/**
* Register a new edit section range
*
- * @param $type string The section type identifier
- * @param $title string The section title
- * @param $start int The byte position for the edit start
- * @return string A marker class for the starting HTML element
+ * @param string $type The section type identifier
+ * @param string $title The section title
+ * @param int $start The byte position for the edit start
+ * @return string A marker class for the starting HTML element
+ *
* @author Adrian Lang <lang@cosmocode.de>
*/
public function startSectionEdit($start, $type, $title = null) {
@@ -72,8 +74,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
/**
* Finish an edit section range
*
- * @param $end int The byte position for the edit end; null for the rest of
- * the page
+ * @param int $end The byte position for the edit end; null for the rest of the page
+ *
* @author Adrian Lang <lang@cosmocode.de>
*/
public function finishSectionEdit($end = null) {
@@ -455,9 +457,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
* Open a list item
*
* @param int $level the nesting level
+ * @param bool $node true when a node; false when a leaf
*/
- function listitem_open($level) {
- $this->doc .= '<li class="level'.$level.'">';
+ function listitem_open($level, $node=false) {
+ $branching = $node ? ' node' : '';
+ $this->doc .= '<li class="level'.$level.$branching.'">';
}
/**
@@ -818,8 +822,9 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$default = $this->_simpleTitle($id);
// now first resolve and clean up the $id
- resolve_pageid(getNS($ID), $id, $exists);
+ resolve_pageid(getNS($ID), $id, $exists, $this->date_at, true);
+ $link = array();
$name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype);
if(!$isImage) {
if($exists) {
@@ -846,11 +851,14 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$link['pre'] = '<span class="curid">';
$link['suf'] = '</span>';
}
- $link['more'] = '';
- $link['class'] = $class;
- $link['url'] = wl($id, $params);
- $link['name'] = $name;
- $link['title'] = $id;
+ $link['more'] = '';
+ $link['class'] = $class;
+ if($this->date_at) {
+ $params['at'] = $this->date_at;
+ }
+ $link['url'] = wl($id, $params);
+ $link['name'] = $name;
+ $link['title'] = $id;
//add search string
if($search) {
($conf['userewrite']) ? $link['url'] .= '?' : $link['url'] .= '&amp;';
@@ -904,6 +912,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
}
//prepare for formating
+ $link = array();
$link['target'] = $conf['target']['extern'];
$link['style'] = '';
$link['pre'] = '';
@@ -981,6 +990,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
global $conf;
//simple setup
+ $link = array();
$link['target'] = $conf['target']['windows'];
$link['pre'] = '';
$link['suf'] = '';
@@ -995,6 +1005,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$link['title'] = $this->_xmlEntities($url);
$url = str_replace('\\', '/', $url);
+ $url = ltrim($url,'/');
$url = 'file:///'.$url;
$link['url'] = $url;
@@ -1062,7 +1073,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$height = null, $cache = null, $linking = null, $return = false) {
global $ID;
list($src, $hash) = explode('#', $src, 2);
- resolve_mediaid(getNS($ID), $src, $exists);
+ resolve_mediaid(getNS($ID), $src, $exists, $this->date_at, true);
$noLink = false;
$render = ($linking == 'linkonly') ? false : true;
@@ -1070,7 +1081,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
list($ext, $mime) = mimetype($src, false);
if(substr($mime, 0, 5) == 'image' && $render) {
- $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache), ($linking == 'direct'));
+ $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src)), ($linking == 'direct'));
} elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) {
// don't link movies
$noLink = true;
@@ -1078,7 +1089,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
// add file icons
$class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
$link['class'] .= ' mediafile mf_'.$class;
- $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache), true);
+ $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache , 'rev'=>$this->_getLastMediaRevisionAt($src)), true);
if($exists) $link['title'] .= ' ('.filesize_h(filesize(mediaFN($src))).')';
}
@@ -1109,9 +1120,10 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
* @param int $height height of media in pixel
* @param string $cache cache|recache|nocache
* @param string $linking linkonly|detail|nolink
+ * @param bool $return return HTML instead of adding to $doc
*/
function externalmedia($src, $title = null, $align = null, $width = null,
- $height = null, $cache = null, $linking = null) {
+ $height = null, $cache = null, $linking = null, $return = false) {
list($src, $hash) = explode('#', $src, 2);
$noLink = false;
$render = ($linking == 'linkonly') ? false : true;
@@ -1135,8 +1147,13 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
if($hash) $link['url'] .= '#'.$hash;
//output formatted
- if($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
- else $this->doc .= $this->_formatLink($link);
+ if($return) {
+ if($linking == 'nolink' || $noLink) return $link['name'];
+ else return $this->_formatLink($link);
+ } else {
+ if($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
+ else $this->doc .= $this->_formatLink($link);
+ }
}
/**
@@ -1430,7 +1447,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
return $title;
}
//add image tag
- $ret .= '<img src="'.ml($src, array('w' => $width, 'h' => $height, 'cache' => $cache)).'"';
+ $ret .= '<img src="'.ml($src, array('w' => $width, 'h' => $height, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src))).'"';
$ret .= ' class="media'.$align.'"';
if($title) {
@@ -1565,7 +1582,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
* Returns HTML code for images used in link titles
*
* @author Andreas Gohr <andi@splitbrain.org>
- * @param string $img
+ * @param array $img
* @return string HTML img tag or similar
*/
function _imageTitle($img) {
@@ -1575,7 +1592,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
// see internalmedia() and externalmedia()
list($img['src']) = explode('#', $img['src'], 2);
if($img['type'] == 'internalmedia') {
- resolve_mediaid(getNS($ID), $img['src'], $exists);
+ resolve_mediaid(getNS($ID), $img['src'], $exists ,$this->date_at, true);
}
return $this->_media(
@@ -1638,13 +1655,22 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
if(!$atts['width']) $atts['width'] = 320;
if(!$atts['height']) $atts['height'] = 240;
- // prepare alternative formats
- $extensions = array('webm', 'ogv', 'mp4');
- $alternatives = media_alternativefiles($src, $extensions);
- $poster = media_alternativefiles($src, array('jpg', 'png'), true);
- $posterUrl = '';
- if(!empty($poster)) {
- $posterUrl = ml(reset($poster), '', true, '&');
+ $posterUrl = '';
+ $files = array();
+ $isExternal = media_isexternal($src);
+
+ if ($isExternal) {
+ // take direct source for external files
+ list(/*ext*/, $srcMime) = mimetype($src);
+ $files[$srcMime] = $src;
+ } else {
+ // prepare alternative formats
+ $extensions = array('webm', 'ogv', 'mp4');
+ $files = media_alternativefiles($src, $extensions);
+ $poster = media_alternativefiles($src, array('jpg', 'png'));
+ if(!empty($poster)) {
+ $posterUrl = ml(reset($poster), '', true, '&');
+ }
}
$out = '';
@@ -1655,13 +1681,19 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$fallback = '';
// output source for each alternative video format
- foreach($alternatives as $mime => $file) {
- $url = ml($file, '', true, '&');
+ foreach($files as $mime => $file) {
+ if ($isExternal) {
+ $url = $file;
+ $linkType = 'externalmedia';
+ } else {
+ $url = ml($file, '', true, '&');
+ $linkType = 'internalmedia';
+ }
$title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file)));
$out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL;
// alternative content (just a link to the file)
- $fallback .= $this->internalmedia($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true);
+ $fallback .= $this->$linkType($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true);
}
// finish
@@ -1679,11 +1711,19 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
* @param array $atts - additional attributes for the <audio> tag
* @return string
*/
- function _audio($src, $atts = null) {
+ function _audio($src, $atts = array()) {
+ $files = array();
+ $isExternal = media_isexternal($src);
- // prepare alternative formats
- $extensions = array('ogg', 'mp3', 'wav');
- $alternatives = media_alternativefiles($src, $extensions);
+ if ($isExternal) {
+ // take direct source for external files
+ list(/*ext*/, $srcMime) = mimetype($src);
+ $files[$srcMime] = $src;
+ } else {
+ // prepare alternative formats
+ $extensions = array('ogg', 'mp3', 'wav');
+ $files = media_alternativefiles($src, $extensions);
+ }
$out = '';
// open audio tag
@@ -1691,13 +1731,19 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$fallback = '';
// output source for each alternative audio format
- foreach($alternatives as $mime => $file) {
- $url = ml($file, '', true, '&');
+ foreach($files as $mime => $file) {
+ if ($isExternal) {
+ $url = $file;
+ $linkType = 'externalmedia';
+ } else {
+ $url = ml($file, '', true, '&');
+ $linkType = 'internalmedia';
+ }
$title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file)));
$out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL;
// alternative content (just a link to the file)
- $fallback .= $this->internalmedia($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true);
+ $fallback .= $this->$linkType($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true);
}
// finish
@@ -1705,6 +1751,21 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$out .= '</audio>'.NL;
return $out;
}
+
+ /**
+ * _getLastMediaRevisionAt is a helperfunction to internalmedia() and _media()
+ * which returns an existing media revision less or equal to rev or date_at
+ *
+ * @author lisps
+ * @param string $media_id
+ * @access protected
+ * @return string revision ('' for current)
+ */
+ function _getLastMediaRevisionAt($media_id){
+ if(!$this->date_at || media_isexternal($media_id)) return '';
+ $pagelog = new MediaChangeLog($media_id);
+ return $pagelog->getLastRevisionAt($this->date_at);
+ }
#endregion
}