12 번째 수정본
(12 번째 수정본부터 12 번째 수정본까지의 변경사항)
(소소한 수정, 다른 사용자에 의한 수정)
(두 수정본의 내용이 동일하거나, 수정본을 비교할 수 없음.)
화일 업로드 기능 추가
- 예전부터 필요성이 제기되어 왔던 기능
- perlmania 자료실에 있는 것과, /사용자의견에 Bab2님이 작성해 둔 것을 참조하여 wiki.pl 소스 안에 집어넣었음.
- 필수 요구 사항 : 없음
- 선택 요구 사항 : 없음
- 사용법
- 편집 화면에 보면 하단에 "화일 업로드" 버튼이 있다.
- 버튼을 클릭하면 화일을 업로드할 수 있는 별도의 창이 뜬다.
- 또는 브라우저 주소창에 직접 "wiki.pl?action=upload" 를 입력하여 업로드 화면을 띄울 수도 있다.
- 이 창에서 화일을 선택하여 업로드하면 Upload:화일명 의 형식으로 링크가 나오니, 이것을 복사하여 페이지에 삽입하면 된다.
- 화일명에 공백이 있을 경우 공백은 언더라인으로 치환되어 저장된다.
- 동일한 이름의 화일이 있을 경우, 화일 이름 앞에 "숫자_" 의 형식으로 자동으로 prefix 가 붙는다. 즉 "화일" "2_화일" "3_화일" .. 등으로 화일명이 부여된다. 화일을 악의로 덮어쓰는 것을 막기 위함이다.
- 업로드한 화일은 config 화일에서 UploadDir 변수에 지정해 준 디렉토리에 저장된다.
- 업로드할 수 있는 화일의 크기는 config 화일에 이미 있던 MaxPost 변수의 값에 좌우된다. 따라서 이 값을 넉넉하게 잡아주어야 한다. (현재는 210KB 정도로 잡혀 있다. 바이트 단위로 잡아 주어야 한다. 예를 들어 2MB 라면 2*1024*1024)
- 업로드한 화일은 Upload:화일명 으로 마치 인터위키처럼 링크할 수 있다. 따라서 intermap 화일에는 Upload 라는 이름의 인터위키가 존재하면 안 된다. (안 될 것은 없지만 있어도 사용할 수 없다)
- 부작용 : 모름
- 웹브라우저에 따라 제대로 동작하지 않을 때가 있다.
- 제대로 되는 브라우저 : IE, 모질라(리눅스에서 테스트), 오페라6.05(MS윈도)
- 잘 안 되는 브라우저 :
- konqueror(리눅스에서 테스트) - 미리 보기나 화일 업로드 버튼을 눌렀을 때 별도의 창이 뜨지를 않는다. 이것은 주소창에 직접 wiki.pl?action=upload 를 입력하여 해결할 수는 있다. 그러나 화일 이름에 한글이 들어가 있을 경우 제대로 업로드가 되지 않았다. 화일명을 영문으로 해 주면 잘 되었다.
- 업로드한 화일들이 하나의 디렉토리 안에 저장되므로, 이용자가 많은 사이트에서는 디렉토리 안에 화일이 몇 천개씩 있게 되어 안 좋을 듯. 애초에는 각 페이지마다 별도의 디렉토리를 생성하여 저장하게 하고 싶었으나, 인터링크 형식으로 나타내는 것이 복잡해지고 (사실 이건 그다지 복잡할 것도 없겠는데), 서로 다른 페이지에서 하나의 화일을 동시에 링크하는 경우도 있겠거니 싶어서 그냥 편한대로 했다. 한 디렉토리에 화일이 몇 천개씩 생길 수도 있다는 얘기이니... 나중에 수정하는 것을 고려해 봐야 할 듯..
- 원래 MaxPost 변수는 페이지 하나의 크기가 너무 커지는 것을 막기 위해 설정되어 있는 것인데, 이값이 작으면 업로드하는데에도 지장이 있다. 별수 없이 이 값을 크게 잡아야 하는데, 이러면 반대로 페이지 크기의 상한선도 커진다.
- config.pl
...
$MaxPost = 1024 * 1024 * 1; # 바이트 단위로 설정
...
$UploadDir = "$DataDir/upload"; # 추가
...
- wiki.pl
###############
### added by gypark
### 패치를 위해 추가된 환경설정 변수
use vars qw(
$UserGotoBar $UserGotoBar2 $UserGotoBar3 $UserGotoBar4
$ConfigFile $SOURCEHIGHLIGHT @SRCHIGHLANG $LinkFirstChar
$EditGuideInExtern $SizeTopFrame $SizeBottomFrame
$LogoPage $CheckTime $LinkDir $IconDir $CountDir $UploadDir # UploadDir 추가
);
###
###############
-
my @ScriptPath = split('/', "$ENV{SCRIPT_NAME}");
$CGI::POST_MAX = $MaxPost;
###############
### replaced by gypark
### file upload
# $CGI::DISABLE_UPLOADS = 1; # no uploads
$CGI::DISABLE_UPLOADS = 0;
###
###############
$q = new CGI;
$q->autoEscape(undef);
###############
### added by gypark
### file upload
if ($q->cgi_error() =~ m/^413/) {
print $q->redirect(-url=>"http:$ENV{SCRIPT_NAME}?action=upload&error=3")
;
exit 1;
}
###
###############
$Now = time; # Reset in case script is persistent
$ScriptName = pop(@ScriptPath); # Name used in links
...
}
-
sub GetSiteUrl {
my ($site) = @_;
my ($data, $url, $status);
if (!$InterSiteInit) {
$InterSiteInit = 1;
($status, $data) = &ReadFile($InterFile);
return "" if (!$status);
%InterSite = split(/\s+/, $data); # Later consider defensive code
###############
### added by gypark
### file upload
$InterSite{'Upload'} = "http:$UploadDir\/";
###
###############
}
$url = $InterSite{$site} if (defined($InterSite{$site}));
return $url;
}
-
sub DoOtherRequest {
...
} elsif ($action eq "version") {
&DoShowVersion();
###############
### added by gypark
### 최근변경내역에 북마크 기능 도입
} elsif ($action eq "bookmark") {
&DoBookmark();
###
###############
###############
### added by gypark
### file upload
} elsif ($action eq "upload") {
&DoUpload();
###
###############
} else {
# Later improve error reporting
&ReportError(Ts('Invalid action parameter %s', $action));
}
return;
...
}
-
sub DoEdit {
...
function help(s)
{
var w = window.open(s, "Help", "width=500,height=400, resizable=1, scrollbar
s=1");
w.focus();
}
//-->
</script>
|;
###############
### added by gypark
### file upload
print qq|
<script language="javascript" type="text/javascript">
<!--
function upload()
{
var w = window.open("$ScriptName?action=upload", "upload", "width=640,height=250,resizable=1,statusbar=1,scrollbars=1");
w.focus();
}
//-->
</script>
|;
###
###############
...
### replaced by gypark
### 미리보기 버튼에 번역함수 적용
# print q(<input type="button" name="prev1" value="Popup Preview" onclick="javascript:preview();">); # luke added
print q(<input type="button" name="prev1" value=").
T('Popup Preview') .
q(" onclick="javascript:preview();">); # luke added
###
###############
###############
### added by gypark
### file upload
print " ".q(<input type="button" name="prev1" value=").
T('Upload File') .
q(" onclick="javascript:upload();">);
###
###############
if ($isConflict) {
print "\n<br><hr noshade size=1><p><strong>", T('This is the text you submitted:'),
...
}
- 통채로 추가
sub DoUpload {
my $file;
my $upload = &GetParam('upload');
my $prev_error = &GetParam('error', "");
my @uploadError = (
T('Upload completed successfully'),
T('Invalid filename'),
T('You can not upload html or any executable scripts'),
T('File is too large'),
T('File has no content'),
);
my $result;
print &GetHttpHeader();
print &GetHtmlHeader("$SiteName : ". T('Upload File'), "");
print $q->h2(T('Upload File')) . "\n";
if (!(&UserCanEdit("",1))) {
print T('Uploading is not allowed');
print $q->end_html;
return;
}
if ($prev_error) {
print "<b>$uploadError[$prev_error]</b><br><hr>\n";
} elsif ($upload) {
$file = &GetParam('upload_file');
$result = &UploadFile($file);
print "<b>$uploadError[$result]</b><br><hr>\n";
}
&PrintUploadFileForm();
print $q->end_html;
}
sub PrintUploadFileForm {
print T('Select the file you want to upload') . "\n";
print "<br>".Ts('File must be smaller than %s MB', ($MaxPost / 1024 / 1024)) . "\n";
print $q->start_form('post',"$ScriptName", 'multipart/form-data') . "\n";
print "<input type='hidden' name='action' value='upload'>";
print "<input type='hidden' name='upload' value='1'>" . "\n";
print "<center>" . "\n";
print $q->filefield("upload_file","",60,80) . "\n";
print " " . "\n";
print $q->submit(T('Upload')) . "\n";
print "</center>" . "\n";
print $q->endform();
}
sub UploadFile {
my ($file) = @_;
my ($filename);
my ($target);
if ($file =~ m/\//) {
$file =~ m/(.*)\/([^\/]*)/;
$filename = $2;
} elsif ($file =~ m/\\/) {
$file =~ m/(.*)\\([^\\]*)/;
$filename = $2;
} else {
$filename = $file;
}
if (($filename eq "") || ($filename =~ /\0/)) {
return 1;
}
if ($filename =~ m/(\.pyc|\.py|\.pl|\.html|\.htm|\.php|\.cgi)$/i) {
return 2;
}
$filename =~ s/ /_/g;
my ($prefix, $target, $target_full) = (1, $filename, "$UploadDir/$filename");
while (-f "$target_full") {
$prefix++;
$target = "$prefix"."_$filename";
$target_full = "$UploadDir/$target";
}
&CreateDir($UploadDir);
open (FILE, ">$target_full") || die Ts('cant opening %s', $target_full) . ": $!";
binmode FILE;
while (<$file>) {
print FILE $_;
}
close(FILE);
chmod(0644, "$target_full");
if ((-s "$target_full") > $MaxPost) {
unlink "$target_full";
return 3;
}
if ((-s "$target_full") == 0) {
unlink "$target_full";
return 4;
}
print T('Following is the Interlink of your file') . "<br>\n";
print "<div style='text-align:center; font-size:larger; font-weight:bold;'>\n";
print "Upload:$target\n";
print "</div>\n";
return 0;
}
- translations/korean.pl
Upload File
화일 업로드
Upload completed successfully
업로드가 성공적으로 끝났습니다
Invalid filename
화일 이름이 올바르지 않습니다
You can not upload html or any executable scripts
html 또는 실행 스크립트는 올릴 수 없습니다
File is too large
화일이 너무 큽니다
File has no content
화일의 내용이 없습니다
Following is the Interlink of your file
다음 주소를 복사해서 사용하세요
Uploading is not allowed
업로드가 허용되지 않습니다
Select the file you want to upload
업로드할 화일을 선택하세요
File must be smaller than %s MB
화일 크기는 %s MB 이하여야 합니다.
Upload
업로드
cant opening %s
%s 를 열 수 없습니다
Notes
도대체 왜 리눅스에서는 안 되는 걸까요? 화일명의 전체 경로가 제대로 넘어가지 않는 듯 합니다.
- 리눅스 뿐만이 아니라 윈도 피닉스, 그러니깐 모질라, 넷스까지 포함하게 되겠네요.. 저것들이 전부 제대로 업이 안되었습니다. 모질라는 주소전송시 UTF-8로 변환을 무조건 수행하는 거 같은데, 이것을 어떻게 해줘야 좋을지 몰라서 저는 그냥 이대로 쓰고 있습니다만.. IE에서도 저 옵션을 끄지않고 한글화일을 올리려하니 제대로 안되더군요. ㅜㅡ
--
Bab2 2003-3-16 4:03 pm
- 유닉스 쪽에서는, 화일명을 전달할 때 전체 경로가 전달되는 게 아닌가 보더라고요. 그래서 기존의 if 문 (전체 경로에서 화일명만 추출해 내는) 에서 제대로 걸리지 않아서 문제가 되었던 듯 합니다. 저 부분을 수정했더니, 모질라에서는 제대로 동작하는 것을 확인했습니다. konqueror 는 당장 자바스크립트 쪽에서 말썽이었는데 그건 일단 넘어가고, 업로드의 경우 화일명에 한글이 있으니 안 되더군요. 디렉토리에 한글이 있는 것은 상관없었습니다.
혹시 MS윈도에서 IE 외에 다른 브라우저를 사용하시는 분들 계시면 연습장에서 업로드 테스트 좀 해봐주세요~
위키위키분류