Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revision support #131

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conf/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
$conf['order'] = 'id'; // order in which the pages are included in the case of multiple pages
$conf['rsort'] = 0; // reverse sort order
$conf['depth'] = 1; // maximum depth of namespace includes, 0 for unlimited depth
$conf['revision'] = 0; // show included pages with respect to revision
//Setup VIM: ex: et ts=2 :
1 change: 1 addition & 0 deletions conf/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
$meta['order'] = array('multichoice', '_choices' => array('id', 'title', 'created', 'modified', 'indexmenu', 'custom'));
$meta['rsort'] = array('onoff');
$meta['depth'] = array('numeric', '_min' => 0);
$meta['revision'] = array('onoff');
//Setup VIM: ex: et ts=2 :
96 changes: 67 additions & 29 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function helper_plugin_include() {
$this->defaults['order'] = $this->getConf('order');
$this->defaults['rsort'] = $this->getConf('rsort');
$this->defaults['depth'] = $this->getConf('depth');
$this->defaults['revision'] = $this->getConf('revision');
}

/**
Expand All @@ -68,6 +69,8 @@ function getMethods() {
* Overrides standard values for showfooter and firstseconly settings
*/
function get_flags($setflags) {
global $REV;
global $DATE_AT;
// load defaults
$flags = $this->defaults;
foreach ($setflags as $flag) {
Expand Down Expand Up @@ -219,6 +222,12 @@ function get_flags($setflags) {
// the include_content URL parameter overrides flags
if (isset($_REQUEST['include_content']))
$flags['linkonly'] = 0;

//we have to disable some functions
if (($flags['revision'] && $REV) || $DATE_AT) {
$flags['editbtn'] = 0;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't needed as the edit buttons below the included page are also using the section edit button functionality of DokuWiki which is automatically disabled by DokuWiki when an old revision is rendered.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is true when you don't use the $DATE_AT functionality (which is only implemented in my revision branch).

But there you need this when you want to see the page at a state after the page was saved and before eventually some media has changed. Because then $REV will be set to '' (current) and only $DATE_AT is set.

return $flags;
}

Expand All @@ -237,9 +246,12 @@ function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $
global $ID;
$root_id = $ID;
}

$page_rev = '';
if(in_array($mode,array('page','section'))) {
$page_rev = $this->_get_revision($page,$flags);
}
if ($flags['linkonly']) {
if (page_exists($page) || $flags['pageexists'] == 0) {
if (page_exists($page,$page_rev) || $flags['pageexists'] == 0) {
$title = '';
if ($flags['title'])
$title = p_get_first_heading($page);
Expand All @@ -256,17 +268,22 @@ function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $
$ins = array();
}
} else {
if (page_exists($page)) {
if (page_exists($page,$page_rev)) {
global $ID;
$backupID = $ID;
$ID = $page; // Change the global $ID as otherwise plugins like the discussion plugin will save data for the wrong page
$ins = p_cached_instructions(wikiFN($page), false, $page);
if($page_rev){
$ins = p_get_instructions(io_readWikiPage(wikiFN($page,$page_rev),$page,$page_rev));
} else {
$ins = p_cached_instructions(wikiFN($page), false, $page);
}

$ID = $backupID;
} else {
$ins = array();
}

$this->_convert_instructions($ins, $lvl, $page, $sect, $flags, $root_id, $included_pages);
$this->_convert_instructions($ins, $lvl, $page, $sect, $flags, $root_id, $included_pages, $page_rev);
}
return $ins;
}
Expand All @@ -284,7 +301,7 @@ function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $
*
* @author Michael Klier <[email protected]>
*/
function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $included_pages = array()) {
function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $included_pages = array(), $page_rev = '') {
global $conf;

// filter instructions if needed
Expand Down Expand Up @@ -512,7 +529,7 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc

// add footer
if($flags['footer']) {
$ins[] = $this->_footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id);
$ins[] = $this->_footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id, $page_rev);
}

// wrap content at the beginning of the include that is not in a section in a section
Expand Down Expand Up @@ -552,10 +569,10 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc
*
* @author Michael Klier <[email protected]>
*/
function _footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id) {
function _footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id, $page_rev) {
$footer = array();
$footer[0] = 'plugin';
$footer[1] = array('include_footer', array($page, $sect, $sect_title, $flags, $root_id, $footer_lvl));
$footer[1] = array('include_footer', array($page, $sect, $sect_title, $flags, $root_id, $footer_lvl, $page_rev));
return $footer;
}

