xowiki::Page instproc www-create-new (public)

 <instance of xowiki::Page[i]> www-create-new \
    [ -parent_id parent_id ] [ -view_method view_method ] \
    [ -name name ] [ -nls_language nls_language ] \
    [ -publish_status publish_status ]

Defined in packages/xowiki/tcl/xowiki-www-procs.tcl

This web-callable method creates a new page, typically an instance of a form page. The method accesses several form variables such as "__form_redirect", "__text_to_html", "last_page_id", "name", "nls_language", "package_id", "package_instance", "page_order", "parent_id", "publish_status", "source_item_id", "title" The call redirects either to the "__form_redirect" or to the created page.

Switches:
-parent_id
(defaults to "0") (optional)
-view_method
(defaults to "edit") (optional)
-name
(optional)
-nls_language
(optional)
-publish_status
(optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_create_composite_test_item create_composite_test_item (test xowf) xowiki::Page instproc www-create-new xowiki::Page instproc www-create-new test_create_composite_test_item->xowiki::Page instproc www-create-new test_create_folder_and_configure create_folder_and_configure (test xowiki) test_create_folder_and_configure->xowiki::Page instproc www-create-new test_create_form_with_form_instance create_form_with_form_instance (test xowiki) test_create_form_with_form_instance->xowiki::Page instproc www-create-new test_create_form_with_numeric create_form_with_numeric (test xowiki) test_create_form_with_numeric->xowiki::Page instproc www-create-new test_create_test_items create_test_items (test xowf) test_create_test_items->xowiki::Page instproc www-create-new _ _ (public) xowiki::Page instproc www-create-new->_ ad_return_complaint ad_return_complaint (public) xowiki::Page instproc www-create-new->ad_return_complaint ad_script_abort ad_script_abort (public) xowiki::Page instproc www-create-new->ad_script_abort ad_text_to_html ad_text_to_html (public) xowiki::Page instproc www-create-new->ad_text_to_html ad_try ad_try (public) xowiki::Page instproc www-create-new->ad_try

Testcases:
create_test_items, create_composite_test_item, xowiki_test_cases, create_form_with_form_instance, create_form_with_numeric, form_validate, create_folder_and_configure
Source code:
set original_package_id ${:package_id}

if {[:exists_query_parameter "package_instance"]} {
  set package_instance [:query_parameter package_instance:localurl]
  #
  # Initialize the target package and set the variable package_id.
  #
  ad_try {
    ::xowiki::Package initialize  -url $package_instance -user_id [::xo::cc user_id]  -actual_query ""
  } on error {errorMsg} {
    ns_log error "Package initialize: $errorMsg\n$::errorInfo"
    return [::$original_package_id error_msg  "Page <b>'${:name}'</b> invalid provided package instance=$package_instance<p>$errorMsg</p>"]
  }
}

#
# Collect some default values from query parameters.
#
set default_variables [list]
foreach param {name title page_order:graph last_page_id:int32 nls_language:wordchar} {
  regexp {^([^:]+):?} $param . key
  if {[:exists_query_parameter $key]} {
    lappend default_variables $key [:query_parameter $param]
  }
}

# TODO: the following calls are here temporarily for posting
# content from manually added forms (e.g. linear forum). The
# following should be done:
#  - create an includelet to create the form markup automatically
#  - validate and transform input as usual
# We should probably allow as well controlling auto-naming and
# and prohibit empty postings.

set text_to_html [:form_parameter "__text_to_html" ""]
foreach key {_text _name} {
  if {[:exists_form_parameter $key]} {
    set __value [:form_parameter $key]
    if {$key in $text_to_html} {
      set __value [ad_text_to_html -- $__value]
    }
    lappend default_variables [string range $key 1 end] $__value
    switch -- $key {
      _name {set name $__value}
    }
  }
}

# Load the instance attributes from the form parameters
set instance_attributes [list]
foreach {_att _value} [::xo::cc get_all_form_parameter] {
  if {[string match _* $_att]} continue
  lappend instance_attributes $_att $_value
}

#
# To create form_pages in different places than the form, one can
# provide parent_id and package_id.
#
# The following construct is more complex than necessary to
# provide backward compatibility. Note that the passed-in
# parent_id has priority over the other measures to obtain it.
#
if {$parent_id == 0} {
  if {![info exists :parent_id]} {
    set :parent_id [::${:package_id} folder_id]
  }
  set fp_parent_id [:form_parameter parent_id [:query_parameter parent_id:int32 ${:parent_id}]]
} else {
  set fp_parent_id $parent_id
}
#
# Allow only inserts to own package.
#
if {![::xo::db::CrClass id_belongs_to_package -item_id $fp_parent_id -package_id ${:package_id}]} {
  ad_return_complaint 1 "invalid parent_id"
  ad_script_abort
}

# In case the Form is inherited and package_id was not specified, we
# use the actual package_id.
set fp_package_id [:form_parameter package_id [:query_parameter package_id:int32 ${:package_id}]]

#
# Handling publish_status. When the publish_status is provided via
# query parameter, this has the highest priority. Otherwise use
# the publish_status according to the production_mode. We control
# this here explicitly, since when "name" is provided via query
# variable, the default production/ready selection fails, and we
# have to set the publish_status manually (see issue #3380).
#
if {$publish_status eq ""} {
  set publish_status [:query_parameter publish_status:wordchar ""]
}
if {$publish_status eq "" && [:exists_query_parameter name]} {
  if {[::${:package_id} get_parameter production_mode:boolean 0]} {
    set publish_status "production"
  } else {
    set publish_status "ready"
  }
  :log "FINAL publish_status $publish_status"
}

#
# Provide "p.source" hook to configure pages by copying variables
# from other pages (e.g. sitewide pages)
#
set source_item_id 0
if {[:exists_query_parameter p.source]} {
  set source_page [:query_parameter p.source:token]
  set source_item_id [::${:package_id} lookup -use_site_wide_pages true -name $source_page]
}
if {$source_item_id == 0} {
  set source_item_id [:query_parameter source_item_id:int32 ""]
}

::xo::Package require $fp_package_id
set f [:create_form_page_instance  -name $name  -nls_language $nls_language  -parent_id $fp_parent_id  -package_id $fp_package_id  -default_variables $default_variables  -instance_attributes $instance_attributes  -source_item_id $source_item_id]

if {$publish_status ne ""
    && $publish_status in {"production" "ready" "live" "expired"}
  } {
  $f publish_status $publish_status
}

#
# Provide "p.configure" hook to programmatically configure pages
#
if {[:exists_query_parameter p.configure]} {
  set configure_method [:query_parameter p.configure:wordchar]
  if {[$f procsearch configure_page=$configure_method] ne ""} {
    #ns_log notice "call [$f procsearch configure_page=$configure_method] // [$f info class]"
    $f configure_page=$configure_method $name
  } else {
    ns_log notice "cannot find configure_page=$configure_method on [$f info precedence]"
  }
}

if {$name eq ""} {
  $f save_new
} else {
  set id [::$fp_package_id lookup -parent_id $fp_parent_id -name $name]
  if {$id == 0} {
    $f save_new
  } else {
    ::xowiki::FormPage get_instance_from_db -item_id $id
    $f copy_content_vars -from_object $id
    $f item_id $id
    $f save
  }
}

$f notification_notify

foreach var {return_url:localurl template_file title detail_link:localurl text} {
  regexp {^([^:]+):?} $var . key
  if {[:exists_query_parameter $key]} {
    set $key [:query_parameter $var]
    :log "set instance var from query param '$key' -> '[set $key]'"
  }
}

if {[info exists template_file]} {
  #
  # strip the leading "/" added by ns_normalizepath.
  #
  # TODO: check use-cases, with the restricted case actually still
  # makes sense.
  #
  set template_file [$fp_package_id normalizepath $template_file]
}
set form_redirect [:form_parameter "__form_redirect" ""]
if {$form_redirect eq ""} {
  set form_redirect [$f pretty_link -query [export_vars {
    {m $view_method} return_url template_file title detail_link text
  }]]
}
${:package_id} returnredirect $form_redirect
set :package_id $original_package_id
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: