From: Carsten K. <car...@us...> - 2002-01-09 17:04:54
|
Update of /cvsroot/phpwiki/phpwiki/lib In directory usw-pr-cvs1:/tmp/cvs-serv26730 Modified Files: loadsave.php Log Message: Added comment "FIXME: better message?". Reindenting and rewrapping in emacs. Index: loadsave.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/loadsave.php,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -r1.21 -r1.22 *** loadsave.php 2002/01/09 04:01:09 1.21 --- loadsave.php 2002/01/09 17:04:51 1.22 *************** *** 6,24 **** function StartLoadDump($title, $html = '') { ! // FIXME: This is a hack ! echo ereg_replace('</body>.*', '', ! GeneratePage('MESSAGE', $html, $title, 0)); } function EndLoadDump() { ! // FIXME: This is a hack ! echo Element('p', QElement('b', _("Complete."))); ! echo Element('p', sprintf( _("Return to %s"),LinkExistingWikiWord($GLOBALS['pagename']) ) ); ! echo "</body></html>\n"; } ! //////////////////////////////////////////////////////////////// // --- 6,25 ---- function StartLoadDump($title, $html = '') { ! // FIXME: This is a hack ! echo ereg_replace('</body>.*', '', ! GeneratePage('MESSAGE', $html, $title, 0)); } function EndLoadDump() { ! // FIXME: This is a hack ! echo Element('p', QElement('b', _("Complete."))); ! echo Element('p', sprintf( _("Return to %s"), ! LinkExistingWikiWord($GLOBALS['pagename']) ) ); ! echo "</body></html>\n"; } ! //////////////////////////////////////////////////////////////// // *************** *** 29,59 **** function MailifyPage ($page, $nversions = 1) { ! global $SERVER_ADMIN, $pagedump_format; ! ! $current = $page->getCurrentRevision(); ! $from = isset($SERVER_ADMIN) ? $SERVER_ADMIN : 'foo@bar'; ! $head = ""; ! if ($pagedump_format == 'quoted-printable') { ! $head = "From $from " . CTime(time()) . "\r\n"; ! $head .= "Subject: " . rawurlencode($page->getName()) . "\r\n"; ! $head .= "From: $from (PhpWiki)\r\n"; ! $head .= "Date: " . Rfc2822DateTime($current->get('mtime')) . "\r\n"; ! $head .= sprintf("Mime-Version: 1.0 (Produced by PhpWiki %s)\r\n", PHPWIKI_VERSION); ! } else { ! $head .= sprintf("Mime-Version: 1.0 (Produced by PhpWiki %s)\r\n", PHPWIKI_VERSION."+carsten's-binary-hack"); ! } ! $head .= "X-RCS_ID: $" ."Id" ."$" ."\r\n"; ! ! $iter = $page->getAllRevisions(); ! $parts = array(); ! while ($revision = $iter->next()) { ! $parts[] = MimeifyPageRevision($revision); ! if ($nversions > 0 && count($parts) >= $nversions) ! break; ! } ! if (count($parts) > 1) ! return $head . MimeMultipart($parts); ! assert($parts); ! return $head . $parts[0]; } --- 30,62 ---- function MailifyPage ($page, $nversions = 1) { ! global $SERVER_ADMIN, $pagedump_format; ! ! $current = $page->getCurrentRevision(); ! $from = isset($SERVER_ADMIN) ? $SERVER_ADMIN : 'foo@bar'; ! $head = ""; ! if ($pagedump_format == 'quoted-printable') { ! $head = "From $from " . CTime(time()) . "\r\n"; ! $head .= "Subject: " . rawurlencode($page->getName()) . "\r\n"; ! $head .= "From: $from (PhpWiki)\r\n"; ! $head .= "Date: " . Rfc2822DateTime($current->get('mtime')) . "\r\n"; ! $head .= sprintf("Mime-Version: 1.0 (Produced by PhpWiki %s)\r\n", ! PHPWIKI_VERSION); ! } else { ! $head .= sprintf("Mime-Version: 1.0 (Produced by PhpWiki %s)\r\n", ! PHPWIKI_VERSION."+carsten's-binary-hack"); ! } ! $head .= "X-RCS_ID: $" ."Id" ."$" ."\r\n"; ! ! $iter = $page->getAllRevisions(); ! $parts = array(); ! while ($revision = $iter->next()) { ! $parts[] = MimeifyPageRevision($revision); ! if ($nversions > 0 && count($parts) >= $nversions) ! break; ! } ! if (count($parts) > 1) ! return $head . MimeMultipart($parts); ! assert($parts); ! return $head . $parts[0]; } *************** *** 61,70 **** * Compute filename to used for storing contents of a wiki page. * ! * Basically we do a rawurlencode() which encodes everything ! * except ASCII alphanumerics and '.', '-', and '_'. * ! * But we also want to encode leading dots to avoid filenames ! * like '.', and '..'. (Also, there's no point in generating ! * "hidden" file names, like '.foo'.) * * @param $pagename string Pagename. --- 64,73 ---- * Compute filename to used for storing contents of a wiki page. * ! * Basically we do a rawurlencode() which encodes everything except ! * ASCII alphanumerics and '.', '-', and '_'. * ! * But we also want to encode leading dots to avoid filenames like ! * '.', and '..'. (Also, there's no point in generating "hidden" file ! * names, like '.foo'.) * * @param $pagename string Pagename. *************** *** 87,99 **** { if ($request->getArg('include') == 'all') { ! $zipname = "wikidb.zip"; $include_archive = true; } else { ! $zipname = "wiki.zip"; $include_archive = false; } ! $zip = new ZipWriter("Created by PhpWiki", $zipname); --- 90,102 ---- { if ($request->getArg('include') == 'all') { ! $zipname = "wikidb.zip"; $include_archive = true; } else { ! $zipname = "wiki.zip"; $include_archive = false; } ! $zip = new ZipWriter("Created by PhpWiki", $zipname); *************** *** 102,121 **** while ($page = $pages->next()) { set_time_limit(30); // Reset watchdog. ! $current = $page->getCurrentRevision(); if ($current->getVersion() == 0) 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($page->getName()), $content, $attrib); --- 105,124 ---- while ($page = $pages->next()) { set_time_limit(30); // Reset watchdog. ! $current = $page->getCurrentRevision(); if ($current->getVersion() == 0) 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($page->getName()), $content, $attrib); *************** *** 129,145 **** if (empty($directory)) ExitWiki(_("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)) ! ExitWiki( sprintf(_("Cannot create directory '%s'"),$directory) . "<br>\n"); else ! $html = sprintf(_("Created directory '%s' for the page dump..."),$directory) . "<br>\n"; } else { $html = sprintf(_("Using directory '%s'"),$directory) . "<br>\n"; } ! StartLoadDump( _("Dumping Pages"), $html); ! $pages = $dbi->getAllPages(); --- 132,150 ---- if (empty($directory)) ExitWiki(_("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)) ! ExitWiki( sprintf(_("Cannot create directory '%s'"), ! $directory) . "<br>\n"); else ! $html = sprintf(_("Created directory '%s' for the page dump..."), ! $directory) . "<br>\n"; } else { $html = sprintf(_("Using directory '%s'"),$directory) . "<br>\n"; } ! StartLoadDump( _("Dumping Pages"), $html); ! $pages = $dbi->getAllPages(); *************** *** 148,169 **** $enc_name = htmlspecialchars($page->getName()); $filename = FilenameForPage($page->getName()); ! echo "<br>$enc_name ... "; if($page->getName() != $filename) ! echo "<small>" . sprintf(_("saved as %s"),$filename) . "</small> ... "; ! $data = MailifyPage($page); ! if ( !($fd = fopen("$directory/$filename", "w")) ) ! ExitWiki("<b>" . sprintf(_("couldn't open file '%s' for writing"),"$directory/$filename") . "</b>\n"); ! $num = fwrite($fd, $data, strlen($data)); echo "<small>" . sprintf(_("%s bytes written"),$num) . "</small>\n"; flush(); ! assert($num == strlen($data)); fclose($fd); } ! EndLoadDump(); } --- 153,176 ---- $enc_name = htmlspecialchars($page->getName()); $filename = FilenameForPage($page->getName()); ! echo "<br>$enc_name ... "; if($page->getName() != $filename) ! echo "<small>" . sprintf(_("saved as %s"),$filename) ! . "</small> ... "; ! $data = MailifyPage($page); ! if ( !($fd = fopen("$directory/$filename", "w")) ) ! ExitWiki("<b>" . sprintf(_("couldn't open file '%s' for writing"), ! "$directory/$filename") . "</b>\n"); ! $num = fwrite($fd, $data, strlen($data)); echo "<small>" . sprintf(_("%s bytes written"),$num) . "</small>\n"; flush(); ! assert($num == strlen($data)); fclose($fd); } ! EndLoadDump(); } *************** *** 177,196 **** function SavePage ($dbi, $pageinfo, $source, $filename) { ! $pagedata = $pageinfo['pagedata']; // Page level meta-data. $versiondata = $pageinfo['versiondata']; // Revision level meta-data. ! if (empty($pageinfo['pagename'])) { ! echo Element('dd'). Element('dt', QElement('b', _("Empty pagename!") )); return; } ! if (empty($versiondata['author_id'])) $versiondata['author_id'] = $versiondata['author']; $pagename = $pageinfo['pagename']; ! $content = $pageinfo['content']; ! $page = $dbi->getPage($pagename); ! foreach ($pagedata as $key => $value) { if (!empty($value)) --- 184,204 ---- function SavePage ($dbi, $pageinfo, $source, $filename) { ! $pagedata = $pageinfo['pagedata']; // Page level meta-data. $versiondata = $pageinfo['versiondata']; // Revision level meta-data. ! if (empty($pageinfo['pagename'])) { ! echo Element('dd'). Element('dt', QElement('b', ! _("Empty pagename!") )); return; } ! if (empty($versiondata['author_id'])) $versiondata['author_id'] = $versiondata['author']; $pagename = $pageinfo['pagename']; ! $content = $pageinfo['content']; ! $page = $dbi->getPage($pagename); ! foreach ($pagedata as $key => $value) { if (!empty($value)) *************** *** 218,230 **** $isnew = false; } ! if (! $skip) { $new = $page->createRevision(WIKIDB_FORCE_CREATE, $content, $versiondata, ExtractWikiPageLinks($content)); ! ! $mesg[] = sprintf(_("- saved to database as version %d"), $new->getVersion()); } ! print( Element('dt', LinkExistingWikiWord($pagename)) . QElement('dd', join(" ", $mesg)) --- 226,239 ---- $isnew = false; } ! if (! $skip) { $new = $page->createRevision(WIKIDB_FORCE_CREATE, $content, $versiondata, ExtractWikiPageLinks($content)); ! ! $mesg[] = sprintf(_("- saved to database as version %d"), ! $new->getVersion()); } ! print( Element('dt', LinkExistingWikiWord($pagename)) . QElement('dd', join(" ", $mesg)) *************** *** 237,243 **** if (!preg_match('/^a:\d+:{[si]:\d+/', $text)) return false; ! $pagehash = unserialize($text); ! // Split up pagehash into four parts: // pagename --- 246,252 ---- if (!preg_match('/^a:\d+:{[si]:\d+/', $text)) return false; ! $pagehash = unserialize($text); ! // Split up pagehash into four parts: // pagename *************** *** 248,257 **** if (!defined('FLAG_PAGE_LOCKED')) define('FLAG_PAGE_LOCKED', 1); ! $pageinfo = array('pagedata' => array(), 'versiondata' => array()); ! $pagedata = &$pageinfo['pagedata']; $versiondata = &$pageinfo['versiondata']; ! // Fill in defaults. if (empty($pagehash['pagename'])) --- 257,266 ---- if (!defined('FLAG_PAGE_LOCKED')) define('FLAG_PAGE_LOCKED', 1); ! $pageinfo = array('pagedata' => array(), 'versiondata' => array()); ! $pagedata = &$pageinfo['pagedata']; $versiondata = &$pageinfo['versiondata']; ! // Fill in defaults. if (empty($pagehash['pagename'])) *************** *** 260,264 **** $pagehash['author'] = $GLOBALS['user']->id(); ! foreach ($pagehash as $key => $value) { switch($key) { --- 269,273 ---- $pagehash['author'] = $GLOBALS['user']->id(); ! foreach ($pagehash as $key => $value) { switch($key) { *************** *** 288,292 **** function SortByPageVersion ($a, $b) { ! return $a['version'] - $b['version']; } --- 297,301 ---- function SortByPageVersion ($a, $b) { ! return $a['version'] - $b['version']; } *************** *** 295,305 **** if (!is_string($text)) { // Read the file. ! $stat = stat($filename); $mtime = $stat[9]; ! $text = implode("", file($filename)); } set_time_limit(30); // Reset watchdog. ! // FIXME: basename("filewithnoslashes") seems to return garbage sometimes. $basename = basename("/dummy/" . $filename); --- 304,314 ---- if (!is_string($text)) { // Read the file. ! $stat = stat($filename); $mtime = $stat[9]; ! $text = implode("", file($filename)); } set_time_limit(30); // Reset watchdog. ! // FIXME: basename("filewithnoslashes") seems to return garbage sometimes. $basename = basename("/dummy/" . $filename); *************** *** 307,314 **** if (!$mtime) $mtime = time(); // Last resort. ! ! $defaults = array('author' => $GLOBALS['user']->id(), 'pagename' => rawurldecode($basename)); ! $default_pagename = rawurldecode($basename); --- 316,323 ---- if (!$mtime) $mtime = time(); // Last resort. ! ! $defaults = array('author' => $GLOBALS['user']->id(), 'pagename' => rawurldecode($basename)); ! $default_pagename = rawurldecode($basename); *************** *** 316,323 **** usort($parts, 'SortByPageVersion'); foreach ($parts as $pageinfo) ! SavePage($dbi, $pageinfo, sprintf(_("MIME file %s"),$filename), $basename); } else if ( ($pageinfo = ParseSerializedPage($text, $default_pagename)) ) { ! SavePage($dbi, $pageinfo, sprintf(_("Serialized file %s"),$filename), $basename); } else { --- 325,334 ---- usort($parts, 'SortByPageVersion'); foreach ($parts as $pageinfo) ! SavePage($dbi, $pageinfo, sprintf(_("MIME file %s"),$filename), ! $basename); } else if ( ($pageinfo = ParseSerializedPage($text, $default_pagename)) ) { ! SavePage($dbi, $pageinfo, sprintf(_("Serialized file %s"),$filename), ! $basename); } else { *************** *** 327,334 **** 'versiondata' => array('author' => $GLOBALS['user']->id()), ! 'content' ! => preg_replace('/[ \t\r]*\n/', "\n", chop($text)) ); ! SavePage($dbi, $pageinfo, sprintf(_("plain file %s"),$filename), $basename); } } --- 338,346 ---- 'versiondata' => array('author' => $GLOBALS['user']->id()), ! 'content' => preg_replace('/[ \t\r]*\n/', "\n", ! chop($text)) ); ! SavePage($dbi, $pageinfo, sprintf(_("plain file %s"),$filename), ! $basename); } } *************** *** 338,352 **** $zip = new ZipReader($zipfile); while (list ($fn, $data, $attrib) = $zip->readFile()) ! { ! // FIXME: basename("filewithnoslashes") seems to return garbage sometimes. ! $fn = basename("/dummy/" . $fn); ! if ( ($files && !in_array($fn, $files)) ! || ($exclude && in_array($fn, $exclude)) ) ! { ! print Element('dt', LinkExistingWikiWord($fn)) . QElement('dd', _("Skipping")); ! continue; ! } ! ! LoadFile($dbi, $fn, $data, $attrib['mtime']); } } --- 350,365 ---- $zip = new ZipReader($zipfile); while (list ($fn, $data, $attrib) = $zip->readFile()) ! { ! // FIXME: basename("filewithnoslashes") seems to return garbage sometimes. ! $fn = basename("/dummy/" . $fn); ! if ( ($files && !in_array($fn, $files)) ! || ($exclude && in_array($fn, $exclude)) ) ! { ! print Element('dt', LinkExistingWikiWord($fn)) ! . QElement('dd', _("Skipping")); ! continue; ! } ! ! LoadFile($dbi, $fn, $data, $attrib['mtime']); } } *************** *** 354,430 **** function LoadDir ($dbi, $dirname, $files = false, $exclude = false) { ! $handle = opendir($dir = $dirname); ! while ($fn = readdir($handle)) ! { ! if ($fn[0] == '.' || filetype("$dir/$fn") != 'file') ! continue; ! ! if ( ($files && !in_array($fn, $files)) ! || ($exclude && in_array($fn, $exclude)) ) ! { ! print Element('dt', LinkExistingWikiWord($fn)) . QElement('dd', _("Skipping")); ! continue; ! } ! ! LoadFile($dbi, "$dir/$fn"); ! } ! closedir($handle); } function IsZipFile ($filename_or_fd) { ! // See if it looks like zip file ! if (is_string($filename_or_fd)) ! { ! $fd = fopen($filename_or_fd, "rb"); ! $magic = fread($fd, 4); ! fclose($fd); ! } ! else ! { ! $fpos = ftell($filename_or_fd); ! $magic = fread($filename_or_fd, 4); ! fseek($filename_or_fd, $fpos); ! } ! ! return $magic == ZIP_LOCHEAD_MAGIC || $magic == ZIP_CENTHEAD_MAGIC; } ! function LoadAny ($dbi, $file_or_dir, $files = false, $exclude = false) { // FIXME: This is a partial workaround for sf bug #501145 ! if (substr_count($file_or_dir,"/") < 1) $type = filetype(rawurlencode($file_or_dir)); ! else { ! $type = filetype($file_or_dir); } ! ! if ($type == 'dir') ! { ! LoadDir($dbi, $file_or_dir, $files, $exclude); ! } ! else if ($type != 'file' && !preg_match('/^(http|ftp):/', $file_or_dir)) ! { ! ExitWiki( sprintf(_("Bad file type: %s"),$type) ); ! } ! else if (IsZipFile($file_or_dir)) ! { ! LoadZip($dbi, $file_or_dir, $files, $exclude); ! } ! else /* if (!$files || in_array(basename($file_or_dir), $files)) */ ! { ! LoadFile($dbi, $file_or_dir); ! } } function LoadFileOrDir ($dbi, $request) { ! $source = $request->getArg('source'); ! StartLoadDump( sprintf(_("Loading '%s'"),$source) ); ! echo "<dl>\n"; ! LoadAny($dbi, $source/*, false, array(gettext("RecentChanges"))*/); ! echo "</dl>\n"; ! EndLoadDump(); } --- 367,442 ---- function LoadDir ($dbi, $dirname, $files = false, $exclude = false) { ! $handle = opendir($dir = $dirname); ! while ($fn = readdir($handle)) ! { ! if ($fn[0] == '.' || filetype("$dir/$fn") != 'file') ! continue; ! ! if ( ($files && !in_array($fn, $files)) ! || ($exclude && in_array($fn, $exclude)) ) ! { ! print Element('dt', LinkExistingWikiWord($fn)) ! . QElement('dd', _("Skipping")); ! continue; ! } ! ! LoadFile($dbi, "$dir/$fn"); ! } ! closedir($handle); } function IsZipFile ($filename_or_fd) { ! // See if it looks like zip file ! if (is_string($filename_or_fd)) ! { ! $fd = fopen($filename_or_fd, "rb"); ! $magic = fread($fd, 4); ! fclose($fd); ! } ! else ! { ! $fpos = ftell($filename_or_fd); ! $magic = fread($filename_or_fd, 4); ! fseek($filename_or_fd, $fpos); ! } ! ! return $magic == ZIP_LOCHEAD_MAGIC || $magic == ZIP_CENTHEAD_MAGIC; } ! function LoadAny ($dbi, $file_or_dir, $files = false, $exclude = false) { // FIXME: This is a partial workaround for sf bug #501145 ! if (substr_count($file_or_dir,"/") < 1) { $type = filetype(rawurlencode($file_or_dir)); ! } else { ! $type = filetype($file_or_dir); } ! ! if ($type == 'dir') { ! LoadDir($dbi, $file_or_dir, $files, $exclude); ! } ! else if ($type != 'file' && !preg_match('/^(http|ftp):/', $file_or_dir)) ! { ! ExitWiki( sprintf(_("Bad file type: %s"),$type) ); ! } ! else if (IsZipFile($file_or_dir)) { ! LoadZip($dbi, $file_or_dir, $files, $exclude); ! } ! else /* if (!$files || in_array(basename($file_or_dir), $files)) */ ! { ! LoadFile($dbi, $file_or_dir); ! } } function LoadFileOrDir ($dbi, $request) { ! $source = $request->getArg('source'); ! StartLoadDump( sprintf(_("Loading '%s'"),$source) ); ! echo "<dl>\n"; ! LoadAny($dbi, $source/*, false, array(gettext("RecentChanges"))*/); ! echo "</dl>\n"; ! EndLoadDump(); } *************** *** 432,446 **** { global $GenericPages, $LANG, $user; ! //FIXME: This is a hack $user->userid = _("The PhpWiki programming team"); ! StartLoadDump(_("Loading up virgin wiki")); echo "<dl>\n"; ! LoadAny($dbi, FindLocalizedFile(WIKI_PGSRC)/*, false, $ignore*/); if ($LANG != "C") ! LoadAny($dbi, FindFile(DEFAULT_WIKI_PGSRC), $GenericPages/*, $ignore*/); ! echo "</dl>\n"; EndLoadDump(); --- 444,459 ---- { global $GenericPages, $LANG, $user; ! //FIXME: This is a hack $user->userid = _("The PhpWiki programming team"); ! StartLoadDump(_("Loading up virgin wiki")); echo "<dl>\n"; ! LoadAny($dbi, FindLocalizedFile(WIKI_PGSRC)/*, false, $ignore*/); if ($LANG != "C") ! LoadAny($dbi, FindFile(DEFAULT_WIKI_PGSRC), ! $GenericPages/*, $ignore*/); ! echo "</dl>\n"; EndLoadDump(); *************** *** 450,461 **** { $upload = $request->getUploadedFile('file'); ! if (!$upload) ExitWiki(_("No uploaded file to upload?")); ! // Dump http headers. StartLoadDump( sprintf(_("Uploading %s"),$upload->getName()) ); echo "<dl>\n"; ! $fd = $upload->open(); if (IsZipFile($fd)) --- 463,475 ---- { $upload = $request->getUploadedFile('file'); ! if (!$upload) + // FIXME: better message? ExitWiki(_("No uploaded file to upload?")); ! // Dump http headers. StartLoadDump( sprintf(_("Uploading %s"),$upload->getName()) ); echo "<dl>\n"; ! $fd = $upload->open(); if (IsZipFile($fd)) *************** *** 463,467 **** else Loadfile($dbi, $upload->getName(), $upload->getContents()); ! echo "</dl>\n"; EndLoadDump(); --- 477,481 ---- else Loadfile($dbi, $upload->getName(), $upload->getContents()); ! echo "</dl>\n"; EndLoadDump(); |