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
There are 3 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki