Not logged in. · Lost password · Register
Forum: General Help and Support Features and Functionality RSS
Prev, Next, Up navigation on wiki pages?
Avatar
tobiaseigen #1
Member since Feb 2007 · 21 posts
Group memberships: Members
Show profile · Link to this post
Subject: Prev, Next, Up navigation on wiki pages?
Hey folks,

We are creating a manual using dokuwiki, and are looking for creative ways to set up the navigation so readers can get around and use the document easily. We've got indexmenu installed and it works well, and will be creating namespaces to keep the document organized and navigable. Is there a plugin or feature that I haven't found yet to produce navigation at the top and bottom of pages that provides direct links to "previous page, next page, up"? Similar to docbook or alot of unix man pages, like this: http://cygwin.com/cygwin-ug-net/setup-net.html

The alternative is putting these in manually which seems like a bad idea, esp since we want to be able to export the manual for printing and offline reading.

Many thanks in advance for any suggestions -

Tobias
Tobias Eigen

Kabissa - Space for Change in Africa
http://www.kabissa.org
Avatar
tobiaseigen #2
Member since Feb 2007 · 21 posts
Group memberships: Members
Show profile · Link to this post
This may be an example of what I'm talking about - how did they do that? See bottom of wiki page with the left and right arrows to go to the prev/next "nom".

http://www.puzzlers.org/dokuwiki/doku.…?id=krewe:noms:ru…
Tobias Eigen

Kabissa - Space for Change in Africa
http://www.kabissa.org
Avatar
tobiaseigen #3
Member since Feb 2007 · 21 posts
Group memberships: Members
Show profile · Link to this post
I'm still trying to figure this out - please let me know if you've heard of anything.

Here's a thought - maybe it belongs in the indexmenu plugin? I've asked in a feature request on the indexmenu talk page page.

Left/Up/Right navigation for books

Hey folks - thanks for this terrific plugin. I am involved in a project to produce a book using dokuwiki - and we are 80% there. Right now we have manually inserted left/right arrows at the bottoms of pages to move to the previous or next page in the book. This is silly since the arrows become part of the document which we don’t want for printing etc. My thought is that indexmenu, which we are using in the left-hand navigation in the monobook template, seems the tool for the job for this. Would it be possible? I’m thinking something simple and intuitive that shows the titles of the previous and next page in the book - like on a wordpress blog like this example. — Tobias Eigen 2007-03-21 15:19


Would be most grateful for any guidance/suggestions on how best to handle this.

Cheers,

Tobias
Tobias Eigen

Kabissa - Space for Change in Africa
http://www.kabissa.org
Avatar
Kite #4
Member since Mar 2007 · 9 posts · Location: Vancouver, BC, Canada
Group memberships: Members
Show profile · Link to this post
In reply to post #2
Hello Tobias,

I am the webmaster at http://www.puzzlers.org and added the navigation footer to pages like http://www.puzzlers.org/dokuwiki/doku.php?id=krewe:noms:kite due to the very large number of pages in that one directory.

The trail starts in the website template where my content <DIV> reads:

 <div class="page">
    <!-- wikipage start -->
    <?php tpl_content() ?>

    <!-- Puzzler page footer start  -->
    <?php puz_insert_php("_footer.php"); ?>
    <!-- Puzzler page footer stop  -->

    <!-- wikipage stop -->
  </div>


The three lines are my "hook" to generate that navigation.   I include a custom script file in the template (for my site it is puzzlers.php), and it includes the puz_insert_php(file) function:

 function puz_insert_php($php_file) {
   global $ACT;
   global $REV;
   global $ID;
   //global $TEXT;
   //global $PRE;
   //global $SUF;
   //global $SUM;
   //global $IDX;
 
   //echo "<!-- ACT: $ACT -->\n";
   switch($ACT){
     case 'show':
         //echo "<!-- DEBUG ID: $ID -->\n";
         echo "\n\t\t<!-- Puzzler inserted PHP start -->\n";
         $file =  preg_replace("/.txt/", "/$php_file", wikiFN(getNS($ID)));
         echo "\n\t\t<!-- DEBUG: \$file=$file -->\n";
         if(@file_exists($file)){
             ob_start();
             $text = io_readFile($file);
             if($INFO['perm'] == AUTH_ADMIN) {
                 eval("?>$text");
             } else {
                 @eval("?>$text");
             }  
             $content = ob_get_contents();
             ob_end_clean();
             echo $content;
         } else {
             echo "\t\t<!-- PHP file was not found -->\n";
         }
         echo "\n\t\t<!-- Puzzler inserted PHP stop -->\n";
         break;
     case 'preview':
     case 'edit':
     case 'wordblock':
     case 'search':
     case 'revisions':
     case 'diff':
     case 'recent':
     case 'index':
     case 'backlink':
     case 'conflict':
     case 'locked':
     case 'login':
     case 'register':
     case 'denied':
     case 'admin':
     case 'profile';
        break;
     default:
             msg("Failed to handle command: ".hsc($ACT),-1);
   }
 }


