From 5b75cd1f5c479ada468fbf62a733c54edad152f1 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Tue, 5 Jan 2010 14:14:00 +0100 Subject: New mail subscription with digest --- inc/pageutils.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'inc/pageutils.php') diff --git a/inc/pageutils.php b/inc/pageutils.php index 9c192e5e6..239ff41c5 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -534,4 +534,21 @@ function isVisiblePage($id){ return !isHiddenPage($id); } +/** + * Format an id for output to a user + * + * Namespaces are denoted by a trailing “:*”. The root namespace is + * “*”. Output is escaped. + * + * @author Adrian Lang + */ +function prettyprint_id($id) { + if (!$id || $id === ':') { + return '*'; + } + if ((substr($id, -1, 1) === ':')) { + $id .= '*'; + } + return hsc($id); +} -- cgit v1.2.3 From 7873e7571e67c02167e5747441a2c6be32b07267 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Mon, 22 Feb 2010 22:13:59 +0100 Subject: Redirect to start page for the root namespace too Dokuwiki emits an HTTP redirect when accessing: /path/to/some/namespace/ to force the browser to: /path/to/some/namespace/$conf['start'] However, this doesn't happen for the root namespace itself. In some ways, this doesn't really matter, since accessing plain "doku.php" will show the root namespace "start" page even without the redirection. Equally, this can be trivially fixed using mod_rewrite rules, but I don't want to encode the start page name into my rewrite rules. Finally, I like the consistency of always having the start page name in the URL, rather than special-casing the root namespace. (Actually, I'd prefer never to have it in the URL, but that looks more complex to achieve). Anyway, the attached patch makes the redirect happen for the root namespace as well. --- inc/pageutils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/pageutils.php') diff --git a/inc/pageutils.php b/inc/pageutils.php index 239ff41c5..b6b1d048b 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -60,7 +60,7 @@ function getID($param='id',$clean=true){ } // Namespace autolinking from URL - if(substr($id,-1) == ':' || ($conf['useslash'] && substr($id,-1) == '/')){ + if(substr($id,-1) == ':' || ($conf['useslash'] && substr($id,-1) == '/') || $id == ''){ if(page_exists($id.$conf['start'])){ // start page inside namespace $id = $id.$conf['start']; -- cgit v1.2.3 From 01e3159c01c6e13a9a102bd4c1e09b852c994223 Mon Sep 17 00:00:00 2001 From: Chris Tapp Date: Sun, 28 Feb 2010 11:54:30 +0100 Subject: Better performance on assigning section IDs FS#1894 --- inc/pageutils.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'inc/pageutils.php') diff --git a/inc/pageutils.php b/inc/pageutils.php index b6b1d048b..33b93bd72 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -198,7 +198,7 @@ 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 + * @param array $check Existing IDs (title => number) * @author Andreas Gohr */ function sectionID($title,&$check) { @@ -212,12 +212,11 @@ function sectionID($title,&$check) { if(is_array($check)){ // make sure tiles are unique - $num = ''; - while(in_array($title.$num,$check)){ - ($num) ? $num++ : $num = 1; + if (!array_key_exists ($title,$check)) { + $check[$title] = 0; + } else { + $title .= ++ $check[$title]; } - $title = $title.$num; - $check[] = $title; } return $title; -- cgit v1.2.3 From b6084253c3d06924ef5817c67d4ae983bb007f39 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 2 Mar 2010 09:27:49 +0100 Subject: Revert "Redirect to start page for the root namespace too" This reverts commit 7873e7571e67c02167e5747441a2c6be32b07267. The patch breaks at least the behaviour of the "view recent changes of the whole wiki" link. --- inc/pageutils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/pageutils.php') diff --git a/inc/pageutils.php b/inc/pageutils.php index 33b93bd72..eb22084c1 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -60,7 +60,7 @@ function getID($param='id',$clean=true){ } // Namespace autolinking from URL - if(substr($id,-1) == ':' || ($conf['useslash'] && substr($id,-1) == '/') || $id == ''){ + if(substr($id,-1) == ':' || ($conf['useslash'] && substr($id,-1) == '/')){ if(page_exists($id.$conf['start'])){ // start page inside namespace $id = $id.$conf['start']; -- cgit v1.2.3 From 06368e4dbb72cef5e440312251d11fbaea6242a9 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Tue, 2 Mar 2010 19:00:37 +0100 Subject: Fixed testcase and getID - FS#1908 FS#1831 FS#1838 $_SERVER['PATH_INFO'] is used now to determine the page id when using internal rewriting, in all testcases I've seen so far this variable was set correctly. There are also a couple of fallbacks if the variable doesn't exist, $_SERVER['SCRIPT_NAME'] is now preferred instead of custom path extraction which fails when doku.php is outside the document root. --- inc/pageutils.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'inc/pageutils.php') diff --git a/inc/pageutils.php b/inc/pageutils.php index eb22084c1..ef09dc7b6 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -23,10 +23,11 @@ function getID($param='id',$clean=true){ $id = isset($_REQUEST[$param]) ? $_REQUEST[$param] : null; - $request = $_SERVER['REQUEST_URI']; - //construct page id from request URI if(empty($id) && $conf['userewrite'] == 2){ + $request = $_SERVER['REQUEST_URI']; + $script = ''; + //get the script URL if($conf['basedir']){ $relpath = ''; @@ -35,15 +36,14 @@ function getID($param='id',$clean=true){ } $script = $conf['basedir'].$relpath.basename($_SERVER['SCRIPT_FILENAME']); - }elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['PATH_TRANSLATED']){ - $request = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','', - $_SERVER['PATH_TRANSLATED']); + }elseif($_SERVER['PATH_INFO']){ + $request = $_SERVER['PATH_INFO']; + }elseif($_SERVER['SCRIPT_NAME']){ + $script = $_SERVER['SCRIPT_NAME']; }elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){ $script = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','', $_SERVER['SCRIPT_FILENAME']); $script = '/'.$script; - }else{ - $script = $_SERVER['SCRIPT_NAME']; } //clean script and request (fixes a windows problem) -- cgit v1.2.3 From 7733c314de594b92b59e2202490ff24f039d632b Mon Sep 17 00:00:00 2001 From: Michael Klier Date: Fri, 26 Mar 2010 11:56:29 +0100 Subject: replaced readdir() with glob() in metaFiles() --- inc/pageutils.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'inc/pageutils.php') diff --git a/inc/pageutils.php b/inc/pageutils.php index ef09dc7b6..cd3cf1fce 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -318,15 +318,7 @@ function metaFiles($id){ $ns = getNS($id); $dir = ($ns) ? metaFN($ns,'').'/' : metaFN($ns,''); $files = array(); - - $dh = @opendir($dir); - if(!$dh) return $files; - while(($file = readdir($dh)) !== false){ - if(strpos($file,$name.'.') === 0 && !is_dir($dir.$file)) - $files[] = $dir.$file; - } - closedir($dh); - + $files = glob($dir.$name.'.*'); return $files; } -- cgit v1.2.3 From f03fd957525a714da1cde7e2957939046bd51bd5 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 4 Apr 2010 20:28:39 +0200 Subject: new fnencode option FS#1649 This patch adds an option to choose how filenames are encoded when saved to the file system. You can choose between urlencoding (url), the new SafeFn method (safe) and storing real UTF-8 (utf-8). --- inc/pageutils.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'inc/pageutils.php') diff --git a/inc/pageutils.php b/inc/pageutils.php index cd3cf1fce..43c84038f 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -543,3 +543,53 @@ function prettyprint_id($id) { } return hsc($id); } + +/** + * Encode a UTF-8 filename to use on any filesystem + * + * Uses the 'fnencode' option to determine encoding + * + * When the second parameter is true the string will + * be encoded only if non ASCII characters are detected - + * This makes it safe to run it multiple times on the + * same string (default is true) + * + * @author Andreas Gohr + * @see urlencode + */ +function utf8_encodeFN($file,$safe=true){ + global $conf; + if($conf['fnencode'] == 'utf-8') return $file; + + if($safe && preg_match('#^[a-zA-Z0-9/_\-\.%]+$#',$file)){ + return $file; + } + + if($conf['fnencode'] == 'safe'){ + return SafeFN::encode($file); + } + + $file = urlencode($file); + $file = str_replace('%2F','/',$file); + return $file; +} + +/** + * Decode a filename back to UTF-8 + * + * Uses the 'fnencode' option to determine encoding + * + * @author Andreas Gohr + * @see urldecode + */ +function utf8_decodeFN($file){ + global $conf; + if($conf['fnencode'] == 'utf-8') return $file; + + if($conf['fnencode'] == 'safe'){ + return SafeFN::decode($file); + } + + return urldecode($file); +} + -- cgit v1.2.3 From b26cdbbe55ab83f30ecba9deee8b3541cb005a88 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Thu, 1 Jul 2010 12:59:59 +0200 Subject: Support ns; ids --- inc/pageutils.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'inc/pageutils.php') diff --git a/inc/pageutils.php b/inc/pageutils.php index 43c84038f..a2efdc5d5 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -437,7 +437,8 @@ function resolve_pageid($ns,&$page,&$exists){ $file = wikiFN($page); // if ends with colon or slash we have a namespace link - if(substr($page,-1) == ':' || ($conf['useslash'] && substr($page,-1) == '/')){ + if(in_array(substr($page,-1), array(':', ';')) || + ($conf['useslash'] && substr($page,-1) == '/')){ if(page_exists($page.$conf['start'])){ // start page inside namespace $page = $page.$conf['start']; -- cgit v1.2.3 From 9708106bad6f238d9aeaccc35258350a66604a6c Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Thu, 1 Jul 2010 13:02:28 +0200 Subject: Fix ns: and ns:start handling --- inc/pageutils.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/pageutils.php') diff --git a/inc/pageutils.php b/inc/pageutils.php index a2efdc5d5..969a6ea0d 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -185,10 +185,10 @@ function noNSorNS($id) { global $conf; $p = noNS($id); - if ($p == $conf['start']) { + if ($p == $conf['start'] || $p == false) { $p = curNS($id); if ($p == false) { - return noNS($id); + return $conf['start']; } } return $p; -- cgit v1.2.3