Expand Down Expand Up @@ -661,6 +678,8 @@ function _get_firstsec(&$ins, $page) {
*/
function _get_included_pages($mode, $page, $sect, $parent_id, $flags) {
global $conf;
global $REV;
global $DATE_AT;
$pages = array();
switch($mode) {
case 'namespace':
Expand Down Expand Up @@ -691,7 +710,7 @@ function _get_included_pages($mode, $page, $sect, $parent_id, $flags) {
}
break;
default:
$page = $this->_apply_macro($page);
$page = $this->_apply_macro($page,$flags);
resolve_pageid(getNS($parent_id), $page, $exists); // resolve shortcuts and clean ID
if (auth_quickaclcheck($page) >= AUTH_READ)
$pages[] = $page;
Expand Down Expand Up @@ -743,7 +762,8 @@ function _get_included_pages($mode, $page, $sect, $parent_id, $flags) {

$result = array();
foreach ($pages as $page) {
$exists = page_exists($page);
$page_rev = $this->_get_revision($page,$flags);
$exists = page_exists($page,$page_rev);
$result[] = array('id' => $page, 'exists' => $exists, 'parent_id' => $parent_id);
}
return $result;
Expand Down Expand Up @@ -784,7 +804,7 @@ function _get_included_pages_from_meta_instructions($instructions) {
/**
* Makes user or date dependent includes possible
*/
function _apply_macro($id) {
function _apply_macro($id,$flags) {
global $INFO;
global $auth;

Expand All @@ -794,32 +814,36 @@ function _apply_macro($id) {
$user = $_SERVER['REMOTE_USER'];
$group = $INFO['userinfo']['grps'][0];

$time_stamp = time();
if(($flags['revision'] && $REV) || $DATE_AT) {
$time_stamp = max($REV,$DATE_AT);
} else {
$time_stamp = time();
}
if(preg_match('/@DATE(\w+)@/',$id,$matches)) {
switch($matches[1]) {
case 'PMONTH':
$time_stamp = strtotime("-1 month");
$time_stamp = strtotime("-1 month",$time_stamp);
break;
case 'NMONTH':
$time_stamp = strtotime("+1 month");
$time_stamp = strtotime("+1 month",$time_stamp);
break;
case 'NWEEK':
$time_stamp = strtotime("+1 week");
$time_stamp = strtotime("+1 week",$time_stamp);
break;
case 'PWEEK':
$time_stamp = strtotime("-1 week");
$time_stamp = strtotime("-1 week",$time_stamp);
break;
case 'TOMORROW':
$time_stamp = strtotime("+1 day");
$time_stamp = strtotime("+1 day",$time_stamp);
break;
case 'YESTERDAY':
$time_stamp = strtotime("-1 day");
$time_stamp = strtotime("-1 day",$time_stamp);
break;
case 'NYEAR':
$time_stamp = strtotime("+1 year");
$time_stamp = strtotime("+1 year",$time_stamp);
break;
case 'PYEAR':
$time_stamp = strtotime("-1 year");
$time_stamp = strtotime("-1 year",$time_stamp);
break;
}
$id = preg_replace('/@DATE(\w+)@/','', $id);
Expand All @@ -833,16 +857,30 @@ function _apply_macro($id) {
'@MONTH@' => date('m',$time_stamp),
'@WEEK@' => date('W',$time_stamp),
'@DAY@' => date('d',$time_stamp),
'@YEARPMONTH@' => date('Ym',strtotime("-1 month")),
'@PMONTH@' => date('m',strtotime("-1 month")),
'@NMONTH@' => date('m',strtotime("+1 month")),
'@YEARNMONTH@' => date('Ym',strtotime("+1 month")),
'@YEARPWEEK@' => date('YW',strtotime("-1 week")),
'@PWEEK@' => date('W',strtotime("-1 week")),
'@NWEEK@' => date('W',strtotime("+1 week")),
'@YEARNWEEK@' => date('YW',strtotime("+1 week")),
'@YEARPMONTH@' => date('Ym',strtotime("-1 month",$time_stamp)),
'@PMONTH@' => date('m',strtotime("-1 month",$time_stamp)),
'@NMONTH@' => date('m',strtotime("+1 month",$time_stamp)),
'@YEARNMONTH@' => date('Ym',strtotime("+1 month",$time_stamp)),
'@YEARPWEEK@' => date('YW',strtotime("-1 week",$time_stamp)),
'@PWEEK@' => date('W',strtotime("-1 week",$time_stamp)),
'@NWEEK@' => date('W',strtotime("+1 week",$time_stamp)),
'@YEARNWEEK@' => date('YW',strtotime("+1 week",$time_stamp)),
);
return str_replace(array_keys($replace), array_values($replace), $id);
}

function _get_revision($page,$flags) {
global $DATE_AT;
global $REV;
$page_rev = '';
if($DATE_AT) {
$pagelog = new PageChangeLog($page);
$page_rev = $pagelog->getLastRevisionAt($DATE_AT);
} else if($flags['revision'] && $REV) {
$pagelog = new PageChangeLog($page);
$page_rev = $pagelog->getLastRevisionAt($REV);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works only with the revisions branch but not with the current master or stable branch. The include plugin should at least support the latest two stable releases.

return $page_rev;
}
}
// vim:ts=4:sw=4:et:
10 changes: 5 additions & 5 deletions syntax/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ function handle($match, $state, $pos, Doku_Handler &$handler) {
*/
function render($mode, Doku_Renderer &$renderer, $data) {

list($page, $sect, $sect_title, $flags, $redirect_id, $footer_lvl) = $data;
list($page, $sect, $sect_title, $flags, $redirect_id, $footer_lvl, $page_rev) = $data;

if ($mode == 'xhtml') {
$renderer->doc .= $this->html_footer($page, $sect, $sect_title, $flags, $footer_lvl, $renderer);
$renderer->doc .= $this->html_footer($page, $sect, $sect_title, $flags, $footer_lvl, $page_rev, $renderer);
return true;
}
return false;
Expand All @@ -46,7 +46,7 @@ function render($mode, Doku_Renderer &$renderer, $data) {
/**
* Returns the meta line below the included page
*/
function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) {
function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, $page_rev, &$renderer) {
global $conf, $ID;

if(!$flags['footer']) return '';
Expand All @@ -57,7 +57,7 @@ function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer)
// permalink
if ($flags['permalink']) {
$class = ($exists ? 'wikilink1' : 'wikilink2');
$url = ($sect) ? wl($page) . '#' . $sect : wl($page);
$url = ($sect) ? wl($page,array('rev'=>$page_rev)) . '#' . $sect : wl($page,array('rev'=>$page_rev));
$name = ($sect) ? $sect_title : $page;
$title = ($sect) ? $page . '#' . $sect : $page;
if (!$title) $title = str_replace('_', ' ', noNS($page));
Expand All @@ -84,7 +84,7 @@ function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer)

// modified date
if ($flags['mdate'] && $exists) {
$mdate = $meta['date']['modified'];
$mdate = $page_rev ? $page_rev : $meta['date']['modified'];
if ($mdate) {
$xhtml[] = '<abbr class="published" title="'.strftime('%Y-%m-%dT%H:%M:%SZ', $mdate).'">'
. strftime($conf['dformat'], $mdate)
Expand Down