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

Added option to honour the main page revision when using included pages #217

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions conf/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
1 change: 1 addition & 0 deletions conf/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
10 changes: 8 additions & 2 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function get_flags($setflags) {
* @author Michael Klier <[email protected]>
* @author Michael Hamann <[email protected]>
*/
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

Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions lang/en/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
57 changes: 56 additions & 1 deletion syntax/include.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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')) {
Copy link
Member

Choose a reason for hiding this comment

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

This if statement could also directly check $REV (as all code below should be moved as explained there).


// initialize variables with empty string
$wanted_revision = '';
Copy link
Member

Choose a reason for hiding this comment

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

$wanted_revision should be initialized to null, outside this if statement.

$revision_before_main_revision = '';
$first_revision = '';
Comment on lines +146 to +147
Copy link
Member

Choose a reason for hiding this comment

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

These two variables are only used inside the if-statement and should thus be initialized there.


$m = p_get_metadata($id); // get metadata for current page
$sum = $m['last_change']['sum']; // get last change summary
Copy link
Member

Choose a reason for hiding this comment

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

These two lines seems to be unused.

global $REV; // load global $REV variable

$changelog = new PageChangeLog($id); // initiate changelog
$chs = $changelog->getRevisions(0, 10000); // load changes list
Comment on lines +153 to +154
Copy link
Member

Choose a reason for hiding this comment

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

Why this limit to 10000 revisions? Wouldn't it make more sense to load revisions dynamically in batches? I.e., use two nested loops below, where the outer loop gets revisions in batches of, e.g., 100 revisions and the inner loop then iterates over the current batch. Further, these two lines should be inside the if statement below. Otherwise, they are also executed when the current revision is used. Further, $changelog->getLastRevisionAt() could be used unless the approval plugin is installed, and even then there are functions for getting a number of revisions around that date.



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
Copy link
Member

Choose a reason for hiding this comment

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

If $wanted_revision is initialized to null, this needs to be adapted.

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;
Copy link
Member

Choose a reason for hiding this comment

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

If $wanted_revision is initialized to null, this line can be removed.

}


// add references for backlink
if ($format == 'metadata') {
$renderer->meta['relation']['references'][$id] = $exists;
Expand All @@ -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;
// }
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this comment as it has been addressed above.

$instructions = $this->helper->_get_instructions($id, $sect, $mode, $level, $flags, $root_id, $secids, $wanted_revision);

if (!$flags['editbtn']) {
global $conf;
Expand Down