xowiki::Page instproc create_link (public)
<instance of xowiki::Page> create_link arg
Defined in /var/www/openacs/packages/xowiki/tcl/xowiki-procs.tcl
Resolve a wiki link specification and create its link object. Some local assets are registered directly as page resources.
- Parameters:
- arg (required)
- Link target, optionally followed by a label and options separated by bars.
- Returns:
- The link object, or empty when no link object is needed.
- Testcases:
- path_resolve, nested_self_references
Source code: #:msg [self args] set label $arg set link $arg set options "" regexp {^([^|]+)[|](.*)$} $arg _ link label regexp {^([^|]*)[|](.*)$} $label _ label options set options [:unescape $options] set link [string trim $link] # Get the package_id from the provided path, and - if found - # return the shortened link relative to it. set package_id [::${:package_id} resolve_package_path $link link] if {$package_id == 0} { # we treat all such links like external links if {[regsub {^//} $link / link]} { # # For local links (starting with //), we provide # a direct treatment. JavaScript and CSS files are # included, images are rendered directly. # switch -glob -- [::xowiki::guesstype $link] { text/css { ::xo::Page requireCSS $link return "" } application/x-javascript - application/javascript { ::xo::Page requireJS $link return "" } image/* { Link create [self]::link -page [self] -name "" -type localimage -label $label -href $link [self]::link configure {*}$options return [self]::link } } } set l [ExternalLink new -label $label -href $link] $l configure {*}$options return $l } # # TODO missing: typed links # ## do we have a typed link? prefix has more than two chars... # if {[regexp {^([^:/?][^:/?][^:/?]+):((..):)?(.+)$} $link _ # link_type _ lang stripped_name]} { # set name file:$stripped_name # } set link_info [:get_anchor_and_query $link] set parent_id [expr {$package_id == ${:package_id} ? ${:parent_id} : [::$package_id folder_id]}] # we might consider make this configurable set use_package_path true set is_self_link false if {[regexp {^:(..):(.+)$} [dict get $link_info link] _ lang stripped_name]} { # # a language link (it starts with a ':') # set item_ref_info [::$package_id item_ref -use_package_path $use_package_path -default_lang [:lang] -parent_id $parent_id ${lang}:$stripped_name] dict set item_ref_info link_type language } elseif {[regexp {^[.]SELF[.]/(.*)$} [dict get $link_info link] _ link]} { # # Remove ".SELF./" from the path and search for the named # resource (e.g. the image name) under the current (physical) # item. # set self_link_ids [:self_link_ids] set parent_id [dict get $self_link_ids parent_id] set package_id [dict get $self_link_ids package_id] #ns_log notice "SELF-LINK '[dict get $link_info link]' in TEXT resolve with parent $parent_id" set is_self_link true set item_ref_info [::$package_id item_ref -use_package_path $use_package_path -default_lang [:lang] -parent_id $parent_id $link] dict set link_info link $link #:log "SELF-LINK returns $item_ref_info" } else { # # A plain link, search relative to the parent. # #ns_log notice "PLAIN-LINK '[dict get $link_info link]' in TEXT resolve with parent $parent_id" set item_ref_info [::$package_id item_ref -use_package_path $use_package_path -default_lang [:lang] -parent_id $parent_id [dict get $link_info link]] } #ns_log notice "link_info $link_info" #ns_log notice "--L link <$arg> lang [:lang] CURRENT ${:name} nls_lang ${:nls_language} -> item_ref_info $item_ref_info" #:log "link '[dict get $link_info link]' package_id $package_id ${:package_id} => [array get {}]" if {$label eq $arg} { set label [dict get $link_info link] } set item_name [string trimleft [dict get $item_ref_info prefix]:[dict get $item_ref_info stripped_name] :] Link create [self]::link -page [self] -form [dict get $item_ref_info form] -type [dict get $item_ref_info link_type] -name $item_name -lang [dict get $item_ref_info prefix] -anchor [dict get $link_info anchor] -query [dict get $link_info query] -stripped_name [dict get $item_ref_info stripped_name] -label $label -parent_id [dict get $item_ref_info parent_id] -item_id [dict get $item_ref_info item_id] -package_id $package_id -is_self_link $is_self_link # in case, we can't link, flush the href if {[:can_link [dict get $item_ref_info item_id]] == 0} { :references refused [dict get $item_ref_info item_id] if {[[self]::link exists href]} { [self]::link unset href } } [self]::link configure {*}$options set result [[self]::link] return $resultXQL Not present: Generic, PostgreSQL, Oracle
![[i]](/resources/acs-subsite/ZoomIn16.gif)