Index: openacs-4/packages/xowiki/xowiki.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/xowiki.info,v
diff -u -r1.17 -r1.18
--- openacs-4/packages/xowiki/xowiki.info 19 Jun 2006 00:40:03 -0000 1.17
+++ openacs-4/packages/xowiki/xowiki.info 26 Jul 2006 22:56:45 -0000 1.18
@@ -8,36 +8,41 @@
"
}
- Page ad_proc select_query {
- {-select_attributes ""}
- {-order_clause ""}
- {-where_clause ""}
- {-count:boolean false}
- {-folder_id}
- {-page_size 20}
- {-page_number ""}
- {-syndication:boolean false}
- {-extra_where_clause ""}
- {-extra_from_clause ""}
- } {
- returns the SQL-query to select the xowiki pages of the specified folder
- @select_attributes attributes for the sql query to be retrieved, in addion
- to ci.item_id acs_objects.object_type, which are always returned
- @param order_clause clause for ordering the solution set
- @param where_clause clause for restricting the answer set
- @param count return the query for counting the solutions
- @param folder_id parent_id
- @return sql query
- } {
- my instvar object_type_key
- if {![info exists folder_id]} {my instvar folder_id}
+ #
+ # URL and naming management
+ #
+ Page proc pretty_link {{-fully_qualified:boolean false} -lang -package_id name} {
+ my instvar folder_id
+ my log "--u name=<$name>"
- set attributes [list ci.item_id ci.name p.page_id]
- foreach a $select_attributes {
- if {$a eq "title"} {set a p.title}
- lappend attributes $a
+ if {![info exists package_id]} {set package_id [$folder_id set package_id]}
+ if {![my isobject ::$package_id]} {
+ my log "--u we create package ::xowiki::Package create ::$package_id -folder_id $folder_id"
+ ::xowiki::Package create ::$package_id -folder_id $folder_id
}
- if {$count} {
- set attribute_selection "count(*)"
- set order_clause "" ;# no need to order when we count
- set page_number "" ;# no pagination when count is used
+ set url [::$package_id package_url]
+
+ if {![info exists lang]} {
+ regexp {^(..):(.*)$} $name _ lang name
+ }
+ if {![info exists lang] && ![string match :* $name]} {
+ set lang [string range [lang::conn::locale] 0 1]
+ }
+ set host [expr {$fully_qualified ? [ad_url] : ""}]
+ if {[info exists lang]} {
+ return $host${url}$lang/[ad_urlencode $name]
} else {
- set attribute_selection [join $attributes ,]
+ return $host${url}[ad_urlencode $name]
}
+ }
- if {$where_clause ne ""} {set where_clause "and $where_clause "}
-# if {$syndication} {
-# append where_clause "and syndication.object_id = p.page_id"
-# set extra_tables ", syndication "
-# } else {
-# set extra_tables ""
-# }
- if {$page_number ne ""} {
- set pagination "offset [expr {$page_size*($page_number-1)}] limit $page_size"
- } else {
- set pagination ""
+ Page proc normalize_name {-package_id string} {
+ set string [string trim $string]
+ # if subst_blank_in_name is turned on, turn spaces into _
+ if {[$package_id get_parameter subst_blank_in_name 1] != 0} {
+ regsub -all { } $string "_" string
}
- return "select $attribute_selection from xowiki_pagei p, cr_items ci $extra_from_clause \
- where ci.parent_id = $folder_id and ci.item_id = p.item_id and \
- ci.live_revision = p.page_id $where_clause $extra_where_clause $order_clause $pagination"
+ return $string
}
+ Page instproc make_link {-privilege -url object method args} {
+ my instvar package_id
+
+ if {[info exists privilege]} {
+ set granted [expr {$privilege eq "public" ? 1 :
+ [permission::permission_p -object_id $package_id -privilege $privilege]
+ }]
+ } else {
+ # determine privilege from policy
+ set granted [$package_id permission_p $object $method]
+ my log "--p $package_id permission_p $object $method ==> $granted"
+ }
+ if {$granted} {
+ if {[$object istype ::xowiki::Package]} {
+ set base [$package_id package_url]
+ if {[info exists url]} {
+ return [uplevel export_vars -base $base$url [list $args]]
+ } else {
+ lappend args [list $method 1]
+ return [uplevel export_vars -base $base [list $args]]
+ }
+ } elseif {[$object istype ::xowiki::Page]} {
+ set base [$package_id url]
+ lappend args [list m $method]
+ return [uplevel export_vars -base $base [list $args]]
+ }
+ }
+ return ""
+ }
+
#
- # data definitions
+ # tag management, get_tags works on instance or gobally
#
- Page parameter {
- page_id
- {revision_id 0}
- object_type
- {folder_id -100}
- {lang_links ""}
- {lang en}
- {render_adp 1}
+ Page proc save_tags {-package_id:required -item_id:required -user_id:required tags} {
+ db_dml delete_tags \
+ "delete from xowiki_tags where item_id = $item_id and user_id = $user_id"
+ foreach tag $tags {
+ db_dml insert_tag \
+ "insert into xowiki_tags (item_id,package_id, user_id, tag, time) \
+ values ($item_id, $package_id, $user_id, :tag, current_timestamp)"
+ }
+ }
+ Page proc get_tags {-package_id:required -item_id -user_id} {
+ if {[info exists item_id]} {
+ if {[info exists user_id]} {
+ # tags for item and user
+ set tags [db_list get_tags "SELECT distinct tag from xowiki_tags where user_id=$user_id and item_id=$item_id and package_id=$package_id"]
+ } else {
+ # all tags for this item
+ set tags [db_list get_tags "SELECT distinct tag from xowiki_tags where item_id=$item_id and package_id=$package_id"]
+ }
+ } else {
+ if {[info exists user_id]} {
+ # all tags for this user
+ set tags [db_list get_tags "SELECT distinct tag from xowiki_tags where user_id=$user_id and package_id=$package_id"]
+ } else {
+ # all tags for the package
+ set tags [db_list get_tags "SELECT distinct tag from xowiki_tags where package_id=$package_id"]
+ }
+ }
+ join $tags " "
}
- Page set recursion_count 0
- Page array set RE {
- include {([^\\]){{(.+)}}[ \n\r]*}
- anchor {([^\\])\\\[\\\[([^\]]+)\\\]\\\]}
- div {()([^\\])>>([^&]*)<<}
- clean {[\\](\{\{|>>|\[\[)}
- }
- PlainPage parameter {
- {render_adp 0}
- }
- PlainPage array set RE {
- include {([^\\]){{(.+)}}[ \n\r]}
- anchor {([^\\])\\\[\\\[([^\]]+)\\\]\\\]}
- div {()([^\\])>>([^<]*)<<}
- clean {[\\](\{\{|>>|\[\[)}
- }
- PageTemplate parameter {
- {render_adp 0}
- }
-
#
# Methods of ::xowiki::Page
#
+ Page instforward query_parameter {%my set package_id} %proc
+ Page instforward exists_query_parameter {%my set package_id} %proc
+ Page instforward form_parameter {%my set package_id} %proc
+ Page instforward exists_form_parameter {%my set package_id} %proc
+
+ Page instproc condition {method attr value} {
+ switch $attr {
+ has_class {return [expr {[my set object_type] eq $value}]}
+ }
+ return 0
+ }
+
+ Page instproc get_user_name {uid} {
+ if {$uid ne "" && $uid != 0} {
+ acs_user::get -user_id $uid -array user
+ return "$user(first_names) $user(last_name)"
+ } else {
+ return nobody
+ }
+ }
+
+
+ Page instproc initialize_loaded_object {} {
+ my instvar title creator
+ if {[info exists title] && $title eq ""} {set title [my set name]}
+ #if {$creator eq ""} {set creator [my get_user_name [my set creation_user]]}
+ next
+ }
+
Page instproc regsub-eval {re string cmd} {
subst [regsub -all $re [string map {\[ \\[ \] \\] \$ \\$ \\ \\\\} $string] \
"\[$cmd\]"]
@@ -688,7 +689,7 @@
return "$ch$label"
}
- my instvar parent_id
+ my instvar parent_id package_id
# do we have a language link (it starts with a ':')
if {[regexp {^:(..):(.*)$} $link _ lang stripped_name]} {
set link_type language
@@ -702,20 +703,14 @@
regexp {^(..):(.+)$} $link _ lang stripped_name
}
}
- set stripped_name [string trim $stripped_name]
- if {$lang eq ""} {set lang [my lang]}
+ set stripped_name [Page normalize_name -package_id $package_id $stripped_name]
+ if {$lang eq ""} {set lang [my lang]}
if {$label eq $arg} {set label $stripped_name}
- # if subst_blank_in_name is turned on, turn spaces into _
- if {[$parent_id get_payload subst_blank_in_name] == 1} {
- regsub -all { } $stripped_name "_" stripped_name
- }
-
- #my log "--LINK lang=$lang type=$link_type stripped_name=$stripped_name"
Link create [self]::link \
-type $link_type -name $lang:$stripped_name -lang $lang \
-stripped_name $stripped_name -label $label \
- -folder_id $parent_id -package_id [$parent_id set package_id]
+ -folder_id $parent_id -package_id $package_id
return $ch[[self]::link render]
}
@@ -754,7 +749,7 @@
}
Page instproc adp_subst {content} {
- set __ignorelist [list RE __defaults name_method object_type_key url_prefix]
+ set __ignorelist [list RE __defaults name_method object_type_key]
foreach __v [my info vars] {
if {[info exists $__v]} continue
my instvar $__v
@@ -783,7 +778,7 @@
}
Page instproc get_content {} {
- my log "--"
+ #my log "--"
set content [my substitute_markup [my set text]]
}
@@ -838,11 +833,10 @@
Page instproc record_last_visited {-user_id} {
- my instvar parent_id item_id
+ my instvar item_id package_id
if {![info exists user_id]} {set user_id [ad_conn user_id]}
if {$user_id > 0} {
# only record information for authenticated users
- set package_id [$parent_id set package_id]
db_dml update_last_visisted \
"update xowiki_last_visited set time = current_timestamp, count = count + 1 \
where page_id = $item_id and user_id = $user_id"
@@ -858,6 +852,16 @@
# Methods of ::xowiki::PlainPage
#
+ PlainPage parameter {
+ {render_adp 0}
+ }
+ PlainPage array set RE {
+ include {([^\\]){{(.+)}}[ \n\r]}
+ anchor {([^\\])\\\[\\\[([^\]]+)\\\]\\\]}
+ div {()([^\\])>>([^<]*)<<}
+ clean {[\\](\{\{|>>|\[\[)}
+ }
+
PlainPage instproc get_content {} {
#my log "-- my class=[my info class]"
return [my substitute_markup [my set text]]
@@ -878,9 +882,15 @@
}
#
- # PageInstance methods
+ # PageTemplate specifics
#
+ PageTemplate parameter {
+ {render_adp 0}
+ }
+ #
+ # PageInstance methods
+ #
PageInstance instproc get_field_type {name template default_spec} {
# get the widget field specifications from the payload of the folder object
# for a field with a specified name in a specified page template
@@ -932,6 +942,11 @@
# Methods of ::xowiki::Object
#
+ #Object instproc save_new {} {
+ #my set text [::Serializer deepSerialize [self]]
+ #next
+ #}
+
Object instproc get_content {} {
if {[[self]::payload info procs content] ne ""} {
return [my substitute_markup [[self]::payload content]]
@@ -946,15 +961,18 @@
}
Object instproc set_payload {cmd} {
set payload [self]::payload
- if {![my isobject $payload]} {::xotcl::Object create $payload -requireNamespace}
+ if {[my isobject $payload]} {$payload destroy}
+ ::xotcl::Object create $payload -requireNamespace
if {[catch {$payload eval $cmd} error ]} {
ns_log error "XoWiki folder object: content lead to error: $error"
}
}
- Object instproc get_payload {var} {
+ Object instproc get_payload {var {default ""}} {
set payload [self]::payload
if {![my isobject $payload]} {::xotcl::Object create $payload -requireNamespace}
- expr {[$payload exists $var] ? [$payload set $var] : ""}
+ expr {[$payload exists $var] ? [$payload set $var] : $default}
}
-}
\ No newline at end of file
+}
+
+source [file dirname [info script]]/xowiki-www-procs.tcl
\ No newline at end of file
Index: openacs-4/packages/xowiki/tcl/xowiki-sc-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-sc-procs.tcl,v
diff -u -r1.10 -r1.11
--- openacs-4/packages/xowiki/tcl/xowiki-sc-procs.tcl 7 Jun 2006 17:08:24 -0000 1.10
+++ openacs-4/packages/xowiki/tcl/xowiki-sc-procs.tcl 26 Jul 2006 22:56:46 -0000 1.11
@@ -15,13 +15,9 @@
} {
ns_log notice "--datasource called with revision_id = $revision_id"
- set page [::Generic::CrItem instantiate -item_id 0 -revision_id $revision_id]
+ set page [::xowiki::Package instantiate_from_page -revision_id $revision_id]
$page volatile
- # ensure context for dependencies of folder object
- set folder_id [$page set parent_id]
- ::xowiki::Page require_folder_object -folder_id $folder_id
-
set html [$page render]
set text [ad_html_text_convert -from text/html -to text/plain -- $html]
#set text [ad_text_to_html $html]; #this could be used for entity encoded html text in rss entries
@@ -30,15 +26,15 @@
#$page set unresolved_references 0
$page instvar item_id
- return [list object_id $revision_id title [$page set title] \
+ return [list object_id $revision_id title [$page title] \
content $text keywords {} \
storage_type text mime text/plain \
syndication [list \
link [::xowiki::Page pretty_link -fully_qualified 1 [$page set name]] \
description $text \
author [$page set creator] \
category "" \
- guid "[ad_url]/o/$item_id" \
+ guid "$item_id" \
pubDate [$page set last_modified]] \
]
}
@@ -48,18 +44,9 @@
returns a url for a message to the search package
} {
- set page [::Generic::CrItem instantiate -item_id 0 -revision_id $revision_id]
+ set page [::xowiki::Package instantiate_from_page -revision_id $revision_id]
$page volatile
- set folder_id [$page set parent_id]
- set pid [db_string get_pid "select package_id from cr_folders where folder_id = $folder_id"]
- if {$pid > 0} {
- return [::xowiki::Page pretty_link -package_id $pid [$page set name]]
- } else {
- # cannot determine package_id; one page from the directory should be viewed to update
- # package id for the content folder...
- return "cannot determine package_id, view a page from the folder containing page \
- [$page set name]"
- }
+ return [::[$page package_id] url]
}
Index: openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 26 Jul 2006 22:56:46 -0000 1.1
@@ -0,0 +1,291 @@
+# different template testing DONE
+# orphan creation DONE
+# orphan deletions completion DONE
+# link resolver DONE
+# edit-new parameter name DONE
+# cgi package_id missing DONE
+# delete all DONE
+# $parent_id set package_id DONE
+# lang link DONE
+# unknown link DONE
+# weblog DONE
+# tag edit DONE
+# tag new DONE
+# weblog on the fly creation DONE
+# behavior without index page DONE
+# renaming objects DONE
+# handling of sc DONE
+# make subst_blank_in_name default DONE
+# package parameters and payload of folder object DONE
+# permissions management DONE
+# permissions admin DONE
+# include DONE
+# edit page template DONE
+# edit page instance DONE
+# delete folder object DONE
+# the flag store_folder_id should not be necessary
+# move require folder object code
+# edit-new last_page_id (needed?)
+# edit last_page_id (needed?)
+
+
+namespace eval ::xowiki {
+
+ Page instproc view {} {
+ # view is used only for the toplevel call, when the xowiki page is viewed
+ # this is not inteded for embedded wiki pages
+ my instvar package_id item_id
+ $package_id instvar folder_id ;# this is the root folder
+ ::xowiki::Page set recursion_count 0
+
+ set content [my render]
+ my log "--after render"
+
+ if {[$package_id get_parameter "use_user_tracking" 1]} {
+ my record_last_visited
+ }
+
+ my log "--after user_tracking"
+ set references [my references]
+ my log "--after references"
+
+ # export title, text, and lang_links to current scope
+ my instvar title name text lang_links
+
+ set tags ""
+ set no_tags 1
+ if {[$package_id get_parameter "use_tags" 1] &&
+ ![my exists_query_parameter no_tags]} {
+ # only activate tags when the user is logged in
+ set no_tags [expr {[ad_conn user_id] == 0}]
+ set tags ""
+ if {!$no_tags} {
+ ::xowiki::Page requireJS "/resources/xowiki/get-http-object.js"
+ set entries [list]
+ set tags [lsort [::xowiki::Page get_tags -user_id [ad_conn user_id] \
+ -item_id $item_id -package_id $package_id]]
+ set href [site_node::get_url_from_object_id -object_id $package_id]weblog?summary=1
+ foreach tag $tags {lappend entries "$tag"}
+ set tags_with_links [join $entries {, }]
+ }
+ }
+
+ my log "--after tags"
+ set return_url [$package_id url] ;# for the time being
+
+ if {[$package_id get_parameter "use_gc"] &&
+ ![my exists_query_parameter no_gc]} {
+ set gc_link [general_comments_create_link -object_name $title $item_id $return_url]
+ set gc_comments [general_comments_get_comments $item_id $return_url]
+ } else {
+ set gc_link ""
+ set gc_comments ""
+ }
+
+ set header_stuff [::xowiki::Page header_stuff]
+ set master [my query_parameter "master" 1]
+ if {[my exists_query_parameter "edit_return_url"]} {
+ set return_url [my query_parameter "edit_return_url"]
+ }
+
+ my log "--after gc title=$title"
+ if {$master} {
+ set context [list $title]
+ set object_type [my info class]
+ set rev_link [my make_link [self] revisions]
+ set edit_link [my make_link [self] edit return_url]
+ set delete_link [my make_link [self] delete]
+ set new_link [my make_link $package_id edit-new object_type]
+ set admin_link [my make_link -privilege admin -url admin/ $package_id {} {}]
+ set index_link [my make_link -privilege public -url "" $package_id {} {}]
+ set save_tag_link [my make_link [self] save-tags]
+ set popular_tags_link [my make_link [self] popular-tags]
+
+ my log "--after context delete_link=$delete_link "
+ set template [$folder_id get_payload template]
+
+ if {$template ne ""} {
+ set __including_page $page
+ set template_code [template::adp_compile -string $template]
+ if {[catch {set content [template::adp_eval template_code]} errmsg]} {
+ set content "Error in Page $name: $errmsg #general-comments.Comments#
+
$content"
- } else {
- ns_return 200 text/html $content
- }
- } else {
- # use adp file
- set template_file [$folder_id get_payload template_file]
- if {$template_file ne ""} {template::set_file "[file dir $__adp_stub]/$template_file"}
- }
-} else {
- ns_return 200 text/html $content
- ad_script_abort
-}
Index: openacs-4/packages/xowiki/tcl/link-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/link-procs.tcl,v
diff -u -r1.5 -r1.6
--- openacs-4/packages/xowiki/tcl/link-procs.tcl 27 May 2006 12:05:16 -0000 1.5
+++ openacs-4/packages/xowiki/tcl/link-procs.tcl 26 Jul 2006 22:56:46 -0000 1.6
@@ -29,16 +29,18 @@
Link instproc render {} {
set page [my info parent]
set item_id [my resolve]
+ #my log "--u resolve returns $item_id"
if {$item_id} {
$page lappend references [list $item_id [my type]]
set href [::xowiki::Page pretty_link -package_id [my package_id] -lang [my lang] \
[my stripped_name]]
my render_found $href [my label]
} else {
+ my instvar package_id
$page incr unresolved_references
set object_type [[$page info class] set object_type]
set name [my label]
- set href [export_vars -base [::xowiki::Page url_prefix -package_id [my package_id]]edit {object_type name}]
+ set href [export_vars -base [$package_id package_url] {{edit-new 1} object_type name}]
my render_not_found $href [my label]
}
}
@@ -49,12 +51,15 @@
set package_id [site_node::get_children -node_id $a -package_key xowiki \
-filters [list name $name] -element package_id]
if {$package_id ne ""} {
- set folder_id [::xowiki::Page require_folder -package_id $package_id \
- -name xowiki -store_folder_id false]
- return [list package_id $package_id folder_id $folder_id]
+ my log "--LINK found package_id=$package_id [my isobject ::$package_id]"
+ if {![my isobject ::$package_id]} {
+ my log "--LINK creating package object"
+ ::xowiki::Package create ::$package_id
+ }
+ return $package_id
}
}
- return [list]
+ return 0
}
@@ -65,7 +70,7 @@
Class create ::xowiki::Link::language -superclass ::xowiki::Link
::xowiki::Link::language instproc render {} {
set page [my info parent]
- my instvar lang
+ my instvar lang name package_id
set item_id [my resolve]
if {$item_id} {
set css_class "found"
@@ -74,7 +79,7 @@
set css_class "undefined"
set last_page_id [$page set item_id]
set object_type [[$page info class] set object_type]
- set link [export_vars -base [::xowiki::Page url_prefix]edit {object_type name last_page_id}]
+ set link [export_vars -base [$package_id package_url] {{edit-new 1} object_type name last_page_id}]
}
$page lappend lang_links \
" $item_id"
+
+ if {$item_id == 0} {
+ if {[regexp {^pages/(..)/(.*)$} $path _ lang local_name]} {
+ } elseif {[regexp {^(..)/(.*)$} $path _ lang local_name]} {
+ } elseif {[regexp {^(..):(.*)$} $path _ lang local_name]} {
+ } else {
+ set key queryparm(lang)
+ set lang [expr {[info exists $key] ? [set $key] : \
+ [string range [lang::conn::locale] 0 1]}]
+ set local_name $path
+ }
+ set name ${lang}:$local_name
+ if {[info exists name]} {
+ set item_id [::Generic::CrItem lookup -name $name -parent_id $folder_id]
+ my log "--try $name -> $item_id"
+ }
+ if {$item_id == 0} {
+ set nname [Page normalize_name -package_id [my set id] $name]
+ set item_id [::Generic::CrItem lookup -name $nname -parent_id $folder_id]
+ my log "--try $nname -> $item_id"
+ }
+ }
+ }
+ if {$item_id != 0} {
+ set key queryparm(revision_id)
+ if {[info exists $key]} {set revision_id [set $key]}
+ if {[info exists revision_id]} {
+ set item_id 0
+ } else {
+ set revision_id 0
+ }
+ my log "--instantiate item_id $item_id revision_id $revision_id"
+ set r [::Generic::CrItem instantiate -item_id $item_id -revision_id $revision_id]
+ my log "--instantiate done "
+ $r set package_id [namespace tail [self]]
+ return $r
+ } else {
+ return ""
+ }
+ }
+
+ Package instproc require_folder_object {
+ {-store_folder_id:boolean true}
+ } {
+ my instvar id folder_id
+ # the flag store_folder_id should not be necessary, when the id is
+ # always stored in the package TODO
+
+ if {$folder_id == 0} {
+ set folder_id [::xowiki::Page require_folder -name xowiki -package_id $id]
+ }
+
+ if {![::xotcl::Object isobject ::$folder_id]} {
+ # if we can't get the folder from the cache, create it
+ if {[catch {eval [nsv_get xotcl_object_cache ::$folder_id]}]} {
+ while {1} {
+ set item_id [ns_cache eval xotcl_object_type_cache item_id-of-$folder_id {
+ set myid [CrItem lookup -name ::$folder_id -parent_id $folder_id]
+ if {$myid == 0} break; # don't cache ID
+ return $myid
+ }]
+ break
+ }
+ if {[info exists item_id]} {
+ # we have a valid item_id and get the folder object
+ #my log "--f fetch folder object -object ::$folder_id -item_id $item_id"
+ ::xowiki::Object fetch_object -object ::$folder_id -item_id $item_id
+ } else {
+ # we have no folder object yet. so we create one...
+ ::xowiki::Object create ::$folder_id
+ ::$folder_id set text "# this is the payload of the folder object\n\nset index_page \"\"\n"
+ ::$folder_id set parent_id $folder_id
+ ::$folder_id set name ::$folder_id
+ ::$folder_id set title ::$folder_id
+ ::$folder_id save_new
+ ::$folder_id initialize_loaded_object
+ }
+ }
+
+ #$o proc destroy {} {my log "--f "; next}
+ ::$folder_id set package_id $id
+ uplevel #0 [list ::$folder_id volatile]
+ } else {
+ #my log "--f reuse folder object $folder_id [::Serializer deepSerialize ::$folder_id]"
+ }
+ if {$store_folder_id} {
+ Page set folder_id $folder_id
+ }
+
+ my set folder_id $folder_id
+ }
+
+ Package instproc return_page {-adp -variables -form} {
+ my log "--vars=[self args]"
+ set __vars [list]
+ foreach _var $variables {
+ if {[llength $_var] == 2} {
+ lappend __vars [lindex $_var 0] [uplevel subst [lindex $_var 1]]
+ } else {
+ set localvar local.$_var
+ upvar $_var $localvar
+ if {[info exists $localvar]} {
+ # ignore undefined variables
+ lappend __vars $_var [set $localvar]
+ }
+ }
+ }
+
+ if {[info exists form]} {
+ set level [template::adp_level]
+ foreach f [uplevel #$level info vars ${form}:*] {
+ lappend __vars &$f $f
+ upvar #$level $f $f
+ }
+ }
+ my log "--before adp" ;#$__vars
+ set text [template::adp_include $adp $__vars]
+ my log "--after adp"
+ return $text
+ }
+
+ Package instproc query_parameter {name {default ""}} {
+ [self class] instvar queryparm
+ return [expr {[info exists queryparm($name)] ? $queryparm($name) : $default}]
+ }
+ Package instproc exists_query_parameter {name} {
+ [self class] exists queryparm($name)
+ }
+
+ Package instproc form_parameter {name {default ""}} {
+ [self class] instvar form_parameter
+ if {![info exists form_parameter]} {array set form_parameter [ns_set array [ns_getform]]}
+ return [expr {[info exists form_parameter($name)] ? $form_parameter($name) : $default}]
+ }
+ Package instproc exists_form_parameter {name} {
+ [self class] instvar form_parameter
+ if {![info exists form_parameter]} {array set form_parameter [ns_set array [ns_getform]]}
+ [self class] exists form_parameter($name)
+ }
+
+
+ Package ad_instproc reindex {} {
+ reindex all items of this package
+ } {
+ my instvar folder_id
+ db_foreach get_pages "select page_id from xowiki_page, cr_revisions r, cr_items i \
+ where page_id = r.revision_id and i.item_id = r.item_id and i.parent_id = $folder_id " {
+ search::queue -object_id $page_id -event DELETE
+ search::queue -object_id $page_id -event INSERT
+ }
+ }
+
+ Package instproc rss {} {
+ my instvar id
+ set cmd [list ::xowiki::Page rss -package_id $id]
+ set rss [my query_parameter rss]
+ if {[regexp {[^0-9]*([0-9]+)d} $rss _ days]} {lappend cmd -days $days}
+ eval $cmd
+ }
+
+ Package instproc edit-new {} {
+ my instvar folder_id id
+ set object_type [my query_parameter object_type "::xowiki::Page"]
+ set page [$object_type new -volatile -parent_id $folder_id -package_id $id]
+ set html [$page edit -new true]
+ my log "--e html length [string length $html]"
+ return $html
+ }
+ Package instproc condition {method attr value} {
+ switch $attr {
+ has_class {set result [expr {[my query_parameter object_type ""] eq $value}]}
+ default {set result 0}
+ }
+ my log "--c [self args] returns $result"
+ return $result
+ }
+
+
+ Class Policy
+ Policy instproc defined_methods {class} {
+ set c [self]::$class
+ expr {[my isclass $c] ? [$c array names require_permission] : [list]}
+ }
+ Policy instproc permission_p {object method} {
+ foreach class [concat [$object info class] [[$object info class] info heritage]] {
+ set c [self]::[namespace tail $class]
+ if {![my isclass $c]} continue
+ set key require_permission($method)
+ if {[$c exists $key]} {
+ set permission [$c set $key]
+ if {$permission eq "login" || $permission eq "none"} {
+ return 1
+ }
+ foreach cond_permission $permission {
+ my log "--cond_permission = $cond_permission"
+ switch [llength $cond_permission] {
+ 3 {foreach {condition attribute privilege} $cond_permission break
+ if {[eval $object condition $method $condition]} break
+ }
+ 2 {foreach {attribute privilege} $cond_permission break
+ break
+ }
+ }
+ }
+ my log "--p checking permission::permission_p -object_id [$object set $attribute] -privilege $privilege"
+ return [permission::permission_p -object_id [$object set $attribute] -privilege $privilege]
+ }
+ }
+ return 0
+ }
+
+ Policy instproc check_permissions {object method} {
+ set allowed 0
+ foreach class [concat [$object info class] [[$object info class] info heritage]] {
+ set c [self]::[namespace tail $class]
+ if {![my isclass $c]} continue
+ set key require_permission($method)
+ if {[$c exists $key]} {
+ set permission [$c set $key]
+ puts "checking $permission for $c $key"
+ switch $permission {
+ none {set allowed 1; break}
+ login {auth::require_login; set allowed 1; break}
+ default {
+ foreach cond_permission $permission {
+ my log "--c check $cond_permission"
+ switch [llength $cond_permission] {
+ 3 {foreach {condition attribute privilege} $cond_permission break
+ if {[eval $object condition $method $condition]} break
+ }
+ 2 {foreach {attribute privilege} $cond_permission break
+ break
+ }
+ }
+ }
+ my log "--c require_permission -object_id [$object set $attribute] -privilege $privilege"
+ permission::require_permission -object_id [$object set $attribute] -privilege $privilege
+ set allowed 1
+ break
+ }
+ }
+ }
+ }
+ return $allowed
+ }
+
+
+
+ Policy policy1 -contains {
+
+ Class Package -array set require_permission {
+ reindex {{id admin}}
+ rss none
+ edit-new {{{has_class ::xowiki::Object} id admin} {id create}}
+ }
+
+ Class Page -array set require_permission {
+ view {{package_id read}}
+ revisions {{package_id write}}
+ edit {{package_id write}}
+ make-live-revision {{package_id write}}
+ delete-revision {{package_id admin}}
+ delete {{package_id admin}}
+ save-tags login
+ popular-tags login
+ }
+
+ Class Object -array set require_permission {
+ edit {{package_id admin}}
+ }
+ }
+
+}
Index: openacs-4/packages/xowiki/tcl/xowiki-form-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-form-procs.tcl,v
diff -u -r1.9 -r1.10
--- openacs-4/packages/xowiki/tcl/xowiki-form-procs.tcl 8 Jul 2006 11:52:17 -0000 1.9
+++ openacs-4/packages/xowiki/tcl/xowiki-form-procs.tcl 26 Jul 2006 22:56:46 -0000 1.10
@@ -113,10 +113,10 @@
if {$nls_language eq ""} {set nls_language [lang::conn::locale]}
set name [string range $nls_language 0 1]:$name
}
- set subst_blank_in_name [$folder_id get_payload subst_blank_in_name]
- if {$subst_blank_in_name == 1} {
- regsub -all " " $name "_" name
- }
+ set name [::xowiki::Page normalize_name -package_id [ad_conn package_id] $name]
+
+ #my log "--form vars = [ns_set array [ns_getform] ]"
+ #my log "--form comparing '[ns_set get [ns_getform] __object_name]' w '$name'"
if {[ns_set get [ns_getform] __new_p]
|| [ns_set get [ns_getform] __object_name] ne $name
} {
@@ -164,15 +164,14 @@
WikiForm instproc new_request {} {
my instvar data
- $data set creator [$data get_name [ad_conn user_id]]
- my log "--F setting creator to [$data get_name [ad_conn user_id]]"
+ $data set creator [$data get_user_name [ad_conn user_id]]
next
}
WikiForm instproc edit_request args {
my instvar data
if {[$data set creator] eq ""} {
- $data set creator [$data get_name [ad_conn user_id]]
+ $data set creator [$data get_user_name [ad_conn user_id]]
}
next
}
@@ -274,8 +273,13 @@
set item_id [$data set item_id]
set page_template [ns_set get [ns_getform] page_template]
set f [ns_getform]
- if {[ns_set find $f return_url]} {set return_url [ns_set get $f return_url]}
- my submit_link [export_vars -base edit {folder_id object_type item_id page_template return_url}]
+ if {[$data exists_query_parameter return_url]} {
+ set return_url [$data query_parameter return_url]
+ }
+ #if {[ns_set find $f return_url]} {set return_url [ns_set get $f return_url]}
+ set link [::xowiki::Page pretty_link -package_id [$data set package_id] [$data set name]]
+ #my submit_link [export_vars -base edit {folder_id object_type item_id page_template return_url}]
+ my submit_link [export_vars -base $link {{m edit} page_template return_url item_id}]
my log "-- submit_link = [my submit_link]"
}
@@ -303,12 +307,16 @@
}
PageInstanceEditForm instproc new_data {} {
+ my instvar data
set __vars {folder_id item_id page_template return_url}
- set object_type [[[my set data] info class] object_type]
+ set object_type [[$data info class] object_type]
#my log "-- cl=[[my set data] info class] ot=$object_type $__vars"
foreach __v $__vars {set $__v [ns_queryget $__v]}
set item_id [next]
- my submit_link [export_vars -base edit $__vars]
+
+ set link [::xowiki::Page pretty_link -package_id [$data set package_id] [$data set name]]
+ my submit_link [export_vars -base $link {{m edit} $__vars}]
+ #my submit_link [export_vars -base edit $__vars]
my log "-- submit_link = [my submit_link]"
return $item_id
}
Index: openacs-4/packages/xowiki/tcl/xowiki-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-procs.tcl,v
diff -u -r1.42 -r1.43
--- openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 23 Jun 2006 08:18:23 -0000 1.42
+++ openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 26 Jul 2006 22:56:46 -0000 1.43
@@ -52,10 +52,6 @@
-mime_type text/xotcl \
-form ::xowiki::ObjectForm
- Object instproc save_new {} {
- #my set text [::Serializer deepSerialize [self]]
- next
- }
#
# create reference table and table for user tracking
@@ -222,11 +218,59 @@
where content_type in ('CrWikiPage', 'CrWikiPlainPage', \
'PageInstance', 'PageTemplate','CrNote', 'CrSubNote')" {;}
}
+
+ if {[apm_version_names_compare $from_version_name "0.30"] == -1 &&
+ [apm_version_names_compare $to_version_name "0.30"] > -1} {
+ ns_log notice "-- upgrading to 0.30"
+ # delete orphan cr revisions, created automatically by content_item
+ # new, when e.g. a title is specified....
+ foreach class {::xowiki::Page ::xowiki::PlainPage ::xowiki::Object
+ ::xowiki::PageTemplate ::xowiki::PageInstance} {
+ db_dml delete_orphan_revisions "
+ delete from cr_revisions where revision_id in (
+ select r.revision_id from cr_items i,cr_revisions r
+ where i.content_type = '$class' and r.item_id = i.item_id
+ and not r.revision_id in (select [$class id_column] from [$class table_name]))
+ "
+ db_dml delete_orphan_items "
+ delete from acs_objects where object_type = '$class'
+ and not object_id in (select item_id from cr_items where content_type = '$class')
+ and not object_id in (select [$class id_column] from [$class table_name])
+ "
+ }
+ }
}
+
#
# Page definitions
#
+
+ Page parameter {
+ page_id
+ {revision_id 0}
+ object_type
+ parent_id
+ package_id
+ name
+ title
+ text
+ {folder_id -100}
+ {lang_links ""}
+ {lang en}
+ {render_adp 1}
+ }
+ Page set recursion_count 0
+ Page array set RE {
+ include {([^\\]){{(.+)}}[ \n\r]*}
+ anchor {([^\\])\\\[\\\[([^\]]+)\\\]\\\]}
+ div {()([^\\])>>([^&]*)<<}
+ clean {[\\](\{\{|>>|\[\[)}
+ }
+ #
+ # templating and CSS
+ #
+
Page proc requireCSS name {set ::need_css($name) 1}
Page proc requireJS name {set ::need_js($name) 1}
Page proc header_stuff {} {
@@ -240,22 +284,64 @@
}
return $result
}
+ Page proc quoted_html_content text {
+ list [ad_text_to_html $text] text/html
+ }
+ #
+ # Operations on the whole instance
+ #
+ Class create Folder
- Page ad_proc reindex {-package_id} {
- reindex all items of a package
+
+ Page ad_proc select_query {
+ {-select_attributes ""}
+ {-order_clause ""}
+ {-where_clause ""}
+ {-count:boolean false}
+ {-folder_id}
+ {-page_size 20}
+ {-page_number ""}
+ {-extra_where_clause ""}
+ {-extra_from_clause ""}
} {
- if {![info exists package_id]} {set package_id [ad_conn package_id]}
- set folder_id [::xowiki::Page require_folder \
- -package_id $package_id \
- -name xowiki]
- db_foreach get_pages "select page_id from xowiki_page" {
- search::queue -object_id $page_id -event DELETE
- search::queue -object_id $page_id -event INSERT
+ returns the SQL-query to select the xowiki pages of the specified folder
+ @select_attributes attributes for the sql query to be retrieved, in addion
+ to ci.item_id acs_objects.object_type, which are always returned
+ @param order_clause clause for ordering the solution set
+ @param where_clause clause for restricting the answer set
+ @param count return the query for counting the solutions
+ @param folder_id parent_id
+ @return sql query
+ } {
+ my instvar object_type_key
+ if {![info exists folder_id]} {my instvar folder_id}
+
+ set attributes [list ci.item_id ci.name p.page_id]
+ foreach a $select_attributes {
+ if {$a eq "title"} {set a p.title}
+ lappend attributes $a
}
+ if {$count} {
+ set attribute_selection "count(*)"
+ set order_clause "" ;# no need to order when we count
+ set page_number "" ;# no pagination when count is used
+ } else {
+ set attribute_selection [join $attributes ,]
+ }
+
+ if {$where_clause ne ""} {set where_clause "and $where_clause "}
+ if {$page_number ne ""} {
+ set pagination "offset [expr {$page_size*($page_number-1)}] limit $page_size"
+ } else {
+ set pagination ""
+ }
+ return "select $attribute_selection from xowiki_pagei p, cr_items ci $extra_from_clause \
+ where ci.parent_id = $folder_id and ci.item_id = p.item_id and \
+ ci.live_revision = p.page_id $where_clause $extra_where_clause $order_clause $pagination"
}
-
+
Page proc rss_head {
-channel_title
-link
@@ -275,14 +361,7 @@
$content"
+ } else {
+ ns_return 200 text/html $content
+ }
+ } else {
+ # use adp file
+ set template_file [my query_parameter "template_file" \
+ [$folder_id get_payload template_file view-default]]
+ if {![regexp {^[./]} $template_file]} {
+ set template_file /packages/xowiki/www/$template_file
+ }
+ set page [self]
+ $package_id return_page -adp $template_file -variables {
+ references name title item_id page context header_stuff return_url
+ content references lang_links
+ rev_link edit_link delete_link new_link admin_link index_link
+ tags no_tags tags_with_links save_tag_link popular_tags_link
+ gc_link gc_comments
+ }
+ }
+ } else {
+ ns_return 200 text/html $content
+ }
+ }
+
+ Page instproc edit {{-new:boolean false}} {
+ my instvar package_id item_id revision_id
+ $package_id instvar folder_id ;# this is the root folder
+
+ #-query {
+ # item_id:integer,optional
+ # name:optional
+ # last_page_id:integer,optional
+ # folder_id:integer,optional
+ # {object_type:optional ::xowiki::Page}
+ # page_template:integer,optional
+ # return_url:optional
+ #}
+
+ # set some default values if they are provided
+ foreach key {name} {
+ if {[$package_id exists_query_parameter $key]} {my set $key [$package_id query_parameter $key]}
+ }
+
+ set object_type [my info class]
+ if {!$new && $object_type eq "::xowiki::Object" && [my set name] eq "::$folder_id"} {
+ # if we edit the folder object, we have to do some extra magic here,
+ # since the folder object has slightly different naming conventions.
+ # ns_log notice "--editing folder object ::$folder_id, FLUSH $page"
+ ns_cache flush xotcl_object_cache [self]
+ ns_cache flush xotcl_object_cache ::$folder_id
+ my move ::$folder_id
+ set page ::$folder_id
+ #ns_log notice "--move page=$page"
+ }
+
+ #
+ # setting up folder id for file selector (use community folder if available)
+ #
+ set fs_folder_id ""
+ if {[info commands dotlrn_fs::get_community_shared_folder] ne ""} {
+ set fs_folder_id [dotlrn_fs::get_community_shared_folder \
+ -community_id [dotlrn_community::get_community_id]]
+ }
+
+ # the following line is like [$package_id url], but works as well with renames of the object
+ set myurl [expr {$new ? [$package_id url] :
+ [Page pretty_link -package_id $package_id [my form_parameter name]]}]
+ if {[my exists_query_parameter "return_url"]} {
+ set submit_link [my query_parameter "return_url" $myurl]
+ set return_url $submit_link
+ } else {
+ set submit_link $myurl
+ }
+ my log "--u sumit_link=$submit_link qp=[my query_parameter return_url]"
+
+ # we have to do template mangling here; ad_form_template writes form variables into the
+ # actual parselevel, so we have to be in our own level in order to access an pass these
+ variable ::template::parse_level
+ lappend parse_level [info level]
+ set action_vars [expr {$new ? "{edit-new 1} object_type return_url" : "{m edit} return_url"}]
+ [$object_type getFormClass -data [self]] create ::xowiki::f1 -volatile \
+ -action [export_vars -base [$package_id url] $action_vars] \
+ -data [self] \
+ -folderspec [expr {$fs_folder_id ne "" ?"folder_id $fs_folder_id":""}] \
+ -submit_link $submit_link
+
+ if {[info exists return_url]} {
+ ::xowiki::f1 generate -export [list [list return_url $return_url]]
+ } else {
+ ::xowiki::f1 generate
+ }
+ ::xowiki::f1 instvar edit_form_page_title context formTemplate
+
+ if {[info exists item_id]} {
+ set rev_link [my make_link [self] revisions]
+ set view_link [my make_link [self] view]
+ }
+ if {[info exists last_page_id]} {
+ set back_link [$package_id url]
+ }
+
+ set index_link [my make_link -privilege public -url "" $package_id {} {}]
+ set html [$package_id return_page -adp /packages/xowiki/www/edit \
+ -form f1 \
+ -variables {item_id edit_form_page_title context formTemplate
+ view_link back_link rev_link index_link}]
+ template::util::lpop parse_level
+ my log "--e html length [string length $html]"
+ return $html
+ }
+
+
+
+ Page instproc revisions {} {
+ my instvar package_id name item_id
+ set context [list [list [$package_id url] $name ] [_ xotcl-core.revisions]]
+ set title "[_ xotcl-core.revision_title] '$name'"
+ set content [next]
+ $package_id return_page -adp /packages/xowiki/www/revisions -variables {
+ content context {page_id $item_id} title
+ }
+ }
+
+
+ Page instproc make-live-revision {} {
+ my instvar revision_id item_id package_id
+ my log "--M set_live_revision($revision_id)"
+ db_exec_plsql make_live {select content_item__set_live_revision(:revision_id)}
+ set page_id [my query_parameter "page_id"]
+ ns_cache flush xotcl_object_cache ::$item_id
+ ad_returnredirect [my query_parameter "return_url" \
+ [export_vars -base [$package_id url] {{m revisions}}]]
+ }
+
+
+ Page instproc delete-revision {} {
+ my instvar revision_id package_id item_id
+ my log "--M delete revision($revision_id)"
+ db_exec_plsql delete_revision {select content_revision__del(:revision_id)}
+ ns_cache flush xotcl_object_cache ::$item_id
+ ns_cache flush xotcl_object_cache ::$revision_id
+ ad_returnredirect [my query_parameter "return_url" \
+ [export_vars -base [$package_id url] {{m revisions}}]]
+ }
+
+ Page instproc delete {} {
+ my instvar package_id item_id name parent_id
+ my log "--D trying to delete $item_id"
+ ::Generic::CrItem delete -item_id $item_id
+ ns_cache flush xotcl_object_cache ::$item_id
+ # we should probably flush as well cached revisions
+ if {$name eq "::$parent_id"} {
+ my log "--D deleting folder object ::$parent_id"
+ ns_cache flush xotcl_object_cache ::$parent_id
+ ns_cache flush xotcl_object_type_cache item_id-of-$parent_id
+ ::$parent_id destroy
+ }
+ ad_returnredirect [my query_parameter "return_url" [$package_id package_url]]
+ }
+
+ Page instproc save-tags {} {
+ my instvar package_id item_id
+ ::xowiki::Page save_tags -user_id [ad_conn user_id] -item_id $item_id \
+ -package_id $package_id [my form_parameter tags]
+ ad_returnredirect [my query_parameter "return_url" [$package_id url]]
+ }
+
+ Page instproc popular-tags {} {
+ my instvar package_id item_id parent_id
+ set limit [my query_parameter "limit" 20]
+ set href [$package_id package_url]weblog?summary=1
+ set entries [list]
+ db_foreach get_popular_tags \
+ "select count(*) as nr,tag from xowiki_tags \
+ where item_id=$item_id group by tag order by nr limit $limit" {
+ lappend entries "$tag ($nr)"
+ }
+ ns_return 200 text/html "[_ xowiki.popular_tags_label]: [join $entries {, }]"
+ }
+}
\ No newline at end of file
Index: openacs-4/packages/xowiki/www/edit.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/Attic/edit.adp,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/xowiki/www/edit.adp 9 Feb 2006 22:53:03 -0000 1.2
+++ openacs-4/packages/xowiki/www/edit.adp 26 Jul 2006 22:56:46 -0000 1.3
@@ -12,14 +12,12 @@
#xowiki.references_label# @references;noquote@
+@lang_links;noquote@
+
+
+@gc_comments;noquote@
@gc_link;noquote@
+>>content<<
-
{{adp portlets/weblog {name Weblog}}}
-
>><<
-
>>sidebar<<
-
{{adp portlets/weblog-mini-calendar}}
-
{{adp portlets/categories {count 1 skin plain-include}}}
-
{{adp portlets/tags {skin plain-include}}}
-
>><<
-