Using this external file and function allows me to upgrade Dokuwiki from time to time by adding my customizations (all with a puz_ prefix) into the current template format.  And this function is generic enough that I can put pretty much any PHP script in for the footer of the page.

The footer script in the Noms area you asked about (below) is not pretty, but gets what I needed done for the pages I had to work with.  I have an outline of the code after the code.

_footer.php (begin)

 <!-- NOM page Footer -->
 <hr />
 <style type="text/css" media="screen">
 div.nav-outer {
    align='center'
 }
 div.nav-left {
    float: left;
    vertical-align: text-top;
    text-align: left;
 }
 div.nav-center {
    #float: left;
    vertical-align: text-bottom;
    text-align: center;
 }
 div.nav-right {
    float:right;
    vertical-align:text-top;
    text-align:right;
 }
 span.nav-left {
    vertical-align: text-top;
    text-align: left;
 }
 span.nav-right {
    vertical-align:text-top;
    text-align:right;
 }

 </style>
 <?php
 
 function pointers($cells, $count, $to_id) {

  require_once(DOKU_INC.'inc/parser/xhtml.php');
  static $xhtml_renderer = NULL;


  if($count < 0) {
      // Left pointers
      for($image = $cells * -1; $image < 0; $image++) {
         if($image >= $count) {
             // output a left pointer
             $res .= "<img src=\"/dokuwiki/lib/exe/fetch.php?w=&h=&cache=cache&media=images:arrows:nomleft.gif\" class=\"media\" alt=\"Prev\" />";
         } else {
             // Ouput a blank to the left of the pointers
             $res .= "<img src=\"/dokuwiki/lib/exe/fetch.php?w=&h=&cache=cache&media=images:arrows:nomzero.gif\" class=\"media\" alt=\"Prev\" />";
         }  
      } // for
  } else {
      // right pointers
      for($image = 0; $image < $cells; $image++) {
         if($image < $count) {
             // outpur a right pointer
             $res .= "<img src=\"/dokuwiki/lib/exe/fetch.php?w=&h=&cache=cache&media=images:arrows:nomright.gif\" class=\"media\" alt=\"Next\" />";
         } else {
             // Ouput a blank to the right of the pointers
             $res .= "<img src=\"/dokuwiki/lib/exe/fetch.php?w=&h=&cache=cache&media=images:arrows:nomzero.gif\" class=\"media\" alt=\"Next\" />";
         }
      } // for
  }  // left or right pointers?
  return "<a href=\"/dokuwiki/doku.php?cache=cache&id=" . $to_id .
         "\" class=\"internallink\" title=\"$to_id\" onclick=\"return svchk()\" " .
          "onkeypress=\"return svchk()\">" . $res . "</a>";
 }

 function Build_Nom_Nav() {
   
    $dir = dirname(wikiFN(getID()));
    $data = array();
    $ns = getNS(getID());
    $current = noNS(getID());
    $links = -1;
   
    //echo "\t\t\t\t<!-- DEBUG \$dir=$dir -->\n";
    search($data, $dir,'search_index',array('ns' => $ns));
   
   
    foreach ($data as $item){
        // echo "\t\t\t\t<!-- DEBUG \$item['id']=" .$item["id"] . " -->\n";
        if( $item['type'] == 'f') {  // only do files
            if( $item["id"] == $current ) {
                //echo "\t\t\t\t<!-- DEBUG FOUND -->\n";
                $links = 0;            // Found ... start counting links
                // Build the prior links list
                echo "\n\t<div class='nav-outer'>\n";
                echo "\n\t<div class='nav-left'>\n";
                if(isset($prior1)) {
                    echo "\t\t<span class='nav-left'>" . pointers(3, -1, "$ns:$prior1");
                    echo html_wikilink($prior1) ."</span><br />\n";
                }
                if(isset($prior2)) {
                    echo "\t\t<span class='nav-left'>" . pointers(3, -2, "$ns:$prior2");
                    echo html_wikilink($prior2) ."</span><br />\n";
                }
                if(isset($prior3)) {
                    echo "\t\t<span class='nav-left'>" . pointers(3, -3, "$ns:$prior3");
                    echo html_wikilink($prior3) ."</span><br />\n";
                }
                echo "\n\t</div> <!-- nav-left -->";
                echo "\n\t<div class='nav-center'>" . html_wikilink($ns) . "</div>";
                echo "\n\t<div class='nav-right'>\n";
            } else {
                if($links < 0) {
                    // searching -- cache the last e entries
                    $prior3 = $prior2;
                    $prior2 = $prior1;
                    $prior1 = $item["id"];
                } elseif ($links < 3) {
                    $links++;
                    //echo "\t\t\t\t<!-- DEBUG following: $links -->\n";
                    echo "\t\t<span class='nav-right'>" . html_wikilink($item["id"]);
                    echo pointers(3, $links, "$ns:" . $item["id"]) ."</span><br />\n";
                } else {
                    echo "\n\t</div> <!-- nav-right -->";
                    echo "\n\t</div> <!-- nav-outer -->";
                    //echo "\t\t\t\t<!-- DEBUG DONE -->\n";
                    break;  // we're done ... no need to check any more
                } // if (found, following, or done)
            } // if(found)
        } // if(is a file)
    } // foreach()
 }         // Build_Nom_Nav()
 
 
 echo "\t\t<!-- Building Nom footer -->\n";
 Build_Nom_Nav();
 echo "\t\t<!-- Done building Nom footer -->\n";
 
 ?>

