Class ::xowiki::Package

::xowiki::Package[i] create ... \
           [ -folder_id (default "0") ] \
           [ -force_refresh_login (default "false") ]

Class Relations

  • class: ::xo::PackageMgr[i]
  • superclass: ::xo::Package[i]
  • instmixin: ::xowiki::ParameterCache[i]
  • subclass: ::xolirc::Package[i], ::s5::Package[i], ::xowf::Package[i]
::xo::PackageMgr create ::xowiki::Package \
     -superclass ::xo::Package \
     -instmixin ::xowiki::ParameterCache

Methods (to be applied on the object)

  • get_package_id_from_page_id (scripted, public)

     xowiki::Package[i] get_package_id_from_page_id \
        [ -revision_id revision_id ] [ -item_id item_id ]

    Obtain the package_id from either the item_id or the revision_id of a page

    Switches:
    -revision_id
    (defaults to "0") (optional)
    -item_id
    (defaults to "0") (optional)

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_create_workflow_with_instance create_workflow_with_instance (test xowf) xowiki::Package proc get_package_id_from_page_id xowiki::Package proc get_package_id_from_page_id test_create_workflow_with_instance->xowiki::Package proc get_package_id_from_page_id

    Testcases:
    create_workflow_with_instance
    if {$revision_id} {
      set object_id $revision_id
    } elseif {$item_id} {
      set object_id $item_id
    } else {
      error "Either item_id or revision_id must be provided"
    }
    return [::xo::dc get_value get_pid {select package_id from acs_objects where object_id = :object_id}]
  • get_url_from_id (scripted, public)

     xowiki::Package[i] get_url_from_id [ -item_id item_id ] \
        [ -revision_id revision_id ]

    Get the full URL from a page in situations, where the context is not set up.

    Switches:
    -item_id
    (defaults to "0") (optional)
    -revision_id
    (defaults to "0") (optional)
    See Also:
    • instantiate_page_from_id

    Partial Call Graph (max 5 caller/called nodes):
    %3

    Testcases:
    No testcase defined.
    set page [::xowiki::Package instantiate_page_from_id  -item_id $item_id -revision_id $revision_id]
    return [::[$page package_id] url]
  • google_sitemapindex (scripted, public)

     xowiki::Package[i] google_sitemapindex [ -changefreq changefreq ] \
        [ -priority priority ] [ -package package ]

    This method provides a sitemap index of all xowiki instances in google site map format https://www.google.com/webmasters/sitemaps/docs/en/protocol.html

    Switches:
    -changefreq
    (defaults to "daily") (optional)
    changefreq as defined by google
    -priority
    (defaults to "priority") (optional)
    priority as defined by google
    -package
    (optional)
    to determine the delivery instance

    Partial Call Graph (max 5 caller/called nodes):
    %3 ad_script_abort ad_script_abort (public) ad_url ad_url (public) parameter::get parameter::get (public) site_node::get_from_object_id site_node::get_from_object_id (public) xo::db::tcl_date xo::db::tcl_date (public) xowiki::Package proc google_sitemapindex xowiki::Package proc google_sitemapindex xowiki::Package proc google_sitemapindex->ad_script_abort xowiki::Package proc google_sitemapindex->ad_url xowiki::Package proc google_sitemapindex->parameter::get xowiki::Package proc google_sitemapindex->site_node::get_from_object_id xowiki::Package proc google_sitemapindex->xo::db::tcl_date

    Testcases:
    No testcase defined.
    set content {<?xml version="1.0" encoding="UTF-8"?>
      <sitemapindex xmlns="http://www.google.com/schemas/sitemap/0.84">
    }
    foreach package_id [::xowiki::Package instances] {
      if {![parameter::get -package_id $package_id  -parameter include_in_google_sitemap_index  -default 1]} {
        continue
      }
      set last_modified [::xo::dc get_value get_newest_modification_date  {select max(last_modified)
                               from acs_objects
                               where package_id = :package_id
                             }]
    
      set time [::xo::db::tcl_date $last_modified tz]
      set time "[clock format [clock scan $time] -format {%Y-%m-%dT%T}]${tz}:00"
    
      #:log "--site_node::get_from_object_id -object_id $package_id"
      array set info [site_node::get_from_object_id -object_id $package_id]
    
      append content <sitemap> \n <loc>[ad_url]$info(url)sitemap.xml</loc> \n <lastmod>$time</lastmod> \n </sitemap>
    }
    append content </sitemapindex> \n
    if {[info exists package]} {
      #
      # Since we are running here in a proc, and we were called via
      # "reply_to_user", we have to provide the proper mime_type to the
      # calling package instance for delivery
      #
      $package set mime_type text/xml
      return $content
    } else {
      #
      # In case, someone called us differently
      #
      ns_return 200 text/xml $content
      ad_script_abort
    }
  • instantiate_page_from_id (scripted, public)

     xowiki::Package[i] instantiate_page_from_id [ -revision_id revision_id ] \
        [ -item_id item_id ] [ -user_id user_id ] [ -parameter parameter ]

    Instantiate a page in situations, where the connection context is not set up (e.g. we have no package object). This call is convenient when testing e.g. from the developer shell.

    Switches:
    -revision_id
    (defaults to "0") (optional)
    -item_id
    (defaults to "0") (optional)
    -user_id
    (defaults to "-1") (optional)
    -parameter
    (optional)

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_create_workflow_with_instance create_workflow_with_instance (test xowf) xowiki::Package proc instantiate_page_from_id xowiki::Package proc instantiate_page_from_id test_create_workflow_with_instance->xowiki::Package proc instantiate_page_from_id

    Testcases:
    create_workflow_with_instance
    set package_id [:get_package_id_from_page_id  -item_id $item_id  -revision_id $revision_id]
    ::xo::Package initialize  -export_vars false  -package_id $package_id  -init_url false -actual_query ""  -parameter $parameter  -user_id $user_id
    set page [::xo::db::CrClass get_instance_from_db -item_id $item_id -revision_id $revision_id]
    ::$package_id set_url -url [$page pretty_link]
    return $page
  • is_xowiki_p (scripted, public)

     xowiki::Package[i] is_xowiki_p package_id

    A small stunt to detect if a package is a descendant of xowiki.

    Parameters:
    package_id
    Returns:
    boolean

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_parameter__check_procs parameter__check_procs (test acs-tcl) xowiki::Package proc is_xowiki_p xowiki::Package proc is_xowiki_p test_parameter__check_procs->xowiki::Package proc is_xowiki_p apm_package_key_from_id apm_package_key_from_id (public) xowiki::Package proc is_xowiki_p->apm_package_key_from_id

    Testcases:
    parameter__check_procs
    set xowiki_p false
    set package_key [apm_package_key_from_id $package_id]
    set package_class [::xo::PackageMgr get_package_class_from_package_key $package_key]
    if {$package_class ne ""} {
      # we found an xo::Package, but is it an xowiki package?
      set classes [list $package_class {*}[$package_class info heritage]]
      if {"::xowiki::Package" in $classes} {
        set xowiki_p true
      }
    }
    return $xowiki_p

