diff --git a/inc/common.php b/inc/common.php index faee93623ecab261521ae7c7ae6e26189cdb2813..9f69203784bb3933fafd9806db1936fbe11900f8 100644 --- a/inc/common.php +++ b/inc/common.php @@ -288,7 +288,7 @@ function breadcrumbs(){ // page names $name = noNSorNS($ID); - if ($conf['useheading']) { + if (useHeading('navigation')) { // get page title $title = p_get_first_heading($ID,true); if ($title) { @@ -1006,7 +1006,7 @@ function saveWikiText($id,$text,$summary,$minor=false){ io_saveFile($conf['cachedir'].'/purgefile',time()); // if useheading is enabled, purge the cache of all linking pages - if($conf['useheading']){ + if(useHeading('content')){ require_once(DOKU_INC.'inc/fulltext.php'); $pages = ft_backlinks($id); foreach ($pages as $page) { diff --git a/inc/confutils.php b/inc/confutils.php index d735b8b8233080ca03f754a6fd63a47216ce6c9f..a7799b9d4a37bcdffce365a3df9fc0ababd1896c 100644 --- a/inc/confutils.php +++ b/inc/confutils.php @@ -205,5 +205,36 @@ function actionOK($action){ return !in_array($action,$disabled); } +/** + * check if headings should be used as link text for the specified link type + * + * @author Chris Smith <chris@jalakai.co.uk> + * + * @param string $linktype 'content'|'navigation', content applies to links in wiki text + * navigation applies to all other links + * @returns boolean true if headings should be used for $linktype, false otherwise + */ +function useHeading($linktype) { + static $useHeading = null; + + if (is_null($useHeading)) { + global $conf; + + if (!empty($conf['useheading'])) { + switch ($conf['useheading']) { + case 'content' : $useHeading['content'] = true; break; + case 'navigation' : $useHeading['navigation'] = true; break; + default: + $useHeading['content'] = true; + $useHeading['navigation'] = true; + } + } else { + $useHeading = array(); + } + } + + return (!empty($useHeading[$linktype])); +} + //Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/inc/html.php b/inc/html.php index 8390a7b09306fd103cd43f17cc1be451cd7f9c45..636c93a13f8c3f424c1a9edb619e8ffe86472aec 100644 --- a/inc/html.php +++ b/inc/html.php @@ -23,7 +23,7 @@ function html_wikilink($id,$name=NULL,$search=''){ $xhtml_renderer = new Doku_Renderer_xhtml(); } - return $xhtml_renderer->internallink($id,$name,$search,true); + return $xhtml_renderer->internallink($id,$name,$search,true,'navigation'); } /** @@ -353,7 +353,7 @@ function html_search(){ $num = 1; foreach($data as $id => $cnt){ print '<div class="search_result">'; - print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$regex); + print html_wikilink(':'.$id,useHeading('navigation')?NULL:$id,$regex); print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />'; if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ? print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>'; @@ -628,7 +628,7 @@ function html_recent($first=0){ ))); $form->addElement(form_makeCloseTag('a')); - $form->addElement(html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id'])); + $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?NULL:$recent['id'])); $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); $form->addElement(' – '.htmlspecialchars($recent['sum'])); @@ -839,7 +839,7 @@ function html_backlinks(){ print '<ul class="idx">'; foreach($data as $blink){ print '<li><div class="li">'; - print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink); + print html_wikilink(':'.$blink,useHeading('navigation')?NULL:$blink); print '</div></li>'; } print '</ul>'; diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 640306f87bd519ad5a9a1221e22925ecd7ff6bd7..5994a4dd1b2747426e5961affdd1b581a4f06b0c 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -427,7 +427,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { $isImage = false; if (is_null($title)){ - if ($conf['useheading'] && $id){ + if (useHeading('content') && $id){ $heading = p_get_first_heading($id,false); if ($heading) return $heading; } diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 96afd159352d533d05bea87e823f1a22c3feb8ba..4fb6cb548e381421c8b1a532d50d5b7623411040 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -472,12 +472,12 @@ class Doku_Renderer_xhtml extends Doku_Renderer { /** * Render an internal Wiki Link * - * $search and $returnonly are not for the renderer but are used + * $search,$returnonly & $linktype are not for the renderer but are used * elsewhere - no need to implement them in other renderers * * @author Andreas Gohr <andi@splitbrain.org> */ - function internallink($id, $name = NULL, $search=NULL,$returnonly=false) { + function internallink($id, $name = NULL, $search=NULL,$returnonly=false,$linktype='content') { global $conf; global $ID; // default name is based on $id as given @@ -485,7 +485,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // now first resolve and clean up the $id resolve_pageid(getNS($ID),$id,$exists); - $name = $this->_getLinkTitle($name, $default, $isImage, $id); + $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); if ( !$isImage ) { if ( $exists ) { $class='wikilink1'; @@ -1026,12 +1026,12 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * * @author Harry Fuecks <hfuecks@gmail.com> */ - function _getLinkTitle($title, $default, & $isImage, $id=NULL) { + function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') { global $conf; $isImage = false; if ( is_null($title) || trim($title)=='') { - if ($conf['useheading'] && $id) { + if (useHeading($linktype) && $id) { $heading = p_get_first_heading($id,true); if ($heading) { return $this->_xmlEntities($heading); diff --git a/inc/parserutils.php b/inc/parserutils.php index 95d9647ff2d4b3658e0d65d901c282da9dd7cd11..ce4e8e9956ffa8ef88f18e5cc57424f658770363 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -618,8 +618,7 @@ function & p_get_renderer($mode) { * @author Andreas Gohr <andi@splitbrain.org> */ function p_get_first_heading($id, $render=true){ - global $conf; - return $conf['useheading'] ? p_get_metadata($id,'title',$render) : null; + return p_get_metadata($id,'title',$render); } /** diff --git a/inc/template.php b/inc/template.php index f5f2e7760f1cf73e270783a6f18aeb1a35ea681c..690f4ff41185c4b8b4d72b84b4277b41c60194c6 100644 --- a/inc/template.php +++ b/inc/template.php @@ -860,7 +860,7 @@ function tpl_youarehere($sep=' » '){ echo '<span class="bchead">'.$lang['youarehere'].': </span>'; // always print the startpage - $title = p_get_first_heading($conf['start']); + $title = useHeading('navigation') ? p_get_first_heading($conf['start']) : $conf['start']; if(!$title) $title = $conf['start']; tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"'); @@ -875,7 +875,7 @@ function tpl_youarehere($sep=' » '){ // output echo $sep; if($exists){ - $title = p_get_first_heading($page); + $title = useHeading($page) ? p_get_first_heading($page) : $page; if(!$title) $title = $parts[$i]; tpl_link(wl($page),hsc($title),'title="'.$page.'"'); }else{ @@ -889,7 +889,7 @@ function tpl_youarehere($sep=' » '){ if($page == $conf['start']) return; echo $sep; if(page_exists($page)){ - $title = p_get_first_heading($page); + $title = useHeading($page) ? p_get_first_heading($page) : $page; if(!$title) $title = $parts[$i]; tpl_link(wl($page),hsc($title),'title="'.$page.'"'); }else{ @@ -989,7 +989,7 @@ function tpl_pagetitle($id=null, $ret=false){ } $name = $id; - if ($conf['useheading']) { + if (useHeading('navigation')) { $title = p_get_first_heading($id); if ($title) $name = $title; } diff --git a/lib/plugins/config/lang/en/lang.php b/lib/plugins/config/lang/en/lang.php index 0865d30902f994644031f5091358f0b58587c844..85317251a0dff2c3f656fb6b5364548799593fba 100644 --- a/lib/plugins/config/lang/en/lang.php +++ b/lib/plugins/config/lang/en/lang.php @@ -221,3 +221,10 @@ $lang['showuseras_o_loginname'] = 'Login name'; $lang['showuseras_o_username'] = "User's full name"; $lang['showuseras_o_email'] = "User's e-mail addresss (obfuscated according to mailguard setting)"; $lang['showuseras_o_email_link'] = "User's e-mail addresss as a mailto: link"; + +/* useheading options */ +$lang['useheading_o_0'] = 'Never'; +$lang['useheading_o_navigation'] = 'Navigation Only'; +$lang['useheading_o_content'] = 'Wiki Content Only'; +$lang['useheading_o_1'] = 'Always'; + diff --git a/lib/plugins/config/settings/config.metadata.php b/lib/plugins/config/settings/config.metadata.php index 5bee0fa32d1e61b157ea1ef80a5cb2bc459f391e..12795d1bbdf578684a2dc301eb964ea6f7e64d55 100644 --- a/lib/plugins/config/settings/config.metadata.php +++ b/lib/plugins/config/settings/config.metadata.php @@ -106,7 +106,7 @@ $meta['maxtoclevel'] = array('multichoice','_choices' => array(0,1,2,3,4,5)); $meta['maxseclevel'] = array('multichoice','_choices' => array(0,1,2,3,4,5)); // 0 for no sec edit buttons $meta['camelcase'] = array('onoff'); $meta['deaccent'] = array('multichoice','_choices' => array(0,1,2)); -$meta['useheading'] = array('onoff'); +$meta['useheading'] = array('multichoice','_choices' => array(0,'navigation','content',1)); $meta['refcheck'] = array('onoff'); $meta['refshow'] = array('numeric');