Wiki source code of FileUpload
Last modified by Ludovic Dubost on 2008/09/05 10:35
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | |||
2 | |||
3 | #info("This form includes a form with file upload and with a wysiwyg editor") | ||
4 | #set($showcomments="no") | ||
5 | #set($showattachments="no") | ||
6 | #if($request.title) | ||
7 | #set($space = $doc.space) | ||
8 | #set($page = $xwiki.getUniquePageName($space, $request.title)) | ||
9 | #set($newdoc = $xwiki.getDocument("${space}.${page}")) | ||
10 | #set($attachgroovy = $xwiki.parseGroovyFromPage("Code.FileUploadGroovy")) | ||
11 | #if($attachgroovy=="groovy_missingrights") | ||
12 | #warning($msg.get("fileupload.uploadgroovyneedsrights")) | ||
13 | #else | ||
14 | #set($nb = $attachgroovy.addAttachments($newdoc, $context)) | ||
15 | #if($nb==-10) | ||
16 | #warning($msg.get("fileupload.currentpageneedsrights", [$doc.fullName])) | ||
17 | #else | ||
18 | ## Updating the page content | ||
19 | #set($attachText = "") | ||
20 | #set($attachList = $newdoc.getAttachmentList()) | ||
21 | #if($attachList.size()>0) | ||
22 | #set($attach = $attachList.get(0)) | ||
23 | #set($url = $newdoc.getAttachmentURL($attach.filename)) | ||
24 | #set($text = $msg.get("fileupload.uploadattachmenttext", [$url, $attach.filename])) | ||
25 | #set($attachText = "${xwiki.nl}${xwiki.nl}${text}") | ||
26 | #end | ||
27 | ## Updating the page content | ||
28 | #set($content = "1 ${request.title}${xwiki.nl}${xwiki.nl}${request.content}") | ||
29 | #if($request.link&&$request.link!="") | ||
30 | #set($content = "${content}${xwiki.nl}${xwiki.nl}Link: ${request.link}") | ||
31 | #end | ||
32 | #set($content = "${content}${attachText}") | ||
33 | ## update and save the document | ||
34 | $newdoc.setContent($content) | ||
35 | $newdoc.setTitle($request.title) | ||
36 | #if($newdoc.getObject("XWiki.TagClass")) | ||
37 | #set($ok = $newdoc.use("XWiki.TagClass")) | ||
38 | #else | ||
39 | #set($ok = $newdoc.use($newdoc.newObject("XWiki.TagClass"))) | ||
40 | #end | ||
41 | $newdoc.set("tags", "article") | ||
42 | $newdoc.save() | ||
43 | #set($message = $msg.get("fileuploadform.articlehasbeencreated")) | ||
44 | #info("$message: [$newdoc.displayTitle>$newdoc.fullName].") | ||
45 | #end ## if nb==-10 | ||
46 | #end ## if has not prog rights | ||
47 | #else | ||
48 | #set($space = $doc.space) | ||
49 | #set($page = $xwiki.getUniquePageName($space, "")) | ||
50 | #set($newdoc = $xwiki.getDocument("${space}.${page}")) | ||
51 | 1.1 $msg.get("fileupload.creatingarticleinspace") $space | ||
52 | <form id="uploadFilesForm" action="" enctype="multipart/form-data" method="POST"> | ||
53 | <table id="uploadFilesTable"> | ||
54 | <tr> | ||
55 | <td style="text-align:right;">$msg.get("fileupload.pagetitle"):</td> | ||
56 | <td> | ||
57 | <input type="text" id="title" name="title" size="50" style="width:100%"> | ||
58 | </td> | ||
59 | </tr> | ||
60 | <tr> | ||
61 | <td style="text-align:right;vertical-align:top;">$msg.get("fileupload.pagecontent"):</td> | ||
62 | <td> | ||
63 | $newdoc.getTextArea() | ||
64 | </td> | ||
65 | </tr> | ||
66 | <tr> | ||
67 | <td style="text-align:right;">$msg.get("fileupload.link"):</td> | ||
68 | <td> | ||
69 | <input type="text" name="link" style="width:100%"> | ||
70 | </td> | ||
71 | </tr> | ||
72 | <tr> | ||
73 | <td style="text-align:right;">$msg.get("fileupload.choosefile"):</td> | ||
74 | <td><input type="file" id="filepath" name="filepath" size="50" style="width:100%;"></td> | ||
75 | </tr> | ||
76 | <tr> | ||
77 | <td></td> | ||
78 | <td><input type="submit" value="$msg.get("fileupload.createarticle")"></td> | ||
79 | <tr> | ||
80 | </table> | ||
81 | </form> | ||
82 | ## Integrating the wysiwyg editor. This is the way the editor should be integrated | ||
83 | {pre} | ||
84 | <script type="text/javascript" src="${request.contextPath}/tiny_mce/tiny_mce.js"></script> | ||
85 | <script type="text/javascript" src="${request.contextPath}/wiki_editor/wiki_editor.js"></script> | ||
86 | <script type="text/javascript"> | ||
87 | //<![CDATA[ | ||
88 | wikiEditor.init({ | ||
89 | elements : "content", | ||
90 | language: "en", | ||
91 | mode: "exact", | ||
92 | content_css: "$xwiki.getSkinFile("style.css")", | ||
93 | debug : false, | ||
94 | remove_linebreaks : false, | ||
95 | plugins: 'table, contextmenu, paste, searchreplace', | ||
96 | wiki_use_style: '$xwiki.useWysiwygStyleToolbar()', | ||
97 | wiki_images_path : '${request.contextPath}/bin/download/$doc.space/$doc.name/', | ||
98 | wiki_attach_path : '${request.contextPath}/bin/view/$doc.space/$doc.name', | ||
99 | wiki_macro_path : '${request.contextPath}/bin/view/$doc.space/$doc.name', | ||
100 | wiki_plugins: 'core' | ||
101 | }); | ||
102 | //]]> | ||
103 | </script> | ||
104 | {/pre} | ||
105 | #end |