The following are examples of using the TclPlugin. To shorten the examples [{TclPlugin...}] is used where [{com.ingenta.jspwiki.plugin.TclPlugin ...}] is correct.
Incorporating one wiki page inside another#
[{TclPlugin script='wiki::page get MyPage' result='wiki' }]
A list of project pages#
Use the following script to place a table of "project" pages into another page. A project page is just a page with a given prefix: For example, "TclPlugin" is a prefix for page about the TclPlugin.
[{TclPlugin scriptPage='ProjectPagesScript' prefix='TclPlugin' result='wiki' }]
Place the following in the ProjectPagesScript wiki page
set projectPages [list] foreach page [wiki::info pages] { if { [string first $args(prefix) [lindex $page 0]] == 0 } { lappend projectPages $page } } set result "|| Page || Author || Last modified \n" set c [string length $args(prefix)] foreach page $projectPages { append result "| \[[string range [lindex $page 0] $c end]|[lindex $page 0]\]" append result "| \[[lindex $page 1]\]" append result "| [clock format [lindex $page 3] -format {%e %B %Y}]" append result "\n" } return $result
Note that this script is similar to the existing IndexPlugin.
Late milestones#
If you keep project milestones in a wiki table, for example,
1 June 2004 | 10% | milestone aa |
1 Aug 2004 | 10% | milestone a |
4 Aug 2004 | done | milestone b |
3 Aug 2004 | 10% | milestone c |
8 Aug 2004 | 10% | milestone d |
12 Aug 2004 | 10% | milestone d |
12 Aug 2004 | 10% | milestone dd |
13 Aug 2004 | 10% | milestone e |
14 Aug 2004 | 10% | milestone g |
21 Aug 2004 | 10% | milestone f |
23 Aug 2004 | 10% | milestone f |
15 September 2004 | 10% | milestone h |
15 September 2004 | 10% | milestone i |
the following script will show late milestones
Due | Days late | Description |
---|---|---|
1 June 2004 | -78 | milestone aa |
1 August 2004 | -17 | milestone a |
3 August 2004 | -15 | milestone c |
8 August 2004 | -10 | milestone d |
12 August 2004 | -6 | milestone dd |
12 August 2004 | -6 | milestone d |
13 August 2004 | -5 | milestone e |
14 August 2004 | -4 | milestone g |
[{TclPlugin scriptPage='LateMilestonesScript' dataPage='ProjectMilestones' result='wiki' }]
Place the following in the LateMilestonesScript wiki page
# parse milestone data from wiki table set data [wiki::page get $args(dataPage)] foreach line [split $data \n] { set m [split $line |] if {[llength $m] != 4} { continue } lappend milestones [list [clock scan [lindex $m 1]] [string trim [lindex $m 2]] [string trim [lindex $m 3]] ] } # order milestones by date proc compareDate { a b } { expr [lindex $a 0] - [lindex $b 0] } set milestones [lsort -command compareDate $milestones] # gather late milestones set today [clock scan "today 0"] set late [list] foreach milestone $milestones { if { [lindex $milestone 0] < $today && [lindex $milestone 1] != "done" } { lappend late $milestone } } # output late milestone presentation set yearday [clock format $today -format %j] set result "|| Due || Days late || Description \n" foreach milestone $late { append result | append result [clock format [lindex $milestone 0] -format "%e %B %Y"] append result | append result [expr [clock format [lindex $milestone 0] -format %j] - $yearday] append result | append result [lindex $milestone 2] append result \n } return $html
Note that there is a flaw in this script in that it does not handle projects that span mulitple years. The root of the flaw is the yearday handling.
Calendar of last week's and this week's events#
Outputs a calendar of recient and forthcoming events from a list of events in the body of the plugin. For example,
[{TclPlugin result='wiki' scriptPage='EventCalendarScript' | 12 Aug 2004 | Event A | 14 Aug 2004 | Event B | 16 Aug 2004 | Event C | 21 Aug 2004 | Event D | 21 Aug 2004 | Event E | 22 Aug 2004 | Event F | 23 Aug 2004 | Event G | 01 Sep 2004 | Event X | 02 Sep 2004 | Event Y }]
outputs
Sun 15 Aug | Mon 16 Aug | Tue 17 Aug | Wed 18 Aug | Thu 19 Aug | Fri 20 Aug | Sat 21 Aug |
---|---|---|---|---|---|---|
Event C | Event D Event E | |||||
Sun 22 Aug | Mon 23 Aug | Tue 24 Aug | Wed 25 Aug | Thu 26 Aug | Fri 27 Aug | Sat 28 Aug |
Event F | Event G |
Save the following in the page EventCalendarScript
# get the wiki data set data $args(_body) # create list of dates between sundays set dates [list] set sunday [clock scan "sunday 0"] foreach offset { -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 } { set date [clock scan "$offset day" -base $sunday ] lappend dates $date set datetoevents($date) [list] } # scan and records the events in the wiki data # where the date is in the first table cell # and the even is in the second foreach line [split $data \n\r] { if { [string first $line |] } { set e [split $line |] set date [lindex $e 1] # get the date at 12am. set date [clock scan [clock format [clock scan $date] -format "%e %b %Y 0"]] set event [lindex $e 2] if [info exists datetoevents($date)] { lappend datetoevents($date) $event } } } # format a wiki table of the calendar set wiki "" set head "" set body "" set day 1 foreach date $dates { # header for date append head "|| " append head [clock format $date -format {%a %e %b}] # events for date append body "| " foreach event $datetoevents($date) { append body $event } # end of the week? incr day if { $day == 8 || $day == 15 } { append wiki $head \n $body \n set head "" set body "" } } return $wiki
List the authors of the page#
The AuthorsPlugin wants a list of the authors that edited the page. An edit is a count of non-consecutive changes except were the changes are more than an hour apart. The following script will output such information for the current page
set versions [wiki::page versions current] proc cmptimes { a b } { expr [lindex $a 3] - [lindex $b 3] } proc cmpcounts { a b } { global counts expr $counts($a) - $counts($b) } set onehour [expr 60 * 60] set previousauthor "" set previousmodified 0 foreach version [lsort -command cmptimes $versions] { set author [lindex $version 1] set modified [lindex $version 3] # skip IP address authored versions if { [regexp {[0-9]+\.[0-9]+.[0-9]+\.[0-9]+} $author] } { continue } if { ! [info exists counts($author)] } { set counts($author) 0 } if { $author != $previousauthor } { incr counts($author) set previousmodified $modified set previousauthor $author } else { if { $previousmodified + $onehour <= $modified } { incr counts($author) set previousmodified $modified } } } append wiki "|| Author || Edits\n" foreach author [lsort -decreasing -command cmpcounts [array names counts]] { append wiki "| $author | $counts($author)\n" } return $wiki