Forum OpenACS Development: Re: xoWiki and images
Firstly, the general part, not specific to xowiki:
file-selector.tcl accepts as optional parameter
- the package id of the file storage fs_package_id, and
- folder_id
it is possible to provide either of these. If non of these are provided, file-selector gets the id from the sitenode (key file-storage)
file-selector is called via insert-image and insert-ilink,
which are called by the OacsFS plugin of xinha. The plugin is configured via the widget spec of the rich text widget (see https://openacs.org/api-doc/proc-view?proc=template%3a%3awidget%3a%3arichtext)
specific for xowiki:
since it is not so easy, the get the braces for the nested lists of the widget spec right, one can use the "folderspec" parameter of the form for editing the xowiki page. See edit.tcl
xowiki first tries to get the shared community folder of the dotlrn community, or it is using the defaults.
actually, i don't see, where one gets a random behavior, but certainly, it is possible to define your own policy in edit.tcl.
Concerning the dangers of the IMG tag: there are three approaches to this: a) restrict in xinha and/or htmlarea tag check, that only local images are used (no external urls); editing the HTML-source in xinha must be disabled.
b) provide an adp-include for images.
c) restrict the users/sites that are allowed to insert images.
hope, this helps.
if {![info exists fs_package_id]} { # we have not filestore package_id. This must be the first call. if {[info exists folder_id]} { # get package_id from folder_id foreach {fs_package_id root_folder_id} \ [fs::get_folder_package_and_root $folder_id] break } else { # get package_id from package name set key file-storage set id [apm_version_id_from_package_key $key] set mount_url [site_node::get_children -all -package_key $key -node_id $id] array set site_node [site_node::get -url $mount_url] set fs_package_id $site_node(package_id) } }
Changing this default behavior could be done in file-selector.tcl, or else one could edit insert-image.tcl to find the subsite's file-storage instance and then pass that into file-selector.tcl -- which is what I decided to do. The following tries to set fs_package_id using a file-storage instance in a subsite, or the file-storage instance in the main site if there's none in the subsite. Here's a cvs diff:
Index: xowiki/www/xinha/insert-image.tcl =================================================================== RCS file: /cvsroot/openacs-4/packages/xowiki/www/xinha/insert-image.tcl,v retrieving revision 1.3 diff -u -r1.3 insert-image.tcl --- xowiki/www/xinha/insert-image.tcl 30 Dec 2005 00:09:58 -0000 1.3 +++ xowiki/www/xinha/insert-image.tcl 30 Jun 2006 19:28:36 -0000 @@ -7,7 +7,19 @@ {fs_package_id:integer,optional} {folder_id:integer,optional} } - +# get file-storage instance from this subsite +set subsite_node [subsite::get_element -element node_id] +set mount_url [site_node::get_children -package_key file-storage -node_id $subsite_node] +if { $mount_url eq "" } { + # no file-storage instance at this subsite so look to main site + set subsite_node [subsite::get_element -subsite_id [subsite::main_site_id] -element node_id] + set mount_url [site_node::get_children -package_key file-storage -node_id $subsite_node] +} +if { $mount_url ne "" } { + # file-storage instance IS at main site + array set site_node [site_node::get -url $mount_url] + set fs_package_id $site_node(package_id) +} set selector_type "image" set file_selector_link [export_vars -base file-selector \ {fs_package_id folder_id selector_type}]
If there is no file-storage instance in the main site either, then the default code in file-selector.tcl will use the first one it finds -- or generate a server error if there is no file-storage mounted at all, but presumably this shouldn't happen in a real site.
I can commit this if you approve, Gustaf, or if there's a better way, I'd like to see it.
Thanks for your help with your brilliant package, Gustaf!
Do you see arguments against this?
-gustaf
Index: xowiki/www/xinha/file-selector.tcl =================================================================== RCS file: /cvsroot/openacs-4/packages/xowiki/www/xinha/file-selector.tcl,v retrieving revision 1.3 diff -u -r1.3 file-selector.tcl --- xowiki/www/xinha/file-selector.tcl 30 Dec 2005 00:09:58 -0000 1.3 +++ xowiki/www/xinha/file-selector.tcl 30 Jun 2006 22:45:48 -0000 @@ -20,10 +20,26 @@ } else { # get package_id from package name set key file-storage - set id [apm_version_id_from_package_key $key] - set mount_url [site_node::get_children -all -package_key $key -node_id $id] - array set site_node [site_node::get -url $mount_url] - set fs_package_id $site_node(package_id) + # get file-storage instance from this subsite + set subsite_node [subsite::get_element -element node_id] + set mount_url [site_node::get_children -package_key $key -node_id $subsite_node] + if { $mount_url eq "" } { + # no file-storage instance at this subsite so look to main site + set subsite_node [subsite::get_element -subsite_id [subsite::main_site_id] -element node_id] + set mount_url [site_node::get_children -package_key file-storage -node_id $subsite_node] + } + if { $mount_url ne "" } { + # file-storage instance IS at main site + array set site_node [site_node::get -url $mount_url] + set fs_package_id $site_node(package_id) + } else { + # look for any file-storage instance + # probably not what user wants; could return error instead + set id [apm_version_id_from_package_key $key] + set mount_url [site_node::get_children -all -package_key $key -node_id $id] + array set site_node [site_node::get -url $mount_url] + set fs_package_id $site_node(package_id) + } } }
If that looks OK, let me know and I can commit it. Thanks again!