From: <de...@de...> - 2007-02-06 19:11:25
|
Author: DanielRohde Date: 2007-02-06 13:10:35 -0600 (Tue, 06 Feb 2007) New Revision: 12787 Modified: twiki/branches/MAIN/twikiplugins/ChecklistPlugin/data/TWiki/ChecklistPlugin.txt twiki/branches/MAIN/twikiplugins/ChecklistPlugin/lib/TWiki/Plugins/ChecklistPlugin.pm Log: Item3553: last try to fix mod_perl bugs; fixed CHECKLISTSTART/END bug; Modified: twiki/branches/MAIN/twikiplugins/ChecklistPlugin/data/TWiki/ChecklistPlugin.txt =================================================================== --- twiki/branches/MAIN/twikiplugins/ChecklistPlugin/data/TWiki/ChecklistPlugin.txt 2007-02-06 11:04:18 UTC (rev 12786) +++ twiki/branches/MAIN/twikiplugins/ChecklistPlugin/data/TWiki/ChecklistPlugin.txt 2007-02-06 19:10:35 UTC (rev 12787) @@ -1,4 +1,4 @@ -%META:TOPICINFO{author="TWikiContributor" date="1170757195" format="1.0" version="$Rev$"}% +%META:TOPICINFO{author="TWikiContributor" date="1170768159" format="1.0" version="$Rev$"}% ---+!! Checklist Plugin <nop>ChecklistPlugin creates simple checklists. @@ -28,7 +28,10 @@ All tags can be used with attributes documented in the [[#ChecklistAttributes][Attributes section]]. -To create a link to the checklist item state topic you can put the following forced link on your checklist topic: <verbatim>[<nop>[%<nop>TOPIC%ChecklistItemState]]</verbatim>. +To create a link to the checklist item state topic you can put the following forced link on your checklist topic: +<verbatim> + [[%TOPIC%ChecklistItemState]] +</verbatim> If you have installed the TWiki:Plugins.SpreadSheetPlugin you can find a statistics on this item state topic. And if you have installed the TWiki:Plugins.EditTablePlugin you can edit the states directly on this topic. @@ -177,7 +180,7 @@ </td> </tr> -<tr><td colspan="2" bgcolor="#CCCCCC"> *Example 8: Create a button to set all states in a checklist to =done=* +<tr><td colspan="2" bgcolor="#CCCCCC"> *Example 8: Create a button to set all states in a checklist to =done=:* * the reset button was clicked * *Hint:* You can use multiple =%<nop>CHECKLIST%= tags to create more than one reset button. </td></tr> @@ -199,7 +202,7 @@ </td> </tr> -<tr><td colspan="2" bgcolor="#CCCCCC"> *Example 9: Insert new items in an existing checklist without state lost.* +<tr><td colspan="2" bgcolor="#CCCCCC"> *Example 9: Insert new items in an existing checklist without state lost:* * =first step= and =second step= was clicked before new items (=first new inserted item= and =second new inserted item=) were added * *Hint:* You can put a =#<ID>= instead of =%<nop>CLI{id="<ID>"}%= into a bullet or ordered list item to add/insert a checklist item with own id. This works only between =%<nop>CHECKLISTSTART%...%<nop>CHECKLISTEND%=. </td></tr> @@ -238,9 +241,9 @@ </verbatim> | *Attribute* | *Usable in Tag(s)* | *Comment* | *Example* | -| anchors | %<nop>CLI%<br/>%<nop>CHECKLIST%<br/>%<nop>CHECKLISTSTART% | enables/disables link anchors (default: =yes=); if enabled a state change will scroll your topic to the clicked checklist item; useful for long checklists | =anchors="yes"= | +| anchors | %<nop>CLI%<br/>%<nop>CHECKLIST%<br/>%<nop>CHECKLISTSTART% | enables/disables link anchors (default: =yes=); if enabled a state change will scroll your topic to the clicked checklist item; useful for long checklists (useless if =useajax= is =on=) | =anchors="yes"= | | clipos | %<nop>CLI%<br/>%<nop>CHECKLISTSTART% | determines the position of the checklist item icon (default: =right=); if you use another value than ="left"= the checklist item icon will be appended to a ordered or bullet list item | =clipos="left"= | -| descr | %<nop>CLI% | a description for a checklist item used in the =[<nop>[%<nop>TOPIC%ChecklistItemState]]= topic; you can use it as a default option (without =descr==), e.g: =%<nop>CLI{"my description"}%= | =descr=""= | +| descr | %<nop>CLI% | a description for a checklist item used in the =[<nop>[%<nop>TOPIC%ChecklistItemState]]= topic; you can use it as a default option (without =descr=), e.g: =%<nop>CLI{"my description"}%= | =descr=""= | | descrcharlimit | %<nop>CLI%<br/>%<nop>CHECKLIST%<br/>%<nop>CHECKLISTSTART% | character limit for a description (useful if no description was given and therefore it is stripped from the text before and after a checklist item) | =descrcharlimit="100"= | | id | %<nop>CLI% | unique id of a checklist item (default: autogenerated); useful and recommended if you insert new checklist items in an existing checklist with states | =id="myfirstownid"= | | name | %<nop>CLI%<br/>%<nop>CHECKLIST%<br/>%<nop>CHECKLISTSTART% | a naming context (default: =_default=) - useful and recommended if you define more than one checklist on a topic (%X% if you use it in =%<nop>CHECKLIST%= you must use it in all related =%<nop>CLI%= tags too) | =name="mychecklist1"= | Modified: twiki/branches/MAIN/twikiplugins/ChecklistPlugin/lib/TWiki/Plugins/ChecklistPlugin.pm =================================================================== --- twiki/branches/MAIN/twikiplugins/ChecklistPlugin/lib/TWiki/Plugins/ChecklistPlugin.pm 2007-02-06 11:04:18 UTC (rev 12786) +++ twiki/branches/MAIN/twikiplugins/ChecklistPlugin/lib/TWiki/Plugins/ChecklistPlugin.pm 2007-02-06 19:10:35 UTC (rev 12787) @@ -55,18 +55,18 @@ # ========================= use vars qw( - $web $topic $user $installWeb $VERSION $RELEASE $REVISION $pluginName + $installWeb $VERSION $RELEASE $REVISION $pluginName $debug %TWikiCompatibility - $defaultsInitialized %globalDefaults @renderedOptions @flagOptions @filteredOptions @listOptions - %options @unknownParams $name + %options @unknownParams %namedDefaults %namedIds $idMapRef $idOrderRef %namedResetIds %itemStatesRead $resetDone $stateChangeDone $saveDone - $initText + $initText %itemsCollected + $web $topic $user ); use strict; -###use warnings; +####use warnings; $TWikiCompatibility{endRenderingHandler} = 1.1; @@ -123,7 +123,7 @@ # XXX ####$debug = 1; - $defaultsInitialized = 0; + &initDefaults($web, $topic); # Plugin correctly initialized TWiki::Func::writeDebug( "- TWiki::Plugins::${pluginName}::initPlugin( $web.$topic ) is OK" ) if $debug; @@ -140,25 +140,42 @@ # This is the place to define customized tags and variables # Called by TWiki::handleCommonTags, after %INCLUDE:"..."% - $initText = $_[0]; - ###### we need exceptions since Dakar release therefore eval is bad - ###eval { - local(%options, %namedDefaults, %itemStatesRead, %namedIds, %namedResetIds, @unknownParams, $name); - $_[0] =~ s/<\/head>/<script src="%PUBURL%\/%TWIKIWEB%\/$pluginName\/itemstatechange.js" language="javascript" type="text\/javascript"><\/script><\/head>/is unless ($_[0]=~/itemstatechange.js/); - $_[0] =~ s/%CHECKLISTSTART%(.*?)%CHECKLISTEND%/&handleAutoChecklist("",$1,$_[0])/sge; - $_[0] =~ s/%CHECKLISTSTART{(.*?)}%(.*?)%CHECKLISTEND%/&handleAutoChecklist($1,$2,$_[0])/sge; - $_[0] =~ s/%CHECKLIST%/&handleChecklist("",$_[0])/ge; - $_[0] =~ s/%CHECKLIST{(.*?)}%/&handleChecklist($1,$_[0])/sge; - ##$_[0] =~ s/%CLI%/&handleChecklistItem("",$_[0])/ge; - ##$_[0] =~ s/%CLI{(.*?)}%/&handleChecklistItem($1,$_[0])/sge; - $_[0] =~ s/([^\n\%]*)%CLI({(.*?)})?%([^\n\%]*)/$1.&handleChecklistItem($3,$_[0],$1,$4).$4/sge; - ###}; - ###TWiki::Func::writeWarning("${pluginName}: $@") if $@; + local(%namedDefaults, %itemStatesRead, %namedIds, %namedResetIds, @unknownParams, $initText, $resetDone,$stateChangeDone,$saveDone,$idMapRef,$idOrderRef, %itemsCollected); + + $initText = $_[0] if $_[0] =~ /\%(CLI|CHECKLIST)/; + + $idMapRef = { }; + $idOrderRef = { }; + %namedIds = ( ); + %namedResetIds = ( ); + + $resetDone = 0; + $stateChangeDone = 0; + $saveDone = 0; + + %namedDefaults = ( ); + %itemStatesRead = ( ); + %itemsCollected = ( ); + + + $_[0] =~ s/<\/head>/<script src="%PUBURL%\/%TWIKIWEB%\/$pluginName\/itemstatechange.js" language="javascript" type="text\/javascript"><\/script><\/head>/is unless ($_[0]=~/itemstatechange.js/); + &handleAllTags(@_); } +# ========================= +sub handleAllTags { + ### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead + $_[0] =~ s/%CHECKLISTSTART%(.*?)%CHECKLISTEND%/&handleAutoChecklist("",$1,$_[0])/sge; + $_[0] =~ s/%CHECKLISTSTART{(.*?)}%(.*?)%CHECKLISTEND%/&handleAutoChecklist($1,$2,$_[0])/sge; + $_[0] =~ s/%CHECKLIST%/&handleChecklist("",$_[0])/ge; + $_[0] =~ s/%CHECKLIST{(.*?)}%/&handleChecklist($1,$_[0])/sge; + $_[0] =~ s/([^\n\%]*)%CLI({(.*?)})?%([^\n\%]*)/$1.&handleChecklistItem($3,$_[0],$1,$4).$4/sge; +} + # ========================= -sub initDefaults() { +sub initDefaults { + my ($web, $topic) = @_; TWiki::Func::writeDebug("- ${pluginName}::initDefaults") if $debug; my $pubUrlPath = TWiki::Func::getPubUrlPath(); @@ -196,27 +213,7 @@ @flagOptions = ('showlegend', 'anchors', 'useforms', 'notify', 'static' , 'useajax', 'statesel'); - $idMapRef = { }; - - $idOrderRef = { }; - %namedIds = ( ); - - %namedResetIds = ( ); - - $resetDone = 0; - $stateChangeDone = 0; - $saveDone = 0; - - $defaultsInitialized = 1; - - %namedDefaults = ( ); - - %itemStatesRead = ( ); - - my $query = TWiki::Func::getCgiQuery(); - &collectAllChecklistItems() if (defined $query->param('clreset')) || (defined $query->param('clpsc')); - } # ========================= @@ -233,10 +230,7 @@ } return 0 if $#unknownParams != -1; - my $name; - - $name=&substIllegalChars($params{'name'}) if defined $params{'name'}; - $name=$globalDefaults{'name'} unless defined $name; + my $name = &getName(\%params); # handle _DEFAULT option (_DEFAULT = descr) $params{'descr'} = $params{'_DEFAULT'} if defined $params{'_DEFAULT'}; @@ -250,13 +244,13 @@ %options = ( ); foreach my $option (@allOptions) { my $v = $params{$option}; + $v = $namedDefaults{$name}{$option} unless defined $v; if ((defined $tmplName)&&(!defined $v)) { $v = (&TWiki::Func::getPreferencesFlag("\U${pluginName}_TEMPLATE_${tmplName}_${option}\E") || undef) if grep /^\Q$option\E$/, @flagOptions; $v = (&TWiki::Func::getPreferencesValue("\U${pluginName}_TEMPLATE_${tmplName}_${option}\E") || undef) unless defined $v; $v = undef if (defined $v) && ($v eq ""); } - $v = $namedDefaults{$name}{$option} unless defined $v; if (defined $v) { if (grep /^\Q$option\E$/, @flagOptions) { $options{$option} = ($v!~/(false|no|off|0|disable)/i); @@ -311,11 +305,6 @@ } - # read item states: - if (! $itemStatesRead{$name}) { - &readChecklistItemStateTopic($idMapRef); - $itemStatesRead{$name} = 1; - } return 1; } @@ -325,14 +314,29 @@ my %params = TWiki::Func::extractParameters($attributes); - $name = &substIllegalChars($params{'name'}) if defined $params{'name'}; - $name = $globalDefaults{'name'} unless defined $name; + my $name = &getName(\%params); + my $tmplName = (defined $params{'template'}?$params{'template'}:undef); + $tmplName = ( &TWiki::Func::getPreferencesValue("\U${pluginName}_TEMPLATE\E") || undef) unless defined $tmplName; # create named defaults (attributes>named defaults>global defaults): foreach my $default (keys %globalDefaults) { - $namedDefaults{$name}{$default}= $params{$default} if defined $params{$default}; + $namedDefaults{$name}{$default}= $params{$default} if defined $params{$default}; + $namedDefaults{$name}{$default}= (&TWiki::Func::getPreferencesValue("\U${pluginName}_TEMPLATE_${tmplName}_${default}\E") || undef) unless (!defined $tmplName) || (defined $params{$default}); + } } +sub initStates { + my ($query) = @_; + if ((!defined $itemsCollected{"$web.$topic"}) &&((defined $query->param('clpsc'))||(defined $query->param('clreset')))) { + $itemsCollected{"$web.$topic"}=1; + &collectAllChecklistItems() ; + } + # read item states: + if (! $itemStatesRead{$options{'name'}}) { + $itemStatesRead{$options{'name'}} = 1; + &readChecklistItemStateTopic($idMapRef); + } +} # ========================= sub renderLegend { my $query = &TWiki::Func::getCgiQuery(); @@ -357,20 +361,23 @@ TWiki::Func::writeDebug("- ${pluginName}::handleChecklist($attributes,...refText...)") if $debug; - my $query = &TWiki::Func::getCgiQuery(); - my $text=""; - &initDefaults() unless $defaultsInitialized; - &initNamedDefaults($attributes); + local(%options); return &createUnknownParamsMessage() unless &initOptions($attributes); + my $query = &TWiki::Func::getCgiQuery(); + my %params = &TWiki::Func::extractParameters($attributes); + my $name = &getName(\%params); + my @states = split /\|/, $options{'states'}; my @icons = split /\|/, $options{'stateicons'}; + if ((defined $query->param('clreset'))&&(!$resetDone)) { + &initStates($query); my $n=$query->param('clreset'); my $s=(defined $query->param('clresetst'))?$query->param('clresetst'):$states[0]; if (($options{'name'} eq $n)&&(grep(/^\Q$s\E$/s, @states))) { @@ -443,7 +450,6 @@ $action=~s/#.*$//s; $action.=&getUniqueUrlParam($action); - if ( ! $options{'useforms'} ) { $action.=($action=~/\?/?';':'?'); $action.="clreset=".&urlEncode($name); @@ -492,7 +498,7 @@ # ========================= sub substItemLine { my ($l,$attribs)=@_; - if ($l=~s/(\#\S+)//) { + if ($l=~s/\#(\S+)//) { $attribs.=" id=\"$1\""; } if ($l=~/\%CLI{.*?}\%/) { @@ -513,14 +519,12 @@ TWiki::Func::writeDebug("- ${pluginName}::handleAutoChecklist($attributes,...text...)") if $debug; - &initDefaults() unless $defaultsInitialized; - - &initNamedDefaults($attributes); - + local(%options); return &createUnknownParamsMessage() unless &initOptions($attributes); $text=~s/\%CLI(\{([^\}]*)\})?\%/&substAttributes($attributes, $2)/meg; $text=~s/^(\s+[\d\*]+.*?)$/&substItemLine($1,$attributes)/meg; + $text=~s/([^\n]+?)\#(\S+)/$1.&substAttributes($attributes, "id=\"$2\"")/meg; if (lc($options{'pos'}) eq 'top' ) { $text="\%CHECKLIST{$attributes}\%\n$text"; @@ -537,16 +541,17 @@ TWiki::Func::writeDebug("- ${pluginName}::handleChecklistItem($attributes)") if $debug; - &initDefaults() unless $defaultsInitialized; - + local(%options); return &createUnknownParamsMessage() unless &initOptions($attributes); + my $query = &TWiki::Func::getCgiQuery(); + + &initStates($query); + $namedIds{$options{'name'}}++ unless defined $options{'id'}; &handleDescription($textBefore, $textAfter); - my $query = &TWiki::Func::getCgiQuery(); - if ((defined $query->param('clpsc'))&&(!$stateChangeDone)) { my ($id,$name,$lastState,$nextstate) = ($query->param('clpsc'),$query->param('clpscn'),$query->param('clpscls'),$query->param('clpscns')); if ($options{'name'} eq $name) { @@ -562,7 +567,6 @@ # ========================= sub handleDescription { my ($textBefore, $textAfter) = @_; - ### TWiki::Func::writeWarning("textBefore='$textBefore', textAfter='$textAfter'"); my $descr = $$idMapRef{$options{'name'}}{$options{'id'}?$options{'id'}:$namedIds{$options{'name'}}}{'descr'}; unless ( (defined $options{'descr'}) || ((defined $descr)&&($descr!~/^\s*$/))) { $options{'descr'}=$options{'text'} if (defined $options{'text'})&&($options{'text'}!~/^\s*$/s); @@ -787,8 +791,8 @@ my $title = &createTitle($name, $state, $icon, \@states); $linktext.=qq@$textBef@ if $textBef; - - $linktext.=$query->img({id=>"CLP_IMG_$name$uetId", -src=>$iconsrc, -border=>0, -alt=>""}); + my $imgtitle = $options{'static'}?$title:""; + $linktext.=$query->img({id=>"CLP_IMG_$name$uetId", -src=>$iconsrc, -border=>0, -title=>$imgtitle, -alt=>$imgtitle}); $linktext.=qq@$textAft@ if $textAft; if (lc($options{'clipos'}) eq 'left') { $linktext.=' '.$options{'text'} unless $options{'text'} =~ /^(\s|\ \;)*$/; @@ -869,7 +873,7 @@ # ========================= sub urlEncode { my ($txt)=@_; - $txt=~s/([^A-Za-z0-9\$\-\_\.\+\!\*\'\(\)\,])/sprintf("%%%02X", ord($1))/seg; + $txt=~s/([^A-Za-z0-9\$\-\_\.\+\!\*\'\(\)\,])/sprintf("%%%02X", ord($1))/seg if defined $txt; return $txt; } # ========================= @@ -925,9 +929,16 @@ # ========================= sub getClisTopicName { my ($name) = @_; - return $namedDefaults{$name}{'statetopic'}?$namedDefaults{$name}{'statetopic'}:$globalDefaults{'statetopic'}; + return $namedDefaults{$name}{'statetopic'}?$namedDefaults{$name}{'statetopic'}:$globalDefaults{'statetopic'}; } # ========================= +sub getName { + my($paramsRef) = @_; + my $name=&substIllegalChars($$paramsRef{'name'}) if defined $$paramsRef{'name'}; + $name=$globalDefaults{'name'} unless defined $name; + return $name; +} +# ========================= sub saveChecklistItemStateTopic { my ($name,$perm) = @_; return if $name eq ""; @@ -939,6 +950,7 @@ &TWiki::Func::redirectCgiQuery(TWiki::Func::getCgiQuery(), $oopsUrl); return; } + my $installWeb = &TWiki::Func::getTwikiWebname(); my $topicText = ""; $topicText.="%RED% WARNING! THIS TOPIC IS GENERATED BY $installWeb.$pluginName PLUGIN. DO NOT EDIT THIS TOPIC (except table data)!%ENDCOLOR%\n"; $topicText.=qq@%BR%Back to the \[\[$web.$topic\]\[checklist topic $topic\]\].\n\n@; @@ -957,7 +969,9 @@ $topicText.="|*context*|*id*|*state*|*description*|\n"; ###foreach my $id (sort keys %{ $$idMapRef{$n}}) { - foreach my $id (@{ $$idOrderRef{$n}}) { + ###foreach my $id (@{ $$idOrderRef{$n}}) { + my @arr = $#{$$idOrderRef{$n}}!=-1 ? @{$$idOrderRef{$n}} : sort(keys(%{$$idMapRef{$n}})); + foreach my $id (@arr) { $topicText.="|$n|".&htmlEncode($id)."|".&htmlEncode($$idMapRef{$n}{$id}{'state'})."| ".&htmlEncode($$idMapRef{$n}{$id}{'descr'})." |\n"; } $topicText.=qq@| *$n* | *statistics:* | *%CALC{"\$COUNTITEMS(R2:C\$COLUMN()..R\$ROW(-1):C\$COLUMN())"}%* | *entries: %CALC{"\$ROW(-2)"}%* |\n@; @@ -982,21 +996,17 @@ } # ========================= sub collectAllChecklistItems { - local(%namedIds,$resetDone,$stateChangeDone, %options, %namedDefaults); + ## never ever local($initText, $idMapRef, $idOrderRef, %itemsCollected, %itemStatesRead, $web, $topic) + local(%namedDefaults, %namedIds, %namedResetIds, @unknownParams, $resetDone,$stateChangeDone,$saveDone ); TWiki::Func::writeDebug( "- ${pluginName}::collectAllChecklistItems()" ) if $debug; - ####my ($text) = &TWiki::Func::readTopicText($web, $topic); - ####return if ($text =~ /^http.*?\/oops/); my $text = $initText; - # remove verbatim/pre blocks: - ####$text=~s/<(verbatim|pre)[^>]*>.*?<\/\1[^>]*>//isg; - # prevent changes: $resetDone=1; $stateChangeDone=1; - &commonTagsHandler($text, $topic, $web); + &handleAllTags($text, $topic, $web); TWiki::Func::writeDebug( "- ${pluginName}::collectAllChecklistItems() done!" ) if $debug; } |