Index: openacs-4/packages/xowiki/tcl/link-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/link-procs.tcl,v diff -u -r1.106 -r1.107 --- openacs-4/packages/xowiki/tcl/link-procs.tcl 27 Jun 2018 12:07:09 -0000 1.106 +++ openacs-4/packages/xowiki/tcl/link-procs.tcl 3 Sep 2024 15:37:55 -0000 1.107 @@ -11,71 +11,73 @@ # generic link methods # Class create BaseLink -parameter { - cssclass cssid href label title target extra_query_parameter + cssclass cssid href label title target extra_query_parameter {anchor ""} {query ""} } BaseLink instproc built_in_target {} { # currently, we do not support named frames, which are mostly deprecated - return [expr {[:target] in {_blank _self _parent _top}}] + return [expr {${:target} in {_blank _self _parent _top}}] } - + BaseLink instproc anchor_atts {} { set atts {} - if {[info exists :title]} {lappend atts "title='[string map [list ' {'}] [:title]]'"} + if {[info exists :title]} {lappend atts "title='[string map [list ' {'}] ${:title}]'"} if {[info exists :target] && [:built_in_target]} { - lappend atts "target='[:target]'" + lappend atts "target='${:target}'" } return [join $atts " "] } BaseLink instproc mk_css_class {{-additional ""} {-default ""}} { - set cls [expr {[info exists :cssclass] ? [:cssclass] : $default}] + set cls [expr {[info exists :cssclass] ? ${:cssclass} : $default}] if {$additional ne ""} { if {$cls eq ""} {set cls $additional} else {append cls " " $additional} } if {$cls ne ""} {set cls "class='$cls'"} - return $cls + return $cls } BaseLink instproc mk_css_class_and_id {{-additional ""} {-default ""}} { - if {[info exists :cssid]} {set id "id='[:cssid]'"} else {set id ""} + if {[info exists :cssid]} {set id "id='${:cssid}'"} else {set id ""} set cls [:mk_css_class -additional $additional -default $default] return [string trim "$cls $id"] } # # external links # - Class create ExternalLink -superclass BaseLink + Class create ExternalLink -superclass BaseLink ExternalLink instproc render {} { set css_atts [:mk_css_class_and_id -additional external] - return "[ns_quotehtml ${:label}] " + return "${:label}" } # # internal links # Class create Link -superclass BaseLink -parameter { - {type link} name lang stripped_name page + {type link} name lang stripped_name page parent_id package_id item_id {form ""} revision_id is_self_link } Link instproc init {} { - set class [self class]::[:type] + #:log "--L link '${:name}' has item_id <[expr {[info exists :item_id] ? ${:item_id} : {none}}]>" + set class [self class]::${:type} if {[:isclass $class]} {:class $class} if {![info exists :name]} { - set :name [string trimleft [:lang]:${:stripped_name} :] + set :name [string trimleft ${:lang}:${:stripped_name} :] } elseif {![info exists :stripped_name]} { # set stripped name and lang from provided name or to the default if {![regexp {^(..):(.*)$} ${:name} _ lang :stripped_name]} { - set :stripped_name ${:name}; set :lang "" + set :stripped_name ${:name} + set :lang "" } } if {![info exists :label]} {set :label ${:name}} if {![info exists :parent_id]} {set :parent_id [${:page} parent_id]} if {![info exists :package_id]} {set :package_id [${:page} package_id]} - #:msg "--L link has class [:info class] // $class // [:type] // ${:parent_id}" + #:log "--L link '${:name}' has class [:info class] // $class // ${:type} // parent ${:parent_id} // page ${:page} // [info exists :item_id]" } Link instproc link_name {-lang -stripped_name} { return $lang:$stripped_name @@ -86,8 +88,7 @@ Link instproc render_target {href label} { #ns_log notice render_target - set target [:target] - if {[info commands ::xowiki::template::$target] ne ""} { + if {[info commands ::xowiki::template::${:target}] ne ""} { # # The target template exists. Use the template # @@ -97,38 +98,37 @@ # can be referenced multiple times. The link is included for # each occurrence. # - set item_id ${:item_id} - set targetId [xowiki::Includelet html_id ${:item_id}-$target] - set page [::xo::db::CrClass get_instance_from_db -item_id $item_id -revision_id 0] + set targetId [xowiki::Includelet html_id ${:item_id}-${:target}] + set page [::xo::db::CrClass get_instance_from_db -item_id ${:item_id} -revision_id 0] set content "Loading ..." set withBody true - - if {[::xowiki::template::$target render_content]} { + + if {[::xowiki::template::${:target} render_content]} { set key ::__xowiki_link_rendered($targetId) if {![info exists $key]} { set $key 1 set content [$page render_content] } else { #ns_log notice "modal with is already included: $key" - set page ::$item_id + set page ::${:item_id} set withBody false } } - set result [::xowiki::template::$target render \ + set result [::xowiki::template::${:target} render \ -with_body $withBody \ -title [$page title] \ -id $targetId \ -content $content \ -label $label \ -href $href] - + return $result } else { - ns_log notice "xowiki::link: unknown target $target" + ns_log notice "xowiki::link: unknown target ${:target}" return "$label" } } - + Link instproc render_found {href label} { if {$href eq ""} { return "$label" @@ -142,57 +142,75 @@ if {$href eq ""} { return \[$label\] } else { - return " $label" + return "$label" } } Link instproc pretty_link {item_id} { - return [::${:package_id} pretty_link -parent_id ${:parent_id} -lang [:lang] \ - -anchor [:anchor] -query [:query] [:name]] + if {$item_id == 0} { + set pageArg "" + } else { + set obj ::$item_id + if {![nsf::is object $obj]} { + set obj [::xo::db::CrClass get_instance_from_db -item_id $item_id] + } + set pageArg [list -page $obj] + } + return [::${:package_id} pretty_link \ + -parent_id ${:parent_id} \ + -lang ${:lang} \ + -anchor ${:anchor} \ + -query ${:query} \ + {*}$pageArg \ + ${:name}] } Link instproc new_link {} { - set page [:page] - set nls_language [$page get_nls_language_from_lang [:lang]] + set nls_language [${:page} get_nls_language_from_lang ${:lang}] if {${:form} ne ""} { - return [${:package_id} make_form_link -form ${:form} \ + return [::${:package_id} make_form_link \ + -form ${:form} \ -parent_id ${:parent_id} \ - -name [:name] \ + -name ${:name} \ -nls_language $nls_language] } - if {[$page exists __unresolved_object_type]} { + if {[${:page} exists __unresolved_object_type]} { + # # get the desired object_type for unresolved entries - set object_type [$page set __unresolved_object_type] + # + set object_type [${:page} set __unresolved_object_type] } else { - set object_type [[$page info class] set object_type] + set object_type [[${:page} info class] set object_type] if {$object_type ne "::xowiki::Page" && $object_type ne "::xowiki::PlainPage"} { + # # TODO: this is a temporary solution. We should find a way to # pass similar to file or image entries the type of this # entry. Maybe we can get the type as well from a kind of # blackboard, where the type of the "edit" wiki-menu-entry is # stored as well. + # set object_type ::xowiki::Page } } - return [$page new_link \ + return [${:page} new_link \ {*}[expr {[info exists object_type] ? [list -object_type $object_type] : {}}] \ - -name [:name] -title [:label] -parent_id ${:parent_id} \ + -name ${:name} -title ${:label} -parent_id ${:parent_id} \ -nls_language $nls_language ${:package_id}] } Link instproc render {} { - set page [:page] set item_id [:resolve] if {$item_id} { - $page references resolved [list $item_id [:type]] + ${:page} references resolved [list $item_id ${:type}] ::xowiki::Package require ${:package_id} if {![info exists :href]} { set :href [:pretty_link $item_id] } - :render_found ${:href} [:label] + :render_found ${:href} ${:label} } else { set new_link [:new_link] - set html [:render_not_found $new_link [:label]] - $page references unresolved $html + set html [:render_not_found $new_link ${:label}] + ${:page} references unresolved \ + [list parent_id ${:parent_id} name ${:name} link_type ${:type} html $html] return $html } } @@ -205,7 +223,7 @@ set package_id [site_node::get_children -node_id $a -package_key xowiki \ -filters [list name $name] -element package_id] if {$package_id ne ""} { - #:log "--LINK found package_id=$package_id [:isobject ::$package_id]" + #:log "--LINK found package_id=$package_id [nsf::is object ::$package_id]" ::xowiki::Package require $package_id return $package_id } @@ -226,114 +244,114 @@ {-label "LABEL"} {-href ""} } { - set result "" + set result "" # this can be used into templates as id to safely attach event # handlers to elements - set timed_id [clock microseconds] + set timed_id [clock microseconds] if {$with_link} {append result [subst [:link_template]]} if {$with_body} {append result [subst [:body_template]]} return $result } - # - # Small bootstrap modal - # - ::xowiki::LinkTemplate create ::xowiki::template::modal-sm -link_template { - $label - } -body_template { - - } +# # +# # Small bootstrap modal +# # +# ::xowiki::LinkTemplate create ::xowiki::template::modal-sm -link_template { +# $label +# } -body_template { +# +# } - # - # Large bootstrap modal - # - ::xowiki::LinkTemplate create ::xowiki::template::modal-lg -link_template { - $label - } -body_template { - - } +# # +# # Large bootstrap modal +# # +# ::xowiki::LinkTemplate create ::xowiki::template::modal-lg -link_template { +# $label +# } -body_template { +# +# } - # - # Small bootstrap modal using ajax - # - ::xowiki::LinkTemplate create ::xowiki::template::modal-sm-ajax -render_content false -link_template { - $label - } -body_template { - - - } +# # +# # Small bootstrap modal using ajax +# # +# ::xowiki::LinkTemplate create ::xowiki::template::modal-sm-ajax -render_content false -link_template { +# $label +# } -body_template { +# +# +# } - # - # Large bootstrap modal using ajax - # - ::xowiki::LinkTemplate create ::xowiki::template::modal-lg-ajax -render_content false -link_template { -$label - } -body_template { - - -} +# # +# # Large bootstrap modal using ajax +# # +# ::xowiki::LinkTemplate create ::xowiki::template::modal-lg-ajax -render_content false -link_template { +# $label +# } -body_template { +# +# +# } # # folder links @@ -343,8 +361,11 @@ return $stripped_name } ::xowiki::Link::folder instproc pretty_link {item_id} { + set page [expr {$item_id == 0 ? "" : "-page ::$item_id"}] return [::${:package_id} pretty_link \ - -anchor [:anchor] -parent_id ${:parent_id} -query [:query] ${:name} ] + -anchor ${:anchor} -parent_id ${:parent_id} -query ${:query} \ + {*}$page \ + ${:name} ] } # @@ -354,25 +375,27 @@ return_only } ::xowiki::Link::language instproc render {} { - set page [:page] set item_id [:resolve] if {$item_id} { set image_css_class "found" - set link [${:package_id} pretty_link -lang ${:lang} -parent_id ${:parent_id} [:stripped_name]] + set link [::${:package_id} pretty_link \ + -lang ${:lang} -parent_id ${:parent_id} \ + -page $item_id \ + ${:stripped_name}] } else { set image_css_class "undefined" - set last_page_id [$page set item_id] - set object_type [[$page info class] set object_type] + set last_page_id [${:page} set item_id] + set object_type [[${:page} info class] set object_type] set name ${:name} - set link [${:package_id} make_link ${:package_id} \ + set link [::${:package_id} make_link ${:package_id} \ edit-new object_type name last_page_id] } # :log "--lang_link=$link" - if {[info exists :return_only] && [:return_only] ne $image_css_class} { + if {[info exists :return_only] && ${:return_only} ne $image_css_class} { set link "" } if {$link ne ""} { - $page lappend lang_links($image_css_class) \ + ${:page} lappend lang_links($image_css_class) \ "${:lang}" } @@ -382,16 +405,16 @@ # # image links # - + Class create ::xowiki::Link::image -superclass ::xowiki::Link \ -parameter { - center float width height + center float width height padding padding-right padding-left padding-top padding-bottom margin margin-left margin-right margin-top margin-bottom - border border-width position top botton left right + border border-width position top bottom left right } ::xowiki::Link::image instproc resolve_href {href} { - set l [[:page] create_link $href] + set l [${:page} create_link $href] if {[$l istype ::xowiki::ExternalLink]} { set href [$l href] } else { @@ -401,26 +424,31 @@ return $href } ::xowiki::Link::image instproc render {} { - set page [:page] set item_id [:resolve] - #:log "-- image resolve for $page returned $item_id (name=${:name}, label=${:label})" - if {$item_id} { - set link [${:package_id} pretty_link -download true -query [:query] \ - -absolute [$page absolute_links] -parent_id ${:parent_id} ${:name}] - #:log "--l fully quali [$page absolute_links], link=$link" - $page references resolved [list $item_id [:type]] + #:log "-- image resolve for ${:page} returned $item_id (name=${:name}, label=${:label})" + if {$item_id != 0} { + set link [::${:package_id} pretty_link \ + -download true \ + -query ${:query} \ + -absolute [expr {[${:page} exists absolute_links] ? [${:page} absolute_links] : 0}] \ + -parent_id ${:parent_id} \ + -page $item_id \ + ${:name}] + #:log "--l fully quali [${:page} absolute_links], link=$link [info commands ::$item_id]" + ${:page} references resolved [list $item_id ${:type}] :render_found $link ${:label} } else { - set last_page_id [$page set item_id] + set last_page_id [${:page} set item_id] set object_type ::xowiki::File set name ${:name} - set link [${:package_id} make_link ${:package_id} edit-new object_type \ + set link [::${:package_id} make_link ${:package_id} edit-new object_type \ [list parent_id ${:parent_id}] \ [list title [ad_html_to_text -no_format -- ${:label}]] \ [list return_url [::xo::cc url]] \ - autoname name last_page_id] + autoname name last_page_id] set html [:render_not_found $link ${:label}] - $page references unresolved $html + ${:page} references unresolved \ + [list parent_id ${:parent_id} name ${:name} link_type ${:type} html $html] return $html } } @@ -430,49 +458,81 @@ float width height center padding padding-right padding-left padding-top padding-bottom margin margin-left margin-right margin-top margin-bottom - border border-width position top botton left right + border border-width position top bottom left right } { if {[info exists :$a]} { if {$a eq "center"} {set pre "
"; set post "
"; continue} append style "$a: [set :$a];" } } - if {$style ne ""} {set style "style='$style'"} - if {[info exists :geometry]} {append link "?geometry=${:geometry}"} - set label [string map [list ' "'"] $label] - if {[info exists :href]} {set href ${:href}} {set href ""} + if {$style ne ""} { + set style "style='$style'" + } + if {[info exists :geometry]} { + append link "?geometry=${:geometry}" + } + #set label [string map [list ' "'"] $label] + set href [expr {[info exists :href] ? ${:href} : ""}] set cls [:mk_css_class_and_id -default [expr {$link ne "" ? "image" : "refused-link"}]] if {$href ne ""} { set href [:resolve_href $href] - if {[string match "java*" $href]} {set href .} - if {[info exists :revision_id]} {append href ?revision_id=[:revision_id]} - return "$pre[ns_quotehtml $label]$post" + if {[string match "java*" $href]} { + set href . + } + if {[info exists :revision_id]} { + append href ?revision_id=${:revision_id} + } + return [subst {$pre$label$post}] } else { - if {[info exists :revision_id]} {append link ?revision_id=[:revision_id]} - return "$pre[ns_quotehtml $label]$post" + if {[info exists :revision_id]} {append link ?revision_id=${:revision_id}} + return [subst {$pre$label$post}] } } # # localimage link # - + Class create ::xowiki::Link::localimage -superclass ::xowiki::Link::image ::xowiki::Link::localimage instproc render {} { - :render_found [:href] [:label] + :render_found ${:href} ${:label} } # + # # file link # Class create ::xowiki::Link::file -superclass ::xowiki::Link::image -parameter { - width height align pluginspage pluginurl hidden href - autostart loop volume controls controller mastersound starttime endtime + width height hidden } + foreach deprecated_attribute { + align name pluginspage pluginurl href autostart + loop volume controls controller mastersound starttime endtime + } { + ::xowiki::Link::file ad_instproc -private -deprecated $deprecated_attribute {value:optional} { + Provide warning for deprecated HTML attribute; + this will be removed in releases after OpenACS 5.10. + } { + if {[info exists value]} { + set :[self proc] $value + } + return [set :[self proc]] + } + + } + ::xowiki::Link::file instproc render_found {internal_href label} { + # + # Many of the attributes below are from HTML4 and deprecated (see + # "deprecated_attribute" above). We just removed "href" from the list + # of still accepted attributes, since this is set often via BaseLink, + # and it could harm applications, where the " variant of the + # stopped working due to newer browsers, stopping to support legacy + # HTML attributes. + # foreach f { width height align pluginspage pluginurl hidden href autostart loop volume controls controller mastersound starttime endtime @@ -483,19 +543,19 @@ } if {[info exists :extra_query_parameter]} { set pairs {} - foreach {pair} [:extra_query_parameter] { + foreach {pair} ${:extra_query_parameter} { lappend pairs [lindex $pair 0]=[ns_urlencode [lindex $pair 1]] } append internal_href ?[string map [list ' "'"] [join $pairs &]] - if {[info exists :revision_id]} {append internal_href &revision_id=[:revision_id]} + if {[info exists :revision_id]} {append internal_href &revision_id=${:revision_id}} } else { - if {[info exists :revision_id]} {append internal_href ?revision_id=[:revision_id]} + if {[info exists :revision_id]} {append internal_href ?revision_id=${:revision_id}} } if {![info exists embed_options]} { - return "$label " + return "$label" } else { set internal_href [string map [list %2e .] $internal_href] - return "" + return "" } } @@ -508,7 +568,7 @@ } ::xowiki::Link::css instproc render_found {href label} { if {[info exists :order]} { - ::xo::Page requireCSS -order [:order] $href + ::xo::Page requireCSS -order ${:order} $href } else { ::xo::Page requireCSS $href } @@ -535,31 +595,32 @@ ::xowiki::Link::swf instproc render_found {href label} { ::xo::Page requireJS /resources/xowiki/swfobject.js - #set link [${:package_id} pretty_link -absolute true -siteurl http://localhost:8003 ${:name}]/download.swf + #set link [::${:package_id} pretty_link -absolute true -siteurl http://localhost:8003 ${:name}]/download.swf lassign {320 240 7} width height version foreach a {width height version} {if {[info exists :$a]} {set $a [set :$a]}} set id [::xowiki::Includelet html_id ${:item_id}] set addParams "" foreach a {quality wmode align salign play loop menu scale} { if {[info exists :$a]} {append addParams "so.addParam('$a', '[set :$a]');\n"} } - - return "
$label
- - " - } + return [ns_trim [subst {
$label
+ + }]] + } + # # glossary links # Class create ::xowiki::Link::glossary -superclass ::xowiki::Link ::xowiki::Link::glossary instproc resolve {} { # look for a package instance of xowiki, named "glossary" (the type) - set id [:lookup_xowiki_package_by_name [:type] \ + set id [:lookup_xowiki_package_by_name ${:type} \ [site_node::get_node_id_from_object_id -object_id ${:package_id}]] #:log "--LINK glossary lookup returned package_id $id" if {$id > 0} { @@ -569,9 +630,9 @@ #::xowiki::Package initialize -package_id $id #:log "--u setting package_id to $id" # lookup the item from the found folder - return [::xo::db::CrClass lookup -name [:name] -parent_id [$id set parent_id]] + return [::xo::db::CrClass lookup -name ${:name} -parent_id [$id set parent_id]] } - #:log "--LINK no page found [:name], [:lang], type=[:type]." + #:log "--LINK no page found ${:name}, ${:lang}, type=${:type}." return 0 } ::xowiki::Link::glossary instproc render_found {href label} { @@ -580,8 +641,8 @@ ::xo::Page requireJS "/resources/xowiki/overlib/overlib.js" if {![info exists :cssid]} {:cssid [::xowiki::Includelet html_id [self]]} template::add_event_listener \ - -id [:cssid] \ - -script [subst {showInfo('[ns_quotehtml $href?master=0]','[ns_quotehtml $label]')}] + -id ${:cssid} \ + -script [subst {showInfo('[ns_quotehtml $href?master=0]','$label')}] return "$label" } @@ -592,18 +653,18 @@ # Class create LinkCache # LinkCache proc flush {parent_id {item_id ""}} { # if {$item_id eq ""} { - # :xo::clusterwide xo::cache_flush_all xowiki_cache link-*-$name-$parent_id + # :acs::clusterwide acs::cache_flush_pattern xowiki_cache link-*-$name-$parent_id # } else { # foreach entry [ns_cache names xowiki_cache link-*-$parent_id] { # array set tmp [ns_cache get xowiki_cache $entry] # if {$tmp(item_id) == $item_id} { - # ::xo::clusterwide ns_cache flush xowiki_cache $entry + # ::acs::clusterwide ns_cache flush xowiki_cache $entry # } # } # } # } # LinkCache instproc resolve {} { - # set key link-[:type]-[:name]-${:parent_id} + # set key link-${:type}-${:name}-${:parent_id} # while {1} { # array set r [ns_cache eval xowiki_cache $key { # set id [next] @@ -620,7 +681,7 @@ # Link instmixin add LinkCache } -::xo::library source_dependent +::xo::library source_dependent # # Local variables: