Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 2
- Log:
Initial import of Instiki 0.11.0 sources from a downloaded Tarball.
Instiki is a Ruby On Rails based Wiki clone.
- Author:
- adh
- Date:
- Sat Jul 22 14:54:51 +0100 2006
- Size:
- 3029 Bytes
1 | # Controller responsible for serving files and pictures. |
2 | |
3 | class FileController < ApplicationController |
4 | |
5 | layout 'default' |
6 | |
7 | before_filter :check_allow_uploads |
8 | |
9 | def file |
10 | if @params['file'] |
11 | # form supplied |
12 | new_file = @web.wiki_files.create(@params['file']) |
13 | if new_file.valid? |
14 | flash[:info] = "File '#{@file_name}' successfully uploaded" |
15 | return_to_last_remembered |
16 | else |
17 | # pass the file with errors back into the form |
18 | @file = new_file |
19 | render |
20 | end |
21 | else |
22 | render(:status => 404, :text => 'Unspecified file name') and return unless @file_name |
23 | # no form supplied, this is a request to download the file |
24 | file = WikiFile.find_by_file_name(@file_name) |
25 | if file |
26 | send_data(file.content, determine_file_options_for(@file_name, :filename => @file_name)) |
27 | else |
28 | @file = WikiFile.new(:file_name => @file_name) |
29 | render |
30 | end |
31 | end |
32 | end |
33 | |
34 | def cancel_upload |
35 | return_to_last_remembered |
36 | end |
37 | |
38 | def import |
39 | if @params['file'] |
40 | @problems = [] |
41 | import_file_name = "#{@web.address}-import-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.zip" |
42 | file_yard.upload_file(import_file_name, @params['file']) |
43 | import_from_archive(file_yard.file_path(import_file_name)) |
44 | if @problems.empty? |
45 | flash[:info] = 'Import successfully finished' |
46 | else |
47 | flash[:error] = 'Import finished, but some pages were not imported:<li>' + |
48 | @problems.join('</li><li>') + '</li>' |
49 | end |
50 | return_to_last_remembered |
51 | else |
52 | # to template |
53 | end |
54 | end |
55 | |
56 | protected |
57 | |
58 | def check_allow_uploads |
59 | if @web.allow_uploads? |
60 | return true |
61 | else |
62 | render :status => 403, :text => 'File uploads are blocked by the webmaster' |
63 | return false |
64 | end |
65 | end |
66 | |
67 | def connect_to_model |
68 | super |
69 | @file_name = @params['id'] |
70 | end |
71 | |
72 | private |
73 | |
74 | def import_from_archive(archive) |
75 | logger.info "Importing pages from #{archive}" |
76 | zip = Zip::ZipInputStream.open(archive) |
77 | while (entry = zip.get_next_entry) do |
78 | ext_length = File.extname(entry.name).length |
79 | page_name = entry.name[0..-(ext_length + 1)] |
80 | page_content = entry.get_input_stream.read |
81 | logger.info "Processing page '#{page_name}'" |
82 | begin |
83 | existing_page = @wiki.read_page(@web.address, page_name) |
84 | if existing_page |
85 | if existing_page.content == page_content |
86 | logger.info "Page '#{page_name}' with the same content already exists. Skipping." |
87 | next |
88 | else |
89 | logger.info "Page '#{page_name}' already exists. Adding a new revision to it." |
90 | wiki.revise_page(@web.address, page_name, page_content, Time.now, @author) |
91 | end |
92 | else |
93 | wiki.write_page(@web.address, page_name, page_content, Time.now, @author) |
94 | end |
95 | rescue => e |
96 | logger.error(e) |
97 | @problems << "#{page_name} : #{e.message}" |
98 | end |
99 | end |
100 | logger.info "Import from #{archive} finished" |
101 | end |
102 | |
103 | end |