diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index 362558fe..e43b0d8e 100644
--- a/app/controllers/application.rb
+++ b/app/controllers/application.rb
@@ -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
diff --git a/app/controllers/file_controller.rb b/app/controllers/file_controller.rb
index fdf3b8ae..724e6b4c 100644
--- a/app/controllers/file_controller.rb
+++ b/app/controllers/file_controller.rb
@@ -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:
" +
+ flash[:error] = 'Import finished, but some pages were not imported:
' +
@problems.join('
') + '
'
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
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index 2e7eb3b7..dbed5666 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -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
diff --git a/app/models/web.rb b/app/models/web.rb
index 1ca17a9e..b37811a6 100644
--- a/app/models/web.rb
+++ b/app/models/web.rb
@@ -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
diff --git a/app/models/wiki_file.rb b/app/models/wiki_file.rb
index 89b166c0..635025e5 100644
--- a/app/models/wiki_file.rb
+++ b/app/models/wiki_file.rb
@@ -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
diff --git a/app/views/admin/edit_web.rhtml b/app/views/admin/edit_web.rhtml
index 558ef68a..58734136 100644
--- a/app/views/admin/edit_web.rhtml
+++ b/app/views/admin/edit_web.rhtml
@@ -48,9 +48,6 @@
/>
Count pages
-
diff --git a/app/views/file/file.rhtml b/app/views/file/file.rhtml
index 63c188eb..4216a9ed 100644
--- a/app/views/file/file.rhtml
+++ b/app/views/file/file.rhtml
@@ -1,19 +1,32 @@
<%
- @title = "Upload #{@file_name}"
+ @title = "Upload #{h @file_name}"
@hide_navigation = false
%>
-
+ Content of <%= h @file_name %> to upload (required):
-
-
-
- as
-
-
-<%= end_form_tag %>
-
\ No newline at end of file
+
+
+
+ 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.
+
+
+<%= end_form_tag %>
\ No newline at end of file
diff --git a/app/views/layouts/default.rhtml b/app/views/layouts/default.rhtml
index fb5e550e..d43208fa 100644
--- a/app/views/layouts/default.rhtml
+++ b/app/views/layouts/default.rhtml
@@ -55,15 +55,16 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<% end %>
-<% if @error or @flash[:error] %>
",
+ renderer.display_content
+
+ # rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form
+ r = get :file, :web => 'wiki1', :id => 'rails-e2e.gif'
+ assert_success
+ assert_rendered_file 'file/file'
+
+ # User uploads the picture
+ picture = File.read("#{RAILS_ROOT}/test/fixtures/rails.gif")
+ r = get :file, :web => 'wiki1', :id => 'rails-e2e.gif', :file => StringIO.new(picture)
+ assert_redirect_url '/'
+ assert @web.has_file?('rails-e2e.gif')
+ assert_equal(picture, File.read("#{RAILS_ROOT}/public/file/rails-e2e.gif"))
+
+ # this should refresh the page display content (cached)
+ assert_equal "",
+ @home.display_content
+ end
+
# def test_pic_upload_end_to_end
# # edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif'
# @wiki.revise_page('wiki1', 'HomePage', '[[instiki-e2e.txt:file]]', Time.now, 'AnonymousBrave',
diff --git a/test/test_helper.rb b/test/test_helper.rb
index fc2079f3..2dae41c9 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -150,8 +150,8 @@ class StubUrlGenerator < AbstractUrlGenerator
if known_pic then %{}
else %{#{text}} end
else
- if known_pic then %{}
- else %{#{text}?} end
+ if known_pic then %{}
+ else %{#{text}?} end
end
end
end
diff --git a/test/unit/page_renderer_test.rb b/test/unit/page_renderer_test.rb
index 00746bff..aabaccf3 100644
--- a/test/unit/page_renderer_test.rb
+++ b/test/unit/page_renderer_test.rb
@@ -282,20 +282,20 @@ class PageRendererTest < Test::Unit::TestCase
FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*")
@web.wiki_files.create(:file_name => 'square.jpg', :description => 'Square', :content => 'never mind')
assert_markup_parsed_as(
- '',
+ '',
'[[square.jpg|Square:pic]]')
assert_markup_parsed_as(
- '',
+ '',
'[[square.jpg:pic]]')
end
def test_link_to_non_existant_pic
assert_markup_parsed_as(
- '