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