From: <car...@us...> - 2025-02-19 23:04:43
|
Revision: 11153 http://sourceforge.net/p/phpwiki/code/11153 Author: carstenklapp Date: 2025-02-19 23:04:42 +0000 (Wed, 19 Feb 2025) Log Message: ----------- Merged functions DumpToDir and DumpSVNToDir. Added file counter to DumpToDir. Don't overwrite existing files. Reformat progress output. Cleanup strings for translation Modified Paths: -------------- trunk/lib/loadsave.php trunk/lib/main.php Modified: trunk/lib/loadsave.php =================================================================== --- trunk/lib/loadsave.php 2025-02-19 21:46:05 UTC (rev 11152) +++ trunk/lib/loadsave.php 2025-02-19 23:04:42 UTC (rev 11153) @@ -319,146 +319,13 @@ exit; } -/** - * @param WikiRequest $request - */ -function DumpSVNToDir(&$request) //this is mostly a copy of DumpToDir -{ - $directory = $request->getArg('directory'); - if (empty($directory)) { - $directory = DEFAULT_DUMP_DIR; - } - if (empty($directory)) { - $html = HTML::p( - array('class' => 'error'), - _("You must specify a directory to dump to") - ); - StartLoadDump($request, _("Dumping Pages for developer"), $html); - EndLoadDump($request); - return; - } - - // see if we can access the directory the user wants us to use - if (!file_exists($directory)) { - if (!mkdir_p($directory, 0755)) { - $html = HTML::p( - array('class' => 'error'), - fmt("Cannot create directory “%s”", $directory) - ); - StartLoadDump($request, _("Dumping Pages for developer"), $html); - EndLoadDump($request); - return; - } else { - $html = HTML::p(fmt( - "Created directory “%s” for the page dump...", - $directory - )); - } - } elseif (!is_writable($directory)) { - $html = HTML::p( - array('class' => 'error'), - fmt( - "Cannot use directory “%s”, it is not writable", - $directory - ) - ); - StartLoadDump($request, _("Dumping pages for SVN"), $html); - EndLoadDump($request); - return; - } else { - $html = HTML::p(fmt("Using directory “%s”", $directory)); - } - - StartLoadDump($request, _("Dumping pages for SVN"), $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(); - } - $include_empty = false; - if ($request->getArg('include') == 'empty') { - $include_empty = true; - } - 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($include_empty, 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(); - PrintXML(HTML::br(), $pagename, ' ... '); - flush(); - - if (in_array($pagename, $excludeList)) { - PrintXML(_("Skipped")); - flush(); - continue; - } - //$filename = FilenameForPage($pagename, 'dumpsvn');//why doesn't this workzzz - $filename = rawurlencode($pagename);//this works - $msg = HTML(); - if ($page->getName() != $filename) { - $msg->pushContent( - HTML::small(fmt("saved as %s", $filename)), - " ... " - ); - } - - if ($request->getArg('include') == 'all') { - $data = MailifyPage($page, 0, true); - } else { - $data = MailifyPage($page, 1, true); - } - - 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))); - PrintXML($msg); - flush(); - assert($num == strlen($data)); - fclose($fd); - - $current = $page->getCurrentRevision(false); - $author=$current->get('author'); - if (isPhpWikiTeam($author)) { //default_pgsrc_hasnotbeenmodified - $creationdate = $page->get('date'); - echo (" (unmodified default page)"); - // echo " DEBUG: setting as Creation Date: " . Rfc2822DateTime($creationdate) . " " . $creationdate . "\n"; - touch($directory . "/" . $filename, $creationdate); - } else { - $moddate = $current->get('mtime'); - // echo " DEBUG: setting as Modification Date: " . Rfc2822DateTime($moddate) . " " . $moddate . "\n"; - touch($directory . "/" . $filename, $moddate); - } - } - - EndLoadDump($request); -} - function isPhpWikiTeam($author) { - $translated_teamnames = array( //do not mark these with _() + // Do not mark these for translation with _() + // More will have to be manually added as translators add to it + $translated_teamnames = array( "The PhpWiki Team", //en - "Das PhpWiki Team" //de + "Das PhpWiki-Team", //de + "L'équipe PhpWiki" //fr ); return in_array($author, $translated_teamnames, true); } @@ -468,6 +335,12 @@ */ function DumpToDir(&$request) { + $forsvn = false; + $title = _("Dumping Pages"); + if ($request->getArg('action') == 'dumpsvn') { + $forsvn = true; + $title = _("Dumping Pages for SVN"); + } $directory = $request->getArg('directory'); if (empty($directory)) { $directory = DEFAULT_DUMP_DIR; @@ -475,9 +348,9 @@ if (empty($directory)) { $html = HTML::p( array('class' => 'error'), - _("You must specify a directory to dump to") + _("You must specify a directory to dump to.") ); - StartLoadDump($request, _("Dumping Pages"), $html); + StartLoadDump($request, $title, $html); EndLoadDump($request); return; } @@ -487,14 +360,14 @@ if (!mkdir_p($directory, 0755)) { $html = HTML::p( array('class' => 'error'), - fmt("Cannot create directory “%s”", $directory) + fmt("Cannot create directory “%s”.", $directory) ); - StartLoadDump($request, _("Dumping Pages"), $html); + StartLoadDump($request, $title, $html); EndLoadDump($request); return; } else { $html = HTML::p(fmt( - "Created directory “%s” for the page dump...", + _("Created directory “%s” for the page dump..."), $directory )); } @@ -502,18 +375,18 @@ $html = HTML::p( array('class' => 'error'), fmt( - "Cannot use directory “%s”, it is not writable", + _("Cannot use directory “%s”, it is not writable."), $directory ) ); - StartLoadDump($request, _("Dumping Pages"), $html); + StartLoadDump($request, $title, $html); EndLoadDump($request); return; } else { - $html = HTML::p(fmt("Using directory “%s”", $directory)); + $html = HTML::p(fmt(_("Using directory “%s”"), $directory)); } - StartLoadDump($request, _("Dumping Pages"), $html); + StartLoadDump($request, $title, $html); $dbi =& $request->_dbi; $thispage = $request->getArg('pagename'); // for "Return to ..." @@ -537,66 +410,107 @@ $request_args = $request->args; $timeout = (!$request->getArg('start_debug')) ? 30 : 240; + PrintXML(HTML::hr()); + $counttotal = 0; + $countsaved = 0; + $countskipped = 0; + $countexcluded = 0; + $SEP = ' ... '; while ($page = $page_iter->next()) { + $counttotal++; $request->args = $request_args; // some plugins might change them (esp. on POST) longer_timeout($timeout); // Reset watchdog $pagename = $page->getName(); - PrintXML(HTML::br(), $pagename, ' ... '); + echo "\n"; + PrintXML(HTML::br(), $pagename, $SEP); flush(); if (in_array($pagename, $excludeList)) { - PrintXML(_("Skipped")); + PrintXML(_("Excluded")); flush(); + $countexcluded++; + echo "\n"; continue; } - //$filename = FilenameForPage($pagename, 'dumpserial');//why doesn't this workzzz + //$filename = FilenameForPage($pagename, $forsvn ? 'dumpsvn', 'dumpserial');//why doesn't this workzzz $filename = rawurlencode($pagename);//this works $msg = HTML(); if ($page->getName() != $filename) { $msg->pushContent( - HTML::small(fmt("saved as %s", $filename)), - " ... " + HTML::small(fmt("naming as %s", $filename)), + $SEP ); } - if ($request->getArg('include') == 'all') { - $data = MailifyPage($page, 0); + // Fixme: the way MailifyPage is called is nasty + if ($forsvn) { + if ($request->getArg('include') == 'all') { + $data = MailifyPage($page, 0, true); + } else { + $data = MailifyPage($page, 1, true); + } } else { - $data = MailifyPage($page); + if ($request->getArg('include') == 'all') { + $data = MailifyPage($page, 0); + } else { + $data = MailifyPage($page); + } } + // Do not overwrite files + if (file_exists($directory . "/" . $filename)) { + $msg->pushContent(HTML::span(_( + _("skipping existing file.") + ))); + //$request->finish($msg); + PrintXML($msg); + $countskipped++; + continue; + } if (!($fd = fopen($directory . "/" . $filename, "wb"))) { - $msg->pushContent(HTML::strong(fmt( - "couldn't open file “%s” for writing", - "$directory/$filename" + $msg->pushContent($SEP, HTML::span(_( + _("couldn't open file for writing") ))); + //$request->finish($msg); + PrintXML($msg); + flush(); + $countskipped++; + // echo "\n"; + continue; + } + if (!$fd) { + echo("\nDEBUG error: fd missing. should not get here!\n"); $request->finish($msg); } $num = fwrite($fd, $data, strlen($data)); - $msg->pushContent(HTML::small(fmt("%s bytes written", $num))); - PrintXML($msg); - flush(); + $msg->pushContent(HTML::strong(fmt(_("%s bytes written"), $num))); assert($num == strlen($data)); fclose($fd); + $countsaved++; $current = $page->getCurrentRevision(false); $author=$current->get('author'); if (isPhpWikiTeam($author)) { //default_pgsrc_hasnotbeenmodified $creationdate = $page->get('date'); - echo (" (unmodified default page)"); + assert($creationdate!=0); // echo " DEBUG: setting as Creation Date: " . Rfc2822DateTime($creationdate) . " " . $creationdate . "\n"; touch($directory . "/" . $filename, $creationdate); + $msg->pushContent(HTML::em($SEP, _("(unmodified default page)"))); } else { $moddate = $current->get('mtime'); // echo " DEBUG: setting as Modification Date: " . Rfc2822DateTime($moddate) . " " . $moddate . "\n"; touch($directory . "/" . $filename, $moddate); } - - + PrintXML($msg); + flush(); } + $msg = HTML::hr(); + $msg->pushContent(HTML::p(fmt(_("Total pages: %d, Saved: %d, Skipped: %d, Excluded: %d"), $counttotal, $countsaved, $countskipped, $countexcluded))); + PrintXML($msg); + //flush(); EndLoadDump($request); } @@ -658,10 +572,10 @@ // See if we can access the directory the user wants us to use if (!file_exists($directory)) { if (!mkdir_p($directory, 0755)) { - $request->finish(fmt("Cannot create directory “%s”", $directory)); + $request->finish(fmt(_("Cannot create directory “%s”."), $directory)); } else { $html = HTML::p(fmt( - "Created directory “%s” for the page dump...", + _("Created directory “%s” for the page dump..."), $directory )); } @@ -864,7 +778,7 @@ } if (in_array($pagename, $excludeList)) { if (!$silent) { - PrintXML(_("Skipped")); + PrintXML(_("Excluded")); flush(); } continue; @@ -941,7 +855,7 @@ $outfile = $directory . "/" . $filename; if (!($fd = fopen($outfile, "wb"))) { $msg->pushContent(HTML::strong(fmt( - "couldn't open file “%s” for writing", + _("couldn't open file “%s” for writing."), $outfile ))); $request->finish($msg); Modified: trunk/lib/main.php =================================================================== --- trunk/lib/main.php 2025-02-19 21:46:05 UTC (rev 11152) +++ trunk/lib/main.php 2025-02-19 23:04:42 UTC (rev 11153) @@ -1390,7 +1390,7 @@ public function action_dumpsvn() { include_once 'lib/loadsave.php'; - DumpSVNToDir($this); + DumpToDir($this); } public function action_dumpserial() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |