\n$||o; # clean up hack that handles EDITACTIONTRACKER correctly if at end
my $error = &TWiki::Func::saveTopicText( $theWeb, $theTopic, $result, "", $quiet );
TWiki::Func::setTopicEditLock( $theWeb, $theTopic, 0 ); # unlock Topic
my $url = &TWiki::Func::getViewUrl( $theWeb, $theTopic );
if( $error ) {
$url = &TWiki::Func::getOopsUrl( $theWeb, $theTopic, "oopssaveerr", $error );
}
&TWiki::Func::redirectCgiQuery( $query, $url );
}
# =========================
sub doCancelEdit
{
my ( $theWeb, $theTopic ) = @_;
&TWiki::Func::writeDebug( "- EditActionTrackerPlugin::doCancelEdit( $theWeb, $theTopic )" ) if $debug;
TWiki::Func::setTopicEditLock( $theWeb, $theTopic, 0 );
&TWiki::Func::redirectCgiQuery( $query, &TWiki::Func::getViewUrl( $theWeb, $theTopic ) );
}
# =========================
sub doEnableEdit
{
my ( $theWeb, $theTopic, $doCheckIfLocked ) = @_;
&TWiki::Func::writeDebug( "- EditActionTrackerPlugin::doEnableEdit( $theWeb, $theTopic )" ) if $debug;
my $wikiUserName = &TWiki::Func::getWikiUserName();
if( ! &TWiki::Func::checkAccessPermission( "change", $wikiUserName, "", $theTopic, $theWeb ) ) {
# user has not permission to change the topic
my $url = &TWiki::Func::getOopsUrl( $theWeb, $theTopic, "oopsaccesschange" );
&TWiki::Func::redirectCgiQuery( $query, $url );
return 0;
}
my( $oopsUrl, $lockUser ) = &TWiki::Func::checkTopicEditLock( $theWeb, $theTopic );
if( ( $doCheckIfLocked ) && ( $lockUser ) ) {
# warn user that other person is editing this topic
&TWiki::Func::redirectCgiQuery( $query, $oopsUrl );
return 0;
}
TWiki::Func::setTopicEditLock( $theWeb, $theTopic, 1 );
return 1;
}
# =========================
# The following code is copied from the ChartPlugin Table object.
package TWiki::Plugins::Table;
sub new
{
my ($class, $topicContents) = @_;
my $this = {};
bless $this, $class;
$this->_parseOutTables($topicContents);
return $this;
}
# The guts of this routine was initially copied from SpreadSheetPlugin.pm
# and were used in the ChartPlugin Table object which this was copied from,
# but this has been modified to support the functionality needed by the
# EditActionTrackerPlugin. One major change is to only count and save tables
# following an %EDITACTIONTRACKER{.*}% tag.
#
# This routine basically returns an array of hashes where each hash
# contains the information for a single table. Thus the first hash in the
# array represents the first table found on the topic page, the second hash
# in the array represents the second table found on the topic page, etc.
sub _parseOutTables
{
my ($this, $topic) = @_;
my $tableNum = 1; # Table number (only count tables with EDITACTIONTRACKER tag)
my @tableMatrix; # Currently parsed table.
my $inEditTable = 0; # Flag to keep track if in an EDITACTIONTRACKER table
my $result = "";
my $insidePRE = 0;
my $insideTABLE = 0;
my $line = "";
my @row = ();
$topic =~ s/\r//go;
$topic =~ s/\\\n//go; # Join lines ending in "\"
foreach( split( /\n/, $topic ) ) {
# change state:
m||i && ( $insidePRE = 1 );
m||i && ( $insidePRE = 1 );
m||i && ( $insidePRE = 0 );
m||i && ( $insidePRE = 0 );
if( ! $insidePRE ) {
$inEditTable = 1 if (/%EDITACTIONTRACKER{(.*)}%/);
if ($inEditTable) {
if( /^\s*\|.*\|\s*$/ ) {
# inside | table |
$insideTABLE = 1;
$line = $_;
$line =~ s/^(\s*\|)(.*)\|\s*$/$2/o; # Remove starting '|'
@row = split( /\|/o, $line, -1 );
_trim(\@row);
push (@tableMatrix, [ @row ]);
} else {
# outside | table |
if( $insideTABLE ) {
# We were inside a table and are now outside of it so
# save the table info into the Table object.
$insideTABLE = 0;
$inEditTable = 0;
if (@tableMatrix != 0) {
# Save the table via its table number
$$this{"TABLE_$tableNum"} = [@tableMatrix];
$tableNum++;
}
undef @tableMatrix; # reset table matrix
}
}
}
}
$result .= "$_\n";
}
$$this{NUM_TABLES} = $tableNum;
}
# Trim any leading and trailing white space and/or '*'.
sub _trim
{
my ($totrim) = @_;
for my $element (@$totrim) {
$element =~ s/^[\s\*]+//; # Strip of leading white/*
$element =~ s/[\s\*]+$//; # Strip of trailing white/*
}
}
# Return the contents of the specified cell
sub getCell
{
my ( $this, $tableNum, $row, $column ) = @_;
my @selectedTable = $this->getTable( $tableNum );
my $value = $selectedTable[$row][$column];
return $value;
}
sub getTable
{
my ($this, $tableNumber) = @_;
my $table = $$this{"TABLE_$tableNumber"};
return @$table if defined( $table );
return ();
}
1;