From 5c2eed9a193e9341fbfee63d4a973898acdc5ee5 Mon Sep 17 00:00:00 2001 From: lisps Date: Thu, 21 Nov 2013 15:50:52 +0100 Subject: add parameter at($DATE_AT) and mind revisions --- doku.php | 15 ++++++++++++++- inc/changelog.php | 23 +++++++++++++++++++++++ inc/common.php | 2 +- inc/html.php | 5 +++-- inc/parser/xhtml.php | 44 ++++++++++++++++++++++++++++++++++++++++---- inc/parserutils.php | 15 +++++++++++---- inc/template.php | 5 +++-- lib/exe/detail.php | 5 ++++- lib/tpl/dokuwiki/detail.php | 2 +- 9 files changed, 100 insertions(+), 16 deletions(-) diff --git a/doku.php b/doku.php index f44e09aa8..2059f9761 100644 --- a/doku.php +++ b/doku.php @@ -34,6 +34,7 @@ $QUERY = trim($INPUT->str('id')); $ID = getID(); $REV = $INPUT->int('rev'); +$DATE_AT= $INPUT->int('at'); $IDX = $INPUT->str('idx'); $DATE = $INPUT->int('date'); $RANGE = $INPUT->str('range'); @@ -47,7 +48,19 @@ $PRE = cleanText(substr($INPUT->post->str('prefix'), 0, -1)); $SUF = cleanText($INPUT->post->str('suffix')); $SUM = $INPUT->post->str('summary'); -//make info about the selected page available +if($DATE_AT) { + $rev_t = getProperRevision($ID,$DATE_AT); + if($rev_t === '') { + $REV = ''; + } else if ($rev_t === false) { + msg('Seite gab es zu diesem Zeitpunkt noch nicht'); + $REV = $DATE_AT; + } else { + $REV = $rev_t; + } +} + +//make infos about the selected page available $INFO = pageinfo(); //export minimal info to JS, plugins can add more diff --git a/inc/changelog.php b/inc/changelog.php index de26fdf6a..0a33f6a6e 100644 --- a/inc/changelog.php +++ b/inc/changelog.php @@ -814,3 +814,26 @@ function getRevisions($id, $first, $num, $chunk_size=8192, $media=false) { $log = new PageRevisionLog($id, $chunk_size); return $log->getRevisions($first, $num, $media); } + +/** +* Return an existing revision for a specific date which is +* the current one or less or equal then the date +* +* @param string $id +* @param number $date_at +* @param boolean $media +* @return string revision ('' for current) +*/ +function getProperRevision($id,$date_at,$media = false){ + $create_time = @filemtime($media?mediaFN($id):wikiFN($id)); + if(((int)$date_at) >= $create_time) { //requestet REV older then time($id) => load current + return ''; + } else { + $log = new PageRevisionLog($id); + if($rev = $log->getRelativeRevision($date_at+1, -1,$media)) { + return $rev; + } else { + return false; + } + } +} \ No newline at end of file diff --git a/inc/common.php b/inc/common.php index dd30b53ab..e5e4f78c8 100644 --- a/inc/common.php +++ b/inc/common.php @@ -161,7 +161,7 @@ function pageinfo() { if($REV) { //check if current revision was meant if($info['exists'] && (@filemtime($info['filepath']) == $REV)) { - $REV = ''; + //$REV = ''; //if we enter a rev we want to see that revision (inc media files) } elseif($RANGE) { //section editing does not work with old revisions! $REV = ''; diff --git a/inc/html.php b/inc/html.php index b48a17fc5..5b79ab659 100644 --- a/inc/html.php +++ b/inc/html.php @@ -207,6 +207,7 @@ function html_show($txt=null){ global $REV; global $HIGH; global $INFO; + global $DATE_AT; //disable section editing for old revisions or in preview if($txt || $REV){ $secedit = false; @@ -226,8 +227,8 @@ function html_show($txt=null){ echo ''; }else{ - if ($REV) print p_locale_xhtml('showrev'); - $html = p_wiki_xhtml($ID,$REV,true); + if ($REV||$DATE_AT) print p_locale_xhtml('showrev'); + $html = p_wiki_xhtml($ID,$REV,true,$DATE_AT); $html = html_secedit($html,$secedit); if($INFO['prependTOC']) $html = tpl_toc(true).$html; $html = html_hilight($html,$HIGH); diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index fd02c0ce0..a677db276 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -28,6 +28,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // @access public var $doc = ''; // will contain the whole document var $toc = array(); // will contain the Table of Contents + var $rev = ''; + var $date_at = ''; var $sectionedits = array(); // A stack of section edit data private $lastsecid = 0; // last section edit id, used by startSectionEdit @@ -618,6 +620,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } $link['more'] = ''; $link['class'] = $class; + if($this->date_at) { + $params['at'] = $this->date_at; + } else if($this->rev) { + //$params['at'] = $this->rev; + } $link['url'] = wl($id, $params); $link['name'] = $name; $link['title'] = $id; @@ -792,7 +799,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer { list($ext,$mime,$dl) = mimetype($src,false); if(substr($mime,0,5) == 'image' && $render){ - $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); + if(($this->rev||$this->date_at)) { + $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache,'rev'=>$this->_getProperMediaRevision($src)),($linking=='direct')); + } else { + $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); + } }elseif($mime == 'application/x-shockwave-flash' && $render){ // don't link flash movies $noLink = true; @@ -800,7 +811,11 @@ 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); + if(($this->rev||$this->date_at)) { + $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache,'rev'=>$this->_getProperMediaRevision($src)),true); + } else { + $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); + } if ($exists) $link['title'] .= ' (' . filesize_h(filesize(mediaFN($src))).')'; } @@ -1048,7 +1063,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $height=null, $cache=null, $render = true) { $ret = ''; - + $intern = !is_externalmedia($src); list($ext,$mime,$dl) = mimetype($src); if(substr($mime,0,5) == 'image'){ // first get the $title @@ -1073,7 +1088,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer { return $title; } //add image tag - $ret .= 'rev||$this->date_at)) { + $ret .= '$width,'h'=>$height,'cache'=>$cache)).'"'; + } $ret .= ' class="media'.$align.'"'; if ($title) { @@ -1221,6 +1240,23 @@ class Doku_Renderer_xhtml extends Doku_Renderer { return $link; } + + /** + * _getProperMediaRevision 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 _getProperMediaRevision($media_id){ + $rev = $this->rev; + if($this->date_at){ + $rev = $this->date_at; + } + return getProperRevision($media_id,$rev,true); + } } diff --git a/inc/parserutils.php b/inc/parserutils.php index b67daaabb..c50bf7332 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -56,7 +56,7 @@ define('METADATA_RENDER_UNLIMITED', 4); * * @author Andreas Gohr */ -function p_wiki_xhtml($id, $rev='', $excuse=true){ +function p_wiki_xhtml($id, $rev='', $excuse=true,$date_at=''){ $file = wikiFN($id,$rev); $ret = ''; @@ -65,9 +65,9 @@ function p_wiki_xhtml($id, $rev='', $excuse=true){ $keep = $ID; $ID = $id; - if($rev){ + if($rev || $date_at){ if(@file_exists($file)){ - $ret = p_render('xhtml',p_get_instructions(io_readWikiPage($file,$id,$rev)),$info); //no caching on old revisions + $ret = p_render('xhtml',p_get_instructions(io_readWikiPage($file,$id,$rev)),$info,$rev,$date_at); //no caching on old revisions }elseif($excuse){ $ret = p_locale_xhtml('norev'); } @@ -583,7 +583,7 @@ function p_sort_modes($a, $b){ * @author Harry Fuecks * @author Andreas Gohr */ -function p_render($mode,$instructions,&$info){ +function p_render($mode,$instructions,&$info,$rev='',$date_at=''){ if(is_null($instructions)) return ''; $Renderer =& p_get_renderer($mode); @@ -591,6 +591,13 @@ function p_render($mode,$instructions,&$info){ $Renderer->reset(); + if($rev) { + $Renderer->rev = $rev; + } + if($date_at) { + $Renderer->date_at = $date_at; + } + $Renderer->smileys = getSmileys(); $Renderer->entities = getEntities(); $Renderer->acronyms = getAcronyms(); diff --git a/inc/template.php b/inc/template.php index 60e178d1a..ac85059a8 100644 --- a/inc/template.php +++ b/inc/template.php @@ -1031,6 +1031,7 @@ function tpl_img_getTag($tags, $alt = '', $src = null) { function tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) { global $IMG; global $INPUT; + global $REV; $w = tpl_img_getTag('File.Width'); $h = tpl_img_getTag('File.Height'); @@ -1055,8 +1056,8 @@ function tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) { } //prepare URLs - $url = ml($IMG, array('cache'=> $INPUT->str('cache')), true, '&'); - $src = ml($IMG, array('cache'=> $INPUT->str('cache'), 'w'=> $w, 'h'=> $h), true, '&'); + $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&'); + $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&'); //prepare attributes $alt = tpl_img_getTag('Simple.Title'); diff --git a/lib/exe/detail.php b/lib/exe/detail.php index cd3f362ad..daa55f405 100644 --- a/lib/exe/detail.php +++ b/lib/exe/detail.php @@ -5,6 +5,9 @@ require_once(DOKU_INC.'inc/init.php'); $IMG = getID('media'); $ID = cleanID($INPUT->str('id')); +$REV = & $INPUT->ref('rev'); +//sanitize revision +$REV = preg_replace('/[^0-9]/', '', $REV); // this makes some general info available as well as the info about the // "parent" page @@ -35,7 +38,7 @@ $ERROR = false; $AUTH = auth_quickaclcheck($IMG); if($AUTH >= AUTH_READ){ // check if image exists - $SRC = mediaFN($IMG); + $SRC = mediaFN($IMG,$REV); if(!@file_exists($SRC)){ //doesn't exist! http_status(404); diff --git a/lib/tpl/dokuwiki/detail.php b/lib/tpl/dokuwiki/detail.php index ec846f6fd..49249612b 100644 --- a/lib/tpl/dokuwiki/detail.php +++ b/lib/tpl/dokuwiki/detail.php @@ -49,7 +49,7 @@ header('X-UA-Compatible: IE=edge,chrome=1'); if($ERROR): echo '

