Question
TWiki topics start with a line or two of Meta Data like
%META:TOPICINFO...
Is it important that the first line of the topic be Meta Data?
What would be the result if some files had a line manually inserted before the Meta Data?
This comes from a requirement to update a group of files with a non-twiki script.
Environment
--
PeterJones - 10 Jul 2007
Answer
If you answer a question - or have a question you asked answered by someone - please remember to edit the page and set the status to answered. The status is in a drop-down list below the edit box.
No, it's not important, though some older plugins might barf. My normal practice is either to use the published APIs for reading/writing topics (which has the advantage that the META fields and
RCS gets updated too), or to do something like this:
open(F, "<data/Web/TWikiTopic.txt") || die $!;
local $/ = "\n";
my ($inHeader, $header, $footer) = (1, '', '');
while (<F>) {
if (/^%META:[A-Z]+{.*}%/) {
if ($inHeader) {
$header .= $_;
} else {
$footer .= $_;
}
next;
} else {
$body .= $_;
$inHeader = 0;
}
}
close(F);
# $header, $body, $footer now contain the top meta, text body, and
# foot meta respectively, so writing the topic is as simple as:
print F $header, $body, $footer;
Note of course that you are only updating a
cache of the topics - the real topic content is stored in
RCS. You really,
really ought to use the TWiki APIs. Here's how to do it using the APIs:
use TWiki;
use TWiki::Func;
$TWiki::Plugins::SESSION = new TWiki('username');
# 'username' is the login name of the user who will be credited with
# the save, and must be an existing TWiki user.
my ($meta, $text) = TWiki::Func::readTopic('Web', 'TWikiTopic');
# $text now contains the body text; munge as you see fit
TWiki::Func::saveTopic('Web', 'TWikiTopic', $meta, $text);
THIS REALLY OUGHT TO BE IN AN FAQ TOPIC - if (when) it works for you, could you please make it one?
--
CrawfordCurrie - 12 Jul 2007
Many thanks Crawford for you answer.
It would appear that touching files like this could have some nasty consequences if the topic and the
RCS are not in sync. I am seeing some weird results with WebChanges since we have started to manually edit files. What other dangers are there if files are continually modified by scripts outside of the TWiki API?
--
PeterJones - 12 Jul 2007
See answer to your second question at
ChangesAndDiffsOmittingRevisions.
--
PeterThoeny - 13 Jul 2007