MakeWikiPage

<< | Cookbook-V1 | >>

Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.


makeWikiPage is a bash script that will take an email message (or any other file piped into it), and create a PmWiki page. In combination with procmail, it will allow you to setup a special email address to which you can send information that you'd like to have included in your PmWiki, without having to create the page manually.

Download the script here.

Setup:

  • Copy the downloaded file, makeWikiPage, somewhere convenient. I keep mine in my ~/bin directory.
  • Verify that the following programs are available on your system in your $PATH:
      echo, cut, tr, grep, sed & formail
  • Edit the following two variables in makeWikiPage:
WikiDir: the full path to your PmWiki data directory.
WikiGroup: the default group in which to create pages, if one is not specified.
  • Add the following receipe to your .procmailrc:
      # send "wiki" files to wiki
      SUBJECT=`formail -xSubject:`
      :0
      * ^TOwikiPage@mydomain.com
      | /home/tom/bin/makeWikiPage $SUBJECT
Be sure to edit the "TO" line to reflect the desired email address, and the last line to the location where you saved makeWikiPage in step #1.
NOTE: if you'd like to have the email headers stripped from the message before the creation of the wikiPage (for less 'cleanup' later), add an "-s" switch to the makeWikiPage line in your procmail recipe.
      (i.e. | /home/tom/bin/makeWikiPage -s $SUBJECT)
  • You'll need to setup the proper alias in your MTA to forward any mail that is sent to wikiPage@mydomain.com (for example) to your regular email address (so that the procmail receipe will be executed). Alternately, setup a new user named wikipage and put the procmail recipe there.
  • The above steps are all that is needed to create the wiki pages from email sent to wikiPage@mydomain.com. If you want to edit the pages later (which I'm sure you'll want to do), the ownership of the pages must be fixed...any of the following methods may be used:
    • Permanently change the group ownership of new files. (this is what I do)
      1. Create a 'pmwiki' group.
      2. Add your unix login, and the login under which your web server runs (www-data, in my case), to the 'pmwiki' group.
      3. Change the 'group owner' of wiki.d to 'pmwiki', and ensure the permissions of wiki.d are set to 2775. Once that is done, all new files created will be owned by the 'pmwiki' group
      4. Finally, you'll need to change the group ownership of previously created files to 'pmwiki'.
    • Change the ownership of the new files to that of your web server (www-data on my debian setup). To accomplish this automatically, just have the following cronjob setup to run every 5 minutes (edit to suit your system):
           */5 * * * * /bin/chown www-data /home/tom/public_html/pmwiki/wiki.d/*
NOTE: possible third method... I haven't tried this, but I believe that one can also use the fixperms.php script added in pmwiki-0.5.15 to fix the permissions/ownership on the pages. If you want to go this route, you'll need to figure the specifics out on your own.

Usage:

 # Usage...  Pipe input to one of the following commands:
 #   makeWikiPage [options] [pagename]
 #     options:
 #       -s                    strips header lines from email
 #     pagename:
 #       Group....Page         wikiPage is named Group.Page
 #       Page                  wikiPage is named $WikiGroup.Page
 #       if pagename is blank, wikiPage is named $WikiGroup.Journal-YYYYMMDD

A WikiPage will be created from any mail sent to wikiPage@mydomain.com. The title of Group.Page will be determined by the following:

  • If the subject line is blank, the WikiPage will be named in the following format:
       $WikiGroup.Journal-YYYYMMDD (i.e. Tom.Journal-20030523)
           (NOTE: $WikiGroup is the variable you set in step #2 above.)
  • If the subject line does not contain a series of 4 periods {....} (the group has not been specified), the page will be named in the following format:
       $WikiGroup.Subject (i.e. if the subject of my email is "Linux", then the created page would be Tom.Linux)
  • If the subject line contains a series of 4 periods {....} (you've specified a group name), the page is named after your subject line (i.e. if the subject is "Tom....MacOSX", then the created page will be "Tom.MacOSX").
  • Duplicate filenames are handled automatically by appending the new text to the end of the existing page, along with a timestamp.

Questions / suggestions:

  • Feel free to send email to tom@hisword.net.

pmwiki-2.3.32 -- Last modified by {{}}?

from IP: 85.171.160.186 ip should be disabled by default for security reasons