Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 344
- Log:
Massive changeset which brings the old, ROOL customised Instiki
version up to date, but without any ROOL customisations in this
latest checked-in version (which is 0.19.1). This is deliberate,
so that it's easy to see the changes made for the ROOL version
in a subsequent changeset. The 'app/views/shared' directory is not
part of Instiki but is kept to maintain the change history with
updated ROOL customisations, some of which involve the same files
in that same directory.
- Author:
- rool
- Date:
- Sat Mar 19 19:52:13 +0000 2011
- Size:
- 4207 Bytes
1 | # Controller responsible for serving files and pictures. |
2 | |
3 | require 'zip/zip' |
4 | require 'instiki_stringsupport' |
5 | |
6 | class FileController < ApplicationController |
7 | |
8 | layout 'default' |
9 | |
10 | before_filter :check_authorized |
11 | before_filter :check_allow_uploads, :dnsbl_check, :except => [:file, :blahtex_png] |
12 | |
13 | def file |
14 | @file_name = params['id'] |
15 | if params['file'] |
16 | return unless is_post and check_allow_uploads |
17 | # form supplied |
18 | new_file = @web.wiki_files.create(params['file']) |
19 | if new_file.valid? |
20 | flash[:info] = "File '#{@file_name}' successfully uploaded" |
21 | redirect_to(params['referring_page']) |
22 | else |
23 | # pass the file with errors back into the form |
24 | @file = new_file |
25 | render |
26 | end |
27 | else |
28 | # no form supplied, this is a request to download the file |
29 | file = @web.files_path.join(@file_name) |
30 | if File.exists?(file) |
31 | send_file(file) |
32 | else |
33 | return unless check_allow_uploads |
34 | @file = WikiFile.new(:file_name => @file_name) |
35 | render |
36 | end |
37 | end |
38 | end |
39 | |
40 | def blahtex_png |
41 | send_file(@web.blahtex_pngs_path.join(params['id'])) |
42 | end |
43 | |
44 | def delete |
45 | @file_name = params['id'] |
46 | file = WikiFile.find_by_file_name(@file_name) |
47 | unless file |
48 | flash[:error] = "File '#{@file_name}' not found." |
49 | redirect_to_page(@page_name) |
50 | end |
51 | system_password = params['system_password'] |
52 | if system_password |
53 | return unless is_post |
54 | # form supplied |
55 | if wiki.authenticate(system_password) |
56 | file.destroy |
57 | flash[:info] = "File '#{@file_name}' deleted." |
58 | else |
59 | flash[:error] = "System Password incorrect." |
60 | end |
61 | redirect_to_page(@page_name) |
62 | else |
63 | # no system password supplied, display the form |
64 | end |
65 | end |
66 | |
67 | def cancel_upload |
68 | return_to_last_remembered |
69 | end |
70 | |
71 | def import |
72 | if params['file'] |
73 | @problems = [] |
74 | import_file_name = "#{@web.address}-import-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.zip" |
75 | import_from_archive(params['file'].path) |
76 | if @problems.empty? |
77 | flash[:info] = 'Import successfully finished' |
78 | else |
79 | flash[:error] = 'Import finished, but some pages were not imported:<li>' + |
80 | @problems.join('</li><li>') + '</li>' |
81 | end |
82 | return_to_last_remembered |
83 | else |
84 | # to template |
85 | end |
86 | end |
87 | |
88 | protected |
89 | |
90 | def check_authorized |
91 | if authorized? or @web.published? |
92 | return true |
93 | else |
94 | @hide_navigation = true |
95 | render(:status => 403, :text => 'This web is private', :layout => true) |
96 | return false |
97 | end |
98 | end |
99 | |
100 | def check_allow_uploads |
101 | render(:status => 404, :text => "Web #{params['web'].inspect} not found", :layout => 'error') and return false unless @web |
102 | if @web.allow_uploads? and authorized? |
103 | return true |
104 | else |
105 | @hide_navigation = true |
106 | render(:status => 403, :text => 'File uploads are blocked by the webmaster', :layout => true) |
107 | return false |
108 | end |
109 | end |
110 | |
111 | private |
112 | |
113 | def import_from_archive(archive) |
114 | logger.info "Importing pages from #{archive}" |
115 | zip = Zip::ZipInputStream.open(archive) |
116 | while (entry = zip.get_next_entry) do |
117 | ext_length = File.extname(entry.name).length |
118 | page_name = entry.name[0..-(ext_length + 1)].purify |
119 | page_content = entry.get_input_stream.read.purify |
120 | logger.info "Processing page '#{page_name}'" |
121 | begin |
122 | existing_page = @wiki.read_page(@web.address, page_name) |
123 | if existing_page |
124 | if existing_page.content == page_content |
125 | logger.info "Page '#{page_name}' with the same content already exists. Skipping." |
126 | next |
127 | else |
128 | logger.info "Page '#{page_name}' already exists. Adding a new revision to it." |
129 | wiki.revise_page(@web.address, page_name, page_name, page_content, Time.now, @author, PageRenderer.new) |
130 | end |
131 | else |
132 | wiki.write_page(@web.address, page_name, page_content, Time.now, @author, PageRenderer.new) |
133 | end |
134 | rescue => e |
135 | logger.error(e) |
136 | @problems << "#{page_name} : #{e.message}" |
137 | end |
138 | end |
139 | logger.info "Import from #{archive} finished" |
140 | end |
141 | |
142 | end |