Index: openacs-4/packages/xowiki/tcl/package-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/package-procs.tcl,v diff -u -r1.137 -r1.138 --- openacs-4/packages/xowiki/tcl/package-procs.tcl 6 Oct 2008 12:06:53 -0000 1.137 +++ openacs-4/packages/xowiki/tcl/package-procs.tcl 8 Oct 2008 10:54:55 -0000 1.138 @@ -100,7 +100,7 @@ download 1 } - Package instproc get_lang_and_name {-path -name vlang vlocal_name} { + Package instproc get_lang_and_name {-path -name -default_lang vlang vlocal_name} { my upvar $vlang lang $vlocal_name local_name if {[info exists path]} { # @@ -112,7 +112,8 @@ } elseif {[regexp {^(file|image|swf|download/file|tag)/(.*)$} $path _ lang local_name]} { } else { set local_name $path - set lang [my default_language] + if {![info exists default_lang]} {set default_lang [my default_language]} + set lang $default_lang } } elseif {[info exists name]} { # @@ -121,7 +122,8 @@ if {![regexp {^(..):(.*)$} $name _ lang local_name]} { if {![regexp {^(file|image|swf):(.*)$} $name _ lang local_name]} { set local_name $name - set lang [my default_language] + if {![info exists default_lang]} {set default_lang [my default_language]} + set lang $default_lang } } } @@ -131,12 +133,12 @@ my upvar $vparent parent $vlocal_name local_name if {[regexp {^([^/]+)/(.*)$} $path _ parent local_name]} { - return [::xo::db::CrClass lookup -name $parent -parent_id $folder_id] - } else { - set parent "" - set local_name $path - return $folder_id + set p [::xo::db::CrClass lookup -name $parent -parent_id $folder_id] + if {$p != 0} { return $p } } + set parent "" + set local_name $path + return $folder_id } Package instproc folder_path {{-parent_id ""}} { @@ -167,12 +169,9 @@ return $name } set folder [my folder_path -parent_id $parent_id] - if {[regexp {^[0-9]+$} $name]} { - # the name looks like an unnamed entry - return $folder$name - } my get_lang_and_name -name $name lang stripped_name - return ${lang}:$folder$stripped_name + #return ${lang}:$folder$stripped_name + return $folder$stripped_name } Package ad_instproc pretty_link { @@ -198,10 +197,8 @@ #my msg "input name=$name, lang=$lang" set default_lang [my default_language] - if {$lang eq ""} { - my get_lang_and_name -name $name lang name - #my msg "lang=$lang, name=$name" - } + my get_lang_and_name -default_lang $lang -name $name lang name + set host [expr {$absolute ? ($siteurl ne "" ? $siteurl : [ad_url]) : ""}] if {$anchor ne ""} {set anchor \#$anchor} #my log "--LINK $lang == $default_lang [expr {$lang ne $default_lang}] $name" @@ -211,11 +208,12 @@ # with e.g. //../image/* set package_prefix [my package_url] } - #my msg "lang=$lang name=$name" + #my msg "lang=$lang, default_lang=$default_lang, name=$name" set encoded_name [string map [list %2d - %5f _ %2e .] [ns_urlencode $name]] set folder [my folder_path -parent_id $parent_id] + #my msg "h=${host}, prefix=${package_prefix}, folder=$folder, name=$encoded_name anchor=$anchor" if {$download} { # # use the special download (file) syntax @@ -226,13 +224,14 @@ # If files are physical files in the www directory, add the # language prefix # - set url ${host}${package_prefix}${lang}/$folder$encoded_name$anchor + set url ${host}${package_prefix}$folder${lang}/$encoded_name$anchor } else { # # Use the short notation without language prefix # set url ${host}${package_prefix}$folder$encoded_name$anchor } + #my msg "final url=$url" return $url } @@ -657,63 +656,68 @@ #my log "--u [self args]" [self class] instvar queryparm set item_id 0 + set parent_id $folder_id if {$path ne ""} { # # Try first a direct lookup of whatever we got # - set item_id [::xo::db::CrClass lookup -name $path -parent_id $folder_id] + set item_id [::xo::db::CrClass lookup -name $path -parent_id $parent_id] if {$simple} { if {$item_id != 0} { return [::xo::db::CrClass get_instance_from_db -item_id $item_id] } return "" } - my log "--try $path ($folder_id) -> $item_id" + my log "--try $path ($folder_id/$parent_id) -> $item_id" if {$item_id == 0} { - my get_lang_and_name -path $path lang local_name - set name ${lang}:$local_name + set nname [my normalize_name $path] + + my get_lang_and_name -path $nname lang stripped_name + set name ${lang}:$stripped_name + my log "--setting name to '$name', stripped_name='$stripped_name'" if {$lang eq "download/file" || $lang eq "file"} { # handle subitems, currently only for files set parent_id [my get_parent_and_name \ - -path $local_name -folder_id $folder_id \ + -path $stripped_name -folder_id $folder_id \ parent local_name] set item_id [::xo::db::CrClass lookup -name file:$local_name -parent_id $parent_id] if {$item_id != 0 && $lang eq "download/file"} { upvar $method_var method set method download } - } - - if {$item_id == 0} { - set parent_id [my get_parent_and_name \ - -path $local_name -folder_id $folder_id \ - parent local_name] - set item_id [::xo::db::CrClass lookup -name $local_name -parent_id $parent_id] - #my msg "--try $name -> $item_id // ::xo::db::CrClass lookup -name $name -parent_id $folder_id" - } - - if {$item_id == 0 && $lang eq "tag"} { + } elseif {$lang eq "tag"} { set tag $local_name set summary [::xo::cc query_parameter summary 0] set popular [::xo::cc query_parameter popular 0] set tag_kind [expr {$popular ? "ptag" :"tag"}] set weblog_page [my get_parameter weblog_page] - my get_lang_and_name -path $weblog_page lang local_name - set name $lang:$local_name + my get_lang_and_name -path $weblog_page lang stripped_name + set name $lang:$stripped_name my set object $weblog_page ::xo::cc set actual_query $tag_kind=$tag&summary=$summary } + if {$item_id == 0} { - set nname [my normalize_name $name] - set item_id [::xo::db::CrClass lookup -name $nname -parent_id $folder_id] - my log "--try $nname -> $item_id" + set parent_id [my get_parent_and_name \ + -path $name -folder_id $folder_id \ + parent local_name] + my get_lang_and_name -path $local_name lang stripped_name + set item_id [::xo::db::CrClass lookup -name ${lang}:$stripped_name -parent_id $parent_id] + my log "--try ${lang}:$stripped_name ($folder_id/$parent_id) -> $item_id" } + + if {$item_id == 0} { + set item_id [::xo::db::CrClass lookup -name $stripped_name -parent_id $parent_id] + my log "--try $stripped_name ($folder_id/$parent_id) -> $item_id" + } + } } + if {$item_id != 0} { set revision_id [my query_parameter revision_id 0] set [expr {$revision_id ? "item_id" : "revision_id"}] 0 @@ -914,7 +918,7 @@ and s.object_id = p.page_id $timerange_clause" \ -orderby "p.last_modified desc" \ -limit $max_entries] - my log $sql + #my log $sql db_foreach [my qn get_pages] $sql { #my log "--found $name" if {[string match "::*" $name]} continue Index: openacs-4/packages/xowiki/tcl/xowiki-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-procs.tcl,v diff -u -r1.294 -r1.295 --- openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 6 Oct 2008 14:15:20 -0000 1.294 +++ openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 8 Oct 2008 10:54:56 -0000 1.295 @@ -160,6 +160,8 @@ ::xo::db::require index -table xowiki_last_visited -col user_id,package_id ::xo::db::require index -table xowiki_last_visited -col time + + # Oracle has a limit of 3118 characters for keys, therefore no text as type for "tag" ::xo::db::require table xowiki_tags \ "item_id integer references cr_items(item_id) on delete cascade, @@ -182,7 +184,63 @@ and p.page_id = cr.revision_id \ and ci.publish_status <> 'production'" + + ############################# # + # A simple autoname handler + # + # The autoname handler has the purpose to generate new names based + # on a stem and a parent_id. Typically this is used for the + # autonaming of FormPages. The goal is to generate "nice" names, + # i.e. with rather small numbers. + # + # Instead of using the table below, another option would be to use + # multiple sequences. However, these sequences would have dynamic + # names, it is not clear, whether there are certain limits on the + # number of sequences (in PostgresSQL or Oracle), the database + # dependencies would be larger than in this simple approach. + # + ::xo::db::require table xowiki_autonames \ + "parent_id integer references acs_objects(object_id) ON DELETE CASCADE, + name varchar(3000), + count integer" + ::xo::db::require index -table xowiki_autonames -col parent_id,name -unique true + + Object create autoname + autoname proc generate {-parent_id -name} { + db_transaction { + set already_recorded [db_0or1row [my qn autoname_query] " + select count from xowiki_autonames + where parent_id = $parent_id and name = :name"] + + if {$already_recorded} { + incr count + db_dml [my qn update_autoname_counter] \ + "update xowiki_autonames set count = count + 1 \ + where parent_id = $parent_id and name = :name" + } else { + set count 1 + db_dml [my qn insert_autoname_counter] \ + "insert into xowiki_autonames (parent_id, name, count) \ + values ($parent_id, :name, $count)" + } + } + return $name$count + } + + autoname proc new {-parent_id -name} { + while {1} { + set generated_name [my generate -parent_id $parent_id -name $name] + if {[::xo::db::CrClass lookup -name $generated_name -parent_id $parent_id] eq 0} { + return $generated_name + } + } + } + + ############################# + # + # Create the xowiki_cache + # # We do here the same as in xotcl-core/tcl/05-db-procs.tcl # Read there for the reasons, why the cache is not created in # a -init file..... @@ -192,7 +250,7 @@ ns_cache create xowiki_cache -size 200000 } - + ############################# # # Page definitions # @@ -701,15 +759,15 @@ # prepend the language prefix only, if the entry is not empty if {$stripped_name ne ""} { - if {[my istype ::xowiki::PageInstance]} { + #if {[my istype ::xowiki::PageInstance]} { # # Do not add a language prefix to anonymous pages # - set anon_instances [my get_from_template anon_instances f] - if {$anon_instances} { - return $stripped_name - } - } + #set anon_instances [my get_from_template anon_instances f] + #if {$anon_instances} { + # return $stripped_name + #} + #} if {$nls_language eq ""} {set nls_language [my nls_language]} set name [string range $nls_language 0 1]:$stripped_name } @@ -1265,6 +1323,8 @@ return $content } + + Page instproc record_last_visited {-user_id} { my instvar item_id package_id if {![info exists user_id]} {set user_id [ad_conn user_id]} @@ -2095,14 +2155,17 @@ return [next] } else { #my msg "we have a form '[my get_form]'" - ::xowiki::Form requireFormCSS set form [my get_form] + if {$form eq ""} {return ""} + + ::xowiki::Form requireFormCSS + foreach {form_vars field_names} [my field_names_from_form -form $form] break my array unset __field_in_form if {$form_vars} {foreach v $field_names {my set __field_in_form($v) 1}} set form_fields [my create_form_fields $field_names] my load_values_into_form_fields $form_fields - + # deactivate form-fields and do some final sanity checks foreach f $form_fields {$f set_disabled 1} my form_fields_sanity_check $form_fields @@ -2182,7 +2245,6 @@ my unset_temporary_instance_variables my instvar package_id name - #my msg "save_data old='$old_name' current='$name'" db_transaction { # @@ -2197,7 +2259,7 @@ my map_categories $category_ids my save -use_given_publish_date $use_given_publish_date - # my log "-- old_name $old_name, name $name" + #my log "-- old_name $old_name, name $name" if {$old_name ne $name} { #my msg "do rename from $old_name to $name" $package_id flush_name_cache -name $old_name -parent_id [my parent_id] Index: openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl,v diff -u -r1.186 -r1.187 --- openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 6 Oct 2008 14:15:20 -0000 1.186 +++ openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 8 Oct 2008 10:54:57 -0000 1.187 @@ -1122,7 +1122,7 @@ # (might happen, when e.g. set via @cr_fields ... hidden) set name_field [my lookup_form_field -name _name $form_fields] if {$anon_instances} { - $name_field config_from_spec hidden + #$name_field config_from_spec hidden } else { if {[$name_field istype ::xowiki::formfield::hidden] && [$name_field required] == true} { $name_field config_from_spec text,required @@ -1207,9 +1207,11 @@ #my set name [$package_id query_parameter name ""] # TODO: maybe use __object_name to for POST url to make code # more straightworward - set n [$package_id query_parameter name \ - [::xo::cc form_parameter __object_name ""]] - if {$n ne ""} { my set name $n } + #set n [$package_id query_parameter name \ + # [::xo::cc form_parameter __object_name ""]] + #if {$n ne ""} { + # my name $n + #} } array set __ia [my set instance_attributes] @@ -1219,10 +1221,16 @@ # for named entries, just set the entry fields to empty, # without changing the instance variables if {[my is_new_entry [my name]]} { - if {![$ff(_title) istype ::xowiki::formfield::hidden]} { + if {$anon_instances} { + set name [autoname new -name [$page_template name] -parent_id $page_template] + #my msg "generated name=$name, page_template-name=[$page_template name]" + $ff(_name) value $name + } else { + $ff(_name) value "" + } + if {![$ff(_title) istype ::xowiki::formfield::hidden]} { $ff(_title) value "" } - if {!$anon_instances} {$ff(_name) value ""} foreach var [list title detail_link text description] { if {[my exists_query_parameter $var]} { set value [my query_parameter $var]