[BUILD STILL BROKEN] File uploads roughly speaking work (to about same extent as in 0.10)
This commit is contained in:
parent
ac72f9b807
commit
0b1a80a852
13 changed files with 172 additions and 297 deletions
|
@ -38,8 +38,6 @@ class ApplicationController < ActionController::Base
|
|||
return false
|
||||
end
|
||||
end
|
||||
@page_name = @file_name = @params['id']
|
||||
@page = @wiki.read_page(@web_name, @page_name) unless @page_name.nil?
|
||||
@author = cookies['author'] || 'AnonymousCoward'
|
||||
end
|
||||
|
||||
|
|
|
@ -9,23 +9,26 @@ class FileController < ApplicationController
|
|||
def file
|
||||
if @params['file']
|
||||
# form supplied
|
||||
new_file = upload_file(@file_name, @params['file'])
|
||||
new_file = @web.wiki_files.create(@params['file'])
|
||||
if new_file.valid?
|
||||
flash[:info] = "File '#{@file_name}' successfully uploaded"
|
||||
return_to_last_remembered
|
||||
else
|
||||
# FIXME handle validation errors more gracefully
|
||||
flash[:errors] = new_file.errors.to_s
|
||||
# pass the file with errors back into the form
|
||||
@file = new_file
|
||||
render
|
||||
end
|
||||
else
|
||||
else
|
||||
(render(:status => 404, :text => 'Unspecified file name') and return) unless @file_name
|
||||
# no form supplied, this is a request to download the file
|
||||
file = WikiFile.find_by_file_name(@file_name)
|
||||
if file
|
||||
send_data(file.content, :filename => @file_name, :type => content_type_header(@file_name))
|
||||
else
|
||||
@file = WikiFile.new(:file_name => @file_name)
|
||||
render
|
||||
end
|
||||
end
|
||||
# if it's neither a supplied form for upload, nor a request for a known file,
|
||||
# display the file/file.rhtml template (which happens to be an upload form)
|
||||
end
|
||||
|
||||
def cancel_upload
|
||||
|
@ -41,7 +44,7 @@ class FileController < ApplicationController
|
|||
if @problems.empty?
|
||||
flash[:info] = 'Import successfully finished'
|
||||
else
|
||||
flash[:error] = "Import finished, but some pages were not imported:<li>" +
|
||||
flash[:error] = 'Import finished, but some pages were not imported:<li>' +
|
||||
@problems.join('</li><li>') + '</li>'
|
||||
end
|
||||
return_to_last_remembered
|
||||
|
@ -60,6 +63,11 @@ class FileController < ApplicationController
|
|||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def connect_to_model
|
||||
super
|
||||
@file_name = @params['id']
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -272,9 +272,16 @@ class WikiController < ApplicationController
|
|||
@tex_content = RedClothForTex.new(@page.content).to_tex
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def connect_to_model
|
||||
super
|
||||
@page_name = @params['id']
|
||||
@page = @wiki.read_page(@web_name, @page_name) if @page_name
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
def convert_tex_to_pdf(tex_path)
|
||||
# TODO remove earlier PDF files with the same prefix
|
||||
# TODO handle gracefully situation where pdflatex is not available
|
||||
|
|
|
@ -6,10 +6,6 @@ class Web < ActiveRecord::Base
|
|||
Wiki.new
|
||||
end
|
||||
|
||||
def file_yard
|
||||
@file_yard ||= FileYard.new("#{Wiki.storage_path}/#{address}", max_upload_size)
|
||||
end
|
||||
|
||||
def settings_changed?(markup, safe_mode, brackets_only)
|
||||
self.markup != markup ||
|
||||
self.safe_mode != safe_mode ||
|
||||
|
@ -84,6 +80,23 @@ class Web < ActiveRecord::Base
|
|||
address
|
||||
end
|
||||
|
||||
def create_files_directory
|
||||
return unless allow_uploads == 1
|
||||
dummy_file = self.wiki_files.build(:file_name => '0', :description => '0', :content => '0')
|
||||
dir = File.dirname(dummy_file.content_path)
|
||||
begin
|
||||
require 'fileutils'
|
||||
FileUtils.mkdir_p dir
|
||||
dummy_file.save
|
||||
dummy_file.destroy
|
||||
rescue => e
|
||||
logger.error("Failed create files directory for #{self.address}: #{e}")
|
||||
raise "Instiki could not create directory to store uploaded files. " +
|
||||
"Please make sure that Instiki is allowed to create directory " +
|
||||
"#{File.expand_path(dir)} and add files to it."
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Returns an array of all the wiki words in any current revision
|
||||
|
@ -114,32 +127,15 @@ class Web < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def create_files_directory
|
||||
return unless allow_uploads == 1
|
||||
dummy_file = self.wiki_files.build(:file_name => '0', :description => '0', :content => '0')
|
||||
dir = File.dirname(dummy_file.content_path)
|
||||
begin
|
||||
require 'fileutils'
|
||||
FileUtils.mkdir_p dir
|
||||
dummy_file.save
|
||||
dummy_file.destroy
|
||||
rescue => e
|
||||
logger.error("Failed create files directory for #{self.address}: #{e}")
|
||||
raise "Instiki could not create directory to store uploaded files. " +
|
||||
"Please make sure that Instiki is allowed to create directory " +
|
||||
"#{File.expand_path(dir)} and add files to it."
|
||||
end
|
||||
end
|
||||
|
||||
def default_web?
|
||||
defined? DEFAULT_WEB and self.address == DEFAULT_WEB
|
||||
end
|
||||
|
||||
def files_path
|
||||
if default_web?
|
||||
"#{RAILS_ROOT}/public/#{self.address}/files"
|
||||
else
|
||||
"#{RAILS_ROOT}/public/files"
|
||||
else
|
||||
"#{RAILS_ROOT}/public/#{self.address}/files"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,9 +4,9 @@ class WikiFile < ActiveRecord::Base
|
|||
before_save :write_content_to_file
|
||||
before_destroy :delete_content_file
|
||||
|
||||
validates_presence_of %w( web file_name description )
|
||||
validates_presence_of %w( web file_name )
|
||||
validates_length_of :file_name, :within=>1..50
|
||||
validates_length_of :description, :within=>1..255
|
||||
validates_length_of :description, :maximum=>255
|
||||
|
||||
def self.find_by_file_name(file_name)
|
||||
find(:first, :conditions => ['file_name = ?', file_name])
|
||||
|
@ -34,7 +34,11 @@ class WikiFile < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def content=(content)
|
||||
@content = content
|
||||
if content.respond_to? :read
|
||||
@content = content.read
|
||||
else
|
||||
@content = content
|
||||
end
|
||||
end
|
||||
|
||||
def content
|
||||
|
@ -46,6 +50,7 @@ class WikiFile < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def write_content_to_file
|
||||
web.create_files_directory unless File.exists?(web.files_path)
|
||||
File.open(self.content_path, 'wb') { |f| f.write(@content) }
|
||||
end
|
||||
|
||||
|
@ -54,4 +59,6 @@ class WikiFile < ActiveRecord::Base
|
|||
FileUtils.rm_f(content_path) if File.exists?(content_path)
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -48,9 +48,6 @@
|
|||
<input type="checkbox" name="count_pages" <%= 'checked="on"' if @web.count_pages %> />
|
||||
Count pages
|
||||
<br/>
|
||||
<!--
|
||||
File uploads are not ready for gfeneral use, and therefore are disabled in release 0.10
|
||||
TODO Enable these input elements again after release 0.10
|
||||
|
||||
<input type="checkbox" name="allow_uploads" <%= 'checked="on"' if @web.allow_uploads %> />
|
||||
Allow uploads of no more than
|
||||
|
@ -61,7 +58,6 @@ TODO Enable these input elements again after release 0.10
|
|||
allow users to upload pictures and other files and include them on wiki pages
|
||||
</em>
|
||||
<br/>
|
||||
-->
|
||||
</small>
|
||||
</p>
|
||||
|
||||
|
|
|
@ -1,19 +1,32 @@
|
|||
<%
|
||||
@title = "Upload #{@file_name}"
|
||||
@title = "Upload #{h @file_name}"
|
||||
@hide_navigation = false
|
||||
%>
|
||||
|
||||
<p>
|
||||
<%= error_messages_for 'file' %>
|
||||
|
||||
<%= form_tag({:controller => 'file', :web => @web_name, :action => 'file'}, {:multipart => true}) %>
|
||||
<p>
|
||||
File to upload:
|
||||
<%= hidden_field 'file', 'file_name' %>
|
||||
<div class="inputFieldWithPrompt">
|
||||
<b>Content of <%= h @file_name %> to upload <small>(required)</small>:</b>
|
||||
<br/>
|
||||
<input type="file" name="file" size="40" />
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" value="Update" /> as
|
||||
<input type="text" name="author" id="authorName" value="<%= @author %>"
|
||||
onClick="this.value == 'AnonymousCoward' ? this.value = '' : true" />
|
||||
</p>
|
||||
<%= end_form_tag %>
|
||||
</p>
|
||||
<input type="file" name="file[content]" size="40" />
|
||||
<br/>
|
||||
<small>
|
||||
Please note that the file you are uploadng will be named <%= h @file_name %> on the wiki -
|
||||
regardless of how it is named on your computer. To change the wiki name of the file, please go
|
||||
<%= link_to :back %> and edit the wiki page that refers to the file.
|
||||
</small>
|
||||
</div>
|
||||
<div class="inputFieldWithPrompt">
|
||||
<b>Description <small>(optional)</small>:</b>
|
||||
<br/>
|
||||
<%= text_field "file", "description", "size" => 40 %>
|
||||
</div>
|
||||
<div>
|
||||
<input type="submit" value="Upload" /> as
|
||||
<%= text_field_tag :author, @author,
|
||||
:onfocus => "this.value == 'AnonymousCoward' ? this.value = '' : true;",
|
||||
:onblur => "this.value == '' ? this.value = 'AnonymousCoward' : true" %>
|
||||
</div>
|
||||
<%= end_form_tag %>
|
|
@ -55,15 +55,16 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|||
<% end %>
|
||||
</h1>
|
||||
|
||||
<% if @error or @flash[:error] %> <div id="error">
|
||||
<hr/><p><%= escape_preserving_linefeeds(@error || @flash[:error]) %></p><hr/></div>
|
||||
<% end %>
|
||||
|
||||
<% if @flash[:info] %> <div id="info">
|
||||
<hr/><p><%= escape_preserving_linefeeds @flash[:info] %></p><hr/></div>
|
||||
<% end %>
|
||||
|
||||
<%= render 'navigation' unless @web.nil? || @hide_navigation %>
|
||||
|
||||
<% if @error or @flash[:error] %>
|
||||
<div class="errorExplanation"><%= escape_preserving_linefeeds(@error || @flash[:error]) %></div>
|
||||
<% end %>
|
||||
|
||||
<%= @content_for_layout %>
|
||||
|
||||
<% if @show_footer %>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue