diff --git a/conf/default.php b/conf/default.php index c619005..1d77479 100644 --- a/conf/default.php +++ b/conf/default.php @@ -27,4 +27,5 @@ $conf['depth'] = 1; // maximum depth of namespace includes, 0 for unlimited depth $conf['readmore'] = 1; // Show readmore link in case of firstsection only $conf['debugoutput'] = 0; // print debug information to debuglog if global allowdebug is enabled +$conf['honourmainrevision'] = 0; //Setup VIM: ex: et ts=2 : diff --git a/conf/metadata.php b/conf/metadata.php index a0fa7b1..a967f98 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -30,4 +30,5 @@ $meta['depth'] = array('numeric', '_min' => 0); $meta['readmore'] = array('onoff'); $meta['debugoutput'] = array('onoff'); +$meta['honourmainrevision'] = array('onoff'); //Setup VIM: ex: et ts=2 : diff --git a/helper.php b/helper.php index 9d2f8a8..1ccb1bb 100644 --- a/helper.php +++ b/helper.php @@ -238,7 +238,7 @@ function get_flags($setflags) { * @author Michael Klier * @author Michael Hamann */ - function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $included_pages = array()) { + function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $included_pages = array(), $wanted_revision = null) { $key = ($sect) ? $page . '#' . $sect : $page; $this->includes[$key] = true; // legacy code for keeping compatibility with other plugins @@ -270,7 +270,13 @@ function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $ 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 (!is_null($wanted_revision)) { + $ins = p_cached_instructions(wikiFN($page, $wanted_revision), false, $page); + } else { + $ins = p_cached_instructions(wikiFN($page), false, $page); + } $ID = $backupID; } else { $ins = array(); diff --git a/lang/en/settings.php b/lang/en/settings.php index 8aec307..c5a19b1 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -38,4 +38,5 @@ $lang['depth'] = 'Maximum depth of namespace includes, 0 for unlimited depth'; $lang['readmore'] = 'Show or not the \'Read More\' link in case of firstsection only'; $lang['debugoutput'] = 'Print verbose debug information to the dokuwiki debuglog if the global "allowdebug" option is enabled'; +$lang['honourmainrevision'] = 'Honour the main page revision. If a revision of the main page is shown, pass this revision date to include pages and get the appropriate revision of those pages as well'; //Setup VIM: ex: et ts=2 : diff --git a/syntax/include.php b/syntax/include.php index 1fd68c8..88051cd 100644 --- a/syntax/include.php +++ b/syntax/include.php @@ -128,6 +128,8 @@ function render($format, Doku_Renderer $renderer, $data) { $secids = p_get_metadata($ID, 'plugin_include secids'); } + + foreach ($pages as $page) { extract($page); $id = $page['id']; @@ -136,6 +138,55 @@ function render($format, Doku_Renderer $renderer, $data) { if (in_array($id, $page_stack)) continue; array_push($page_stack, $id); + // check if the include plugin should honour the main page revision + if ($this->getConf('honourmainrevision')) { + + // initialize variables with empty string + $wanted_revision = ''; + $revision_before_main_revision = ''; + $first_revision = ''; + + $m = p_get_metadata($id); // get metadata for current page + $sum = $m['last_change']['sum']; // get last change summary + global $REV; // load global $REV variable + + $changelog = new PageChangeLog($id); // initiate changelog + $chs = $changelog->getRevisions(0, 10000); // load changes list + + + if (intval($REV) > 0) { // check if a revision is shown for the main page, otherwise simply get last revision of all included pages + + foreach ($chs as $rev) { + $ch = $changelog->getRevisionInfo($rev); + if (intval($rev) <= intval($REV)) { + // a revision lower than the main page revision is found + if ($revision_before_main_revision == '') { + $revision_before_main_revision = $rev; + } + + // check for approved in summary (works only if approval plugin is enabled) + if ($ch['sum'] == "APPROVED") { + // revision found before the $REV date with APPROVAL in summary + $wanted_revision = $rev; + break; + } + } + $first_revision = $rev; + } + + if ($wanted_revision == '') { // no suitable revision found with approval + if ($revision_before_main_revision != '') { // a revision is found before $REV, use this revision + $wanted_revision = $revision_before_main_revision; + } else { // simply use the oldest revision of the included page, despite the revision date is newer than the main page revision date + $wanted_revision = $first_revision; + } + } + } + } else { + $wanted_revision = null; + } + + // add references for backlink if ($format == 'metadata') { $renderer->meta['relation']['references'][$id] = $exists; @@ -151,7 +202,11 @@ function render($format, Doku_Renderer $renderer, $data) { unset($flags['include_secid']); } - $instructions = $this->helper->_get_instructions($id, $sect, $mode, $level, $flags, $root_id, $secids); + // add configuration option to honour top page revision or not + // if (not configuration_option_honour_revision) { + // $wanted_revision = null; + // } + $instructions = $this->helper->_get_instructions($id, $sect, $mode, $level, $flags, $root_id, $secids, $wanted_revision); if (!$flags['editbtn']) { global $conf;