Hello,
I would like to show something like path to current page. I.e. the main path how one can reach the page.
I have already did some attempt to implement it:
I have configuration parameter 'context' that defines name of special page that contains something like full hierarchical contents of the site using multi-level unordered lists. Each item can be plain text or simple wiki link:
----
* [[Start]]
* [[Introduction]]
* Setting up WinSCP
* [[Requirements]]
* [[Installation]]
* Getting started
* [[getting_started|Quick Start Guide]]
* [[ssh|Understanding SSH]]
* [[Protocols]]
* [[Security]]
...
----
Then when I'm in 'security' page I want to get path
Start >> Getting started
where 'Start' is link to 'start' page and 'Getting started' is plain text.
To inc/common.php I have added:
----
/**
* This builds the context trail and returns it as array
*/
function context(){
global $ID;
global $conf;
global $context_cache;
$level0 = NULL;
$found = false;
if (!empty($context_cache))
{
$found = true;
$cache = $context_cache;
}
else
{
$file = wikiFN($conf['context']);
if (file_exists($file))
{
$levels = array();
$text = io_readFile($file, false);
$context = array();
foreach ($text as $line)
{
if (preg_match('/^(( )+)\\* ((\\[\\[(\\w+?)(\\|(.*))?\\]\\])|(.*))\\s*$/', $line, $matches))
{
$level = (strlen($matches[1]) / 2) - 1;
$context = array_slice($context, 0, $level);
$page = !empty($matches[5]) ? cleanID($matches[5]) : NULL;
if ($page == $ID)
{
$found = true;
break;
}
else
{
if (empty($matches[8]))
{
$title = !empty($matches[7]) ? $matches[7] : ucwords($page);
}
else
{
$title = $matches[8];
}
$c = array("page" => $page, "title" => $title);
$context[] = $c;
if ($level == 0)
{
// first level-zero context
if ($level0 === NULL)
{
$level0 = $c;
}
else
// next level-zero context, forget the first
{
$level0 = false;
}
}
}
}
}
}
}
if (!$found)
{
// if there were only one level-zero context, consider it the default and
// use it if the page was not found in the index
$context = !empty($level0) ? array($level0) : array();
}
return $context;
}
----
To inc/html.php I have added:
----
function html_context(){
global $lang;
global $conf;
//check if enabled
if(!$conf['context']) return;
$context = context();
print '<div class="context">';
foreach ($context as $c)
{
$page = $c["page"];
$title = $c["title"];
$title = htmlspecialchars($title);
if (empty($page))
{
print $title;
}
else
{
print '<a href="'.wl($page).'" class="context" onclick="return svchk()" '.
'onkeypress="return svchk()" title="'.$title.'">'.$title.'</a>';
}
print ' » ';
}
print '</div>';
}
----
In inc/ip.php I have modified function io_readFile():
----
function io_readFile($file,$join = true){
$ret = '';
if(@file_exists($file)){
if(substr($file,-3) == '.gz'){
$ret = gzfile($file);
}else{
$ret = file($file);
}
if ($join)
{
$ret = join('',$ret);
}
}
return cleanText($ret);
}
----
Then it is enough to just call html_context() from somewhere. The default good localtion would be somewhere the html_breadcrumbs() is called. Due to my non-standard design I call it from html_show().
Possible improvement would be to include the generated context in the cache, but that would mean rather huge changes to parser to distinguish parsing page from parsing lang/* texts.
Also this brings DokuWiki close to implementation of #24.
You can see what it looks like at:
http://winscp.sourceforge.net/eng/docs/security
http://winscp.sourceforge.net/eng/docs/index
Martin.