Wikitrail


Since one of my roommates was so kind to leave his laptop in Bologna, I was able to port the wikitrqail action from pmwiki to wikka.

Saved as actions/trail.php and used as {{trail list="YourListPage"}} in a page, the action provides a trail in the form:

<< previous page | trail-page | next page >>

"YourListPage" must contain a list of pages.

Could perhaps be usefull for documentations. Of course you have to use the action in every page, but if you work with a template it should not be that problem.

Two things are different compared to the action in pmwiki:

- if the list-page is a category, the trail will be composed of the pages belonging to the category (ordered alphabetically).

- the option to show a hierarchy of the page, based on the depth of the a bulleted list, is not included. It is more like a static breadcrump then a trail.

For the rest see the documentation.

Code

<?php
/**
 * Based on a list of pages, this action shows links to the previous and next page in the trail.
 *
 * Generell a trail like "<< previous page | trail-page | next page >>" is shown (previous/ next page and the
 * coresponding arrows are omitted if there is no such page).
 *
 * The trail-page a) should contain a list defining the trail of the pages (only works with entries like ~-WikiPage at
 * the monent!).
 *
 * Or the name of the trail-page b) starts with "Category". In this case, the trail is build from the ordered list of
 * pages belonging to the category.
 *
 * Syntax:
 * {{trail list="YourListPage"}}
 *
 * Credits:
 * This action has been portioned from {@link http://www.pmwiki.org pmwiki}. Note that the option
 * "The ^|TrailPage|^ markup uses the depth of the bullets to display the ancestry of the TrailPage to the
 * current one." has not been portioned because that option is more a form of static breadcrumb then a trail.
 * Thank goes to John Rankin who made the original suggestion for WikiTrails at pmwiki.
 *
 * @package   Action
 * @subpackage    Navigation
 * @name    Trail
 *
 * @author    Patrick R. Michaud (pmichaud@pobox.com) (original version for pmwiki)
 * @author    {@link http://wikka.jnsx.com/NilsLindenberg Nils Lindenberg} (ported to wikkawiki, additional code for categories)
 * @copyright    Copyright 2002-2004 Patrick R. Michaud (pmichaud@pobox.com)
 * @license    http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 *
 * @input    string $trailpage mandatory: a page with list of pages or a category
 * @output    links to the previous/next page in the trail and the trail-page itself
 *
 * @version    0.3
 *
 * @uses        CheckMySQLVersion()
 * @uses        FullCategoryTextSearch()
 * @uses        FullTextSearch()
 * @uses        GetPageTag()
 * @uses        Link()
 * @uses        LoadPage()
 * @todo   - the action uses code copied from the category-action, better change to a function
 *         - making a title for a trail possible
 *         - making class/seperator/signs customizable
 *         - making "round-way" possible, i.e. last page links to first-page
 *         - regexp-pattern for recognizing a Wikiword/Free-link
 *         - if [[WikiWord Other name]] the trail should show "other name" instead of the wikiword
 *         - parameter which forces the action to search for a list even on a category-page
 */


//setting the defaults
$thispage = $this->GetPageTag();
$nextpage = '';
$prevpage = '';
$seperator = '|';
$signleft = '&laquo;';
$signright = ' &raquo;';
$output = '';

//getting user-input
if (is_array($vars))
{
    foreach ($vars as $param => $value)
    {
            if ($param == 'list') {$list=htmlspecialchars($vars['list']);}
    }
}

if (isset($list))
{
    if ($trailpage=$this->LoadPage($list))
    {
        $pages = array();
        //if we have a category as a list-page, get the pages belonging to the category
        if (preg_match('/^Category/',$trailpage['tag']))
        {
            if ($this->CheckMySQLVersion(4,0,1))
            {
                $results = $this->FullCategoryTextSearch($trailpage['tag']);
            }
            else
            {
                $results = $this->FullTextSearch($trailpage['tag']);
            }
            foreach ($results as $cpage)
            {
                if (!preg_match('/^Category/', $cpage['tag']))
                {
                    $pages[] = $cpage['tag'];
                }
            }
            sort($pages);
        }
        else //search the page for a bulleted list containing Wikiwords
        {
            foreach(explode("\n",$trailpage['body']) as $x)
            {
                if (preg_match("/(~-|\\t-|~1\)|\\t1\)|~A\)|\\tA\)|~a\)|\\ta\)|~I\)|\\tI\)|~i\)|\\ti\))\\s?(\[\[)?([A-Za-z0-9ÄÖÜ]*)/",$x,$match))
                {
                    $pages[] = $match[3];
                }
            }
        }
        //search the list of pages for this page and make the trail
        for($i=0;$i<count($pages);$i++)
        {
            if (strtolower($pages[$i]) == strtolower($thispage))
            {
                $output .= '<span class="wikitrail">';
                if ($i>0) $output .= $signleft.' '.$this->Link($pages[$i-1]).' '.$seperator.' ';
                $output .= $this->Link($list);
                if ($i+1<count($pages)) $output .= ' '.$seperator.' '.$this->Link($pages[$i+1]).' '.$signright;
                $output .= '</span>';
            }
        }
    }
    else $output .='List-page could not be retrieved!';
}
else $output .= 'You did not enter a list-page!';

//output section
print $output;
?>


Comments?



CategoryUserContributions
Comments
Comment by WikkaCharla
2007-12-13 11:45:21
I am unable to get this to work for me, i installed as directed and have attempted to implement with no luck, there is no text on the page that is supposed to call the {{trail list=""}} but if i type the wrong page title, i do get an error, but the correct page title does not appear at all. I've looked at the source, been to the irc channel with no luck. Is anyone even looking at this page to see my comment.
Comment by BrianKoontz
2007-12-13 19:50:33
WikkaCharla, it looks to me like the regexp was incorrect (embedded commas were being used to separate character search ranges). I've updated this page, so try the new version (or diff with the previous page) and see if that works for you.
Comment by NilsLindenberg
2007-12-15 08:39:19
Brian, thanks for the fix! WikkaCharla, please try again and leave a comment here if it works (or not).
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki