summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/changelog.php20
-rw-r--r--inc/common.php3
-rw-r--r--inc/html.php5
-rw-r--r--inc/lang/en/lang.php2
-rw-r--r--inc/pageutils.php38
-rw-r--r--inc/parser/xhtml.php41
-rw-r--r--inc/parserutils.php12
-rw-r--r--inc/template.php5
8 files changed, 98 insertions, 28 deletions
diff --git a/inc/changelog.php b/inc/changelog.php
index 8c14f21b0..6af336fc2 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -845,6 +845,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
@@ -1072,3 +1091,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 e56285f62..11b8a7e26 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -438,6 +438,8 @@ 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']);
+ if(isset($urlParameters['at']) && $conf['date_at_format']) $urlParameters['at'] = date($conf['date_at_format'],$urlParameters['at']);
$urlParameters = buildURLparams($urlParameters, $separator);
} else {
$urlParameters = str_replace(',', $separator, $urlParameters);
@@ -544,6 +546,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 a65fdfc31..495bdf919 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 3190b0e13..fb455f85f 100644
--- a/inc/lang/en/lang.php
+++ b/inc/lang/en/lang.php
@@ -368,4 +368,6 @@ $lang['currentns'] = 'Current namespace';
$lang['searchresult'] = 'Search Result';
$lang['plainhtml'] = 'Plain HTML';
$lang['wikimarkup'] = 'Wiki Markup';
+$lang['page_nonexist_rev'] = 'Page did not exist at %s. It was subsequently created at <a href="%s">%s</a>.';
+$lang['unable_to_parse_date'] = 'Unable to parse at parameter "%s".';
//Setup VIM: ex: et ts=2 :
diff --git a/inc/pageutils.php b/inc/pageutils.php
index 5f62926e4..49c00d36f 100644
--- a/inc/pageutils.php
+++ b/inc/pageutils.php
@@ -255,7 +255,13 @@ function sectionID($title,&$check) {
* @param bool $clean flag indicating that $id should be cleaned (see wikiFN as well)
* @return bool exists?
*/
-function page_exists($id,$rev='',$clean=true) {
+function page_exists($id,$rev='',$clean=true, $date_at=false) {
+ if($rev !== '' && $date_at) {
+ $pagelog = new PageChangeLog($id);
+ $pagelog_rev = $pagelog->getLastRevisionAt($rev);
+ if($pagelog_rev !== false)
+ $rev = $pagelog_rev;
+ }
return @file_exists(wikiFN($id,$rev,$clean));
}
@@ -486,9 +492,17 @@ function resolve_id($ns,$id,$clean=true){
* @param string &$page (reference) relative media id, updated to resolved id
* @param bool &$exists (reference) updated with existance of media
*/
-function resolve_mediaid($ns,&$page,&$exists){
+function resolve_mediaid($ns,&$page,&$exists,$rev='',$date_at=false){
$page = resolve_id($ns,$page);
- $file = mediaFN($page);
+ if($rev !== '' && $date_at){
+ $medialog = new MediaChangeLog($page);
+ $medialog_rev = $medialog->getLastRevisionAt($rev);
+ if($medialog_rev !== false) {
+ $rev = $medialog_rev;
+ }
+ }
+
+ $file = mediaFN($page,$rev);
$exists = @file_exists($file);
}
@@ -501,7 +515,7 @@ function resolve_mediaid($ns,&$page,&$exists){
* @param string &$page (reference) relative page id, updated to resolved id
* @param bool &$exists (reference) updated with existance of media
*/
-function resolve_pageid($ns,&$page,&$exists){
+function resolve_pageid($ns,&$page,&$exists,$rev='',$date_at=false ){
global $conf;
global $ID;
$exists = false;
@@ -521,20 +535,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;
@@ -551,7 +571,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 44ead9d45..5627a0353 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;
@@ -818,7 +819,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) {
@@ -846,11 +847,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;';
@@ -1062,7 +1066,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 +1074,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 +1082,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))).')';
}
@@ -1436,7 +1440,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) {
@@ -1581,7 +1585,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(
@@ -1740,6 +1744,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
}
diff --git a/inc/parserutils.php b/inc/parserutils.php
index 9c2a0b570..4aebec2c8 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');
}
@@ -583,7 +583,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);
@@ -591,6 +591,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 7f3c68534..2dd77502f 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -1123,6 +1123,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');
@@ -1147,8 +1148,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');