IncludePageAction


This is a little action I made for including a page in another page, for example, a navigation bar. This is very useful if you want the same thing to appear on many different pages, but you don't want to have to edit each page every time you want to change something.

Syntax:

{{incpage page="PageName"}}


Save the following script as actions/incpage.php

-- Jamie

Hi Jamie. Thank you for the contribution, however it appears that your action duplicates an action that is already in Wikka version 1.1.4.0 and above. You can see the code for the standard Wikka 'include' action on the IncludeAction page. To avoid confusion, my preference is to remove this page. -- JsnX



<?php
if (!isset($vars['page'])) {
echo "No page specified.<br><br><strong>Syntax: {{incpage page=\"wikiname\"}}</strong>  (Case insensitive)";
}
else {
$url = $vars['page'];
$host = $this->config['mysql_host'];
$db = $this->config['mysql_database'];
$user = $this->config['mysql_user'];
$passwd = $this->config['mysql_password'];
$connection = @mysql_connect($host, $user, $passwd);
@mysql_select_db($db, $connection);
$sql = "select body from" . $this->config['table_prefix'] . " pages where tag=\"$url\" and latest=\"Y\"";
$query = mysql_query($sql, $connection);
while ($nav = mysql_fetch_array($query)) {
$body = $nav['body'];
break;
}
$body = $this->Format($body, "wakka");
echo $body;
}
?>



I wasn't sure where to put this question, forgive me if I am breaking Wiki-netiquette. I thought perhaps instead of deleting this page, someone could help me with a small upgrade to the IncludeAction. See, I am attempting to use WikkaWiki as a PIM and have been playing with some of the contributions on the GmBowenWikkaAsPIM page. One thing I want to do however is to have a page that lists my current projects which themselves are each Wiki Pages. Each of these Wiki Pages start out with a To Do list at the top. What I want is for the Project list page to have "includes" that pull "x" number of lines from the specified Wiki Page instead of the whole thing as the include Action currently does.

I'm pretty brain dead in this explanation so here is a screenshot that should explain what I mean better. Notice the automatic line numbering.
PimInclude Example

Here's my include.php hack at this point. (Be gentle. I'm not a programmer, nor familiar with PHP). It takes "page", as before, and now also "numlines" which is pretty self explanatory.

<?php

if (is_array($vars))
{
    foreach ($vars as $param => $value)
    {
        if ($param == 'page') {
            $page=$this->htmlspecialchars_ent($vars['page']);
            $page = strtolower($page);
        }
        if ($param == 'numlines') {
            $numlines=$this->htmlspecialchars_ent($vars['numlines']);
        }
    }
}

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);
       
        if (!$numlines) {
            print $this->Format($page["body"]);
        }
        else {
            $newtext = $this->Format($page["body"]);
            $newtext = explode ("\n", $newtext);
            $i = 0;
            while ($i <= $numlines-1) {
                print ($i+1).") ".$newtext[$i]."\n";
                $i++;
            }          
        }
    }
} else print "<span class='error'>Circular reference detected</span>";

?>


There are little quirks that I'd like help fixing. Such as that styles get messed up if you have indentations on your to do list items. Also things obviously get a little wierd if one of your To Do list items it a subproject page with an include call to to do list items it contains. I'd like it to be able to handle this though. I think this is one thing that could make Wikka pretty capable of being a hipster GTD solution. ;)


CategoryDevelopmentActions
Comments
Comment by ChristianBarthelemy
2004-11-24 19:45:09
How does it differ/compare to {{include}} standard action?
Comment by JavaWoman
2004-11-25 18:38:21
I agree with JsnX that it's probably better to remove this page (something that shouldn't be done lightly). However, the existence of this page does nicely illustrate the importance of good, 'browsable' user documentation which would/should have made it obvious that an action like {{include}} already exists.
Thanks to Jamie not only for going to the effort of writing an action, but also for making this documentation need so clear!

(On my action list to make such documentation "automatically" available.)
Comment by 81.169.127.6
2004-12-29 13:10:29
you can add comments
Comment by IanHayhurst
2005-02-16 10:52:20
Interestingly I was using Jamie's action (I work with a Derek Scuffell so that's how come) We were using it to include navigation in the top and bottom of a long page, The alternative ""{{include page="wibblePage"}}"" detects a circular reference and can't be used inthat way without alteration ;-) Ian
Comment by JavaWoman
2005-02-17 08:03:48
Ian,
It would probably be better to edit header.php and footer.php for that purpose (if possible); they are actually templates rather than actions!
Your usage does suggest that it would be good to have some sort of templating system.
Comment by IanHayhurst
2005-02-17 09:11:38
JavaWoman, Done that ... at least on the header for site nav and a few corporate intranet 'required links' (though thanks for the suggestion) the sort of Navigation I was using was slightly subordinate to the whole wikki more key pages in a category (where listing the whole category content is not helpful... or indeed controlable). so the included page was just:-
WikiWord :: AnotherWikiWord :: MoreWikiWords :: SomethingElse :: GoHereToo
Cheers Ian
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki