summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/changelog.php20
-rw-r--r--inc/common.php2
-rw-r--r--inc/html.php5
-rw-r--r--inc/lang/en/lang.php1
-rw-r--r--inc/pageutils.php37
-rw-r--r--inc/parser/xhtml.php31
-rw-r--r--inc/parserutils.php12
-rw-r--r--inc/template.php5
8 files changed, 90 insertions, 23 deletions
diff --git a/inc/changelog.php b/inc/changelog.php
index de06c9683..84ee39b9a 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -827,6 +827,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;
+ }
+ }
/**
* Returns the next lines of the changelog of the chunck before head or after tail
@@ -1049,3 +1068,4 @@ function getRevisions($id, $first, $num, $chunk_size = 8192, $media = false) {
}
return $changelog->getRevisions($first, $num);
}
+
diff --git a/inc/common.php b/inc/common.php
index 110b91417..0b15c284d 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -394,6 +394,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);
@@ -494,6 +495,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/html.php b/inc/html.php
index 57a22b880..3f6cd640f 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -222,6 +222,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;
@@ -241,8 +242,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);
diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php
index 592289185..278be82cd 100644
--- a/inc/lang/en/lang.php
+++ b/inc/lang/en/lang.php
@@ -366,4 +366,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 :
diff --git a/inc/pageutils.php b/inc/pageutils.php
index 8474c5697..d5d33e76f 100644
--- a/inc/pageutils.php
+++ b/inc/pageutils.php
@@ -233,7 +233,13 @@ function sectionID($title,&$check) {
*
* @author Chris Smith <chris@jalakai.co.uk>
*/
-function page_exists($id,$rev='',$clean=true) {
+function page_exists($id,$rev='',$clean=true, $data_at=false) {
+ if($rev !== '' && $date_at) {
+ $pagelog = new PageChangeLog($page);
+ $pagelog_rev = $pagelog->getLastRevisionAt($rev);
+ if($pagelog_rev !== false)
+ $rev = $pagelog_rev;
+ }
return @file_exists(wikiFN($id,$rev,$clean));
}
@@ -436,9 +442,16 @@ function resolve_id($ns,$id,$clean=true){
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
-function resolve_mediaid($ns,&$page,&$exists){
+function resolve_mediaid($ns,&$page,&$exists,$rev='',$date_at=false){
+ if($rev !== '' && $date_at){
+ $medialog = new MediaChangeLog($media_id);
+ $medialog_rev = $medialog->getLastRevisionAt($rev);
+ if($medialog_rev !== false) {
+ $rev = $medialog_rev;
+ }
+ }
$page = resolve_id($ns,$page);
- $file = mediaFN($page);
+ $file = mediaFN($page,$rev);
$exists = @file_exists($file);
}
@@ -447,7 +460,7 @@ function resolve_mediaid($ns,&$page,&$exists){
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
-function resolve_pageid($ns,&$page,&$exists){
+function resolve_pageid($ns,&$page,&$exists,$rev='',$date_at=false ){
global $conf;
global $ID;
$exists = false;
@@ -467,20 +480,26 @@ function resolve_pageid($ns,&$page,&$exists){
$page = resolve_id($ns,$page,false); // resolve but don't clean, yet
// get filename (calls clean itself)
- $file = wikiFN($page);
+ if($rev !== '' && $date_at) {
+ $pagelog = new PageChangeLog($page);
+ $pagelog_rev = $pagelog->getLastRevisionAt($rev);
+ if($pagelog_rev !== false)//something found
+ $rev = $pagelog_rev;
+ }
+ $file = wikiFN($page,$rev);
// if ends with colon or slash we have a namespace link
if(in_array(substr($page,-1), array(':', ';')) ||
($conf['useslash'] && substr($page,-1) == '/')){
- if(page_exists($page.$conf['start'])){
+ if(page_exists($page.$conf['start'],$rev,true,$date_at)){
// start page inside namespace
$page = $page.$conf['start'];
$exists = true;
- }elseif(page_exists($page.noNS(cleanID($page)))){
+ }elseif(page_exists($page.noNS(cleanID($page)),$rev,true,$date_at)){
// page named like the NS inside the NS
$page = $page.noNS(cleanID($page));
$exists = true;
- }elseif(page_exists($page)){
+ }elseif(page_exists($page,$rev,true,$date_at)){
// page like namespace exists
$page = $page;
$exists = true;
@@ -497,7 +516,7 @@ function resolve_pageid($ns,&$page,&$exists){
}else{
$try = $page.'s';
}
- if(page_exists($try)){
+ if(page_exists($try,$rev,true,$date_at)){
$page = $try;
$exists = true;
}
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index e3f9a4187..dee3c922d 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -25,6 +25,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 $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
@@ -591,7 +592,7 @@ 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);
$name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype);
if ( !$isImage ) {
@@ -621,6 +622,9 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
}
$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;
@@ -796,7 +800,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$height=null, $cache=null, $linking=null, $return=NULL) {
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;
@@ -804,7 +808,7 @@ 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'));
+ $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;
@@ -812,7 +816,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))).')';
}
@@ -1090,7 +1094,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) {
@@ -1221,7 +1225,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
// see internalmedia() and externalmedia()
list($img['src'],$hash) = 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($img['src'],
@@ -1350,6 +1354,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);
+ }
}
diff --git a/inc/parserutils.php b/inc/parserutils.php
index 06bd6dbb8..e2811b081 100644
--- a/inc/parserutils.php
+++ b/inc/parserutils.php
@@ -56,7 +56,7 @@ define('METADATA_RENDER_UNLIMITED', 4);
*
* @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 = '';
@@ -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,$date_at); //no caching on old revisions
}elseif($excuse){
$ret = p_locale_xhtml('norev');
}
@@ -584,7 +584,7 @@ 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,$date_at=''){
if(is_null($instructions)) return '';
$Renderer = p_get_renderer($mode);
@@ -592,6 +592,10 @@ function p_render($mode,$instructions,&$info){
$Renderer->reset();
+ 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 8bd3234cc..2cb6d3da8 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -1124,6 +1124,7 @@ function tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) {
global $IMG;
/** @var Input $INPUT */
global $INPUT;
+ global $REV;
$w = tpl_img_getTag('File.Width');
$h = tpl_img_getTag('File.Height');
@@ -1148,8 +1149,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');