xowiki::Package instproc pretty_link (public)
<instance of xowiki::Package> pretty_link [ -anchor anchor ] \ [ -query query ] [ -absolute on|off ] [ -siteurl siteurl ] \ [ -lang lang ] [ -parent_id parent_id ] [ -download on|off ] \ [ -context_url context_url ] [ -folder_ids folder_ids ] \ [ -path_encode on|off ] [ -page page ] name
Defined in /var/www/openacs.org/packages/xowiki/tcl/package-procs.tcl
Generate a (minimal) link to a wiki page with the specified name. Practically all links in the xowiki systems are generated through this method. The method returns the URL path urlencoded, unless "-path_encode" is set to false.
- Switches:
- -anchor (optional)
- anchor to be added to the link
- -query (optional)
- query parameters to be added literally to the resulting URL
- -absolute (optional, boolean, defaults to
"false"
)- make an absolute link (including protocol and host)
- -siteurl (optional)
- -lang (optional)
- use the specified 2 character language code (rather than computing the value)
- -parent_id (optional)
- parent_id
- -download (optional, boolean, defaults to
"false"
)- create download link (without m=download)
- -context_url (optional)
- -folder_ids (optional)
- -path_encode (optional, boolean, defaults to
"true"
)- control URL encoding of the path segmemts
- -page (optional)
- Parameters:
- name (required)
- name of the wiki page
- Testcases:
- link_tests
Source code: #:log "input name=$name, lang=$lang parent_id=$parent_id" set host [expr {$absolute ? ($siteurl ne "" ? $siteurl : [ad_url]) : ""}] if {$anchor ne ""} {set anchor \#$anchor} if {$query ne ""} {set query ?$query} :get_lang_and_name -default_lang $lang -name $name lang name set package_prefix [:get_parameter -check_query_parameter false package_prefix ${:package_url}] if {$package_prefix eq "/" && [string length $lang]>2} { # # Don't compact the path for images etc. to avoid conflicts # with e.g. //../image/* # set package_prefix ${:package_url} } #:msg "name=$name, parent_id=$parent_id, package_prefix=$package_prefix" if {$path_encode} { set encoded_name [ad_urlencode_path $name] } else { set encoded_name $name } if {$parent_id eq -100} { # In case, we have a CR top-level entry, we assume, we can # resolve it at least against the root folder of the current # package. set folder_path "" set encoded_name "" set default_lang [:default_language] } else { if {$parent_id in {"" 0}} { ad_log warning "pretty_link of $name: you should consider to pass a parent_id to support folders" set parent_id ${:folder_id} } set folder_path [:folder_path -parent_id $parent_id -folder_ids $folder_ids -path_encode $path_encode] set pkg [::$parent_id package_id] if {![nsf::is object ::$pkg]} { ::xowiki::Package require $pkg } set package_prefix [::$pkg get_parameter package_prefix [$pkg package_url]] set default_lang [::$pkg default_language] } #:msg "folder_path = $folder_path, -parent_id $parent_id -folder_ids $folder_ids // default_lang [:default_language]" #:log "h=${host}, prefix=${package_prefix}, folder=$folder_path, name=$encoded_name anchor=$anchor download=$download" # # Lookup plain page name. If we succeed, there is a danger of a # name clash between a folder and a language prefixed page. In # case, the lookup succeeds, add a language prefix to the page, # although it could be omitted otherwise. This way, we can # disambiguate between a folder named "foo" and a page named # "en:foo" in the same folder. # # Note: such a naming disambiguation is probably needed in the # general case as well on path segments, when arbitrary objects # can have children and same-named folders exist. # set found_id [:lookup -parent_id $parent_id -name $name] #:log "lookup [list :lookup -parent_id $parent_id -name $name] -> $found_id" # # In case, we did not receive a "page" but we could look up the # entry, instantiate the target page to be able to distinguish # between folder and page in ambiguous cases. # if {$found_id != 0 && $page eq ""} { #ad_log warning "have to fetch target page. You should provide '-page' to pretty_link" set page [::xo::db::CrClass get_instance_from_db -item_id $found_id] } if {$found_id != 0 && $page ne ""} { # # Do never add a language prefix for certain pages # if {[$page is_unprefixed]} { #:log "... $page is unprefixed" set found_id 0 } } #:log "found_id=$found_id name=$name,folder_path=$folder_path,lang=$lang,default_lang=$default_lang" #:log "host <${host}> package_prefix <${package_prefix}>" if {$download} { # # Use the special download (file) syntax. # set url ${host}${package_prefix}download/file/$folder_path$encoded_name$query$anchor } elseif {$lang ne $default_lang || [[self class] exists www-file($name)]} { # # If files are physical files in the www directory, add the # language prefix # set url ${host}${package_prefix}${lang}/$folder_path$encoded_name$query$anchor } elseif {$found_id != 0} { set url ${host}${package_prefix}$folder_path${lang}:$encoded_name$query$anchor } else { # # Use the short notation without language prefix. # set url ${host}${package_prefix}$folder_path$encoded_name$query$anchor } #:msg "final url=$url" return $urlXQL Not present: Generic, PostgreSQL, Oracle