/** * 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 MakeWikiZipHtml(&$request) { $request->_TemplatesProcessed = array(); $zipname = "wikihtml.zip"; $zip = new ZipWriter("Created by PhpWiki " . PHPWIKI_VERSION, $zipname); $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); } global $WikiTheme; if (defined('HTML_DUMP_SUFFIX')) { $WikiTheme->HTML_DUMP_SUFFIX = HTML_DUMP_SUFFIX; } $WikiTheme->DUMP_MODE = 'ZIPHTML'; $_bodyAttr = @$WikiTheme->_MoreAttr['body']; unset($WikiTheme->_MoreAttr['body']); /* ignore fatals in plugins */ if (check_php_version(4, 1)) { global $ErrorManager; $ErrorManager->pushErrorHandler(new WikiFunctionCb('_dump_error_handler')); } $request_args = $request->args; $timeout = !$request->getArg('start_debug') ? 20 : 240; while ($page = $page_iter->next()) { $request->args = $request_args; // some plugins might change them (esp. on POST) longer_timeout($timeout); // Reset watchdog $current = $page->getCurrentRevision(); if ($current->getVersion() == 0) { continue; } $pagename = $page->getName(); if (in_array($pagename, $excludeList)) { continue; } $attrib = array('mtime' => $current->get('mtime'), 'is_ascii' => 1); if ($page->get('locked')) { $attrib['write_protected'] = 1; } $request->setArg('pagename', $pagename); // Template::_basepage fix $filename = FilenameForPage($pagename) . $WikiTheme->HTML_DUMP_SUFFIX; $revision = $page->getCurrentRevision(); $transformedContent = $revision->getTransformedContent(); $template = new Template('browse', $request, array('revision' => $revision, 'CONTENT' => $transformedContent)); $data = GeneratePageasXML($template, $pagename); $zip->addRegularFile($filename, $data, $attrib); if (USECACHE) { $request->_dbi->_cache->invalidate_cache($pagename); unset($request->_dbi->_cache->_pagedata_cache); unset($request->_dbi->_cache->_versiondata_cache); unset($request->_dbi->_cache->_glv_cache); } unset($request->_dbi->_cache->_backend->_page_data); unset($revision->_transformedContent); unset($revision); unset($template->_request); unset($template); unset($data); } $page_iter->free(); $attrib = false; // Deal with css and images here. if (!empty($WikiTheme->dumped_images) and is_array($WikiTheme->dumped_images)) { // dirs are created automatically //if ($WikiTheme->dumped_images) $zip->addRegularFile("images", "", $attrib); foreach ($WikiTheme->dumped_images as $img_file) { if ($from = $WikiTheme->_findFile($img_file, true) and basename($from)) { $target = "images/" . basename($img_file); if (check_php_version(4, 3)) { $zip->addRegularFile($target, file_get_contents($WikiTheme->_path . $from), $attrib); } else { $zip->addRegularFile($target, join('', file($WikiTheme->_path . $from)), $attrib); } } } } if (!empty($WikiTheme->dumped_buttons) and is_array($WikiTheme->dumped_buttons)) { //if ($WikiTheme->dumped_buttons) $zip->addRegularFile("images/buttons", "", $attrib); foreach ($WikiTheme->dumped_buttons as $text => $img_file) { if ($from = $WikiTheme->_findFile($img_file, true) and basename($from)) { $target = "images/buttons/" . basename($img_file); if (check_php_version(4, 3)) { $zip->addRegularFile($target, file_get_contents($WikiTheme->_path . $from), $attrib); } else { $zip->addRegularFile($target, join('', file($WikiTheme->_path . $from)), $attrib); } } } } if (!empty($WikiTheme->dumped_css) and is_array($WikiTheme->dumped_css)) { foreach ($WikiTheme->dumped_css as $css_file) { if ($from = $WikiTheme->_findFile(basename($css_file), true) and basename($from)) { $target = basename($css_file); if (check_php_version(4, 3)) { $zip->addRegularFile($target, file_get_contents($WikiTheme->_path . $from), $attrib); } else { $zip->addRegularFile($target, join('', file($WikiTheme->_path . $from)), $attrib); } } } } $zip->finish(); if (check_php_version(4, 1)) { global $ErrorManager; $ErrorManager->popErrorHandler(); } $WikiTheme->HTML_DUMP_SUFFIX = ''; $WikiTheme->DUMP_MODE = false; $WikiTheme->_MoreAttr['body'] = $_bodyAttr; }
/** * 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(&$request) { global $ErrorManager; if ($request->getArg('include') == 'all') { $zipname = WIKI_NAME . _("FullDump") . date('Ymd-Hi') . '.zip'; $include_archive = true; } else { $zipname = WIKI_NAME . _("LatestSnapshot") . date('Ymd-Hi') . '.zip'; $include_archive = false; } $include_empty = false; if ($request->getArg('include') == 'empty') { $include_empty = true; } $zip = new ZipWriter("Created by PhpWiki " . PHPWIKI_VERSION, $zipname); /* ignore fatals in plugins */ $ErrorManager->pushErrorHandler(new WikiFunctionCb('_dump_error_handler')); $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 $current = $page->getCurrentRevision(); if ($current->getVersion() == 0) { continue; } $pagename = $page->getName(); $wpn = new WikiPageName($pagename); if (!$wpn->isValid()) { continue; } if (in_array($page->getName(), $excludeList)) { continue; } $attrib = array('mtime' => $current->get('mtime'), 'is_ascii' => 1); if ($page->get('locked')) { $attrib['write_protected'] = 1; } if ($include_archive) { $content = MailifyPage($page, 0); } else { $content = MailifyPage($page); } $zip->addRegularFile(FilenameForPage($pagename), $content, $attrib); } $zip->finish(); $ErrorManager->popErrorHandler(); }
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(); }