_footer.php (end)


In the footer script in the Noms area (above), I essentially:
1. Output some local styles.
2. Scan the directory for files, then sort them into alpha order.
3. Iterate across the file list keeping track of the last 3 pages until the current page is found in the list
4. Output the left (before) set of links + the "up" in the navigation and start counting $links = 0.
5. for the next three pages in the list, output the right (after) set of links for navigation
6. stop looking at files after the 3rd right hand link.

This file is the "hard part" you can't see on my site; everything else is sort of findable on the web (my graphics, the important parts of the puz_insert_php(file) function -- its just one of the "do" functions from docuwiki where I replaced the output with the meat of the include_form code which is a plugin in Docuwiki.   In fact, you could probably just replace that function call  with the include form plugin  to include the  _footer.php ;-).

I hope that helps,

Kite
This post was edited on 2007-03-21, 15:42 by Kite.
Avatar
tobiaseigen #5
Member since Feb 2007 · 21 posts
Group memberships: Members
Show profile · Link to this post
Subject: Thanks Kite!
Thanks for sharing the code, Kite! I will review this and see what I can do with it. 

Ideally I'd like to see this functionality as an installable plugin and not a hack - so that I (and others) can use it on multiple sites and using any template.

Cheers,

Tobias
Tobias Eigen

Kabissa - Space for Change in Africa
http://www.kabissa.org
Avatar
Kite #6
Member since Mar 2007 · 9 posts · Location: Vancouver, BC, Canada
Group memberships: Members
Show profile · Link to this post
Tobias,

Plugins have their place, but using a plug-in here is actually more work than my code ;-)  

I would hate to think that for most "book style" websites they use embedded links to manage navigation ... that's just bad, I think.  More likely, you want a "table of contents" file - a list ordered page IDs - then, like my footer, you pick the left and right pages and inject the links.  Again, I think this is the Template's job.  Your template should always do the work you need done that covers more than a few pages and needs to be consistent.

I'm not editing more than 400 pages to add a tag for a footer when the template can do the work and find the footer and use it properly.   I don't think the code in the footer page is optimal, but the "hack" is just the code out of my incl_form plugin ... I just don't see a reason to re-write it; but I've done similar code by telling the template to use a plugin to generate something like a list or something. 

For example, I can us my existing INCL_FORM plug-in if I replace the template function call with something like:

  echo p_render('xhtml',p_get_instructions("~~INCL_FORM:_footer~~"),$info);

Then I just need to move my page into my Forms collection and off I go.  I think there were a couple other issues, like how the form cleans an ID to remove the leading underscore though.  That's not hard to work around, either.   But still, if its not in the template, then I lose the automation of all those pages just inherit the decorations without editing.

I've been looking at the footer script and thinking "that should be simpler" ... but no real idea yet.  I've taken many of my "hacks" and made them plugins and others I've said "a hack is good enough for THIS use."   Its a case-by-case problem/question/solution.

I always keep my customizations as a file of template function call "hacks" that replaces a bit of template.  An upgrade means I just replace the template PHP and slip in my half dozen function bits.  Since essentially all my functionality is outside the template, its highly reusable to me.  I've done numerous upgrades and have it down to editing a dozen of the hundreds of files and, I hope you'll agree, we have a nice distinctive and usable website. 

After all, the whole point of the template is to do site wide or wide reaching customization and those customizations aren't a "hack" when they are self-contained, functional, and admired by others who want to know "how did they do THAT?".

Ted

p.s. If I was using the file to determine the order of pages, I'd probably keep the file scan, too, and append any pages not already in the file to the end so new topics are always reachable, too.
This post was edited 2 times, last on 2007-03-23, 07:24 by Kite.
Avatar
Kite #7
Member since Mar 2007 · 9 posts · Location: Vancouver, BC, Canada
Group memberships: Members
Show profile · Link to this post
Tobias et.al.

See my plugin revisions in thread http://forum.dokuwiki.org/thread/483, especially post http://forum.dokuwiki.org/post/2561 and following.

Kite
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-05-26, 17:35:51 (UTC +02:00)