[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
multi_publish-0.1 - publish text + multiple non-text media items in just
From: |
boud |
Subject: |
multi_publish-0.1 - publish text + multiple non-text media items in just one preview/confirm cycle (patch #6143) |
Date: |
Tue, 7 Aug 2007 13:16:23 +0200 (CEST) |
hi samizdat-devel,
Here's version 0.1 of multi_publish, with most modifications to
controller/message_controller.rb and a few to models/content.rb.
It's deliberately written with multi_publish, multi_set_content and
multi_preview (all in message_controller) rather long-winded as new methods
in order that it can be experimented with without much danger of
totally disabling publication in case it contains some non-trivial
bugs. However, check_content is modified rather than cloned (but my
feeling is that it won't break anything).
CONFIG:
config['limit']['multi_message'] should be set to the maximum
number of uploads. Otherwise, it defaults to 10.
Unfilled upload fields will be ignored.
TODO: Giving too many fields to a user can unnecessarily encourage
them to publish too many photos/etc. An option similar to mir would be
to first give a form asking how many items are required, and then
reissuing the form if the person submits a number.
KNOWN BUGS:
There's a known bug #20710 with upload conflicts present in 070618-1 (and
presumably earlier versions) - this same bug applies here.
https://savannah.nongnu.org/bugs/index.php?20710
At the moment, the idea is that ui=advanced automatically redirects
publish to multi_publish (though it is technically possibly to go
directly to multi_publish with a basic interface, by typing the URL
message/multi_publish) - i think that having 3 different types of interfaces
would be too confusing.
i've also added a warning at the preview stage - mediawiki and i think
many other similar software tend to give a BIG warning at the preview
stage, since with a confirm button at the bottom of the page, people can
easily forget to confirm - and then get angry when they think their
contribution has been deleted/ignored.
Should the files be published as non-wiki even if the user requests
wiki for the parent message? My feeling is that in practice,
photos/videos are (relatively) objective in terms of news
reporting. Of course there is a choice of what/how to photograph,
which photos to publish or not publish, and they can be edited with
gimp or with non-free software. But any normal text item about a news
event *necessarily* must be subjective, since it's a summary of the
event in a natural language after processing the
audio/visual/tactile/olfactory/scent signals of the event through one
or more human brains and cannot be a raw recording of an event (except
if it's a word-for-word report on a speech or a document, for example,
like wikisource).
So that's why i set:
+ set_open(false) #(@parent.open) TODO discuss: is this a reasonable
default?
Anyway, anyone should feel free to rewrite this patch more elegantly and
compactly :)
cheers
boud
----------------------------------------------------------------------
--- s070618/samizdat/lib/samizdat/models/content.rb 2007-04-26
02:11:26.000000000 +0200
+++ /usr/lib/ruby/1.8/samizdat/models/content.rb 2007-08-07
12:48:59.577605240 +0200
@@ -61,6 +61,9 @@
#
attr_reader :body
+ # hack for multi_message
+ attr_writer :file_index
+
# relative path to file holding multimedia message content (+nil+ if inline)
#
def file_path(id = @id)
@@ -106,11 +109,13 @@
# todo: extract file-handling methods dependent on request#filename into a
# separate class
#
- def upload(request)
+# def upload(request)
+ def upload(request,file_index=nil) # multi_message hacking !
@id.kind_of?(Integer) and raise RuntimeError,
'Content#upload called for existing message content'
- file = request.cgi_params['file'][0] # just a file object, not its
contents
+ @file_index = file_index
+ file = request.cgi_params['file' + @file_index.to_s][0] # just a file
object, not its contents
return nil unless
(file.kind_of? StringIO or file.kind_of? Tempfile) and file.size > 0
@@ -130,6 +135,9 @@
end
end
+ # 0.6.0.070618-1: validate_upload seems to be unused
+ # Is it for preview or rather for confirm?
+ #
# check whether uploaded file is in place
#
def validate_upload(request)
@@ -233,14 +241,15 @@
# id component of the file path of a new upload
#
def upload_id
- 'upload'
+# 'upload'
+ 'upload' + @file_index.to_s # for multi_messaging (will this break the
wiki?)
end
# multimedia message content filename
#
def upload_filename(request, id)
(id.kind_of?(Integer) or upload_id == id) or raise RuntimeError,
- 'Unexpected file upload id'
+ _('Unexpected file upload id')
request.content_dir + file_path(id).untaint
end
--- s070618/samizdat/lib/samizdat/controllers/message_controller.rb
2007-06-18 13:01:02.000000000 +0200
+++ /usr/lib/ruby/1.8/samizdat/controllers/message_controller.rb
2007-08-07 11:32:17.520224304 +0200
@@ -95,6 +120,8 @@
end
def publish
+ @request.redirect('message/multi_publish') if @request.advanced_ui?
+
assert_post
@message = Message.new
@@ -116,11 +143,84 @@
elsif @request.has_key? 'preview'
preview
else
- @title = _('New Message')
+ @title = _('New Message') +
+ # TODO: copied from member_controller, should be modularised
+ %{ | <a href="member/set?ui=} +
+ ( @request.advanced_ui? ?
+ 'basic">' + _('Return to basic interface') :
+ 'advanced">' + _('Enable advanced interface')
+ ) + '</a>'
@content_for_layout = box(@title, form(nil, *edit_form(:show_focuses)))
end
end
+ def multi_publish
+ assert_post
+
+ @message = Message.new
+ set_creator
+ set_content
+ set_lang
+ set_desc
+ set_open
+ set_focus
+
+ # how many more messages (usually non-text media items)
+ (config['limit']['multi_message'].kind_of? Integer) ?
+ @n_more = config['limit']['multi_message'] : 10
+
+ @more_messages = Array.new(@n_more,Message.new)
+ multi_set_content
+
+ if @request.has_key? 'confirm'
+ check_content
+ save do
+ @message.insert!
+# @message.content.move_upload(@request)
+ update_focus
+ end
+
+ @id_parent = @message.id
+ @parent = @message
+
+ @more_messages.each_index do |i|
+ if @uploads[i] and nil != @uploads[i]
+ @message = @more_messages[i]
+ set_creator
+ @message.parent = @id_parent # @parent.id
+
+ # set_content # done above in multi_set_content
+ set_lang(@parent.lang)
+ set_desc
+ set_open(false) #(@parent.open) TODO discuss: is this a reasonable
default?
+
+# @message.content.format = @formats[i].to_s
+ # TODO: this is probably redundant with what is done in
multi_set_content
+ title = (@request.values_at %w[title]).to_s
+ @more_messages[i].content =
+ Content.new(nil, @session.login, title, @formats[i].to_s, nil)
+
+ save do
+ @message.insert!
+ @message.content.file_index = i
+ @message.content.move_upload(@request)
+ end
+ end
+ end
+
+ @request.redirect(location_under_parent)
+
+# @request.redirect(@message.id)
+ elsif @request.has_key? 'preview'
+ multi_preview
+ else
+ @title = _('New Message')
+ @content_for_layout = box(@title, form(nil,
*edit_form(:show_focuses,:many_messages)))
+ end
+
+ end
+
+
def reply
assert_post
@@ -278,6 +391,41 @@
@message.content = new_content
end
+ def multi_set_content
+ title, format, body = @request.values_at %w[title format body]
+
+ new_content = Content.new(nil, @session.login, title, format, body)
+ @old_content = (@message.content or new_content)
+ @message.content = new_content
+
+# if not @uploads or @uploads.length < @n_more
+ @uploads_found = false
+ @uploads = Array.new(@n_more,nil)
+ @formats = Array.new(@n_more,nil)
+# end
+
+ @more_messages.each_index do |i|
+# format = m.content.format
+
+ upload_i = @request.cgi_params['upload' + i.to_s]
+ if upload_i and i.to_s == upload_i.to_s
+ @uploads[i] = true
+ @uploads_found = true
+ else
+ @uploads[i] = nil
+ end
+ @formats[i] = @request.cgi_params['format' + i.to_s]
+
+# title += ' ___' + @formats[i].to_s + '___ ' if nil != title # debug only
+
+ @more_messages[i].content =
+ Content.new(nil, @session.login, title, @formats[i].to_s, nil)
+ # Content.new(nil, @session.login, title, @formats[i].to_s, 'DEBUG')
+ end
+# @old_content = (m.content or new_content)
+# m.content = new_content
+ end
+
def set_lang(default = nil)
@message.lang = @message.validate_lang(
(@request['lang'] or default or @request.language))
@@ -323,8 +471,13 @@
def check_content
@message.content.title or raise UserError,
_('Message title is required')
- @upload or @message.content.body.kind_of? String or raise UserError,
- _('Message body is required')
+
+ @upload or @message.content.body.kind_of? String or
+ @uploads_found or # multi_message
+ raise UserError, _('Message body is required') +
+ '@upload=' + @upload.to_s + '__' + # debug only
+ '@message...=' + @message.content.body.to_s + '__' +
+ '@uploads_found=' + @uploads_found.to_s + '__'
cache.fetch_or_add('antispam') {
Antispam.new(config['antispam'])
@@ -338,10 +491,19 @@
[:text, 'title', @old_content.title],
[:label, 'body', _('Content')],
[:textarea, 'body', @old_content.body],
- [:label, 'file', _('Upload content from file')],
- [:file, 'file']
]
+ if options.include? :many_messages
+ @more_messages.each_index do |i|
+ fields.push([:label, 'file' + i.to_s, _('Upload content from file')],
+ [:file, 'file' + i.to_s])
+ end
+ else
+ fields.push([:label, 'file', _('Upload content from file')],
+ [:file, 'file'])
+ end
+
+
if options.include? :show_focuses
# select focus for new message
fields.push(*focus_fields(nil, false))
@@ -364,9 +526,15 @@
[:checkbox, 'open', @message.open,
(options.include?(:disable_open) ? :disabled : nil)]
)
+ else # keep old values even with basic interface # fixes bug #20303
+ fields.push([:hidden, 'format', @old_content.format ])
end
+# if options.include? :multi_media
+# fields.push([:br], [:submit, 'confirm', _('Confirm')])
+# else
fields.push([:br], [:submit, 'preview', _('Preview')])
+# end
fields
end
@@ -403,6 +571,87 @@
)
end
+
+ def multi_preview
+# @upload ||= @message.content.upload(@request)
+
+ @more_messages.each_index do |i|
+ if not @uploads[i] # or nil == @uploads[i]
+# @uploads[i] =
+ upload_try = @more_messages[i].content.upload(@request,i)
+ if upload_try != nil
+ @uploads[i] = true
+ @uploads_found
+ end
+ @formats[i] = @more_messages[i].content.format
+ end
+ end
+
+ check_content
+
+ body = @message.content.body
+ if body and body != limit_string(body, config['limit']['short'])
+ cut_warning = '<p>'+sprintf(_('Warning: content is longer than %s characters.
In some situations, it will be truncated.'), config['limit']['short'])+'</p>'
+ end
+
+ @title = _('Message Preview')
+
+# uploads_true = true if @uploads
+ uploads_layout = [] # [:hidden, 'uploads', uploads_true]]
+ @more_messages.each_index do |i|
+ if @uploads[i] and @uploads[i] != nil
+ uploads_layout += [
+# [:hidden, 'upload'+i.to_s, @uploads[i]],
+ [:hidden, 'upload'+i.to_s, i.to_s],
+ [:hidden, 'format'+i.to_s, @formats[i]]
+# [:hidden, 'format'+i.to_s + @formats[i].to_s + '__', @formats[i]] # debug only
+ ]
+ end
+ end
+
+ message_preview_layout = message(@message, :preview)
+ @id_parent = @message.id
+ @parent = @message
+ @more_messages.each_index do |i|
+ if @uploads[i] and @uploads[i] != nil
+# @message = @more_messages[i]
+# set_creator
+ @more_messages[i].creator = Member.cached(@session.member)
+ @more_messages[i].parent = @id_parent # @parent.id
+ @more_messages[i].content.file_index = i
+ message_preview_layout += message(@more_messages[i], :preview)
+# message_preview_layout += message(@message, :preview)
+ end
+ end
+# @message = @parent
+
+ @content_for_layout = box(
+ @message.content.title +
+ ' | ' + _('WARNING: This is only a preview - it has <em>not</em> yet been saved.'),
+# message(@message, :preview) <<
+ message_preview_layout <<
+ cut_warning.to_s <<
+ '<p>' << _("Press 'Back' button to change the message.") << '</p>' <<
+ secure_form(
+ nil,
+ [:submit, 'confirm', _('Confirm')],
+ [:hidden, 'title', @message.content.title],
+# [:hidden, 'upload', @upload1],
+# [:hidden, 'upload1', @upload1],
+ [:hidden, 'body', @upload ? nil : body],
+ [:hidden, 'focus', @focus],
+ [:hidden, 'rating', @rating],
+ [:hidden, 'lang', @message.lang],
+ [:hidden, 'format', @message.content.format],
+ [:hidden, 'desc', @message.desc],
+ [:hidden, 'open', @message.open],
+ [:hidden, 'action', @action.to_s],
+ *uploads_layout
+ )
+ )
+ end
+
+
def update_focus
if @focus and @rating
Focus.new(@request, @focus, @message.id).rating = @rating
----------------------------------------------------------------------
- multi_publish-0.1 - publish text + multiple non-text media items in just one preview/confirm cycle (patch #6143),
boud <=