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>";
?>




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>"; 
}
?>

--CyneBeald
Comments
Comment by S0106001109760ad7.tb.shawcable.net
2005-11-16 01:52:03
For our wiki use as a program renewal, at a college,
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>";

?>
Comment by cynebeald.kosire.net
2005-11-23 16:19:05
In 1.1.6.0 I had to remove the second line, "$page = strtolower($page);" to make it work.
Comment by CyneBeald
2005-12-21 00:15:17
re: my last comment: that actually depends on what locale and collation is the default in the MySQL database. If you're using one of the *_cs sets, it won't work, if you're using *_ci then it's OK (we switched servers, that's how I found out).

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.
Comment by CyneBeald
2005-12-21 00:48:25
On second thought, I should probably start using the bug tracker... I submitted a ticket (http://wush.net/trac/wikka/ticket/60) but I'm not sure what to do now. Fix it myself, and post the code here, so everyone passing by notices it? Or post a fix to the bug tracker? Or wait for one of the devs to assign the bug to themselves?
Comment by DarTar
2005-12-21 13:21:08
At the moment there are several options: you can post a patch here and ask developers to commit it to the repository or ask for a SVN login. I agree, though, that we need some clear procedures for bugfixing and code change and I hope JavaWoman will help me write some basic guidelines for contributors ;)
Comment by CyneBeald
2005-12-21 14:34:33
Well, I don't think you should be giving SVN write acess too freely (I am, after all, still quite new here), so, could you please commit it to the repository for me? The fix is posted here on the page (and on the bug tracker too).

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.
Comment by DarTar
2005-12-21 15:20:21
Don't worry - we are not planning to give SVN access to anyone ;) moreover consider that we are still in a test phase with the repository (the official repository will probably be hosted in a subdomain at wikkawiki.org, once we have setup things properly).

I saw the code on the tracker, thanks: I'll give it a try to see how it affects performance.
Comment by MasinAlDujaili
2006-05-22 03:55:02
How about a simple [Edit] link next to the beginning of the included pages? I know, it would look a lot like WikiPedia, but it could be useful. Perhaps the action could be extended to evaluate a second parameter showlink="x" where x=0 means no link, x=1 means show link to page, x=2 means show edit link and x=3 means show both.
Comment by DarTar
2006-05-22 06:22:36
interesting suggestion, could you please open a ticket at http://tracker.wikkawiki.org ?
Comment by MasinAlDujaili
2006-05-22 06:49:27
Perhaps it should be mentioned that the ACL of the included page is considered, and users having no read permission don't see anything. Which, of course, is no bug as it's at least 100% correct. But it's not to be expected that it does it this way. I've been positively surprised :-)
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki