diff --git a/inc/common.php b/inc/common.php index ac5332a3eaa01dfd34edbeb7f7314a32b3247279..7fa9c564b073b7385c486448d1c49a192caf333a 100644 --- a/inc/common.php +++ b/inc/common.php @@ -206,9 +206,11 @@ function breadcrumbs(){ * currently used to replace the colon with something else * on Windows systems and to have proper URL encoding * + * Urlencoding is ommitted when the second parameter is false + * * @author Andreas Gohr <andi@splitbrain.org> */ -function idfilter($id){ +function idfilter($id,$ue=true){ global $conf; if ($conf['useslash'] && $conf['userewrite']){ $id = strtr($id,':','/'); @@ -216,9 +218,11 @@ function idfilter($id){ $conf['userewrite']) { $id = strtr($id,':',';'); } - $id = urlencode($id); - $id = str_replace('%3A',':',$id); //keep as colon - $id = str_replace('%2F','/',$id); //keep as slash + if($ue){ + $id = urlencode($id); + $id = str_replace('%3A',':',$id); //keep as colon + $id = str_replace('%2F','/',$id); //keep as slash + } return $id; } @@ -440,6 +444,8 @@ function cleanID($id){ * returns the full path to the datafile specified by ID and * optional revision * + * The filename is URL encoded to protect Unicode chars + * * @author Andreas Gohr <andi@splitbrain.org> */ function wikiFN($id,$rev=''){ @@ -447,16 +453,16 @@ function wikiFN($id,$rev=''){ $id = cleanID($id); $id = str_replace(':','/',$id); if(empty($rev)){ - return $conf['datadir'].'/'.$id.'.txt'; + $fn = $conf['datadir'].'/'.$id.'.txt'; }else{ $fn = $conf['olddir'].'/'.$id.'.'.$rev.'.txt'; - if(!$conf['usegzip'] || @file_exists($fn)){ - //return plaintext if exists or gzip is disabled - return $fn; - }else{ - return $fn.'.gz'; + if($conf['usegzip'] && !@file_exists($fn)){ + //return gzip if enabled and plaintext doesn't exist + $fn .= '.gz'; } } + $fn = utf8_encodeFN($fn); + return $fn; } /** diff --git a/inc/html.php b/inc/html.php index 97a0c091bf48a16b2385777d62fa4b42b24d57fc..16269d0a847045c3369d7c1e089e1dd21e51890f 100644 --- a/inc/html.php +++ b/inc/html.php @@ -242,7 +242,8 @@ function html_btn($name,$id,$akey,$params,$method='get'){ $ret = ''; - $id = idfilter($id); + //filter id (without urlencoding) + $id = idfilter($id,false); //make nice URLs even for buttons $link = getBaseURL().'/'; diff --git a/inc/search.php b/inc/search.php index 46b36f816738cc6a2ce9c9170df400b875054fa7..ebc7eda9dcbd15974dbbaded6f18e33978a7b20a 100644 --- a/inc/search.php +++ b/inc/search.php @@ -324,7 +324,8 @@ function sort_search_fulltext($a,$b){ * @author Andreas Gohr <andi@splitbrain.org> */ function pathID($path){ - $id = str_replace('/',':',$path); + $id = utf8_decodeFN($path); + $id = str_replace('/',':',$id); $id = preg_replace('#\.txt$#','',$id); $id = preg_replace('#^:+#','',$id); $id = preg_replace('#:+$#','',$id); diff --git a/inc/utf8.php b/inc/utf8.php index 5e5dfe8bbab5226e714a148e54dc3f7323891bf6..d06cfc58c88950021f4560d6feecf03d1646fb04 100644 --- a/inc/utf8.php +++ b/inc/utf8.php @@ -6,6 +6,30 @@ * @author Andreas Gohr <andi@splitbrain.org> */ +/** + * URL-Encode a filename to allow unicodecharacters + * + * Slashes are not encoded + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function utf8_encodeFN($file){ + $file = rawurlencode($file); + $file = str_replace('%2F','/',$file); + return $file; +} + +/** + * URL-Decode a filename + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function utf8_decodeFN($file){ + $file = rawurldecode($file); + return $file; +} + + /** * This is a unicode aware replacement for strtolower() *