qwikdoc 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/.rspec +2 -0
- data/CHANGES +3 -0
- data/COPYING +340 -0
- data/Gemfile +3 -0
- data/README.md +10 -0
- data/Rakefile +10 -0
- data/TextFormattingRules +137 -0
- data/TextFormattingRules.ja +143 -0
- data/bin/qwikdoc +34 -0
- data/lib/qwik_doc.rb +15 -0
- data/lib/qwik_doc/hack.rb +184 -0
- data/qwikdoc.gemspec +26 -0
- data/spec/qwik_doc_spec.rb +305 -0
- data/spec/spec_helper.rb +12 -0
- data/vendor/qwik/Makefile +63 -0
- data/vendor/qwik/Rakefile +17 -0
- data/vendor/qwik/act-aa.rb +83 -0
- data/vendor/qwik/act-archive.rb +386 -0
- data/vendor/qwik/act-attach.rb +304 -0
- data/vendor/qwik/act-backup.rb +236 -0
- data/vendor/qwik/act-basic.rb +325 -0
- data/vendor/qwik/act-book.rb +161 -0
- data/vendor/qwik/act-calc.rb +371 -0
- data/vendor/qwik/act-charset.rb +251 -0
- data/vendor/qwik/act-christel.rb +112 -0
- data/vendor/qwik/act-chronology.rb +149 -0
- data/vendor/qwik/act-code.rb +155 -0
- data/vendor/qwik/act-comment.rb +554 -0
- data/vendor/qwik/act-config.rb +49 -0
- data/vendor/qwik/act-counter.rb +125 -0
- data/vendor/qwik/act-day.rb +96 -0
- data/vendor/qwik/act-describe.rb +135 -0
- data/vendor/qwik/act-diary.rb +109 -0
- data/vendor/qwik/act-edit.rb +317 -0
- data/vendor/qwik/act-embed-html.rb +296 -0
- data/vendor/qwik/act-emode.rb +150 -0
- data/vendor/qwik/act-event.rb +187 -0
- data/vendor/qwik/act-file.rb +303 -0
- data/vendor/qwik/act-files.rb +771 -0
- data/vendor/qwik/act-getpass.rb +295 -0
- data/vendor/qwik/act-history.rb +136 -0
- data/vendor/qwik/act-html.rb +204 -0
- data/vendor/qwik/act-httpauth.rb +147 -0
- data/vendor/qwik/act-include.rb +142 -0
- data/vendor/qwik/act-interwiki.rb +189 -0
- data/vendor/qwik/act-isearch.rb +109 -0
- data/vendor/qwik/act-keywords.rb +137 -0
- data/vendor/qwik/act-lang.rb +81 -0
- data/vendor/qwik/act-license.rb +63 -0
- data/vendor/qwik/act-list.rb +287 -0
- data/vendor/qwik/act-login.rb +410 -0
- data/vendor/qwik/act-logout.rb +60 -0
- data/vendor/qwik/act-mail.rb +159 -0
- data/vendor/qwik/act-map.rb +292 -0
- data/vendor/qwik/act-md5.rb +42 -0
- data/vendor/qwik/act-mdlb.rb +741 -0
- data/vendor/qwik/act-media.rb +416 -0
- data/vendor/qwik/act-member.rb +157 -0
- data/vendor/qwik/act-menu.rb +142 -0
- data/vendor/qwik/act-metadata.rb +323 -0
- data/vendor/qwik/act-mlsubmitform.rb +49 -0
- data/vendor/qwik/act-monitor.rb +167 -0
- data/vendor/qwik/act-new.rb +418 -0
- data/vendor/qwik/act-pagelist.rb +248 -0
- data/vendor/qwik/act-password.rb +145 -0
- data/vendor/qwik/act-plan.rb +210 -0
- data/vendor/qwik/act-povray.rb +230 -0
- data/vendor/qwik/act-presen.rb +380 -0
- data/vendor/qwik/act-redirect.rb +133 -0
- data/vendor/qwik/act-ring.rb +1071 -0
- data/vendor/qwik/act-rrefs.rb +255 -0
- data/vendor/qwik/act-ruby.rb +116 -0
- data/vendor/qwik/act-sample.rb +170 -0
- data/vendor/qwik/act-save.rb +295 -0
- data/vendor/qwik/act-schedule.rb +374 -0
- data/vendor/qwik/act-search.rb +180 -0
- data/vendor/qwik/act-searchwords.rb +51 -0
- data/vendor/qwik/act-sendpass.rb +83 -0
- data/vendor/qwik/act-site.rb +89 -0
- data/vendor/qwik/act-sitebackup.rb +419 -0
- data/vendor/qwik/act-sitelog.rb +118 -0
- data/vendor/qwik/act-smil.rb +299 -0
- data/vendor/qwik/act-status.rb +220 -0
- data/vendor/qwik/act-style.rb +608 -0
- data/vendor/qwik/act-table.rb +263 -0
- data/vendor/qwik/act-tableform.rb +241 -0
- data/vendor/qwik/act-tag.rb +103 -0
- data/vendor/qwik/act-text.rb +70 -0
- data/vendor/qwik/act-textarea.rb +164 -0
- data/vendor/qwik/act-theme.rb +346 -0
- data/vendor/qwik/act-toc.rb +112 -0
- data/vendor/qwik/act-typekey.rb +198 -0
- data/vendor/qwik/act-under-const.rb +94 -0
- data/vendor/qwik/act-webservice.rb +321 -0
- data/vendor/qwik/act-wema.rb +558 -0
- data/vendor/qwik/act-wysiwyg.rb +238 -0
- data/vendor/qwik/action.rb +325 -0
- data/vendor/qwik/autoreload.rb +98 -0
- data/vendor/qwik/bench-bench.rb +28 -0
- data/vendor/qwik/bench-emode.rb +47 -0
- data/vendor/qwik/bench-format-xml.rb +70 -0
- data/vendor/qwik/bench-large-table.rb +62 -0
- data/vendor/qwik/bench-md5.rb +14 -0
- data/vendor/qwik/bench-module-session.rb +19 -0
- data/vendor/qwik/bench-page.rb +50 -0
- data/vendor/qwik/bench-s-md5.rb +28 -0
- data/vendor/qwik/bench-session.rb +25 -0
- data/vendor/qwik/bench-textformat.rb +31 -0
- data/vendor/qwik/catalog-factory.rb +91 -0
- data/vendor/qwik/catalog-ja.rb +479 -0
- data/vendor/qwik/catalog-ml-ja.rb +145 -0
- data/vendor/qwik/check-act-monitor.rb +112 -0
- data/vendor/qwik/check-act-monitor2.rb +46 -0
- data/vendor/qwik/check-act-theme.rb +27 -0
- data/vendor/qwik/check-event.rb +112 -0
- data/vendor/qwik/check-event2.rb +55 -0
- data/vendor/qwik/check-htree-rexml.rb +77 -0
- data/vendor/qwik/check-htree.rb +51 -0
- data/vendor/qwik/check-libxml.rb +135 -0
- data/vendor/qwik/check-many-pages.rb +47 -0
- data/vendor/qwik/check-monitor.rb +33 -0
- data/vendor/qwik/check-observer.rb +67 -0
- data/vendor/qwik/check-server.rb +61 -0
- data/vendor/qwik/check-uuencode.rb +33 -0
- data/vendor/qwik/check-webdav.rb +65 -0
- data/vendor/qwik/check-xml-xpath.rb +27 -0
- data/vendor/qwik/common-backtrace.rb +94 -0
- data/vendor/qwik/common-basic.rb +111 -0
- data/vendor/qwik/common-condition.rb +142 -0
- data/vendor/qwik/common-error.rb +48 -0
- data/vendor/qwik/common-gettext.rb +50 -0
- data/vendor/qwik/common-javascript.rb +45 -0
- data/vendor/qwik/common-notice.rb +132 -0
- data/vendor/qwik/common-plain.rb +105 -0
- data/vendor/qwik/common-plugin.rb +111 -0
- data/vendor/qwik/common-res.rb +76 -0
- data/vendor/qwik/common-resolve.rb +92 -0
- data/vendor/qwik/common-send.rb +171 -0
- data/vendor/qwik/common-session.rb +139 -0
- data/vendor/qwik/common-surface.rb +261 -0
- data/vendor/qwik/common-url.rb +90 -0
- data/vendor/qwik/compat/Makefile +12 -0
- data/vendor/qwik/compat/add_load_path.rb +1 -0
- data/vendor/qwik/config.rb +299 -0
- data/vendor/qwik/db-b-backup.rb +142 -0
- data/vendor/qwik/db-backup.rb +184 -0
- data/vendor/qwik/db-berkeley.rb +306 -0
- data/vendor/qwik/db-filesystem.rb +305 -0
- data/vendor/qwik/db-indexer.rb +154 -0
- data/vendor/qwik/db-searchwords.rb +238 -0
- data/vendor/qwik/description-ja.rb +267 -0
- data/vendor/qwik/description.rb +256 -0
- data/vendor/qwik/dev-add-copyright.rb +23 -0
- data/vendor/qwik/dev-backup.rb +24 -0
- data/vendor/qwik/dev-bench.rb +175 -0
- data/vendor/qwik/dev-calctime.rb +52 -0
- data/vendor/qwik/dev-css-compressor.rb +60 -0
- data/vendor/qwik/dev-extract-catalog.rb +102 -0
- data/vendor/qwik/dev-js-compressor.rb +73 -0
- data/vendor/qwik/dev-release.rb +235 -0
- data/vendor/qwik/dev-replace.rb +353 -0
- data/vendor/qwik/dev-sendmail.rb +25 -0
- data/vendor/qwik/farm.rb +283 -0
- data/vendor/qwik/gettext.rb +56 -0
- data/vendor/qwik/group-cond.rb +157 -0
- data/vendor/qwik/group-config.rb +247 -0
- data/vendor/qwik/group-confirm.rb +147 -0
- data/vendor/qwik/group-db.rb +326 -0
- data/vendor/qwik/group-mail.rb +195 -0
- data/vendor/qwik/group-member.rb +307 -0
- data/vendor/qwik/group-sendmail.rb +231 -0
- data/vendor/qwik/group-site.rb +374 -0
- data/vendor/qwik/group-sweep.rb +63 -0
- data/vendor/qwik/group.rb +157 -0
- data/vendor/qwik/helper.rb +6 -0
- data/vendor/qwik/html-generator.rb +104 -0
- data/vendor/qwik/html-to-wabisabi.rb +149 -0
- data/vendor/qwik/htree-diff.rb +87 -0
- data/vendor/qwik/htree-format-xml.rb +57 -0
- data/vendor/qwik/htree-generator.rb +144 -0
- data/vendor/qwik/htree-get.rb +251 -0
- data/vendor/qwik/htree-html-generator.rb +179 -0
- data/vendor/qwik/htree-template.rb +263 -0
- data/vendor/qwik/htree-to-wabisabi.rb +171 -0
- data/vendor/qwik/loadlib.rb +79 -0
- data/vendor/qwik/logger.rb +115 -0
- data/vendor/qwik/mail-body.rb +171 -0
- data/vendor/qwik/mail-header.rb +474 -0
- data/vendor/qwik/mail-multipart.rb +193 -0
- data/vendor/qwik/mail-parse.rb +147 -0
- data/vendor/qwik/mail.rb +341 -0
- data/vendor/qwik/mailaddress.rb +83 -0
- data/vendor/qwik/mdlb-model.rb +81 -0
- data/vendor/qwik/mdlb-sample.rb +324 -0
- data/vendor/qwik/ml-catalog-factory.rb +27 -0
- data/vendor/qwik/ml-exception.rb +15 -0
- data/vendor/qwik/ml-generator.rb +28 -0
- data/vendor/qwik/ml-gettext.rb +137 -0
- data/vendor/qwik/ml-logger.rb +82 -0
- data/vendor/qwik/ml-memory.rb +65 -0
- data/vendor/qwik/ml-msg-validator.rb +86 -0
- data/vendor/qwik/ml-processor.rb +609 -0
- data/vendor/qwik/ml-quickml-server.rb +122 -0
- data/vendor/qwik/ml-sendmail.rb +0 -0
- data/vendor/qwik/ml-server.rb +107 -0
- data/vendor/qwik/ml-session.rb +348 -0
- data/vendor/qwik/ml-sweeper.rb +101 -0
- data/vendor/qwik/mock-logger.rb +65 -0
- data/vendor/qwik/mock-sendmail.rb +78 -0
- data/vendor/qwik/mock-socket.rb +82 -0
- data/vendor/qwik/modulobe.rb +406 -0
- data/vendor/qwik/mongrel-server.rb +72 -0
- data/vendor/qwik/page-files.rb +249 -0
- data/vendor/qwik/page-generate.rb +82 -0
- data/vendor/qwik/page-get.rb +262 -0
- data/vendor/qwik/page-images.rb +168 -0
- data/vendor/qwik/page-put.rb +128 -0
- data/vendor/qwik/page-rrefs.rb +154 -0
- data/vendor/qwik/page-title.rb +0 -0
- data/vendor/qwik/page-wikidb.rb +234 -0
- data/vendor/qwik/page.rb +67 -0
- data/vendor/qwik/pages.rb +444 -0
- data/vendor/qwik/parse-plugin.rb +249 -0
- data/vendor/qwik/parser-emode.rb +116 -0
- data/vendor/qwik/parser-inline.rb +273 -0
- data/vendor/qwik/parser.rb +350 -0
- data/vendor/qwik/password.rb +183 -0
- data/vendor/qwik/periodic.rb +79 -0
- data/vendor/qwik/qp.rb +56 -0
- data/vendor/qwik/qwik-service.rb +341 -0
- data/vendor/qwik/qwik.rb +5 -0
- data/vendor/qwik/qwikweb-adduser.rb +34 -0
- data/vendor/qwik/qwikweb-catalog-validator.rb +110 -0
- data/vendor/qwik/qwikweb-incgen.rb +28 -0
- data/vendor/qwik/qwikweb-makesite.rb +41 -0
- data/vendor/qwik/qwikweb-server.rb +44 -0
- data/vendor/qwik/qwikweb-showpassword.rb +26 -0
- data/vendor/qwik/qwikweb-watchlog.rb +67 -0
- data/vendor/qwik/request-path.rb +304 -0
- data/vendor/qwik/request-ua.rb +76 -0
- data/vendor/qwik/request-webrick.rb +81 -0
- data/vendor/qwik/request.rb +91 -0
- data/vendor/qwik/resolve-tdiary.rb +292 -0
- data/vendor/qwik/resolve.rb +121 -0
- data/vendor/qwik/response.rb +228 -0
- data/vendor/qwik/server-memory.rb +57 -0
- data/vendor/qwik/server-webrick.rb +102 -0
- data/vendor/qwik/server.rb +252 -0
- data/vendor/qwik/site-config.rb +149 -0
- data/vendor/qwik/site-db.rb +136 -0
- data/vendor/qwik/site-event.rb +162 -0
- data/vendor/qwik/site-files.rb +86 -0
- data/vendor/qwik/site-group.rb +103 -0
- data/vendor/qwik/site-index.rb +47 -0
- data/vendor/qwik/site-log.rb +64 -0
- data/vendor/qwik/site-member.rb +230 -0
- data/vendor/qwik/site-monitor.rb +97 -0
- data/vendor/qwik/site-pages.rb +62 -0
- data/vendor/qwik/site-plan.rb +139 -0
- data/vendor/qwik/site-report.rb +282 -0
- data/vendor/qwik/site-resolve.rb +230 -0
- data/vendor/qwik/site-rrefs.rb +18 -0
- data/vendor/qwik/site-search.rb +180 -0
- data/vendor/qwik/site-timeline.rb +153 -0
- data/vendor/qwik/site-url.rb +189 -0
- data/vendor/qwik/site.rb +76 -0
- data/vendor/qwik/smil-time.rb +105 -0
- data/vendor/qwik/smtp-session.rb +331 -0
- data/vendor/qwik/template-generator.rb +149 -0
- data/vendor/qwik/template.rb +85 -0
- data/vendor/qwik/test-common.rb +10 -0
- data/vendor/qwik/test-ml-info.rb +225 -0
- data/vendor/qwik/test-module-ml.rb +142 -0
- data/vendor/qwik/test-module-path.rb +110 -0
- data/vendor/qwik/test-module-public.rb +70 -0
- data/vendor/qwik/test-module-server.rb +98 -0
- data/vendor/qwik/test-module-session.rb +264 -0
- data/vendor/qwik/test-module-suite.rb +91 -0
- data/vendor/qwik/test-ms-applemail.rb +59 -0
- data/vendor/qwik/test-ms-attach.rb +174 -0
- data/vendor/qwik/test-ms-basic.rb +40 -0
- data/vendor/qwik/test-ms-close.rb +35 -0
- data/vendor/qwik/test-ms-confirm.rb +75 -0
- data/vendor/qwik/test-ms-ignore-spam.rb +57 -0
- data/vendor/qwik/test-ms-japanese.rb +97 -0
- data/vendor/qwik/test-ms-jfilename.rb +82 -0
- data/vendor/qwik/test-ms-large.rb +58 -0
- data/vendor/qwik/test-ms-member.rb +103 -0
- data/vendor/qwik/test-ms-multipart.rb +84 -0
- data/vendor/qwik/test-ms-org.rb +129 -0
- data/vendor/qwik/test-ms-plan.rb +130 -0
- data/vendor/qwik/test-ms-post.rb +53 -0
- data/vendor/qwik/test-ms-quopri.rb +76 -0
- data/vendor/qwik/test-sub-quopri.rb +45 -0
- data/vendor/qwik/test-submit-base64.rb +59 -0
- data/vendor/qwik/test-submit-forward.rb +61 -0
- data/vendor/qwik/test-submit-html-mail.rb +52 -0
- data/vendor/qwik/test-submit-japanese.rb +135 -0
- data/vendor/qwik/test-submit-jfilename.rb +144 -0
- data/vendor/qwik/test-submit-uuencode.rb +71 -0
- data/vendor/qwik/test-suite-all.rb +8 -0
- data/vendor/qwik/test-suite-basic.rb +9 -0
- data/vendor/qwik/test-suite-ml.rb +9 -0
- data/vendor/qwik/test-typekey.rb +64 -0
- data/vendor/qwik/testunit.rb +45 -0
- data/vendor/qwik/tokenizer-inline.rb +294 -0
- data/vendor/qwik/tokenizer.rb +332 -0
- data/vendor/qwik/typekey.rb +160 -0
- data/vendor/qwik/util-basic.rb +135 -0
- data/vendor/qwik/util-charset.rb +332 -0
- data/vendor/qwik/util-css.rb +56 -0
- data/vendor/qwik/util-csv-tokenizer.rb +113 -0
- data/vendor/qwik/util-filename.rb +112 -0
- data/vendor/qwik/util-pathname.rb +202 -0
- data/vendor/qwik/util-pid.rb +58 -0
- data/vendor/qwik/util-safe.rb +67 -0
- data/vendor/qwik/util-sendmail.rb +273 -0
- data/vendor/qwik/util-string.rb +203 -0
- data/vendor/qwik/util-time.rb +125 -0
- data/vendor/qwik/util-webrick.rb +176 -0
- data/vendor/qwik/version.rb +11 -0
- data/vendor/qwik/wabisabi-basic.rb +163 -0
- data/vendor/qwik/wabisabi-diff.rb +130 -0
- data/vendor/qwik/wabisabi-format-xml.rb +310 -0
- data/vendor/qwik/wabisabi-generator.rb +262 -0
- data/vendor/qwik/wabisabi-index.rb +174 -0
- data/vendor/qwik/wabisabi-table.rb +212 -0
- data/vendor/qwik/wabisabi-template.rb +295 -0
- data/vendor/qwik/wabisabi-to-htree.rb +111 -0
- data/vendor/qwik/wabisabi-to-wiki.rb +690 -0
- data/vendor/qwik/wabisabi-traverse.rb +207 -0
- data/vendor/qwik/wabisabi-validator.rb +116 -0
- data/vendor/qwik/wabisabi.rb +5 -0
- metadata +416 -0
|
@@ -0,0 +1,771 @@
|
|
|
1
|
+
# -*- coding: shift_jis -*-
|
|
2
|
+
# Copyright (C) 2003-2006 Kouichirou Eto, All rights reserved.
|
|
3
|
+
# This is free software with ABSOLUTELY NO WARRANTY.
|
|
4
|
+
# You can redistribute it and/or modify it under the terms of the GNU GPL 2.
|
|
5
|
+
|
|
6
|
+
$LOAD_PATH.unshift '..' unless $LOAD_PATH.include? '..'
|
|
7
|
+
|
|
8
|
+
module Qwik
|
|
9
|
+
class Action
|
|
10
|
+
D_ExtFiles = {
|
|
11
|
+
:dt => 'Attach file function',
|
|
12
|
+
:dd => 'You can attach files to pages.',
|
|
13
|
+
:dc => "* How to
|
|
14
|
+
Go to edit page, you see attach file form on the bottom.
|
|
15
|
+
You can attach many files at once by following 'attach many' link.
|
|
16
|
+
|
|
17
|
+
If you attached files, system automatically added link to the files.
|
|
18
|
+
{{file(\"somefile.txt\")}}
|
|
19
|
+
** Show attached files plugin
|
|
20
|
+
{{show_files}}
|
|
21
|
+
{{show_files}}
|
|
22
|
+
You can show the list of attached files.
|
|
23
|
+
"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
D_ExtFiles_ja = {
|
|
27
|
+
:dt => '�t�@�C���Y�t�@�\ ',
|
|
28
|
+
:dd => '�y�[�W�Ƀt�@�C����Y�t�ł��܂��B',
|
|
29
|
+
:dc => '* �g����
|
|
30
|
+
�ҏW��ʂ̈�ԉ��ɁA�t�@�C���Y�t�̂��߂̃t�H�[��������܂��B
|
|
31
|
+
�u\'\'\'��������Y�t����\'\'\'�v�Ƃ��������N�����ǂ�ƁA
|
|
32
|
+
��������̃t�@�C������x�ɓY�t���邽�߂̉�ʂɂƂт܂��B
|
|
33
|
+
|
|
34
|
+
�Y�t������ƁA�Ɏ����I�Ƀy�[�W�̈�ԉ��ɓY�t�t�@�C���ւ̃����N�����܂��B
|
|
35
|
+
{{file("somefile.txt")}}
|
|
36
|
+
** �Y�t�t�@�C���ꗗ�v���O�C��
|
|
37
|
+
{{show_files}}
|
|
38
|
+
�t�@�C���ꗗ��\���ł��܂��B
|
|
39
|
+
'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
# ============================== files list
|
|
43
|
+
def plg_show_files
|
|
44
|
+
div = [:div, {:class=>'files'},
|
|
45
|
+
[:h5, [:a, {:href=>"#{@req.base}.files"}, _('Files')]]]
|
|
46
|
+
list = files_list
|
|
47
|
+
div << [:ul, *list] if list
|
|
48
|
+
return div
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def files_list
|
|
52
|
+
return files_list_internal(@req.base, @site.files(@req.base))
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def files_list_internal(base, files)
|
|
56
|
+
list = files.list
|
|
57
|
+
return nil if list.empty?
|
|
58
|
+
return list.map {|file|
|
|
59
|
+
encoded = Filename.encode(file)
|
|
60
|
+
[:li, [:a, {:href=>"#{base}.files/#{encoded}"}, file.to_page_charset],
|
|
61
|
+
[:span, {:class=>'delete'},
|
|
62
|
+
' (', [:a, {:href=>"#{base}.file_del/#{encoded}"},
|
|
63
|
+
_('Delete')], ')'],
|
|
64
|
+
[:span, {:class=>'download'},
|
|
65
|
+
' (', [:a, {:href=>"#{base}.download/#{encoded}"},
|
|
66
|
+
_('Download')], ')'],
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# ============================== download
|
|
72
|
+
def ext_download
|
|
73
|
+
if 0 < @req.path_args.length # has target file
|
|
74
|
+
if @req.path_args[0] == '.theme'
|
|
75
|
+
@req.path_args.shift
|
|
76
|
+
return pre_act_theme
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
filename = files_parse_filename(@req.path_args)
|
|
80
|
+
files = @site.files(@req.base)
|
|
81
|
+
if files.nil? || ! files.exist?(filename)
|
|
82
|
+
return c_notfound(_('No such file'))
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
return c_download(files.path(filename).to_s) # Download it.
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
return c_nerror(_('Error'))
|
|
89
|
+
end
|
|
90
|
+
alias act_download ext_download
|
|
91
|
+
|
|
92
|
+
# ============================== files
|
|
93
|
+
def ext_files
|
|
94
|
+
if 0 < @req.path_args.length # has target file
|
|
95
|
+
if @req.path_args[0] == '.theme'
|
|
96
|
+
@req.path_args.shift
|
|
97
|
+
return pre_act_theme
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
filename = files_parse_filename(@req.path_args)
|
|
101
|
+
files = @site.files(@req.base)
|
|
102
|
+
if files.nil? || ! files.exist?(filename)
|
|
103
|
+
return c_notfound(_('No such file'))
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
if files_force_download?(filename)
|
|
107
|
+
return c_download(files.path(filename).to_s) # Download it.
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
if ! Filename.allowable_characters_for_path?(filename)
|
|
111
|
+
return c_download(files.path(filename).to_s) # Download it.
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
return c_simple_send(files.path(filename).to_s) # Send it.
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Upload the content.
|
|
118
|
+
content = @req.query['content']
|
|
119
|
+
return files_put(content) if content
|
|
120
|
+
|
|
121
|
+
# Show files form and the list.
|
|
122
|
+
return show_files_form_and_the_list
|
|
123
|
+
end
|
|
124
|
+
alias act_files ext_files
|
|
125
|
+
|
|
126
|
+
def show_files_form_and_the_list
|
|
127
|
+
c_require_member
|
|
128
|
+
ar = plg_files_form(20)
|
|
129
|
+
w = c_notice(_('Attach file')) {[
|
|
130
|
+
[:p, _('Attach a file')],
|
|
131
|
+
ar
|
|
132
|
+
]}
|
|
133
|
+
return w
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def files_parse_filename(args)
|
|
137
|
+
filename = args.join('/').set_url_charset # Must be UTF-8
|
|
138
|
+
filename = Filename.decode(filename)
|
|
139
|
+
return filename
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
FILES_FORCE_DOWNLOAD = %w(doc xls ppt html htm)
|
|
143
|
+
def files_force_download?(filename)
|
|
144
|
+
ext = filename.path.ext
|
|
145
|
+
FILES_FORCE_DOWNLOAD.detect { |bad_ext| bad_ext.downcase == ext.downcase }
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def ext_file_del
|
|
149
|
+
c_require_member
|
|
150
|
+
return c_nerror(_('Error')) if @req.path_args.length == 0
|
|
151
|
+
filename = files_parse_filename(@req.path_args)
|
|
152
|
+
|
|
153
|
+
if @req.path_args[0] == '.theme'
|
|
154
|
+
@req.path_args.shift
|
|
155
|
+
return pre_act_theme
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# confirm before delete
|
|
159
|
+
return files_delete_confirm(filename) unless @req.is_post?
|
|
160
|
+
return files_delete(filename) # delete it
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def files_delete_confirm(filename)
|
|
164
|
+
encoded = Filename.encode(filename)
|
|
165
|
+
action = "../#{@req.base}.file_del/#{encoded}" # Bad...
|
|
166
|
+
return c_notice(_('Confirm file deletion')) {
|
|
167
|
+
[:form, {:method=>'POST', :action=>action},
|
|
168
|
+
[:p, _("Push 'Delete' to delete a file")],
|
|
169
|
+
[:p, [:input, {:type=>'submit', :value=>_('Delete')}]]]
|
|
170
|
+
}
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def files_delete(filename)
|
|
174
|
+
c_require_post
|
|
175
|
+
url = "../#{@req.base}.html"
|
|
176
|
+
begin
|
|
177
|
+
@site.files(@req.base).delete(filename)
|
|
178
|
+
rescue FileNotExist
|
|
179
|
+
return c_nerror(_('Already deleted.'), url)
|
|
180
|
+
rescue FailedToDelete
|
|
181
|
+
return c_nerror(_('Failed to delete.'), url)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
c_make_log('file delete') # FILE DELETE
|
|
185
|
+
|
|
186
|
+
return c_notice(_('The file has been deleted.'), url) {
|
|
187
|
+
[:p, [:a, {:href=>url}, _('Go back')]]
|
|
188
|
+
}
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def plg_files_page_total
|
|
192
|
+
total = @site.files(@req.base).total
|
|
193
|
+
msg = sprintf(_("Total %s in this page"), total.byte_format)
|
|
194
|
+
return [:span, msg]
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def plg_files_site_total
|
|
198
|
+
total = @site.files_total
|
|
199
|
+
max_total = @config[:max_total_file_size]
|
|
200
|
+
warn_size = @config[:max_total_warn_size]
|
|
201
|
+
msg = _("Attached files total:") + " #{total.byte_format}"
|
|
202
|
+
if max_total < total
|
|
203
|
+
msg = [msg + ", ", [:strong, _('Total file size exceeded.')]]
|
|
204
|
+
elsif max_total - warn_size < total
|
|
205
|
+
warn_msg = sprintf(_("%s left"), (max_total - total).byte_format)
|
|
206
|
+
msg = [msg + ", ", [:strong ,warn_msg]]
|
|
207
|
+
end
|
|
208
|
+
return [:span, {:class => 'files_site_total'}, msg]
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# ==============================
|
|
212
|
+
def plg_files_form(upload_number=1)
|
|
213
|
+
files_form(@req.base, upload_number)
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# called from act-edit
|
|
217
|
+
def files_form(pagename, upload_number=1)
|
|
218
|
+
size = '40'
|
|
219
|
+
ar = []
|
|
220
|
+
upload_number.times {
|
|
221
|
+
ar << [:div, {:class=>'inputfile'},
|
|
222
|
+
[:input, {:type=>'file', :name=>'content'}]]
|
|
223
|
+
}
|
|
224
|
+
ar << [:div, {:class=>'input_submit'},
|
|
225
|
+
[:input, {:class=>'submit', :type=>'submit', :value=>_('Attach')}]]
|
|
226
|
+
form = [:form, {:action=>"#{pagename}.files",
|
|
227
|
+
:method=>'POST', :enctype=>'multipart/form-data'},
|
|
228
|
+
*ar]
|
|
229
|
+
return form
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
private
|
|
233
|
+
|
|
234
|
+
def files_put(content)
|
|
235
|
+
c_require_member
|
|
236
|
+
c_require_post
|
|
237
|
+
|
|
238
|
+
site_total = @site.files_total
|
|
239
|
+
max_total_file_size = @config[:max_total_file_size]
|
|
240
|
+
warn_size = @config[:max_total_warn_size]
|
|
241
|
+
|
|
242
|
+
list = []
|
|
243
|
+
content.each_data {|data|
|
|
244
|
+
fullfilename = data.filename
|
|
245
|
+
next if fullfilename.empty?
|
|
246
|
+
|
|
247
|
+
# Get basename.
|
|
248
|
+
#filename = fullfilename.path.basename.to_s
|
|
249
|
+
filename = Action.get_basename(fullfilename)
|
|
250
|
+
|
|
251
|
+
max_size = @site.siteconfig['max_file_size'].to_i
|
|
252
|
+
if max_size < data.length
|
|
253
|
+
list << [:p, [:strong, filename], [:em, _('Maximum size exceeded.')],
|
|
254
|
+
[:br],
|
|
255
|
+
_('Maximum size'), max_size, [:br],
|
|
256
|
+
_('File size'), data.length, [:br]]
|
|
257
|
+
next
|
|
258
|
+
elsif max_total_file_size < site_total
|
|
259
|
+
list << [:p, [:strong, filename], ' : ', [:em, _('The file is not saved.')],
|
|
260
|
+
[:br],
|
|
261
|
+
[:strong, _('Total file size exceeded.')],[:br],
|
|
262
|
+
_('Maximum total size'), max_total_file_size.byte_format, [:br],
|
|
263
|
+
_('Current total size'), site_total.byte_format, [:br]]
|
|
264
|
+
#get next even total file size is exceeded
|
|
265
|
+
#to display which files are not saved explicitly
|
|
266
|
+
next
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
# If the file is saved as another name, you can use return value.
|
|
270
|
+
filename = @site.files(@req.base).fput(filename, data)
|
|
271
|
+
|
|
272
|
+
c_make_log('file attach') # FILE ATTACH
|
|
273
|
+
site_total += data.length
|
|
274
|
+
|
|
275
|
+
page = @site[@req.base]
|
|
276
|
+
page.add("\n{{file(#{filename})}}\n") # files_update_page
|
|
277
|
+
|
|
278
|
+
if max_total_file_size < site_total
|
|
279
|
+
list << [:p, [:strong, filename], ' : ', _('The file is saved.'),
|
|
280
|
+
[:br],
|
|
281
|
+
[:strong, _('Exceeded limit.')]]
|
|
282
|
+
elsif max_total_file_size - warn_size < site_total
|
|
283
|
+
msg = _("Reaching limit.") + " " +
|
|
284
|
+
sprintf(_("%s left"), (max_total_file_size - site_total).byte_format)
|
|
285
|
+
list << [:p, [:strong, filename], ' : ', _('The file is saved.'),
|
|
286
|
+
[:br],
|
|
287
|
+
[:strong, msg]]
|
|
288
|
+
else
|
|
289
|
+
list << [:p, [:strong, filename], ' : ', _('The file is saved.')]
|
|
290
|
+
end
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
url = "#{@req.base}.html"
|
|
294
|
+
|
|
295
|
+
ar = list + [
|
|
296
|
+
[:hr],
|
|
297
|
+
[:p, _('Go next'), ' : ', [:a, {:href=>url}, url]],
|
|
298
|
+
]
|
|
299
|
+
return c_notice(_('File attachment completed'), url) { ar }
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
def self.get_basename(filename)
|
|
303
|
+
basename = filename.sub(/\A.*[\/\\]([^\/\\]+)\z/) { $1 }
|
|
304
|
+
return basename
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
if $0 == __FILE__
|
|
310
|
+
require 'qwik/test-common'
|
|
311
|
+
$test = true
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
if defined?($test) && $test
|
|
315
|
+
class TestActFiles < Test::Unit::TestCase
|
|
316
|
+
include TestSession
|
|
317
|
+
|
|
318
|
+
def test_files
|
|
319
|
+
t_add_user
|
|
320
|
+
|
|
321
|
+
ok_wi([:div, {:class=>'files'},
|
|
322
|
+
[:h5, [:a, {:href=>'1.files'}, 'Files']]],
|
|
323
|
+
'{{show_files}}')
|
|
324
|
+
|
|
325
|
+
page = @site['1']
|
|
326
|
+
page.store('t')
|
|
327
|
+
|
|
328
|
+
# See the form.
|
|
329
|
+
res = session('/test/1.files')
|
|
330
|
+
form = res.body.get_path("//div[@class='section']/form")
|
|
331
|
+
ok_eq({:method=>'POST', :action=>'1.files',
|
|
332
|
+
:enctype=>'multipart/form-data'}, form[1])
|
|
333
|
+
ok_eq([:div, {:class=>'inputfile'},
|
|
334
|
+
[:input, {:type=>'file', :name=>'content'}]], form[2])
|
|
335
|
+
ok_eq([:div, {:class=>'input_submit'},
|
|
336
|
+
[:input, {:value=>'Attach', :type=>'submit', :class=>'submit'}]],
|
|
337
|
+
form.last)
|
|
338
|
+
|
|
339
|
+
# Put a file.
|
|
340
|
+
res = session('POST /test/1.files') {|req|
|
|
341
|
+
req.query.update('content'=>t_make_content('t.txt', 't'))
|
|
342
|
+
}
|
|
343
|
+
ok_title('File attachment completed')
|
|
344
|
+
|
|
345
|
+
# Check log.
|
|
346
|
+
eq(",0.000000,user@e.com,file attach,1\n", @site['_SiteLog'].load)
|
|
347
|
+
|
|
348
|
+
# The reference is added.
|
|
349
|
+
ok_eq('t
|
|
350
|
+
|
|
351
|
+
{{file(t.txt)}}
|
|
352
|
+
', page.load)
|
|
353
|
+
|
|
354
|
+
# Get the file.
|
|
355
|
+
res = session('/test/1.files/t.txt')
|
|
356
|
+
ok_eq('t', res.body)
|
|
357
|
+
ok_eq('text/plain', res['Content-Type'])
|
|
358
|
+
|
|
359
|
+
# Put a file with same file name again.
|
|
360
|
+
# The file is saved as another filename.
|
|
361
|
+
res = session('POST /test/1.files') {|req|
|
|
362
|
+
req.query.update('content'=>t_make_content('t.txt', 't2'))
|
|
363
|
+
}
|
|
364
|
+
ok_title('File attachment completed')
|
|
365
|
+
ok_xp([:p, [:strong, '1-t.txt'], ' : ',
|
|
366
|
+
'The file is saved.'],
|
|
367
|
+
"//div[@class='section']/p")
|
|
368
|
+
|
|
369
|
+
# Delete the second file.
|
|
370
|
+
res = session('POST /test/1.file_del/1-t.txt')
|
|
371
|
+
ok_title('The file has been deleted.')
|
|
372
|
+
|
|
373
|
+
# See the page again.
|
|
374
|
+
ok_wi([:div, {:class=>'files'},
|
|
375
|
+
[:h5, [:a, {:href=>'1.files'}, 'Files']],
|
|
376
|
+
[:ul,
|
|
377
|
+
[:li, [:a, {:href=>'1.files/t.txt'}, 't.txt'],
|
|
378
|
+
[:span, {:class=>'delete'},
|
|
379
|
+
" (", [:a, {:href=>"1.file_del/t.txt"}, 'Delete'], ")"],
|
|
380
|
+
[:span, {:class=>'download'},
|
|
381
|
+
" (", [:a, {:href=>'1.download/t.txt'}, 'Download'],
|
|
382
|
+
")"]]]],
|
|
383
|
+
'{{show_files}}')
|
|
384
|
+
|
|
385
|
+
# Put another file.
|
|
386
|
+
res = session('POST /test/1.files') {|req|
|
|
387
|
+
req.query.update('content'=>t_make_content('s.png', TEST_PNG_DATA))
|
|
388
|
+
}
|
|
389
|
+
ok_title('File attachment completed')
|
|
390
|
+
|
|
391
|
+
# The reference is added too.
|
|
392
|
+
ok_eq('{{show_files}}
|
|
393
|
+
|
|
394
|
+
{{file(s.png)}}
|
|
395
|
+
', page.load)
|
|
396
|
+
|
|
397
|
+
# See the page again.
|
|
398
|
+
res = session('/test/1.html')
|
|
399
|
+
ok_xp([:div, {:class=>'files'},
|
|
400
|
+
[:h5, [:a, {:href=>'1.files'}, 'Files']],
|
|
401
|
+
[:ul,
|
|
402
|
+
[:li, [:a, {:href=>'1.files/s.png'}, 's.png'],
|
|
403
|
+
[:span, {:class=>'delete'},
|
|
404
|
+
" (", [:a, {:href=>"1.file_del/s.png"}, 'Delete'], ")"],
|
|
405
|
+
[:span, {:class=>'download'},
|
|
406
|
+
" (", [:a, {:href=>'1.download/s.png'},
|
|
407
|
+
'Download'], ")"]],
|
|
408
|
+
[:li, [:a, {:href=>'1.files/t.txt'}, 't.txt'],
|
|
409
|
+
[:span, {:class=>'delete'},
|
|
410
|
+
" (", [:a, {:href=>"1.file_del/t.txt"}, 'Delete'], ")"],
|
|
411
|
+
[:span, {:class=>'download'},
|
|
412
|
+
" (", [:a, {:href=>'1.download/t.txt'},
|
|
413
|
+
'Download'], ")"]]]],
|
|
414
|
+
"//div[@class='files']")
|
|
415
|
+
|
|
416
|
+
# Show a form to delete the file.
|
|
417
|
+
res = session('/test/1.file_del/t.txt')
|
|
418
|
+
ok_title('Confirm file deletion')
|
|
419
|
+
|
|
420
|
+
# Delete it.
|
|
421
|
+
res = session('POST /test/1.file_del/t.txt')
|
|
422
|
+
ok_title('The file has been deleted.')
|
|
423
|
+
|
|
424
|
+
# Try to delete it again. But the file is already deleted.
|
|
425
|
+
res = session('POST /test/1.file_del/t.txt')
|
|
426
|
+
ok_title('Already deleted.')
|
|
427
|
+
|
|
428
|
+
# Try to get file agin. But the file is already deleted.
|
|
429
|
+
res = session('/test/1.files/t.txt')
|
|
430
|
+
ok_title('No such file')
|
|
431
|
+
end
|
|
432
|
+
|
|
433
|
+
def test_multi_files
|
|
434
|
+
t_add_user
|
|
435
|
+
page = @site.create_new
|
|
436
|
+
|
|
437
|
+
# See the form.
|
|
438
|
+
res = session('/test/1.files')
|
|
439
|
+
form = @res.body.get_path("//div[@class='section']/form")
|
|
440
|
+
ok_eq({:method=>'POST', :action=>'1.files',
|
|
441
|
+
:enctype=>'multipart/form-data'}, form[1])
|
|
442
|
+
ok_eq([:div, {:class=>'inputfile'},
|
|
443
|
+
[:input, {:type=>'file', :name=>'content'}]], form[2])
|
|
444
|
+
ok_eq([:div, {:class=>'inputfile'},
|
|
445
|
+
[:input, { :type=>'file', :name=>'content'}]], form[4])
|
|
446
|
+
ok_eq([:div, {:class=>'input_submit'},
|
|
447
|
+
[:input, {:value=>'Attach', :type=>'submit', :class=>'submit'}]],
|
|
448
|
+
form.last)
|
|
449
|
+
|
|
450
|
+
# Put multiple files.
|
|
451
|
+
content1 = t_make_content('t1.txt', 't1')
|
|
452
|
+
content2 = t_make_content('t2.txt', 't2')
|
|
453
|
+
content1.append_data(content2)
|
|
454
|
+
res = session('POST /test/1.files') {|req|
|
|
455
|
+
req.query.update('content'=>content1)
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
ok_title('File attachment completed')
|
|
459
|
+
ok_in([
|
|
460
|
+
[:p, [:strong, 't1.txt'], ' : ', 'The file is saved.'],
|
|
461
|
+
[:p, [:strong, 't2.txt'], ' : ', 'The file is saved.'],
|
|
462
|
+
[:hr],
|
|
463
|
+
[:p, 'Go next', ' : ',
|
|
464
|
+
[:a, {:href=>'1.html'}, '1.html']]],
|
|
465
|
+
"//div[@class='section']")
|
|
466
|
+
|
|
467
|
+
# The reference is added.
|
|
468
|
+
ok_eq('
|
|
469
|
+
{{file(t1.txt)}}
|
|
470
|
+
|
|
471
|
+
{{file(t2.txt)}}
|
|
472
|
+
', page.load)
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
def test_act_files
|
|
476
|
+
t_add_user
|
|
477
|
+
|
|
478
|
+
page = @site['FrontPage']
|
|
479
|
+
page.store('t')
|
|
480
|
+
|
|
481
|
+
# See the form.
|
|
482
|
+
res = session('/test/.files')
|
|
483
|
+
form = res.body.get_path("//div[@class='section']/form")
|
|
484
|
+
ok_eq({:method=>'POST', :action=>'FrontPage.files',
|
|
485
|
+
:enctype=>'multipart/form-data'}, form[1])
|
|
486
|
+
|
|
487
|
+
# Put a file.
|
|
488
|
+
res = session('POST /test/.files') {|req|
|
|
489
|
+
req.query.update('content'=>t_make_content('t.txt', 't'))
|
|
490
|
+
}
|
|
491
|
+
ok_title('File attachment completed')
|
|
492
|
+
|
|
493
|
+
# Check log.
|
|
494
|
+
eq(",0.000000,user@e.com,file attach,FrontPage\n", @site['_SiteLog'].load)
|
|
495
|
+
|
|
496
|
+
# The reference is added.
|
|
497
|
+
ok_eq('t
|
|
498
|
+
|
|
499
|
+
{{file(t.txt)}}
|
|
500
|
+
', page.load)
|
|
501
|
+
|
|
502
|
+
# Get the file.
|
|
503
|
+
res = session('/test/.files/t.txt')
|
|
504
|
+
ok_eq('t', res.body)
|
|
505
|
+
end
|
|
506
|
+
|
|
507
|
+
def test_jfilename
|
|
508
|
+
t_add_user
|
|
509
|
+
|
|
510
|
+
page = @site.create_new
|
|
511
|
+
page.store('t')
|
|
512
|
+
|
|
513
|
+
# Put a file with Japanese filename.
|
|
514
|
+
res = session('POST /test/1.files') {|req|
|
|
515
|
+
req.query.update('content'=>t_make_content('��.txt', 't'))
|
|
516
|
+
}
|
|
517
|
+
ok_title('File attachment completed')
|
|
518
|
+
|
|
519
|
+
# Check log.
|
|
520
|
+
ok_eq(",0.000000,user@e.com,file attach,1\n", @site['_SiteLog'].load)
|
|
521
|
+
|
|
522
|
+
# The reference is added.
|
|
523
|
+
ok_eq('t
|
|
524
|
+
|
|
525
|
+
{{file(��.txt)}}
|
|
526
|
+
', page.load)
|
|
527
|
+
|
|
528
|
+
# Get the file.
|
|
529
|
+
res = session('/test/1.files/=E3=81=82.txt')
|
|
530
|
+
ok_eq('t', res.body)
|
|
531
|
+
|
|
532
|
+
# You can use SJIS charset.
|
|
533
|
+
res = session('/test/1.files/��.txt')
|
|
534
|
+
ok_eq('t', res.body)
|
|
535
|
+
|
|
536
|
+
# You can use UTF-8 charset.
|
|
537
|
+
res = session('/test/1.files/��.txt'.set_sourcecode_charset.to_url_charset)
|
|
538
|
+
ok_eq('t', res.body)
|
|
539
|
+
|
|
540
|
+
# Delete it.
|
|
541
|
+
res = session('POST /test/1.file_del/=E3=81=82.txt')
|
|
542
|
+
ok_title('The file has been deleted.')
|
|
543
|
+
end
|
|
544
|
+
|
|
545
|
+
def test_download
|
|
546
|
+
t_add_user
|
|
547
|
+
|
|
548
|
+
page = @site.create_new
|
|
549
|
+
page.store('t')
|
|
550
|
+
|
|
551
|
+
# Put a file.
|
|
552
|
+
res = session('POST /test/1.files') {|req|
|
|
553
|
+
req.query.update('content'=>t_make_content('t.txt', 't'))
|
|
554
|
+
}
|
|
555
|
+
ok_title('File attachment completed')
|
|
556
|
+
|
|
557
|
+
# Error check.
|
|
558
|
+
res = session('/test/1.download')
|
|
559
|
+
ok_title('Error')
|
|
560
|
+
|
|
561
|
+
# Download the file.
|
|
562
|
+
res = session('/test/1.download/t.txt')
|
|
563
|
+
ok_eq('text/plain', res['Content-Type'])
|
|
564
|
+
ok_eq("attachment; filename=\"t.txt\"", res['Content-Disposition'])
|
|
565
|
+
ok_eq('t', res.body)
|
|
566
|
+
|
|
567
|
+
# Put a file with Japanese filename.
|
|
568
|
+
res = session('POST /test/1.files') {|req|
|
|
569
|
+
req.query.update('content'=>t_make_content('��.txt', 't'))
|
|
570
|
+
}
|
|
571
|
+
ok_title('File attachment completed')
|
|
572
|
+
|
|
573
|
+
# Download the file.
|
|
574
|
+
res = session('/test/1.download/=E3=81=82.txt')
|
|
575
|
+
ok_eq('text/plain', res['Content-Type'])
|
|
576
|
+
ok_eq("attachment; filename=\"��.txt\"",
|
|
577
|
+
res['Content-Disposition'])
|
|
578
|
+
ok_eq('t', res.body)
|
|
579
|
+
end
|
|
580
|
+
|
|
581
|
+
def test_force_download
|
|
582
|
+
t_add_user
|
|
583
|
+
|
|
584
|
+
page = @site.create_new
|
|
585
|
+
page.store('t')
|
|
586
|
+
|
|
587
|
+
# Put a file.
|
|
588
|
+
res = session('POST /test/1.files') {|req|
|
|
589
|
+
req.query.update('content'=>t_make_content('t.doc', 't'))
|
|
590
|
+
}
|
|
591
|
+
ok_title('File attachment completed')
|
|
592
|
+
|
|
593
|
+
# Download the file.
|
|
594
|
+
res = session('/test/1.download/t.doc')
|
|
595
|
+
ok_eq('application/msword', res['Content-Type'])
|
|
596
|
+
ok_eq("attachment; filename=\"t.doc\"", res['Content-Disposition'])
|
|
597
|
+
ok_eq('t', res.body)
|
|
598
|
+
|
|
599
|
+
# Download by files extension.
|
|
600
|
+
res = session('/test/1.files/t.doc')
|
|
601
|
+
ok_eq('application/msword', res['Content-Type'])
|
|
602
|
+
ok_eq("attachment; filename=\"t.doc\"", res['Content-Disposition'])
|
|
603
|
+
ok_eq('t', res.body)
|
|
604
|
+
end
|
|
605
|
+
|
|
606
|
+
def test_force_download_capital_ext
|
|
607
|
+
t_add_user
|
|
608
|
+
|
|
609
|
+
page = @site.create_new
|
|
610
|
+
page.store('t')
|
|
611
|
+
|
|
612
|
+
# Put a file.
|
|
613
|
+
res = session('POST /test/1.files') {|req|
|
|
614
|
+
req.query.update('content'=>t_make_content('T.DOC', 't'))
|
|
615
|
+
}
|
|
616
|
+
ok_title('File attachment completed')
|
|
617
|
+
|
|
618
|
+
# Download the file.
|
|
619
|
+
res = session('/test/1.download/T.DOC')
|
|
620
|
+
ok_eq('application/msword', res['Content-Type'])
|
|
621
|
+
ok_eq("attachment; filename=\"T.DOC\"", res['Content-Disposition'])
|
|
622
|
+
ok_eq('t', res.body)
|
|
623
|
+
|
|
624
|
+
# Download by files extension.
|
|
625
|
+
res = session('/test/1.files/T.DOC')
|
|
626
|
+
ok_eq('application/msword', res['Content-Type'])
|
|
627
|
+
ok_eq("attachment; filename=\"T.DOC\"", res['Content-Disposition'])
|
|
628
|
+
ok_eq('t', res.body)
|
|
629
|
+
end
|
|
630
|
+
|
|
631
|
+
def test_class_method
|
|
632
|
+
c = Qwik::Action
|
|
633
|
+
eq("a.txt", c.get_basename("/tmp/a.txt"))
|
|
634
|
+
eq("a.txt", c.get_basename("c:\\tmp\\a.txt"))
|
|
635
|
+
end
|
|
636
|
+
|
|
637
|
+
def test_upload_from_windows
|
|
638
|
+
t_add_user
|
|
639
|
+
|
|
640
|
+
page = @site.create_new
|
|
641
|
+
page.store('t')
|
|
642
|
+
|
|
643
|
+
# Put a file.
|
|
644
|
+
res = session('POST /test/1.files') {|req|
|
|
645
|
+
req.query.update('content'=>t_make_content("c:\\tmp\\t.txt", 't'))
|
|
646
|
+
}
|
|
647
|
+
ok_title('File attachment completed')
|
|
648
|
+
|
|
649
|
+
# Download by files extension.
|
|
650
|
+
res = session('/test/1.files/t.txt')
|
|
651
|
+
ok_eq('text/plain', res['Content-Type'])
|
|
652
|
+
ok_eq('t', res.body)
|
|
653
|
+
end
|
|
654
|
+
|
|
655
|
+
def test_big_file
|
|
656
|
+
t_add_user
|
|
657
|
+
|
|
658
|
+
# Set max_file_size to 1MB.
|
|
659
|
+
config = @site['_SiteConfig']
|
|
660
|
+
max_size = 1 * 1024 * 1024 # 1MB
|
|
661
|
+
config.store(":max_file_size:#{max_size}")
|
|
662
|
+
|
|
663
|
+
page = @site.create_new
|
|
664
|
+
page.store('t')
|
|
665
|
+
|
|
666
|
+
# Try to store a file with 2MB size.
|
|
667
|
+
big_content = '0' * (2 * 1024 * 1024) # 2MB
|
|
668
|
+
res = session('POST /test/1.files') {|req|
|
|
669
|
+
req.query.update('content'=>t_make_content('t.txt', big_content))
|
|
670
|
+
}
|
|
671
|
+
ok_title('File attachment completed')
|
|
672
|
+
ok_in(['Maximum size exceeded.'],
|
|
673
|
+
"//div[@class='section']/p/em")
|
|
674
|
+
|
|
675
|
+
# Get the file.
|
|
676
|
+
res = session('/test/1.files/t.txt')
|
|
677
|
+
ok_title('No such file')
|
|
678
|
+
end
|
|
679
|
+
|
|
680
|
+
def test_force_download_by_character
|
|
681
|
+
t_add_user
|
|
682
|
+
|
|
683
|
+
page = @site.create_new
|
|
684
|
+
page.store('t')
|
|
685
|
+
|
|
686
|
+
# Put a file.
|
|
687
|
+
res = session('POST /test/1.files') {|req|
|
|
688
|
+
req.query.update('content'=>t_make_content('t!.txt', 't'))
|
|
689
|
+
}
|
|
690
|
+
ok_title('File attachment completed')
|
|
691
|
+
|
|
692
|
+
# Download the file.
|
|
693
|
+
res = session('/test/1.download/t!.txt')
|
|
694
|
+
ok_eq("attachment; filename=\"t!.txt\"", res['Content-Disposition'])
|
|
695
|
+
ok_eq('t', res.body)
|
|
696
|
+
|
|
697
|
+
# Download by files extension.
|
|
698
|
+
res = session('/test/1.files/t!.txt')
|
|
699
|
+
ok_eq("attachment; filename=\"t!.txt\"", res['Content-Disposition'])
|
|
700
|
+
ok_eq('t', res.body)
|
|
701
|
+
end
|
|
702
|
+
|
|
703
|
+
def test_total_file_size_limit
|
|
704
|
+
t_add_user
|
|
705
|
+
|
|
706
|
+
def attach(size)
|
|
707
|
+
content = '0' * size
|
|
708
|
+
filename = "#{size.byte_format}.txt"
|
|
709
|
+
res = session('POST /test/1.files') {|req|
|
|
710
|
+
req.query.update('content'=>t_make_content(filename, content))
|
|
711
|
+
}
|
|
712
|
+
ok_title('File attachment completed')
|
|
713
|
+
return filename,content
|
|
714
|
+
end
|
|
715
|
+
# Set max_total_file_size to 1MB and warn 256KB
|
|
716
|
+
default_max_total_file_size = @config[:max_total_file_size]
|
|
717
|
+
default_max_total_warn_size = @config[:max_total_warn_size]
|
|
718
|
+
@config[:max_total_file_size] = 1 * 1024 * 1024 # 1MB
|
|
719
|
+
@config[:max_total_warn_size] = 256 * 1024 # 256KB
|
|
720
|
+
|
|
721
|
+
page = @site.create_new
|
|
722
|
+
page.store('t')
|
|
723
|
+
|
|
724
|
+
## Try to store a file with 512KB size.
|
|
725
|
+
filename,content = attach(512*1024)
|
|
726
|
+
ok_xp([:p, [:strong, filename], ' : ', 'The file is saved.'],
|
|
727
|
+
"//div[@class='section']/p")
|
|
728
|
+
|
|
729
|
+
# Get the file.
|
|
730
|
+
res = session("/test/1.files/#{filename}")
|
|
731
|
+
ok_eq(content,res.body)
|
|
732
|
+
|
|
733
|
+
## Try to store a file with 300KB size. will get the warning
|
|
734
|
+
filename,content = attach(300*1024)
|
|
735
|
+
ok_xp([:p, [:strong, filename], ' : ', 'The file is saved.',
|
|
736
|
+
[:br], [:strong, "Reaching limit. 212KB left"]],
|
|
737
|
+
"//div[@class='section']/p")
|
|
738
|
+
|
|
739
|
+
# Get the file.
|
|
740
|
+
res = session("/test/1.files/#{filename}")
|
|
741
|
+
ok_eq(content,res.body)
|
|
742
|
+
|
|
743
|
+
## Try to store a file with 300KB size. will exceeds the limit
|
|
744
|
+
filename,content = attach(256*1024)
|
|
745
|
+
ok_xp([:p, [:strong, filename], ' : ', 'The file is saved.',
|
|
746
|
+
[:br], [:strong, "Exceeded limit."]],
|
|
747
|
+
"//div[@class='section']/p")
|
|
748
|
+
|
|
749
|
+
# Get the file.
|
|
750
|
+
res = session("/test/1.files/#{filename}")
|
|
751
|
+
ok_eq(content,res.body)
|
|
752
|
+
|
|
753
|
+
## Try to store a file with 300KB size. will exceeds the limit
|
|
754
|
+
filename,content = attach(1)
|
|
755
|
+
ok_xp([:p, [:strong, filename], ' : ', [:em, 'The file is not saved.'],
|
|
756
|
+
[:br],
|
|
757
|
+
[:strong, "Total file size exceeded."],[:br],
|
|
758
|
+
'Maximum total size', @config[:max_total_file_size].byte_format, [:br],
|
|
759
|
+
'Current total size', ((512+300+256)*1024).byte_format, [:br]],
|
|
760
|
+
"//div[@class='section']/p")
|
|
761
|
+
|
|
762
|
+
# Get the file.
|
|
763
|
+
res = session("/test/1.files/#{filename}")
|
|
764
|
+
ok_title('No such file')
|
|
765
|
+
|
|
766
|
+
#clean up
|
|
767
|
+
@config[:max_total_file_size] = default_max_total_file_size
|
|
768
|
+
@config[:max_total_warn_size] = default_max_total_warn_size
|
|
769
|
+
end
|
|
770
|
+
end
|
|
771
|
+
end
|