summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/common.php21
-rw-r--r--inc/format.php16
-rw-r--r--inc/parser.php17
-rw-r--r--inc/template.php4
4 files changed, 46 insertions, 12 deletions
diff --git a/inc/common.php b/inc/common.php
index 72f6fde12..251fbcdc3 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -119,18 +119,29 @@ function breadcrumbs(){
$crumbs = array();
}
//we only save on show and existing wiki documents
- if($ACT != 'show' || !@file_exists(wikiFN($ID))){
+ $file = wikiFN($ID);
+ if($ACT != 'show' || !@file_exists($file)){
$_SESSION[$conf['title']]['bc'] = $crumbs;
return $crumbs;
}
+
+ // page names
+ $name = noNS($ID);
+ if ($conf['useheading']) {
+ // get page title
+ $title = getFirstHeading(io_readFile($file));
+ if ($title) {
+ $name = $title;
+ }
+ }
+
//remove ID from array
- $pos = array_search($ID,$crumbs);
- if($pos !== false && $pos !== null){
- array_splice($crumbs,$pos,1);
+ if (isset($crumbs[$ID])) {
+ unset($crumbs[$ID]);
}
//add to array
- $crumbs[] =$ID;
+ $crumbs[$ID] = $name;
//reduce size
while(count($crumbs) > $conf['breadcrumbs']){
array_shift($crumbs);
diff --git a/inc/format.php b/inc/format.php
index 8e953fade..fe4b6fa72 100644
--- a/inc/format.php
+++ b/inc/format.php
@@ -89,17 +89,19 @@ function format_link_wiki($link){
list($link['url'],$hash) = split('#',$link['url'],2);
$hash = cleanID($hash);
- //use link without namespace as name
- if(empty($link['name'])) $link['name'] = preg_replace('/.*:/','',$link['url']);
- $link['name'] = htmlspecialchars($link['name']);
-
$link['url'] = cleanID($link['url']);
$link['title'] = $link['url'];
- //set class depending on existance
+ //set class and name depending on file existence and content
$file = wikiFN($link['url']);
if(@file_exists($file)){
$link['class']="wikilink1";
+ if ($conf['useheading'] && empty($link['name'])) {
+ $title = getFirstHeading(io_readFile($file));
+ if ($title){
+ $link['name'] = $title;
+ }
+ }
}else{
if($conf['autoplural']){
//try plural/nonplural
@@ -122,6 +124,10 @@ function format_link_wiki($link){
}
}
+ //if no name yet, use link without namespace
+ if(empty($link['name'])) $link['name'] = preg_replace('/.*:/','',$link['url']);
+ $link['name'] = htmlspecialchars($link['name']);
+
//construct the full link
$link['url'] = wl($link['url']);
diff --git a/inc/parser.php b/inc/parser.php
index 0fe04afba..e14c5bcd5 100644
--- a/inc/parser.php
+++ b/inc/parser.php
@@ -838,4 +838,21 @@ function mediaformat($text){
return format_link_build($link);
}
+/**
+ * Get first heading, to be used as a page title
+ *
+ * @author Jan Decaluwe <jan@jandecaluwe.com>
+ */
+function getFirstHeading($text){
+ $title = '';
+ $lines = split("\n",$text);
+ foreach($lines as $line){
+ if(preg_match('/^\s*==+(.+?)==+\s*$/',$line,$matches)){
+ $title = $matches[1];
+ break;
+ }
+ }
+ return $title;
+}
+
?>
diff --git a/inc/template.php b/inc/template.php
index 8f8c6f9dc..ab135e95f 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -273,9 +273,9 @@ function tpl_breadcrumbs(){
$crumbs = breadcrumbs(); //setup crumb trace
print $lang['breadcrumb'].':';
- foreach ($crumbs as $crumb){
+ foreach ($crumbs as $id => $name){
print ' &raquo; ';
- tpl_link(wl($crumb),noNS($crumb),'class="breadcrumbs" title="'.$crumb.'"');
+ tpl_link(wl($id),$name,'class="breadcrumbs" title="'.$id.'"');
}
}