diff --git a/bin/gollum b/bin/gollum index bd50d9f6..5271c1a3 100755 --- a/bin/gollum +++ b/bin/gollum @@ -19,7 +19,10 @@ require 'gollum' exec = {} options = { 'port' => 4567, 'bind' => '0.0.0.0' } -wiki_options = { :live_preview => false } +wiki_options = { + :live_preview => false, + :allow_uploads => false, +} opts = OptionParser.new do |opts| opts.banner = help @@ -77,6 +80,10 @@ opts = OptionParser.new do |opts| wiki_options[:live_preview] = true end + opts.on("--allow-uploads", "Allows file uploads.") do + wiki_options[:allow_uploads] = true + end + opts.on("--mathjax", "Enables mathjax.") do wiki_options[:mathjax] = true end diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 516ba9ea..5f6bb7f0 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -13,6 +13,10 @@ require 'gollum/views/has_page' require File.expand_path '../helpers', __FILE__ +#required to upload bigger binary files +Grit::Git.git_timeout = 120 # timeout in secs +Grit::Git.git_max_size = 190 * 10**6 # size in bytes (10^6=1 MB) + # Fix to_url class String alias :upstream_to_url :to_url @@ -146,6 +150,53 @@ module Precious end end + post '/uploadFile' do + wiki = wiki_new + + unless wiki.allow_uploads + @message = "File uploads are disabled" + mustache :error + return + end + + if params[:file] + fullname = params[:file][:filename] + tempfile = params[:file][:tempfile] + end + + dir = 'uploads' + ext = ::File.extname(fullname) + format = ext.split('.').last || 'txt' + filename = ::File.basename(fullname, ext) + contents = ::File.read(tempfile) + reponame = filename + '.' + format + + head = wiki.repo.head + + options = { + :message => "Uploaded file to uploads/#{reponame}", + :parent => wiki.repo.head.commit, + } + author = session['gollum.author'] + unless author.nil? + options.merge! author + end + + begin + committer = Gollum::Committer.new(wiki, options) + committer.add_to_index(dir, filename, format, contents) + committer.after_commit do |committer, sha| + wiki.clear_cache + committer.update_working_dir(dir, filename, format) + end + committer.commit + redirect to('/') + rescue Gollum::DuplicatePageError => e + @message = "Duplicate page: #{e.message}" + mustache :error + end + end + post '/rename/*' do wikip = wiki_page(params[:splat].first) halt 500 if wikip.nil? @@ -283,6 +334,7 @@ module Precious @mathjax = wiki.mathjax @h1_title = wiki.h1_title @editable = false + @allow_uploads = wiki.allow_uploads mustache :page end @@ -401,6 +453,7 @@ module Precious @mathjax = wiki.mathjax @h1_title = wiki.h1_title @bar_side = wiki.bar_side + @allow_uploads = wiki.allow_uploads mustache :page elsif file = wiki.file(fullpath, wiki.ref, true) diff --git a/lib/gollum/public/gollum/javascript/gollum.dialog.js b/lib/gollum/public/gollum/javascript/gollum.dialog.js index 4672e399..a058aa98 100755 --- a/lib/gollum/public/gollum/javascript/gollum.dialog.js +++ b/lib/gollum/public/gollum/javascript/gollum.dialog.js @@ -37,11 +37,14 @@ fieldMarkup += '