xowiki::Page instproc www-create-new (public)
<instance of xowiki::Page> www-create-new \ [ -parent_id parent_id ] [ -view_method view_method ] \ [ -name name ] [ -nls_language nls_language ] \ [ -publish_status publish_status ]
Defined in /var/www/openacs.org/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 (optional, defaults to
"0"
)- -view_method (optional, defaults to
"edit"
)- -name (optional)
- -nls_language (optional)
- -publish_status (optional)
- 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 {} # # The value for "name" is validated later, and requires the type # of the object. Different names are allowed for files, folders # and other wiki pages. # foreach name_and_spec [list name title page_order:graph last_page_id:int32 nls_language:oneof,arg=[join [lang::system::get_locales] |] ] { set p [string first : $name_and_spec] set key [expr {$p > -1 ? [string range $name_and_spec 0 $p-1] : $name_and_spec}] if {[:exists_query_parameter $key]} { lappend default_variables $key [:query_parameter $name_and_spec] } } # 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:0..n ""] 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:int32 [: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:int32 [: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 name_and_spec { return_url:localurl template_file title detail_link:localurl text } { set p [string first : $name_and_spec] set key [expr {$p > -1 ? [string range $name_and_spec 0 $p-1] : $name_and_spec}] if {[:exists_query_parameter $key]} { set $key [:query_parameter $name_and_spec] :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:0..n ""] 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_idXQL Not present: Generic, PostgreSQL, Oracle