|
Cookbook /
GlobalOperationsSummary: How to apply an operation to every page of a wiki
Version:
Prerequisites:
Status:
Maintainer:
Categories: Administration
QuestionHow do I apply operation XYZ on every page of my Wiki? AnswerThis recipe assumes that you are at least minimally fluent in writing PHP code. Say if you want to do if ($action=='foo_all') {
Lock(2);
$page = RetrieveAuthPage($pagename, "admin");
if (!$page) { Abort("?admin password required"); }
$pagelist = and insert include_once('local/foo_all.php');
into your During each iteration through the loop,
Clear HistoryThis is for expiring page history that's older than
$keepdays = @$_REQUEST['keepdays'];
$keepgmt = $Now - $keepdays * 86400;
$keys = array_keys($page);
foreach($keys as $k)
if (preg_match("/^\\w+:(\\d+)/", $k, $match))
if ($match[1] < $keepgmt) unset($page[$k]);
$WikiDir->delete($pagename);
WritePage($pagename, $page);
???This space intentionally left blank for additional ideas. Notes and Comments
Shell and command-lineBelow is a command line that extracts the text from a file storing a wiki
page. It could be useful in a shell script for doing something with all wiki
pages, e.g. extracting a list of all external
grep '^text=' wiki.d/Main.WikiSandbox | sed -e 's/^text=//' | tr '\262' '\012'
Note that the end-of-line encoding may be different under various circumstances (e.g. Internationalization). You may need to check each page file for the newline character and handle accordingly.
perl -e "while(<>){if(m(newline=(.+))){$n=$1;}if(m(text=(.+))){$t=$1;}}$t=~s($n)(\n)g;print $t;" wiki.d/Main.WikiSandbox
See AlsoContributors
|