Compare commits

..

10 Commits

Author SHA1 Message Date
bootstraponline 9c714e7687 Release 2.5.0 2013-07-21 07:22:46 -04:00
bootstraponline 6c3523d61c Merge pull request #725 from amenonsen/upload
Add a file Upload button
2013-07-21 04:19:58 -07:00
Abhijit Menon-Sen 183840b793 Add file upload functionality
Adds an :allow_uploads wiki option, an --allow-uploads flag to
bin/gollum, an "Upload" button with a file upload dialog, and a
handler to commit uploaded files into the repository.

:allow_uploads defaults to false, to prevent unauthenticated users
from uploading arbitrary files into the repository (albeit only in
the uploads directory).

This code is based on the patch from @l3iggs at
https://github.com/gollum/gollum/issues/694, but the handling on the
backend is completely rewritten to use the Committer infrastructure.
2013-07-21 16:28:15 +05:30
bootstraponline 4e2856aa64 Update gollum-lib to 1.0.4 2013-07-20 19:24:26 -04:00
Abhijit Menon-Sen 4627a39165 Merge pull request #727 from amenonsen/no-live-preview
Disable live preview by default, because it's broken (closes #718)
2013-07-18 05:39:48 -07:00
bootstraponline c87cbe83d2 Fix #709
Require Ruby >= 1.9
2013-07-18 08:17:17 -04:00
bootstraponline f05282badf Drop 1.8.7 support on Travis (It's broken)
Don't email me on fail
2013-07-18 08:16:01 -04:00
Abhijit Menon-Sen 957879346e Merge pull request #726 from amenonsen/fixes
Trivial fix: set label.for to the input's id
2013-07-17 18:53:37 -07:00
Abhijit Menon-Sen 87e64f67f3 A tiny patch to disable live preview (#718) 2013-07-17 14:24:36 +05:30
Abhijit Menon-Sen 43840d246d Trivial fix: set label.for to the input's id 2013-07-17 13:31:46 +05:30
9 changed files with 118 additions and 12 deletions
-4
View File
@@ -1,8 +1,4 @@
rvm:
- 1.8.7
- 1.9.3
notifications:
email:
- code@bootstraponline.com
before_install:
- sudo apt-get update
+12 -1
View File
@@ -19,7 +19,10 @@ require 'gollum'
exec = {}
options = { 'port' => 4567, 'bind' => '0.0.0.0' }
wiki_options = {}
wiki_options = {
:live_preview => false,
:allow_uploads => false,
}
opts = OptionParser.new do |opts|
opts.banner = help
@@ -73,6 +76,14 @@ opts = OptionParser.new do |opts|
wiki_options[:live_preview] = false
end
opts.on("--live-preview", "Enables livepreview.") do
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
+4 -4
View File
@@ -2,11 +2,11 @@ Gem::Specification.new do |s|
s.specification_version = 2 if s.respond_to? :specification_version=
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.rubygems_version = '1.3.5'
s.required_ruby_version = ">= 1.8.7"
s.required_ruby_version = ">= 1.9"
s.name = 'gollum'
s.version = '2.4.15'
s.date = '2013-06-18'
s.version = '2.5.0'
s.date = '2013-07-21'
s.rubyforge_project = 'gollum'
s.license = 'MIT'
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--charset=UTF-8"]
s.extra_rdoc_files = %w[README.md LICENSE]
s.add_dependency 'gollum-lib', '~> 1.0.3'
s.add_dependency 'gollum-lib', '~> 1.0.4'
s.add_dependency 'sinatra', '~> 1.4.2'
s.add_dependency 'mustache', ['>= 0.99.4', '< 1.0.0']
s.add_dependency 'useragent', '~> 0.6.0'
+1 -1
View File
@@ -17,7 +17,7 @@ require File.expand_path('../gollum/uri_encode_component', __FILE__)
$KCODE = 'U' if RUBY_VERSION[0,3] == '1.8'
module Gollum
VERSION = '2.4.15'
VERSION = '2.5.0'
def self.assets_path
::File.expand_path('gollum/public', ::File.dirname(__FILE__))
+53
View File
@@ -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)
@@ -37,11 +37,14 @@
fieldMarkup += '<div class="field">';
switch ( fieldArray[i].type ) {
// only text is supported for now
case 'text':
fieldMarkup += Dialog.createFieldText( fieldArray[i] );
break;
case 'file':
fieldMarkup += Dialog.createFieldFile( fieldArray[i] );
break;
default:
break;
@@ -60,7 +63,7 @@
if ( fieldAttributes.name ) {
html += '<label';
if ( fieldAttributes.id ) {
html += ' for="' + fieldAttributes.name + '"';
html += ' for="gollum-dialog-dialog-generated-field-' + fieldAttributes.id + '"';
}
html += '>' + fieldAttributes.name + '</label>';
}
@@ -86,6 +89,22 @@
return html;
},
createFieldFile: function( fieldAttributes ) {
// Not actually a field, but an embedded form.
var html = '';
var id = fieldAttributes.id || 'upload';
var name = fieldAttributes.name || 'file';
var action = fieldAttributes.action || 'uploadFile';
html += '<form method=post enctype="multipart/form-data" ' +
'action="' + action + '" ' + 'id="' + id + '">';
html += '<input type=file name="' + name + '">';
html += '</form>';
return html;
},
createMarkup: function( title, body ) {
Dialog.markupCreated = true;
if ($.facebox) {
@@ -145,6 +145,25 @@ $(document).ready(function() {
}
}
if ($('#minibutton-upload-page').length) {
$('#minibutton-upload-page').parent().removeClass('jaws');
$('#minibutton-upload-page').click(function(e) {
e.preventDefault();
$.GollumDialog.init({
title: 'Upload File',
fields: [
{
type: 'file'
}
],
OK: function( res ) {
$('#upload').submit();
}
});
});
}
if ($('#minibutton-rename-page').length) {
$('#minibutton-rename-page').parent().removeClass('jaws');
$('#minibutton-rename-page').click(function(e) {
+4
View File
@@ -20,6 +20,10 @@ Mousetrap.bind(['e'], function( e ) {
class="action-fileview">Files</a></li>
<li class="minibutton jaws">
<a href="#" id="minibutton-new-page">New</a></li>
{{#allow_uploads}}
<li class="minibutton jaws">
<a href="#" id="minibutton-upload-page">Upload</a></li>
{{/allow_uploads}}
{{#editable}}
<li class="minibutton jaws">
<a href="#" id="minibutton-rename-page">Rename</a></li>
+4
View File
@@ -39,6 +39,10 @@ module Precious
@editable
end
def allow_uploads
@allow_uploads
end
def has_header
@header = (@page.header || false) if @header.nil?
!!@header