Methods (to be applied on instances)

  • external_name (scripted, public)

     <instance of xowiki::Package[i]> external_name \
        [ -parent_id parent_id ] name

    Generate a name with a potentially inserted parent name

    Switches:
    -parent_id
    (optional)
    parent_id (for now just for download)
    Parameters:
    name - name of the wiki page

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_xowiki_test_cases xowiki_test_cases (test xowiki) xowiki::Package instproc external_name xowiki::Package instproc external_name test_xowiki_test_cases->xowiki::Package instproc external_name

    Testcases:
    xowiki_test_cases
    set folder [:folder_path -parent_id $parent_id]
    if {$folder ne ""} {
      # Return the stripped name for sub-items, the parent has already
      # the language prefix
      # :get_lang_and_name -name $name lang stripped_name
      return $folder$name
    }
    return $name
  • folder_path (scripted, public)

     <instance of xowiki::Package[i]> folder_path \
        [ -parent_id parent_id ] [ -context_url context_url ] \
        [ -folder_ids folder_ids ] [ -path_encode on|off ]

    Construct a folder path from a hierarchy of xowiki objects. It is designed to work with linked objects, respecting logical and physical parent IDs. The result is URL encoded, unless path_encode is set to false.

    Switches:
    -parent_id
    (optional)
    -context_url
    (optional)
    -folder_ids
    (optional)
    -path_encode
    (boolean) (defaults to "true") (optional)

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_link_tests link_tests (test xowiki) xowiki::Package instproc folder_path xowiki::Package instproc folder_path test_link_tests->xowiki::Package instproc folder_path ad_urlencode_path ad_urlencode_path (public) xowiki::Package instproc folder_path->ad_urlencode_path

    Testcases:
    link_tests
    #
    # Handle different parent_ids
    #
    if {$parent_id eq "" || $parent_id == ${:folder_id}} {
      return ""
    }
    #
    # The item might be in a folder along the folder path.  So it
    # will be found by the object resolver. For the time being, we
    # do nothing more about this.
    #
    #
    if { $context_url ne {} } {
      set parts [split $context_url /]
      set index [expr {[llength $parts]-1}]
    }
    
    if { $context_url ne {} } {
      set context_id [:get_parent_and_name -path $context_url -lang "" -parent_id $parent_id parent local_name]
      #:msg "context_url $context_url folder_ids $folder_ids context_id $context_id"
    }
    
    set path ""
    set ids {}
    while {1} {
      lappend ids $parent_id
      set fo [::xo::db::CrClass get_instance_from_db -item_id $parent_id]
      if { $context_url ne {} } {
        set context_name [lindex $parts $index]
        if {1 && $parent_id in $folder_ids} {
          #:msg "---- parent $parent_id in $folder_ids"
          set context_id [::$context_id item_id]
          set fo [::xo::db::CrClass get_instance_from_db -item_id $context_id]
        } else {
          #:msg "context_url $context_url, parts $parts, context_name $context_name // parts $parts // index $index / folder $fo"
    
          if { [$fo name] ne $context_name } {
            set context_folder [:get_page_from_name -parent_id $parent_id -assume_folder true -name $context_name]
            if {$context_folder eq ""} {
              :msg "my get_page_from_name -parent_id $parent_id -assume_folder true -name $context_name ==> EMPTY"
              :msg "Cannot lookup '$context_name' in package folder $parent_id [::$parent_id name]"
    
              set new_path [join [lrange $parts 0 $index] /]
              set p2 [:get_parent_and_name -path [join [lrange $parts 0 $index] /] -lang "" -parent_id $parent_id parent local_name]
              :msg "p2=$p2 new_path=$new_path '$local_name' ex=[nsf::object::exists $p2] [$p2 name]"
    
            }
            :msg "context_name [$context_folder serialize]"
            set context_id [$context_folder item_id]
            set fo [::xo::db::CrClass get_instance_from_db -item_id $context_id]
          }
          incr index -1
        }
      }
    
      #:get_lang_and_name -name [$fo name] lang stripped_name
      #set path $stripped_name/$path
    
      if {[$fo parent_id] < 0} break
    
      if {[$fo is_link_page]} {
        set pid [$fo package_id]
        foreach id $ids {
          if {[::$id package_id] ne $pid} {
            #:msg "SYMLINK ++++ have to fix package_id of $id from [::$id package_id] to $pid"
            $id set_resolve_context -package_id $pid -parent_id [::$id parent_id]
          }
        }
        if {0} {
          #
          # In some older versions, this code was necessary. Keep it
          # here as a reference, in case not all relevant cases were
          # covered by the tests
          #
          set target [$fo get_target_from_link_page]
          set target_name [$target name]
          #:msg "----- $path //  target $target [$target name] package_id [$target package_id] path '$path'"
          set orig_path $path
          regsub "^$target_name/" $path "" path
          if {$orig_path ne $path} {
            :msg "----> orig <$orig_path> new <$path> => full [$fo name]/$path"
          }
        }
      }
    
      set name [$fo name]
      if {$path_encode} {
        set name [ad_urlencode_path $name]
      }
      # prepend always the actual folder name
      set path $name/$path
    
      if {${:folder_id} == [$fo parent_id]} {
        #:msg ".... :folder_id ${:folder_id} == $fo parentid"
        break
      }
    
      set parent_id [$fo parent_id]
    }
    
    #:msg ====$path
    return $path
  • get_ids_for_bulk_actions (scripted, public)

     <instance of xowiki::Package[i]> get_ids_for_bulk_actions \
        [ -parent_id parent_id ] page_references

    The page_reference is either an item_id, a fully qualified URL path or the name exactly as stored in the content repository ("name" attribute in the database, requires parent_id to be provided as well)

    Switches:
    -parent_id
    (optional)
    optional, only needed in legacy cases, when page_reference is provided as page name
    Parameters:
    page_references - item_ids, paths or names to be resolved as item_ids
    Returns:
    list of valid item_ids

    Partial Call Graph (max 5 caller/called nodes):
    %3

    Testcases:
    No testcase defined.
    set item_ids {}
    foreach page_ref $page_references {
      set item_id 0
      #
      # First check whether we got a valid item_id, then check for a
      # URL path. If both are failing, resort to the legacy methods
      # (which will be dropped eventually).
      #
      if {[string is integer -strict $page_ref]} {
        ::xo::dc 0or1row -prepare integer check_ref {
          select item_id from cr_items where item_id = :page_ref
        }
      } elseif {[string index $page_ref 0] eq "/"} {
        #
        # $page_ref looks like a URL path
        #
        set ref [:item_info_from_url $page_ref]
        set item_id [dict get $ref item_id]
        ns_log notice "get_ids_for_bulk_actions: URL '$page_ref' item_ref <$ref> -> $item_id"
      } else {
        #
        # Try $page_ref as item_ref
        #
        if {![info exists parent_id]} {
          set parent_ids [list ""]
        } else {
          set parent_ids $parent_id
        }
        foreach p_id $parent_ids {
          set p [:get_page_from_item_ref -parent_id $p_id $page_ref]
          if {$p ne ""} {
            set item_id [$p item_id]
            break
          }
        }
        ns_log notice "get_ids_for_bulk_actions: tried to resolve item_ref <$page_ref> -> $item_id"
      }
    
      if {$item_id == 0} {
        #
        # Try to resolve either via a passed in parent_id or via root folder
        #
        set parent_ids [expr {[info exists parent_id] ? $parent_id : ${:folder_id}}]
        foreach p_id $parent_ids {
          set item_id [::xo::db::CrClass lookup -name $page_ref -parent_id $p_id]
          if {$item_id != 0} {
            break
          }
        }
      }
    
      if {$item_id != 0} {
        #:log "add $page_ref // $item_id"
        lappend item_ids $item_id
      } else {
        ns_log warning "get_ids_for_bulk_actions: clipboard entry <$page_ref> could not be resolved"
      }
    }
    return $item_ids
  • get_parameter (scripted, public)

     <instance of xowiki::Package[i]> get_parameter \
        [ -check_query_parameter check_query_parameter ] [ -nocache ] \
        [ -type type ] attribute [ default ]

    Resolves configurable parameters according to the following precedence: (1) values specifically set per page {{set-parameter ...}} (2) query parameter (3) form fields from the parameter_page FormPage (4) standard OpenACS package parameter The specified attribute can be of the form "name:value_constraint"

    Switches:
    -check_query_parameter
    (defaults to "true") (optional)
    -nocache
    (optional)
    -type
    (optional)
    Parameters:
    attribute
    default (optional)

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_create_form_with_form_instance create_form_with_form_instance (test xowiki) xowiki::Package instproc get_parameter xowiki::Package instproc get_parameter test_create_form_with_form_instance->xowiki::Package instproc get_parameter ad_return_complaint ad_return_complaint (public) xowiki::Package instproc get_parameter->ad_return_complaint xo::validate_parameter_constraints xo::validate_parameter_constraints (public) xowiki::Package instproc get_parameter->xo::validate_parameter_constraints

    Testcases:
    create_form_with_form_instance
    set attribute_name $attribute
    set attribute_constraint ""
    regexp {^([^:]+):(.*)$} $attribute . attribute_name attribute_constraint
    
    if {$nocache} {
      set value ""
    } else {
      #
      # Cached values, or values programmatically set
      #
      set value [::xo::cc get_parameter $attribute_name]
    }
    
    if {$check_query_parameter && $value eq ""} {
      #
      # Query parameter handle already the notation with
      # "name:valueconstraint"
      #
      set value [string trim [:query_parameter $attribute]]
    }
    if {$value eq "" && $attribute_name ne "parameter_page"} {
      #
      # Try to get the parameter from the parameter_page.  We have to
      # be very cautious here to avoid recursive calls (e.g. when
      # resolve_page_name needs as well parameters such as
      # use_connection_locale or subst_blank_in_name, etc.).
      #
      set value [:get_parameter_from_parameter_page  -parameter_page_name [:get_parameter parameter_page:graph ""]  $attribute_name]
    }
    
    if {$value eq ""} {
      set value [next $attribute_name $default]
    }
    if {$type ne ""} {
      #
      # To be extended and generalized.
      #
      switch -- $type {
        word {if {[regexp {\W} $value]} {
          ad_return_complaint 1 "value for parameter '$attribute' contains invalid character"}
        }
        noquote {if {[regexp {['\"]} $value]} {
          ad_return_complaint 1 "value for parameter '$attribute' contains invalid character"}
        }
        default {error "requested type unknown: $type"}
      }
    }
    if {$value ne "" && $attribute_constraint ne ""} {
      xo::validate_parameter_constraints $attribute_name $attribute_constraint $value
    }
    #:log "           $attribute returns '$value'"
    return $value
  • get_parameter_from_parameter_page (scripted, public)

     <instance of xowiki::Package[i]> get_parameter_from_parameter_page \
        [ -parameter_page_name parameter_page_name ] parameter [ default ]

    Try to get the parameter from the named parameter_page.

    Switches:
    -parameter_page_name
    (optional)
    Parameters:
    parameter
    default (optional)
    Returns:
    parameter value or empty

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_xowiki_test_cases xowiki_test_cases (test xowiki) xowiki::Package instproc get_parameter_from_parameter_page xowiki::Package instproc get_parameter_from_parameter_page test_xowiki_test_cases->xowiki::Package instproc get_parameter_from_parameter_page ad_log ad_log (public) xowiki::Package instproc get_parameter_from_parameter_page->ad_log nsf::is nsf::is xowiki::Package instproc get_parameter_from_parameter_page->nsf::is

    Testcases:
    xowiki_test_cases
    set value $default
    if {$parameter_page_name ne ""} {
      if {![regexp {/?..:} $parameter_page_name]} {
        ad_log error "Name of parameter page '$parameter_page_name'"  "of FormPage [self] must contain a language prefix"
      } else {
        set page [::xo::cc cache  [list ::${:id} get_page_from_item_ref $parameter_page_name]]
        if {$page eq ""} {
          ad_log error "Could not resolve parameter page '$parameter_page_name'"  "for package ${:id}."
        }
        #
        # The following block should not be necessary
        #
        if {![::nsf::is object $page]} {
          ad_log warning "We have to refetch parameter page"
          ::xo::db::CrClass get_instance_from_db -item_id [string trimleft $page :]
        }
    
        if {$page ne "" && [$page exists instance_attributes]} {
          set __ia [$page set instance_attributes]
          if {[dict exists $__ia $parameter]} {
            set value [dict get $__ia $parameter]
          }
        }
      }
    }
    return $value
  • import (scripted, public)

     <instance of xowiki::Package[i]> import [ -user_id user_id ] \
        [ -parent_id parent_id ] [ -replace replace ] [ -objects objects ] \
        [ -create_user_ids create_user_ids ]

    import the specified pages into the xowiki instance

    Switches:
    -user_id
    (optional)
    -parent_id
    (defaults to "0") (optional)
    -replace
    (defaults to "0") (optional)
    -objects
    (optional)
    -create_user_ids
    (defaults to "0") (optional)

    Partial Call Graph (max 5 caller/called nodes):
    %3

    Testcases:
    No testcase defined.
    if {$parent_id == 0} {set parent_id ${:folder_id}}
    if {![info exists user_id]} {set user_id [::xo::cc user_id]}
    if {![info exists objects]} {set objects [::xowiki::Page allinstances]}
    set msg "#xowiki.processing_objects#: $objects<p>"
    set importer [Importer new -package_id ${:id} -parent_id $parent_id -user_id $user_id]
    $importer import_all -replace $replace -objects $objects -create_user_ids $create_user_ids
    append msg [$importer report]
  • invoke (scripted)

     <instance of xowiki::Package[i]> invoke

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_create_folder_with_page create_folder_with_page (test ) xowiki::Package instproc invoke xowiki::Package instproc invoke test_create_folder_with_page->xowiki::Package instproc invoke test_create_form_with_form_instance create_form_with_form_instance (test xowiki) test_create_form_with_form_instance->xowiki::Package instproc invoke test_create_workflow_with_instance create_workflow_with_instance (test xowf) test_create_workflow_with_instance->xowiki::Package instproc invoke test_xowf xowf (test ) test_xowf->xowiki::Package instproc invoke ad_log ad_log (public) xowiki::Package instproc invoke->ad_log ad_return_complaint ad_return_complaint (public) xowiki::Package instproc invoke->ad_return_complaint ad_script_abort ad_script_abort (public) xowiki::Package instproc invoke->ad_script_abort ad_try ad_try (public) xowiki::Package instproc invoke->ad_try

    Testcases:
    create_folder_with_page, xowf, create_workflow_with_instance, create_form_with_form_instance
    #
    # Do we have a valid method?
    #
    if {![regexp {^[.a-zA-Z0-9_-]+$} $method]} {
      return [:error_msg "No valid method provided!"]
    }
    
    #
    # Call the method on the resolved page. This call might trigger an
    # ad_script_abort, so use ad_try to catch these properly.
    #
    ad_try {
      set page_or_package [:resolve_page -lang [:default_language] ${:object} method]
    } on error {errorMsg} {
      #
      # Report true errors in the error log and return the template.
      #
      ad_log error $errorMsg
      return [:error_msg -template_file $error_template [ns_quotehtml $errorMsg]]
    }
    
    #
    # Set the invoke object, such it might be used later
    #
    ::xo::cc invoke_object $page_or_package
    
    #:log "--r resolve_page '${:object}' => $page_or_package"
    if {$page_or_package ne ""} {
    
      # TODO: remove me when settled
      if {[$page_or_package istype ::xowiki::FormPage] && [$page_or_package info vars storage_type] eq ""} {ad_log notice "$page_or_package has no storage_type"}
    
      #
      # Check, of the target is a symbolic link
      #
      if {[$page_or_package istype ::xowiki::FormPage]
          && [$page_or_package is_link_page]
        } {
        #
        # If the target is a symbolic link, we may want to call the
        # method on the target. The default behavior is defined in the
        # array delegate_link_to_target, but if can be overruled with
        # the boolean query parameter "deref".
        #
        set deref [[self class] exists delegate_link_to_target($method)]
        if {[:exists_query_parameter deref]} {
          set deref [:query_parameter deref:boolean]
        }
    
        #:log "LINK <$method> default deref $deref"
        if {$deref} {
          set target [$page_or_package get_target_from_link_page]
          #:log "delegate $method from $page_or_package [$page_or_package name] to $target [$target name]"
          if {$target ne ""} {
            $target set __link_source $page_or_package
            set page_or_package $target
          }
        }
      }
    
      #:log "call procsearch www-$method on: [$page_or_package info precedence]"
      if {[$page_or_package procsearch www-$method] eq ""} {
        return [:error_msg "Method <b>'[ns_quotehtml $method]'</b> is not defined for this object"]
      } else {
    
        #:log "${:object} id=$page_or_package method=$method (${:id} batch_mode $batch_mode)"
    
        if {$batch_mode} {
          ${:id} set __batch_mode 1
        }
    
        ad_try {
          set r [:call $page_or_package $method ""]
        } on error {errorMsg} {
          if {[string match "*for parameter*" $errorMsg]} {
            #
            # The exception might have been due to invalid input parameters
            #
            ad_return_complaint 1 [ns_quotehtml $errorMsg]
            ad_script_abort
          } else {
            #
            # The exception was a real error
            #
            ad_log error "error during invocation of method $method errorMsg: $errorMsg$::errorInfo"
            return [:error_msg -status_code 500  -template_file $error_template  "error during [ns_quotehtml $method]: <pre>[ns_quotehtml $errorMsg]</pre>"]
          }
    
        } finally {
          if {$batch_mode} {
            ${:id} unset -nocomplain __batch_mode
          }
        }
    
        return $r
      }
    } else {
      #
      # The requested page was not found, provide an error message and
      # an optional link for creating the page. The creation link
      # depends on the method "create_new_snippet", which checks
      # whether the policy in place supports "edit-new" permissions
      # for the current user.
      #
      set path [::xowiki::Includelet html_encode ${:object}]
      set edit_snippet [:create_new_snippet $path]
      return [:error_msg -status_code 404 -template_file $error_template  "Page <b>'[ns_quotehtml $path]'</b> is not available. $edit_snippet"]
    }
  • item_info_from_url (scripted)

     <instance of xowiki::Package[i]> item_info_from_url

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_path_resolve path_resolve (test ) xowiki::Package instproc item_info_from_url xowiki::Package instproc item_info_from_url test_path_resolve->xowiki::Package instproc item_info_from_url test_xowiki xowiki (test ) test_xowiki->xowiki::Package instproc item_info_from_url

    Testcases:
    path_resolve, xowiki
    #
    # Obtain item info (item_id parent_id lang stripped_name) from the
    # specified url. Search starts always at the root.
    #
    # @param with_package_prefix flag, if provided URL contains package-url
    # @return item ref data (parent_id lang stripped_name method)
    #
    if {$with_package_prefix && [string match "/*" $url]} {
      set url [string range $url [string length [:package_url]] end]
    }
    if {$default_lang eq ""} {set default_lang [:default_language]}
    :get_lang_and_name -default_lang $default_lang -path $url (lang) stripped_url
    #:log "get_lang_and_name -default_lang $default_lang -path $url -> $(lang) '$stripped_url'"
    
    set (parent_id) [:get_parent_and_name  -lang $(lang) -path $stripped_url  -parent_id ${:folder_id}  parent local_name]
    #:log "get_parent_and_name '$stripped_url' returns [array get {}]"
    
    if {![regexp {^(download)/(.+)$} $(lang) _ (method) (lang)]} {
      set (method) ""
      # The lang value "tag" is used for allowing tag-URLs without
      # parameters, since several tag harvester assume such a syntax
      # and don't process arguments. We rewrite in such cases simply
      # the url and query parameters and update the connection
      # context.
      if {$(lang) eq "tag"} {
        # todo: missing: tag links to subdirectories, also on url generation
        set tag $stripped_url
        :validate_tag $tag
        set summary [string is true -strict [::xo::cc query_parameter summary:boolean 0]]
        set popular [string is true -strict [::xo::cc query_parameter popular:boolean 0]]
        set tag_kind [expr {$popular ? "ptag" :"tag"}]
        set weblog_page [:get_parameter -check_query_parameter false weblog_page:graph]
        :get_lang_and_name -default_lang $default_lang -name $weblog_page (lang) local_name
        set :object $weblog_page
        ::xo::cc set actual_query $tag_kind=$tag&summary=$summary
      }
    }
    array set "" [:prefixed_lookup -parent_id $(parent_id)  -default_lang $default_lang -lang $(lang)  -stripped_name $local_name]
    #:log "prefixed_lookup '$local_name' returns [array get {}]"
    
    if {$(item_id) == 0} {
      #
      # Check symlink (todo: should this happen in package->lookup?)
      #
      ::xo::db::CrClass get_instance_from_db -item_id $(parent_id)
      if {[$(parent_id) is_link_page]} {
        #
        #  We encompassed a link to a page or folder, treat both the same way.
        #
        #:log "item_info_from_url LINK page $(parent_id)"
    
        set link_id $(parent_id)
        set target [::$link_id get_target_from_link_page]
    
        $target set_resolve_context -package_id ${:id} -parent_id $link_id
        array set "" [list logical_package_id ${:id} logical_parent_id $link_id]
    
        #:log "SYMLINK PREFIXED $target ([$target name]) set_resolve_context -package_id ${:id} -parent_id $link_id"
    
        array set "" [[$target package_id] prefixed_lookup -parent_id [$target item_id]  -default_lang $default_lang -lang $(lang) -stripped_name $(stripped_name)]
        #
        # We can't reset the resolve context here, since it is also
        # required for rendering the target
        #
      }
    }
    #:log "final returns [array get {}]"
    
    return [array get ""]
  • item_ref (scripted, public)

     <instance of xowiki::Package[i]> item_ref \
        [ -use_package_path use_package_path ] \
        [ -use_site_wide_pages use_site_wide_pages ] \
        [ -normalize_name normalize_name ] -default_lang default_lang  \
        -parent_id parent_id  link

    An item_ref refers to an item (existing or non-existing) in the content repository relative to some parent_id. The item might be either a folder or some kind of "page" (e.g. a file). An item_ref might be complex, i.e. consist of a path of simple_item_refs, separated by "/". An item_ref stops at the first unknown part in the path and returns item_id == 0 and the appropriate parent_id (and name etc.) for insertion.

    Switches:
    -use_package_path
    (defaults to "false") (optional)
    -use_site_wide_pages
    (defaults to "false") (optional)
    -normalize_name
    (defaults to "true") (optional)
    -default_lang
    (required)
    -parent_id
    (required)
    Parameters:
    link
    Returns:
    item info containing link_type form prefix stripped_name item_id parent_id

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_path_resolve path_resolve (test xowiki) xowiki::Package instproc item_ref xowiki::Package instproc item_ref test_path_resolve->xowiki::Package instproc item_ref test_xowiki_test_cases xowiki_test_cases (test xowiki) test_xowiki_test_cases->xowiki::Package instproc item_ref

    Testcases:
    xowiki_test_cases, path_resolve
    # A trailing slash says that the last element is a folder. We
    # substitute it to allow easy iteration over the slash separated
    # segments.
    if {[string match "*/" $link]} {
      set llink [string trimright $link /]\0
    } else {
      set llink $link
    }
    
    set elements [split $llink /]
    # Get start-page, if path is empty
    if {[llength $elements] == 0} {
      set link [:get_parameter -check_query_parameter false index_page "index"]
      set elements [list $link]
    }
    
    #
    # Iterate bottom-up until the first unknown element appears in the
    # path (we can handle only one unknown at a time).
    #
    set nr_elements [llength $elements]
    set n 0
    set ref_ids {}
    foreach element $elements {
      set (last_parent_id) $parent_id
      lappend ref_ids $parent_id
      array set "" [:simple_item_ref  -normalize_name $normalize_name  -use_package_path $use_package_path  -use_site_wide_pages $use_site_wide_pages  -default_lang $default_lang  -parent_id $parent_id  -assume_folder [expr {[incr n] < $nr_elements}]  $element]
      #:msg "simple_item_ref <$element> => [array get {}]"
      if {$(item_id) == 0} {
        set parent_id $(parent_id)
        break
      } else {
        set parent_id $(item_id)
      }
    }
    
    return [list link $link link_type $(link_type) form $(form)  prefix $(prefix) stripped_name $(stripped_name)  item_id $(item_id) parent_id $(parent_id) ref_ids $ref_ids]
  • lookup (scripted, public)

     <instance of xowiki::Package[i]> lookup \
        [ -use_package_path use_package_path ] \
        [ -use_site_wide_pages use_site_wide_pages ] \
        [ -default_lang default_lang ] -name name  \
        [ -parent_id parent_id ]

    Lookup name (with maybe cross-package references) from a given parent_id or from the list of configured instances (obtained via package_path).

    Switches:
    -use_package_path
    (defaults to "true") (optional)
    -use_site_wide_pages
    (defaults to "false") (optional)
    -default_lang
    (optional)
    -name
    (required)
    -parent_id
    (optional)

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_path_resolve path_resolve (test xowiki) xowiki::Package instproc lookup xowiki::Package instproc lookup test_path_resolve->xowiki::Package instproc lookup

    Testcases:
    path_resolve
    #:log "LOOKUP of <$name> on-package: ${:id} parent_id '$parent_id'"
    set pkg_info [:get_package_id_from_page_name -default_lang $default_lang $name]
    
    if {[dict exists $pkg_info package_id]} {
      set package_id [dict get $pkg_info package_id]
    } else {
      return 0
    }
    
    if {$parent_id eq ""} {
      set parent_id [::$package_id folder_id]
    }
    set item_id [::xo::db::CrClass lookup  -name [dict get $pkg_info page_name]  -parent_id $parent_id]
    #:log "[dict get $pkg_info page_name] $parent_id in package $package_id returns $item_id, parent_id $parent_id"
    
    #
    # Test for "0" is only needed when we want to create the first
    # root folder.
    #
    if {$item_id == 0 && $parent_id != 0} {
      #
      # Page not found so far, get the parent page.
      #
      set p [::xo::db::CrClass get_instance_from_db -item_id $parent_id]
      #
      # Is the parent-page a regular page and a folder-link?
      # If so, de-reference the link.
      #
      if {[$p istype ::xowiki::FormPage] && [$p is_link_page] && [$p is_folder_page]} {
        set target [$p get_target_from_link_page]
        set target_package_id [$target package_id]
        set target_item_id    [$target item_id]
        #:log "SYMLINK LOOKUP from target-package $target_package_id source package $package_id name $name"
        #
        # Avoid potential recursive loop
        #
        if {${:id} != $target_package_id || $parent_id != $target_item_id} {
          set target_item_id [::$target_package_id lookup  -use_package_path $use_package_path  -use_site_wide_pages $use_site_wide_pages  -default_lang $default_lang  -name $name  -parent_id $target_item_id]
        } else {
          :log "SYMLINK LOOKUP avoid recursive loop name $name package_id ${:id} parent_id [$target item_id]"
          set target_item_id 0
        }
        if {$target_item_id != 0} {
          #:msg "SYMLINK FIX $target_item_id set_resolve_context -package_id ${:id} -parent_id $parent_id"
          ::xo::db::CrClass get_instance_from_db -item_id $target_item_id
          ::$target_item_id set_resolve_context -package_id ${:id} -parent_id $parent_id
        }
        return $target_item_id
      }
    }
    
    if {$item_id == 0 && $use_package_path} {
      #
      # Page not found so far. Is the page inherited along the package
      # path?
      #
      foreach package [:package_path] {
        set item_id [$package lookup -name $name]
        #:msg "lookup from package $package $name returns $item_id"
        if {$item_id != 0} break
      }
    }
    
    if {$item_id == 0 && $use_site_wide_pages} {
      #
      # Page not found so far. Is the page a site_wide page?
      #
      foreach pkgClass [${:id} info precedence] {
        if {[$pkgClass istype ::xo::PackageMgr] && [$pkgClass package_key] ne "apm_package"} {
          set item_id [$pkgClass lookup_side_wide_page -name $name]
          #ns_log notice "SITE_WIDE: [list $pkgClass lookup_side_wide_page -name $name] -> $item_id"
          if {$item_id ne 0} {
            break
          }
        }
      }
    }
    
    return $item_id
  • make_link (scripted, public)

     <instance of xowiki::Package[i]> make_link \
        [ -with_entities with_entities ] [ -privilege privilege ] \
        [ -link link ] object [ method ] args [ args... ]

    Creates conditionally a link for use in xowiki. When the generated link will be activated, the specified method of the object will be invoked. make_link checks in advance, whether the actual user has enough rights to invoke the method. If not, this method returns empty.

    Switches:
    -with_entities
    (defaults to "0") (optional)
    -privilege
    (optional)
    When provided, the privilege can be "public" (do not check rights) or a privilege to be checked on the package_id and the current user. When this parameter is not specified, the policy is used to determine the rights to be checked.
    -link
    (optional)
    When this parameter is specified, is used used as base link for export_vars when applied on pages (or for packages as next segment under the package url). When not specified, the base url for pages is the current url, and for packages it is the package url.
    Parameters:
    object - The object to which the link refers to. If it is a package_id it will base to the root_url of the package_id. If it is a page, it will base to the page_url
    method (optional) - Which method to use. This will be appended as "m=method" to the url. Examples for methods:
    • view: To view and existing page
    • edit: To edit an existing page
    • revisions: To view the revisions of an existing page

    args - List of attributes to be append to the link. Every element can be an attribute name, or a "name value" pair. Behaves like export_vars.
    Returns:
    The link or empty
    See Also:

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_xowiki_test_cases xowiki_test_cases (test xowiki) xowiki::Package instproc make_link xowiki::Package instproc make_link test_xowiki_test_cases->xowiki::Package instproc make_link ad_try ad_try (public) xowiki::Package instproc make_link->ad_try

    Testcases:
    xowiki_test_cases
    
    set computed_link ""
    
    if {[$object istype ::xowiki::Package]} {
      set base ${:package_url}
      if {$method ne ""} {
        #
        # Convention for calling methods on the package.
        #
        lappend args [list $method 1]
      }
      if {[info exists link]} {
        set computed_link [uplevel export_vars -base [list $base$link] [list $args]]
      } else {
        set computed_link [uplevel export_vars -base [list $base] [list $args]]
      }
    } elseif {[$object istype ::xowiki::Page]} {
      if {[info exists link]} {
        set base $link
      } else {
        #
        # Use the provided object for computing the base URL.
        #
        set base [$object pretty_link]
        #
        # Before, we had
        #
        #    set base ${:url}
        #
        # which depends on the invocation context.
        #
      }
      if {$method ne ""} {
        #
        # Convention for calling methods on an xowiki::Page
        #
        lappend args [list m $method]
      }
      #set computed_link [uplevel export_vars -base [list $base] -no_base_encode [list $args]]
      set computed_link [uplevel [list export_vars -base $base -no_base_encode $args]]
      #:msg "computed_link = '$computed_link'"
    }
    if {$with_entities} {
      regsub -all & $computed_link "&amp;" computed_link
    }
    
    # provide links based in untrusted_user_id
    set party_id [::xo::cc set untrusted_user_id]
    if {[info exists privilege]} {
      #:log "-- checking priv $privilege for [self args] from id ${:id}"
      set granted [expr {$privilege eq "public" ? 1 :
                         [::xo::cc permission -object_id ${:id} -privilege $privilege -party_id $party_id] }]
    } else {
      # determine privilege from policy
      #:msg "-- check permissions from ${:id} of object $object $method"
      ad_try {
        set granted [:check_permissions  -user_id $party_id  -package_id ${:id}  -link $computed_link $object $method]
      } on error {errorMsg} {
        ns_log error "error in check_permissions: $errorMsg"
        set granted 0
      }
      #:msg "--p ${:id} check_permissions $object $method ==> $granted"
    }
    #:log "granted=$granted $computed_link"
    if {$granted} {
      return $computed_link
    }
    return ""
  • normalize_path (scripted)

     <instance of xowiki::Package[i]> normalize_path

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_package_normalize_path package_normalize_path (test ) xowiki::Package instproc normalize_path xowiki::Package instproc normalize_path test_package_normalize_path->xowiki::Package instproc normalize_path test_xowiki xowiki (test ) test_xowiki->xowiki::Package instproc normalize_path

    Testcases:
    package_normalize_path, xowiki
    #
    # Don't allow any addressing outside of the jail.
    #
    # ns_normalizepath always adds a leading "/", so remove this.
    #
    set nn [ns_normalizepath $name]
    return [string range $nn 1 end]
  • pretty_link (scripted, public)

     <instance of xowiki::Package[i]> 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

    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
    (boolean) (defaults to "false") (optional)
    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
    (boolean) (defaults to "false") (optional)
    create download link (without m=download)
    -context_url
    (optional)
    -folder_ids
    (optional)
    -path_encode
    (boolean) (defaults to "true") (optional)
    control URL encoding of the path segmemts
    -page
    (optional)
    Parameters:
    name - name of the wiki page

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_link_tests link_tests (test xowiki) xowiki::Package instproc pretty_link xowiki::Package instproc pretty_link test_link_tests->xowiki::Package instproc pretty_link ad_log ad_log (public) xowiki::Package instproc pretty_link->ad_log ad_url ad_url (public) xowiki::Package instproc pretty_link->ad_url ad_urlencode_path ad_urlencode_path (public) xowiki::Package instproc pretty_link->ad_urlencode_path

    Testcases:
    link_tests
    #: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 $url
  • reparent (scripted, public)

     <instance of xowiki::Package[i]> reparent [ -item_id item_id ] \
        [ -new_parent_id new_parent_id ] \
        [ -allowed_parent_types allowed_parent_types ]

    Reparent a wiki page from one parent page to another one. The function changes the parent_id in cr_items, updates the cr-child-rels, and clears the caches. The function does not require the item to be instantiated. Limitations: The method does not perform permission checks (whether the actual user has rights to move the page to another parent folder), which should be implemented by the calling methods. Currently, the method does not perform cycle checks. It might be recommended to make sure the target parent is in the same package instance.

    Switches:
    -item_id
    (optional)
    item_id of the item to be moved
    -new_parent_id
    (optional)
    item_id of the target parent
    -allowed_parent_types
    (defaults to "::xowiki::FormPage ::xowiki::Page") (optional)

    Partial Call Graph (max 5 caller/called nodes):
    %3 xowiki::update_item_index xowiki::update_item_index (public) xowiki::Package instproc reparent xowiki::Package instproc reparent xowiki::Package instproc reparent->xowiki::update_item_index

    Testcases:
    No testcase defined.
    set parent_id [::xo::db::CrClass get_parent_id -item_id $item_id]
    set name      [::xo::db::CrClass get_name      -item_id $item_id]
    if {$new_parent_id == $parent_id} {
      # nothing to do
      return
    }
    
    set object_type [::xo::db::CrClass get_object_type -item_id $item_id]
    set parent_object_type [::xo::db::CrClass get_object_type -item_id $new_parent_id]
    if {$parent_object_type ni $allowed_parent_types} {
      error "parent_object_type $parent_object_type not in allowed types"
    }
    set relation_tag $parent_object_type-$object_type
    ::xo::dc transaction {
      ::xo::dc dml update_cr_items {
        update cr_items set parent_id = :new_parent_id where item_id = :item_id
      }
      ::xowiki::update_item_index -item_id $item_id -parent_id $new_parent_id
    
      ::xo::dc dml update_cr_child_rels {
        update cr_child_rels set parent_id = :new_parent_id, relation_tag = :relation_tag
        where child_id = :item_id
      }
      ::xo::dc dml update_rels_object {
        update acs_objects
        set context_id = :new_parent_id,
        title = :relation_tag || ': ' || :new_parent_id || ' - '  || :item_id
        where object_id = (select rel_id from cr_child_rels
                           where child_id = :item_id)
      }
    }
    #
    # clear caches
    #
    :flush_references -item_id $item_id -name $name -parent_id $parent_id
    :flush_page_fragment_cache -scope agg
    
    ::xo::xotcl_object_cache flush $item_id
    
    #
    # Clear potentially cached revisions. The function could be
    # optimized in the future by an index of the cached revision_ids
    # for an item_id
    #
    foreach revision_id [::xo::dc list get_revisions {
      select revision_id from cr_revisions where item_id = :item_id
    }] {
      ::xo::xotcl_object_cache flush $revision_id
    }
  • require_root_folder (scripted, public)

     <instance of xowiki::Package[i]> require_root_folder \
        [ -parent_id parent_id ] [ -content_types content_types ] \
        -name name 

    Make sure, the root folder for the given package exists. If not, create it and register all allowed content types.

    Switches:
    -parent_id
    (defaults to "-100") (optional)
    -content_types
    (optional)
    -name
    (required)
    Returns:
    folder_id

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_create_form_with_form_instance create_form_with_form_instance (test xowiki) xowiki::Package instproc require_root_folder xowiki::Package instproc require_root_folder test_create_form_with_form_instance->xowiki::Package instproc require_root_folder ad_log ad_log (public) xowiki::Package instproc require_root_folder->ad_log xowiki::transform_root_folder xowiki::transform_root_folder xowiki::Package instproc require_root_folder->xowiki::transform_root_folder

    Testcases:
    create_form_with_form_instance
    set folder_id [xo::xotcl_package_cache eval root_folder-${:id} {
    
      set folder_id [::xo::db::CrClass lookup -name $name -parent_id $parent_id]
      if {$folder_id == 0} {
        #
        # When the folder_id is empty, then something is wrong. Maybe an
        # earlier update script was not running correctly.
        #
        set old_folder_id [xo::dc get_value double_check_old_package {
          select item_id from cr_items where name = :name and parent_id = :parent_id
        }]
        if {$old_folder_id ne ""} {
          :log "-- try to transform old root folder $old_folder_id of package ${:id}"
          ::xowiki::transform_root_folder ${:id}
          set folder_id $old_folder_id
        } else {
          #
          # Check, if the package_key belongs to xowiki (it might be a
          # subclass). If this is not the case, the call is probably an
          # error and we do not want to create a root folder.
          #
          set package_class [::xo::PackageMgr get_package_class_from_package_key ${:package_key}]
          if {$package_class eq ""} {
            ad_log error "trying to create an xowiki root folder for non-xowiki package ${:id}"
            error "trying to create an xowiki root folder for non-xowiki package ${:id}"
          } else {
            ::xowiki::Package require_site_wide_pages
            set form_id [::${:id} instantiate_forms -forms en:folder.form]
            set f [FormPage new -destroy_on_cleanup  -name $name  -text ""  -package_id ${:id}  -parent_id $parent_id  -nls_language en_US  -publish_status ready  -instance_attributes {}  -page_template $form_id]
            $f save_new
            set folder_id [$f item_id]
    
            ::xo::db::sql::acs_object set_attribute -object_id_in $folder_id  -attribute_name_in context_id -value_in ${:id}
    
            :log "CREATED folder '$name' and parent $parent_id ==> $folder_id"
          }
        }
      }
    
      # register all specified content types
      #::xo::db::CrFolder register_content_types  #    -folder_id $folder_id  #    -content_types $content_types
      #:log "returning from cache folder_id $folder_id"
      return $folder_id
    }]
    #:log "returning from require folder_id $folder_id"
    return $folder_id
  • resolve_page (scripted, public)

     <instance of xowiki::Package[i]> resolve_page \
        [ -use_package_path use_package_path ] [ -simple on|off ] \
        [ -lang lang ] object method_var

    Try to resolve from object (path) and query parameter the called object (might be a package or page) and the method to be called.

    Switches:
    -use_package_path
    (defaults to "true") (optional)
    -simple
    (boolean) (defaults to "false") (optional)
    when set, do not try to resolve using item refs, prototype pages or package_path
    -lang
    (optional)
    language used for resolving
    Parameters:
    object - element name to be resolved (not an XOTcl object)
    method_var - output variable for method to be called on the object
    Returns:
    instantiated object (Page or Package) or empty

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_path_resolve path_resolve (test xowiki) xowiki::Package instproc resolve_page xowiki::Package instproc resolve_page test_path_resolve->xowiki::Package instproc resolve_page test_xowiki_test_cases xowiki_test_cases (test xowiki) test_xowiki_test_cases->xowiki::Package instproc resolve_page ad_log ad_log (public) xowiki::Package instproc resolve_page->ad_log

    Testcases:
    xowiki_test_cases, path_resolve
    upvar $method_var method
    
    # get the default language if not specified
    if {![info exists lang]} {
      set lang [:default_language]
      :log "no lang specified for '$object', use default_language <$lang>"
    }
    #:log "object '$object', default-lang $lang"
    
    #
    # First, resolve package level methods,
    # having the syntax PACKAGE_URL?METHOD&....
    #
    
    if {$object eq ""} {
      #
      # We allow only to call methods defined by the policy
      #
      set exported [${:policy} defined_methods Package]
      foreach m $exported {
        #:log "--QP :exists_query_parameter $m = [:exists_query_parameter $m] || [:exists_form_parameter $m]"
        if {[:exists_query_parameter $m] || [:exists_form_parameter $m]} {
          set method $m  ;# determining the method, similar file extensions
          return [self]
        }
      }
    }
    
    if {[string match "//*" $object]} {
      #
      # We have a reference to another instance, we can't resolve this
      # from this package.  Report back not found by empty result.
      #
      #ns_log notice "reference to another instance: <$object>"
      return ""
    }
    
    #:log "--o object is '$object'"
    if {$object eq ""} {
      #
      # We have no object, but as well no method callable on the
      # package If the method is "view", allow it to be called on the
      # root folder object.
      set m [:query_parameter m]
      if {$m in {list show-object file-upload}} {
        array set "" [list  name [::${:folder_id} name]  stripped_name [::${:folder_id} name]  parent_id [::${:folder_id} parent_id]  item_id ${:folder_id}  method [:query_parameter m]]
      } else {
        set object [${:id} get_parameter index_page:graph "index"]
        #:log "--o object after getting index_page is '$object'"
      }
    }
    
    #
    # Second, resolve on object level, unless we have already an
    # item_id from above.
    #
    if {![info exists (item_id)]} {
      array set "" [:item_info_from_url -with_package_prefix false -default_lang $lang $object]
      #:log "item_info_from_url returns [array get {}]"
    }
    
    #:log "object <$object>"
    set fallback_languages [:get_parameter -check_query_parameter false fallback_languages ""]
    if {$(item_id) == 0 && $fallback_languages ne ""} {
      foreach fallback_language $fallback_languages {
        if {$fallback_language ne $lang} {
          array set "" [:item_info_from_url -with_package_prefix false -default_lang $fallback_language $object]
          if { $(item_id) != 0 } {
            :log "item_info_from_url based on fallback_lang <$fallback_language> returns [array get {}]"
            break
          }
        }
      }
    }
    
    if {$(item_id) ne 0} {
      if {$(method) ne ""} { set method $(method) }
      set page [:get_page_from_item_or_revision_id $(item_id)]
    
      # TODO: remove me when settled
      if {[$page info vars storage_type] eq ""} {ad_log notice "$page has no storage_type"}
    
      if {[info exists (logical_package_id)] && [info exists (logical_parent_id)]} {
        #
        # If there was a logical_package_id provided from
        # item_info_from_url, we require that also a logical_parent_id
        # is required. In this case, change the context of the
        # resolved package to this page.
        #
        $page set_resolve_context -package_id $(logical_package_id) -parent_id $(logical_parent_id)
      }
    
      return $page
    }
    
    if {$simple} {
      return ""
    }
    #:log "NOT found object=$object"
    
    # try standard page
    set standard_page [${:id} get_parameter -check_query_parameter false $(stripped_name)_page]
    if {$standard_page ne ""} {
      #
      # Allow for now mapped standard pages just on the top-level
      #
      set page [:get_page_from_item_ref  -allow_cross_package_item_refs false  -use_package_path true  -use_site_wide_pages true  -use_prototype_pages true  -default_lang $lang  -parent_id ${:folder_id}  $standard_page]
      #:log "--o resolving standard_page '$standard_page' returns $page"
      if {$page ne ""} {
        return $page
      }
      # Maybe we are calling from a different language, but the
      # standard page with en: was already instantiated.
      #set standard_page "en:$stripped_object"
      #set page [:resolve_request -default_lang en -path $standard_page method]
      #:msg "resolve -default_lang en -path $standard_page returns --> $page"
      #if {$page ne ""} {
      #  return $page
      #}
    }
    
    # Maybe, a prototype page was imported with language en:, but the current language is different
    #if {$lang ne "en"} {
    #  set page [:resolve_request -default_lang en -path $stripped_object method]
    #  #:msg "resolve -default_lang en -path $stripped_object returns --> $page"
    #  if {$page ne ""} {
    #     return $page
    #  }
    #}
    
    if {$use_package_path} {
      # Check for this page along the package path
      #:log "check along package path"
      foreach package [:package_path] {
        set page [$package resolve_page -simple true -lang $lang $object method]
        if {$page ne ""} {
          #:log "set_resolve_context inherited -package_id ${:id} -parent_id ${:folder_id}"
          $page set_resolve_context -package_id ${:id} -parent_id ${:folder_id}
          return $page
        }
      }
      #:log "package path done [array get {}]"
    }
    
    #
    # The call ":lookup -use_site_wide_pages true" works for looking
    # up the site-wide-pages all kind of packages, not only ::xowiki::Package
    #
    set (item_id) [:lookup -use_site_wide_pages true -name en:$(stripped_name)]
    set page [expr {$(item_id) != 0 ? [:get_page_from_item_or_revision_id $(item_id)] : ""}]
    #:log "get_site_wide_page for en:'$(stripped_name)' returned '$page' (stripped name)"
    if {$page ne ""} {
      #:log "set_resolve_context site-wide -package_id ${:id} -parent_id ${:folder_id}"
      $page set_resolve_context -package_id ${:id} -parent_id ${:folder_id}
      return $page
    }
    
    #
    # Is the current user allowed to create a page from the prototype
    # pages?  In some packages, this might not be allowed.
    #
    if {[:check_permissions -package_id ${:id} [self] create-from-prototype]} {
    
      :log "try to import a prototype page for '$(stripped_name)' [array get {}]"
      if {$(stripped_name) ne ""} {
        #
        # Try to import of prototype pages into the actual folder.
        #
        if {[info exists (logical_parent_id)]} {
          set parent_id $(logical_parent_id)
        } elseif {[info exists (parent_id)]} {
          set parent_id $(parent_id)
        } else {
          set parent_id ${:folder_id}
        }
        set page [:www-import-prototype-page  -lang $lang  -parent_id $parent_id  -add_revision false  $(stripped_name)]
      }
      if {$page eq ""} {
        :log "no prototype for '$object' found"
      }
    }
    
    return $page
  • www-change-page-order (scripted, public)

     <instance of xowiki::Package[i]> www-change-page-order

    This web-callable method changes the page order for pages by renumbering and filling gaps. The parameter "clean" is just used for page inserts. This method is typically called via AJAX.

    Partial Call Graph (max 5 caller/called nodes):
    %3

    Testcases:
    No testcase defined.
    ::xowiki::utility change_page_order  -from [string trim [:form_parameter from ""]]  -to [string trim [:form_parameter to ""]]  -clean [string trim [:form_parameter clean ""]]  -folder_id [string trim [:form_parameter folder_id:int32 ${:folder_id}]]  -package_id ${:id}  -publish_status [string trim [:form_parameter publish_status:word "ready|live|expired"]]
    
    set :mime_type text/plain
    return ""
  • www-delete (scripted, public)

     <instance of xowiki::Package[i]> www-delete [ -item_id item_id ] \
        [ -name name ] [ -parent_id parent_id ] [ -return_url return_url ]

    This web-callable "delete" method does not require an instantiated object, while the class-specific delete methods in xowiki-procs need these. If a (broken) object can't be instantiated, it cannot be deleted. Therefore, we need this package level delete method. While the class specific methods are used from the application pages, the package_level method is used from the admin pages. If no "item_id", "name" or "return_url" are given, take it from the query parameters.

    Switches:
    -item_id
    (optional)
    -name
    (optional)
    -parent_id
    (optional)
    -return_url
    (optional)

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_xowiki_test_cases xowiki_test_cases (test xowiki) xowiki::Package instproc www-delete xowiki::Package instproc www-delete test_xowiki_test_cases->xowiki::Package instproc www-delete _ _ (public) xowiki::Package instproc www-delete->_ ad_urlencode_folder_path ad_urlencode_folder_path (public) xowiki::Package instproc www-delete->ad_urlencode_folder_path

    Testcases:
    xowiki_test_cases
    #:log "--D delete [self args]"
    
    if {![info exists item_id]} {
      set item_id [:query_parameter item_id:int32]
      #:log "--D item_id from query parameter $item_id"
    }
    #
    # if no name is given, take it from the query parameter
    #
    if {![info exists name]} {
      set name [:query_parameter name]
    }
    
    if {![info exists return_url]} {
      set return_url [:query_parameter_return_url  [ad_urlencode_folder_path ${:package_url}]]
    }
    
    if {$item_id eq ""} {
      set item_info [:item_info_from_url -with_package_prefix false $name]
      if {[dict get $item_info item_id] == 0} {
        :log "www-delete: url lookup of '$name' failed"
      } else {
        set parent_id [dict get $item_info parent_id]
        set item_id   [dict get $item_info item_id]
        set name      [dict get $item_info name]
      }
    } else {
      set name [::xo::db::CrClass get_name -item_id $item_id]
      if {![info exists parent_id]} {
        set parent_id [::xo::db::CrClass get_parent_id -item_id $item_id]
      }
    }
    #:msg item_id=$item_id/name=$name
    
    if {$item_id ne ""} {
      :log "--D trying to delete $item_id $name"
      set object_type [::xo::db::CrClass get_object_type -item_id $item_id]
      # In case of PageTemplate and subtypes, we need to check
      # for pages using this template
      set classes [list $object_type {*}[$object_type info heritage]]
      if {"::xowiki::PageTemplate" in $classes} {
        set count [::xowiki::PageTemplate count_usages -item_id $item_id -publish_status all]
        if {$count > 0} {
          return [${:id} error_msg  [_ xowiki.error-delete_entries_first [list count $count]]]
        }
      }
      if {[:get_parameter with_general_comments:boolean 0]} {
        #
        # We have general comments. In a first step, we have to delete
        # these, before we are able to delete the item.
        #
        set comment_ids [::xo::dc list get_comments {
          select comment_id from general_comments where object_id = :item_id
        }]
        foreach comment_id $comment_ids {
          :log "-- deleting comment $comment_id"
          ::xo::db::sql::content_item del -item_id $comment_id
        }
      }
      foreach child_item_id [::xo::db::CrClass get_child_item_ids -item_id $item_id] {
        :flush_references -item_id $child_item_id
      }
    
      $object_type delete -item_id $item_id
      :flush_references -item_id $item_id -name $name -parent_id $parent_id
      :flush_page_fragment_cache -scope agg
    } else {
      :log "--D nothing to delete!"
    }
    :returnredirect $return_url
  • www-edit-category-tree (scripted, public)

     <instance of xowiki::Package[i]> www-edit-category-tree

    This web-callable method redirects the caller to the category admin page for a certain category tree. The "object_id" and "tree_id" have to be provided as a query parameter.

    Partial Call Graph (max 5 caller/called nodes):
    %3 export_vars export_vars (public) site_node::get_package_url site_node::get_package_url (public) xowiki::Package instproc www-edit-category-tree xowiki::Package instproc www-edit-category-tree xowiki::Package instproc www-edit-category-tree->export_vars xowiki::Package instproc www-edit-category-tree->site_node::get_package_url

    Testcases:
    No testcase defined.
    set object_id [:query_parameter object_id:int32]
    set tree_id [:query_parameter tree_id:int32]
    
    # flush could be made more precise in the future
    :flush_page_fragment_cache -scope agg
    :returnredirect [export_vars  -base [site_node::get_package_url -package_key categories]/cadmin/tree-view {
                           tree_id {ctx_id $object_id} object_id
                         }]
  • www-edit-new (scripted, public)

     <instance of xowiki::Package[i]> www-edit-new

    This web-callable method can be used to create new pages in the current package. The behavior can be influenced by the query parameters "object_type", "autoname", "parent_id" and "source_item_id". Finally, it calls "www-edit" for the freshly created page.

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_create_form_with_form_instance create_form_with_form_instance (test xowiki) xowiki::Package instproc www-edit-new xowiki::Package instproc www-edit-new test_create_form_with_form_instance->xowiki::Package instproc www-edit-new ad_return_complaint ad_return_complaint (public) xowiki::Package instproc www-edit-new->ad_return_complaint ad_script_abort ad_script_abort (public) xowiki::Package instproc www-edit-new->ad_script_abort

    Testcases:
    create_form_with_form_instance
    set object_type [:query_parameter object_type:class "::xowiki::Page"]
    set autoname [:get_parameter autoname:boolean 0]
    set parent_id [${:id} query_parameter parent_id:cr_item_of_package,arg=${:id}]
    if {$parent_id eq ""} {
      set parent_id [${:id} form_parameter folder_id:int32 ${:folder_id}]
      if {![::xo::db::CrClass id_belongs_to_package -item_id $parent_id -package_id ${:id}]} {
        ad_return_complaint 1 "invalid parent_id"
        ad_script_abort
      }
    }
    set page [$object_type new -volatile -parent_id $parent_id -package_id ${:id}]
    # :ds "parent_id of $page = [$page parent_id], cl=[$page info class] parent_id=$parent_id\n[$page serialize]"
    if {$object_type eq "::xowiki::PageInstance"} {
      #
      # If we create a PageInstance via the ad_form based
      # PageInstanceForm, we have to provide the page_template here to
      # be able to validate the name, where "build_name" needs
      # access to the ::xowiki::PageTemplate of the
      # ::xowiki::PageInstance.
      #
      $page set page_template [:form_parameter page_template:int32]
    }
    
    set source_item_id [${:id} query_parameter source_item_id:int32 ""]
    if {$source_item_id ne ""} {
      if {![string is integer -strict $source_item_id]} {
        ad_return_complaint 1 "invalid source_item_id"
        ad_script_abort
      }
      set source [$object_type get_instance_from_db -item_id $source_item_id]
      $page copy_content_vars -from_object $source
      set name "[::xowiki::autoname new -parent_id $source_item_id -name [$source name]]"
      # :get_lang_and_name -name $name lang name
      $page set name $name
      #:msg nls=[$page nls_language],source-nls=[$source nls_language],page=$page,name=$name
    } else {
      $page set name ""
    }
    
    return [$page www-edit -new true -autoname $autoname]
  • www-google-sitemap (scripted, public)

     <instance of xowiki::Package[i]> www-google-sitemap \
        [ -max_entries max_entries ] [ -changefreq changefreq ] \
        [ -priority priority ]

    This web-callable method reports the content of xowiki folder in google site map format https://www.google.com/webmasters/sitemaps/docs/en/protocol.html

    Switches:
    -max_entries
    (optional)
    maximum number of entries retrieved
    -changefreq
    (defaults to "daily") (optional)
    changefreq as defined by google
    -priority
    (defaults to "0.5") (optional)
    priority as defined by google

    Partial Call Graph (max 5 caller/called nodes):
    %3 xo::db::tcl_date xo::db::tcl_date (public) xowiki::url xowiki::url (private) xowiki::Package instproc www-google-sitemap xowiki::Package instproc www-google-sitemap xowiki::Package instproc www-google-sitemap->xo::db::tcl_date xowiki::Package instproc www-google-sitemap->xowiki::url

    Testcases:
    No testcase defined.
    set package ::${:id}
    set folder_id [$package folder_id]
    
    set timerange_clause ""
    
    set content {<?xml version="1.0" encoding="UTF-8"?>
      <urlset xmlns="http://www.google.com/schemas/sitemap/0.84"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84
    http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">
    }
    
    set sql [::xo::dc select  -vars "ci.parent_id, s.body, p.name, p.creator, p.title, p.page_id, p.object_type as content_type, p.last_modified, p.description"  -from "xowiki_pagex p, syndication s, cr_items ci"  -where "ci.parent_id = :folder_id and ci.live_revision = s.object_id  and s.object_id = p.page_id $timerange_clause"  -orderby "p.last_modified desc"  -limit $max_entries]
    # :log $sql
    
    ::xo::dc foreach get_pages $sql {
      #:log "--found $name"
      if {[string match "::*" $name]} continue
      if {$content_type eq "::xowiki::PageTemplate::"} continue
    
      set time [::xo::db::tcl_date $last_modified tz]
      set time "[clock format [clock scan $time] -format {%Y-%m-%dT%T}]${tz}:00"
    
      append content <url> \n <loc>[$package pretty_link -absolute true -parent_id $parent_id $name]</loc> \n <lastmod>$time</lastmod> \n <changefreq>$changefreq</changefreq> \n <priority>$priority</priority> \n </url> \n
    }
    
    append content </urlset> \n
    
    set :mime_type text/xml
    return $content
  • www-google-sitemapindex (scripted, public)

     <instance of xowiki::Package[i]> www-google-sitemapindex

    This web-callable method calls "google_sitemapindex" for producing a sitemap index.

    Partial Call Graph (max 5 caller/called nodes):
    %3

    Testcases:
    No testcase defined.
    [self class] google_sitemapindex -package [self]
  • www-import-prototype-page (scripted, public)

     <instance of xowiki::Package[i]> www-import-prototype-page \
        [ -add_revision on|off ] [ -lang lang ] [ -parent_id parent_id ] \
        [ prototype_name ]

    This web-callable method is designed for admin to ease the import of prototpye pages. When called via web, the query parameter "import-prototype-page" determines the page for the import.

    Switches:
    -add_revision
    (boolean) (defaults to "true") (optional)
    -lang
    (defaults to "en") (optional)
    -parent_id
    (optional)
    Parameters:
    prototype_name (optional)

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_create_form_with_form_instance create_form_with_form_instance (test xowiki) xowiki::Package instproc www-import-prototype-page xowiki::Package instproc www-import-prototype-page test_create_form_with_form_instance->xowiki::Package instproc www-import-prototype-page ad_urlencode_folder_path ad_urlencode_folder_path (public) xowiki::Package instproc www-import-prototype-page->ad_urlencode_folder_path

    Testcases:
    create_form_with_form_instance
    set page ""
    if {$prototype_name eq ""} {
      set prototype_name [:query_parameter import-prototype-page ""]
      set via_url 1
    }
    if {![info exists parent_id]} {
      set parent_id ${:folder_id}
    }
    if {$prototype_name eq ""} {
      error "No name for prototype given"
    }
    
    set page [::xowiki::Package import_prototype_page  -package_key [:package_key]  -name $prototype_name  -lang $lang  -parent_id $parent_id  -package_id ${:id}  -add_revision $add_revision]
    
    if {[info exists via_url] && [:exists_query_parameter "return_url"]} {
      :returnredirect [:query_parameter "return_url:localurl" [ad_urlencode_folder_path ${:package_url}]]
    } else {
      return $page
    }
  • www-manage-categories (scripted, public)

     <instance of xowiki::Package[i]> www-manage-categories

    This web-callable method redirects the caller to the category admin page configured for the current package. The "object_id" has to be provided as a query parameter.

    Partial Call Graph (max 5 caller/called nodes):
    %3 export_vars export_vars (public) site_node::get_package_url site_node::get_package_url (public) xowiki::Package instproc www-manage-categories xowiki::Package instproc www-manage-categories xowiki::Package instproc www-manage-categories->export_vars xowiki::Package instproc www-manage-categories->site_node::get_package_url

    Testcases:
    No testcase defined.
    set object_id [:query_parameter object_id:int32]
    
    # flush could be made more precise in the future
    :flush_page_fragment_cache -scope agg
    
    set href [export_vars  -base [site_node::get_package_url -package_key categories]cadmin/object-map {
                    {ctx_id $object_id} object_id
                  }]
    :returnredirect $href
  • www-refresh-login (scripted, public)

     <instance of xowiki::Package[i]> www-refresh-login

    This web-callable method forces a refresh of a login and do a redirect. Intended for use from ajax.

    Partial Call Graph (max 5 caller/called nodes):
    %3 export_vars export_vars (public) subsite::get_url subsite::get_url (public) xowiki::Package instproc www-refresh-login xowiki::Package instproc www-refresh-login xowiki::Package instproc www-refresh-login->export_vars xowiki::Package instproc www-refresh-login->subsite::get_url

    Testcases:
    No testcase defined.
    set return_url [:query_parameter return_url:localurl]
    if {[::xo::cc user_id] == 0} {
      set url [subsite::get_url]register
      :returnredirect [export_vars -base $url return_url]
    } else {
      :returnredirect $return_url
    }
  • www-reindex (scripted, public)

     <instance of xowiki::Package[i]> www-reindex

    This web-callable method can be used to reindex all items of this package by adding all pages of this package to the search queue.

    Partial Call Graph (max 5 caller/called nodes):
    %3 search::queue search::queue (public) xowiki::Package instproc www-reindex xowiki::Package instproc www-reindex xowiki::Package instproc www-reindex->search::queue

    Testcases:
    No testcase defined.
    set id ${:id}
    set pages [::xo::dc list get_pages {
      select page_id,package_id from xowiki_page, cr_revisions r, cr_items ci, acs_objects o
      where page_id = r.revision_id and ci.item_id = r.item_id and ci.live_revision = page_id
      and publish_status = 'ready'
      and page_id = o.object_id and o.package_id = :id
    }]
    #:log "--reindex returns <$pages>"
    foreach page_id $pages {
      #search::queue -object_id $page_id -event DELETE
      search::queue -object_id $page_id -event INSERT
    }
    :returnredirect .
  • www-rss (scripted, public)

     <instance of xowiki::Package[i]> www-rss [ -maxentries maxentries ] \
        [ -name_filter name_filter ] [ -entries_of entries_of ] \
        [ -title title ] [ -days days ]

    This web-callable method reports the content of xowiki folder in rss 2.0 format. The reporting order is descending by date. The title of the feed is taken from the title, the description is taken from the description field of the folder object.

    Switches:
    -maxentries
    (optional)
    maximum number of entries retrieved
    -name_filter
    (optional)
    -entries_of
    (optional)
    -title
    (optional)
    -days
    (optional)
    report entries changed in specified last days

    Partial Call Graph (max 5 caller/called nodes):
    %3

    Testcases:
    No testcase defined.
    set folder_id [::${:id} folder_id]
    if {![info exists name_filter]} {
      set name_filter [:get_parameter -check_query_parameter false -type word name_filter ""]
    }
    if {![info exists entries_of]} {
      set entries_of [:get_parameter -check_query_parameter false -type noquote entries_of ""]
    }
    if {![info exists title]} {
      set title [:get_parameter -check_query_parameter false PackageTitle ${:instance_name}]
    }
    set description [:get_parameter -check_query_parameter false PackageDescription ""]
    
    if {![info exists days]} {
      set rss_query_parameter [:query_parameter rss]
      if {[regexp {^([0-9]+)d} $rss_query_parameter _ days]
          && $days < 50000
        } {
        # Variable "days" is set by regexp
      } else {
        ns_log warning "rss_query_parameter has invalid value '$rss_query_parameter'; fall back to 10d"
        set days 10
      }
    } else {
      set days 10
    }
    set r [RSS new -destroy_on_cleanup  -package_id ${:id}  -parent_ids [:query_parameter parent_ids:int32,0..n ""]  -name_filter $name_filter  -entries_of $entries_of  -title $title  -description $description  -days $days]
    
    set :mime_type text/xml
    return [$r render]
  • www-update-references (scripted, public)

     <instance of xowiki::Package[i]> www-update-references

    This web-callable method can be used to update the page references between all items of this package instance. Call with e.g. xowiki/?update-references

    Partial Call Graph (max 5 caller/called nodes):
    %3

    Testcases:
    No testcase defined.
    set id ${:id}
    set item_ids [::xo::dc list get_pages {
      select ci.item_id from xowiki_page, cr_revisions r, cr_items ci, acs_objects o
      where page_id = r.revision_id and ci.item_id = r.item_id and ci.live_revision = page_id
      and publish_status = 'ready'
      and page_id = o.object_id and o.package_id = :id
    }]
    #:log "--update-references returns <$item_ids>"
    foreach item_id $item_ids {
      set o [::xo::db::CrClass get_instance_from_db -item_id $item_id]
      if {$o ne ""} {
        ns_log notice "render $o [$o name]"
        try {
          $o render -update_references all
        } on error {errorMsg} {
          ns_log warning "render $o [$o name] -> error: $errorMsg"
        }
      }
    }
    :returnredirect .