]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/loadsave.php
pass exclude to the get_all_pages backend
[SourceForge/phpwiki.git] / lib / loadsave.php
1 <?php //-*-php-*-
2 rcs_id('$Id: loadsave.php,v 1.129 2004-11-25 08:11:40 rurban Exp $');
3
4 /*
5  Copyright 1999, 2000, 2001, 2002, 2004 $ThePhpWikiProgrammingTeam
6
7  This file is part of PhpWiki.
8
9  PhpWiki is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13
14  PhpWiki is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with PhpWiki; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24
25 require_once("lib/ziplib.php");
26 require_once("lib/Template.php");
27
28 /**
29  * ignore fatal errors during dump
30  */
31 function _dump_error_handler(&$error) {
32     if ($error->isFatal()) {
33         $error->errno = E_USER_WARNING;
34         return true;
35     }
36     return true;         // Ignore error
37     /*
38     if (preg_match('/Plugin/', $error->errstr))
39         return true;
40     */
41     // let the message come through: call the remaining handlers:
42     // return false; 
43 }
44
45 function StartLoadDump(&$request, $title, $html = '')
46 {
47     // MockRequest is from the unit testsuite, a faked request. (may be cmd-line)
48     // We are silent on unittests.
49     if (isa($request,'MockRequest'))
50         return;
51     // FIXME: This is a hack. This really is the worst overall hack in phpwiki.
52     if ($html)
53         $html->pushContent('%BODY%');
54     $tmpl = Template('html', array('TITLE' => $title,
55                                    'HEADER' => $title,
56                                    'CONTENT' => $html ? $html : '%BODY%'));
57     echo ereg_replace('%BODY%.*', '', $tmpl->getExpansion($html));
58     $request->chunkOutput();
59     
60     // set marker for sendPageChangeNotification()
61     $request->_deferredPageChangeNotification = array();
62 }
63
64 function EndLoadDump(&$request)
65 {
66     if (isa($request,'MockRequest'))
67         return;
68     $action = $request->getArg('action');
69     $label = '';
70     switch ($action) {
71     case 'zip':        $label = _("ZIP files of database"); break;
72     case 'dumpserial': $label = _("Dump to directory"); break;
73     case 'upload':     $label = _("Upload File"); break;
74     case 'loadfile':   $label = _("Load File"); break;
75     case 'upgrade':    $label = _("Upgrade"); break;
76     case 'dumphtml': 
77     case 'ziphtml':    $label = _("Dump pages as XHTML"); break;
78     }
79     if ($label) $label = str_replace(" ","_",$label);
80     if ($action == 'browse') // loading virgin 
81         $pagelink = WikiLink(HOME_PAGE);
82     else
83         $pagelink = WikiLink(new WikiPageName(_("PhpWikiAdministration"),false,$label));
84
85     // do deferred sendPageChangeNotification()
86     if (!empty($request->_deferredPageChangeNotification)) {
87         $pages = $all_emails = $all_users = array();
88         foreach ($request->_deferredPageChangeNotification as $p) {
89             list($pagename, $emails, $userids) = $p;
90             $pages[] = $pagename;
91             $all_emails = array_unique(array_merge($all_emails, $emails));
92             $all_users = array_unique(array_merge($all_users, $userids));
93         }
94         $editedby = sprintf(_("Edited by: %s"), $request->_user->getId());
95         $content = "Loaded the following pages:\n" . join("\n", $pages);
96         if (mail(join(',',$all_emails),"[".WIKI_NAME."] "._("LoadDump"), 
97                  _("LoadDump")."\n".
98                  $editedby."\n\n".
99                  $content))
100             trigger_error(sprintf(_("PageChange Notification sent to %s"),
101                                   join(',',$all_users)), E_USER_NOTICE);
102         else
103             trigger_error(sprintf(_("PageChange Notification Error: Couldn't send to %s"),
104                                   join(',',$all_users)), E_USER_WARNING);
105         unset($pages);
106         unset($all_emails);
107         unset($all_users);
108     }
109     unset($request->_deferredPageChangeNotification);
110
111     PrintXML(HTML::p(HTML::strong(_("Complete."))),
112              HTML::p(fmt("Return to %s", $pagelink)));
113     echo "</body></html>\n";
114 }
115
116
117 ////////////////////////////////////////////////////////////////
118 //
119 //  Functions for dumping.
120 //
121 ////////////////////////////////////////////////////////////////
122
123 /**
124  * For reference see:
125  * http://www.nacs.uci.edu/indiv/ehood/MIME/2045/rfc2045.html
126  * http://www.faqs.org/rfcs/rfc2045.html
127  * (RFC 1521 has been superceeded by RFC 2045 & others).
128  *
129  * Also see http://www.faqs.org/rfcs/rfc2822.html
130  */
131 function MailifyPage ($page, $nversions = 1)
132 {
133     $current = $page->getCurrentRevision();
134     $head = '';
135
136     if (STRICT_MAILABLE_PAGEDUMPS) {
137         $from = defined('SERVER_ADMIN') ? SERVER_ADMIN : 'foo@bar';
138         //This is for unix mailbox format: (not RFC (2)822)
139         // $head .= "From $from  " . CTime(time()) . "\r\n";
140         $head .= "Subject: " . rawurlencode($page->getName()) . "\r\n";
141         $head .= "From: $from (PhpWiki)\r\n";
142         // RFC 2822 requires only a Date: and originator (From:)
143         // field, however the obsolete standard RFC 822 also
144         // requires a destination field.
145         $head .= "To: $from (PhpWiki)\r\n";
146     }
147     $head .= "Date: " . Rfc2822DateTime($current->get('mtime')) . "\r\n";
148     $head .= sprintf("Mime-Version: 1.0 (Produced by PhpWiki %s)\r\n",
149                      PHPWIKI_VERSION);
150
151     // This should just be entered by hand (or by script?)
152     // in the actual pgsrc files, since only they should have
153     // RCS ids.
154     //$head .= "X-Rcs-Id: \$Id\$\r\n";
155
156     $iter = $page->getAllRevisions();
157     $parts = array();
158     while ($revision = $iter->next()) {
159         $parts[] = MimeifyPageRevision($revision);
160         if ($nversions > 0 && count($parts) >= $nversions)
161             break;
162     }
163     if (count($parts) > 1)
164         return $head . MimeMultipart($parts);
165     assert($parts);
166     return $head . $parts[0];
167 }
168
169 /***
170  * Compute filename to used for storing contents of a wiki page.
171  *
172  * Basically we do a rawurlencode() which encodes everything except
173  * ASCII alphanumerics and '.', '-', and '_'.
174  *
175  * But we also want to encode leading dots to avoid filenames like
176  * '.', and '..'. (Also, there's no point in generating "hidden" file
177  * names, like '.foo'.)
178  *
179  * @param $pagename string Pagename.
180  * @return string Filename for page.
181  */
182 function FilenameForPage ($pagename)
183 {
184     $enc = rawurlencode($pagename);
185     return preg_replace('/^\./', '%2e', $enc);
186 }
187
188 /**
189  * The main() function which generates a zip archive of a PhpWiki.
190  *
191  * If $include_archive is false, only the current version of each page
192  * is included in the zip file; otherwise all archived versions are
193  * included as well.
194  */
195 function MakeWikiZip (&$request)
196 {
197     if ($request->getArg('include') == 'all') {
198         $zipname         = WIKI_NAME . _("FullDump") . date('Ymd-Hi') . '.zip';
199         $include_archive = true;
200     }
201     else {
202         $zipname         = WIKI_NAME . _("LatestSnapshot") . date('Ymd-Hi') . '.zip';
203         $include_archive = false;
204     }
205
206
207     $zip = new ZipWriter("Created by PhpWiki " . PHPWIKI_VERSION, $zipname);
208
209     /* ignore fatals in plugins */
210     if (check_php_version(4,1)) {
211         global $ErrorManager;
212         $ErrorManager->pushErrorHandler(new WikiFunctionCb('_dump_error_handler'));
213     }
214
215     $dbi = $request->getDbh();
216     $thispage = $request->getArg('pagename'); // for "Return to ..."
217     if ($exclude = $request->getArg('exclude')) {   // exclude which pagenames
218         $excludeList = explodePageList($exclude); 
219     } else {
220         $excludeList = array();
221     }
222     if ($whichpages = $request->getArg('pages')) {  // which pagenames
223         if ($whichpages == '[]') // current page
224             $whichpages = $thispage;
225         $pages = new WikiDB_Array_PageIterator(explodePageList($whichpages));
226     } else {
227         $pages = $dbi->getAllPages(false,false,false,$excludeList);
228     }
229     $request_args = $request->args;
230     
231     while ($page = $pages->next()) {
232         $request->args = $request_args; // some plugins might change them (esp. on POST)
233         if (! $request->getArg('start_debug'))
234             @set_time_limit(30); // Reset watchdog
235         else    
236             @set_time_limit(240);
237
238         $current = $page->getCurrentRevision();
239         if ($current->getVersion() == 0)
240             continue;
241
242         $pagename = $page->getName();
243         $wpn = new WikiPageName($pagename);
244         if (!$wpn->isValid())
245             continue;
246         if (in_array($page->getName(), $excludeList)) {
247             continue;
248         }
249
250         $attrib = array('mtime'    => $current->get('mtime'),
251                         'is_ascii' => 1);
252         if ($page->get('locked'))
253             $attrib['write_protected'] = 1;
254
255         if ($include_archive)
256             $content = MailifyPage($page, 0);
257         else
258             $content = MailifyPage($page);
259
260         $zip->addRegularFile( FilenameForPage($pagename),
261                               $content, $attrib);
262     }
263     $zip->finish();
264     if (check_php_version(4,1)) {
265         global $ErrorManager;
266         $ErrorManager->popErrorHandler();
267     }
268 }
269
270 function DumpToDir (&$request)
271 {
272     $directory = $request->getArg('directory');
273     if (empty($directory))
274         $directory = DEFAULT_DUMP_DIR; // See lib/plugin/WikiForm.php:87
275     if (empty($directory))
276         $request->finish(_("You must specify a directory to dump to"));
277
278     // see if we can access the directory the user wants us to use
279     if (! file_exists($directory)) {
280         if (! mkdir($directory, 0755))
281             $request->finish(fmt("Cannot create directory '%s'", $directory));
282         else
283             $html = HTML::p(fmt("Created directory '%s' for the page dump...",
284                                 $directory));
285     } else {
286         $html = HTML::p(fmt("Using directory '%s'", $directory));
287     }
288
289     StartLoadDump($request, _("Dumping Pages"), $html);
290
291     $dbi = $request->getDbh();
292     $thispage = $request->getArg('pagename'); // for "Return to ..."
293     if ($exclude = $request->getArg('exclude')) {   // exclude which pagenames
294         $excludeList = explodePageList($exclude); 
295     } else {
296         $excludeList = array();
297     }
298     if ($whichpages = $request->getArg('pages')) {  // which pagenames
299         if ($whichpages == '[]') // current page
300             $whichpages = $thispage;
301         $pages = new WikiDB_Array_PageIterator(explodePageList($whichpages));
302     } else {
303         $pages = $dbi->getAllPages(false,false,false,$excludeList);
304     }
305
306     $request_args = $request->args;
307     
308     while ($page = $pages->next()) {
309         $request->args = $request_args; // some plugins might change them (esp. on POST)
310         if (! $request->getArg('start_debug'))
311             @set_time_limit(30); // Reset watchdog.
312         else    
313             @set_time_limit(240);
314
315         $pagename = $page->getName();
316         if (!isa($request,'MockRequest')) {
317             PrintXML(HTML::br(), $pagename, ' ... ');
318             flush();
319         }
320
321         if (in_array($pagename, $excludeList)) {
322             if (!isa($request,'MockRequest')) {
323                 PrintXML(_("Skipped."));
324                 flush();
325             }
326             continue;
327         }
328         $filename = FilenameForPage($pagename);
329         $msg = HTML();
330         if($page->getName() != $filename) {
331             $msg->pushContent(HTML::small(fmt("saved as %s", $filename)),
332                               " ... ");
333         }
334
335         if ($request->getArg('include') == 'all')
336             $data = MailifyPage($page, 0);
337         else
338             $data = MailifyPage($page);
339
340         if ( !($fd = fopen($directory."/".$filename, "wb")) ) {
341             $msg->pushContent(HTML::strong(fmt("couldn't open file '%s' for writing",
342                                                "$directory/$filename")));
343             $request->finish($msg);
344         }
345
346         $num = fwrite($fd, $data, strlen($data));
347         $msg->pushContent(HTML::small(fmt("%s bytes written", $num)));
348         if (!isa($request,'MockRequest')) {
349             PrintXML($msg);
350             flush();
351         }
352         assert($num == strlen($data));
353         fclose($fd);
354     }
355
356     EndLoadDump($request);
357 }
358
359 /**
360  * Dump all pages as XHTML to a directory, as pagename.html.
361  * Copies all used css files to the directory, all used images to a 
362  * "images" subdirectory, and all used buttons to a "images/buttons" subdirectory.
363  * The webserver must have write permissions to these directories. 
364  *   chown httpd HTML_DUMP_DIR; chmod u+rwx HTML_DUMP_DIR 
365  * should be enough.
366  *
367  * @param string directory (optional) path to dump to. Default: HTML_DUMP_DIR
368  * @param string pages     (optional) Comma-seperated of glob-style pagenames to dump
369  * @param string exclude   (optional) Comma-seperated of glob-style pagenames to exclude
370  */
371 function DumpHtmlToDir (&$request)
372 {
373     $directory = $request->getArg('directory');
374     if (empty($directory))
375         $directory = HTML_DUMP_DIR; // See lib/plugin/WikiForm.php:87
376     if (empty($directory))
377         $request->finish(_("You must specify a directory to dump to"));
378
379     // see if we can access the directory the user wants us to use
380     if (! file_exists($directory)) {
381         if (! mkdir($directory, 0755))
382             $request->finish(fmt("Cannot create directory '%s'", $directory));
383         else
384             $html = HTML::p(fmt("Created directory '%s' for the page dump...",
385                                 $directory));
386     } else {
387         $html = HTML::p(fmt("Using directory '%s'", $directory));
388     }
389     $request->_TemplatesProcessed = array();
390     StartLoadDump($request, _("Dumping Pages"), $html);
391     $thispage = $request->getArg('pagename'); // for "Return to ..."
392
393     $dbi =& $request->_dbi;
394     if ($exclude = $request->getArg('exclude')) {   // exclude which pagenames
395         $excludeList = explodePageList($exclude); 
396     } else {
397         $excludeList = array();
398     }
399     if ($whichpages = $request->getArg('pages')) {  // which pagenames
400         if ($whichpages == '[]') // current page
401             $whichpages = $thispage;
402         $pages = new WikiDB_Array_PageIterator(explodePageList($whichpages));
403     } else {
404         $pages = $dbi->getAllPages(false,false,false,$excludeList);
405     }
406
407     global $WikiTheme;
408     if (defined('HTML_DUMP_SUFFIX'))
409         $WikiTheme->HTML_DUMP_SUFFIX = HTML_DUMP_SUFFIX;
410     $WikiTheme->DUMP_MODE = 'HTML';
411     $request_args = $request->args;
412
413     // check if the dumped file will be accessible from outside
414     $doc_root = $request->get("DOCUMENT_ROOT");
415     $ldir = NormalizeLocalFileName($directory);
416     $wikiroot = NormalizeLocalFileName('');
417     if (string_starts_with($ldir, $doc_root)) {
418         $link_prefix = substr($directory, strlen($doc_root))."/";
419     } elseif (string_starts_with($ldir, $wikiroot)) {
420         $link_prefix = NormalizeWebFileName(substr($directory, strlen($wikiroot)))."/";
421     } else {
422         $prefix = '';
423         if (isWindows()) {
424             $prefix = '/' . substr($doc_root,0,2); // add drive where apache is installed
425         }
426         $link_prefix = "file://".$prefix.$directory."/";
427     }
428     
429     while ($page = $pages->next()) {
430         $request->args = $request_args; // some plugins might change them (esp. on POST)
431         if (! $request->getArg('start_debug'))
432             @set_time_limit(30); // Reset watchdog.
433         else    
434             @set_time_limit(240);
435           
436         $pagename = $page->getName();
437         if (!isa($request,'MockRequest')) {
438             PrintXML(HTML::br(), $pagename, ' ... ');
439             flush();
440         }
441         if (in_array($pagename, $excludeList)) {
442             if (!isa($request,'MockRequest')) {
443                 PrintXML(_("Skipped."));
444                 flush();
445             }
446             continue;
447         }
448
449         $request->setArg('pagename', $pagename); // Template::_basepage fix
450         $filename = FilenameForPage($pagename) . $WikiTheme->HTML_DUMP_SUFFIX;
451         $msg = HTML();
452
453         $revision = $page->getCurrentRevision();
454         $template = new Template('browse', $request,
455                                  array('revision' => $revision,
456                                        'CONTENT' => $revision->getTransformedContent()));
457
458         $data = GeneratePageasXML($template, $pagename);
459
460         if ( !($fd = fopen($directory."/".$filename, "wb")) ) {
461             $msg->pushContent(HTML::strong(fmt("couldn't open file '%s' for writing",
462                                                "$directory/$filename")));
463             $request->finish($msg);
464         }
465         $num = fwrite($fd, $data, strlen($data));
466         if ($page->getName() != $filename) {
467             $link = LinkURL($link_prefix.$filename, $filename);
468             $msg->pushContent(HTML::small(_("saved as "), $link, " ... "));
469         }
470         $msg->pushContent(HTML::small(fmt("%s bytes written", $num), "\n"));
471         if (!isa($request,'MockRequest')) {
472             PrintXML($msg);
473         }
474         flush();
475         $request->chunkOutput();
476
477         assert($num == strlen($data));
478         fclose($fd);
479
480         if (USECACHE) {
481           $request->_dbi->_cache->invalidate_cache($pagename);
482           unset ($request->_dbi->_cache->_pagedata_cache);
483           unset ($request->_dbi->_cache->_versiondata_cache);
484           unset ($request->_dbi->_cache->_glv_cache);
485         }
486         unset ($request->_dbi->_cache->_backend->_page_data);
487
488         unset($msg);
489         unset($revision->_transformedContent);
490         unset($revision);
491         unset($template->_request);
492         unset($template);
493         unset($data);
494     }
495     $pages->free();
496
497     if (!empty($WikiTheme->dumped_images) and is_array($WikiTheme->dumped_images)) {
498         @mkdir("$directory/images");
499         foreach ($WikiTheme->dumped_images as $img_file) {
500             if (($from = $WikiTheme->_findFile($img_file)) and basename($from)) {
501                 $target = "$directory/images/".basename($img_file);
502                 if (copy($WikiTheme->_path . $from, $target)) {
503                     $msg = HTML(HTML::br(), HTML($from), HTML::small(fmt("... copied to %s", $target)));
504                     if (!isa($request,'MockRequest'))
505                         PrintXML($msg);
506                 }
507             } else {
508                 $msg = HTML(HTML::br(), HTML($from), HTML::small(fmt("... not found", $target)));
509                 if (!isa($request,'MockRequest'))
510                     PrintXML($msg);
511             }
512         }
513     }
514     if (!empty($WikiTheme->dumped_buttons) and is_array($WikiTheme->dumped_buttons)) {
515         // Buttons also
516         @mkdir("$directory/images/buttons");
517         foreach ($WikiTheme->dumped_buttons as $text => $img_file) {
518             if (($from = $WikiTheme->_findFile($img_file)) and basename($from)) {
519                 $target = "$directory/images/buttons/".basename($img_file);
520                 if (copy($WikiTheme->_path . $from, $target)) {
521                     $msg = HTML(HTML::br(), HTML($from), HTML::small(fmt("... copied to %s", $target)));
522                     if (!isa($request,'MockRequest'))
523                         PrintXML($msg);
524                 }
525             } else {
526                 $msg = HTML(HTML::br(), HTML($from), HTML::small(fmt("... not found", $target)));
527                 if (!isa($request,'MockRequest'))
528                     PrintXML($msg);
529             }
530         }
531     }
532     if (!empty($WikiTheme->dumped_css) and is_array($WikiTheme->dumped_css)) {
533       foreach ($WikiTheme->dumped_css as $css_file) {
534           if (($from = $WikiTheme->_findFile(basename($css_file))) and basename($from)) {
535               $target = "$directory/" . basename($css_file);
536               if (copy($WikiTheme->_path . $from, $target)) {
537                   $msg = HTML(HTML::br(), HTML($from), HTML::small(fmt("... copied to %s", $target)));
538                   if (!isa($request,'MockRequest'))
539                       PrintXML($msg);
540               }
541           } else {
542               $msg = HTML(HTML::br(), HTML($from), HTML::small(fmt("... not found", $target)));
543               if (!isa($request,'MockRequest'))
544                   PrintXML($msg);
545           }
546       }
547     }
548     $WikiTheme->HTML_DUMP_SUFFIX = '';
549     $WikiTheme->DUMP_MODE = false;
550
551     $request->setArg('pagename',$thispage); // Template::_basepage fix
552     EndLoadDump($request);
553 }
554
555 /* Known problem: any plugins or other code which echo()s text will
556  * lead to a corrupted html zip file which may produce the following
557  * errors upon unzipping:
558  *
559  * warning [wikihtml.zip]:  2401 extra bytes at beginning or within zipfile
560  * file #58:  bad zipfile offset (local header sig):  177561
561  *  (attempting to re-compensate)
562  *
563  * However, the actual wiki page data should be unaffected.
564  */
565 function MakeWikiZipHtml (&$request)
566 {
567     $request->_TemplatesProcessed = array();
568     $zipname = "wikihtml.zip";
569     $zip = new ZipWriter("Created by PhpWiki " . PHPWIKI_VERSION, $zipname);
570     $dbi = $request->getDbh();
571     $thispage = $request->getArg('pagename'); // for "Return to ..."
572     if ($exclude = $request->getArg('exclude')) {   // exclude which pagenames
573         $excludeList = explodePageList($exclude); 
574     } else {
575         $excludeList = array();
576     }
577     if ($whichpages = $request->getArg('pages')) {  // which pagenames
578         if ($whichpages == '[]') // current page
579             $whichpages = $thispage;
580         $pages = new WikiDB_Array_PageIterator(explodePageList($whichpages));
581     } else {
582         $pages = $dbi->getAllPages(false,false,false,$excludeList);
583     }
584
585     global $WikiTheme;
586     if (defined('HTML_DUMP_SUFFIX'))
587         $WikiTheme->HTML_DUMP_SUFFIX = HTML_DUMP_SUFFIX;
588
589     /* ignore fatals in plugins */
590     if (check_php_version(4,1)) {
591         global $ErrorManager;
592         $ErrorManager->pushErrorHandler(new WikiFunctionCb('_dump_error_handler'));
593     }
594
595     $request_args = $request->args;
596     
597     while ($page = $pages->next()) {
598         $request->args = $request_args; // some plugins might change them (esp. on POST)
599         if (! $request->getArg('start_debug'))
600             @set_time_limit(30); // Reset watchdog.
601         else    
602             @set_time_limit(240);
603
604         $current = $page->getCurrentRevision();
605         if ($current->getVersion() == 0)
606             continue;
607         $pagename = $page->getName();
608         if (in_array($pagename, $excludeList)) {
609             continue;
610         }
611
612         $attrib = array('mtime'    => $current->get('mtime'),
613                         'is_ascii' => 1);
614         if ($page->get('locked'))
615             $attrib['write_protected'] = 1;
616
617         $request->setArg('pagename',$pagename); // Template::_basepage fix
618         $filename = FilenameForPage($pagename) . $WikiTheme->HTML_DUMP_SUFFIX;
619         $revision = $page->getCurrentRevision();
620
621         $transformedContent = $revision->getTransformedContent();
622
623         $template = new Template('browse', $request,
624                                  array('revision' => $revision,
625                                        'CONTENT' => $transformedContent));
626
627         $data = GeneratePageasXML($template, $pagename);
628
629         $zip->addRegularFile( $filename, $data, $attrib);
630         
631         if (USECACHE) {
632           $request->_dbi->_cache->invalidate_cache($pagename);
633           unset ($request->_dbi->_cache->_pagedata_cache);
634           unset ($request->_dbi->_cache->_versiondata_cache);
635           unset ($request->_dbi->_cache->_glv_cache);
636         }
637         unset ($request->_dbi->_cache->_backend->_page_data);
638
639         unset($revision->_transformedContent);
640         unset($revision);
641         unset($template->_request);
642         unset($template);
643         unset($data);
644     }
645     // FIXME: Deal with css and images here.
646     $zip->finish();
647     if (check_php_version(4,1)) {
648         global $ErrorManager;
649         $ErrorManager->popErrorHandler();
650     }
651     $WikiTheme->$HTML_DUMP_SUFFIX = '';
652 }
653
654
655 ////////////////////////////////////////////////////////////////
656 //
657 //  Functions for restoring.
658 //
659 ////////////////////////////////////////////////////////////////
660
661 function SavePage (&$request, &$pageinfo, $source, $filename)
662 {
663     static $overwite_all = false;
664     $pagedata    = $pageinfo['pagedata'];    // Page level meta-data.
665     $versiondata = $pageinfo['versiondata']; // Revision level meta-data.
666
667     if (empty($pageinfo['pagename'])) {
668         PrintXML(HTML::dt(HTML::strong(_("Empty pagename!"))));
669         return;
670     }
671
672     if (empty($versiondata['author_id']))
673         $versiondata['author_id'] = $versiondata['author'];
674
675     $pagename = $pageinfo['pagename'];
676     $content  = $pageinfo['content'];
677
678     if ($pagename ==_("InterWikiMap"))
679         $content = _tryinsertInterWikiMap($content);
680
681     $dbi = $request->getDbh();
682     $page = $dbi->getPage($pagename);
683
684     // Try to merge if updated pgsrc contents are different. This
685     // whole thing is hackish
686     //
687     // TODO: try merge unless:
688     // if (current contents = default contents && pgsrc_version >=
689     // pgsrc_version) then just upgrade this pgsrc
690     $needs_merge = false;
691     $merging = false;
692     $overwrite = false;
693
694     if ($request->getArg('merge')) {
695         $merging = true;
696     }
697     else if ($request->getArg('overwrite')) {
698         $overwrite = true;
699     }
700
701     $current = $page->getCurrentRevision();
702     if ( $current and (! $current->hasDefaultContents())
703          && ($current->getPackedContent() != $content)
704          && ($merging == true) ) {
705         include_once('lib/editpage.php');
706         $request->setArg('pagename', $pagename);
707         $r = $current->getVersion();
708         $request->setArg('revision', $current->getVersion());
709         $p = new LoadFileConflictPageEditor($request);
710         $p->_content = $content;
711         $p->_currentVersion = $r - 1;
712         $p->editPage($saveFailed = true);
713         return; //early return
714     }
715
716     foreach ($pagedata as $key => $value) {
717         if (!empty($value))
718             $page->set($key, $value);
719     }
720
721     $mesg = HTML::dd();
722     $skip = false;
723     if ($source)
724         $mesg->pushContent(' ', fmt("from %s", $source));
725
726
727     if (!$current) {
728         //FIXME: This should not happen! (empty vdata, corrupt cache or db)
729         $current = $page->getCurrentRevision();
730     }
731     if ($current->getVersion() == 0) {
732         $mesg->pushContent(' - ', _("new page"));
733         $isnew = true;
734     }
735     else {
736         if ( (! $current->hasDefaultContents())
737              && ($current->getPackedContent() != $content) ) {
738             if ($overwrite) {
739                 $mesg->pushContent(' ',
740                                    fmt("has edit conflicts - overwriting anyway"));
741                 $skip = false;
742                 if (substr_count($source, 'pgsrc')) {
743                     $versiondata['author'] = _("The PhpWiki programming team");
744                     // but leave authorid as userid who loaded the file
745                 }
746             }
747             else {
748                 $mesg->pushContent(' ', fmt("has edit conflicts - skipped"));
749                 $needs_merge = true; // hackish
750                 $skip = true;
751             }
752         }
753         else if ($current->getPackedContent() == $content
754                  && $current->get('author') == $versiondata['author']) {
755             // The page metadata is already changed, we don't need a new revision.
756             // This was called previously "is identical to current version %d - skipped"
757             // which is wrong, since the pagedata was stored, not skipped.
758             $mesg->pushContent(' ',
759                                fmt("content is identical to current version %d - no new revision created",
760                                    $current->getVersion()));
761             $skip = true;
762         }
763         $isnew = false;
764     }
765
766     if (! $skip ) {
767         // in case of failures print the culprit:
768         if (!isa($request,'MockRequest')) {
769             PrintXML(HTML::dt(WikiLink($pagename))); flush();
770         }
771         $new = $page->save($content, WIKIDB_FORCE_CREATE, $versiondata);
772         $dbi->touch();
773         $mesg->pushContent(' ', fmt("- saved to database as version %d",
774                                     $new->getVersion()));
775     }
776     if ($needs_merge) {
777         $f = $source;
778         // hackish, $source contains needed path+filename
779         $f = str_replace(sprintf(_("MIME file %s"), ''), '', $f);
780         $f = str_replace(sprintf(_("Serialized file %s"), ''), '', $f);
781         $f = str_replace(sprintf(_("plain file %s"), ''), '', $f);
782         //check if uploaded file? they pass just the content, but the file is gone
783         if (@stat($f)) {
784             global $WikiTheme;
785             $meb = Button(array('action' => 'loadfile',
786                                 'merge'=> true,
787                                 'source'=> $f),
788                           _("Merge Edit"),
789                           _("PhpWikiAdministration"),
790                           'wikiadmin');
791             $owb = Button(array('action' => 'loadfile',
792                                 'overwrite'=> true,
793                                 'source'=> $f),
794                           _("Restore Anyway"),
795                           _("PhpWikiAdministration"),
796                           'wikiunsafe');
797             $mesg->pushContent(' ', $meb, " ", $owb);
798             if (!$overwite_all) {
799                 $args = $request->getArgs();
800                 $args['overwrite'] = 1;
801                 $owb = Button($args,
802                               _("Overwrite All"),
803                               _("PhpWikiAdministration"),
804                               'wikiunsafe');
805                 $mesg->pushContent(HTML::div(array('class' => 'hint'), $owb));
806                 $overwite_all = true;
807             }
808         } else {
809             $mesg->pushContent(HTML::em(_(" Sorry, cannot merge.")));
810         }
811     }
812
813     if (!isa($request,'MockRequest')) {
814       if ($skip)
815         PrintXML(HTML::dt(HTML::em(WikiLink($pagename))), $mesg);
816       else
817         PrintXML($mesg);
818       flush();
819     }
820 }
821
822 // action=revert (by diff)
823 function RevertPage (&$request)
824 {
825     $mesg = HTML::dd();
826     $pagename = $request->getArg('pagename');
827     $version = $request->getArg('version');
828     if (!$version) {
829         PrintXML(HTML::dt(fmt("Revert")," ",WikiLink($pagename)),
830                  HTML::dd(_("missing required version argument")));
831         return;
832     }
833     $dbi = $request->getDbh();
834     $page = $dbi->getPage($pagename);
835     $current = $page->getCurrentRevision();
836     if ($current->getVersion() == 0) {
837         $mesg->pushContent(' ', _("no page content"));
838         PrintXML(HTML::dt(fmt("Revert")," ",WikiLink($pagename)),
839                  $mesg);
840         return;
841     }
842     if ($current->getVersion() == $version) {
843         $mesg->pushContent(' ', _("same version page"));
844         return;
845     }
846     $rev = $page->getRevision($version);
847     $content = $rev->getPackedContent();
848     $versiondata = $rev->_data;
849     $versiondata['summary'] = sprintf(_("revert to version %d"), $version);
850     $new = $page->save($content, $current->getVersion() + 1, $versiondata);
851     $dbi->touch();
852     $mesg->pushContent(' ', fmt("- version %d saved to database as version %d",
853                                 $version, $new->getVersion()));
854     PrintXML(HTML::dt(fmt("Revert")," ",WikiLink($pagename)),
855              $mesg);
856     flush();
857 }
858
859 function _tryinsertInterWikiMap($content) {
860     $goback = false;
861     if (strpos($content, "<verbatim>")) {
862         //$error_html = " The newly loaded pgsrc already contains a verbatim block.";
863         $goback = true;
864     }
865     if (!$goback && !defined('INTERWIKI_MAP_FILE')) {
866         $error_html = sprintf(" "._("%s: not defined"), "INTERWIKI_MAP_FILE");
867         $goback = true;
868     }
869     $mapfile = FindFile(INTERWIKI_MAP_FILE,1);
870     if (!$goback && !file_exists($mapfile)) {
871         $error_html = sprintf(" "._("%s: file not found"), INTERWIKI_MAP_FILE);
872         $goback = true;
873     }
874
875     if (!empty($error_html))
876         trigger_error(_("Default InterWiki map file not loaded.")
877                       . $error_html, E_USER_NOTICE);
878     if ($goback)
879         return $content;
880
881     // if loading from virgin setup do echo, otherwise trigger_error E_USER_NOTICE
882     if (!isa($GLOBALS['request'],'MockRequest'))
883         echo sprintf(_("Loading InterWikiMap from external file %s."), $mapfile),"<br />";
884
885     $fd = fopen ($mapfile, "rb");
886     $data = fread ($fd, filesize($mapfile));
887     fclose ($fd);
888     $content = $content . "\n<verbatim>\n$data</verbatim>\n";
889     return $content;
890 }
891
892 function ParseSerializedPage($text, $default_pagename, $user)
893 {
894     if (!preg_match('/^a:\d+:{[si]:\d+/', $text))
895         return false;
896
897     $pagehash = unserialize($text);
898
899     // Split up pagehash into four parts:
900     //   pagename
901     //   content
902     //   page-level meta-data
903     //   revision-level meta-data
904
905     if (!defined('FLAG_PAGE_LOCKED'))
906         define('FLAG_PAGE_LOCKED', 1);
907     $pageinfo = array('pagedata'    => array(),
908                       'versiondata' => array());
909
910     $pagedata = &$pageinfo['pagedata'];
911     $versiondata = &$pageinfo['versiondata'];
912
913     // Fill in defaults.
914     if (empty($pagehash['pagename']))
915         $pagehash['pagename'] = $default_pagename;
916     if (empty($pagehash['author'])) {
917         $pagehash['author'] = $user->getId();
918     }
919
920     foreach ($pagehash as $key => $value) {
921         switch($key) {
922             case 'pagename':
923             case 'version':
924             case 'hits':
925                 $pageinfo[$key] = $value;
926                 break;
927             case 'content':
928                 $pageinfo[$key] = join("\n", $value);
929                 break;
930             case 'flags':
931                 if (($value & FLAG_PAGE_LOCKED) != 0)
932                     $pagedata['locked'] = 'yes';
933                 break;
934             case 'owner':
935             case 'created':
936                 $pagedata[$key] = $value;
937                 break;
938             case 'acl':
939             case 'perm':
940                 $pagedata['perm'] = ParseMimeifiedPerm($value);
941                 break;
942             case 'lastmodified':
943                 $versiondata['mtime'] = $value;
944                 break;
945             case 'author':
946             case 'author_id':
947             case 'summary':
948                 $versiondata[$key] = $value;
949                 break;
950         }
951     }
952     return $pageinfo;
953 }
954
955 function SortByPageVersion ($a, $b) {
956     return $a['version'] - $b['version'];
957 }
958
959 function LoadFile (&$request, $filename, $text = false, $mtime = false)
960 {
961     if (!is_string($text)) {
962         // Read the file.
963         $stat  = stat($filename);
964         $mtime = $stat[9];
965         $text  = implode("", file($filename));
966     }
967
968         if (! $request->getArg('start_debug'))
969         @set_time_limit(30); // Reset watchdog.
970     else    
971         @set_time_limit(240);
972
973     // FIXME: basename("filewithnoslashes") seems to return garbage sometimes.
974     $basename = basename("/dummy/" . $filename);
975
976     if (!$mtime)
977         $mtime = time();    // Last resort.
978
979     $default_pagename = rawurldecode($basename);
980
981     if ( ($parts = ParseMimeifiedPages($text)) ) {
982         usort($parts, 'SortByPageVersion');
983         foreach ($parts as $pageinfo)
984             SavePage($request, $pageinfo, sprintf(_("MIME file %s"),
985                                                   $filename), $basename);
986     }
987     else if ( ($pageinfo = ParseSerializedPage($text, $default_pagename,
988                                                $request->getUser())) ) {
989         SavePage($request, $pageinfo, sprintf(_("Serialized file %s"),
990                                               $filename), $basename);
991     }
992     else {
993         $user = $request->getUser();
994
995         // Assume plain text file.
996         $pageinfo = array('pagename' => $default_pagename,
997                           'pagedata' => array(),
998                           'versiondata'
999                           => array('author' => $user->getId()),
1000                           'content'  => preg_replace('/[ \t\r]*\n/', "\n",
1001                                                      chop($text))
1002                           );
1003         SavePage($request, $pageinfo, sprintf(_("plain file %s"), $filename),
1004                  $basename);
1005     }
1006 }
1007
1008 function LoadZip (&$request, $zipfile, $files = false, $exclude = false) {
1009     $zip = new ZipReader($zipfile);
1010     while (list ($fn, $data, $attrib) = $zip->readFile()) {
1011         // FIXME: basename("filewithnoslashes") seems to return
1012         // garbage sometimes.
1013         $fn = basename("/dummy/" . $fn);
1014         if ( ($files && !in_array($fn, $files))
1015              || ($exclude && in_array($fn, $exclude)) ) {
1016             PrintXML(HTML::dt(WikiLink($fn)),
1017                      HTML::dd(_("Skipping")));
1018             flush();
1019             continue;
1020         }
1021
1022         LoadFile($request, $fn, $data, $attrib['mtime']);
1023     }
1024 }
1025
1026 function LoadDir (&$request, $dirname, $files = false, $exclude = false) {
1027     $fileset = new LimitedFileSet($dirname, $files, $exclude);
1028
1029     if (!$files and ($skiplist = $fileset->getSkippedFiles())) {
1030         PrintXML(HTML::dt(HTML::strong(_("Skipping"))));
1031         $list = HTML::ul();
1032         foreach ($skiplist as $file)
1033             $list->pushContent(HTML::li(WikiLink($file)));
1034         PrintXML(HTML::dd($list));
1035     }
1036
1037     // Defer HomePage loading until the end. If anything goes wrong
1038     // the pages can still be loaded again.
1039     $files = $fileset->getFiles();
1040     if (in_array(HOME_PAGE, $files)) {
1041         $files = array_diff($files, array(HOME_PAGE));
1042         $files[] = HOME_PAGE;
1043     }
1044     foreach ($files as $file) {
1045         if (substr($file,-1,1) != '~') // refuse to load backup files
1046             LoadFile($request, "$dirname/$file");
1047     }
1048 }
1049
1050 class LimitedFileSet extends FileSet {
1051     function LimitedFileSet($dirname, $_include, $exclude) {
1052         $this->_includefiles = $_include;
1053         $this->_exclude = $exclude;
1054         $this->_skiplist = array();
1055         parent::FileSet($dirname);
1056     }
1057
1058     function _filenameSelector($fn) {
1059         $incl = &$this->_includefiles;
1060         $excl = &$this->_exclude;
1061
1062         if ( ($incl && !in_array($fn, $incl))
1063              || ($excl && in_array($fn, $excl)) ) {
1064             $this->_skiplist[] = $fn;
1065             return false;
1066         } else {
1067             return true;
1068         }
1069     }
1070
1071     function getSkippedFiles () {
1072         return $this->_skiplist;
1073     }
1074 }
1075
1076
1077 function IsZipFile ($filename_or_fd)
1078 {
1079     // See if it looks like zip file
1080     if (is_string($filename_or_fd))
1081     {
1082         $fd    = fopen($filename_or_fd, "rb");
1083         $magic = fread($fd, 4);
1084         fclose($fd);
1085     }
1086     else
1087     {
1088         $fpos  = ftell($filename_or_fd);
1089         $magic = fread($filename_or_fd, 4);
1090         fseek($filename_or_fd, $fpos);
1091     }
1092
1093     return $magic == ZIP_LOCHEAD_MAGIC || $magic == ZIP_CENTHEAD_MAGIC;
1094 }
1095
1096
1097 function LoadAny (&$request, $file_or_dir, $files = false, $exclude = false)
1098 {
1099     // Try urlencoded filename for accented characters.
1100     if (!file_exists($file_or_dir)) {
1101         // Make sure there are slashes first to avoid confusing phps
1102         // with broken dirname or basename functions.
1103         // FIXME: windows uses \ and :
1104         if (is_integer(strpos($file_or_dir, "/"))) {
1105             $file_or_dir = FindFile($file_or_dir);
1106             // Panic
1107             if (!file_exists($file_or_dir))
1108                 $file_or_dir = dirname($file_or_dir) . "/"
1109                     . urlencode(basename($file_or_dir));
1110         } else {
1111             // This is probably just a file.
1112             $file_or_dir = urlencode($file_or_dir);
1113         }
1114     }
1115
1116     $type = filetype($file_or_dir);
1117     if ($type == 'link') {
1118         // For symbolic links, use stat() to determine
1119         // the type of the underlying file.
1120         list(,,$mode) = stat($file_or_dir);
1121         $type = ($mode >> 12) & 017;
1122         if ($type == 010)
1123             $type = 'file';
1124         elseif ($type == 004)
1125             $type = 'dir';
1126     }
1127
1128     if (! $type) {
1129         $request->finish(fmt("Unable to load: %s", $file_or_dir));
1130     }
1131     else if ($type == 'dir') {
1132         LoadDir($request, $file_or_dir, $files, $exclude);
1133     }
1134     else if ($type != 'file' && !preg_match('/^(http|ftp):/', $file_or_dir))
1135     {
1136         $request->finish(fmt("Bad file type: %s", $type));
1137     }
1138     else if (IsZipFile($file_or_dir)) {
1139         LoadZip($request, $file_or_dir, $files, $exclude);
1140     }
1141     else /* if (!$files || in_array(basename($file_or_dir), $files)) */
1142     {
1143         LoadFile($request, $file_or_dir);
1144     }
1145 }
1146
1147 function LoadFileOrDir (&$request)
1148 {
1149     $source = $request->getArg('source');
1150     $finder = new FileFinder;
1151     $source = $finder->slashifyPath($source);
1152     $page = rawurldecode(basename($source));
1153     StartLoadDump($request, fmt("Loading '%s'", 
1154         HTML(dirname($source),
1155              dirname($source) ? "/" : "",
1156              WikiLink($page,'auto'))));
1157     echo "<dl>\n";
1158     LoadAny($request, $source);
1159     echo "</dl>\n";
1160     EndLoadDump($request);
1161 }
1162
1163 function SetupWiki (&$request)
1164 {
1165     global $GenericPages, $LANG;
1166
1167
1168     //FIXME: This is a hack (err, "interim solution")
1169     // This is a bogo-bogo-login:  Login without
1170     // saving login information in session state.
1171     // This avoids logging in the unsuspecting
1172     // visitor as "The PhpWiki programming team".
1173     //
1174     // This really needs to be cleaned up...
1175     // (I'm working on it.)
1176     $real_user = $request->_user;
1177     if (ENABLE_USER_NEW)
1178         $request->_user = new _BogoUser(_("The PhpWiki programming team"));
1179
1180     else
1181         $request->_user = new WikiUser($request, _("The PhpWiki programming team"),
1182                                        WIKIAUTH_BOGO);
1183
1184     StartLoadDump($request, _("Loading up virgin wiki"));
1185     echo "<dl>\n";
1186
1187     $pgsrc = FindLocalizedFile(WIKI_PGSRC);
1188     $default_pgsrc = FindFile(DEFAULT_WIKI_PGSRC);
1189
1190     $request->setArg('overwrite',true);
1191     if ($default_pgsrc != $pgsrc) {
1192         LoadAny($request, $default_pgsrc, $GenericPages);
1193     }
1194     $request->setArg('overwrite',false);
1195     LoadAny($request, $pgsrc);
1196
1197     // Ensure that all mandatory pages are loaded
1198     $finder = new FileFinder;
1199     foreach (array_merge(explode(':','OldTextFormattingRules:TextFormattingRules:PhpWikiAdministration'),
1200                          $GLOBALS['AllActionPages'],
1201                          array(constant('HOME_PAGE'))) as $f) {
1202         $page = gettext($f);
1203         if (isSubPage($page))
1204             $page = urlencode($page);
1205         if (! $request->_dbi->isWikiPage(urldecode($page)) ) {
1206             // translated version provided?
1207             if ($lf = FindLocalizedFile($pgsrc . $finder->_pathsep . $page, 1))
1208                 LoadAny($request, $lf);
1209             else { // load english version of required action page
1210                 LoadAny($request, FindFile(DEFAULT_WIKI_PGSRC . $finder->_pathsep . urlencode($f)));
1211                 $page = $f;
1212             }
1213         }
1214         if (!$request->_dbi->isWikiPage(urldecode($page))) {
1215             trigger_error(sprintf("Mandatory file %s couldn't be loaded!", $page),
1216                           E_USER_WARNING);
1217         }
1218     }
1219
1220     echo "</dl>\n";
1221     EndLoadDump($request);
1222 }
1223
1224 function LoadPostFile (&$request)
1225 {
1226     $upload = $request->getUploadedFile('file');
1227
1228     if (!$upload)
1229         $request->finish(_("No uploaded file to upload?")); // FIXME: more concise message
1230
1231
1232     // Dump http headers.
1233     StartLoadDump($request, sprintf(_("Uploading %s"), $upload->getName()));
1234     echo "<dl>\n";
1235
1236     $fd = $upload->open();
1237     if (IsZipFile($fd))
1238         LoadZip($request, $fd, false, array(_("RecentChanges")));
1239     else
1240         LoadFile($request, $upload->getName(), $upload->getContents());
1241
1242     echo "</dl>\n";
1243     EndLoadDump($request);
1244 }
1245
1246 /**
1247  $Log: not supported by cvs2svn $
1248  Revision 1.128  2004/11/16 16:16:44  rurban
1249  enable Overwrite All for upgrade
1250
1251  Revision 1.127  2004/11/01 10:43:57  rurban
1252  seperate PassUser methods into seperate dir (memory usage)
1253  fix WikiUser (old) overlarge data session
1254  remove wikidb arg from various page class methods, use global ->_dbi instead
1255  ...
1256
1257  Revision 1.126  2004/10/16 15:13:39  rurban
1258  new [Overwrite All] button
1259
1260  Revision 1.125  2004/10/14 19:19:33  rurban
1261  loadsave: check if the dumped file will be accessible from outside.
1262  and some other minor fixes. (cvsclient native not yet ready)
1263
1264  Revision 1.124  2004/10/04 23:44:28  rurban
1265  for older or CGI phps
1266
1267  Revision 1.123  2004/09/25 16:26:54  rurban
1268  deferr notifies (to be improved)
1269
1270  Revision 1.122  2004/09/17 14:25:45  rurban
1271  update comments
1272
1273  Revision 1.121  2004/09/08 13:38:00  rurban
1274  improve loadfile stability by using markup=2 as default for undefined markup-style.
1275  use more refs for huge objects.
1276  fix debug=static issue in WikiPluginCached
1277
1278  Revision 1.120  2004/07/08 19:04:42  rurban
1279  more unittest fixes (file backend, metadata RatingsDb)
1280
1281  Revision 1.119  2004/07/08 15:23:59  rurban
1282  less verbose for tests
1283
1284  Revision 1.118  2004/07/08 13:50:32  rurban
1285  various unit test fixes: print error backtrace on _DEBUG_TRACE; allusers fix; new PHPWIKI_NOMAIN constant for omitting the mainloop
1286
1287  Revision 1.117  2004/07/02 09:55:58  rurban
1288  more stability fixes: new DISABLE_GETIMAGESIZE if your php crashes when loading LinkIcons: failing getimagesize in old phps; blockparser stabilized
1289
1290  Revision 1.116  2004/07/01 09:05:41  rurban
1291  support pages and exclude arguments for all 4 dump methods
1292
1293  Revision 1.115  2004/07/01 08:51:22  rurban
1294  dumphtml: added exclude, print pagename before processing
1295
1296  Revision 1.114  2004/06/28 12:51:41  rurban
1297  improved dumphtml and virgin setup
1298
1299  Revision 1.113  2004/06/27 10:26:02  rurban
1300  oci8 patch by Philippe Vanhaesendonck + some ADODB notes+fixes
1301
1302  Revision 1.112  2004/06/25 14:29:20  rurban
1303  WikiGroup refactoring:
1304    global group attached to user, code for not_current user.
1305    improved helpers for special groups (avoid double invocations)
1306  new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
1307  fixed a XHTML validation error on userprefs.tmpl
1308
1309  Revision 1.111  2004/06/21 16:38:55  rurban
1310  fixed the StartLoadDump html argument hack.
1311
1312  Revision 1.110  2004/06/21 16:22:30  rurban
1313  add DEFAULT_DUMP_DIR and HTML_DUMP_DIR constants, for easier cmdline dumps,
1314  fixed dumping buttons locally (images/buttons/),
1315  support pages arg for dumphtml,
1316  optional directory arg for dumpserial + dumphtml,
1317  fix a AllPages warning,
1318  show dump warnings/errors on DEBUG,
1319  don't warn just ignore on wikilens pagelist columns, if not loaded.
1320  RateIt pagelist column is called "rating", not "ratingwidget" (Dan?)
1321
1322  Revision 1.109  2004/06/17 11:31:05  rurban
1323  jump back to label after dump/upgrade
1324
1325  Revision 1.108  2004/06/16 12:43:01  rurban
1326  4.0.6 cannot use this errorhandler (not found)
1327
1328  Revision 1.107  2004/06/14 11:31:37  rurban
1329  renamed global $Theme to $WikiTheme (gforge nameclash)
1330  inherit PageList default options from PageList
1331    default sortby=pagename
1332  use options in PageList_Selectable (limit, sortby, ...)
1333  added action revert, with button at action=diff
1334  added option regex to WikiAdminSearchReplace
1335
1336  Revision 1.106  2004/06/13 13:54:25  rurban
1337  Catch fatals on the four dump calls (as file and zip, as html and mimified)
1338  FoafViewer: Check against external requirements, instead of fatal.
1339  Change output for xhtmldumps: using file:// urls to the local fs.
1340  Catch SOAP fatal by checking for GOOGLE_LICENSE_KEY
1341  Import GOOGLE_LICENSE_KEY and FORTUNE_DIR from config.ini.
1342
1343  Revision 1.105  2004/06/08 19:48:16  rurban
1344  fixed foreign setup: no ugly skipped msg for the GenericPages, load english actionpages if translated not found
1345
1346  Revision 1.104  2004/06/08 13:51:57  rurban
1347  some comments only
1348
1349  Revision 1.103  2004/06/08 10:54:46  rurban
1350  better acl dump representation, read back acl and owner
1351
1352  Revision 1.102  2004/06/06 16:58:51  rurban
1353  added more required ActionPages for foreign languages
1354  install now english ActionPages if no localized are found. (again)
1355  fixed default anon user level to be 0, instead of -1
1356    (wrong "required administrator to view this page"...)
1357
1358  Revision 1.101  2004/06/04 20:32:53  rurban
1359  Several locale related improvements suggested by Pierrick Meignen
1360  LDAP fix by John Cole
1361  reenable admin check without ENABLE_PAGEPERM in the admin plugins
1362
1363  Revision 1.100  2004/05/02 21:26:38  rurban
1364  limit user session data (HomePageHandle and auth_dbi have to invalidated anyway)
1365    because they will not survive db sessions, if too large.
1366  extended action=upgrade
1367  some WikiTranslation button work
1368  revert WIKIAUTH_UNOBTAINABLE (need it for main.php)
1369  some temp. session debug statements
1370
1371  Revision 1.99  2004/05/02 15:10:07  rurban
1372  new finally reliable way to detect if /index.php is called directly
1373    and if to include lib/main.php
1374  new global AllActionPages
1375  SetupWiki now loads all mandatory pages: HOME_PAGE, action pages, and warns if not.
1376  WikiTranslation what=buttons for Carsten to create the missing MacOSX buttons
1377  PageGroupTestOne => subpages
1378  renamed PhpWikiRss to PhpWikiRecentChanges
1379  more docs, default configs, ...
1380
1381  Revision 1.98  2004/04/29 23:25:12  rurban
1382  re-ordered locale init (as in 1.3.9)
1383  fixed loadfile with subpages, and merge/restore anyway
1384    (sf.net bug #844188)
1385
1386  Revision 1.96  2004/04/19 23:13:03  zorloc
1387  Connect the rest of PhpWiki to the IniConfig system.  Also the keyword regular expression is not a config setting
1388
1389  Revision 1.95  2004/04/18 01:11:52  rurban
1390  more numeric pagename fixes.
1391  fixed action=upload with merge conflict warnings.
1392  charset changed from constant to global (dynamic utf-8 switching)
1393
1394  Revision 1.94  2004/03/14 16:36:37  rurban
1395  dont load backup files
1396
1397  Revision 1.93  2004/02/26 03:22:05  rurban
1398  also copy css and images with XHTML Dump
1399
1400  Revision 1.92  2004/02/26 02:25:54  rurban
1401  fix empty and #-anchored links in XHTML Dumps
1402
1403  Revision 1.91  2004/02/24 17:19:37  rurban
1404  debugging helpers only
1405
1406  Revision 1.90  2004/02/24 17:09:24  rurban
1407  fixed \r\r\n with dumping on windows
1408
1409  Revision 1.88  2004/02/22 23:20:31  rurban
1410  fixed DumpHtmlToDir,
1411  enhanced sortby handling in PageList
1412    new button_heading th style (enabled),
1413  added sortby and limit support to the db backends and plugins
1414    for paging support (<<prev, next>> links on long lists)
1415
1416  Revision 1.87  2004/01/26 09:17:49  rurban
1417  * changed stored pref representation as before.
1418    the array of objects is 1) bigger and 2)
1419    less portable. If we would import packed pref
1420    objects and the object definition was changed, PHP would fail.
1421    This doesn't happen with an simple array of non-default values.
1422  * use $prefs->retrieve and $prefs->store methods, where retrieve
1423    understands the interim format of array of objects also.
1424  * simplified $prefs->get() and fixed $prefs->set()
1425  * added $user->_userid and class '_WikiUser' portability functions
1426  * fixed $user object ->_level upgrading, mostly using sessions.
1427    this fixes yesterdays problems with loosing authorization level.
1428  * fixed WikiUserNew::checkPass to return the _level
1429  * fixed WikiUserNew::isSignedIn
1430  * added explodePageList to class PageList, support sortby arg
1431  * fixed UserPreferences for WikiUserNew
1432  * fixed WikiPlugin for empty defaults array
1433  * UnfoldSubpages: added pagename arg, renamed pages arg,
1434    removed sort arg, support sortby arg
1435
1436  Revision 1.86  2003/12/02 16:18:26  carstenklapp
1437  Minor enhancement: Provide more meaningful filenames for WikiDB zip
1438  dumps & snapshots.
1439
1440  Revision 1.85  2003/11/30 18:18:13  carstenklapp
1441  Minor code optimization: use include_once instead of require_once
1442  inside functions that might not always called.
1443
1444  Revision 1.84  2003/11/26 20:47:47  carstenklapp
1445  Redo bugfix: My last refactoring broke merge-edit & overwrite
1446  functionality again, should be fixed now. Sorry.
1447
1448  Revision 1.83  2003/11/20 22:18:54  carstenklapp
1449  New feature: h1 during merge-edit displays WikiLink to original page.
1450  Internal changes: Replaced some hackish url-generation code in
1451  function SavePage (for pgsrc merge-edit) with appropriate Button()
1452  calls.
1453
1454  Revision 1.82  2003/11/18 19:48:01  carstenklapp
1455  Fixed missing gettext _() for button name.
1456
1457  Revision 1.81  2003/11/18 18:28:35  carstenklapp
1458  Bugfix: In the Load File function of PhpWikiAdministration: When doing
1459  a "Merge Edit" or "Restore Anyway", page names containing accented
1460  letters (such as locale/de/pgsrc/G%E4steBuch) would produce a file not
1461  found error (Use FilenameForPage funtion to urlencode page names).
1462
1463  Revision 1.80  2003/03/07 02:46:57  dairiki
1464  Omit checks for safe_mode before set_time_limit().  Just prefix the
1465  set_time_limit() calls with @ so that they fail silently if not
1466  supported.
1467
1468  Revision 1.79  2003/02/26 01:56:05  dairiki
1469  Only zip pages with legal pagenames.
1470
1471  Revision 1.78  2003/02/24 02:05:43  dairiki
1472  Fix "n bytes written" message when dumping HTML.
1473
1474  Revision 1.77  2003/02/21 04:12:05  dairiki
1475  Minor fixes for new cached markup.
1476
1477  Revision 1.76  2003/02/16 19:47:17  dairiki
1478  Update WikiDB timestamp when editing or deleting pages.
1479
1480  Revision 1.75  2003/02/15 03:04:30  dairiki
1481  Fix for WikiUser constructor API change.
1482
1483  Revision 1.74  2003/02/15 02:18:04  dairiki
1484  When default language was English (at least), pgsrc was being
1485  loaded twice.
1486
1487  LimitedFileSet: Fix typo/bug. ($include was being ignored.)
1488
1489  SetupWiki(): Fix bugs in loading of $GenericPages.
1490
1491  Revision 1.73  2003/01/28 21:09:17  zorloc
1492  The get_cfg_var() function should only be used when one is
1493  interested in the value from php.ini or similar. Use ini_get()
1494  instead to get the effective value of a configuration variable.
1495  -- Martin Geisler
1496
1497  Revision 1.72  2003/01/03 22:25:53  carstenklapp
1498  Cosmetic fix to "Merge Edit" & "Overwrite" buttons. Added "The PhpWiki
1499  programming team" as author when loading from pgsrc. Source
1500  reformatting.
1501
1502  Revision 1.71  2003/01/03 02:48:05  carstenklapp
1503  function SavePage: Added loadfile options for overwriting or merge &
1504  compare a loaded pgsrc file with an existing page.
1505
1506  function LoadAny: Added a general error message when unable to load a
1507  file instead of defaulting to "Bad file type".
1508
1509  */
1510
1511 // For emacs users
1512 // Local Variables:
1513 // mode: php
1514 // tab-width: 8
1515 // c-basic-offset: 4
1516 // c-hanging-comment-ender-p: nil
1517 // indent-tabs-mode: nil
1518 // End:
1519 ?>