0.
모니위키 쓰다가 논문 같은 것 attachment 형식으로 올려서 정리하고 싶었는데
한글파일도 업로드가 제대로 안 되고 공백 문자도 포함되면 안 되는 규정 때문에
안타까웠는데..
방학을 맞이하여^^ 약간 손을 대어 보았습니다.
1. 파일 중간 공백 허용 패치
최근 버전의
[attachment:file.txt] 의 매크로는, 중간에 공백이 허용 안 되었는데,
공백 문자가 내부적으로 여러 attachment 를 함께 쓸 경우를 위해서 예약되어서인 것
처럼 보입니다.
그래서, attachment 매크로 파싱하는 부분에, " 와 " 의 사이에 있는 공백 문자는
파일 이름의 일부로 인식하도록 수정해 보았습니다. 따라서 앞으로 공백 문자가 포함된
파일을 attachment 할 때는
[attachment:"hello world.pdf"]
이런 식으로 " 로 둘러 싸 주면 됩니다.
(이 부분은 moniwiki/plugin/Attachment.php 를 수정하였습니다.)
2. 한글 파일 허용 패치
2-1.
한글 파일은, 모질라에서는 제대로 되었는데 IE6 에서 문제가 되더군요..
모니위키의 Attachment.php 에서 한글 이름이 들어 왔을 때 이를 URL encoding
해 줘서 다음 페이지로 넘겨야 하는데, 이 과정이 빠져 있었습니다.
웹 브라우저에서 이 부분을 자동으로 해 줬는데, 모질라에서는 잘 처리해
줬지만 IE6 이 안 되더군요... 그래서 명시적으로 urlencoding() 함수로
인코딩을 해 줘서 넘겼습니다.
이를 위해서 (moniwiki/plugin/Attachment.php) 파일을 수정했습니다.
2-2.
다음 문제는 다운로드 할 때, 파일 이름 정보를 받을 때, 인코딩이 utf-8 로 되어
있으면 HTTP response 메시지 헤더에서 한글 파일 이름을 제대로 받아 오지 못하더군요..
(이 경우도 모질라는 되는데 IE6이 문제..)
그래서 utf-8 로 로케일이 설정되어 있으면, HTTP response 헤더 부분에
파일 이름을 넣어 주는 부분에서 iconv 함수로 파일이름을 euc-kr 로 바꿔 주니,
잘 받아 오더군요..^^
이를 위해서 (moniwiki/plugin/download.php) 파일을 수정했습니다.
3. 버그
php 가 처음인데다가, 모니위키 구조를 이해 못한 채로, 3일만에 주섬주섬 패치를
만드느라, 제대로 동작하지 않는 경우가 많으리라 생각됩니다 ^^a 우선은 제 환경이
IE 기반 브라우저이기 때문에, IE 의 불편함을 해결하는 선까지 (제가 정상적으로
쓸 수 있는 선까지^^) 테스트를 했습니다.
제가 확인한 것으로는, 한글 허용 패치 부분에서, 2-2 번 문제 (HTTP 헤더의
파일이름의 인코딩을 UTF-8 에서 euc-kr 로 바꿔준 경우)에, 오히려 모질라에서
정상 작동하지 않았습니다.
(그 부분 고치기 전에는 모질라에서 잘 되었는데 말이죠..)
iolo 님께 얼핏 들은 말로는, 예전에도 한글 인코딩 관련해서 문제가 많았다고
하는데, 어디서 찾아 볼 수 있을까요?? 여건이 된다면 이 쪽 패치 완성시키고
싶은데 지식이 부족해서요...
-
patch_emptychar.diff (5 KB)

