From 4ceab83fd024405dfa43e10241bb9a9f7fee5bf5 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 1 Dec 2008 22:55:39 +0100 Subject: 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 --- inc/pageutils.php | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) (limited to 'inc/pageutils.php') 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 -*/ + * Returns the current namespace + * + * @author Nathan Fritz + */ function curNS($id) { return noNS(getNS($id)); } /** -* Returns the ID without the namespace or current namespace for 'start' pages -* -* @author Nathan Fritz -*/ + * Returns the ID without the namespace or current namespace for 'start' pages + * + * @author Nathan Fritz + */ function noNSorNS($id) { global $conf; @@ -188,6 +188,36 @@ function noNSorNS($id) { return $p; } +/** + * 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 + */ +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 * -- cgit v1.2.3