Merge branch 'bzr/golem' of /Users/distler/Sites/code/instiki

This commit is contained in:
Jacques Distler 2009-03-03 12:19:13 -06:00
commit 3fdfad29a3
5 changed files with 32 additions and 17 deletions

View file

@ -43,6 +43,9 @@ class ApplicationController < ActionController::Base
end end
FILE_TYPES = { FILE_TYPES = {
'.aif' => 'audio/x-aiff',
'.aiff'=> 'audio/x-aiff',
'.avi' => 'video/x-msvideo',
'.exe' => 'application/octet-stream', '.exe' => 'application/octet-stream',
'.gif' => 'image/gif', '.gif' => 'image/gif',
'.jpg' => 'image/jpeg', '.jpg' => 'image/jpeg',
@ -51,19 +54,29 @@ class ApplicationController < ActionController::Base
'.oga' => 'audio/ogg', '.oga' => 'audio/ogg',
'.ogg' => 'audio/ogg', '.ogg' => 'audio/ogg',
'.ogv' => 'video/ogg', '.ogv' => 'video/ogg',
'.mov' => 'video/quicktime',
'.mp3' => 'audio/mpeg',
'.mp4' => 'video/mp4',
'.txt' => 'text/plain', '.txt' => 'text/plain',
'.tex' => 'text/plain', '.tex' => 'text/plain',
'.wav' => 'audio/x-wav',
'.zip' => 'application/zip' '.zip' => 'application/zip'
} unless defined? FILE_TYPES } unless defined? FILE_TYPES
DISPOSITION = { DISPOSITION = {
'application/octet-stream' => 'attachment', 'application/octet-stream' => 'attachment',
'application/pdf' => 'inline',
'image/gif' => 'inline', 'image/gif' => 'inline',
'image/jpeg' => 'inline', 'image/jpeg' => 'inline',
'application/pdf' => 'inline',
'image/png' => 'inline', 'image/png' => 'inline',
'audio/mpeg' => 'inline',
'audio/x-wav' => 'inline',
'audio/x-aiff' => 'inline',
'audio/ogg' => 'inline', 'audio/ogg' => 'inline',
'video/ogg' => 'inline', 'video/ogg' => 'inline',
'video/mp4' => 'inline',
'video/quicktime' => 'inline',
'video/x-msvideo' => 'inline',
'text/plain' => 'inline', 'text/plain' => 'inline',
'application/zip' => 'attachment' 'application/zip' => 'attachment'
} unless defined? DISPOSITION } unless defined? DISPOSITION

View file

@ -105,7 +105,7 @@ module WikiChunk
unless defined? WIKI_LINK unless defined? WIKI_LINK
WIKI_LINK = /(":)?\[\[\s*([^\]\s][^\]]*?)\s*\]\]/ WIKI_LINK = /(":)?\[\[\s*([^\]\s][^\]]*?)\s*\]\]/
LINK_TYPE_SEPARATION = Regexp.new('^(.+):((file)|(pic)|(video)|(delete))$', 0) LINK_TYPE_SEPARATION = Regexp.new('^(.+):((file)|(pic)|(video)|(audio)|(delete))$', 0)
ALIAS_SEPARATION = Regexp.new('^(.+)\|(.+)$', 0) ALIAS_SEPARATION = Regexp.new('^(.+)\|(.+)$', 0)
WEB_SEPARATION = Regexp.new('^(.+):(.+)$', 0) WEB_SEPARATION = Regexp.new('^(.+):(.+)$', 0)
end end

View file

