Revision [9952]

This is an old revision of WikiBreadcrumb made by NilsLindenberg on 2005-07-13 20:28:02.


Simple History trail for wikka

The following code is a simple history trails feature (JavaWoman informed me that "breadcrumbs" are strictly for heirarchical systems & since wiki's are "flat" calling it a "breadcrumb" feature is inappropriate) that can be added to the header.php code to provide a linear history of the last few previously visited pages in the wiki. It only requires a single field added to the users database (add a field called "recentpages" set as type TINYTEXT and set it so it can be null (which is the default)) and it seems to work like a charm. I was inspired by the trail feature at coocoo wakka, but wrote this from scratch.

add the following code to your header.php file near the bottom (immediately before the last "?>").
// WikiTrails code V1.1a copyright by G. M. Bowen & Andrew Somerville, 2005.
// Version1.1a has a minor code change (as suggested here) so that non-wikiname pages were linked properly
// Prepared for a SSHRC funded research project. Licensed under GPL.
// Please keep attributions if distributing code.  
if ($user = $this->GetUser())
    $username = $this->GetUserName();
    $check = $this->LoadSingle("SELECT recentpages FROM ".$this->config["table_prefix"]."users WHERE name='".$username."'");
    $newstring = str_replace(' '.$this->GetPageTag().' ',' ',' '.trim($check['recentpages']).' ');
    $newstring = trim($newstring).' '.$this->GetPageTag()." "; 
    if (str_word_count($newstring) > 6) {          
            $newstring = trim(strstr($newstring, " "));
    $newstring .= " ";
    $this->query("UPDATE ".$this->config['table_prefix']."users SET recentpages = '$newstring' WHERE name='$username' ");  

    // Add trails to printout
    $recent = $this->LoadSingle("SELECT recentpages FROM ".$this->config["table_prefix"]."users WHERE name='".$username."'");

    # Section rewritten by andrew.
    $page_names = Array();
    # Parse string at spaces, into an array.
    $this_pagename = strtok(trim($recent[recentpages]), " ");
    while ($this_pagename) {
        $this_pagename = strtok(" ");
    # Get rid of duplicates.
    $page_names = array_unique($page_names);
    # Create the trail by walking through the array of page names.
    $separator  = "";
    $page_trail = "";
    foreach ($page_names as $this_pagename) {
        $page_trail .= $separator."[[".$this_pagename."]]";
        $separator   = "-->";
    # Print the trail.
    echo "<br /><small><b>Trail:</b> ".$this->format($page_trail)."</small>";
//FINISH breadcrumb code

If you want the list of previously visited pages to be greater or lesser change the "6" value.

Hope this meets your needs folks. If you find ways of making the code more efficient (and that is certainly possible), then please feel free to update it.

Version V1.1 fixes search and replace issues. Problem was that if you were at the page AndrEw and you also had a page AndrewsPage then when you moved around sooner or later you'd get sPage. That problem is now solved.

There are 22 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki