/** * The main() function which generates a zip archive of a PhpWiki. * * If $include_archive is false, only the current version of each page * is included in the zip file; otherwise all archived versions are * included as well. */ function MakeWikiZip($include_archive = false) { global $dbi, $WikiPageStore, $ArchivePageStore; $pages = GetAllWikiPageNames($dbi); $zipname = "wiki.zip"; if ($include_archive) { $zipname = "wikidb.zip"; } $zip = new ZipWriter("Created by PhpWiki", $zipname); for (reset($pages); $pagename = current($pages); next($pages)) { set_time_limit(30); // Reset watchdog. $pagehash = RetrievePage($dbi, $pagename, $WikiPageStore); if (!is_array($pagehash)) { continue; } if ($include_archive) { $oldpagehash = RetrievePage($dbi, $pagename, $ArchivePageStore); } else { $oldpagehash = false; } $attrib = array('mtime' => $pagehash['lastmodified'], 'is_ascii' => 1); if (($pagehash['flags'] & FLAG_PAGE_LOCKED) != 0) { $attrib['write_protected'] = 1; } $content = MailifyPage($pagehash, $oldpagehash); $zip->addRegularFile(encode_pagename_for_wikizip($pagehash['pagename']), $content, $attrib); } $zip->finish(); }
function DumpToDir(&$request) { $directory = $request->getArg('directory'); if (empty($directory)) { $directory = DEFAULT_DUMP_DIR; } // See lib/plugin/WikiForm.php:87 if (empty($directory)) { $request->finish(_("You must specify a directory to dump to")); } // see if we can access the directory the user wants us to use if (!file_exists($directory)) { if (!mkdir($directory, 0755)) { $request->finish(fmt("Cannot create directory '%s'", $directory)); } else { $html = HTML::p(fmt("Created directory '%s' for the page dump...", $directory)); } } else { $html = HTML::p(fmt("Using directory '%s'", $directory)); } StartLoadDump($request, _("Dumping Pages"), $html); $dbi =& $request->_dbi; $thispage = $request->getArg('pagename'); // for "Return to ..." if ($exclude = $request->getArg('exclude')) { // exclude which pagenames $excludeList = explodePageList($exclude); } else { $excludeList = array(); } if ($pages = $request->getArg('pages')) { // which pagenames if ($pages == '[]') { // current page $pages = $thispage; } $page_iter = new WikiDB_Array_PageIterator(explodePageList($pages)); } else { $page_iter = $dbi->getAllPages(false, false, false, $excludeList); } $request_args = $request->args; $timeout = !$request->getArg('start_debug') ? 30 : 240; while ($page = $page_iter->next()) { $request->args = $request_args; // some plugins might change them (esp. on POST) longer_timeout($timeout); // Reset watchdog $pagename = $page->getName(); if (!isa($request, 'MockRequest')) { PrintXML(HTML::br(), $pagename, ' ... '); flush(); } if (in_array($pagename, $excludeList)) { if (!isa($request, 'MockRequest')) { PrintXML(_("Skipped.")); flush(); } continue; } $filename = FilenameForPage($pagename); $msg = HTML(); if ($page->getName() != $filename) { $msg->pushContent(HTML::small(fmt("saved as %s", $filename)), " ... "); } if ($request->getArg('include') == 'all') { $data = MailifyPage($page, 0); } else { $data = MailifyPage($page); } if (!($fd = fopen($directory . "/" . $filename, "wb"))) { $msg->pushContent(HTML::strong(fmt("couldn't open file '%s' for writing", "{$directory}/{$filename}"))); $request->finish($msg); } $num = fwrite($fd, $data, strlen($data)); $msg->pushContent(HTML::small(fmt("%s bytes written", $num))); if (!isa($request, 'MockRequest')) { PrintXML($msg); flush(); } assert($num == strlen($data)); fclose($fd); } EndLoadDump($request); }
function dumpFile(&$thispage, $filename) { include_once "lib/loadsave.php"; $mailified = MailifyPage($thispage); $attrib = array('mtime' => $thispage->get('mtime'), 'is_ascii' => 1); $zip = new ZipWriter("Created by PhpWiki " . PHPWIKI_VERSION, $filename); $zip->addRegularFile(FilenameForPage($thispage->getName()), $mailified, $attrib); $zip->finish(); }
function run($dbi, $argstr, &$request, $basepage) { extract($this->getArgs($argstr, $request)); // allow plugin-form if (!empty($s)) { $page = $s; } if (!$page) { return ''; } if (!$dbi->isWikiPage($page)) { return fmt("Page %s not found.", WikiLink($page, 'unknown')); } $p = $dbi->getPage($page); include_once "lib/loadsave.php"; $mailified = MailifyPage($p, $format == 'backup' ? 99 : 1); // fixup_headers massages the page dump headers depending on // the 'format' argument, 'normal'(default) or 'forcvs'. // // Normal: Don't add X-Rcs-Id, add unique Message-Id, don't // strip any fields from Content-Type. // // ForCVS: Add empty X-Rcs-Id, strip attributes from // Content-Type field: "author", "version", "lastmodified", // "author_id", "hits". $this->pagename = $page; $this->generateMessageId($mailified); if ($format == 'forcvs') { $this->fixup_headers_forcvs($mailified); } else { // backup or normal $this->fixup_headers($mailified); } if ($download) { // TODO: we need a way to hook into the generated headers, to override // Content-Type, Set-Cookie, Cache-control, ... $request->discardOutput(); // Hijack the http request from PhpWiki. ob_end_clean(); // clean up after hijacking $request //ob_end_flush(); //debugging Header("Content-disposition: attachment; filename=\"" . FilenameForPage($page) . "\""); // Read charset from generated page itself. // Inconsequential at the moment, since loadsave.php // always generates headers $charset = $p->get('charset'); if (!$charset) { $charset = $GLOBALS['charset']; } // We generate 3 Content-Type headers! first in loadsave, // then here and the mimified string $mailified also has it! Header("Content-Type: text/plain; name=\"" . FilenameForPage($page) . "\"; charset=\"" . $charset . "\""); $request->checkValidators(); // let $request provide last modifed & etag Header("Content-Id: <" . $this->MessageId . ">"); // be nice to http keepalive~s // FIXME: he length is wrong BTW. must strip the header. Header("Content-Length: " . strlen($mailified)); // Here comes our prepared mime file echo $mailified; exit; // noreturn! php exits. return; } // We are displaing inline preview in a WikiPage, so wrap the // text if it is too long--unless quoted-printable (TODO). $mailified = safe_wordwrap($mailified, 70); $dlcvs = Button(array('action' => $this->getName(), 'format' => 'forcvs', 'download' => true), _("Download for CVS"), $page); $dl = Button(array('action' => $this->getName(), 'download' => true), _("Download for backup"), $page); $dlall = Button(array('action' => $this->getName(), 'format' => 'backup', 'download' => true), _("Download all revisions for backup"), $page); $h2 = HTML::h2(fmt("Preview: Page dump of %s", WikiLink($page, 'auto'))); global $WikiTheme; if (!($Sep = $WikiTheme->getButtonSeparator())) { $Sep = " "; } if ($format == 'forcvs') { $desc = _("(formatted for PhpWiki developers as pgsrc template, not for backing up)"); $altpreviewbuttons = HTML(Button(array('action' => $this->getName()), _("Preview as normal format"), $page), $Sep, Button(array('action' => $this->getName(), 'format' => 'backup'), _("Preview as backup format"), $page)); } elseif ($format == 'backup') { $desc = _("(formatted for backing up: all revisions)"); // all revisions $altpreviewbuttons = HTML(Button(array('action' => $this->getName(), 'format' => 'forcvs'), _("Preview as developer format"), $page), $Sep, Button(array('action' => $this->getName(), 'format' => ''), _("Preview as normal format"), $page)); } else { $desc = _("(normal formatting: latest revision only)"); $altpreviewbuttons = HTML(Button(array('action' => $this->getName(), 'format' => 'forcvs'), _("Preview as developer format"), $page), $Sep, Button(array('action' => $this->getName(), 'format' => 'backup'), _("Preview as backup format"), $page)); } $warning = HTML(_("Please use one of the downloadable versions rather than copying and pasting from the above preview.") . " " . _("The wordwrap of the preview doesn't take nested markup or list indentation into consideration!") . " ", HTML::em(_("PhpWiki developers should manually inspect the downloaded file for nested markup before rewrapping with emacs and checking into CVS."))); return HTML($h2, HTML::em($desc), HTML::pre($mailified), $altpreviewbuttons, HTML::div(array('class' => 'errors'), HTML::strong(_("Warning:")), " ", $warning), $dl, $Sep, $dlall, $Sep, $dlcvs); }