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