Index: openacs-4/packages/acs-content-repository/acs-content-repository.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/acs-content-repository.info,v
diff -u -r1.109.2.24 -r1.109.2.25
--- openacs-4/packages/acs-content-repository/acs-content-repository.info 9 Aug 2016 16:31:26 -0000 1.109.2.24
+++ openacs-4/packages/acs-content-repository/acs-content-repository.info 27 Oct 2016 18:01:59 -0000 1.109.2.25
@@ -2,39 +2,41 @@
- ACS Content Repository
- ACS Content Repository Services
- t
- t
-
-
- OpenACS
- The canonical repository for OpenACS content.
- 2016-08-08
- OpenACS
- Provides the API for creating and managing user generated content including
- full support for versioning, rendering content to the filesystem, folders and composite content items, and
- other CMS backing functionality. Utilized by Bug Tracker, File Storage, and other packages.
+ ACS Content Repository
+ ACS Content Repository Services
+ t
+ t
+ f
+ t
+
+
+ OpenACS
+ The canonical repository for OpenACS content.
+ 2016-10-24
+ OpenACS
+ Provides the API for creating and managing user generated content including
+ full support for versioning, rendering content to the filesystem, folders and composite content items, and
+ other CMS backing functionality. Utilized by Bug Tracker, File Storage, and other packages.
- GPL
- 3
+ GPL
+ 3
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
Index: openacs-4/packages/acs-content-repository/tcl/content-item-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/content-item-procs.tcl,v
diff -u -r1.24.2.2 -r1.24.2.3
--- openacs-4/packages/acs-content-repository/tcl/content-item-procs.tcl 5 Jan 2016 15:28:43 -0000 1.24.2.2
+++ openacs-4/packages/acs-content-repository/tcl/content-item-procs.tcl 27 Oct 2016 18:02:00 -0000 1.24.2.3
@@ -75,14 +75,18 @@
if {$creation_user eq ""} {
set creation_user [ad_conn user_id]
}
-
if {$creation_ip eq ""} {
set creation_ip [ad_conn peeraddr]
}
if {$package_id eq ""} {
set package_id [ad_conn package_id]
}
+ set mime_type [cr_check_mime_type \
+ -filename $name \
+ -mime_type $mime_type \
+ -file $tmp_filename]
+
set var_list [list]
lappend var_list \
[list name $name] \
@@ -102,53 +106,53 @@
[list is_live $is_live ] \
[list storage_type $storage_type]
- # we don't pass title, text, or data to content_item__new
- # because the magic revision creation of the pl/sql proc does
- # not create a proper subtype of content revision, also it
- # can't set attributes of an extended type
+ # we don't pass title, text, or data to content_item__new because
+ # the magic revision creation of the pl/sql proc does not create a
+ # proper subtype of content revision, also it can't set attributes
+ # of an extended type
- # the content type is not the object type of the cr_item so we pass in
- # the cr_item subtype here and content_type as part of
+ # the content type is not the object type of the cr_item so we
+ # pass in the cr_item subtype here and content_type as part of
# var_list
db_transaction {
# An explict lock was necessary for PostgreSQL between 8.0 and
- # 8.2; left the following statement here for documentary purposes
+ # 8.2; left the following statement here for documentary
+ # purposes
#
# db_dml lock_objects "LOCK TABLE acs_objects IN SHARE ROW EXCLUSIVE MODE"
- set item_id [package_exec_plsql \
- -var_list $var_list \
- content_item new]
- # if we have attributes we pass in everything
- # and create a revision with all subtype attributes that were
- # passed in
+ set item_id [package_exec_plsql \
+ -var_list $var_list \
+ content_item new]
+ # if we have attributes we pass in everything and create a
+ # revision with all subtype attributes that were passed in
- # since we can't rely on content_item__new to create a revision
- # we have to pass is_live to content::revision::new and
- # set the live revision there
- if {([info exists title] && $title ne "")
+ # since we can't rely on content_item__new to create a
+ # revision we have to pass is_live to content::revision::new
+ # and set the live revision there
+ if {([info exists title] && $title ne "")
|| ([info exists text] && $text ne "")
- || ([info exists data] && $data ne "")
- || ([info exists tmp_filename] && $tmp_filename ne "")
- || [llength $attributes]
- } {
- content::revision::new \
- -item_id $item_id \
- -title $title \
- -description $description \
- -content $text \
- -mime_type $mime_type \
- -content_type $content_type \
- -is_live $is_live \
- -package_id $package_id \
- -creation_user $creation_user \
- -creation_ip $creation_ip \
- -creation_date $creation_date \
- -nls_language $nls_language \
- -tmp_filename $tmp_filename \
- -attributes $attributes
+ || ([info exists data] && $data ne "")
+ || ([info exists tmp_filename] && $tmp_filename ne "")
+ || [llength $attributes]
+ } {
+ content::revision::new \
+ -item_id $item_id \
+ -title $title \
+ -description $description \
+ -content $text \
+ -mime_type $mime_type \
+ -content_type $content_type \
+ -is_live $is_live \
+ -package_id $package_id \
+ -creation_user $creation_user \
+ -creation_ip $creation_ip \
+ -creation_date $creation_date \
+ -nls_language $nls_language \
+ -tmp_filename $tmp_filename \
+ -attributes $attributes
+ }
}
- }
return $item_id
}
Index: openacs-4/packages/acs-content-repository/tcl/content-revision-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/content-revision-procs.tcl,v
diff -u -r1.26.2.2 -r1.26.2.3
--- openacs-4/packages/acs-content-repository/tcl/content-revision-procs.tcl 2 Jan 2016 21:24:47 -0000 1.26.2.2
+++ openacs-4/packages/acs-content-repository/tcl/content-revision-procs.tcl 27 Oct 2016 18:02:00 -0000 1.26.2.3
@@ -135,6 +135,11 @@
select table_name from acs_object_types where object_type = :content_type
}]
+ set mime_type [cr_check_mime_type \
+ -filename $title \
+ -mime_type $mime_type \
+ -file $tmp_filename]
+
set query_text "insert into ${table_name}i
(revision_id, object_type, creation_user, creation_date, creation_ip, title, description, item_id, object_package_id, mime_type $attribute_names)
values (:revision_id, :content_type, :creation_user, :creation_date, :creation_ip, :title, :description, :item_id, :package_id, :mime_type $attribute_values)"
Index: openacs-4/packages/acs-content-repository/tcl/content-revision-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/content-revision-procs.xql,v
diff -u -r1.2 -r1.2.14.1
--- openacs-4/packages/acs-content-repository/tcl/content-revision-procs.xql 31 May 2006 13:42:30 -0000 1.2
+++ openacs-4/packages/acs-content-repository/tcl/content-revision-procs.xql 27 Oct 2016 18:02:00 -0000 1.2.14.1
@@ -11,7 +11,13 @@
- select storage_type from cr_items where item_id=:item_id
+ select storage_type from cr_items where item_id=:item_id
+
+
+
+ select exists(select 1 from cr_mime_types where mime_type = :mime_type)
+
+
Index: openacs-4/packages/acs-content-repository/tcl/revision-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/revision-procs.tcl,v
diff -u -r1.32.2.2 -r1.32.2.3
--- openacs-4/packages/acs-content-repository/tcl/revision-procs.tcl 5 Jan 2016 14:55:50 -0000 1.32.2.2
+++ openacs-4/packages/acs-content-repository/tcl/revision-procs.tcl 27 Oct 2016 18:02:00 -0000 1.32.2.3
@@ -358,7 +358,44 @@
return [db_string registered_type_for_mime_type "" -default ""]
}
+ad_proc cr_check_mime_type {
+ -mime_type
+ {-filename ""}
+ {-file ""}
+} {
+ Check wether the mimetype is registered. If not, check wether it
+ can be guessed from the filename. If guessed mimetype is not
+ registered optionally insert it.
+ @param mime_type param The mime type
+ @param filename the filename
+ @param file the actual file being saved. This option currently
+ doesn't have any effect, but in the future would be better
+ to inspect the actual file content instead of trusting the user.
+
+ @return the mapped mimetype
+} {
+ # TODO: we use only the extension to get the mimetype. Something
+ # better should be done, like inspecting the actual content of the
+ # file and never trust the user on this regard, but as this
+ # involves changes also in the data model, we leave this for the
+ # future. Usages of this proc in the systems are already set to
+ # give us the path to the file here.
+ set extension [string tolower [string trimleft [file extension $filename] "."]]
+ if {[db_0or1row lookup_mimetype {}]} {
+ return $mime_type
+ }
+ set mime_type [string tolower [ns_guesstype $filename]]
+ if {[db_0or1row lookup_mimetype {}]} {
+ return $mime_type
+ }
+ set allow_mimetype_creation_p \
+ [parameter::get \
+ -parameter AllowMimeTypeCreationP -default 0]
+ return [cr_filename_to_mime_type -create=$allow_mimetype_creation_p \
+ $filename]
+}
+
ad_proc -public cr_filename_to_mime_type {
-create:boolean
filename
@@ -381,10 +418,11 @@
return "*/*"
}
- if {[db_0or1row lookup_mimetype { select mime_type from cr_extension_mime_type_map where extension = :extension }]} {
+ if {[db_0or1row lookup_mimetype {}]} {
return $mime_type
} else {
set mime_type [string tolower [ns_guesstype $filename]]
+
ns_log Debug "guessed mime \"$mime_type\" create_p $create_p"
if {(!$create_p) || $mime_type eq "*/*" || $mime_type eq ""} {
# we don't have anything meaningful for this mimetype
Index: openacs-4/packages/acs-content-repository/tcl/revision-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/revision-procs.xql,v
diff -u -r1.7 -r1.7.14.1
--- openacs-4/packages/acs-content-repository/tcl/revision-procs.xql 4 Jun 2006 00:45:23 -0000 1.7
+++ openacs-4/packages/acs-content-repository/tcl/revision-procs.xql 27 Oct 2016 18:02:00 -0000 1.7.14.1
@@ -1,64 +1,80 @@
-
-
- select i.storage_type, i.storage_area_key, r.mime_type, i.item_id,
- r.content_length
- from cr_items i, cr_revisions r
- where r.revision_id = :revision_id and i.item_id = r.item_id
-
-
+
+
+ select i.storage_type, i.storage_area_key, r.mime_type, i.item_id,
+ r.content_length
+ from cr_items i, cr_revisions r
+ where r.revision_id = :revision_id and i.item_id = r.item_id
+
+
-
-
- select content
- from cr_revisions
- where revision_id = :revision_id
-
-
+
+
+ select content
+ from cr_revisions
+ where revision_id = :revision_id
+
+
-
-
- select content_type
- from cr_items
- where item_id = :item_id
-
-
+
+
+ select content_type
+ from cr_items
+ where item_id = :item_id
+
+
-
-
- insert into cr_mime_types (mime_type)
- select :mime_type
- from dual
- where not exists (select 1 from cr_mime_types where mime_type = :mime_type)
-
-
+
+
+ insert into cr_mime_types (mime_type)
+ select :mime_type
+ from dual
+ where not exists (select 1 from cr_mime_types where mime_type = :mime_type)
+
+
-
-
- select content_type
- from cr_content_mime_type_map
- where mime_type = :mime_type
-
-
+
+
+ select content_type
+ from cr_content_mime_type_map
+ where mime_type = :mime_type
+
+
-
-
- select 1
- from cr_content_mime_type_map
- where mime_type = :mime_type
- and content_type = 'content_revision'
-
-
+
+
+ select 1
+ from cr_content_mime_type_map
+ where mime_type = :mime_type
+ and content_type = 'content_revision'
+
+
-
+
- select 1
- from cr_content_mime_type_map
- where mime_type = :mime_type
- and content_type = 'image'
+ select mime_type
+ from cr_extension_mime_type_map
+ where extension = :extension
-
+
+
+
+ select mime_type
+ from cr_extension_mime_type_map
+ where extension = :extension
+
+
+
+
+
+ select 1
+ from cr_content_mime_type_map
+ where mime_type = :mime_type
+ and content_type = 'image'
+
+
+
Index: openacs-4/packages/file-storage/tcl/file-storage-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/file-storage-procs.tcl,v
diff -u -r1.69.2.2 -r1.69.2.3
--- openacs-4/packages/file-storage/tcl/file-storage-procs.tcl 2 Jan 2016 20:13:30 -0000 1.69.2.2
+++ openacs-4/packages/file-storage/tcl/file-storage-procs.tcl 27 Oct 2016 18:02:00 -0000 1.69.2.3
@@ -752,9 +752,15 @@
set indbp "f"
set storage_type "file"
}
- if {$mime_type eq ""} {
- set mime_type [cr_filename_to_mime_type -create -- $name]
- }
+
+ # This check also happens in content repository, but as something
+ # similar was already here and mimetype coming from this was used
+ # afterwards, we kept this behavior.
+ set mime_type [cr_check_mime_type \
+ -filename $name \
+ -mime_type $mime_type \
+ -file $tmp_filename]
+
# we have to do this here because we create the object before
# calling cr_import_content
@@ -1030,10 +1036,15 @@
if {$storage_type eq ""} {
set storage_type [db_string get_storage_type {}]
}
- if {$mime_type eq ""} {
- set mime_type [cr_filename_to_mime_type -create -- $name]
- }
+ # This check also happens in content repository, but as something
+ # similar was already here and mimetype coming from this was used
+ # afterwards, we kept this behavior.
+ set mime_type [cr_check_mime_type \
+ -filename $name \
+ -mime_type $mime_type \
+ -file $tmp_filename]
+
set tmp_size [file size $tmp_filename]
set parent_id [fs::get_parent -item_id $item_id]
set revision_id [cr_import_content \
Index: openacs-4/packages/xotcl-core/tcl/cr-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-core/tcl/cr-procs.tcl,v
diff -u -r1.54.2.14 -r1.54.2.15
--- openacs-4/packages/xotcl-core/tcl/cr-procs.tcl 31 Aug 2016 11:04:14 -0000 1.54.2.14
+++ openacs-4/packages/xotcl-core/tcl/cr-procs.tcl 27 Oct 2016 18:02:00 -0000 1.54.2.15
@@ -948,7 +948,13 @@
[my info class] instvar storage_type
set revision_id [xo::dc nextval acs_object_id_seq]
if {$storage_type eq "file"} {
- my instvar import_file
+ my instvar import_file mime_type name
+ # Get the mime_type from the file, eventually creating a new
+ # one if it's unrecognized.
+ set mime_type [cr_check_mime_type \
+ -mime_type $mime_type \
+ -filename $name \
+ -file $import_file]
set text [cr_create_content_file $item_id $revision_id $import_file]
}
::xo::dc [::xo::dc insert-view-operation] revision_add \
@@ -1062,12 +1068,29 @@
"[my set __title_prefix] ($name)" : $name}]
}
+ if {$storage_type eq "file"} {
+ # Get the mime_type from the file, eventually creating a new
+ # one if it's unrecognized.
+ set mime_type [cr_check_mime_type \
+ -mime_type $mime_type \
+ -filename $name \
+ -file $import_file]
+ }
+
set item_id [::xo::db::sql::content_item new \
- -name $name -parent_id $parent_id -creation_user $creation_user \
- -creation_ip $creation_ip \
- -item_subtype "content_item" -content_type $object_type \
- -description $description -mime_type $mime_type -nls_language $nls_language \
- -is_live f -storage_type $storage_type -package_id $package_id -with_child_rels f]
+ -name $name \
+ -parent_id $parent_id \
+ -creation_user $creation_user \
+ -creation_ip $creation_ip \
+ -item_subtype "content_item" \
+ -content_type $object_type \
+ -description $description \
+ -mime_type $mime_type \
+ -nls_language $nls_language \
+ -is_live f \
+ -storage_type $storage_type \
+ -package_id $package_id \
+ -with_child_rels f]
if {$storage_type eq "file"} {
set text [cr_create_content_file $item_id $revision_id $import_file]