summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2008-12-01 22:55:39 +0100
committerAndreas Gohr <andi@splitbrain.org>2008-12-01 22:55:39 +0100
commit4ceab83fd024405dfa43e10241bb9a9f7fee5bf5 (patch)
treeae76ea4ea79982aaed8e2dc251d8fd917e523b39
parent137ce95a340b36e962f90c44c9f6414dc2e0d1e4 (diff)
downloadrpg-4ceab83fd024405dfa43e10241bb9a9f7fee5bf5.tar.gz
rpg-4ceab83fd024405dfa43e10241bb9a9f7fee5bf5.tar.bz2
Better creation of section IDs FS#1536
This patch enhances the creation of section IDs for number only headlines. It also moves section ID creation to a function in pageutils.php removing some duplicate functionality in inc/action.php darcs-hash:20081201215539-7ad00-48f3c153a2c126d9fb06aa90e4f1b857f76ebec7.gz
-rw-r--r--inc/actions.php6
-rw-r--r--inc/pageutils.php46
-rw-r--r--inc/parser/xhtml.php16
3 files changed, 42 insertions, 26 deletions
diff --git a/inc/actions.php b/inc/actions.php
index 8da6c47cc..62b39efc2 100644
--- a/inc/actions.php
+++ b/inc/actions.php
@@ -340,11 +340,7 @@ function act_redirect($id,$preact){
//get section name when coming from section edit
if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){
- #FIXME duplicates code from xhtml renderer
- $title = $match[0];
- $title = str_replace(':','',cleanID($title));
- $title = ltrim($title,'0123456789._-');
- if(empty($title)) $title='section';
+ $title = sectionID($match[0]);
}
$opts = array(
diff --git a/inc/pageutils.php b/inc/pageutils.php
index e509dfde3..7a140ef8c 100644
--- a/inc/pageutils.php
+++ b/inc/pageutils.php
@@ -162,19 +162,19 @@ function noNS($id) {
}
/**
-* Returns the current namespace
-*
-* @author Nathan Fritz <fritzn@crown.edu>
-*/
+ * Returns the current namespace
+ *
+ * @author Nathan Fritz <fritzn@crown.edu>
+ */
function curNS($id) {
return noNS(getNS($id));
}
/**
-* Returns the ID without the namespace or current namespace for 'start' pages
-*
-* @author Nathan Fritz <fritzn@crown.edu>
-*/
+ * Returns the ID without the namespace or current namespace for 'start' pages
+ *
+ * @author Nathan Fritz <fritzn@crown.edu>
+ */
function noNSorNS($id) {
global $conf;
@@ -189,6 +189,36 @@ function noNSorNS($id) {
}
/**
+ * Creates a XHTML valid linkid from a given headline title
+ *
+ * @param string $title The headline title
+ * @param array $check List of existing IDs
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function sectionID($title,&$check=null) {
+ $title = str_replace(':','',cleanID($title));
+ $new = ltrim($title,'0123456789._-');
+ if(empty($new)){
+ $title = 'section'.preg_replace('/[^0-9]+/','',$title); //keep numbers from headline
+ }else{
+ $title = $new;
+ }
+
+ if(!is_null($check) && is_array($check)){
+ // make sure tiles are unique
+ $num = '';
+ while(in_array($title.$num,$check)){
+ ($num) ? $num++ : $num = 1;
+ }
+ $title = $title.$num;
+ $check[] = $title;
+ }
+
+ return $title;
+}
+
+
+/**
* Wiki page existence check
*
* parameters as for wikiFN
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index 4fb6cb548..fda1ef36e 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -1004,21 +1004,11 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
* @author Andreas Gohr <andi@splitbrain.org>
*/
function _headerToLink($title,$create=false) {
- $title = str_replace(':','',cleanID($title));
- $title = ltrim($title,'0123456789._-');
- if(empty($title)) $title='section';
-
if($create){
- // make sure tiles are unique
- $num = '';
- while(in_array($title.$num,$this->headers)){
- ($num) ? $num++ : $num = 1;
- }
- $title = $title.$num;
- $this->headers[] = $title;
+ return sectionID($title,$this->headers);
+ }else{
+ return sectionID($title);
}
-
- return $title;
}
/**