@ -9,7 +9,7 @@ module Sanitizer
require 'node' require 'node'
require 'stringsupport' require 'stringsupport'
acceptable_elements = %w[a abbr acronym address area b big blockquote br acceptable_elements = %w[a abbr acronym address area audio b big blockquote br
button caption center cite code col colgroup dd del dfn dir div dl dt button caption center cite code col colgroup dd del dfn dir div dl dt
em fieldset font form h1 h2 h3 h4 h5 h6 hr i img input ins kbd label em fieldset font form h1 h2 h3 h4 h5 h6 hr i img input ins kbd label
legend li map menu ol optgroup option p pre q s samp select small span legend li map menu ol optgroup option p pre q s samp select small span
@ -31,8 +31,8 @@ module Sanitizer
align alt axis border cellpadding cellspacing char charoff charset align alt axis border cellpadding cellspacing char charoff charset
checked cite class clear cols colspan color compact controls coords datetime checked cite class clear cols colspan color compact controls coords datetime
dir disabled enctype for frame headers height href hreflang hspace id dir disabled enctype for frame headers height href hreflang hspace id
ismap label lang longdesc maxlength media method multiple name nohref ismap label lang longdesc loop maxlength media method multiple name nohref
noshade nowrap prompt readonly rel rev rows rowspan rules scope noshade nowrap poster prompt readonly rel rev rows rowspan rules scope
selected shape size span src start style summary tabindex target title selected shape size span src start style summary tabindex target title
type usemap valign value vspace width xml:lang] type usemap valign value vspace width xml:lang]

View file

@ -35,8 +35,10 @@ class AbstractUrlGenerator
file_link(mode, name, text, web.address, known_page, description) file_link(mode, name, text, web.address, known_page, description)
when :pic when :pic
pic_link(mode, name, text, web.address, known_page) pic_link(mode, name, text, web.address, known_page)
when :audio
media_link(mode, name, text, web.address, known_page, 'audio')
when :video when :video
video_link(mode, name, text, web.address, known_page) media_link(mode, name, text, web.address, known_page, 'video')
when :delete when :delete
delete_link(mode, name, web.address, known_page) delete_link(mode, name, web.address, known_page)
else else
@ -143,25 +145,25 @@ class UrlGenerator < AbstractUrlGenerator
end end
end end
def video_link(mode, name, text, web_address, known_vid) def media_link(mode, name, text, web_address, known_media, media_type)
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file', href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
:id => name :id => name
case mode case mode
when :export when :export
if known_vid if known_media
%{<video src="#{CGI.escape(name)}" controls="controls">#{text}</video>} %{<#{media_type} src="#{CGI.escape(name)}" controls="controls">#{text}</#{media_type}>}
else else
text text
end end
when :publish when :publish
if known_vid if known_media
%{<video src="#{href}" controls="controls">#{text}</video>} %{<#{media_type} src="#{href}" controls="controls">#{text}</#{media_type}>}
else else
%{<span class="newWikiWord">#{text}</span>} %{<span class="newWikiWord">#{text}</span>}
end end
else else
if known_vid if known_media
%{<video src="#{href}" controls="controls">#{text}</video>} %{<#{media_type} src="#{href}" controls="controls">#{text}</#{media_type}>}
else else
%{<span class="newWikiWord">#{text}<a href="#{href}">?</a></span>} %{<span class="newWikiWord">#{text}<a href="#{href}">?</a></span>}
end end

View file

@ -19,7 +19,7 @@ module HTML5
module HTMLSanitizeModule module HTMLSanitizeModule
ACCEPTABLE_ELEMENTS = %w[a abbr acronym address area b big blockquote br ACCEPTABLE_ELEMENTS = %w[a abbr acronym address area audio b big blockquote br
button caption center cite code col colgroup dd del dfn dir div dl dt button caption center cite code col colgroup dd del dfn dir div dl dt
em fieldset font form h1 h2 h3 h4 h5 h6 hr i img input ins kbd label em fieldset font form h1 h2 h3 h4 h5 h6 hr i img input ins kbd label
legend li map menu ol optgroup option p pre q s samp select small span legend li map menu ol optgroup option p pre q s samp select small span
@ -41,8 +41,8 @@ module HTML5
align alt axis border cellpadding cellspacing char charoff charset align alt axis border cellpadding cellspacing char charoff charset
checked cite class clear cols colspan color compact controls coords datetime checked cite class clear cols colspan color compact controls coords datetime
dir disabled enctype for frame headers height href hreflang hspace id dir disabled enctype for frame headers height href hreflang hspace id
ismap label lang longdesc maxlength media method multiple name nohref ismap label lang longdesc loop maxlength media method multiple name nohref
noshade nowrap prompt readonly rel rev rows rowspan rules scope noshade nowrap poster prompt readonly rel rev rows rowspan rules scope
selected shape size span src start style summary tabindex target title selected shape size span src start style summary tabindex target title
type usemap valign value vspace width xml:lang] type usemap valign value vspace width xml:lang]