'.$ERROR.'

'; else: ?> - +

-- cgit v1.2.3 From 4bde2196a1e3572cead3f4d4e4b6a5a752bd62b3 Mon Sep 17 00:00:00 2001 From: lisps Date: Fri, 22 Nov 2013 09:04:44 +0100 Subject: remove property rev from xhtml.php changed variable name $create_time to $modified_time --- doku.php | 2 +- inc/changelog.php | 4 ++-- inc/common.php | 1 + inc/parser/xhtml.php | 17 +++++------------ inc/parserutils.php | 7 ++----- lib/exe/detail.php | 4 +--- 6 files changed, 12 insertions(+), 23 deletions(-) diff --git a/doku.php b/doku.php index 2059f9761..17ec824a9 100644 --- a/doku.php +++ b/doku.php @@ -34,7 +34,7 @@ $QUERY = trim($INPUT->str('id')); $ID = getID(); $REV = $INPUT->int('rev'); -$DATE_AT= $INPUT->int('at'); +$DATE_AT = $INPUT->int('at'); $IDX = $INPUT->str('idx'); $DATE = $INPUT->int('date'); $RANGE = $INPUT->str('range'); diff --git a/inc/changelog.php b/inc/changelog.php index 0a33f6a6e..7ce8096d5 100644 --- a/inc/changelog.php +++ b/inc/changelog.php @@ -825,8 +825,8 @@ function getRevisions($id, $first, $num, $chunk_size=8192, $media=false) { * @return string revision ('' for current) */ function getProperRevision($id,$date_at,$media = false){ - $create_time = @filemtime($media?mediaFN($id):wikiFN($id)); - if(((int)$date_at) >= $create_time) { //requestet REV older then time($id) => load current + $modified_time = @filemtime($media?mediaFN($id):wikiFN($id)); + if(((int)$date_at) >= $modified_time) { //requestet REV younger or equal then time($id) => load current return ''; } else { $log = new PageRevisionLog($id); diff --git a/inc/common.php b/inc/common.php index e5e4f78c8..7f7095a12 100644 --- a/inc/common.php +++ b/inc/common.php @@ -383,6 +383,7 @@ function idfilter($id, $ue = true) { function wl($id = '', $urlParameters = '', $absolute = false, $separator = '&') { global $conf; if(is_array($urlParameters)) { + if(isset($urlParameters['rev']) && !$urlParameters['rev']) unset($urlParameters['rev']); $urlParameters = buildURLparams($urlParameters, $separator); } else { $urlParameters = str_replace(',', $separator, $urlParameters); diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index a677db276..f6e186cdb 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -28,8 +28,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // @access public var $doc = ''; // will contain the whole document var $toc = array(); // will contain the Table of Contents - var $rev = ''; - var $date_at = ''; + var $date_at = ''; // link pages and media against this revision var $sectionedits = array(); // A stack of section edit data private $lastsecid = 0; // last section edit id, used by startSectionEdit @@ -622,8 +621,6 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $link['class'] = $class; if($this->date_at) { $params['at'] = $this->date_at; - } else if($this->rev) { - //$params['at'] = $this->rev; } $link['url'] = wl($id, $params); $link['name'] = $name; @@ -799,7 +796,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { list($ext,$mime,$dl) = mimetype($src,false); if(substr($mime,0,5) == 'image' && $render){ - if(($this->rev||$this->date_at)) { + if($this->date_at) { $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache,'rev'=>$this->_getProperMediaRevision($src)),($linking=='direct')); } else { $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); @@ -811,7 +808,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // add file icons $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); $link['class'] .= ' mediafile mf_'.$class; - if(($this->rev||$this->date_at)) { + if($this->date_at) { $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache,'rev'=>$this->_getProperMediaRevision($src)),true); } else { $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); @@ -1088,7 +1085,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { return $title; } //add image tag - if($intern && ($this->rev||$this->date_at)) { + if($intern && $this->date_at) { $ret .= '$width,'h'=>$height,'cache'=>$cache)).'"'; @@ -1251,11 +1248,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * @return string revision ('' for current) */ function _getProperMediaRevision($media_id){ - $rev = $this->rev; - if($this->date_at){ - $rev = $this->date_at; - } - return getProperRevision($media_id,$rev,true); + return getProperRevision($media_id,$this->date_at,true); } diff --git a/inc/parserutils.php b/inc/parserutils.php index c50bf7332..ecb1ac888 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -67,7 +67,7 @@ function p_wiki_xhtml($id, $rev='', $excuse=true,$date_at=''){ if($rev || $date_at){ if(@file_exists($file)){ - $ret = p_render('xhtml',p_get_instructions(io_readWikiPage($file,$id,$rev)),$info,$rev,$date_at); //no caching on old revisions + $ret = p_render('xhtml',p_get_instructions(io_readWikiPage($file,$id,$rev)),$info,max($rev,$date_at)); //no caching on old revisions }elseif($excuse){ $ret = p_locale_xhtml('norev'); } @@ -583,7 +583,7 @@ function p_sort_modes($a, $b){ * @author Harry Fuecks * @author Andreas Gohr */ -function p_render($mode,$instructions,&$info,$rev='',$date_at=''){ +function p_render($mode,$instructions,&$info,$date_at=''){ if(is_null($instructions)) return ''; $Renderer =& p_get_renderer($mode); @@ -591,9 +591,6 @@ function p_render($mode,$instructions,&$info,$rev='',$date_at=''){ $Renderer->reset(); - if($rev) { - $Renderer->rev = $rev; - } if($date_at) { $Renderer->date_at = $date_at; } diff --git a/lib/exe/detail.php b/lib/exe/detail.php index daa55f405..cc29d5b87 100644 --- a/lib/exe/detail.php +++ b/lib/exe/detail.php @@ -5,9 +5,7 @@ require_once(DOKU_INC.'inc/init.php'); $IMG = getID('media'); $ID = cleanID($INPUT->str('id')); -$REV = & $INPUT->ref('rev'); -//sanitize revision -$REV = preg_replace('/[^0-9]/', '', $REV); +$REV = $INPUT->int('rev'); // this makes some general info available as well as the info about the // "parent" page -- cgit v1.2.3 From 78b874e68a5f2a45f71a91efb168761c283e3a91 Mon Sep 17 00:00:00 2001 From: lisps Date: Fri, 22 Nov 2013 10:51:16 +0100 Subject: fix function name media_isexternal() remove empty rev from ml() rename getProperRevision() to getLastRevisionAt() make getLastRevisionAt() a method of ChangeLog --- doku.php | 3 ++- inc/changelog.php | 41 +++++++++++++++++++---------------------- inc/common.php | 1 + inc/parser/xhtml.php | 5 +++-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/doku.php b/doku.php index 17ec824a9..e90f8bea2 100644 --- a/doku.php +++ b/doku.php @@ -49,7 +49,8 @@ $SUF = cleanText($INPUT->post->str('suffix')); $SUM = $INPUT->post->str('summary'); if($DATE_AT) { - $rev_t = getProperRevision($ID,$DATE_AT); + $pagelog = new PageChangeLog($ID); + $rev_t = $pagelog->getLastRevisionAt($DATE_AT); if($rev_t === '') { $REV = ''; } else if ($rev_t === false) { diff --git a/inc/changelog.php b/inc/changelog.php index 75fe29e5b..ccb5f7a3e 100644 --- a/inc/changelog.php +++ b/inc/changelog.php @@ -771,6 +771,25 @@ abstract class ChangeLog { public function isCurrentRevision($rev) { return $rev == @filemtime($this->getFilename()); } + + /** + * Return an existing revision for a specific date which is + * the current one or younger or equal then the date + * + * @param string $id + * @param number $date_at timestamp + * @return string revision ('' for current) + */ + function getLastRevisionAt($date_at){ + //requested date_at(timestamp) younger or equal then modified_time($this->id) => load current + if($date_at >= @filemtime($this->getFilename())) { + return ''; + } else if ($rev = $this->getRelativeRevision($date_at+1, -1)) { //+1 to get also the requested date revision + return $rev; + } else { + return false; + } + } } class PageChangelog extends ChangeLog { @@ -870,25 +889,3 @@ function getRevisions($id, $first, $num, $chunk_size=8192, $media=false) { return $changelog->getRevisions($first, $num); } -/** -* Return an existing revision for a specific date which is -* the current one or less or equal then the date -* -* @param string $id -* @param number $date_at -* @param boolean $media -* @return string revision ('' for current) -*/ -function getProperRevision($id,$date_at,$media = false){ - $modified_time = @filemtime($media?mediaFN($id):wikiFN($id)); - if(((int)$date_at) >= $modified_time) { //requestet REV younger or equal then time($id) => load current - return ''; - } else { - $log = new PageRevisionLog($id); - if($rev = $log->getRelativeRevision($date_at+1, -1,$media)) { - return $rev; - } else { - return false; - } - } -} diff --git a/inc/common.php b/inc/common.php index 106bf7c15..5dcf58e39 100644 --- a/inc/common.php +++ b/inc/common.php @@ -484,6 +484,7 @@ function ml($id = '', $more = '', $direct = true, $sep = '&', $abs = false) if(empty($more['w'])) unset($more['w']); if(empty($more['h'])) unset($more['h']); if(isset($more['id']) && $direct) unset($more['id']); + if(isset($more['rev']) && !$more['rev']) unset($more['rev']); $more = buildURLparams($more, $sep); } else { $matches = array(); diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index f6e186cdb..76aecac10 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -1060,7 +1060,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $height=null, $cache=null, $render = true) { $ret = ''; - $intern = !is_externalmedia($src); + $intern = !media_isexternal($src); list($ext,$mime,$dl) = mimetype($src); if(substr($mime,0,5) == 'image'){ // first get the $title @@ -1248,7 +1248,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * @return string revision ('' for current) */ function _getProperMediaRevision($media_id){ - return getProperRevision($media_id,$this->date_at,true); + $pagelog = new MediaChangeLog($media_id); + return $pagelog->getLastRevisionAt($this->date_at); } -- cgit v1.2.3 From 4eb5e17453694b80e84a83a6960d02ac63cfa320 Mon Sep 17 00:00:00 2001 From: lisps Date: Fri, 22 Nov 2013 13:27:38 +0100 Subject: add test getlastrevisionat --- .../tests/inc/changelog_getlastrevisionat.test.php | 127 +++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 _test/tests/inc/changelog_getlastrevisionat.test.php diff --git a/_test/tests/inc/changelog_getlastrevisionat.test.php b/_test/tests/inc/changelog_getlastrevisionat.test.php new file mode 100644 index 000000000..b4d0466b3 --- /dev/null +++ b/_test/tests/inc/changelog_getlastrevisionat.test.php @@ -0,0 +1,127 @@ +getLastRevisionAt($rev); + $this->assertEquals($revsexpected, $revs); + } + + /** + * start at exact current revision of mailinglist page + * + */ + function test_startatexactcurrentrev() { + $rev = 1385051947; + $revsexpected = ''; + + //set a known timestamp + touch(wikiFN($this->pageid), $rev); + + $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192); + $revs = $pagelog->getLastRevisionAt($rev); + $this->assertEquals($revsexpected, $revs); + + } + + /** + * test a future revision + * + */ + function test_futurerev() { + $rev = 1385051947; + $revsexpected = ''; + + //set a known timestamp + touch(wikiFN($this->pageid), $rev); + + $rev +=1; + + $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192); + $revs = $pagelog->getLastRevisionAt($rev); + $this->assertEquals($revsexpected, $revs); + + } + + /** + * start at exact last revision of mailinglist page + * + */ + function test_exactlastrev() { + $rev = 1360110636; + $revsexpected = 1360110636; + + $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192); + $revs = $pagelog->getLastRevisionAt($rev); + $this->assertEquals($revsexpected, $revs); + } + + + /** + * Request not existing revision + * + */ + function test_olderrev() { + $rev = 1; + $revexpected = false; + + $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192); + $revfound = $pagelog->getLastRevisionAt($rev); + $this->assertEquals($revexpected, $revfound); + } + + /** + * Start at non existing revision somewhere between existing revisions + */ + function test_notexistingrev() { + $rev = 1362525890; + $revexpected = 1362525359; + + $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192); + $revfound = $pagelog->getLastRevisionAt($rev); + $this->assertEquals($revexpected, $revfound); + } + + /** + * request nonexisting page + * + */ + function test_notexistingpage() { + $rev = 1385051947; + $currentexpected = false; + + $pagelog = new PageChangeLog('nonexistingpage', $chunk_size = 8192); + $current = $pagelog->getLastRevisionAt($rev); + $this->assertEquals($currentexpected, $current); + } +} \ No newline at end of file -- cgit v1.2.3 From 4c3263af6652b0a479e2c742914eb67a7929b9b9 Mon Sep 17 00:00:00 2001 From: lisps Date: Fri, 22 Nov 2013 13:45:20 +0100 Subject: localize msg --- doku.php | 3 ++- inc/lang/en/lang.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doku.php b/doku.php index e90f8bea2..be6ab81f8 100644 --- a/doku.php +++ b/doku.php @@ -54,7 +54,8 @@ if($DATE_AT) { if($rev_t === '') { $REV = ''; } else if ($rev_t === false) { - msg('Seite gab es zu diesem Zeitpunkt noch nicht'); + $rev_n = $pagelog->getRelativeRevision($DATE_AT,+1); + msg(sprintf($lang['page_nonexist_rev'], $DATE_AT,$rev_n)); $REV = $DATE_AT; } else { $REV = $rev_t; diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php index 73b9981d2..ad887f4c4 100644 --- a/inc/lang/en/lang.php +++ b/inc/lang/en/lang.php @@ -365,4 +365,5 @@ $lang['currentns'] = 'Current namespace'; $lang['searchresult'] = 'Search Result'; $lang['plainhtml'] = 'Plain HTML'; $lang['wikimarkup'] = 'Wiki Markup'; +$lang['page_nonexist_rev'] = "Page has not existed with revision %d, try %d"; //Setup VIM: ex: et ts=2 : -- cgit v1.2.3 From d81178045b12622c84f48c892ddda32c6aba5576 Mon Sep 17 00:00:00 2001 From: lisps Date: Fri, 22 Nov 2013 13:56:58 +0100 Subject: restore old version of pageinfo() --- inc/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/common.php b/inc/common.php index 5dcf58e39..ce74717d0 100644 --- a/inc/common.php +++ b/inc/common.php @@ -161,7 +161,7 @@ function pageinfo() { if($REV) { //check if current revision was meant if($info['exists'] && (@filemtime($info['filepath']) == $REV)) { - //$REV = ''; //if we enter a rev we want to see that revision (inc media files) + $REV = ''; } elseif($RANGE) { //section editing does not work with old revisions! $REV = ''; -- cgit v1.2.3 From 52dc5ead7374060b89484fc0713bc38d8ec1467c Mon Sep 17 00:00:00 2001 From: lisps Date: Fri, 22 Nov 2013 14:36:35 +0100 Subject: rename function _getProperMediaRevision to _getLastMediaRevisionAt reduce a bit duplicated code --- inc/parser/xhtml.php | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 76aecac10..2070c3af6 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -796,11 +796,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { list($ext,$mime,$dl) = mimetype($src,false); if(substr($mime,0,5) == 'image' && $render){ - if($this->date_at) { - $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache,'rev'=>$this->_getProperMediaRevision($src)),($linking=='direct')); - } else { - $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' && $render){ // don't link flash movies $noLink = true; @@ -808,11 +804,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // add file icons $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); $link['class'] .= ' mediafile mf_'.$class; - if($this->date_at) { - $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache,'rev'=>$this->_getProperMediaRevision($src)),true); - } else { - $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))).')'; } @@ -1060,7 +1052,6 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $height=null, $cache=null, $render = true) { $ret = ''; - $intern = !media_isexternal($src); list($ext,$mime,$dl) = mimetype($src); if(substr($mime,0,5) == 'image'){ // first get the $title @@ -1085,11 +1076,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { return $title; } //add image tag - if($intern && $this->date_at) { - $ret .= '$width,'h'=>$height,'cache'=>$cache)).'"'; - } + $ret .= 'date_at || media_isexternal($media_id)) return ''; $pagelog = new MediaChangeLog($media_id); return $pagelog->getLastRevisionAt($this->date_at); } -- cgit v1.2.3 From 07a7d227f78d5956f62a4164def7c68ca03019ee Mon Sep 17 00:00:00 2001 From: lisps Date: Fri, 22 Nov 2013 14:56:42 +0100 Subject: add test for empty rev in ml() and wl() --- _test/tests/inc/common_ml.test.php | 11 +++++++++++ _test/tests/inc/common_wl.test.php | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/_test/tests/inc/common_ml.test.php b/_test/tests/inc/common_ml.test.php index 415c0a88d..027dcaef2 100644 --- a/_test/tests/inc/common_ml.test.php +++ b/_test/tests/inc/common_ml.test.php @@ -146,4 +146,15 @@ class common_ml_test extends DokuWikiTest { $this->assertEquals($expect, ml($id, $args)); } + + function test_ml_empty_rev() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 0; + + $args = array('a' => 'b', 'c' => 'd', 'rev' => ''); + + $expect = DOKU_BASE . $this->script . '?a=b&c=d&media=some:img.jpg'; + $this->assertEquals($expect, ml('some:img.jpg', $args)); + } } diff --git a/_test/tests/inc/common_wl.test.php b/_test/tests/inc/common_wl.test.php index 2e34dcae3..4bfde3f39 100644 --- a/_test/tests/inc/common_wl.test.php +++ b/_test/tests/inc/common_wl.test.php @@ -142,6 +142,17 @@ class common_wl_test extends DokuWikiTest { $expect = DOKU_BASE . DOKU_SCRIPT . '/some/one?a=b&c=d'; $this->assertEquals($expect, wl('some:one', 'a=b,c=d', false, '&')); } + + function test_wl_empty_rev() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 0; + + $args = array('a' => 'b', 'c' => 'd', 'rev' => ''); + + $expect = DOKU_BASE . DOKU_SCRIPT . '?id=some:&a=b&c=d'; + $this->assertEquals($expect, wl('some:', $args)); + } -- cgit v1.2.3 From 1c8a8d7b204705f17b35bc64d62981204405e372 Mon Sep 17 00:00:00 2001 From: lisps Date: Mon, 25 Nov 2013 13:45:01 +0100 Subject: change behavior only on date_at --- inc/parserutils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/parserutils.php b/inc/parserutils.php index ecb1ac888..b97fb5d00 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -67,7 +67,7 @@ function p_wiki_xhtml($id, $rev='', $excuse=true,$date_at=''){ if($rev || $date_at){ if(@file_exists($file)){ - $ret = p_render('xhtml',p_get_instructions(io_readWikiPage($file,$id,$rev)),$info,max($rev,$date_at)); //no caching on old revisions + $ret = p_render('xhtml',p_get_instructions(io_readWikiPage($file,$id,$rev)),$info,$date_at); //no caching on old revisions }elseif($excuse){ $ret = p_locale_xhtml('norev'); } -- cgit v1.2.3 From df0e21b4abb118b585b79ac5546ef4bd9c3b8229 Mon Sep 17 00:00:00 2001 From: lisps Date: Mon, 17 Feb 2014 23:26:54 +0100 Subject: fix last merge --- inc/parser/xhtml.php | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 1cf1acc32..0d5881aa0 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -1272,6 +1272,95 @@ class Doku_Renderer_xhtml extends Doku_Renderer { return $link; } + + + /** + * Embed video(s) in HTML + * + * @author Anika Henke + * + * @param string $src - ID of video to embed + * @param int $width - width of the video in pixels + * @param int $height - height of the video in pixels + * @param array $atts - additional attributes for the