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
Discussion: ImportText-Talk

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 .

See Also

Contributors

  • Pm, 2007-05-23

Comments

See discussion at ImportText-Talk

User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on October 21, 2013, at 08:05 PM