ImportText

Summary: Import text files as PmWiki pages
Version: 20231117
Prerequisites: pmwiki-2.2.0-beta51
Status: Under development
Maintainer: Petko (originally by Pm)
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

See also $RCLineMax: if enabled, and you're importing more pages than this number, some of these may not appear in (All) Recent Changes pages.

Release Notes

  • 20231117 - report if saving of a page failed, reported by Gregor Klarič
  • 20231116 - update for PHP 7.2+, reported by Gb
  • 20070527 - added $ImportTime capability, change output of ?action=import
  • 20070523 - initial version

See Also

Cookbook /
PageRegenerate  Make PmWiki regenerate a page, as if someone had done an edit+save sequence. (Stable)
PmWiki /
PageFileFormat  Create wiki formatted pages in bulk and for upload to your pmwiki site

Contributors

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.