@@ -7,6 +7,25 @@
7//
8// $Id: Attachment.php,v 1.15 2005/04/08 04:26:17 wkpark Exp $
9
10function getSecondAttachPos ($value){
11 $startQuote = strpos ($value, '"') ;
12 if ($startQuote === false)
13 return strpos ($value, ' ') ;
14 $endQuote = strpos ($value, '"', $startQuote +1) ;
15 if ($endQuote === false)
17 return strpos ($value, ' ', $endQuote + 1) ;
20function getOriginalFileName ($value){
21 $len = strlen ($value) ;
24 if ($value[0] === '"' && $value[$len-1] === '"')
25 return substr ($value, 1, $len - 2) ;
10function macro_Attachment($formatter,$value,$option='') {
11 global $DBInfo;
12
@@ -16,14 +35,14 @@
16 else $mydownload='download';
17
18 $text='';
19 if (($p=
strpos($value
,' ')) !== false) {
38 if (($p=
getSecondAttachPos ($value)) !== false) {
20 // [attachment:my.ext hello]
21 // [attachment:my.ext attachment:my.png]
22 // [attachment:my.ext http://url/../my.png]
23 $text=$ntext=substr($value,$p+1);
24 $value=substr($value,0,$p);
25 if (substr($text,0,11)=='attachment:') {
26 $fname=substr($text,11);
45 $fname=
getOriginalFileName (substr($text,11
));
27 $ntext=macro_Attachment($formatter,$fname,1);
28 }
29 if (preg_match("/\.(png|gif|jpeg|jpg)$/i",$ntext)) {
@@ -59,7 +78,7 @@
59
60 if (($p=strpos($value,':')) !== false or ($p=strpos($value,'/')) !== false) {
61 $subpage=substr($value,0,$p);
62 $file=substr($value,$p+1);
81 $file=
getOriginalFileName (substr($value,$p+1
));
63 $value=$subpage.'/'.$file; # normalize page arg
64 if ($subpage and $DBInfo->hasPage($subpage)) {
65 $pagename=$subpage;
@@ -73,7 +92,7 @@
73 $pagename=$formatter->page->name;
74 $key=$DBInfo->pageToKeyname($formatter->page->name);
75 $dir=$DBInfo->upload_dir.'/'.$key;
95 $file=$value
= getOriginalFileName ($value) ;
77 }
78 // check file name XXX
79 if (!$file) return 'attachment:/';
@@ -85,12 +104,12 @@
85 if (file_exists($upload_file)) {
86 if (!$img_link && preg_match("/\.(png|gif|jpeg|jpg)$/i",$upload_file)) {
87 if ($key != $pagename || $force_download)
88 $url=$formatter->link_url(_urlencode($pagename),"?action=$mydownload&value=$value
");
107 $url=$formatter->link_url(_urlencode($pagename),"?action=$mydownload&value=
".urlencode($value
));
89 else
90 $url=$DBInfo->url_prefix."/"._urlencode($upload_file);
91 return "<span class=\"imgAttach\"><img src='$url' alt='$file' $attr/></span>";
92 } else {
93 $link=$formatter->link_url(_urlencode($pagename),"?action=$mydownload&value=$value
",$text);
112 $link=$formatter->link_url(_urlencode($pagename),"?action=$mydownload&value=
".urlencode($value
),$text);
94 if ($img_link)
95 return "<span class=\"attach\"><a href='$link'>$img_link</a></span>";
96
@@ -98,7 +117,7 @@
98 }
99 }
100 if ($pagename == $formatter->page->name)
101 return '<span class="attach">'.$formatter->link_to("?action=UploadFile&rename=$file
",sprintf(_("Upload new Attachment \"%s\""),$file)).'</span>';
120 return '<span class="attach">'.$formatter->link_to("?action=UploadFile&rename=
".urlencode($file
),sprintf(_("Upload new Attachment \"%s\""),$file)).'</span>';
102
103 if (!$pagename) $pagename='UploadFile';
104 return '<span class="attach">'.$formatter->link_tag($pagename,"?action=UploadFile&rename=$file",sprintf(_("Upload new Attachment \"%s\" on the \"%s\""),$file, $pagename)).'</span>';
@@ -57,8 +57,11 @@
57 $mimetype=strtolower($mime[$match[1]]);
58 if (!$mimetype) $mimetype="application/x-unknown";
59
61 if (strcmp ($DBInfo->charset, 'utf-8')==0)
62 $hfname = iconv ($DBInfo->charset, "euc-kr", $file) ;
60 header("Content-Type: $mimetype\r\n");
61 header("Content-Disposition: inline; filename=\"$
file\"" );
64 header("Content-Disposition: inline; filename=\"$
hfname\"" );
62 #header("Content-Disposition: attachment; filename=\"$file\"" );
63 header("Content-Description: MoniWiki PHP Downloader" );
64 Header("Pragma: no-cache");