Include other pages
The following action includes another wikipage and takes care not to be trapped in a circular reference, i.e. included pages can include other pages without running into trouble.actions/include.php
<?php
if (!$page) $page = $wikka_vars;
$page = strtolower($page);
if (!$this->config["includes"]) $this->config["includes"][] = strtolower($this->tag);
if (!in_array($page, $this->config["includes"]) && $page != $this->tag) {
if ($this->HasAccess("read", $page)) {
$this->config["includes"][] = $page;
$page = $this->LoadPage($page);
print $this->Format($page["body"]);
}
} else print "<span class='error'>Circular reference detected</span>";
?>
if (!$page) $page = $wikka_vars;
$page = strtolower($page);
if (!$this->config["includes"]) $this->config["includes"][] = strtolower($this->tag);
if (!in_array($page, $this->config["includes"]) && $page != $this->tag) {
if ($this->HasAccess("read", $page)) {
$this->config["includes"][] = $page;
$page = $this->LoadPage($page);
print $this->Format($page["body"]);
}
} else print "<span class='error'>Circular reference detected</span>";
?>
Thanks, Sebastian. Seems this could be useful. Look for it in the next release, 1.1.4.0. And it's live right now. - JsnX
To use: {{include page="PageName"}} or {{include PageName}}
Fix for case sensitive/insensitive locales
I modified the code so it doesn't break on case sensitive database locales. In cases where there really is a circular reference, this code does two DB queries more than the original to find out the correct case of the included page. Since this shouldn't really happen in the normal case, I don't think that it's an issue.<?php
if (!$page) $page = $wikka_vars;
if (!$this->config["includes"]) $this->config["includes"][] = $this->tag;
if ($this->HasAccess("read", $page)) {
$page = $this->LoadPage($page);
if (!in_array($page["tag"], $this->config["includes"]) && $page["tag"] != $this->tag) {
$this->config["includes"][] = $page["tag"];
print $this->Format($page["body"]);
} else print "<span class='error'>Circular reference detected</span>";
}
?>
if (!$page) $page = $wikka_vars;
if (!$this->config["includes"]) $this->config["includes"][] = $this->tag;
if ($this->HasAccess("read", $page)) {
$page = $this->LoadPage($page);
if (!in_array($page["tag"], $this->config["includes"]) && $page["tag"] != $this->tag) {
$this->config["includes"][] = $page["tag"];
print $this->Format($page["body"]);
} else print "<span class='error'>Circular reference detected</span>";
}
?>
--CyneBeald
we really needed a way to sometimes include JUST the first line
of a page (not the whole page).
With and without formating,
This modification seem to do it.
Rob McCormack
<?php
if (!$page) $page = $wikka_vars;
// -------------------------------------------------------//
// Mod by kroniks.com
// New include type of PageLineOne
// In the system can include just one line from document
// Example:
// {{include pagelineone="SemesterOne"}}
// -------------------------------------------------------//
if(!empty($pagelineone)) { $page = $pagelineone; }
elseif(!empty($pagelineoneplaintext)) { $page = $pagelineoneplaintext; }
// END of mod by kroniks.com
$page = strtolower($page);
if (!$this->config["includes"]) $this->config["includes"][] = strtolower($this->tag);
// Mod by kroniks.com
// OLD source code if (!in_array($page, $this->config["includes"]) && $page != $this->tag) {
// New code with swith off checking twice use code
if ($page != $this->tag) {
// END of mod by kroniks.com
if ($this->HasAccess("read", $page)) {
$this->config["includes"][] = $page;
$page = $this->LoadPage($page);
// Mod by kroniks.com
if(!empty($pagelineone)) {
$page1 = split("\n", $page["body"]);
print $this->Format($page1[0]);
} elseif(!empty($pagelineoneplaintext)) {
$page1 = split("\n", $page["body"]);
print preg_replace("/[=]{2,}/","" , $page1[0]);
} else {
print $this->Format($page["body"]);
}
// END of mod by kroniks.com
}
} else print "<span class='error'>Circular reference detected</span>";
?>
I'm curious, what *is* the reason for first converting the page name to lowercase in the first place? It could be a potential vulnerability in some circumstances (trying to force a circular link using bad case in a case-insensitive database), but I'm not really convinced it can really abused that way. I'll probably rewrite/refactor this action, if nobody would mind.
I took the liberty of setting the target for this to 1.1.6.1 in the bug tracker (since I already have a fix for it ready, and it's a minor change), I hope you don't mind.
I saw the code on the tracker, thanks: I'll give it a try to see how it affects performance.