Skip to content
Snippets Groups Projects
Commit a3ec5f4a authored by matthiasgrimm's avatar matthiasgrimm
Browse files

add a back button to parent page

This patch extends the template functions with back
button linking to the current pages' parent if
available. Both tpl_button() and tpl_actionlink()
are supported.

For this to work the first page in the namespace must
have the same name as the namespace itself. The 'back'
button of every page in this namespace links to
namespace:namespace. The 'back' button of the page
namespace:namespace links to the first page of the
containing namespace and so forth until the start page
has been reached.

Because of the precondition decribed above, the default
template hasn't got the new 'back' button. It is reserved
for custom made templates and installations which take
care of the precondition.

darcs-hash:20050519174025-7ef76-1e9c78c941f53871905fc1ba08b28a826553daa3.gz
parent bad0b545
No related branches found
No related tags found
No related merge requests found
......@@ -193,6 +193,42 @@ function tpl_link($url,$name,$more=''){
print ">$name</a>";
}
/**
* get the parent page
*
* Tries to find out which page is parent.
* returns false if none is available
*
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function tpl_getparent($ID){
global $conf;
if ($ID != $conf['start']) {
$idparts = explode(':', $ID);
$pn = array_pop($idparts); // get the page name
for ($n=0; $n < 2; $n++) {
if (count($idparts) == 0) {
$ID = $conf['start']; // go to topmost page
break;
}else{
$ns = array_pop($idparts); // get the last part of namespace
if ($pn != $ns) { // are we already home?
array_push($idparts, $ns, $ns); // no, then add a page with same name
$ID = implode (':', $idparts); // as the namespace and recombine $ID
break;
}
}
}
if (@file_exists(wikiFN($ID))) {
return $ID;
}
}
return false;
}
/**
* Print one of the buttons
*
......@@ -205,8 +241,10 @@ function tpl_link($url,$name,$more=''){
* index - The index
* admin - admin page - if enough rights
* top - a back to top button
* back - a back to parent button - if available
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function tpl_button($type){
global $ID;
......@@ -226,6 +264,11 @@ function tpl_button($type){
case 'index':
print html_btn(index,$ID,'x',array('do' => 'index'));
break;
case 'back':
if ($ID = tpl_getparent($ID)) {
print html_btn(back,$ID,'b',array('do' => 'show'));
}
break;
case 'top':
print html_topbtn();
break;
......@@ -259,8 +302,10 @@ function tpl_button($type){
* index - The index
* admin - admin page - if enough rights
* top - a back to top button
* back - a back to parent button - if available
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
* @see tpl_button
*/
function tpl_actionlink($type,$pre='',$suf=''){
......@@ -308,6 +353,11 @@ function tpl_actionlink($type,$pre='',$suf=''){
case 'top':
print '<a href="#top" class="action" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>';
break;
case 'back':
if ($ID = tpl_getparent($ID)) {
tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action" accesskey="b"');
}
break;
case 'login':
if($conf['useacl']){
if($_SERVER['REMOTE_USER']){
......
......@@ -31,6 +31,7 @@ $lang['btn_logout'] = 'Abmelden';
$lang['btn_admin'] = 'Admin';
$lang['btn_update'] = 'Updaten';
$lang['btn_delete'] = 'Löschen';
$lang['btn_back'] = 'Zurück';
$lang['loggedinas'] = 'Angemeldet als';
$lang['user'] = 'Benutzername';
......
......@@ -30,6 +30,7 @@ $lang['btn_logout'] = 'Logout';
$lang['btn_admin'] = 'Admin';
$lang['btn_update'] = 'Update';
$lang['btn_delete'] = 'Delete';
$lang['btn_back'] = 'Back';
$lang['loggedinas'] = 'Logged in as';
$lang['user'] = 'Username';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment