4 Allows to download a tarball including all WikiPages and images that
5 currently are in the database.
10 $ewiki_t["en"]["WIKIDUMP"] = "Here you can download all pages of this Wiki in HTML format at once. They'll get packed into a an archive of the UNIX .tar format.";
11 $ewiki_t["en"]["download tarball"] = "Download Tarball";
12 $ewiki_t["en"]["with images"] = "With images";
13 $ewiki_t["en"]["complete .html files"] = "Complete HTMLfiles";
14 $ewiki_t["en"]["include virtual pages"] = "Include virtual pages";
16 $ewiki_t["de"]["WIKIDUMP"] = "Du kannst dir hier alle Seiten des Wikis im HTML-Format herunterladen. Das Archiv wird im UNIX .tar Format erstellt.";
17 $ewiki_t["de"]["download tarball"] = "tarball herunterladen";
18 $ewiki_t["de"]["with images"] = "mit Graphiken";
19 $ewiki_t["de"]["complete .html files"] = "vollständige .html Dateien";
20 $ewiki_t["de"]["include virtual pages"] = "auch virtuelle Seiten";
23 $ewiki_plugins["page"]["WikiDump"] = "ewiki_page_wiki_dump_tarball";
27 #-- template (if $fullhtml)
28 function ewiki_dump_template($id, $content, $linksto=0, $html_ext=".html") {
30 $title = $head_title = ewiki_split_title($id);
32 $title = '<a href="' . urlencode(urlencode($id)). (($linksto>0) ? '.links':''). $html_ext . '">' . $title . '</a>';
34 $version = EWIKI_VERSION;
37 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
40 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
41 <title>$head_title</title>
42 <meta name="generator" content="WikiDump, ewiki/$version">
44 <body bgcolor="#ffffff";>
54 function ewiki_page_wiki_dump_tarball($id, $data, $action) {
56 #-- return legacy page
57 if (empty($_REQUEST["download_tarball"])) {
58 $url = ewiki_script("", $id);
59 return(ewiki_make_title($id, $id, 2) . ewiki_t(<<<END
62 <form action="$url" method="POST" enctype="multipart/form-data">
63 <input type="hidden" name="id" value="$id">
64 <input type="submit" name="download_tarball" value="_{download tarball}">
66 <input type="checkbox" name="dump_images" value="1"> _{with images}<br />
67 <input type="checkbox" name="dump_virtual" value="1"> _{include virtual pages}<br />
68 <input type="checkbox" name="dump_fullhtml" value="1" checked> _{complete .html files}<br />
69 <input type="checkbox" name="dump_linksto" value="1"> _{with backlink pages}<br />
74 #-- tarball generation
76 $di = $_REQUEST["dump_images"];
77 $fh = $_REQUEST["dump_fullhtml"];
78 $bl = $_REQUEST["dump_linksto"];
79 $vp = $_REQUEST["dump_virtual"];
80 $_REQUEST = $_GET = $_POST = array();
82 ewiki_page_wiki_dump_send($di, $fh, $vp, $bl);
87 function ewiki_page_wiki_dump_send($imgs=1, $fullhtml=0, $virtual=0, $linksto=0) {
89 global $ewiki_config, $ewiki_plugins;
91 #-- reconfigure ewiki_format() to generate offline pages and files
96 $ewiki_config["script"] = "%s$html_ext";
97 $ewiki_config["script_binary"] = "%s";
98 $ewiki_config["print_title"] = 0;
100 #-- fetch also dynamic pages
102 $virtual = array_keys($ewiki_plugins["page"]);
108 #-- get all pages / binary files
109 $result = ewiki_db::GETALL(array("id", "version", "flags"));
113 header("Content-Type: application/x-tar");
114 header("Content-Disposition: attachment; filename=\"WikiDump.tar.gz\"");
117 $tarball = new ewiki_virtual_tarball();
120 #-- convert all pages
121 while (($row=$result->get()) || count($virtual)) {
125 #-- fetch page from database
126 if ($id = $row["id"]) {
127 $row = ewiki_db::GET($id);
129 #-- virtual page plugins
130 elseif ($id = array_pop($virtual)) {
131 $pf = $ewiki_plugins["page"][$id];
132 $content = $pf($id, $content, "view");
134 "flags" => EWIKI_DB_F_TEXT|EWIKI_DB_F_HTML,
135 "lastmodified" => time(),
144 $fn = urlencode($fn);
146 #-- post process for ordinary pages / binary data
148 switch ($row["flags"] & EWIKI_DB_F_TYPE) {
150 case (EWIKI_DB_F_TEXT):
151 $content = ewiki_format($row["content"]);
154 case (EWIKI_DB_F_BINARY):
155 if (($row["meta"]["class"]=="image") && ($imgs)) {
156 $content = &$row["content"];
169 if (empty($content)) {
175 "mtime" => $row["lastmodified"],
177 "mode" => 0664 | (($row["flags"]&EWIKI_DB_F_WRITEABLE)?0002:0000),
180 #-- html post process
181 if (!($row["flags"] & EWIKI_DB_F_BINARY)) {
183 #-- use page template
185 $content = ewiki_dump_template($id, $content, $linksto);
191 "$fn.links$html_ext",
194 ewiki_page_links($id, $row, "links"),
224 ############################################################################
229 #-- allows to generate a tarball from virtual files
230 # (supports no directories or symlinks and other stuff)
231 class ewiki_virtual_tarball {
235 function open($fn="/dev/stdout") {
241 if ($fn && ($fn != "-")) {
242 $this->f = gzopen("$fn", "wb9");
245 $_ENV["HTTP_ACCEPT_ENCODING"] = "gzip, deflate";
246 $_SERVER["HTTP_ACCEPT_ENCODING"] = "gzip, deflate";
247 ob_start("ob_gzhandler");
255 $this->write(str_repeat("\000", 9*1024));
257 #-- close file handle
264 function write($str) {
266 gzwrite($this->f, $str);
276 function oct($int, $len) {
279 $o = ($int & 0x07) . $o;
287 function add($filename, $content, $args=array()) {
289 $args = array_merge($args, array(
293 "uid" => 65534, #-- common for user "nobody"
299 $args["mode"] |= 0100000;
300 $args["size"] = strlen($content);
302 $magic = "ustar \000";
303 $filename = substr($filename, 0, 99);
306 $header = str_pad($filename, 100, "\000") # 0x0000
307 . $this->oct($args["mode"], 8) # 0x0064
308 . $this->oct($args["uid"], 8) # 0x006C
309 . $this->oct($args["gid"], 8) # 0x0074
310 . $this->oct($args["size"], 12) # 0x007C
311 . $this->oct($args["mtime"], 12) # 0x0088
312 . ($checksum) # 0x0094
313 . ($args["type"]) # 0x009C
314 . str_repeat("\000", 100) # 0x009D
316 . str_pad($args["uname"], 32, "\000") # 0x0109
317 . str_pad($args["gname"], 32, "\000") # 0x0129
319 $header = str_pad($header, 512, "\000");
321 #-- calculate and add header checksum
323 for ($n=0; $n<512; $n++) {
324 $cksum += ord($header[$n]);
326 $header = substr($header, 0, 0x0094)
327 . $this->oct($cksum, 7) . " "
328 . substr($header, 0x009C);
331 if ($fill = (512 - (strlen($content) % 512))) {
332 $content .= str_repeat("\000", $fill);
334 $this->write($header . $content);