]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/stdlib.php
php5 compatibility (5.0.1 ok)
[SourceForge/phpwiki.git] / lib / stdlib.php
1 <?php //rcs_id('$Id: stdlib.php,v 1.208 2004-10-12 13:13:20 rurban Exp $');
2
3 /*
4   Standard functions for Wiki functionality
5     WikiURL ($pagename, $args, $get_abs_url)
6     AbsoluteURL ($url)
7     IconForLink ($protocol_or_url)
8     PossiblyGlueIconToText($proto_or_url, $text)
9     IsSafeURL($url)
10     LinkURL ($url, $linktext)
11     LinkImage ($url, $alt)
12
13     SplitQueryArgs ($query_args)
14     LinkPhpwikiURL ($url, $text, $basepage)
15     ConvertOldMarkup ($content, $markup_type = "block")
16     MangleXmlIdentifier($str)
17     UnMangleXmlIdentifier($str)
18     
19     class Stack { push($item), pop(), cnt(), top() }
20     class Alert { show() }
21     class WikiPageName {getParent(),isValid(),getWarnings() }
22
23     expand_tabs($str, $tab_width = 8)
24     SplitPagename ($page)
25     NoSuchRevision ($request, $page, $version)
26     TimezoneOffset ($time, $no_colon)
27     Iso8601DateTime ($time)
28     Rfc2822DateTime ($time)
29     ParseRfc1123DateTime ($timestr)
30     CTime ($time)
31     ByteFormatter ($bytes = 0, $longformat = false)
32     __printf ($fmt)
33     __sprintf ($fmt)
34     __vsprintf ($fmt, $args)
35
36     file_mtime ($filename)
37     sort_file_mtime ($a, $b)
38     class fileSet {fileSet($directory, $filepattern = false), getFiles($exclude=false, $sortby=false, $limit=false) }
39     class ListRegexExpand { listMatchCallback($item, $key),  expandRegex ($index, &$pages) }
40
41     glob_to_pcre ($glob)
42     glob_match ($glob, $against, $case_sensitive = true)
43     explodeList ($input, $allnames, $glob_style = true, $case_sensitive = true)
44     explodePageList ($input, $perm = false)
45     isa ($object, $class)
46     can ($object, $method)
47     function_usable ($function_name)
48     hash ($x)
49     better_srand ($seed = '')
50     count_all ($arg)
51     isSubPage ($pagename)
52     subPageSlice ($pagename, $pos)
53
54     phpwiki_version ()
55     isWikiWord ($word)
56     obj2hash ($obj, $exclude = false, $fields = false)
57     isUtf8String ($s)
58     fixTitleEncoding ($s)
59     url_get_contents ($uri)
60     GenerateId ($name)
61     firstNWordsOfContent ($n, $content)
62     extractSection ($section, $content, $page, $quiet = false, $sectionhead = false)
63     isExternalReferrer()
64
65   function: LinkInterWikiLink($link, $linktext)
66   moved to: lib/interwiki.php
67   function: linkExistingWikiWord($wikiword, $linktext, $version)
68   moved to: lib/Theme.php
69   function: LinkUnknownWikiWord($wikiword, $linktext)
70   moved to: lib/Theme.php
71   function: UpdateRecentChanges($dbi, $pagename, $isnewpage) 
72   gone see: lib/plugin/RecentChanges.php
73 */
74 if (defined('_PHPWIKI_STDLIB_LOADED')) return;
75 else define('_PHPWIKI_STDLIB_LOADED', true);
76
77 define('MAX_PAGENAME_LENGTH', 100);
78
79             
80 /**
81  * Convert string to a valid XML identifier.
82  *
83  * XML 1.0 identifiers are of the form: [A-Za-z][A-Za-z0-9:_.-]*
84  *
85  * We would like to have, e.g. named anchors within wiki pages
86  * names like "Table of Contents" --- clearly not a valid XML
87  * fragment identifier.
88  *
89  * This function implements a one-to-one map from {any string}
90  * to {valid XML identifiers}.
91  *
92  * It does this by
93  * converting all bytes not in [A-Za-z0-9:_-],
94  * and any leading byte not in [A-Za-z] to 'xbb.',
95  * where 'bb' is the hexadecimal representation of the
96  * character.
97  *
98  * As a special case, the empty string is converted to 'empty.'
99  *
100  * @param string $str
101  * @return string
102  */
103 function MangleXmlIdentifier($str) {
104     if (!$str)
105         return 'empty.';
106     
107     return preg_replace('/[^-_:A-Za-z0-9]|(?<=^)[^A-Za-z]/e',
108                         "'x' . sprintf('%02x', ord('\\0')) . '.'",
109                         $str);
110 }
111
112 function UnMangleXmlIdentifier($str) {
113     if ($str == 'empty.')
114         return '';
115     return preg_replace('/x(\w\w)\./e',
116                         "sprintf('%c', hex('\\0'))",
117                         $str);
118 }
119
120 /**
121  * Generates a valid URL for a given Wiki pagename.
122  * @param mixed $pagename If a string this will be the name of the Wiki page to link to.
123  *                        If a WikiDB_Page object function will extract the name to link to.
124  *                        If a WikiDB_PageRevision object function will extract the name to link to.
125  * @param array $args 
126  * @param boolean $get_abs_url Default value is false.
127  * @return string The absolute URL to the page passed as $pagename.
128  */
129 function WikiURL($pagename, $args = '', $get_abs_url = false) {
130     $anchor = false;
131     
132     if (is_object($pagename)) {
133         if (isa($pagename, 'WikiDB_Page')) {
134             $pagename = $pagename->getName();
135         }
136         elseif (isa($pagename, 'WikiDB_PageRevision')) {
137             $page = $pagename->getPage();
138             $args['version'] = $pagename->getVersion();
139             $pagename = $page->getName();
140         }
141         elseif (isa($pagename, 'WikiPageName')) {
142             $anchor = $pagename->anchor;
143             $pagename = $pagename->name;
144         } else { // php5
145             $anchor = $pagename->anchor;
146             $pagename = $pagename->name;
147         }
148     }
149     if (!$get_abs_url and DEBUG and $GLOBALS['request']->getArg('start_debug')) {
150         if (!$args)
151             $args = 'start_debug=' . $GLOBALS['request']->getArg('start_debug');
152         elseif (is_array($args))
153             $args['start_debug'] = $GLOBALS['request']->getArg('start_debug');
154         else 
155             $args .= '&start_debug=' . $GLOBALS['request']->getArg('start_debug');
156     }
157     if (is_array($args)) {
158         $enc_args = array();
159         foreach ($args as $key => $val) {
160             if (!is_array($val)) // ugly hack for getURLtoSelf() which also takes POST vars
161               $enc_args[] = urlencode($key) . '=' . urlencode($val);
162         }
163         $args = join('&', $enc_args);
164     }
165
166     if (USE_PATH_INFO) {
167         $url = $get_abs_url ? SERVER_URL . VIRTUAL_PATH . "/" : "";
168         $url .= preg_replace('/%2f/i', '/', rawurlencode($pagename));
169         if ($args)
170             $url .= "?$args";
171     }
172     else {
173         $url = $get_abs_url ? SERVER_URL . SCRIPT_NAME : basename(SCRIPT_NAME);
174         $url .= "?pagename=" . rawurlencode($pagename);
175         if ($args)
176             $url .= "&$args";
177     }
178     if ($anchor)
179         $url .= "#" . MangleXmlIdentifier($anchor);
180     return $url;
181 }
182
183 /** Convert relative URL to absolute URL.
184  *
185  * This converts a relative URL to one of PhpWiki's support files
186  * to an absolute one.
187  *
188  * @param string $url
189  * @return string Absolute URL
190  */
191 function AbsoluteURL ($url) {
192     if (preg_match('/^https?:/', $url))
193         return $url;
194     if ($url[0] != '/') {
195         $base = USE_PATH_INFO ? VIRTUAL_PATH : dirname(SCRIPT_NAME);
196         while ($base != '/' and substr($url, 0, 3) == "../") {
197             $url = substr($url, 3);
198             $base = dirname($base);
199         }
200         if ($base != '/')
201             $base .= '/';
202         $url = $base . $url;
203     }
204     return SERVER_URL . $url;
205 }
206
207 /**
208  * Generates icon in front of links.
209  *
210  * @param string $protocol_or_url URL or protocol to determine which icon to use.
211  *
212  * @return HtmlElement HtmlElement object that contains data to create img link to
213  * icon for use with url or protocol passed to the function. False if no img to be
214  * displayed.
215  */
216 function IconForLink($protocol_or_url) {
217     global $WikiTheme;
218     if (0 and $filename_suffix == false) {
219         // display apache style icon for file type instead of protocol icon
220         // - archive: unix:gz,bz2,tgz,tar,z; mac:dmg,dmgz,bin,img,cpt,sit; pc:zip;
221         // - document: html, htm, text, txt, rtf, pdf, doc
222         // - non-inlined image: jpg,jpeg,png,gif,tiff,tif,swf,pict,psd,eps,ps
223         // - audio: mp3,mp2,aiff,aif,au
224         // - multimedia: mpeg,mpg,mov,qt
225     } else {
226         list ($proto) = explode(':', $protocol_or_url, 2);
227         $src = $WikiTheme->getLinkIconURL($proto);
228         if ($src)
229             return HTML::img(array('src' => $src, 'alt' => "", 'class' => 'linkicon', 'border' => 0));
230         else
231             return false;
232     }
233 }
234
235 /**
236  * Glue icon in front of or after text.
237  * Pref: 'noLinkIcons'  - ignore icon if set
238  * Theme: 'LinkIcons'   - 'yes'   at front
239  *                      - 'no'    display no icon
240  *                      - 'front' display at left
241  *                      - 'after' display at right
242  *
243  * @param string $protocol_or_url Protocol or URL.  Used to determine the
244  * proper icon.
245  * @param string $text The text.
246  * @return XmlContent.
247  */
248 function PossiblyGlueIconToText($proto_or_url, $text) {
249     global $request, $WikiTheme;
250     if ($request->getPref('noLinkIcons'))
251         return $text;
252     $icon = IconForLink($proto_or_url);
253     if (!$icon)
254         return $text;
255     if ($where = $WikiTheme->getLinkIconAttr()) {
256         if ($where == 'no') return $text;
257         if ($where != 'after') $where = 'front';
258     } else {
259         $where = 'front';
260     }
261     if ($where == 'after') {
262         // span the icon only to the last word (tie them together), 
263         // to let the previous words wrap on line breaks.
264         if (!is_object($text)) {
265             preg_match('/^(\s*\S*)(\s*)$/', $text, $m);
266             list (, $prefix, $last_word) = $m;
267         }
268         else {
269             $last_word = $text;
270             $prefix = false;
271         }
272         $text = HTML::span(array('style' => 'white-space: nowrap'),
273                            $last_word, HTML::Raw('&nbsp;'), $icon);
274         if ($prefix)
275             $text = HTML($prefix, $text);
276         return $text;
277     }
278     // span the icon only to the first word (tie them together), 
279     // to let the next words wrap on line breaks
280     if (!is_object($text)) {
281         preg_match('/^\s*(\S*)(.*?)\s*$/', $text, $m);
282         list (, $first_word, $tail) = $m;
283     }
284     else {
285         $first_word = $text;
286         $tail = false;
287     }
288     $text = HTML::span(array('style' => 'white-space: nowrap'),
289                        $icon, $first_word);
290     if ($tail)
291         $text = HTML($text, $tail);
292     return $text;
293 }
294
295 /**
296  * Determines if the url passed to function is safe, by detecting if the characters
297  * '<', '>', or '"' are present.
298  *
299  * @param string $url URL to check for unsafe characters.
300  * @return boolean True if same, false else.
301  */
302 function IsSafeURL($url) {
303     return !preg_match('/[<>"]/', $url);
304 }
305
306 /**
307  * Generates an HtmlElement object to store data for a link.
308  *
309  * @param string $url URL that the link will point to.
310  * @param string $linktext Text to be displayed as link.
311  * @return HtmlElement HtmlElement object that contains data to construct an html link.
312  */
313 function LinkURL($url, $linktext = '') {
314     // FIXME: Is this needed (or sufficient?)
315     if(! IsSafeURL($url)) {
316         $link = HTML::strong(HTML::u(array('class' => 'baduri'),
317                                      _("BAD URL -- remove all of <, >, \"")));
318     }
319     else {
320         if (!$linktext)
321             $linktext = preg_replace("/mailto:/A", "", $url);
322         
323         $link = HTML::a(array('href' => $url),
324                         PossiblyGlueIconToText($url, $linktext));
325         
326     }
327     $link->setAttr('class', $linktext ? 'namedurl' : 'rawurl');
328     return $link;
329 }
330
331 /**
332  * FIXME: disallow sizes which are too small. 
333  * Spammers may use such (typically invisible) image attributes to higher their GoogleRank.
334  */
335 function LinkImage($url, $alt = false) {
336     // FIXME: Is this needed (or sufficient?)
337     if(! IsSafeURL($url)) {
338         $link = HTML::strong(HTML::u(array('class' => 'baduri'),
339                                      _("BAD URL -- remove all of <, >, \"")));
340     } else {
341         // support new syntax: [image.jpg size=50% border=n]
342         $arr = split(' ',$url);
343         if (count($arr) > 1) {
344             $url = $arr[0];
345         }
346         if (empty($alt)) $alt = basename($url);
347         $link = HTML::img(array('src' => $url, 'alt' => $alt));
348         if (count($arr) > 1) {
349             array_shift($arr);
350             foreach ($arr as $attr) {
351                 if (preg_match('/^size=(\d+%)$/',$attr,$m)) {
352                     $link->setAttr('width',$m[1]);
353                     $link->setAttr('height',$m[1]);
354                 }
355                 if (preg_match('/^size=(\d+)x(\d+)$/',$attr,$m)) {
356                     $link->setAttr('width',$m[1]);
357                     $link->setAttr('height',$m[2]);
358                 }
359                 if (preg_match('/^border=(\d+)$/',$attr,$m))
360                     $link->setAttr('border',$m[1]);
361                 if (preg_match('/^align=(\w+)$/',$attr,$m))
362                     $link->setAttr('align',$m[1]);
363                 if (preg_match('/^hspace=(\d+)$/',$attr,$m))
364                     $link->setAttr('hspace',$m[1]);
365                 if (preg_match('/^vspace=(\d+)$/',$attr,$m))
366                     $link->setAttr('vspace',$m[1]);
367             }
368         }
369         // check width and height as spam countermeasure
370         if (($width  = $link->getAttr('width')) and ($height = $link->getAttr('height'))) {
371             //$width  = (int) $width; // px or % or other suffix
372             //$height = (int) $height;
373             if (($width < 3 and $height < 10) or 
374                 ($height < 3 and $width < 20) or 
375                 ($height < 7 and $width < 7))
376             {
377                 trigger_error(_("Invalid image size"), E_USER_NOTICE);
378                 return '';
379             }
380         } else {
381             // Older php versions crash here with certain png's: 
382             // confirmed for 4.1.2, 4.1.3, 4.2.3; 4.3.2 and 4.3.7 are ok
383             //   http://phpwiki.sourceforge.net/demo/themes/default/images/http.png
384             // See http://bugs.php.net/search.php?cmd=display&search_for=getimagesize
385             if (!check_php_version(4,3) and preg_match("/^http.+\.png$/i",$url))
386                 ; // it's safe to assume that this will fail.
387             elseif (!DISABLE_GETIMAGESIZE and ($size = @getimagesize($url))) {
388                 $width  = $size[0];
389                 $height = $size[1];
390                 if (($width < 3 and $height < 10) 
391                     or ($height < 3 and $width < 20)
392                     or ($height < 7 and $width < 7))
393                 {
394                     trigger_error(_("Invalid image size"), E_USER_NOTICE);
395                     return '';
396                 }
397             }
398         }
399     }
400     $link->setAttr('class', 'inlineimage');
401     return $link;
402 }
403
404
405
406 class Stack {
407
408     // var in php5 deprecated
409     function Stack() {
410         $this->items = array();
411         $this->size = 0;
412     }
413     function push($item) {
414         $this->items[$this->size] = $item;
415         $this->size++;
416         return true;
417     }  
418     
419     function pop() {
420         if ($this->size == 0) {
421             return false; // stack is empty
422         }  
423         $this->size--;
424         return $this->items[$this->size];
425     }  
426     
427     function cnt() {
428         return $this->size;
429     }  
430     
431     function top() {
432         if($this->size)
433             return $this->items[$this->size - 1];
434         else
435             return '';
436     }
437     
438 }  
439 // end class definition
440
441 function SplitQueryArgs ($query_args = '') 
442 {
443     $split_args = split('&', $query_args);
444     $args = array();
445     while (list($key, $val) = each($split_args))
446         if (preg_match('/^ ([^=]+) =? (.*) /x', $val, $m))
447             $args[$m[1]] = $m[2];
448     return $args;
449 }
450
451 function LinkPhpwikiURL($url, $text = '', $basepage = false) {
452     $args = array();
453     
454     if (!preg_match('/^ phpwiki: ([^?]*) [?]? (.*) $/x', $url, $m)) {
455         return HTML::strong(array('class' => 'rawurl'),
456                             HTML::u(array('class' => 'baduri'),
457                                     _("BAD phpwiki: URL")));
458     }
459
460     if ($m[1])
461         $pagename = urldecode($m[1]);
462     $qargs = $m[2];
463     
464     if (empty($pagename) &&
465         preg_match('/^(diff|edit|links|info)=([^&]+)$/', $qargs, $m)) {
466         // Convert old style links (to not break diff links in
467         // RecentChanges).
468         $pagename = urldecode($m[2]);
469         $args = array("action" => $m[1]);
470     }
471     else {
472         $args = SplitQueryArgs($qargs);
473     }
474
475     if (empty($pagename))
476         $pagename = $GLOBALS['request']->getArg('pagename');
477
478     if (isset($args['action']) && $args['action'] == 'browse')
479         unset($args['action']);
480     
481     /*FIXME:
482       if (empty($args['action']))
483       $class = 'wikilink';
484       else if (is_safe_action($args['action']))
485       $class = 'wikiaction';
486     */
487     if (empty($args['action']) || is_safe_action($args['action']))
488         $class = 'wikiaction';
489     else {
490         // Don't allow administrative links on unlocked pages.
491         $dbi = $GLOBALS['request']->getDbh();
492         $page = $dbi->getPage($basepage ? $basepage : $pagename);
493         if (!$page->get('locked'))
494             return HTML::span(array('class' => 'wikiunsafe'),
495                               HTML::u(_("Lock page to enable link")));
496         $class = 'wikiadmin';
497     }
498     
499     if (!$text)
500         $text = HTML::span(array('class' => 'rawurl'), $url);
501
502     $wikipage = new WikiPageName($pagename);
503     if (!$wikipage->isValid()) {
504         global $WikiTheme;
505         return $WikiTheme->linkBadWikiWord($wikipage, $url);
506     }
507     
508     return HTML::a(array('href'  => WikiURL($pagename, $args),
509                          'class' => $class),
510                    $text);
511 }
512
513 /**
514  * A class to assist in parsing wiki pagenames.
515  *
516  * Now with subpages and anchors, parsing and passing around
517  * pagenames is more complicated.  This should help.
518  */
519 class WikiPageName
520 {
521     /** Short name for page.
522      *
523      * This is the value of $name passed to the constructor.
524      * (For use, e.g. as a default label for links to the page.)
525      */
526     //var $shortName;
527
528     /** The full page name.
529      *
530      * This is the full name of the page (without anchor).
531      */
532     //var $name;
533     
534     /** The anchor.
535      *
536      * This is the referenced anchor within the page, or the empty string.
537      */
538     //var $anchor;
539     
540     /** Constructor
541      *
542      * @param mixed $name Page name.
543      * WikiDB_Page, WikiDB_PageRevision, or string.
544      * This can be a relative subpage name (like '/SubPage'),
545      * or can be the empty string to refer to the $basename.
546      *
547      * @param string $anchor For links to anchors in page.
548      *
549      * @param mixed $basename Page name from which to interpret
550      * relative or other non-fully-specified page names.
551      */
552     function WikiPageName($name, $basename=false, $anchor=false) {
553         if (is_string($name)) {
554             $this->shortName = $name;
555         
556             if ($name == '' or $name[0] == SUBPAGE_SEPARATOR) {
557                 if ($basename)
558                     $name = $this->_pagename($basename) . $name;
559                 else
560                     $name = $this->_normalize_bad_pagename($name);
561             }
562         }
563         else {
564             $name = $this->_pagename($name);
565             $this->shortName = $name;
566         }
567
568         $this->name = $this->_check($name);
569         $this->anchor = (string)$anchor;
570     }
571
572     function getParent() {
573         $name = $this->name;
574         if (!($tail = strrchr($name, SUBPAGE_SEPARATOR)))
575             return false;
576         return substr($name, 0, -strlen($tail));
577     }
578
579     function isValid($strict = false) {
580         if ($strict)
581             return !isset($this->_errors);
582         return (is_string($this->name) and $this->name != '');
583     }
584
585     function getWarnings() {
586         $warnings = array();
587         if (isset($this->_warnings))
588             $warnings = array_merge($warnings, $this->_warnings);
589         if (isset($this->_errors))
590             $warnings = array_merge($warnings, $this->_errors);
591         if (!$warnings)
592             return false;
593         
594         return sprintf(_("'%s': Bad page name: %s"),
595                        $this->shortName, join(', ', $warnings));
596     }
597     
598     function _pagename($page) {
599         if (isa($page, 'WikiDB_Page'))
600             return $page->getName();
601         elseif (isa($page, 'WikiDB_PageRevision'))
602             return $page->getPageName();
603         elseif (isa($page, 'WikiPageName'))
604             return $page->name;
605         if (!is_string($page)) {
606             trigger_error(sprintf("Non-string pagename '%s' (%s)(%s)",
607                                   $page, gettype($page), get_class($page)),
608                           E_USER_NOTICE);
609         }
610         //assert(is_string($page));
611         return $page;
612     }
613
614     function _normalize_bad_pagename($name) {
615         trigger_error("Bad pagename: " . $name, E_USER_WARNING);
616
617         // Punt...  You really shouldn't get here.
618         if (empty($name)) {
619             global $request;
620             return $request->getArg('pagename');
621         }
622         assert($name[0] == SUBPAGE_SEPARATOR);
623         return substr($name, 1);
624     }
625
626
627     function _check($pagename) {
628         // Compress internal white-space to single space character.
629         $pagename = preg_replace('/[\s\xa0]+/', ' ', $orig = $pagename);
630         if ($pagename != $orig)
631             $this->_warnings[] = _("White space converted to single space");
632     
633         // Delete any control characters.
634         $pagename = preg_replace('/[\x00-\x1f\x7f\x80-\x9f]/', '', $orig = $pagename);
635         if ($pagename != $orig)
636             $this->_errors[] = _("Control characters not allowed");
637
638         // Strip leading and trailing white-space.
639         $pagename = trim($pagename);
640
641         $orig = $pagename;
642         while ($pagename and $pagename[0] == SUBPAGE_SEPARATOR)
643             $pagename = substr($pagename, 1);
644         if ($pagename != $orig)
645             $this->_errors[] = sprintf(_("Leading %s not allowed"), SUBPAGE_SEPARATOR);
646
647         if (preg_match('/[:;]/', $pagename)) {
648             $this->_warnings[] = _("';' and ':' are deprecated");
649             $pagename = str_replace(':', '', $pagename);
650             $pagename = str_replace(';', '', $pagename);
651         }
652         
653         if (strlen($pagename) > MAX_PAGENAME_LENGTH) {
654             $pagename = substr($pagename, 0, MAX_PAGENAME_LENGTH);
655             $this->_errors[] = _("too long");
656         }
657
658         if (strstr($pagename, '..')) {
659             $this->_warnings[] = sprintf(_("illegal .. removed"), $pagename);
660             $pagename = str_replace('..', '', $pagename);
661         }
662         
663         return $pagename;
664     }
665 }
666
667 /**
668  * Convert old page markup to new-style markup.
669  *
670  * @param string $text Old-style wiki markup.
671  *
672  * @param string $markup_type
673  * One of: <dl>
674  * <dt><code>"block"</code>  <dd>Convert all markup.
675  * <dt><code>"inline"</code> <dd>Convert only inline markup.
676  * <dt><code>"links"</code>  <dd>Convert only link markup.
677  * </dl>
678  *
679  * @return string New-style wiki markup.
680  *
681  * @bugs Footnotes don't work quite as before (esp if there are
682  *   multiple references to the same footnote.  But close enough,
683  *   probably for now....
684  * @bugs  Apache2 and IIS crash with OldTextFormattingRules or
685  *   AnciennesR%E8glesDeFormatage. ( at the 2nd attempt to do the anchored block regex )
686  *   It only crashes with CreateToc so far, but other pages (not in pgsrc) are 
687  *   also known to crash, even with Apache1.
688  */
689 function ConvertOldMarkup ($text, $markup_type = "block") {
690
691     static $subs;
692     static $block_re;
693     
694     // FIXME:
695     // Trying to detect why the 2nd paragraph of OldTextFormattingRules or
696     // AnciennesR%E8glesDeFormatage crashes. 
697     // It only crashes with CreateToc so far, but other pages (not in pgsrc) are 
698     // also known to crash, even with Apache1.
699     $debug_skip = false;
700     // I suspect this only to crash with Apache2 and IIS.
701     if (in_array(php_sapi_name(),array('apache2handler','apache2filter','isapi'))
702         and preg_match("/plugin CreateToc/", $text)) 
703     {
704         trigger_error(_("The CreateTocPlugin is not yet old markup compatible! ")
705                      ._("Please remove the CreateToc line to be able to reformat this page to old markup. ")
706                      ._("Skipped."), E_USER_WARNING);
707         $debug_skip = true;
708         //if (!DEBUG) return $text;
709         return $text;
710     }
711
712     if (empty($subs)) {
713         /*****************************************************************
714          * Conversions for inline markup:
715          */
716
717         // escape tilde's
718         $orig[] = '/~/';
719         $repl[] = '~~';
720
721         // escape escaped brackets
722         $orig[] = '/\[\[/';
723         $repl[] = '~[';
724
725         // change ! escapes to ~'s.
726         global $WikiNameRegexp, $request;
727         $bang_esc[] = "(?:" . ALLOWED_PROTOCOLS . "):[^\s<>\[\]\"'()]*[^\s<>\[\]\"'(),.?]";
728         $map = getInterwikiMap();
729         if ($map_regex = $map->getRegexp())
730             $bang_esc[] = $map_regex . ":[^\\s.,;?()]+"; // FIXME: is this really needed?
731         $bang_esc[] = $WikiNameRegexp;
732         $orig[] = '/!((?:' . join(')|(', $bang_esc) . '))/';
733         $repl[] = '~\\1';
734
735         $subs["links"] = array($orig, $repl);
736
737         // Escape '<'s
738         //$orig[] = '/<(?!\?plugin)|(?<!^)</m';
739         //$repl[] = '~<';
740         
741         // Convert footnote references.
742         $orig[] = '/(?<=.)(?<!~)\[\s*(\d+)\s*\]/m';
743         $repl[] = '#[|ftnt_ref_\\1]<sup>~[[\\1|#ftnt_\\1]~]</sup>';
744
745         // Convert old style emphases to HTML style emphasis.
746         $orig[] = '/__(.*?)__/';
747         $repl[] = '<strong>\\1</strong>';
748         $orig[] = "/''(.*?)''/";
749         $repl[] = '<em>\\1</em>';
750
751         // Escape nestled markup.
752         $orig[] = '/^(?<=^|\s)[=_](?=\S)|(?<=\S)[=_*](?=\s|$)/m';
753         $repl[] = '~\\0';
754         
755         // in old markup headings only allowed at beginning of line
756         $orig[] = '/!/';
757         $repl[] = '~!';
758
759         $subs["inline"] = array($orig, $repl);
760
761         /*****************************************************************
762          * Patterns which match block markup constructs which take
763          * special handling...
764          */
765
766         // Indented blocks
767         $blockpats[] = '[ \t]+\S(?:.*\s*\n[ \t]+\S)*';
768         // Tables
769         $blockpats[] = '\|(?:.*\n\|)*';
770
771         // List items
772         $blockpats[] = '[#*;]*(?:[*#]|;.*?:)';
773
774         // Footnote definitions
775         $blockpats[] = '\[\s*(\d+)\s*\]';
776
777         if (!$debug_skip) {
778         // Plugins
779         $blockpats[] = '<\?plugin(?:-form)?\b.*\?>\s*$';
780         }
781
782         // Section Title
783         $blockpats[] = '!{1,3}[^!]';
784
785         $block_re = ( '/\A((?:.|\n)*?)(^(?:'
786                       . join("|", $blockpats)
787                       . ').*$)\n?/m' );
788         
789     }
790     
791     if ($markup_type != "block") {
792         list ($orig, $repl) = $subs[$markup_type];
793         return preg_replace($orig, $repl, $text);
794     }
795     else {
796         list ($orig, $repl) = $subs['inline'];
797         $out = '';
798         //FIXME:
799         // php crashes here in the 2nd paragraph of OldTextFormattingRules, 
800         // AnciennesR%E8glesDeFormatage and more 
801          while (preg_match($block_re, $text, $m)) {
802             $text = substr($text, strlen($m[0]));
803             list (,$leading_text, $block) = $m;
804             $suffix = "\n";
805             
806             if (strchr(" \t", $block[0])) {
807                 // Indented block
808                 $prefix = "<pre>\n";
809                 $suffix = "\n</pre>\n";
810             }
811             elseif ($block[0] == '|') {
812                 // Old-style table
813                 $prefix = "<?plugin OldStyleTable\n";
814                 $suffix = "\n?>\n";
815             }
816             elseif (strchr("#*;", $block[0])) {
817                 // Old-style list item
818                 preg_match('/^([#*;]*)([*#]|;.*?:) */', $block, $m);
819                 list (,$ind,$bullet) = $m;
820                 $block = substr($block, strlen($m[0]));
821                 
822                 $indent = str_repeat('     ', strlen($ind));
823                 if ($bullet[0] == ';') {
824                     //$term = ltrim(substr($bullet, 1));
825                     //return $indent . $term . "\n" . $indent . '     ';
826                     $prefix = $ind . $bullet;
827                 }
828                 else
829                     $prefix = $indent . $bullet . ' ';
830             }
831             elseif ($block[0] == '[') {
832                 // Footnote definition
833                 preg_match('/^\[\s*(\d+)\s*\]/', $block, $m);
834                 $footnum = $m[1];
835                 $block = substr($block, strlen($m[0]));
836                 $prefix = "#[|ftnt_${footnum}]~[[${footnum}|#ftnt_ref_${footnum}]~] ";
837             }
838             elseif ($block[0] == '<') {
839                 // Plugin.
840                 // HACK: no inline markup...
841                 $prefix = $block;
842                 $block = '';
843             }
844             elseif ($block[0] == '!') {
845                 // Section heading
846                 preg_match('/^!{1,3}/', $block, $m);
847                 $prefix = $m[0];
848                 $block = substr($block, strlen($m[0]));
849             }
850             else {
851                 // AAck!
852                 assert(0);
853             }
854             if ($leading_text) $leading_text = preg_replace($orig, $repl, $leading_text);
855             if ($block) $block = preg_replace($orig, $repl, $block);
856             $out .= $leading_text;
857             $out .= $prefix;
858             $out .= $block;
859             $out .= $suffix;
860         }
861         return $out . preg_replace($orig, $repl, $text);
862     }
863 }
864
865
866 /**
867  * Expand tabs in string.
868  *
869  * Converts all tabs to (the appropriate number of) spaces.
870  *
871  * @param string $str
872  * @param integer $tab_width
873  * @return string
874  */
875 function expand_tabs($str, $tab_width = 8) {
876     $split = split("\t", $str);
877     $tail = array_pop($split);
878     $expanded = "\n";
879     foreach ($split as $hunk) {
880         $expanded .= $hunk;
881         $pos = strlen(strrchr($expanded, "\n")) - 1;
882         $expanded .= str_repeat(" ", ($tab_width - $pos % $tab_width));
883     }
884     return substr($expanded, 1) . $tail;
885 }
886
887 /**
888  * Split WikiWords in page names.
889  *
890  * It has been deemed useful to split WikiWords (into "Wiki Words") in
891  * places like page titles. This is rumored to help search engines
892  * quite a bit.
893  *
894  * @param $page string The page name.
895  *
896  * @return string The split name.
897  */
898 function SplitPagename ($page) {
899     
900     if (preg_match("/\s/", $page))
901         return $page;           // Already split --- don't split any more.
902     
903     // This algorithm is specialized for several languages.
904     // (Thanks to Pierrick MEIGNEN)
905     // Improvements for other languages welcome.
906     static $RE;
907     if (!isset($RE)) {
908         // This mess splits between a lower-case letter followed by
909         // either an upper-case or a numeral; except that it wont
910         // split the prefixes 'Mc', 'De', or 'Di' off of their tails.
911         switch ($GLOBALS['LANG']) {
912         case 'en':
913         case 'it':
914         case 'es': 
915         case 'de':
916             $RE[] = '/([[:lower:]])((?<!Mc|De|Di)[[:upper:]]|\d)/';
917             break;
918         case 'fr': 
919             $RE[] = '/([[:lower:]])((?<!Mc|Di)[[:upper:]]|\d)/';
920             break;
921         }
922         $sep = preg_quote(SUBPAGE_SEPARATOR, '/');
923         // This the single-letter words 'I' and 'A' from any following
924         // capitalized words.
925         switch ($GLOBALS['LANG']) {
926         case 'en': 
927             $RE[] = "/(?<= |${sep}|^)([AI])([[:upper:]][[:lower:]])/";
928             break;
929         case 'fr': 
930             $RE[] = "/(?<= |${sep}|^)([À])([[:upper:]][[:lower:]])/";
931             break;
932         }
933         // Split numerals from following letters.
934         $RE[] = '/(\d)([[:alpha:]])/';
935         // Split at subpage seperators. TBD in Theme.php
936         $RE[] = "/([^${sep}]+)(${sep})/";
937         
938         foreach ($RE as $key)
939             $RE[$key] = pcre_fix_posix_classes($key);
940     }
941
942     foreach ($RE as $regexp) {
943         $page = preg_replace($regexp, '\\1 \\2', $page);
944     }
945     return $page;
946 }
947
948 function NoSuchRevision (&$request, $page, $version) {
949     $html = HTML(HTML::h2(_("Revision Not Found")),
950                  HTML::p(fmt("I'm sorry.  Version %d of %s is not in the database.",
951                              $version, WikiLink($page, 'auto'))));
952     include_once('lib/Template.php');
953     GeneratePage($html, _("Bad Version"), $page->getCurrentRevision());
954     $request->finish();
955 }
956
957
958 /**
959  * Get time offset for local time zone.
960  *
961  * @param $time time_t Get offset for this time. Default: now.
962  * @param $no_colon boolean Don't put colon between hours and minutes.
963  * @return string Offset as a string in the format +HH:MM.
964  */
965 function TimezoneOffset ($time = false, $no_colon = false) {
966     if ($time === false)
967         $time = time();
968     $secs = date('Z', $time);
969
970     if ($secs < 0) {
971         $sign = '-';
972         $secs = -$secs;
973     }
974     else {
975         $sign = '+';
976     }
977     $colon = $no_colon ? '' : ':';
978     $mins = intval(($secs + 30) / 60);
979     return sprintf("%s%02d%s%02d",
980                    $sign, $mins / 60, $colon, $mins % 60);
981 }
982
983
984 /**
985  * Format time in ISO-8601 format.
986  *
987  * @param $time time_t Time.  Default: now.
988  * @return string Date and time in ISO-8601 format.
989  */
990 function Iso8601DateTime ($time = false) {
991     if ($time === false)
992         $time = time();
993     $tzoff = TimezoneOffset($time);
994     $date  = date('Y-m-d', $time);
995     $time  = date('H:i:s', $time);
996     return $date . 'T' . $time . $tzoff;
997 }
998
999 /**
1000  * Format time in RFC-2822 format.
1001  *
1002  * @param $time time_t Time.  Default: now.
1003  * @return string Date and time in RFC-2822 format.
1004  */
1005 function Rfc2822DateTime ($time = false) {
1006     if ($time === false)
1007         $time = time();
1008     return date('D, j M Y H:i:s ', $time) . TimezoneOffset($time, 'no colon');
1009 }
1010
1011 /**
1012  * Format time in RFC-1123 format.
1013  *
1014  * @param $time time_t Time.  Default: now.
1015  * @return string Date and time in RFC-1123 format.
1016  */
1017 function Rfc1123DateTime ($time = false) {
1018     if ($time === false)
1019         $time = time();
1020     return gmdate('D, d M Y H:i:s \G\M\T', $time);
1021 }
1022
1023 /** Parse date in RFC-1123 format.
1024  *
1025  * According to RFC 1123 we must accept dates in the following
1026  * formats:
1027  *
1028  *   Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
1029  *   Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
1030  *   Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() format
1031  *
1032  * (Though we're only allowed to generate dates in the first format.)
1033  */
1034 function ParseRfc1123DateTime ($timestr) {
1035     $timestr = trim($timestr);
1036     if (preg_match('/^ \w{3},\s* (\d{1,2}) \s* (\w{3}) \s* (\d{4}) \s*'
1037                    .'(\d\d):(\d\d):(\d\d) \s* GMT $/ix',
1038                    $timestr, $m)) {
1039         list(, $mday, $mon, $year, $hh, $mm, $ss) = $m;
1040     }
1041     elseif (preg_match('/^ \w+,\s* (\d{1,2})-(\w{3})-(\d{2}|\d{4}) \s*'
1042                        .'(\d\d):(\d\d):(\d\d) \s* GMT $/ix',
1043                        $timestr, $m)) {
1044         list(, $mday, $mon, $year, $hh, $mm, $ss) = $m;
1045         if ($year < 70) $year += 2000;
1046         elseif ($year < 100) $year += 1900;
1047     }
1048     elseif (preg_match('/^\w+\s* (\w{3}) \s* (\d{1,2}) \s*'
1049                        .'(\d\d):(\d\d):(\d\d) \s* (\d{4})$/ix',
1050                        $timestr, $m)) {
1051         list(, $mon, $mday, $hh, $mm, $ss, $year) = $m;
1052     }
1053     else {
1054         // Parse failed.
1055         return false;
1056     }
1057
1058     $time = strtotime("$mday $mon $year ${hh}:${mm}:${ss} GMT");
1059     if ($time == -1)
1060         return false;           // failed
1061     return $time;
1062 }
1063
1064 /**
1065  * Format time to standard 'ctime' format.
1066  *
1067  * @param $time time_t Time.  Default: now.
1068  * @return string Date and time.
1069  */
1070 function CTime ($time = false)
1071 {
1072     if ($time === false)
1073         $time = time();
1074     return date("D M j H:i:s Y", $time);
1075 }
1076
1077
1078 /**
1079  * Format number as kilobytes or bytes.
1080  * Short format is used for PageList
1081  * Long format is used in PageInfo
1082  *
1083  * @param $bytes       int.  Default: 0.
1084  * @param $longformat  bool. Default: false.
1085  * @return class FormattedText (XmlElement.php).
1086  */
1087 function ByteFormatter ($bytes = 0, $longformat = false) {
1088     if ($bytes < 0)
1089         return fmt("-???");
1090     if ($bytes < 1024) {
1091         if (! $longformat)
1092             $size = fmt("%s b", $bytes);
1093         else
1094             $size = fmt("%s bytes", $bytes);
1095     }
1096     else {
1097         $kb = round($bytes / 1024, 1);
1098         if (! $longformat)
1099             $size = fmt("%s k", $kb);
1100         else
1101             $size = fmt("%s Kb (%s bytes)", $kb, $bytes);
1102     }
1103     return $size;
1104 }
1105
1106 /**
1107  * Internationalized printf.
1108  *
1109  * This is essentially the same as PHP's built-in printf
1110  * with the following exceptions:
1111  * <ol>
1112  * <li> It passes the format string through gettext().
1113  * <li> It supports the argument reordering extensions.
1114  * </ol>
1115  *
1116  * Example:
1117  *
1118  * In php code, use:
1119  * <pre>
1120  *    __printf("Differences between versions %s and %s of %s",
1121  *             $new_link, $old_link, $page_link);
1122  * </pre>
1123  *
1124  * Then in locale/po/de.po, one can reorder the printf arguments:
1125  *
1126  * <pre>
1127  *    msgid "Differences between %s and %s of %s."
1128  *    msgstr "Der Unterschiedsergebnis von %3$s, zwischen %1$s und %2$s."
1129  * </pre>
1130  *
1131  * (Note that while PHP tries to expand $vars within double-quotes,
1132  * the values in msgstr undergo no such expansion, so the '$'s
1133  * okay...)
1134  *
1135  * One shouldn't use reordered arguments in the default format string.
1136  * Backslashes in the default string would be necessary to escape the
1137  * '$'s, and they'll cause all kinds of trouble....
1138  */ 
1139 function __printf ($fmt) {
1140     $args = func_get_args();
1141     array_shift($args);
1142     echo __vsprintf($fmt, $args);
1143 }
1144
1145 /**
1146  * Internationalized sprintf.
1147  *
1148  * This is essentially the same as PHP's built-in printf with the
1149  * following exceptions:
1150  *
1151  * <ol>
1152  * <li> It passes the format string through gettext().
1153  * <li> It supports the argument reordering extensions.
1154  * </ol>
1155  *
1156  * @see __printf
1157  */ 
1158 function __sprintf ($fmt) {
1159     $args = func_get_args();
1160     array_shift($args);
1161     return __vsprintf($fmt, $args);
1162 }
1163
1164 /**
1165  * Internationalized vsprintf.
1166  *
1167  * This is essentially the same as PHP's built-in printf with the
1168  * following exceptions:
1169  *
1170  * <ol>
1171  * <li> It passes the format string through gettext().
1172  * <li> It supports the argument reordering extensions.
1173  * </ol>
1174  *
1175  * @see __printf
1176  */ 
1177 function __vsprintf ($fmt, $args) {
1178     $fmt = gettext($fmt);
1179     // PHP's sprintf doesn't support variable with specifiers,
1180     // like sprintf("%*s", 10, "x"); --- so we won't either.
1181     
1182     if (preg_match_all('/(?<!%)%(\d+)\$/x', $fmt, $m)) {
1183         // Format string has '%2$s' style argument reordering.
1184         // PHP doesn't support this.
1185         if (preg_match('/(?<!%)%[- ]?\d*[^- \d$]/x', $fmt))
1186             // literal variable name substitution only to keep locale
1187             // strings uncluttered
1188             trigger_error(sprintf(_("Can't mix '%s' with '%s' type format strings"),
1189                                   '%1\$s','%s'), E_USER_WARNING); //php+locale error
1190         
1191         $fmt = preg_replace('/(?<!%)%\d+\$/x', '%', $fmt);
1192         $newargs = array();
1193         
1194         // Reorder arguments appropriately.
1195         foreach($m[1] as $argnum) {
1196             if ($argnum < 1 || $argnum > count($args))
1197                 trigger_error(sprintf(_("%s: argument index out of range"), 
1198                                       $argnum), E_USER_WARNING);
1199             $newargs[] = $args[$argnum - 1];
1200         }
1201         $args = $newargs;
1202     }
1203     
1204     // Not all PHP's have vsprintf, so...
1205     array_unshift($args, $fmt);
1206     return call_user_func_array('sprintf', $args);
1207 }
1208
1209 function file_mtime ($filename) {
1210     if ($stat = @stat($filename))
1211         return $stat[9];
1212     else 
1213         return false;
1214 }
1215
1216 function sort_file_mtime ($a, $b) {
1217     $ma = file_mtime($a);
1218     $mb = file_mtime($b);
1219     if (!$ma or !$mb or $ma == $mb) return 0;
1220     return ($ma > $mb) ? -1 : 1;
1221 }
1222
1223 class fileSet {
1224     /**
1225      * Build an array in $this->_fileList of files from $dirname.
1226      * Subdirectories are not traversed.
1227      *
1228      * (This was a function LoadDir in lib/loadsave.php)
1229      * See also http://www.php.net/manual/en/function.readdir.php
1230      */
1231     function getFiles($exclude=false, $sortby=false, $limit=false) {
1232         $list = $this->_fileList;
1233
1234         if ($sortby) {
1235             require_once('lib/PageList.php');
1236             switch (Pagelist::sortby($sortby, 'db')) {
1237             case 'pagename ASC': break;
1238             case 'pagename DESC': 
1239                 $list = array_reverse($list); 
1240                 break;
1241             case 'mtime ASC': 
1242                 usort($list,'sort_file_mtime'); 
1243                 break;
1244             case 'mtime DESC': 
1245                 usort($list,'sort_file_mtime');
1246                 $list = array_reverse($list); 
1247                 break;
1248             }
1249         }
1250         if ($limit)
1251             return array_splice($list, 0, $limit);
1252         return $list;
1253     }
1254
1255     function _filenameSelector($filename) {
1256         if (! $this->_pattern)
1257             return true;
1258         else {
1259             return glob_match ($this->_pattern, $filename, $this->_case);
1260         }
1261     }
1262
1263     function fileSet($directory, $filepattern = false) {
1264         $this->_fileList = array();
1265         $this->_pattern = $filepattern;
1266         $this->_case = !isWindows();
1267         $this->_pathsep = '/';
1268
1269         if (empty($directory)) {
1270             trigger_error(sprintf(_("%s is empty."), 'directoryname'),
1271                           E_USER_NOTICE);
1272             return; // early return
1273         }
1274
1275         @ $dir_handle = opendir($dir=$directory);
1276         if (empty($dir_handle)) {
1277             trigger_error(sprintf(_("Unable to open directory '%s' for reading"),
1278                                   $dir), E_USER_NOTICE);
1279             return; // early return
1280         }
1281
1282         while ($filename = readdir($dir_handle)) {
1283             if ($filename[0] == '.' || filetype($dir . $this->_pathsep . $filename) != 'file')
1284                 continue;
1285             if ($this->_filenameSelector($filename)) {
1286                 array_push($this->_fileList, "$filename");
1287                 //trigger_error(sprintf(_("found file %s"), $filename),
1288                 //                      E_USER_NOTICE); //debugging
1289             }
1290         }
1291         closedir($dir_handle);
1292     }
1293 };
1294
1295 // File globbing
1296
1297 // expands a list containing regex's to its matching entries
1298 class ListRegexExpand {
1299     //var $match, $list, $index, $case_sensitive;
1300     function ListRegexExpand (&$list, $match, $case_sensitive = true) {
1301         $this->match = str_replace('/','\/',$match);
1302         $this->list = &$list;
1303         $this->case_sensitive = $case_sensitive;        
1304         //$this->index = false;
1305     }
1306     function listMatchCallback ($item, $key) {
1307         if (preg_match('/' . $this->match . ($this->case_sensitive ? '/' : '/i'), $item)) {
1308             unset($this->list[$this->index]);
1309             $this->list[] = $item;
1310         }
1311     }
1312     function expandRegex ($index, &$pages) {
1313         $this->index = $index;
1314         array_walk($pages, array($this, 'listMatchCallback'));
1315         return $this->list;
1316     }
1317 }
1318
1319 // convert fileglob to regex style
1320 function glob_to_pcre ($glob) {
1321     $re = preg_replace('/\./', '\\.', $glob);
1322     $re = preg_replace(array('/\*/','/\?/'), array('.*','.'), $glob);
1323     if (!preg_match('/^[\?\*]/',$glob))
1324         $re = '^' . $re;
1325     if (!preg_match('/[\?\*]$/',$glob))
1326         $re = $re . '$';
1327     return $re;
1328 }
1329
1330 function glob_match ($glob, $against, $case_sensitive = true) {
1331     return preg_match('/' . glob_to_pcre($glob) . ($case_sensitive ? '/' : '/i'), $against);
1332 }
1333
1334 function explodeList($input, $allnames, $glob_style = true, $case_sensitive = true) {
1335     $list = explode(',',$input);
1336     // expand wildcards from list of $allnames
1337     if (preg_match('/[\?\*]/',$input)) {
1338         // Optimizing loop invariants:
1339         // http://phplens.com/lens/php-book/optimizing-debugging-php.php
1340         for ($i = 0, $max = sizeof($list); $i < $max; $i++) {
1341             $f = $list[$i];
1342             if (preg_match('/[\?\*]/',$f)) {
1343                 reset($allnames);
1344                 $expand = new ListRegexExpand($list, $glob_style ? glob_to_pcre($f) : $f, $case_sensitive);
1345                 $expand->expandRegex($i, $allnames);
1346             }
1347         }
1348     }
1349     return $list;
1350 }
1351
1352 // echo implode(":",explodeList("Test*",array("xx","Test1","Test2")));
1353 function explodePageList($input, $perm=false, $sortby='pagename', $limit=false) {
1354     include_once("lib/PageList.php");
1355     return PageList::explodePageList($input,$perm,$sortby,$limit);
1356 }
1357
1358 // Class introspections
1359
1360 /** 
1361  * Determine whether object is of a specified type.
1362  * In PHP builtin since 4.2.0 as is_a()
1363  *
1364  * @param $object object An object.
1365  * @param $class string Class name.
1366  * @return bool True iff $object is a $class
1367  * or a sub-type of $class. 
1368  */
1369 function isa ($object, $class) {
1370     $lclass = strtolower($class);
1371
1372     return is_object($object)
1373         && ( strtolower(get_class($object)) == $lclass
1374              || is_subclass_of($object, $lclass) );
1375 }
1376
1377 /** Determine whether (possible) object has method.
1378  *
1379  * @param $object mixed Object
1380  * @param $method string Method name
1381  * @return bool True iff $object is an object with has method $method.
1382  */
1383 function can ($object, $method) {
1384     return is_object($object) && method_exists($object, strtolower($method));
1385 }
1386
1387 /** Determine whether a function is okay to use.
1388  *
1389  * Some providers (e.g. Lycos) disable some of PHP functions for
1390  * "security reasons."  This makes those functions, of course,
1391  * unusable, despite the fact the function_exists() says they
1392  * exist.
1393  *
1394  * This function test to see if a function exists and is not
1395  * disallowed by PHP's disable_functions config setting.
1396  *
1397  * @param string $function_name  Function name
1398  * @return bool  True iff function can be used.
1399  */
1400 function function_usable($function_name) {
1401     static $disabled;
1402     if (!is_array($disabled)) {
1403         $disabled = array();
1404         // Use get_cfg_var since ini_get() is one of the disabled functions
1405         // (on Lycos, at least.)
1406         $split = preg_split('/\s*,\s*/', trim(get_cfg_var('disable_functions')));
1407         foreach ($split as $f)
1408             $disabled[strtolower($f)] = true;
1409     }
1410
1411     return ( function_exists($function_name)
1412              and ! isset($disabled[strtolower($function_name)])
1413              );
1414 }
1415     
1416     
1417 /** Hash a value.
1418  *
1419  * This is used for generating ETags.
1420  */
1421 function hash ($x) {
1422     if (is_scalar($x)) {
1423         return $x;
1424     }
1425     elseif (is_array($x)) {            
1426         ksort($x);
1427         return md5(serialize($x));
1428     }
1429     elseif (is_object($x)) {
1430         return $x->hash();
1431     }
1432     trigger_error("Can't hash $x", E_USER_ERROR);
1433 }
1434
1435     
1436 /**
1437  * Seed the random number generator.
1438  *
1439  * better_srand() ensures the randomizer is seeded only once.
1440  * 
1441  * How random do you want it? See:
1442  * http://www.php.net/manual/en/function.srand.php
1443  * http://www.php.net/manual/en/function.mt-srand.php
1444  */
1445 function better_srand($seed = '') {
1446     static $wascalled = FALSE;
1447     if (!$wascalled) {
1448         $seed = $seed === '' ? (double) microtime() * 1000000 : $seed;
1449         srand($seed);
1450         $wascalled = TRUE;
1451         //trigger_error("new random seed", E_USER_NOTICE); //debugging
1452     }
1453 }
1454
1455 /**
1456  * Recursively count all non-empty elements 
1457  * in array of any dimension or mixed - i.e. 
1458  * array('1' => 2, '2' => array('1' => 3, '2' => 4))
1459  * See http://www.php.net/manual/en/function.count.php
1460  */
1461 function count_all($arg) {
1462     // skip if argument is empty
1463     if ($arg) {
1464         //print_r($arg); //debugging
1465         $count = 0;
1466         // not an array, return 1 (base case) 
1467         if(!is_array($arg))
1468             return 1;
1469         // else call recursively for all elements $arg
1470         foreach($arg as $key => $val)
1471             $count += count_all($val);
1472         return $count;
1473     }
1474 }
1475
1476 function isSubPage($pagename) {
1477     return (strstr($pagename, SUBPAGE_SEPARATOR));
1478 }
1479
1480 function subPageSlice($pagename, $pos) {
1481     $pages = explode(SUBPAGE_SEPARATOR,$pagename);
1482     $pages = array_slice($pages,$pos,1);
1483     return $pages[0];
1484 }
1485
1486 /**
1487  * Alert
1488  *
1489  * Class for "popping up" and alert box.  (Except that right now, it doesn't
1490  * pop up...)
1491  *
1492  * FIXME:
1493  * This is a hackish and needs to be refactored.  However it would be nice to
1494  * unify all the different methods we use for showing Alerts and Dialogs.
1495  * (E.g. "Page deleted", login form, ...)
1496  */
1497 class Alert {
1498     /** Constructor
1499      *
1500      * @param object $request
1501      * @param mixed $head  Header ("title") for alert box.
1502      * @param mixed $body  The text in the alert box.
1503      * @param hash $buttons  An array mapping button labels to URLs.
1504      *    The default is a single "Okay" button pointing to $request->getURLtoSelf().
1505      */
1506     function Alert($head, $body, $buttons=false) {
1507         if ($buttons === false)
1508             $buttons = array();
1509
1510         $this->_tokens = array('HEADER' => $head, 'CONTENT' => $body);
1511         $this->_buttons = $buttons;
1512     }
1513
1514     /**
1515      * Show the alert box.
1516      */
1517     function show(&$request) {
1518         global $request;
1519
1520         $tokens = $this->_tokens;
1521         $tokens['BUTTONS'] = $this->_getButtons();
1522         
1523         $request->discardOutput();
1524         $tmpl = new Template('dialog', $request, $tokens);
1525         $tmpl->printXML();
1526         $request->finish();
1527     }
1528
1529
1530     function _getButtons() {
1531         global $request;
1532
1533         $buttons = $this->_buttons;
1534         if (!$buttons)
1535             $buttons = array(_("Okay") => $request->getURLtoSelf());
1536         
1537         global $WikiTheme;
1538         foreach ($buttons as $label => $url)
1539             print "$label $url\n";
1540             $out[] = $WikiTheme->makeButton($label, $url, 'wikiaction');
1541         return new XmlContent($out);
1542     }
1543 }
1544
1545 // 1.3.8     => 1030.08
1546 // 1.3.9-p1  => 1030.091
1547 // 1.3.10pre => 1030.099
1548 function phpwiki_version() {
1549     static $PHPWIKI_VERSION;
1550     if (!isset($PHPWIKI_VERSION)) {
1551         $arr = explode('.',preg_replace('/\D+$/','', PHPWIKI_VERSION)); // remove the pre
1552         $arr[2] = preg_replace('/\.+/','.',preg_replace('/\D/','.',$arr[2]));
1553         $PHPWIKI_VERSION = $arr[0]*1000 + $arr[1]*10 + 0.01*$arr[2];
1554         if (substr(PHPWIKI_VERSION,-3,3) == 'pre')
1555             $PHPWIKI_VERSION -= 0.001;
1556     }
1557     return $PHPWIKI_VERSION;
1558 }
1559
1560 function isWikiWord($word) {
1561     global $WikiNameRegexp;
1562     //or preg_match('/\A' . $WikiNameRegexp . '\z/', $word) ??
1563     return preg_match("/^$WikiNameRegexp\$/",$word);
1564 }
1565
1566 // needed to store serialized objects-values only (perm, pref)
1567 function obj2hash ($obj, $exclude = false, $fields = false) {
1568     $a = array();
1569     if (! $fields ) $fields = get_object_vars($obj);
1570     foreach ($fields as $key => $val) {
1571         if (is_array($exclude)) {
1572             if (in_array($key,$exclude)) continue;
1573         }
1574         $a[$key] = $val;
1575     }
1576     return $a;
1577 }
1578
1579 /**
1580  * isUtf8String($string) - cheap utf-8 detection
1581  *
1582  * segfaults for strings longer than 10kb!
1583  * Use http://www.phpdiscuss.com/article.php?id=565&group=php.i18n or
1584  * checkTitleEncoding() at http://cvs.sourceforge.net/viewcvs.py/wikipedia/phase3/languages/Language.php
1585  */
1586 function isUtf8String( $s ) {
1587     $ptrASCII  = '[\x00-\x7F]';
1588     $ptr2Octet = '[\xC2-\xDF][\x80-\xBF]';
1589     $ptr3Octet = '[\xE0-\xEF][\x80-\xBF]{2}';
1590     $ptr4Octet = '[\xF0-\xF4][\x80-\xBF]{3}';
1591     $ptr5Octet = '[\xF8-\xFB][\x80-\xBF]{4}';
1592     $ptr6Octet = '[\xFC-\xFD][\x80-\xBF]{5}';
1593     return preg_match("/^($ptrASCII|$ptr2Octet|$ptr3Octet|$ptr4Octet|$ptr5Octet|$ptr6Octet)*$/s", $s);
1594 }
1595
1596 /** 
1597  * Check for UTF-8 URLs; Internet Explorer produces these if you
1598  * type non-ASCII chars in the URL bar or follow unescaped links.
1599  * Requires urldecoded pagename.
1600  * Fixes sf.net bug #953949
1601  *
1602  * src: languages/Language.php:checkTitleEncoding() from mediawiki
1603  */
1604 function fixTitleEncoding( $s ) {
1605     global $charset;
1606
1607     $s = trim($s);
1608     // print a warning?
1609     if (empty($s)) return $s;
1610
1611     $ishigh = preg_match( '/[\x80-\xff]/', $s);
1612     /*
1613     $isutf = ($ishigh ? preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
1614                                     '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s ) : true );
1615     */
1616     $isutf = ($ishigh ? isUtf8String($s) : true);
1617     $locharset = strtolower($charset);
1618
1619     if( $locharset != "utf-8" and $ishigh and $isutf )
1620         // if charset == 'iso-8859-1' then simply use utf8_decode()
1621         if ($locharset == 'iso-8859-1')
1622             return utf8_decode( $s );
1623         else
1624             // TODO: check for iconv support
1625             return iconv( "UTF-8", $charset, $s );
1626
1627     if ($locharset == "utf-8" and $ishigh and !$isutf )
1628         return utf8_encode( $s );
1629
1630     // Other languages can safely leave this function, or replace
1631     // it with one to detect and convert another legacy encoding.
1632     return $s;
1633 }
1634
1635 /** 
1636  * MySQL fulltext index doesn't grok utf-8, so we
1637  * need to fold cases and convert to hex.
1638  * src: languages/Language.php:stripForSearch() from mediawiki
1639  */
1640 /*
1641 function stripForSearch( $string ) {
1642     global $wikiLowerChars; 
1643     // '/(?:[a-z]|\xc3[\x9f-\xbf]|\xc4[\x81\x83\x85\x87])/' => "a-z\xdf-\xf6\xf8-\xff"
1644     return preg_replace(
1645                         "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
1646                         "'U8' . bin2hex( strtr( \"\$1\", \$wikiLowerChars ) )",
1647                         $string );
1648 }
1649 */
1650
1651 /** 
1652  * Workaround for allow_url_fopen, to get the content of an external URI.
1653  * It returns the contents in one slurp. Parsers might want to check for allow_url_fopen
1654  * and use fopen, fread chunkwise. (see lib/XmlParser.php)
1655  */
1656 function url_get_contents( $uri ) {
1657     if (get_cfg_var('allow_url_fopen')) { // was ini_get('allow_url_fopen'))
1658         return @file_get_contents($uri);
1659     } else {
1660         require_once("lib/HttpClient.php");
1661         $bits = parse_url($uri);
1662         $host = $bits['host'];
1663         $port = isset($bits['port']) ? $bits['port'] : 80;
1664         $path = isset($bits['path']) ? $bits['path'] : '/';
1665         if (isset($bits['query'])) {
1666             $path .= '?'.$bits['query'];
1667         }
1668         $client = new HttpClient($host, $port);
1669         $client->use_gzip = false;
1670         if (!$client->get($path)) {
1671             return false;
1672         } else {
1673             return $client->getContent();
1674         }
1675     }
1676 }
1677
1678 /**
1679  * Generate consecutively named strings:
1680  *   Name, Name2, Name3, ...
1681  */
1682 function GenerateId($name) {
1683     static $ids = array();
1684     if (empty($ids[$name])) {
1685         $ids[$name] = 1;
1686         return $name;
1687     } else {
1688         $ids[$name]++;
1689         return $name . $ids[$name];
1690     }
1691 }
1692
1693 // from IncludePage. To be of general use.
1694 // content: string or array of strings
1695 function firstNWordsOfContent( $n, $content ) {
1696     if ($content and $n > 0) {
1697         if (is_array($content)) {
1698             // fixme: return a list of lines then?
1699             $content = join("\n", $content);
1700             $return_array = true;
1701             $wordcount = 0;
1702             foreach ($content as $line) {
1703                 $words = explode(' ', $line);
1704                 if ($wordcount + count($words) > $n) {
1705                     $new[] = implode(' ', array_slice($words, 0, $n - $wordcount))
1706                            . sprintf(_("... (first %s words)"), $n);
1707                     return $new;
1708                 } else {
1709                     $wordcount += count($words);
1710                     $new[] = $line;
1711                 }
1712             }
1713             return $new;
1714         } else {
1715             // fixme: use better whitespace/word seperators
1716             $words = explode(' ', $content);
1717             if (count($words) > $n) {
1718                 return join(' ', array_slice($words, 0, $n))
1719                        . sprintf(_("... (first %s words)"), $n);
1720             } else {
1721                 return $content;
1722             }
1723         }
1724     } else {
1725         return '';
1726     }
1727 }
1728
1729 // moved from lib/plugin/IncludePage.php
1730 function extractSection ($section, $content, $page, $quiet = false, $sectionhead = false) {
1731     $qsection = preg_replace('/\s+/', '\s+', preg_quote($section, '/'));
1732
1733     if (preg_match("/ ^(!{1,})\\s*$qsection" // section header
1734                    . "  \\s*$\\n?"           // possible blank lines
1735                    . "  ( (?: ^.*\\n? )*? )" // some lines
1736                    . "  (?= ^\\1 | \\Z)/xm", // sec header (same or higher level) (or EOF)
1737                    implode("\n", $content),
1738                    $match)) {
1739         // Strip trailing blanks lines and ---- <hr>s
1740         $text = preg_replace("/\\s*^-{4,}\\s*$/m", "", $match[2]);
1741         if ($sectionhead)
1742             $text = $match[1] . $section ."\n". $text;
1743         return explode("\n", $text);
1744     }
1745     if ($quiet)
1746         $mesg = $page ." ". $section;
1747     else
1748         $mesg = $section;
1749     return array(sprintf(_("<%s: no such section>"), $mesg));
1750 }
1751
1752 function isExternalReferrer(&$request) {
1753     if ($referrer = $request->get('HTTP_REFERER')) {
1754         $home = SCRIPT_NAME; // was SERVER_URL, but we want to check sister wiki's also
1755         if (substr(strtolower($referrer),0,strlen($home)) == strtolower($home)) return false;
1756         require_once("lib/ExternalReferrer.php");
1757         $se = new SearchEngines();
1758         return $se->parseSearchQuery($referrer);
1759     }
1760     return false;
1761 }
1762
1763 // $Log: not supported by cvs2svn $
1764 // Revision 1.207  2004/09/26 12:21:40  rurban
1765 // removed old log entries.
1766 // added persistent start_debug on internal links and DEBUG
1767 // added isExternalReferrer (not yet used)
1768 //
1769 // Revision 1.206  2004/09/25 16:28:36  rurban
1770 // added to TOC, firstNWordsOfContent is now plugin compatible, added extractSection
1771 //
1772 // Revision 1.205  2004/09/23 13:59:35  rurban
1773 // Before removing a page display a sample of 100 words.
1774 //
1775 // Revision 1.204  2004/09/17 13:19:15  rurban
1776 // fix LinkPhpwikiURL bug reported in http://phpwiki.sourceforge.net/phpwiki/KnownBugs
1777 // by SteveBennett.
1778 //
1779 // Revision 1.203  2004/09/16 08:00:52  rurban
1780 // just some comments
1781 //
1782 // Revision 1.202  2004/09/14 10:11:44  rurban
1783 // start 2nd Id with ...Plugin2
1784 //
1785 // Revision 1.201  2004/09/14 10:06:42  rurban
1786 // generate iterated plugin ids, set plugin span id also
1787 //
1788 // Revision 1.200  2004/08/05 17:34:26  rurban
1789 // move require to sortby branch
1790 //
1791 // Revision 1.199  2004/08/05 10:38:15  rurban
1792 // fix Bug #993692:  Making Snapshots or Backups doesn't work anymore
1793 // in CVS version.
1794 //
1795 // Revision 1.198  2004/07/02 10:30:36  rurban
1796 // always disable getimagesize for < php-4.3 with external png's
1797 //
1798 // Revision 1.197  2004/07/02 09:55:58  rurban
1799 // more stability fixes: new DISABLE_GETIMAGESIZE if your php crashes when loading LinkIcons: failing getimagesize in old phps; blockparser stabilized
1800 //
1801 // Revision 1.196  2004/07/01 08:51:22  rurban
1802 // dumphtml: added exclude, print pagename before processing
1803 //
1804 // Revision 1.195  2004/06/29 08:52:22  rurban
1805 // Use ...version() $need_content argument in WikiDB also:
1806 // To reduce the memory footprint for larger sets of pagelists,
1807 // we don't cache the content (only true or false) and
1808 // we purge the pagedata (_cached_html) also.
1809 // _cached_html is only cached for the current pagename.
1810 // => Vastly improved page existance check, ACL check, ...
1811 //
1812 // Now only PagedList info=content or size needs the whole content, esp. if sortable.
1813 //
1814 // Revision 1.194  2004/06/29 06:48:04  rurban
1815 // Improve LDAP auth and GROUP_LDAP membership:
1816 //   no error message on false password,
1817 //   added two new config vars: LDAP_OU_USERS and LDAP_OU_GROUP with GROUP_METHOD=LDAP
1818 //   fixed two group queries (this -> user)
1819 // stdlib: ConvertOldMarkup still flawed
1820 //
1821 // Revision 1.193  2004/06/28 13:27:03  rurban
1822 // CreateToc disabled for old markup and Apache2 only
1823 //
1824 // Revision 1.192  2004/06/28 12:47:43  rurban
1825 // skip if non-DEBUG and old markup with CreateToc
1826 //
1827 // Revision 1.191  2004/06/25 14:31:56  rurban
1828 // avoid debug_skip warning
1829 //
1830 // Revision 1.190  2004/06/25 14:29:20  rurban
1831 // WikiGroup refactoring:
1832 //   global group attached to user, code for not_current user.
1833 //   improved helpers for special groups (avoid double invocations)
1834 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
1835 // fixed a XHTML validation error on userprefs.tmpl
1836 //
1837 // Revision 1.189  2004/06/20 09:45:35  rurban
1838 // php5 isa fix (wrong strtolower)
1839 //
1840 // Revision 1.188  2004/06/16 10:38:58  rurban
1841 // Disallow refernces in calls if the declaration is a reference
1842 // ("allow_call_time_pass_reference clean").
1843 //   PhpWiki is now allow_call_time_pass_reference = Off clean,
1844 //   but several external libraries may not.
1845 //   In detail these libs look to be affected (not tested):
1846 //   * Pear_DB odbc
1847 //   * adodb oracle
1848 //
1849 // Revision 1.187  2004/06/14 11:31:37  rurban
1850 // renamed global $Theme to $WikiTheme (gforge nameclash)
1851 // inherit PageList default options from PageList
1852 //   default sortby=pagename
1853 // use options in PageList_Selectable (limit, sortby, ...)
1854 // added action revert, with button at action=diff
1855 // added option regex to WikiAdminSearchReplace
1856 //
1857 // Revision 1.186  2004/06/13 13:54:25  rurban
1858 // Catch fatals on the four dump calls (as file and zip, as html and mimified)
1859 // FoafViewer: Check against external requirements, instead of fatal.
1860 // Change output for xhtmldumps: using file:// urls to the local fs.
1861 // Catch SOAP fatal by checking for GOOGLE_LICENSE_KEY
1862 // Import GOOGLE_LICENSE_KEY and FORTUNE_DIR from config.ini.
1863 //
1864 // Revision 1.185  2004/06/11 09:07:30  rurban
1865 // support theme-specific LinkIconAttr: front or after or none
1866 //
1867 // Revision 1.184  2004/06/04 20:32:53  rurban
1868 // Several locale related improvements suggested by Pierrick Meignen
1869 // LDAP fix by John Cole
1870 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
1871 //
1872 // Revision 1.183  2004/06/01 10:22:56  rurban
1873 // added url_get_contents() used in XmlParser and elsewhere
1874 //
1875 // Revision 1.182  2004/05/25 12:40:48  rurban
1876 // trim the pagename
1877 //
1878 // Revision 1.181  2004/05/25 10:18:44  rurban
1879 // Check for UTF-8 URLs; Internet Explorer produces these if you
1880 // type non-ASCII chars in the URL bar or follow unescaped links.
1881 // Fixes sf.net bug #953949
1882 // src: languages/Language.php:checkTitleEncoding() from mediawiki
1883 //
1884 // Revision 1.180  2004/05/18 16:23:39  rurban
1885 // rename split_pagename to SplitPagename
1886 //
1887 // Revision 1.179  2004/05/18 16:18:37  rurban
1888 // AutoSplit at subpage seperators
1889 // RssFeed stability fix for empty feeds or broken connections
1890 //
1891 // Revision 1.178  2004/05/12 10:49:55  rurban
1892 // require_once fix for those libs which are loaded before FileFinder and
1893 //   its automatic include_path fix, and where require_once doesn't grok
1894 //   dirname(__FILE__) != './lib'
1895 // upgrade fix with PearDB
1896 // navbar.tmpl: remove spaces for IE &nbsp; button alignment
1897 //
1898 // Revision 1.177  2004/05/08 14:06:12  rurban
1899 // new support for inlined image attributes: [image.jpg size=50x30 align=right]
1900 // minor stability and portability fixes
1901 //
1902 // Revision 1.176  2004/05/08 11:25:15  rurban
1903 // php-4.0.4 fixes
1904 //
1905 // Revision 1.175  2004/05/06 17:30:38  rurban
1906 // CategoryGroup: oops, dos2unix eol
1907 // improved phpwiki_version:
1908 //   pre -= .0001 (1.3.10pre: 1030.099)
1909 //   -p1 += .001 (1.3.9-p1: 1030.091)
1910 // improved InstallTable for mysql and generic SQL versions and all newer tables so far.
1911 // abstracted more ADODB/PearDB methods for action=upgrade stuff:
1912 //   backend->backendType(), backend->database(),
1913 //   backend->listOfFields(),
1914 //   backend->listOfTables(),
1915 //
1916 // Revision 1.174  2004/05/06 12:02:05  rurban
1917 // fix sf.net bug#949002: [ Link | ] assertion
1918 //
1919 // Revision 1.173  2004/05/03 15:00:31  rurban
1920 // added more database upgrading: session.sess_ip, page.id autp_increment
1921 //
1922 // Revision 1.172  2004/04/26 20:44:34  rurban
1923 // locking table specific for better databases
1924 //
1925 // Revision 1.171  2004/04/19 23:13:03  zorloc
1926 // Connect the rest of PhpWiki to the IniConfig system.  Also the keyword regular expression is not a config setting
1927 //
1928 // Revision 1.170  2004/04/19 18:27:45  rurban
1929 // Prevent from some PHP5 warnings (ref args, no :: object init)
1930 //   php5 runs now through, just one wrong XmlElement object init missing
1931 // Removed unneccesary UpgradeUser lines
1932 // Changed WikiLink to omit version if current (RecentChanges)
1933 //
1934 // Revision 1.169  2004/04/15 21:29:48  rurban
1935 // allow [0] with new markup: link to page "0"
1936 //
1937 // Revision 1.168  2004/04/10 02:30:49  rurban
1938 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
1939 // Fixed "cannot setlocale..." (sf.net problem)
1940 //
1941 // Revision 1.167  2004/04/02 15:06:55  rurban
1942 // fixed a nasty ADODB_mysql session update bug
1943 // improved UserPreferences layout (tabled hints)
1944 // fixed UserPreferences auth handling
1945 // improved auth stability
1946 // improved old cookie handling: fixed deletion of old cookies with paths
1947 //
1948 // Revision 1.166  2004/04/01 15:57:10  rurban
1949 // simplified Sidebar theme: table, not absolute css positioning
1950 // added the new box methods.
1951 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
1952 //
1953 // Revision 1.165  2004/03/24 19:39:03  rurban
1954 // php5 workaround code (plus some interim debugging code in XmlElement)
1955 //   php5 doesn't work yet with the current XmlElement class constructors,
1956 //   WikiUserNew does work better than php4.
1957 // rewrote WikiUserNew user upgrading to ease php5 update
1958 // fixed pref handling in WikiUserNew
1959 // added Email Notification
1960 // added simple Email verification
1961 // removed emailVerify userpref subclass: just a email property
1962 // changed pref binary storage layout: numarray => hash of non default values
1963 // print optimize message only if really done.
1964 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
1965 //   prefs should be stored in db or homepage, besides the current session.
1966 //
1967 // Revision 1.164  2004/03/18 21:41:09  rurban
1968 // fixed sqlite support
1969 // WikiUserNew: PHP5 fixes: don't assign $this (untested)
1970 //
1971 // Revision 1.163  2004/03/17 18:41:49  rurban
1972 // just reformatting
1973 //
1974 // Revision 1.162  2004/03/16 15:43:08  rurban
1975 // make fileSet sortable to please PageList
1976 //
1977 // Revision 1.161  2004/03/12 15:48:07  rurban
1978 // fixed explodePageList: wrong sortby argument order in UnfoldSubpages
1979 // simplified lib/stdlib.php:explodePageList
1980 //
1981 // Revision 1.160  2004/02/28 21:14:08  rurban
1982 // generally more PHPDOC docs
1983 //   see http://xarch.tu-graz.ac.at/home/rurban/phpwiki/xref/
1984 // fxied WikiUserNew pref handling: empty theme not stored, save only
1985 //   changed prefs, sql prefs improved, fixed password update,
1986 //   removed REPLACE sql (dangerous)
1987 // moved gettext init after the locale was guessed
1988 // + some minor changes
1989 //
1990
1991 // (c-file-style: "gnu")
1992 // Local Variables:
1993 // mode: php
1994 // tab-width: 8
1995 // c-basic-offset: 4
1996 // c-hanging-comment-ender-p: nil
1997 // indent-tabs-mode: nil
1998 // End:   
1999 ?>