]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - admin/dumpserial.php
2004-11-28 19:19 rurban
[SourceForge/phpwiki.git] / admin / dumpserial.php
1 <!-- $Id: dumpserial.php,v 1.1.2.1.2.2 2005-01-07 13:59:57 rurban Exp $ -->
2
3 <?php
4    /*
5       Write out all pages from the database to a user-specified
6       directory as serialized data structures.
7    */
8    if (!defined('WIKI_ADMIN'))
9       die("You must be logged in as the administrator to dump serialized pages.");
10   
11    $directory = $dumpserial;
12    $pages = GetAllWikiPagenames($dbi);
13
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");
18       else
19          $html = "Created directory '$directory' for the page dump...<br>\n";
20    } else {
21       $html = "Using directory '$directory'<br>\n";
22    }
23
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> ... ";
31
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";
36       } else {
37          ExitWiki("<b>couldn't open file '$directory/$filename' for writing</b>\n");
38       }
39    }
40
41    $html .= "<p><b>Dump complete.</b>";
42    GeneratePage('MESSAGE', $html, 'Dump serialized pages', 0);
43    ExitWiki('');
44 ?>