Friday, July 31, 2009

command-line edit foswiki topics

We use foswiki at SDO for our "Local Operating Procedures" (LOPs). These many consist of numbered steps, with some metadata attached.

I recently was tasked to add a document number to the metadata. Easy, except with hundreds of documents, I didn't want to do this manually.

Each Wiki topic is a text document. The text document also stores the metadata (like the document number). Of course, since it's text it is easy to edit and script the edit with perl.

However, each topic text file also has an associated RCS file for versioning information. If you just edit the text file, the web page itself looks fine, but you can't see the change you made in the page's history (unless you make another change using the web interface).

But it turns out to be very easy to record your direct text file edits in RCS. Simply do
rcs -l TextFileName.txt
## now make your changes using whatever method (manual, scripted, etc.), then:
ci -mnone -t-none -wusername -u TextFileName.txt

That's it! Now the edits you made from your terminal are visible in the topic's history.

2 comments:

  1. Thanks for this! Helped me script some changes to foswiki.

    ReplyDelete
  2. I tried something similar and it didn't work exactly right.
    Regarding the first line above, I always say "co" instead of "rcs" when checking out a file. No difference, I guess.
    If it isn't obvious, the above two lines will not work without some editing or changes to the file happening between the 1st and 2nd line.
    The above will break foswiki, leaving no working file, unless you are the foswiki file tree owner (apache in my case), and you are in the foswiki file tree.
    But even then I have a problem. I run the rcs commands and it updates the file just fine. I can use rlog and see my revision (revision 2, let's call it)
    But when I view my changed file from the web interface, my revision is not there! The blue bar at the bottom does not show my revision after "History:".
    Foswiki must be keeping this information somewhere else.

    ReplyDelete