Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

ImportText

Summary: Import text files as PmWiki pages
Version: 2007-05-27
Prerequisites: pmwiki-2.2.0-beta51
Status: Under development
Maintainer: Pm
Categories: System tools

Questions answered by this recipe

  • Can PmWiki automatically import text files as pages?

Description

The import.phpΔ script simplifies the process of importing text markup into PmWiki.

This script is still somewhat untested -- use with caution and be sure to have reasonable backups!

Plain text files (with or without wiki markup) are placed in an "import directory" defined by the $ImportDir variable (default "import/"). Each file to be imported must be named with a valid pagename and an optional '.txt' extension. (Note: a valid pagename consists of a Groupname and a Wikipagename separated with a dot. For example: Main.MyNewPage (optionally followed by ".txt"))

Whenever this script detects that the import/ directory has changed, or at intervals given by $ImportFreq (in seconds), it scans the import/ directory to see if there are any new files to be imported. When one is found, the script updates the corresponding page in wiki.d with the text of the file as if it had been posted through the normal edit process. The "post" is performed assuming authorship as given by the $ImportAuthor variable (default is 'ImportText').

To avoid hitting PHP's "maximum execution time" limits, this script will perform imports for up to 15 seconds (as set by the $ImportTime variable). If it's unable to process all of the imported files within that period of time, it closes out its work and queues the remaining files to be processed on subsequent requests.

The script keeps track of which files have previously been imported so that it doesn't re-import it again later. As extra protection, if the $EnableImportRename variable is set (default is yes), then the script attempts to rename each input file with a timestamp suffix.

The script also provides ?action=import to force immediate importing of any files in the import/ directory. By default, ?action=import can only be invoked by someone with admin privileges.

To install this script, copy it into the cookbook/ directory and add the following lines to a customization file:

     # load script
     include_once('cookbook/import.php');
     # check for new files at least once per hour
     $ImportFreq = 3600;

Then, create a directory called import/ that will contain any text files to be imported by the script. If you want the script to be able to rename the files after importing them, make sure the webserver has write permission to the import/ directory. Use the $ImportDir variable to have the script scan a different directory.

Notes

Release Notes

  • 2007-05-23, initial version
  • 2007-05-27, added $ImportTime capability, change output of ?action=import .

Comments

  • i am very interested in these things -- are you made some progress so far? http://www.kl3tte.de(approve links) 2007-12-03
  • I don't know if this is a stupid question, but is it meant to be used through ftp - uploading the .txt files directly to your webserver's pmwikiinstallation/import directory or is there some sort of special page where they can be imported besides the ?action=import which checks the import dir for new files?

randomusr 2007-10-07

  • This can also be used as a way to mass-delete one or more (!) files. Simply create a text file with the single word "delete" (no quotes; be aware that your site may have customized this word) and then copy it to have the same names as the files you want to delete. (I was deleting a bunch of files in wikiforms so they happened to be named 01000 to 01122 which made it very easy for a script to generate the files.) Upload these to the import directory and it will process through... Peter Bowers December 19, 2007, at 02:43 AM
  • I'm working too on this concept. It's very useful to synchronize in the two ways. I test your scripts: it renames the txt file whith then date of import but if another application want to modify the file, it does not longer exist. I want to try using pmwiki as a frontend for PyGTD. It's necessary to update data from the txt files but also impact the txt files (with the same name) for PyGTD processing. Howto ? ctime ? FrançoisElie April 27, 2008

See Also

Contributors

  • Pm, 2007-05-23
Edit - History - Print - Recent Changes - Search
Page last modified on April 27, 2008, at 04:04 PM