Skip to content

Commit

Permalink
add parameter at($DATE_AT) and mind revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
lisps committed Nov 21, 2013
1 parent ee33e0c commit 5c2eed9
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 16 deletions.
15 changes: 14 additions & 1 deletion doku.php
Expand Up @@ -34,6 +34,7 @@
$ID = getID();

$REV = $INPUT->int('rev');
$DATE_AT= $INPUT->int('at');
$IDX = $INPUT->str('idx');
$DATE = $INPUT->int('date');
$RANGE = $INPUT->str('range');
Expand All @@ -47,7 +48,19 @@
$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
Expand Down
23 changes: 23 additions & 0 deletions inc/changelog.php
Expand Up @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion inc/common.php
Expand Up @@ -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 = '';
Expand Down
5 changes: 3 additions & 2 deletions inc/html.php
Expand Up @@ -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;
Expand All @@ -226,8 +227,8 @@ function html_show($txt=null){
echo '</div></div>';

}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);
Expand Down
44 changes: 40 additions & 4 deletions inc/parser/xhtml.php
Expand Up @@ -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
Expand Down Expand Up @@ -618,6 +620,11 @@ function internallink($id, $name = null, $search=null,$returnonly=false,$linktyp
}
$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;
Expand Down Expand Up @@ -792,15 +799,23 @@ function internalmedia ($src, $title=null, $align=null, $width=null,

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;
}else{
// 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))).')';
}

Expand Down Expand Up @@ -1048,7 +1063,7 @@ function _media ($src, $title=null, $align=null, $width=null,
$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
Expand All @@ -1073,7 +1088,11 @@ function _media ($src, $title=null, $align=null, $width=null,
return $title;
}
//add image tag
$ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"';
if($intern && ($this->rev||$this->date_at)) {
$ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache,'rev'=>$this->_getProperMediaRevision($src))).'"';
} else {
$ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"';
}
$ret .= ' class="media'.$align.'"';

if ($title) {
Expand Down Expand Up @@ -1221,6 +1240,23 @@ function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $rende

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);
}


}
Expand Down
15 changes: 11 additions & 4 deletions inc/parserutils.php
Expand Up @@ -56,7 +56,7 @@
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function p_wiki_xhtml($id, $rev='', $excuse=true){
function p_wiki_xhtml($id, $rev='', $excuse=true,$date_at=''){
$file = wikiFN($id,$rev);
$ret = '';

Expand All @@ -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');
}
Expand Down Expand Up @@ -583,14 +583,21 @@ function p_sort_modes($a, $b){
* @author Harry Fuecks <hfuecks@gmail.com>
* @author Andreas Gohr <andi@splitbrain.org>
*/
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);
if (is_null($Renderer)) return null;

$Renderer->reset();

if($rev) {
$Renderer->rev = $rev;
}
if($date_at) {
$Renderer->date_at = $date_at;
}

$Renderer->smileys = getSmileys();
$Renderer->entities = getEntities();
$Renderer->acronyms = getAcronyms();
Expand Down
5 changes: 3 additions & 2 deletions inc/template.php
Expand Up @@ -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');

Expand All @@ -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');
Expand Down
5 changes: 4 additions & 1 deletion lib/exe/detail.php
Expand Up @@ -5,6 +5,9 @@

$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
Expand Down Expand Up @@ -35,7 +38,7 @@
$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);
Expand Down
2 changes: 1 addition & 1 deletion lib/tpl/dokuwiki/detail.php
Expand Up @@ -49,7 +49,7 @@
if($ERROR):
echo '<h1>'.$ERROR.'</h1>';
else: ?>

<?php if($REV) echo p_locale_xhtml('showrev');?>
<h1><?php echo nl2br(hsc(tpl_img_getTag('simple.title'))); ?></h1>

<?php tpl_img(900,700); /* parameters: maximum width, maximum height (and more) */ ?>
Expand Down

0 comments on commit 5c2eed9

Please sign in to comment.