+8
-1
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user