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