-
Notifications
You must be signed in to change notification settings - Fork 54
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
base: master
Are you sure you want to change the base?
Changes from all commits
582870d
de49edd
8580e0d
a927595
0b3d433
0697c2d
d3694ac
8dee5a3
ad97b99
1feb293
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$revision_before_main_revision = ''; | ||
$first_revision = ''; | ||
Comment on lines
+146
to
+147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two variables are only used inside the |
||
|
||
$m = p_get_metadata($id); // get metadata for current page | ||
$sum = $m['last_change']['sum']; // get last change summary | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 (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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
} | ||
|
||
|
||
// 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; | ||
// } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
There was a problem hiding this comment.
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).