]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/stdlib.php
fixed sqlite support
[SourceForge/phpwiki.git] / lib / stdlib.php
1 <?php //rcs_id('$Id: stdlib.php,v 1.164 2004-03-18 21:41:09 rurban Exp $');
2
3 /*
4   Standard functions for Wiki functionality
5     WikiURL($pagename, $args, $get_abs_url)
6     IconForLink($protocol_or_url)
7     LinkURL($url, $linktext)
8     LinkImage($url, $alt)
9
10     SplitQueryArgs ($query_args)
11     LinkPhpwikiURL($url, $text)
12     ConvertOldMarkup($content)
13     
14     class Stack { push($item), pop(), cnt(), top() }
15
16     split_pagename ($page)
17     NoSuchRevision ($request, $page, $version)
18     TimezoneOffset ($time, $no_colon)
19     Iso8601DateTime ($time)
20     Rfc2822DateTime ($time)
21     CTime ($time)
22     __printf ($fmt)
23     __sprintf ($fmt)
24     __vsprintf ($fmt, $args)
25     better_srand($seed = '')
26     count_all($arg)
27     isSubPage($pagename)
28     subPageSlice($pagename, $pos)
29     explodePageList($input, $perm = false)
30
31   function: LinkInterWikiLink($link, $linktext)
32   moved to: lib/interwiki.php
33   function: linkExistingWikiWord($wikiword, $linktext, $version)
34   moved to: lib/Theme.php
35   function: LinkUnknownWikiWord($wikiword, $linktext)
36   moved to: lib/Theme.php
37   function: UpdateRecentChanges($dbi, $pagename, $isnewpage) 
38   gone see: lib/plugin/RecentChanges.php
39 */
40
41 define('MAX_PAGENAME_LENGTH', 100);
42
43             
44 /**
45  * Convert string to a valid XML identifier.
46  *
47  * XML 1.0 identifiers are of the form: [A-Za-z][A-Za-z0-9:_.-]*
48  *
49  * We would like to have, e.g. named anchors within wiki pages
50  * names like "Table of Contents" --- clearly not a valid XML
51  * fragment identifier.
52  *
53  * This function implements a one-to-one map from {any string}
54  * to {valid XML identifiers}.
55  *
56  * It does this by
57  * converting all bytes not in [A-Za-z0-9:_-],
58  * and any leading byte not in [A-Za-z] to 'xbb.',
59  * where 'bb' is the hexadecimal representation of the
60  * character.
61  *
62  * As a special case, the empty string is converted to 'empty.'
63  *
64  * @param string $str
65  * @return string
66  */
67 function MangleXmlIdentifier($str) {
68     if (!$str)
69         return 'empty.';
70     
71     return preg_replace('/[^-_:A-Za-z0-9]|(?<=^)[^A-Za-z]/e',
72                         "'x' . sprintf('%02x', ord('\\0')) . '.'",
73                         $str);
74 }
75
76 /**
77  * Generates a valid URL for a given Wiki pagename.
78  * @param mixed $pagename If a string this will be the name of the Wiki page to link to.
79  *                        If a WikiDB_Page object function will extract the name to link to.
80  *                        If a WikiDB_PageRevision object function will extract the name to link to.
81  * @param array $args 
82  * @param boolean $get_abs_url Default value is false.
83  * @return string The absolute URL to the page passed as $pagename.
84  */
85 function WikiURL($pagename, $args = '', $get_abs_url = false) {
86     $anchor = false;
87     
88     if (is_object($pagename)) {
89         if (isa($pagename, 'WikiDB_Page')) {
90             $pagename = $pagename->getName();
91         }
92         elseif (isa($pagename, 'WikiDB_PageRevision')) {
93             $page = $pagename->getPage();
94             $args['version'] = $pagename->getVersion();
95             $pagename = $page->getName();
96         }
97         elseif (isa($pagename, 'WikiPageName')) {
98             $anchor = $pagename->anchor;
99             $pagename = $pagename->name;
100         }
101     }
102     
103     if (is_array($args)) {
104         $enc_args = array();
105         foreach  ($args as $key => $val) {
106             if (!is_array($val)) // ugly hack for getURLtoSelf() which also takes POST vars
107               $enc_args[] = urlencode($key) . '=' . urlencode($val);
108         }
109         $args = join('&', $enc_args);
110     }
111
112     if (USE_PATH_INFO) {
113         $url = $get_abs_url ? SERVER_URL . VIRTUAL_PATH . "/" : "";
114         $url .= preg_replace('/%2f/i', '/', rawurlencode($pagename));
115         if ($args)
116             $url .= "?$args";
117     }
118     else {
119         $url = $get_abs_url ? SERVER_URL . SCRIPT_NAME : basename(SCRIPT_NAME);
120         $url .= "?pagename=" . rawurlencode($pagename);
121         if ($args)
122             $url .= "&$args";
123     }
124     if ($anchor)
125         $url .= "#" . MangleXmlIdentifier($anchor);
126     return $url;
127 }
128
129 /** Convert relative URL to absolute URL.
130  *
131  * This converts a relative URL to one of PhpWiki's support files
132  * to an absolute one.
133  *
134  * @param string $url
135  * @return string Absolute URL
136  */
137 function AbsoluteURL ($url) {
138     if (preg_match('/^https?:/', $url))
139         return $url;
140     if ($url[0] != '/') {
141         $base = USE_PATH_INFO ? VIRTUAL_PATH : dirname(SCRIPT_NAME);
142         while ($base != '/' and substr($url, 0, 3) == "../") {
143             $url = substr($url, 3);
144             $base = dirname($base);
145         }
146         if ($base != '/')
147             $base .= '/';
148         $url = $base . $url;
149     }
150     return SERVER_URL . $url;
151 }
152
153 /**
154  * Generates icon in front of links.
155  *
156  * @param string $protocol_or_url URL or protocol to determine which icon to use.
157  *
158  * @return HtmlElement HtmlElement object that contains data to create img link to
159  * icon for use with url or protocol passed to the function. False if no img to be
160  * displayed.
161  */
162 function IconForLink($protocol_or_url) {
163     global $Theme;
164     if ($filename_suffix = false) {
165         // display apache style icon for file type instead of protocol icon
166         // - archive: unix:gz,bz2,tgz,tar,z; mac:dmg,dmgz,bin,img,cpt,sit; pc:zip;
167         // - document: html, htm, text, txt, rtf, pdf, doc
168         // - non-inlined image: jpg,jpeg,png,gif,tiff,tif,swf,pict,psd,eps,ps
169         // - audio: mp3,mp2,aiff,aif,au
170         // - multimedia: mpeg,mpg,mov,qt
171     } else {
172         list ($proto) = explode(':', $protocol_or_url, 2);
173         $src = $Theme->getLinkIconURL($proto);
174         if ($src)
175             return HTML::img(array('src' => $src, 'alt' => "", 'class' => 'linkicon', 'border' => 0));
176         else
177             return false;
178     }
179 }
180
181 /**
182  * Glue icon in front of text.
183  *
184  * @param string $protocol_or_url Protocol or URL.  Used to determine the
185  * proper icon.
186  * @param string $text The text.
187  * @return XmlContent.
188  */
189 function PossiblyGlueIconToText($proto_or_url, $text) {
190     global $request;
191     if (! $request->getPref('noLinkIcons')) {
192         $icon = IconForLink($proto_or_url);
193         if ($icon) {
194             if (!is_object($text)) {
195                 preg_match('/^\s*(\S*)(.*?)\s*$/', $text, $m);
196                 list (, $first_word, $tail) = $m;
197             }
198             else {
199                 $first_word = $text;
200                 $tail = false;
201             }
202             
203             $text = HTML::span(array('style' => 'white-space: nowrap'),
204                                $icon, $first_word);
205             if ($tail)
206                 $text = HTML($text, $tail);
207         }
208     }
209     return $text;
210 }
211
212 /**
213  * Determines if the url passed to function is safe, by detecting if the characters
214  * '<', '>', or '"' are present.
215  *
216  * @param string $url URL to check for unsafe characters.
217  * @return boolean True if same, false else.
218  */
219 function IsSafeURL($url) {
220     return !ereg('[<>"]', $url);
221 }
222
223 /**
224  * Generates an HtmlElement object to store data for a link.
225  *
226  * @param string $url URL that the link will point to.
227  * @param string $linktext Text to be displayed as link.
228  * @return HtmlElement HtmlElement object that contains data to construct an html link.
229  */
230 function LinkURL($url, $linktext = '') {
231     // FIXME: Is this needed (or sufficient?)
232     if(! IsSafeURL($url)) {
233         $link = HTML::strong(HTML::u(array('class' => 'baduri'),
234                                      _("BAD URL -- remove all of <, >, \"")));
235     }
236     else {
237         if (!$linktext)
238             $linktext = preg_replace("/mailto:/A", "", $url);
239         
240         $link = HTML::a(array('href' => $url),
241                         PossiblyGlueIconToText($url, $linktext));
242         
243     }
244     $link->setAttr('class', $linktext ? 'namedurl' : 'rawurl');
245     return $link;
246 }
247
248
249 function LinkImage($url, $alt = false) {
250     // FIXME: Is this needed (or sufficient?)
251     if(! IsSafeURL($url)) {
252         $link = HTML::strong(HTML::u(array('class' => 'baduri'),
253                                      _("BAD URL -- remove all of <, >, \"")));
254     }
255     else {
256         if (empty($alt))
257             $alt = $url;
258         $link = HTML::img(array('src' => $url, 'alt' => $alt));
259     }
260     $link->setAttr('class', 'inlineimage');
261     return $link;
262 }
263
264
265
266 class Stack {
267     var $items = array();
268     var $size = 0;
269     
270     function push($item) {
271         $this->items[$this->size] = $item;
272         $this->size++;
273         return true;
274     }  
275     
276     function pop() {
277         if ($this->size == 0) {
278             return false; // stack is empty
279         }  
280         $this->size--;
281         return $this->items[$this->size];
282     }  
283     
284     function cnt() {
285         return $this->size;
286     }  
287     
288     function top() {
289         if($this->size)
290             return $this->items[$this->size - 1];
291         else
292             return '';
293     }
294     
295 }  
296 // end class definition
297
298 function SplitQueryArgs ($query_args = '') 
299 {
300     $split_args = split('&', $query_args);
301     $args = array();
302     while (list($key, $val) = each($split_args))
303         if (preg_match('/^ ([^=]+) =? (.*) /x', $val, $m))
304             $args[$m[1]] = $m[2];
305     return $args;
306 }
307
308 function LinkPhpwikiURL($url, $text = '', $basepage) {
309     $args = array();
310     
311     if (!preg_match('/^ phpwiki: ([^?]*) [?]? (.*) $/x', $url, $m)) {
312         return HTML::strong(array('class' => 'rawurl'),
313                             HTML::u(array('class' => 'baduri'),
314                                     _("BAD phpwiki: URL")));
315     }
316
317     if ($m[1])
318         $pagename = urldecode($m[1]);
319     $qargs = $m[2];
320     
321     if (empty($pagename) &&
322         preg_match('/^(diff|edit|links|info)=([^&]+)$/', $qargs, $m)) {
323         // Convert old style links (to not break diff links in
324         // RecentChanges).
325         $pagename = urldecode($m[2]);
326         $args = array("action" => $m[1]);
327     }
328     else {
329         $args = SplitQueryArgs($qargs);
330     }
331
332     if (empty($pagename))
333         $pagename = $GLOBALS['request']->getArg('pagename');
334
335     if (isset($args['action']) && $args['action'] == 'browse')
336         unset($args['action']);
337     
338     /*FIXME:
339       if (empty($args['action']))
340       $class = 'wikilink';
341       else if (is_safe_action($args['action']))
342       $class = 'wikiaction';
343     */
344     if (empty($args['action']) || is_safe_action($args['action']))
345         $class = 'wikiaction';
346     else {
347         // Don't allow administrative links on unlocked pages.
348         $dbi = $GLOBALS['request']->getDbh();
349         $page = $dbi->getPage($basepage);
350         if (!$page->get('locked'))
351             return HTML::span(array('class' => 'wikiunsafe'),
352                               HTML::u(_("Lock page to enable link")));
353         $class = 'wikiadmin';
354     }
355     
356     if (!$text)
357         $text = HTML::span(array('class' => 'rawurl'), $url);
358
359     $wikipage = new WikiPageName($pagename);
360     if (!$wikipage->isValid()) {
361         global $Theme;
362         return $Theme->linkBadWikiWord($wikipage, $url);
363     }
364     
365     return HTML::a(array('href'  => WikiURL($pagename, $args),
366                          'class' => $class),
367                    $text);
368 }
369
370 /**
371  * A class to assist in parsing wiki pagenames.
372  *
373  * Now with subpages and anchors, parsing and passing around
374  * pagenames is more complicated.  This should help.
375  */
376 class WikiPagename
377 {
378     /** Short name for page.
379      *
380      * This is the value of $name passed to the constructor.
381      * (For use, e.g. as a default label for links to the page.)
382      */
383     var $shortName;
384
385     /** The full page name.
386      *
387      * This is the full name of the page (without anchor).
388      */
389     var $name;
390     
391     /** The anchor.
392      *
393      * This is the referenced anchor within the page, or the empty string.
394      */
395     var $anchor;
396     
397     /** Constructor
398      *
399      * @param mixed $name Page name.
400      * WikiDB_Page, WikiDB_PageRevision, or string.
401      * This can be a relative subpage name (like '/SubPage'),
402      * or can be the empty string to refer to the $basename.
403      *
404      * @param string $anchor For links to anchors in page.
405      *
406      * @param mixed $basename Page name from which to interpret
407      * relative or other non-fully-specified page names.
408      */
409     function WikiPageName($name, $basename=false, $anchor=false) {
410         if (is_string($name)) {
411             $this->shortName = $name;
412         
413             if (empty($name) or $name[0] == SUBPAGE_SEPARATOR) {
414                 if ($basename)
415                     $name = $this->_pagename($basename) . $name;
416                 else
417                     $name = $this->_normalize_bad_pagename($name);
418             }
419         }
420         else {
421             $name = $this->_pagename($name);
422             $this->shortName = $name;
423         }
424
425         $this->name = $this->_check($name);
426         $this->anchor = (string)$anchor;
427     }
428
429     function getParent() {
430         $name = $this->name;
431         if (!($tail = strrchr($name, SUBPAGE_SEPARATOR)))
432             return false;
433         return substr($name, 0, -strlen($tail));
434     }
435
436     function isValid($strict = false) {
437         if ($strict)
438             return !isset($this->_errors);
439         return !empty($this->name);
440     }
441
442     function getWarnings() {
443         $warnings = array();
444         if (isset($this->_warnings))
445             $warnings = array_merge($warnings, $this->_warnings);
446         if (isset($this->_errors))
447             $warnings = array_merge($warnings, $this->_errors);
448         if (!$warnings)
449             return false;
450         
451         return sprintf(_("'%s': Bad page name: %s"),
452                        $this->shortName, join(', ', $warnings));
453     }
454     
455     function _pagename($page) {
456         if (isa($page, 'WikiDB_Page'))
457             return $page->getName();
458         elseif (isa($page, 'WikiDB_PageRevision'))
459             return $page->getPageName();
460         elseif (isa($page, 'WikiPageName'))
461             return $page->name;
462         if (!is_string($page)) {
463             trigger_error(sprintf("Non-string pagename '%s' (%s)(%s)",
464                                   $page, gettype($page), get_class($page)),
465                           E_USER_NOTICE);
466         }
467         //assert(is_string($page));
468         return $page;
469     }
470
471     function _normalize_bad_pagename($name) {
472         trigger_error("Bad pagename: " . $name, E_USER_WARNING);
473
474         // Punt...  You really shouldn't get here.
475         if (empty($name)) {
476             global $request;
477             return $request->getArg('pagename');
478         }
479         assert($name[0] == SUBPAGE_SEPARATOR);
480         return substr($name, 1);
481     }
482
483
484     function _check($pagename) {
485         // Compress internal white-space to single space character.
486         $pagename = preg_replace('/[\s\xa0]+/', ' ', $orig = $pagename);
487         if ($pagename != $orig)
488             $this->_warnings[] = _("White space converted to single space");
489     
490         // Delete any control characters.
491         $pagename = preg_replace('/[\x00-\x1f\x7f\x80-\x9f]/', '', $orig = $pagename);
492         if ($pagename != $orig)
493             $this->_errors[] = _("Control characters not allowed");
494
495         // Strip leading and trailing white-space.
496         $pagename = trim($pagename);
497
498         $orig = $pagename;
499         while ($pagename and $pagename[0] == SUBPAGE_SEPARATOR)
500             $pagename = substr($pagename, 1);
501         if ($pagename != $orig)
502             $this->_errors[] = sprintf(_("Leading %s not allowed"), SUBPAGE_SEPARATOR);
503
504         if (preg_match('/[:;]/', $pagename))
505             $this->_warnings[] = _("';' and ':' in pagenames are deprecated");
506         
507         if (strlen($pagename) > MAX_PAGENAME_LENGTH) {
508             $pagename = substr($pagename, 0, MAX_PAGENAME_LENGTH);
509             $this->_errors[] = _("too long");
510         }
511         
512
513         if ($pagename == '.' or $pagename == '..') {
514             $this->_errors[] = sprintf(_("illegal pagename"), $pagename);
515             $pagename = '';
516         }
517         
518         return $pagename;
519     }
520 }
521
522 /**
523  * Convert old page markup to new-style markup.
524  *
525  * @param string $text Old-style wiki markup.
526  *
527  * @param string $markup_type
528  * One of: <dl>
529  * <dt><code>"block"</code>  <dd>Convert all markup.
530  * <dt><code>"inline"</code> <dd>Convert only inline markup.
531  * <dt><code>"links"</code>  <dd>Convert only link markup.
532  * </dl>
533  *
534  * @return string New-style wiki markup.
535  *
536  * @bugs Footnotes don't work quite as before (esp if there are
537  *   multiple references to the same footnote.  But close enough,
538  *   probably for now....
539  */
540 function ConvertOldMarkup ($text, $markup_type = "block") {
541
542     static $subs;
543     static $block_re;
544     
545     if (empty($subs)) {
546         /*****************************************************************
547          * Conversions for inline markup:
548          */
549
550         // escape tilde's
551         $orig[] = '/~/';
552         $repl[] = '~~';
553
554         // escape escaped brackets
555         $orig[] = '/\[\[/';
556         $repl[] = '~[';
557
558         // change ! escapes to ~'s.
559         global $AllowedProtocols, $WikiNameRegexp, $request;
560         //include_once('lib/interwiki.php');
561         $map = PageType_interwikimap::GetMap($request);
562         $bang_esc[] = "(?:$AllowedProtocols):[^\s<>\[\]\"'()]*[^\s<>\[\]\"'(),.?]";
563         $bang_esc[] = $map->getRegexp() . ":[^\\s.,;?()]+"; // FIXME: is this really needed?
564         $bang_esc[] = $WikiNameRegexp;
565         $orig[] = '/!((?:' . join(')|(', $bang_esc) . '))/';
566         $repl[] = '~\\1';
567
568         $subs["links"] = array($orig, $repl);
569
570         // Escape '<'s
571         //$orig[] = '/<(?!\?plugin)|(?<!^)</m';
572         //$repl[] = '~<';
573         
574         // Convert footnote references.
575         $orig[] = '/(?<=.)(?<!~)\[\s*(\d+)\s*\]/m';
576         $repl[] = '#[|ftnt_ref_\\1]<sup>~[[\\1|#ftnt_\\1]~]</sup>';
577
578         // Convert old style emphases to HTML style emphasis.
579         $orig[] = '/__(.*?)__/';
580         $repl[] = '<strong>\\1</strong>';
581         $orig[] = "/''(.*?)''/";
582         $repl[] = '<em>\\1</em>';
583
584         // Escape nestled markup.
585         $orig[] = '/^(?<=^|\s)[=_](?=\S)|(?<=\S)[=_*](?=\s|$)/m';
586         $repl[] = '~\\0';
587         
588         // in old markup headings only allowed at beginning of line
589         $orig[] = '/!/';
590         $repl[] = '~!';
591
592         $subs["inline"] = array($orig, $repl);
593
594         /*****************************************************************
595          * Patterns which match block markup constructs which take
596          * special handling...
597          */
598
599         // Indented blocks
600         $blockpats[] = '[ \t]+\S(?:.*\s*\n[ \t]+\S)*';
601
602         // Tables
603         $blockpats[] = '\|(?:.*\n\|)*';
604
605         // List items
606         $blockpats[] = '[#*;]*(?:[*#]|;.*?:)';
607
608         // Footnote definitions
609         $blockpats[] = '\[\s*(\d+)\s*\]';
610
611         // Plugins
612         $blockpats[] = '<\?plugin(?:-form)?\b.*\?>\s*$';
613
614         // Section Title
615         $blockpats[] = '!{1,3}[^!]';
616
617         $block_re = ( '/\A((?:.|\n)*?)(^(?:'
618                       . join("|", $blockpats)
619                       . ').*$)\n?/m' );
620         
621     }
622     
623     if ($markup_type != "block") {
624         list ($orig, $repl) = $subs[$markup_type];
625         return preg_replace($orig, $repl, $text);
626     }
627     else {
628         list ($orig, $repl) = $subs['inline'];
629         $out = '';
630         while (preg_match($block_re, $text, $m)) {
631             $text = substr($text, strlen($m[0]));
632             list (,$leading_text, $block) = $m;
633             $suffix = "\n";
634             
635             if (strchr(" \t", $block[0])) {
636                 // Indented block
637                 $prefix = "<pre>\n";
638                 $suffix = "\n</pre>\n";
639             }
640             elseif ($block[0] == '|') {
641                 // Old-style table
642                 $prefix = "<?plugin OldStyleTable\n";
643                 $suffix = "\n?>\n";
644             }
645             elseif (strchr("#*;", $block[0])) {
646                 // Old-style list item
647                 preg_match('/^([#*;]*)([*#]|;.*?:) */', $block, $m);
648                 list (,$ind,$bullet) = $m;
649                 $block = substr($block, strlen($m[0]));
650                 
651                 $indent = str_repeat('     ', strlen($ind));
652                 if ($bullet[0] == ';') {
653                     //$term = ltrim(substr($bullet, 1));
654                     //return $indent . $term . "\n" . $indent . '     ';
655                     $prefix = $ind . $bullet;
656                 }
657                 else
658                     $prefix = $indent . $bullet . ' ';
659             }
660             elseif ($block[0] == '[') {
661                 // Footnote definition
662                 preg_match('/^\[\s*(\d+)\s*\]/', $block, $m);
663                 $footnum = $m[1];
664                 $block = substr($block, strlen($m[0]));
665                 $prefix = "#[|ftnt_${footnum}]~[[${footnum}|#ftnt_ref_${footnum}]~] ";
666             }
667             elseif ($block[0] == '<') {
668                 // Plugin.
669                 // HACK: no inline markup...
670                 $prefix = $block;
671                 $block = '';
672             }
673             elseif ($block[0] == '!') {
674                 // Section heading
675                 preg_match('/^!{1,3}/', $block, $m);
676                 $prefix = $m[0];
677                 $block = substr($block, strlen($m[0]));
678             }
679             else {
680                 // AAck!
681                 assert(0);
682             }
683
684             $out .= ( preg_replace($orig, $repl, $leading_text)
685                       . $prefix
686                       . preg_replace($orig, $repl, $block)
687                       . $suffix );
688         }
689         return $out . preg_replace($orig, $repl, $text);
690     }
691 }
692
693
694 /**
695  * Expand tabs in string.
696  *
697  * Converts all tabs to (the appropriate number of) spaces.
698  *
699  * @param string $str
700  * @param integer $tab_width
701  * @return string
702  */
703 function expand_tabs($str, $tab_width = 8) {
704     $split = split("\t", $str);
705     $tail = array_pop($split);
706     $expanded = "\n";
707     foreach ($split as $hunk) {
708         $expanded .= $hunk;
709         $pos = strlen(strrchr($expanded, "\n")) - 1;
710         $expanded .= str_repeat(" ", ($tab_width - $pos % $tab_width));
711     }
712     return substr($expanded, 1) . $tail;
713 }
714
715 /**
716  * Split WikiWords in page names.
717  *
718  * It has been deemed useful to split WikiWords (into "Wiki Words") in
719  * places like page titles. This is rumored to help search engines
720  * quite a bit.
721  *
722  * @param $page string The page name.
723  *
724  * @return string The split name.
725  */
726 function split_pagename ($page) {
727     
728     if (preg_match("/\s/", $page))
729         return $page;           // Already split --- don't split any more.
730     
731     // FIXME: this algorithm is Anglo-centric.
732     static $RE;
733     if (!isset($RE)) {
734         // This mess splits between a lower-case letter followed by
735         // either an upper-case or a numeral; except that it wont
736         // split the prefixes 'Mc', 'De', or 'Di' off of their tails.
737         $RE[] = '/([[:lower:]])((?<!Mc|De|Di)[[:upper:]]|\d)/';
738         // This the single-letter words 'I' and 'A' from any following
739         // capitalized words.
740         $sep = preg_quote(SUBPAGE_SEPARATOR, '/');
741         $RE[] = "/(?<= |${sep}|^)([AI])([[:upper:]][[:lower:]])/";
742         // Split numerals from following letters.
743         $RE[] = '/(\d)([[:alpha:]])/';
744         
745         foreach ($RE as $key => $val)
746             $RE[$key] = pcre_fix_posix_classes($val);
747     }
748
749     foreach ($RE as $regexp) {
750         $page = preg_replace($regexp, '\\1 \\2', $page);
751     }
752     return $page;
753 }
754
755 function NoSuchRevision (&$request, $page, $version) {
756     $html = HTML(HTML::h2(_("Revision Not Found")),
757                  HTML::p(fmt("I'm sorry.  Version %d of %s is not in the database.",
758                              $version, WikiLink($page, 'auto'))));
759     include_once('lib/Template.php');
760     GeneratePage($html, _("Bad Version"), $page->getCurrentRevision());
761     $request->finish();
762 }
763
764
765 /**
766  * Get time offset for local time zone.
767  *
768  * @param $time time_t Get offset for this time. Default: now.
769  * @param $no_colon boolean Don't put colon between hours and minutes.
770  * @return string Offset as a string in the format +HH:MM.
771  */
772 function TimezoneOffset ($time = false, $no_colon = false) {
773     if ($time === false)
774         $time = time();
775     $secs = date('Z', $time);
776
777     if ($secs < 0) {
778         $sign = '-';
779         $secs = -$secs;
780     }
781     else {
782         $sign = '+';
783     }
784     $colon = $no_colon ? '' : ':';
785     $mins = intval(($secs + 30) / 60);
786     return sprintf("%s%02d%s%02d",
787                    $sign, $mins / 60, $colon, $mins % 60);
788 }
789
790
791 /**
792  * Format time in ISO-8601 format.
793  *
794  * @param $time time_t Time.  Default: now.
795  * @return string Date and time in ISO-8601 format.
796  */
797 function Iso8601DateTime ($time = false) {
798     if ($time === false)
799         $time = time();
800     $tzoff = TimezoneOffset($time);
801     $date  = date('Y-m-d', $time);
802     $time  = date('H:i:s', $time);
803     return $date . 'T' . $time . $tzoff;
804 }
805
806 /**
807  * Format time in RFC-2822 format.
808  *
809  * @param $time time_t Time.  Default: now.
810  * @return string Date and time in RFC-2822 format.
811  */
812 function Rfc2822DateTime ($time = false) {
813     if ($time === false)
814         $time = time();
815     return date('D, j M Y H:i:s ', $time) . TimezoneOffset($time, 'no colon');
816 }
817
818 /**
819  * Format time in RFC-1123 format.
820  *
821  * @param $time time_t Time.  Default: now.
822  * @return string Date and time in RFC-1123 format.
823  */
824 function Rfc1123DateTime ($time = false) {
825     if ($time === false)
826         $time = time();
827     return gmdate('D, d M Y H:i:s \G\M\T', $time);
828 }
829
830 /** Parse date in RFC-1123 format.
831  *
832  * According to RFC 1123 we must accept dates in the following
833  * formats:
834  *
835  *   Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
836  *   Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
837  *   Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() format
838  *
839  * (Though we're only allowed to generate dates in the first format.)
840  */
841 function ParseRfc1123DateTime ($timestr) {
842     $timestr = trim($timestr);
843     if (preg_match('/^ \w{3},\s* (\d{1,2}) \s* (\w{3}) \s* (\d{4}) \s*'
844                    .'(\d\d):(\d\d):(\d\d) \s* GMT $/ix',
845                    $timestr, $m)) {
846         list(, $mday, $mon, $year, $hh, $mm, $ss) = $m;
847     }
848     elseif (preg_match('/^ \w+,\s* (\d{1,2})-(\w{3})-(\d{2}|\d{4}) \s*'
849                        .'(\d\d):(\d\d):(\d\d) \s* GMT $/ix',
850                        $timestr, $m)) {
851         list(, $mday, $mon, $year, $hh, $mm, $ss) = $m;
852         if ($year < 70) $year += 2000;
853         elseif ($year < 100) $year += 1900;
854     }
855     elseif (preg_match('/^\w+\s* (\w{3}) \s* (\d{1,2}) \s*'
856                        .'(\d\d):(\d\d):(\d\d) \s* (\d{4})$/ix',
857                        $timestr, $m)) {
858         list(, $mon, $mday, $hh, $mm, $ss, $year) = $m;
859     }
860     else {
861         // Parse failed.
862         return false;
863     }
864
865     $time = strtotime("$mday $mon $year ${hh}:${mm}:${ss} GMT");
866     if ($time == -1)
867         return false;           // failed
868     return $time;
869 }
870
871 /**
872  * Format time to standard 'ctime' format.
873  *
874  * @param $time time_t Time.  Default: now.
875  * @return string Date and time.
876  */
877 function CTime ($time = false)
878 {
879     if ($time === false)
880         $time = time();
881     return date("D M j H:i:s Y", $time);
882 }
883
884
885 /**
886  * Format number as kilobytes or bytes.
887  * Short format is used for PageList
888  * Long format is used in PageInfo
889  *
890  * @param $bytes       int.  Default: 0.
891  * @param $longformat  bool. Default: false.
892  * @return class FormattedText (XmlElement.php).
893  */
894 function ByteFormatter ($bytes = 0, $longformat = false) {
895     if ($bytes < 0)
896         return fmt("-???");
897     if ($bytes < 1024) {
898         if (! $longformat)
899             $size = fmt("%s b", $bytes);
900         else
901             $size = fmt("%s bytes", $bytes);
902     }
903     else {
904         $kb = round($bytes / 1024, 1);
905         if (! $longformat)
906             $size = fmt("%s k", $kb);
907         else
908             $size = fmt("%s Kb (%s bytes)", $kb, $bytes);
909     }
910     return $size;
911 }
912
913 /**
914  * Internationalized printf.
915  *
916  * This is essentially the same as PHP's built-in printf
917  * with the following exceptions:
918  * <ol>
919  * <li> It passes the format string through gettext().
920  * <li> It supports the argument reordering extensions.
921  * </ol>
922  *
923  * Example:
924  *
925  * In php code, use:
926  * <pre>
927  *    __printf("Differences between versions %s and %s of %s",
928  *             $new_link, $old_link, $page_link);
929  * </pre>
930  *
931  * Then in locale/po/de.po, one can reorder the printf arguments:
932  *
933  * <pre>
934  *    msgid "Differences between %s and %s of %s."
935  *    msgstr "Der Unterschiedsergebnis von %3$s, zwischen %1$s und %2$s."
936  * </pre>
937  *
938  * (Note that while PHP tries to expand $vars within double-quotes,
939  * the values in msgstr undergo no such expansion, so the '$'s
940  * okay...)
941  *
942  * One shouldn't use reordered arguments in the default format string.
943  * Backslashes in the default string would be necessary to escape the
944  * '$'s, and they'll cause all kinds of trouble....
945  */ 
946 function __printf ($fmt) {
947     $args = func_get_args();
948     array_shift($args);
949     echo __vsprintf($fmt, $args);
950 }
951
952 /**
953  * Internationalized sprintf.
954  *
955  * This is essentially the same as PHP's built-in printf with the
956  * following exceptions:
957  *
958  * <ol>
959  * <li> It passes the format string through gettext().
960  * <li> It supports the argument reordering extensions.
961  * </ol>
962  *
963  * @see __printf
964  */ 
965 function __sprintf ($fmt) {
966     $args = func_get_args();
967     array_shift($args);
968     return __vsprintf($fmt, $args);
969 }
970
971 /**
972  * Internationalized vsprintf.
973  *
974  * This is essentially the same as PHP's built-in printf with the
975  * following exceptions:
976  *
977  * <ol>
978  * <li> It passes the format string through gettext().
979  * <li> It supports the argument reordering extensions.
980  * </ol>
981  *
982  * @see __printf
983  */ 
984 function __vsprintf ($fmt, $args) {
985     $fmt = gettext($fmt);
986     // PHP's sprintf doesn't support variable with specifiers,
987     // like sprintf("%*s", 10, "x"); --- so we won't either.
988     
989     if (preg_match_all('/(?<!%)%(\d+)\$/x', $fmt, $m)) {
990         // Format string has '%2$s' style argument reordering.
991         // PHP doesn't support this.
992         if (preg_match('/(?<!%)%[- ]?\d*[^- \d$]/x', $fmt))
993             // literal variable name substitution only to keep locale
994             // strings uncluttered
995             trigger_error(sprintf(_("Can't mix '%s' with '%s' type format strings"),
996                                   '%1\$s','%s'), E_USER_WARNING); //php+locale error
997         
998         $fmt = preg_replace('/(?<!%)%\d+\$/x', '%', $fmt);
999         $newargs = array();
1000         
1001         // Reorder arguments appropriately.
1002         foreach($m[1] as $argnum) {
1003             if ($argnum < 1 || $argnum > count($args))
1004                 trigger_error(sprintf(_("%s: argument index out of range"), 
1005                                       $argnum), E_USER_WARNING);
1006             $newargs[] = $args[$argnum - 1];
1007         }
1008         $args = $newargs;
1009     }
1010     
1011     // Not all PHP's have vsprintf, so...
1012     array_unshift($args, $fmt);
1013     return call_user_func_array('sprintf', $args);
1014 }
1015
1016 function file_mtime ($filename) {
1017     if ($stat = stat($filename))
1018         return $stat[9];
1019 }
1020
1021 function sort_file_mtime ($a, $b) {
1022     $ma = file_mtime($a);
1023     $mb = file_mtime($b);
1024     if (!$ma or !$mb or $ma == $mb) return 0;
1025     return ($ma > $mb) ? -1 : 1;
1026 }
1027
1028 class fileSet {
1029     /**
1030      * Build an array in $this->_fileList of files from $dirname.
1031      * Subdirectories are not traversed.
1032      *
1033      * (This was a function LoadDir in lib/loadsave.php)
1034      * See also http://www.php.net/manual/en/function.readdir.php
1035      */
1036     function getFiles($exclude=false,$sortby=false,$limit=false) {
1037         $list = $this->_fileList;
1038         if ($sortby) {
1039             switch (Pagelist::sortby($sortby,'db')) {
1040             case 'pagename ASC': break;
1041             case 'pagename DESC': 
1042                 $list = array_reverse($list); 
1043                 break;
1044             case 'mtime ASC': 
1045                 usort($list,'sort_file_mtime'); 
1046                 break;
1047             case 'mtime DESC': 
1048                 usort($list,'sort_file_mtime');
1049                 $list = array_reverse($list); 
1050                 break;
1051             }
1052         }
1053         if ($limit)
1054             return array_splice($list,0,$limit);
1055         return $list;
1056     }
1057
1058     function _filenameSelector($filename) {
1059         if (! $this->_pattern)
1060             return true;
1061         else {
1062             return glob_match ($this->_pattern, $filename, $this->_case);
1063         }
1064     }
1065
1066     function fileSet($directory, $filepattern = false) {
1067         $this->_fileList = array();
1068         $this->_pattern = $filepattern;
1069         $this->_case = !isWindows();
1070         $this->_pathsep = '/';
1071
1072         if (empty($directory)) {
1073             trigger_error(sprintf(_("%s is empty."), 'directoryname'),
1074                           E_USER_NOTICE);
1075             return; // early return
1076         }
1077
1078         @ $dir_handle = opendir($dir=$directory);
1079         if (empty($dir_handle)) {
1080             trigger_error(sprintf(_("Unable to open directory '%s' for reading"),
1081                                   $dir), E_USER_NOTICE);
1082             return; // early return
1083         }
1084
1085         while ($filename = readdir($dir_handle)) {
1086             if ($filename[0] == '.' || filetype($dir . $this->_pathsep . $filename) != 'file')
1087                 continue;
1088             if ($this->_filenameSelector($filename)) {
1089                 array_push($this->_fileList, "$filename");
1090                 //trigger_error(sprintf(_("found file %s"), $filename),
1091                 //                      E_USER_NOTICE); //debugging
1092             }
1093         }
1094         closedir($dir_handle);
1095     }
1096 };
1097
1098 // File globbing
1099
1100 // expands a list containing regex's to its matching entries
1101 class ListRegexExpand {
1102     var $match, $list, $index, $case_sensitive;
1103     function ListRegexExpand (&$list, $match, $case_sensitive = true) {
1104         $this->match = str_replace('/','\/',$match);
1105         $this->list = &$list;
1106         $this->case_sensitive = $case_sensitive;        
1107     }
1108     function listMatchCallback ($item, $key) {
1109         if (preg_match('/' . $this->match . ($this->case_sensitive ? '/' : '/i'), $item)) {
1110             unset($this->list[$this->index]);
1111             $this->list[] = $item;
1112         }
1113     }
1114     function expandRegex ($index, &$pages) {
1115         $this->index = $index;
1116         array_walk($pages, array($this, 'listMatchCallback'));
1117         return $this->list;
1118     }
1119 }
1120
1121 // convert fileglob to regex style
1122 function glob_to_pcre ($glob) {
1123     $re = preg_replace('/\./', '\\.', $glob);
1124     $re = preg_replace(array('/\*/','/\?/'), array('.*','.'), $glob);
1125     if (!preg_match('/^[\?\*]/',$glob))
1126         $re = '^' . $re;
1127     if (!preg_match('/[\?\*]$/',$glob))
1128         $re = $re . '$';
1129     return $re;
1130 }
1131
1132 function glob_match ($glob, $against, $case_sensitive = true) {
1133     return preg_match('/' . glob_to_pcre($glob) . ($case_sensitive ? '/' : '/i'), $against);
1134 }
1135
1136 function explodeList($input, $allnames, $glob_style = true, $case_sensitive = true) {
1137     $list = explode(',',$input);
1138     // expand wildcards from list of $allnames
1139     if (preg_match('/[\?\*]/',$input)) {
1140         // Optimizing loop invariants:
1141         // http://phplens.com/lens/php-book/optimizing-debugging-php.php
1142         for ($i = 0, $max = sizeof($list); $i < $max; $i++) {
1143             $f = $list[$i];
1144             if (preg_match('/[\?\*]/',$f)) {
1145                 reset($allnames);
1146                 $expand = new ListRegexExpand($list, $glob_style ? glob_to_pcre($f) : $f, $case_sensitive);
1147                 $expand->expandRegex($i, $allnames);
1148             }
1149         }
1150     }
1151     return $list;
1152 }
1153
1154 // echo implode(":",explodeList("Test*",array("xx","Test1","Test2")));
1155 function explodePageList($input, $perm=false, $sortby='pagename', $limit=false) {
1156     include_once("lib/PageList.php");
1157     return PageList::explodePageList($input,$perm,$sortby,$limit);
1158 }
1159
1160 // Class introspections
1161
1162 /** Determine whether object is of a specified type.
1163  *
1164  * @param $object object An object.
1165  * @param $class string Class name.
1166  * @return bool True iff $object is a $class
1167  * or a sub-type of $class. 
1168  */
1169 function isa ($object, $class) {
1170     $lclass = strtolower($class);
1171
1172     return is_object($object)
1173         && ( get_class($object) == strtolower($lclass)
1174              || is_subclass_of($object, $lclass) );
1175 }
1176
1177 /** Determine whether (possible) object has method.
1178  *
1179  * @param $object mixed Object
1180  * @param $method string Method name
1181  * @return bool True iff $object is an object with has method $method.
1182  */
1183 function can ($object, $method) {
1184     return is_object($object) && method_exists($object, strtolower($method));
1185 }
1186
1187 /** Determine whether a function is okay to use.
1188  *
1189  * Some providers (e.g. Lycos) disable some of PHP functions for
1190  * "security reasons."  This makes those functions, of course,
1191  * unusable, despite the fact the function_exists() says they
1192  * exist.
1193  *
1194  * This function test to see if a function exists and is not
1195  * disallowed by PHP's disable_functions config setting.
1196  *
1197  * @param string $function_name  Function name
1198  * @return bool  True iff function can be used.
1199  */
1200 function function_usable($function_name) {
1201     static $disabled;
1202     if (!is_array($disabled)) {
1203         $disabled = array();
1204         // Use get_cfg_var since ini_get() is one of the disabled functions
1205         // (on Lycos, at least.)
1206         $split = preg_split('/\s*,\s*/', trim(get_cfg_var('disable_functions')));
1207         foreach ($split as $f)
1208             $disabled[strtolower($f)] = true;
1209     }
1210
1211     return ( function_exists($function_name)
1212              and ! isset($disabled[strtolower($function_name)])
1213              );
1214 }
1215     
1216     
1217 /** Hash a value.
1218  *
1219  * This is used for generating ETags.
1220  */
1221 function hash ($x) {
1222     if (is_scalar($x)) {
1223         return $x;
1224     }
1225     elseif (is_array($x)) {            
1226         ksort($x);
1227         return md5(serialize($x));
1228     }
1229     elseif (is_object($x)) {
1230         return $x->hash();
1231     }
1232     trigger_error("Can't hash $x", E_USER_ERROR);
1233 }
1234
1235     
1236 /**
1237  * Seed the random number generator.
1238  *
1239  * better_srand() ensures the randomizer is seeded only once.
1240  * 
1241  * How random do you want it? See:
1242  * http://www.php.net/manual/en/function.srand.php
1243  * http://www.php.net/manual/en/function.mt-srand.php
1244  */
1245 function better_srand($seed = '') {
1246     static $wascalled = FALSE;
1247     if (!$wascalled) {
1248         $seed = $seed === '' ? (double) microtime() * 1000000 : $seed;
1249         srand($seed);
1250         $wascalled = TRUE;
1251         //trigger_error("new random seed", E_USER_NOTICE); //debugging
1252     }
1253 }
1254
1255 /**
1256  * Recursively count all non-empty elements 
1257  * in array of any dimension or mixed - i.e. 
1258  * array('1' => 2, '2' => array('1' => 3, '2' => 4))
1259  * See http://www.php.net/manual/en/function.count.php
1260  */
1261 function count_all($arg) {
1262     // skip if argument is empty
1263     if ($arg) {
1264         //print_r($arg); //debugging
1265         $count = 0;
1266         // not an array, return 1 (base case) 
1267         if(!is_array($arg))
1268             return 1;
1269         // else call recursively for all elements $arg
1270         foreach($arg as $key => $val)
1271             $count += count_all($val);
1272         return $count;
1273     }
1274 }
1275
1276 function isSubPage($pagename) {
1277     return (strstr($pagename, SUBPAGE_SEPARATOR));
1278 }
1279
1280 function subPageSlice($pagename, $pos) {
1281     $pages = explode(SUBPAGE_SEPARATOR,$pagename);
1282     $pages = array_slice($pages,$pos,1);
1283     return $pages[0];
1284 }
1285
1286 /**
1287  * Alert
1288  *
1289  * Class for "popping up" and alert box.  (Except that right now, it doesn't
1290  * pop up...)
1291  *
1292  * FIXME:
1293  * This is a hackish and needs to be refactored.  However it would be nice to
1294  * unify all the different methods we use for showing Alerts and Dialogs.
1295  * (E.g. "Page deleted", login form, ...)
1296  */
1297 class Alert {
1298     /** Constructor
1299      *
1300      * @param object $request
1301      * @param mixed $head  Header ("title") for alert box.
1302      * @param mixed $body  The text in the alert box.
1303      * @param hash $buttons  An array mapping button labels to URLs.
1304      *    The default is a single "Okay" button pointing to $request->getURLtoSelf().
1305      */
1306     function Alert($head, $body, $buttons=false) {
1307         if ($buttons === false)
1308             $buttons = array();
1309
1310         $this->_tokens = array('HEADER' => $head, 'CONTENT' => $body);
1311         $this->_buttons = $buttons;
1312     }
1313
1314     /**
1315      * Show the alert box.
1316      */
1317     function show(&$request) {
1318         global $request;
1319
1320         $tokens = $this->_tokens;
1321         $tokens['BUTTONS'] = $this->_getButtons();
1322         
1323         $request->discardOutput();
1324         $tmpl = new Template('dialog', $request, $tokens);
1325         $tmpl->printXML();
1326         $request->finish();
1327     }
1328
1329
1330     function _getButtons() {
1331         global $request;
1332
1333         $buttons = $this->_buttons;
1334         if (!$buttons)
1335             $buttons = array(_("Okay") => $request->getURLtoSelf());
1336         
1337         global $Theme;
1338         foreach ($buttons as $label => $url)
1339             print "$label $url\n";
1340             $out[] = $Theme->makeButton($label, $url, 'wikiaction');
1341         return new XmlContent($out);
1342     }
1343 }
1344
1345 /** 
1346  * Returns true if current php version is at mimimum a.b.c 
1347  * Called: check_php_version(4,1)
1348  */
1349 function check_php_version ($a = '0', $b = '0', $c = '0') {
1350     global $PHP_VERSION;
1351     if(!isset($PHP_VERSION))
1352         $PHP_VERSION = substr( str_pad( preg_replace('/\D/','', PHP_VERSION), 3, '0'), 0, 3);
1353     return $PHP_VERSION >= ($a.$b.$c);
1354 }
1355
1356 function isWikiWord($word) {
1357     global $WikiNameRegexp;
1358     //or preg_match('/\A' . $WikiNameRegexp . '\z/', $word) ??
1359     return preg_match("/^$WikiNameRegexp\$/",$word);
1360 }
1361
1362 // needed to store serialized objects-values only (perm, pref)
1363 function obj2hash ($obj, $exclude = false, $fields = false) {
1364     $a = array();
1365     if (! $fields ) $fields = get_object_vars($obj);
1366     foreach ($fields as $key => $val) {
1367         if (is_array($exclude)) {
1368             if (in_array($key,$exclude)) continue;
1369         }
1370         $a[$key] = $val;
1371     }
1372     return $a;
1373 }
1374
1375 // $Log: not supported by cvs2svn $
1376 // Revision 1.163  2004/03/17 18:41:49  rurban
1377 // just reformatting
1378 //
1379 // Revision 1.162  2004/03/16 15:43:08  rurban
1380 // make fileSet sortable to please PageList
1381 //
1382 // Revision 1.161  2004/03/12 15:48:07  rurban
1383 // fixed explodePageList: wrong sortby argument order in UnfoldSubpages
1384 // simplified lib/stdlib.php:explodePageList
1385 //
1386 // Revision 1.160  2004/02/28 21:14:08  rurban
1387 // generally more PHPDOC docs
1388 //   see http://xarch.tu-graz.ac.at/home/rurban/phpwiki/xref/
1389 // fxied WikiUserNew pref handling: empty theme not stored, save only
1390 //   changed prefs, sql prefs improved, fixed password update,
1391 //   removed REPLACE sql (dangerous)
1392 // moved gettext init after the locale was guessed
1393 // + some minor changes
1394 //
1395 // Revision 1.158  2004/02/19 21:54:17  rurban
1396 // moved initerwiki code to PageType.php
1397 // re-enabled and fixed InlineImages support, now also for InterWiki Urls
1398 //      * [File:my_image.gif] inlines the image,
1399 //      * File:my_image.gif shows a plain inter-wiki link,
1400 //      * [what a pic|File:my_image.gif] shows a named inter-wiki link to the gif
1401 //      * [File:my_image.gif|what a pic] shows a inlimed image linked to the page "what a pic"
1402 //
1403 // Revision 1.157  2004/02/09 03:58:12  rurban
1404 // for now default DB_SESSION to false
1405 // PagePerm:
1406 //   * not existing perms will now query the parent, and not
1407 //     return the default perm
1408 //   * added pagePermissions func which returns the object per page
1409 //   * added getAccessDescription
1410 // WikiUserNew:
1411 //   * added global ->prepare (not yet used) with smart user/pref/member table prefixing.
1412 //   * force init of authdbh in the 2 db classes
1413 // main:
1414 //   * fixed session handling (not triple auth request anymore)
1415 //   * don't store cookie prefs with sessions
1416 // stdlib: global obj2hash helper from _AuthInfo, also needed for PagePerm
1417 //
1418 // Revision 1.156  2004/01/26 09:17:49  rurban
1419 // * changed stored pref representation as before.
1420 //   the array of objects is 1) bigger and 2)
1421 //   less portable. If we would import packed pref
1422 //   objects and the object definition was changed, PHP would fail.
1423 //   This doesn't happen with an simple array of non-default values.
1424 // * use $prefs->retrieve and $prefs->store methods, where retrieve
1425 //   understands the interim format of array of objects also.
1426 // * simplified $prefs->get() and fixed $prefs->set()
1427 // * added $user->_userid and class '_WikiUser' portability functions
1428 // * fixed $user object ->_level upgrading, mostly using sessions.
1429 //   this fixes yesterdays problems with loosing authorization level.
1430 // * fixed WikiUserNew::checkPass to return the _level
1431 // * fixed WikiUserNew::isSignedIn
1432 // * added explodePageList to class PageList, support sortby arg
1433 // * fixed UserPreferences for WikiUserNew
1434 // * fixed WikiPlugin for empty defaults array
1435 // * UnfoldSubpages: added pagename arg, renamed pages arg,
1436 //   removed sort arg, support sortby arg
1437 //
1438 // Revision 1.155  2004/01/25 10:52:22  rurban
1439 // added sortby support to explodePageList() and UnfoldSubpages
1440 // fixes [ 758044 ] Plugin UnfoldSubpages does not sort (includes fix)
1441 //
1442 // Revision 1.154  2004/01/25 03:49:03  rurban
1443 // added isWikiWord() to avoid redundancy
1444 // added check_php_version() to check for older php versions.
1445 //   e.g. object::method calls, ...
1446 //
1447 // Revision 1.153  2003/11/30 18:43:18  carstenklapp
1448 // Fixed careless mistakes in my last optimization commit.
1449 //
1450 // Revision 1.152  2003/11/30 18:20:34  carstenklapp
1451 // Minor code optimization: reduce invariant loops
1452 //
1453 // Revision 1.151  2003/11/29 19:30:01  carstenklapp
1454 // New function ByteFormatter.
1455 //
1456 // Revision 1.150  2003/09/13 22:43:00  carstenklapp
1457 // New preference to hide LinkIcons.
1458 //
1459 // Revision 1.149  2003/03/26 19:37:08  dairiki
1460 // Fix "object to string conversion" bug with external image links.
1461 //
1462 // Revision 1.148  2003/03/25 21:03:02  dairiki
1463 // Cleanup debugging output.
1464 //
1465 // Revision 1.147  2003/03/13 20:17:05  dairiki
1466 // Bug fix: Fix linking of pages whose names contain a hash ('#').
1467 //
1468 // Revision 1.146  2003/03/07 02:46:24  dairiki
1469 // function_usable(): New function.
1470 //
1471 // Revision 1.145  2003/03/04 01:55:05  dairiki
1472 // Fix to ensure absolute URL for logo in RSS recent changes.
1473 //
1474 // Revision 1.144  2003/02/26 00:39:30  dairiki
1475 // Bug fix: for magic PhpWiki URLs, "lock page to enable link" message was
1476 // being displayed at incorrect times.
1477 //
1478 // Revision 1.143  2003/02/26 00:10:26  dairiki
1479 // More/better/different checks for bad page names.
1480 //
1481 // Revision 1.142  2003/02/25 22:19:46  dairiki
1482 // Add some sanity checking for pagenames.
1483 //
1484 // Revision 1.141  2003/02/22 20:49:55  dairiki
1485 // Fixes for "Call-time pass by reference has been deprecated" errors.
1486 //
1487 // Revision 1.140  2003/02/21 23:33:29  dairiki
1488 // Set alt="" on the link icon image tags.
1489 // (See SF bug #675141.)
1490 //
1491 // Revision 1.139  2003/02/21 22:16:27  dairiki
1492 // Get rid of MakeWikiForm, and form-style MagicPhpWikiURLs.
1493 // These have been obsolete for quite awhile (I hope).
1494 //
1495 // Revision 1.138  2003/02/21 04:12:36  dairiki
1496 // WikiPageName: fixes for new cached links.
1497 //
1498 // Alert: new class for displaying alerts.
1499 //
1500 // ExtractWikiPageLinks and friends are now gone.
1501 //
1502 // LinkBracketLink moved to InlineParser.php
1503 //
1504 // Revision 1.137  2003/02/18 23:13:40  dairiki
1505 // Wups again.  Typo fix.
1506 //
1507 // Revision 1.136  2003/02/18 21:52:07  dairiki
1508 // Fix so that one can still link to wiki pages with # in their names.
1509 // (This was made difficult by the introduction of named tags, since
1510 // '[Page #1]' is now a link to anchor '1' in page 'Page'.
1511 //
1512 // Now the ~ escape for page names should work: [Page ~#1].
1513 //
1514 // Revision 1.135  2003/02/18 19:17:04  dairiki
1515 // split_pagename():
1516 //     Bug fix. 'ThisIsABug' was being split to 'This IsA Bug'.
1517 //     Cleanup up subpage splitting code.
1518 //
1519 // Revision 1.134  2003/02/16 19:44:20  dairiki
1520 // New function hash().  This is a helper, primarily for generating
1521 // HTTP ETags.
1522 //
1523 // Revision 1.133  2003/02/16 04:50:09  dairiki
1524 // New functions:
1525 // Rfc1123DateTime(), ParseRfc1123DateTime()
1526 // for converting unix timestamps to and from strings.
1527 //
1528 // These functions produce and grok the time strings
1529 // in the format specified by RFC 2616 for use in HTTP headers
1530 // (like Last-Modified).
1531 //
1532 // Revision 1.132  2003/01/04 22:19:43  carstenklapp
1533 // Bugfix UnfoldSubpages: "Undefined offset: 1" error when plugin invoked
1534 // on a page with no subpages (explodeList(): array 0-based, sizeof 1-based).
1535 //
1536
1537 // (c-file-style: "gnu")
1538 // Local Variables:
1539 // mode: php
1540 // tab-width: 8
1541 // c-basic-offset: 4
1542 // c-hanging-comment-ender-p: nil
1543 // indent-tabs-mode: nil
1544 // End:   
1545 ?>