Purge deleted pages and attachments from the server directories.
- When a wiki page is deleted, the disk file which contained it is archived and hidden. To actually remove the file, the administrator needs to log into the server via FTP or SSH and manually delete it.
- When a new version of an attachment is uploaded (see
$EnableUploadVersions), its previous versions are similarly archived.
With this recipe, wiki administrators can remove all "deleted" archived files (wiki pages or uploads) via a pmwiki action, without logging into the server.
- Copy cleanup.phpΔ to your pmwiki/cookbook directory (alt. download: cleanup.php).
- Add to config.php such a line:
if($action=='cleanup' || $action=='cleanup2') include_once("
You also need to set the directories to be cleaned up. Typically, one or more of the following lines should be added to config.php:
$WorkDir] = 1; # cleanup deleted wiki pages $CleanUpDirs["uploads"] = 1; # cleanup deleted uploads
$PageListCacheDir] = 1; # cleanup old cache from pagelists
The script will scan these directories recursively and will remove all "deleted" files from them and from their subdirectories.
The script will remove files which were deleted more than 30 days ago and will keep the more recently deleted ones. To change the number of days, set in config.php:
$CleanUpKeepDays = 0; # remove all deleted files/pages -OR- $CleanUpKeepDays = 10; # remove files/pages deleted 10+ days ago
Note, the cleanup of the "cache" directories deletes the cached files as soon as they are obsolete.
The recipe should work with different
$UploadPrefixFmt settings and with PerGroupSubDirectories. To scan only certain subdirectories of pmwiki/wiki.d or of pmwiki/uploads, set them instead of the ones in the Install section above:
$CleanUpDirs["uploads/Main"] = 1; # cleanup deleted uploads in Main group # cleanup deleted pages in Main group (if PerGroupSubDirectories installed) $CleanUpDirs["
$WorkDir/Main"] = 1; # note the quotes
To purge all deleted files, there are two steps:
- Go to
http://yourwiki/pmwiki.php?action=cleanup(you may need to enter your Administrator password). You will see a list of all scanned directories and subdirectories, and all files to be purged.
- If you are happy with the listed files, click on the link at the bottom of the page to actually delete them.
- It is highly recommended to have backups when you perform mass deletions.
- If you have a huge number of files to be deleted, combined with a slow server/filesystem, the script might hit the system limits before finishing the cleanup and display a warning about max_execution_time or set_time_limit. In that case, just reload the page until it finishes cleanly.
Change log / Release notes
- 20220507 : Update for PHP 7.4-8.1.
- 20140808 : Add preview mode. Only list directories containing files [to be] deleted, not all scanned directories. Note that the installation line has changed.
- 20111102 : The recipe can now clean up cache directories.
- 20111026 : First public release, ready to be tested.
- Recipe written and maintained by Petko (5ko [snail] 5ko [period] fr).
- If this recipe helps you or saves you time, you can help support its continued development by ♥ .
See discussion at CleanUp-Talk