--- fedwiki/lib/TWiki/Func.pm Sat Jan 4 19:35:57 2003 +++ testwiki/lib/TWiki/Func.pm Sun Oct 5 18:53:55 2003 @@ -704,6 +704,72 @@ return ""; } +=pod +---+++ appendTopicText( $web, $topic, $append, $ignorePermissions, $dontNotify ) ==> $oopsUrl + +| Description: | Save topic text, typically obtained by readTopicText(). Topic data usually in +| Parameter: =$web= | Web name, e.g. ="Main"=, or empty | +| Parameter: =$topic= | Topic name, e.g. ="MyTopic"=, or ="Main.MyTopic"= | +| Parameter: =$append= | Topic text to append, assumed to include meta data | +| Parameter: =$ignorePermissions= | Set to ="1"= if checkAccessPermission() is already perfor +| Parameter: =$dontNotify= | Set to ="1"= if not to notify users of the change | +| Return: =$oopsUrl= | Empty string if OK; the =$oopsUrl= for calling redirectCgiQuery() in ca + + * Example:
+ =my $text = "This is what I am going to append\n;" + =# check for oops URL in case of error:=
+ =my $result = TWiki::Func::appendTopicText( $web, $topic, $text, $ignorePermissions, $dontNotify); # append topic text=
+ + =if( $result ne "ok" ) =
+ =  my $url = TWiki::getOopsUrl( $web, $topic, "oopssaveerr", $result ) + =  TWiki::Func::redirectCgiQuery( $query, $oopsUrl );=
+ =  return;=
+ =}= + +=cut +# ------------------------- +sub appendTopicText +{ + my( $web, $topic, $append, $ignorePermissions, $dontNotify ) = @_; + + my( $mirrorSite, $mirrorViewURL ) = TWiki::readOnlyMirrorWeb( $web ); + return "this is a mirror" if( $mirrorSite ); + return "topic locked, and queuing not yet implemented" if (TWiki::Func::setTopicEditLock( $web, $topic, 1 )); + return "no permissions" unless( + TWiki::Access::checkAccessPermission( "change", $TWiki::wikiUserName, "", $topic, $web ) + or $ignorePermissions + ); + + + return "undefined text" unless( defined $append ); + return "empty text" unless( $append ); + + # extract meta data and merge old attachment meta data + my $meta = ""; + my $text = ""; !! I don't understand why text is passed into the following call + ( $meta, $text ) = TWiki::Store::_extractMetaData( $web, $topic, $text ); + my( $oldMeta, $oldText ) = TWiki::Store::readTopic( $web, $topic ); + $meta->copyFrom( $oldMeta, "FILEATTACHMENT" ); + + $text = $text . $append; + + # save topic, inhibiting the logging + my $error = TWiki::Store::saveTopic( $web, $topic, $text, $meta, "", 0, $dontNotify, 1 ); + + # we do the logging here to avoid addding more to TWiki::Store + # yet we want appends to show up properly + if ( $TWiki::doLogTopicSave ) { + TWiki::Store::writeLog( "append", "$TWiki::webName.$topic", "" ); + } + + TWiki::Func::setTopicEditLock( $web, $topic, 0 ); + + return $error if( $error ); + return "ok"; +} + + + # ========================= =pod