Reshaped "import wiki" feature from command-line to web interface

This commit is contained in:
Alexey Verkhovsky 2005-01-27 03:55:19 +00:00
parent 3e4154de82
commit 06daadc7df
7 changed files with 69 additions and 88 deletions

View file

@ -71,7 +71,7 @@ class ApplicationController < ActionController::Base
not @web_name.nil?
end
@@REMEMBER_NOT = ['locked', 'save', 'back', 'file', 'pic']
@@REMEMBER_NOT = ['locked', 'save', 'back', 'file', 'pic', 'import']
def remember_location
if @response.headers['Status'] == '200 OK'
unless @@REMEMBER_NOT.include? action_name or @request.method != :get

View file

@ -45,6 +45,44 @@ class FileController < ApplicationController
end
end
def import
check_authorization
if @params['file']
logger.info 'Importing pages from a file'
import_file_name = "#{@web.address}-import-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.zip"
file_yard.upload_file(import_file_name, @params['file'])
zip = Zip::ZipInputStream.open(file_yard.file_path(import_file_name))
problems = []
while (entry = zip.get_next_entry) do
ext_length = File.extname(entry.name).length
page_name = entry.name[0..-(ext_length + 1)]
page_content = entry.get_input_stream.read
logger.info "Processing page '#{page_name}'"
begin
if @wiki.read_page(@web.address, page_name)
logger.info "Page '#{page_name}' already exists. Adding a new revision to it."
wiki.revise_page(@web.address, page_name, page_content, Time.now, 'Importer')
else
wiki.write_page(@web.address, page_name, page_content, Time.now, 'Importer')
end
rescue Instiki::ValidationError => e
logger.error(e)
problems << e.message
end
end
logger.info 'Import finished'
if problems.empty?
flash[:info] = 'Import successfully finished'
else
flash[:info] = "Import finished, but some pages were not imported:<li>" +
problems.join('</li><li>') + '</li>'
end
return_to_last_remembered
else
# to template
end
end
protected

View file

@ -1,3 +1,4 @@
require 'fileutils'
require 'instiki_errors'
class FileYard
@ -6,6 +7,7 @@ class FileYard
def initialize(files_path)
@files_path = files_path
FileUtils.mkdir_p(files_path) unless File.exist?(files_path)
@files = Dir["#{files_path}/*"].collect{|path| File.basename(path) if File.file?(path) }.compact
end

View file

@ -0,0 +1,23 @@
<p>
<%= form_tag({}, {:multipart => true}) %>
<p>
File to upload:
<br/>
<input type="file" name="file" size="40" />
</p>
<p>
System password:
<br/>
<input type="password" id="system_password" name="system_password" />
</p>
<p>
<input type="submit" value="Update" /> as
<input type="text" name="author" id="authorName" value="<%= @author %>"
onClick="this.value == 'AnonymousCoward' ? this.value = '' : true" />
<% if @page %>
| <a href="../file/">Cancel</a> <small>(unlocks page)</small>
<% end %>
</p>
<%= end_form_tag %>
</p>