Questions answered by this recipe
- Can PmWiki automatically import text files as pages?
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.
- 2007-05-23, initial version
- 2007-05-27, added $ImportTime capability, change output of ?action=import .
- Pm, 2007-05-23
See discussion at ImportText-Talk