1 <!-- $Id: dumpserial.php,v 1.1.2.1 2005-01-05 04:24:49 rurban Exp $ -->
5 Write out all pages from the database to a user-specified
6 directory as serialized data structures.
8 if (!defined('WIKI_ADMIN'))
9 die("You must be logged in as the administrator to dump serialized pages.");
11 $directory = $dumpserial;
12 $pages = GetAllWikiPagenames($dbi);
14 // see if we can access the directory the user wants us to use
15 if (! file_exists($directory)) {
16 if (! mkdir($directory, 0755))
17 ExitWiki("Cannot create directory '$directory'<br>\n");
19 $html = "Created directory '$directory' for the page dump...<br>\n";
21 $html = "Using directory '$directory'<br>\n";
24 $numpages = count($pages);
25 for ($x = 0; $x < $numpages; $x++) {
26 $pagename = htmlspecialchars($pages[$x]);
27 $filename = preg_replace('/^\./', '%2e', rawurlencode($pages[$x]));
28 $html .= "<br>$pagename ... ";
29 if($pagename != $filename)
30 $html .= "<small>saved as $filename</small> ... ";
32 $data = serialize(RetrievePage($dbi, $pages[$x], $WikiPageStore));
33 if ($fd = fopen("$directory/$filename", "w")) {
34 $num = fwrite($fd, $data, strlen($data));
35 $html .= "<small>$num bytes written</small>\n";
37 ExitWiki("<b>couldn't open file '$directory/$filename' for writing</b>\n");
41 $html .= "<p><b>Dump complete.</b>";
42 GeneratePage('MESSAGE', $html, 'Dump serialized pages', 0);