1 <?php //rcs_id('$Id: stdlib.php,v 1.245 2005-09-18 16:01:09 rurban Exp $');
3 Copyright 1999,2000,2001,2002,2004,2005 $ThePhpWikiProgrammingTeam
5 This file is part of PhpWiki.
7 PhpWiki is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 PhpWiki is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with PhpWiki; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 Standard functions for Wiki functionality
24 WikiURL ($pagename, $args, $get_abs_url)
26 IconForLink ($protocol_or_url)
27 PossiblyGlueIconToText($proto_or_url, $text)
29 LinkURL ($url, $linktext)
30 LinkImage ($url, $alt)
32 SplitQueryArgs ($query_args)
33 LinkPhpwikiURL ($url, $text, $basepage)
34 ConvertOldMarkup ($content, $markup_type = "block")
35 MangleXmlIdentifier($str)
36 UnMangleXmlIdentifier($str)
38 class Stack { push($item), pop(), cnt(), top() }
39 class Alert { show() }
40 class WikiPageName {getParent(),isValid(),getWarnings() }
42 expand_tabs($str, $tab_width = 8)
44 NoSuchRevision ($request, $page, $version)
45 TimezoneOffset ($time, $no_colon)
46 Iso8601DateTime ($time)
47 Rfc2822DateTime ($time)
48 ParseRfc1123DateTime ($timestr)
50 ByteFormatter ($bytes = 0, $longformat = false)
53 __vsprintf ($fmt, $args)
55 file_mtime ($filename)
56 sort_file_mtime ($a, $b)
57 class fileSet {fileSet($directory, $filepattern = false), getFiles($exclude=false, $sortby=false, $limit=false) }
58 class ListRegexExpand { listMatchCallback($item, $key), expandRegex ($index, &$pages) }
61 glob_match ($glob, $against, $case_sensitive = true)
62 explodeList ($input, $allnames, $glob_style = true, $case_sensitive = true)
63 explodePageList ($input, $perm = false)
65 can ($object, $method)
66 function_usable ($function_name)
68 better_srand ($seed = '')
71 subPageSlice ($pagename, $pos)
75 obj2hash ($obj, $exclude = false, $fields = false)
78 url_get_contents ($uri)
80 firstNWordsOfContent ($n, $content)
81 extractSection ($section, $content, $page, $quiet = false, $sectionhead = false)
84 function: LinkInterWikiLink($link, $linktext)
85 moved to: lib/interwiki.php
86 function: linkExistingWikiWord($wikiword, $linktext, $version)
87 moved to: lib/Theme.php
88 function: LinkUnknownWikiWord($wikiword, $linktext)
89 moved to: lib/Theme.php
90 function: UpdateRecentChanges($dbi, $pagename, $isnewpage)
91 gone see: lib/plugin/RecentChanges.php
93 if (defined('_PHPWIKI_STDLIB_LOADED')) return;
94 else define('_PHPWIKI_STDLIB_LOADED', true);
96 define('MAX_PAGENAME_LENGTH', 100);
99 * Convert string to a valid XML identifier.
101 * XML 1.0 identifiers are of the form: [A-Za-z][A-Za-z0-9:_.-]*
103 * We would like to have, e.g. named anchors within wiki pages
104 * names like "Table of Contents" --- clearly not a valid XML
105 * fragment identifier.
107 * This function implements a one-to-one map from {any string}
108 * to {valid XML identifiers}.
111 * converting all bytes not in [A-Za-z0-9:_-],
112 * and any leading byte not in [A-Za-z] to 'xbb.',
113 * where 'bb' is the hexadecimal representation of the
116 * As a special case, the empty string is converted to 'empty.'
121 function MangleXmlIdentifier($str) {
125 return preg_replace('/[^-_:A-Za-z0-9]|(?<=^)[^A-Za-z]/e',
126 "'x' . sprintf('%02x', ord('\\0')) . '.'",
130 function UnMangleXmlIdentifier($str) {
131 if ($str == 'empty.')
133 return preg_replace('/x(\w\w)\./e',
134 "sprintf('%c', hex('\\0'))",
139 * Generates a valid URL for a given Wiki pagename.
140 * @param mixed $pagename If a string this will be the name of the Wiki page to link to.
141 * If a WikiDB_Page object function will extract the name to link to.
142 * If a WikiDB_PageRevision object function will extract the name to link to.
144 * @param boolean $get_abs_url Default value is false.
145 * @return string The absolute URL to the page passed as $pagename.
147 function WikiURL($pagename, $args = '', $get_abs_url = false) {
150 if (is_object($pagename)) {
151 if (isa($pagename, 'WikiDB_Page')) {
152 $pagename = $pagename->getName();
154 elseif (isa($pagename, 'WikiDB_PageRevision')) {
155 $page = $pagename->getPage();
156 $args['version'] = $pagename->getVersion();
157 $pagename = $page->getName();
159 elseif (isa($pagename, 'WikiPageName')) {
160 $anchor = $pagename->anchor;
161 $pagename = $pagename->name;
163 $anchor = $pagename->anchor;
164 $pagename = $pagename->name;
167 if (!$get_abs_url and DEBUG and $GLOBALS['request']->getArg('start_debug')) {
169 $args = 'start_debug=' . $GLOBALS['request']->getArg('start_debug');
170 elseif (is_array($args))
171 $args['start_debug'] = $GLOBALS['request']->getArg('start_debug');
173 $args .= '&start_debug=' . $GLOBALS['request']->getArg('start_debug');
175 if (is_array($args)) {
177 foreach ($args as $key => $val) {
178 // avoid default args
179 if (USE_PATH_INFO and $key == 'pagename')
181 elseif ($key == 'action' and $val == 'browse')
183 elseif (!is_array($val)) // ugly hack for getURLtoSelf() which also takes POST vars
184 $enc_args[] = urlencode($key) . '=' . urlencode($val);
186 $args = join('&', $enc_args);
189 if (USE_PATH_INFO or !empty($GLOBALS['WikiTheme']->HTML_DUMP_SUFFIX)) {
190 $url = $get_abs_url ? (SERVER_URL . VIRTUAL_PATH . "/") : "";
191 $url = $url . preg_replace('/%2f/i', '/', rawurlencode($pagename));
192 if (!empty($GLOBALS['WikiTheme']->HTML_DUMP_SUFFIX))
193 $url .= $GLOBALS['WikiTheme']->HTML_DUMP_SUFFIX;
198 $url = $get_abs_url ? SERVER_URL . SCRIPT_NAME : basename(SCRIPT_NAME);
199 $url .= "?pagename=" . rawurlencode($pagename);
204 $url .= "#" . MangleXmlIdentifier($anchor);
208 /** Convert relative URL to absolute URL.
210 * This converts a relative URL to one of PhpWiki's support files
211 * to an absolute one.
214 * @return string Absolute URL
216 function AbsoluteURL ($url) {
217 if (preg_match('/^https?:/', $url))
219 if ($url[0] != '/') {
220 $base = USE_PATH_INFO ? VIRTUAL_PATH : dirname(SCRIPT_NAME);
221 while ($base != '/' and substr($url, 0, 3) == "../") {
222 $url = substr($url, 3);
223 $base = dirname($base);
229 return SERVER_URL . $url;
232 function DataURL ($url) {
233 if (preg_match('/^https?:/', $url))
235 $url = NormalizeWebFileName($url);
236 if (DEBUG and $GLOBALS['request']->getArg('start_debug') and substr($url,-4,4) == '.php')
237 $url .= "?start_debug=1"; // XMLRPC and SOAP debugging helper.
238 return AbsoluteURL($url);
242 * Generates icon in front of links.
244 * @param string $protocol_or_url URL or protocol to determine which icon to use.
246 * @return HtmlElement HtmlElement object that contains data to create img link to
247 * icon for use with url or protocol passed to the function. False if no img to be
250 function IconForLink($protocol_or_url) {
252 if (0 and $filename_suffix == false) {
253 // display apache style icon for file type instead of protocol icon
254 // - archive: unix:gz,bz2,tgz,tar,z; mac:dmg,dmgz,bin,img,cpt,sit; pc:zip;
255 // - document: html, htm, text, txt, rtf, pdf, doc
256 // - non-inlined image: jpg,jpeg,png,gif,tiff,tif,swf,pict,psd,eps,ps
257 // - audio: mp3,mp2,aiff,aif,au
258 // - multimedia: mpeg,mpg,mov,qt
260 list ($proto) = explode(':', $protocol_or_url, 2);
261 $src = $WikiTheme->getLinkIconURL($proto);
263 return HTML::img(array('src' => $src, 'alt' => "", 'class' => 'linkicon', 'border' => 0));
270 * Glue icon in front of or after text.
271 * Pref: 'noLinkIcons' - ignore icon if set
272 * Theme: 'LinkIcons' - 'yes' at front
273 * - 'no' display no icon
274 * - 'front' display at left
275 * - 'after' display at right
277 * @param string $protocol_or_url Protocol or URL. Used to determine the
279 * @param string $text The text.
280 * @return XmlContent.
282 function PossiblyGlueIconToText($proto_or_url, $text) {
283 global $request, $WikiTheme;
284 if ($request->getPref('noLinkIcons'))
286 $icon = IconForLink($proto_or_url);
289 if ($where = $WikiTheme->getLinkIconAttr()) {
290 if ($where == 'no') return $text;
291 if ($where != 'after') $where = 'front';
295 if ($where == 'after') {
296 // span the icon only to the last word (tie them together),
297 // to let the previous words wrap on line breaks.
298 if (!is_object($text)) {
299 preg_match('/^(\s*\S*)(\s*)$/', $text, $m);
300 list (, $prefix, $last_word) = $m;
306 $text = HTML::span(array('style' => 'white-space: nowrap'),
307 $last_word, HTML::Raw(' '), $icon);
309 $text = HTML($prefix, $text);
312 // span the icon only to the first word (tie them together),
313 // to let the next words wrap on line breaks
314 if (!is_object($text)) {
315 preg_match('/^\s*(\S*)(.*?)\s*$/', $text, $m);
316 list (, $first_word, $tail) = $m;
322 $text = HTML::span(array('style' => 'white-space: nowrap'),
325 $text = HTML($text, $tail);
330 * Determines if the url passed to function is safe, by detecting if the characters
331 * '<', '>', or '"' are present.
332 * Check against their urlencoded values also.
334 * @param string $url URL to check for unsafe characters.
335 * @return boolean True if same, false else.
337 function IsSafeURL($url) {
338 return !preg_match('/([<>"])|(%3C)|(%3E)|(%22)/', $url);
342 * Generates an HtmlElement object to store data for a link.
344 * @param string $url URL that the link will point to.
345 * @param string $linktext Text to be displayed as link.
346 * @return HtmlElement HtmlElement object that contains data to construct an html link.
348 function LinkURL($url, $linktext = '') {
349 // FIXME: Is this needed (or sufficient?)
350 if(! IsSafeURL($url)) {
351 $link = HTML::strong(HTML::u(array('class' => 'baduri'),
352 _("BAD URL -- remove all of <, >, \"")));
356 $linktext = preg_replace("/mailto:/A", "", $url);
357 $args = array('href' => $url);
358 if ( defined('EXTERNAL_LINK_TARGET') ) // can also be set in the css
359 $args['target'] = is_string(EXTERNAL_LINK_TARGET) ? EXTERNAL_LINK_TARGET : "_blank";
360 $link = HTML::a($args, PossiblyGlueIconToText($url, $linktext));
362 $link->setAttr('class', $linktext ? 'namedurl' : 'rawurl');
369 * Syntax: [image.png size=50% border=n align= hspace= vspace= width= height=]
370 * Disallows sizes which are too small.
371 * Spammers may use such (typically invisible) image attributes to higher their GoogleRank.
373 * Handle embeddable objects, like svg, class, vrml, swf, svgz, pdf, avi, wmv especially.
375 function LinkImage($url, $alt = false) {
376 $force_img = "png|jpg|gif|jpeg|bmp|pl|cgi";
377 // Disallow tags in img src urls. Typical CSS attacks.
378 // FIXME: Is this needed (or sufficient?)
379 if(! IsSafeURL($url)) {
380 $link = HTML::strong(HTML::u(array('class' => 'baduri'),
381 _("BAD URL -- remove all of <, >, \"")));
383 // support new syntax: [image.jpg size=50% border=n]
384 if (!preg_match("/\.(".$force_img.")/i", $url))
386 $arr = split(' ',$url);
387 if (count($arr) > 1) {
390 if (empty($alt)) $alt = basename($url);
391 $link = HTML::img(array('src' => $url, 'alt' => $alt, 'title' => $alt));
392 if (count($arr) > 1) {
394 foreach ($arr as $attr) {
395 if (preg_match('/^size=(\d+%)$/',$attr,$m)) {
396 $link->setAttr('width',$m[1]);
397 $link->setAttr('height',$m[1]);
399 if (preg_match('/^size=(\d+)x(\d+)$/',$attr,$m)) {
400 $link->setAttr('width',$m[1]);
401 $link->setAttr('height',$m[2]);
403 if (preg_match('/^border=(\d+)$/',$attr,$m))
404 $link->setAttr('border',$m[1]);
405 if (preg_match('/^align=(\w+)$/',$attr,$m))
406 $link->setAttr('align',$m[1]);
407 if (preg_match('/^hspace=(\d+)$/',$attr,$m))
408 $link->setAttr('hspace',$m[1]);
409 if (preg_match('/^vspace=(\d+)$/',$attr,$m))
410 $link->setAttr('vspace',$m[1]);
413 // Check width and height as spam countermeasure
414 if (($width = $link->getAttr('width')) and ($height = $link->getAttr('height'))) {
415 //$width = (int) $width; // px or % or other suffix
416 //$height = (int) $height;
417 if (($width < 3 and $height < 10) or
418 ($height < 3 and $width < 20) or
419 ($height < 7 and $width < 7))
421 trigger_error(_("Invalid image size"), E_USER_WARNING);
425 // Older php versions crash here with certain png's:
426 // confirmed for 4.1.2, 4.1.3, 4.2.3; 4.3.2 and 4.3.7 are ok
427 // http://phpwiki.sourceforge.net/demo/themes/default/images/http.png
428 // See http://bugs.php.net/search.php?cmd=display&search_for=getimagesize
429 if (!check_php_version(4,3) and preg_match("/^http.+\.png$/i",$url))
430 ; // it's safe to assume that this will fail.
431 elseif (!DISABLE_GETIMAGESIZE and ($size = @getimagesize($url))) {
434 if (($width < 3 and $height < 10)
435 or ($height < 3 and $width < 20)
436 or ($height < 7 and $width < 7))
438 trigger_error(_("Invalid image size"), E_USER_WARNING);
444 $link->setAttr('class', 'inlineimage');
446 /* Check for inlined objects. Everything allowed in INLINE_IMAGES besides
447 * png|jpg|gif|jpeg|bmp|pl|cgi
448 * Note: Allow cgi's (pl,cgi) returning images.
450 if (!preg_match("/\.(".$force_img.")/i", $url)) {
451 //HTML::img(array('src' => $url, 'alt' => $alt, 'title' => $alt));
452 // => HTML::object(array('src' => $url)) ...;
453 return ImgObject($link, $ori_url);
459 * <object> / <embed> tags instead of <img> for all non-image extensions allowed via INLINE_IMAGES
460 * Called by LinkImage(), not directly.
461 * Syntax: [image.svg size=50% border=n align= hspace= vspace= width= height=]
462 * $alt may be an alternate img
463 * TODO: Need to unify with WikiPluginCached::embedObject()
465 * Note that Safari 1.0 will crash with <object>, use only <embed>
466 * http://www.alleged.org.uk/pdc/2002/svg-object.html
468 function ImgObject($img, $url) {
469 // get the url args: data="sample.svgz" type="image/svg+xml" width="400" height="300"
470 $args = split(' ', $url);
471 if (count($args) >= 1) {
472 $url = array_shift($args);
473 foreach ($args as $attr) {
474 if (preg_match('/^type=(\S+)$/',$attr,$m))
475 $img->setAttr('type', $m[1]);
476 if (preg_match('/^data=(\S+)$/',$attr,$m))
477 $img->setAttr('data', $m[1]);
480 $type = $img->getAttr('type');
482 // TODO: map extension to mime-types if type is not given and php < 4.3
483 if (function_exists('mime_content_type'))
484 $type = mime_content_type($url);
486 $link = HTML::object(array_merge($img->_attr, array('src' => $url, 'type' => $type)));
487 $link->setAttr('class', 'inlineobject');
488 if (isBrowserSafari()) {
489 return HTML::embed($link->_attr);
491 $link->pushContent(HTML::embed($link->_attr));
498 // var in php5 deprecated
500 $this->items = array();
503 function push($item) {
504 $this->items[$this->size] = $item;
510 if ($this->size == 0) {
511 return false; // stack is empty
514 return $this->items[$this->size];
523 return $this->items[$this->size - 1];
529 // end class definition
531 function SplitQueryArgs ($query_args = '')
533 // FIXME: use the arg-seperator which might not be &
534 $split_args = split('&', $query_args);
536 while (list($key, $val) = each($split_args))
537 if (preg_match('/^ ([^=]+) =? (.*) /x', $val, $m))
538 $args[$m[1]] = $m[2];
542 function LinkPhpwikiURL($url, $text = '', $basepage = false) {
545 if (!preg_match('/^ phpwiki: ([^?]*) [?]? (.*) $/x', $url, $m)) {
546 return HTML::strong(array('class' => 'rawurl'),
547 HTML::u(array('class' => 'baduri'),
548 _("BAD phpwiki: URL")));
552 $pagename = urldecode($m[1]);
555 if (empty($pagename) &&
556 preg_match('/^(diff|edit|links|info)=([^&]+)$/', $qargs, $m)) {
557 // Convert old style links (to not break diff links in
559 $pagename = urldecode($m[2]);
560 $args = array("action" => $m[1]);
563 $args = SplitQueryArgs($qargs);
566 if (empty($pagename))
567 $pagename = $GLOBALS['request']->getArg('pagename');
569 if (isset($args['action']) && $args['action'] == 'browse')
570 unset($args['action']);
573 if (empty($args['action']))
575 else if (is_safe_action($args['action']))
576 $class = 'wikiaction';
578 if (empty($args['action']) || is_safe_action($args['action']))
579 $class = 'wikiaction';
581 // Don't allow administrative links on unlocked pages.
582 $dbi = $GLOBALS['request']->getDbh();
583 $page = $dbi->getPage($basepage ? $basepage : $pagename);
584 if (!$page->get('locked'))
585 return HTML::span(array('class' => 'wikiunsafe'),
586 HTML::u(_("Lock page to enable link")));
587 $class = 'wikiadmin';
591 $text = HTML::span(array('class' => 'rawurl'), $url);
593 $wikipage = new WikiPageName($pagename);
594 if (!$wikipage->isValid()) {
596 return $WikiTheme->linkBadWikiWord($wikipage, $url);
599 return HTML::a(array('href' => WikiURL($pagename, $args),
605 * A class to assist in parsing wiki pagenames.
607 * Now with subpages and anchors, parsing and passing around
608 * pagenames is more complicated. This should help.
612 /** Short name for page.
614 * This is the value of $name passed to the constructor.
615 * (For use, e.g. as a default label for links to the page.)
619 /** The full page name.
621 * This is the full name of the page (without anchor).
627 * This is the referenced anchor within the page, or the empty string.
633 * @param mixed $name Page name.
634 * WikiDB_Page, WikiDB_PageRevision, or string.
635 * This can be a relative subpage name (like '/SubPage'),
636 * or can be the empty string to refer to the $basename.
638 * @param string $anchor For links to anchors in page.
640 * @param mixed $basename Page name from which to interpret
641 * relative or other non-fully-specified page names.
643 function WikiPageName($name, $basename=false, $anchor=false) {
644 if (is_string($name)) {
645 $this->shortName = $name;
646 if (strstr($name, ':')) {
647 list($moniker, $this->shortName) = split (":", $name, 2);
648 $map = getInterwikiMap(); // allow overrides to custom maps
649 if (isset($map->_map[$moniker])) {
650 $url = $map->_map[$moniker];
651 if (strstr($url, '%s'))
652 $url = sprintf($url, $this->shortName);
654 $url .= $this->shortName;
655 // expand Talk or User, but not to absolute urls!
656 if (strstr($url, '//')) {
657 if ($moniker == 'Talk')
658 $name = $name . SUBPAGE_SEPARATOR . _("Discussion");
659 elseif ($moniker == 'User')
664 if (strstr($name, '?'))
665 list($name, $dummy) = split("?", $name, 2);
668 // FIXME: We should really fix the cause for "/PageName" in the WikiDB
669 if ($name == '' or $name[0] == SUBPAGE_SEPARATOR) {
671 $name = $this->_pagename($basename) . $name;
673 $name = $this->_normalize_bad_pagename($name);
674 $this->shortName = $name;
679 $name = $this->_pagename($name);
680 $this->shortName = $name;
683 $this->name = $this->_check($name);
684 $this->anchor = (string)$anchor;
691 function getParent() {
693 if (!($tail = strrchr($name, SUBPAGE_SEPARATOR)))
695 return substr($name, 0, -strlen($tail));
698 function isValid($strict = false) {
700 return !isset($this->_errors);
701 return (is_string($this->name) and $this->name != '');
704 function getWarnings() {
706 if (isset($this->_warnings))
707 $warnings = array_merge($warnings, $this->_warnings);
708 if (isset($this->_errors))
709 $warnings = array_merge($warnings, $this->_errors);
713 return sprintf(_("'%s': Bad page name: %s"),
714 $this->shortName, join(', ', $warnings));
717 function _pagename($page) {
718 if (isa($page, 'WikiDB_Page'))
719 return $page->getName();
720 elseif (isa($page, 'WikiDB_PageRevision'))
721 return $page->getPageName();
722 elseif (isa($page, 'WikiPageName'))
724 // '0' or e.g. '1984' should be allowed though
725 if (!is_string($page) and !is_integer($page)) {
726 trigger_error(sprintf("Non-string pagename '%s' (%s)(%s)",
727 $page, gettype($page), get_class($page)),
730 //assert(is_string($page));
734 function _normalize_bad_pagename($name) {
735 trigger_error("Bad pagename: " . $name, E_USER_WARNING);
737 // Punt... You really shouldn't get here.
740 return $request->getArg('pagename');
742 assert($name[0] == SUBPAGE_SEPARATOR);
743 $this->_errors[] = sprintf(_("Leading %s not allowed"), SUBPAGE_SEPARATOR);
744 return substr($name, 1);
748 function _check($pagename) {
749 // Compress internal white-space to single space character.
750 $pagename = preg_replace('/[\s\xa0]+/', ' ', $orig = $pagename);
751 if ($pagename != $orig)
752 $this->_warnings[] = _("White space converted to single space");
754 // Delete any control characters.
755 if (DATABASE_TYPE == 'cvs' or DATABASE_TYPE == 'file') {
756 $pagename = preg_replace('/[\x00-\x1f\x7f\x80-\x9f]/', '', $orig = $pagename);
757 if ($pagename != $orig)
758 $this->_errors[] = _("Control characters not allowed");
761 // Strip leading and trailing white-space.
762 $pagename = trim($pagename);
765 while ($pagename and $pagename[0] == SUBPAGE_SEPARATOR)
766 $pagename = substr($pagename, 1);
767 if ($pagename != $orig)
768 $this->_errors[] = sprintf(_("Leading %s not allowed"), SUBPAGE_SEPARATOR);
770 // ";" is urlencoded, so safe from php arg-delim problems
771 /*if (strstr($pagename, ';')) {
772 $this->_warnings[] = _("';' is deprecated");
773 $pagename = str_replace(';', '', $pagename);
776 // not only for SQL, also to restrict url length
777 if (strlen($pagename) > MAX_PAGENAME_LENGTH) {
778 $pagename = substr($pagename, 0, MAX_PAGENAME_LENGTH);
779 $this->_errors[] = _("too long");
782 // disallow some chars only on file and cvs
783 if ((DATABASE_TYPE == 'cvs' or DATABASE_TYPE == 'file')
784 and preg_match('/(:|\.\.)/', $pagename, $m)) {
785 $this->_warnings[] = sprintf(_("Illegal chars %s removed"), $m[1]);
786 $pagename = str_replace('..', '', $pagename);
787 $pagename = str_replace(':', '', $pagename);
795 * Convert old page markup to new-style markup.
797 * @param string $text Old-style wiki markup.
799 * @param string $markup_type
801 * <dt><code>"block"</code> <dd>Convert all markup.
802 * <dt><code>"inline"</code> <dd>Convert only inline markup.
803 * <dt><code>"links"</code> <dd>Convert only link markup.
806 * @return string New-style wiki markup.
808 * @bugs Footnotes don't work quite as before (esp if there are
809 * multiple references to the same footnote. But close enough,
810 * probably for now....
811 * @bugs Apache2 and IIS crash with OldTextFormattingRules or
812 * AnciennesR%E8glesDeFormatage. (at the 2nd attempt to do the anchored block regex)
813 * It only crashes with CreateToc so far, but other pages (not in pgsrc) are
814 * also known to crash, even with Apache1.
816 function ConvertOldMarkup ($text, $markup_type = "block") {
822 // Trying to detect why the 2nd paragraph of OldTextFormattingRules or
823 // AnciennesR%E8glesDeFormatage crashes.
824 // It only crashes with CreateToc so far, but other pages (not in pgsrc) are
825 // also known to crash, even with Apache1.
827 // I suspect this only to crash with Apache2 and IIS.
828 if (in_array(php_sapi_name(),array('apache2handler','apache2filter','isapi'))
829 and preg_match("/plugin CreateToc/", $text))
831 trigger_error(_("The CreateTocPlugin is not yet old markup compatible! ")
832 ._("Please remove the CreateToc line to be able to reformat this page to old markup. ")
833 ._("Skipped."), E_USER_WARNING);
835 //if (!DEBUG) return $text;
840 /*****************************************************************
841 * Conversions for inline markup:
848 // escape escaped brackets
852 // change ! escapes to ~'s.
853 global $WikiNameRegexp, $request;
854 $bang_esc[] = "(?:" . ALLOWED_PROTOCOLS . "):[^\s<>\[\]\"'()]*[^\s<>\[\]\"'(),.?]";
855 // before 4.3.9 pcre had a memory release bug, which might hit us here. so be safe.
856 if (check_php_version(4,3,9)) {
857 $map = getInterwikiMap();
858 if ($map_regex = $map->getRegexp())
859 $bang_esc[] = $map_regex . ":[^\\s.,;?()]+"; // FIXME: is this really needed?
861 $bang_esc[] = $WikiNameRegexp;
862 $orig[] = '/!((?:' . join(')|(', $bang_esc) . '))/';
865 $subs["links"] = array($orig, $repl);
867 // Temporarily URL-encode pairs of underscores in links to hide
868 // them from the re for bold markup.
869 $orig[] = '/\[[^\[\]]*?__[^\[\]]*?\]/e';
870 $repl[] = 'str_replace(\'__\', \'%5F%5F\', \'\\0\')';
873 //$orig[] = '/<(?!\?plugin)|(?<!^)</m';
876 // Convert footnote references.
877 $orig[] = '/(?<=.)(?<!~)\[\s*(\d+)\s*\]/m';
878 $repl[] = '#[|ftnt_ref_\\1]<sup>~[[\\1|#ftnt_\\1]~]</sup>';
880 // Convert old style emphases to HTML style emphasis.
881 $orig[] = '/__(.*?)__/';
882 $repl[] = '<strong>\\1</strong>';
883 $orig[] = "/''(.*?)''/";
884 $repl[] = '<em>\\1</em>';
886 // Escape nestled markup.
887 $orig[] = '/^(?<=^|\s)[=_](?=\S)|(?<=\S)[=_*](?=\s|$)/m';
890 // in old markup headings only allowed at beginning of line
894 // Convert URL-encoded pairs of underscores in links back to
895 // real underscores after bold markup has been converted.
896 $orig = '/\[[^\[\]]*?%5F%5F[^\[\]]*?\]/e';
897 $repl = 'str_replace(\'%5F%5F\', \'__\', \'\\0\')';
899 $subs["inline"] = array($orig, $repl);
901 /*****************************************************************
902 * Patterns which match block markup constructs which take
903 * special handling...
907 $blockpats[] = '[ \t]+\S(?:.*\s*\n[ \t]+\S)*';
909 $blockpats[] = '\|(?:.*\n\|)*';
912 $blockpats[] = '[#*;]*(?:[*#]|;.*?:)';
914 // Footnote definitions
915 $blockpats[] = '\[\s*(\d+)\s*\]';
919 $blockpats[] = '<\?plugin(?:-form)?\b.*\?>\s*$';
923 $blockpats[] = '!{1,3}[^!]';
925 removed .|\n in the anchor not to crash on /m because with /m "." already includes \n
926 this breaks headings but it doesn't crash anymore (crash on non-cgi, non-cli only)
928 $block_re = ( '/\A((?:.|\n)*?)(^(?:'
929 . join("|", $blockpats)
934 if ($markup_type != "block") {
935 list ($orig, $repl) = $subs[$markup_type];
936 return preg_replace($orig, $repl, $text);
939 list ($orig, $repl) = $subs['inline'];
942 // php crashes here in the 2nd paragraph of OldTextFormattingRules,
943 // AnciennesR%E8glesDeFormatage and more
944 // See http://www.pcre.org/pcre.txt LIMITATIONS
945 while (preg_match($block_re, $text, $m)) {
946 $text = substr($text, strlen($m[0]));
947 list (,$leading_text, $block) = $m;
950 if (strchr(" \t", $block[0])) {
953 $suffix = "\n</pre>\n";
955 elseif ($block[0] == '|') {
957 $prefix = "<?plugin OldStyleTable\n";
960 elseif (strchr("#*;", $block[0])) {
961 // Old-style list item
962 preg_match('/^([#*;]*)([*#]|;.*?:) */', $block, $m);
963 list (,$ind,$bullet) = $m;
964 $block = substr($block, strlen($m[0]));
966 $indent = str_repeat(' ', strlen($ind));
967 if ($bullet[0] == ';') {
968 //$term = ltrim(substr($bullet, 1));
969 //return $indent . $term . "\n" . $indent . ' ';
970 $prefix = $ind . $bullet;
973 $prefix = $indent . $bullet . ' ';
975 elseif ($block[0] == '[') {
976 // Footnote definition
977 preg_match('/^\[\s*(\d+)\s*\]/', $block, $m);
979 $block = substr($block, strlen($m[0]));
980 $prefix = "#[|ftnt_${footnum}]~[[${footnum}|#ftnt_ref_${footnum}]~] ";
982 elseif ($block[0] == '<') {
984 // HACK: no inline markup...
988 elseif ($block[0] == '!') {
990 preg_match('/^!{1,3}/', $block, $m);
992 $block = substr($block, strlen($m[0]));
998 if ($leading_text) $leading_text = preg_replace($orig, $repl, $leading_text);
999 if ($block) $block = preg_replace($orig, $repl, $block);
1000 $out .= $leading_text;
1005 return $out . preg_replace($orig, $repl, $text);
1011 * Expand tabs in string.
1013 * Converts all tabs to (the appropriate number of) spaces.
1015 * @param string $str
1016 * @param integer $tab_width
1019 function expand_tabs($str, $tab_width = 8) {
1020 $split = split("\t", $str);
1021 $tail = array_pop($split);
1023 foreach ($split as $hunk) {
1025 $pos = strlen(strrchr($expanded, "\n")) - 1;
1026 $expanded .= str_repeat(" ", ($tab_width - $pos % $tab_width));
1028 return substr($expanded, 1) . $tail;
1032 * Split WikiWords in page names.
1034 * It has been deemed useful to split WikiWords (into "Wiki Words") in
1035 * places like page titles. This is rumored to help search engines
1038 * @param $page string The page name.
1040 * @return string The split name.
1042 function SplitPagename ($page) {
1044 if (preg_match("/\s/", $page))
1045 return $page; // Already split --- don't split any more.
1047 // This algorithm is specialized for several languages.
1048 // (Thanks to Pierrick MEIGNEN)
1049 // Improvements for other languages welcome.
1052 // This mess splits between a lower-case letter followed by
1053 // either an upper-case or a numeral; except that it wont
1054 // split the prefixes 'Mc', 'De', or 'Di' off of their tails.
1055 switch ($GLOBALS['LANG']) {
1060 $RE[] = '/([[:lower:]])((?<!Mc|De|Di)[[:upper:]]|\d)/';
1063 $RE[] = '/([[:lower:]])((?<!Mc|Di)[[:upper:]]|\d)/';
1066 $sep = preg_quote(SUBPAGE_SEPARATOR, '/');
1067 // This the single-letter words 'I' and 'A' from any following
1068 // capitalized words.
1069 switch ($GLOBALS['LANG']) {
1071 $RE[] = "/(?<= |${sep}|^)([AI])([[:upper:]][[:lower:]])/";
1074 $RE[] = "/(?<= |${sep}|^)([À])([[:upper:]][[:lower:]])/";
1077 // Split numerals from following letters.
1078 $RE[] = '/(\d)([[:alpha:]])/';
1079 // Split at subpage seperators. TBD in Theme.php
1080 $RE[] = "/([^${sep}]+)(${sep})/";
1082 foreach ($RE as $key)
1083 $RE[$key] = pcre_fix_posix_classes($key);
1086 foreach ($RE as $regexp) {
1087 $page = preg_replace($regexp, '\\1 \\2', $page);
1092 function NoSuchRevision (&$request, $page, $version) {
1093 $html = HTML(HTML::h2(_("Revision Not Found")),
1094 HTML::p(fmt("I'm sorry. Version %d of %s is not in the database.",
1095 $version, WikiLink($page, 'auto'))));
1096 include_once('lib/Template.php');
1097 GeneratePage($html, _("Bad Version"), $page->getCurrentRevision());
1103 * Get time offset for local time zone.
1105 * @param $time time_t Get offset for this time. Default: now.
1106 * @param $no_colon boolean Don't put colon between hours and minutes.
1107 * @return string Offset as a string in the format +HH:MM.
1109 function TimezoneOffset ($time = false, $no_colon = false) {
1110 if ($time === false)
1112 $secs = date('Z', $time);
1121 $colon = $no_colon ? '' : ':';
1122 $mins = intval(($secs + 30) / 60);
1123 return sprintf("%s%02d%s%02d",
1124 $sign, $mins / 60, $colon, $mins % 60);
1129 * Format time in ISO-8601 format.
1131 * @param $time time_t Time. Default: now.
1132 * @return string Date and time in ISO-8601 format.
1134 function Iso8601DateTime ($time = false) {
1135 if ($time === false)
1137 $tzoff = TimezoneOffset($time);
1138 $date = date('Y-m-d', $time);
1139 $time = date('H:i:s', $time);
1140 return $date . 'T' . $time . $tzoff;
1144 * Format time in RFC-2822 format.
1146 * @param $time time_t Time. Default: now.
1147 * @return string Date and time in RFC-2822 format.
1149 function Rfc2822DateTime ($time = false) {
1150 if ($time === false)
1152 return date('D, j M Y H:i:s ', $time) . TimezoneOffset($time, 'no colon');
1156 * Format time in RFC-1123 format.
1158 * @param $time time_t Time. Default: now.
1159 * @return string Date and time in RFC-1123 format.
1161 function Rfc1123DateTime ($time = false) {
1162 if ($time === false)
1164 return gmdate('D, d M Y H:i:s \G\M\T', $time);
1167 /** Parse date in RFC-1123 format.
1169 * According to RFC 1123 we must accept dates in the following
1172 * Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
1173 * Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
1174 * Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
1176 * (Though we're only allowed to generate dates in the first format.)
1178 function ParseRfc1123DateTime ($timestr) {
1179 $timestr = trim($timestr);
1180 if (preg_match('/^ \w{3},\s* (\d{1,2}) \s* (\w{3}) \s* (\d{4}) \s*'
1181 .'(\d\d):(\d\d):(\d\d) \s* GMT $/ix',
1183 list(, $mday, $mon, $year, $hh, $mm, $ss) = $m;
1185 elseif (preg_match('/^ \w+,\s* (\d{1,2})-(\w{3})-(\d{2}|\d{4}) \s*'
1186 .'(\d\d):(\d\d):(\d\d) \s* GMT $/ix',
1188 list(, $mday, $mon, $year, $hh, $mm, $ss) = $m;
1189 if ($year < 70) $year += 2000;
1190 elseif ($year < 100) $year += 1900;
1192 elseif (preg_match('/^\w+\s* (\w{3}) \s* (\d{1,2}) \s*'
1193 .'(\d\d):(\d\d):(\d\d) \s* (\d{4})$/ix',
1195 list(, $mon, $mday, $hh, $mm, $ss, $year) = $m;
1202 $time = strtotime("$mday $mon $year ${hh}:${mm}:${ss} GMT");
1204 return false; // failed
1209 * Format time to standard 'ctime' format.
1211 * @param $time time_t Time. Default: now.
1212 * @return string Date and time.
1214 function CTime ($time = false)
1216 if ($time === false)
1218 return date("D M j H:i:s Y", $time);
1223 * Format number as kilobytes or bytes.
1224 * Short format is used for PageList
1225 * Long format is used in PageInfo
1227 * @param $bytes int. Default: 0.
1228 * @param $longformat bool. Default: false.
1229 * @return class FormattedText (XmlElement.php).
1231 function ByteFormatter ($bytes = 0, $longformat = false) {
1234 if ($bytes < 1024) {
1236 $size = fmt("%s b", $bytes);
1238 $size = fmt("%s bytes", $bytes);
1241 $kb = round($bytes / 1024, 1);
1243 $size = fmt("%s k", $kb);
1245 $size = fmt("%s Kb (%s bytes)", $kb, $bytes);
1251 * Internationalized printf.
1253 * This is essentially the same as PHP's built-in printf
1254 * with the following exceptions:
1256 * <li> It passes the format string through gettext().
1257 * <li> It supports the argument reordering extensions.
1264 * __printf("Differences between versions %s and %s of %s",
1265 * $new_link, $old_link, $page_link);
1268 * Then in locale/po/de.po, one can reorder the printf arguments:
1271 * msgid "Differences between %s and %s of %s."
1272 * msgstr "Der Unterschiedsergebnis von %3$s, zwischen %1$s und %2$s."
1275 * (Note that while PHP tries to expand $vars within double-quotes,
1276 * the values in msgstr undergo no such expansion, so the '$'s
1279 * One shouldn't use reordered arguments in the default format string.
1280 * Backslashes in the default string would be necessary to escape the
1281 * '$'s, and they'll cause all kinds of trouble....
1283 function __printf ($fmt) {
1284 $args = func_get_args();
1286 echo __vsprintf($fmt, $args);
1290 * Internationalized sprintf.
1292 * This is essentially the same as PHP's built-in printf with the
1293 * following exceptions:
1296 * <li> It passes the format string through gettext().
1297 * <li> It supports the argument reordering extensions.
1302 function __sprintf ($fmt) {
1303 $args = func_get_args();
1305 return __vsprintf($fmt, $args);
1309 * Internationalized vsprintf.
1311 * This is essentially the same as PHP's built-in printf with the
1312 * following exceptions:
1315 * <li> It passes the format string through gettext().
1316 * <li> It supports the argument reordering extensions.
1321 function __vsprintf ($fmt, $args) {
1322 $fmt = gettext($fmt);
1323 // PHP's sprintf doesn't support variable with specifiers,
1324 // like sprintf("%*s", 10, "x"); --- so we won't either.
1326 if (preg_match_all('/(?<!%)%(\d+)\$/x', $fmt, $m)) {
1327 // Format string has '%2$s' style argument reordering.
1328 // PHP doesn't support this.
1329 if (preg_match('/(?<!%)%[- ]?\d*[^- \d$]/x', $fmt))
1330 // literal variable name substitution only to keep locale
1331 // strings uncluttered
1332 trigger_error(sprintf(_("Can't mix '%s' with '%s' type format strings"),
1333 '%1\$s','%s'), E_USER_WARNING); //php+locale error
1335 $fmt = preg_replace('/(?<!%)%\d+\$/x', '%', $fmt);
1338 // Reorder arguments appropriately.
1339 foreach($m[1] as $argnum) {
1340 if ($argnum < 1 || $argnum > count($args))
1341 trigger_error(sprintf(_("%s: argument index out of range"),
1342 $argnum), E_USER_WARNING);
1343 $newargs[] = $args[$argnum - 1];
1348 // Not all PHP's have vsprintf, so...
1349 array_unshift($args, $fmt);
1350 return call_user_func_array('sprintf', $args);
1353 function file_mtime ($filename) {
1354 if ($stat = @stat($filename))
1360 function sort_file_mtime ($a, $b) {
1361 $ma = file_mtime($a);
1362 $mb = file_mtime($b);
1363 if (!$ma or !$mb or $ma == $mb) return 0;
1364 return ($ma > $mb) ? -1 : 1;
1369 * Build an array in $this->_fileList of files from $dirname.
1370 * Subdirectories are not traversed.
1372 * (This was a function LoadDir in lib/loadsave.php)
1373 * See also http://www.php.net/manual/en/function.readdir.php
1375 function getFiles($exclude=false, $sortby=false, $limit=false) {
1376 $list = $this->_fileList;
1379 require_once('lib/PageList.php');
1380 switch (Pagelist::sortby($sortby, 'db')) {
1381 case 'pagename ASC': break;
1382 case 'pagename DESC':
1383 $list = array_reverse($list);
1386 usort($list,'sort_file_mtime');
1389 usort($list,'sort_file_mtime');
1390 $list = array_reverse($list);
1395 return array_splice($list, 0, $limit);
1399 function _filenameSelector($filename) {
1400 if (! $this->_pattern )
1403 if (! $this->_pcre_pattern )
1404 $this->_pcre_pattern = glob_to_pcre($this->_pattern);
1405 return preg_match('/' . $this->_pcre_pattern . ($this->_case ? '/' : '/i'),
1410 function fileSet($directory, $filepattern = false) {
1411 $this->_fileList = array();
1412 $this->_pattern = $filepattern;
1414 $this->_pcre_pattern = glob_to_pcre($this->_pattern);
1415 $this->_case = !isWindows();
1416 $this->_pathsep = '/';
1418 if (empty($directory)) {
1419 trigger_error(sprintf(_("%s is empty."), 'directoryname'),
1421 return; // early return
1424 @ $dir_handle = opendir($dir=$directory);
1425 if (empty($dir_handle)) {
1426 trigger_error(sprintf(_("Unable to open directory '%s' for reading"),
1427 $dir), E_USER_NOTICE);
1428 return; // early return
1431 while ($filename = readdir($dir_handle)) {
1432 if ($filename[0] == '.' || filetype($dir . $this->_pathsep . $filename) != 'file')
1434 if ($this->_filenameSelector($filename)) {
1435 array_push($this->_fileList, "$filename");
1436 //trigger_error(sprintf(_("found file %s"), $filename),
1437 // E_USER_NOTICE); //debugging
1440 closedir($dir_handle);
1446 // expands a list containing regex's to its matching entries
1447 class ListRegexExpand {
1448 //var $match, $list, $index, $case_sensitive;
1449 function ListRegexExpand (&$list, $match, $case_sensitive = true) {
1450 $this->match = $match;
1451 $this->list = &$list;
1452 $this->case_sensitive = $case_sensitive;
1453 //$this->index = false;
1455 function listMatchCallback ($item, $key) {
1456 $quoted = str_replace('/','\/',$item);
1457 if (preg_match('/' . $this->match . ($this->case_sensitive ? '/' : '/i'),
1459 unset($this->list[$this->index]);
1460 $this->list[] = $item;
1463 function expandRegex ($index, &$pages) {
1464 $this->index = $index;
1465 array_walk($pages, array($this, 'listMatchCallback'));
1470 // Convert fileglob to regex style:
1471 // Convert some wildcards to pcre style, escape the rest
1472 // Escape . \\ + * ? [ ^ ] $ ( ) { } = ! < > | : /
1473 // Fixed bug #994994: "/" in $glob.
1474 function glob_to_pcre ($glob) {
1475 // check simple case: no need to escape
1476 $escape = '\[](){}=!<>|:/';
1477 if (strcspn($glob, $escape . ".+*?^$") == strlen($glob))
1479 // preg_replace cannot handle "\\\\\\2" so convert \\ to \xff
1480 $glob = strtr($glob, "\\", "\xff");
1481 $glob = str_replace("/", '\/', $glob);
1482 // first convert some unescaped expressions to pcre style: . => \.
1484 $re = preg_replace('/([^\xff])?(['.preg_quote($special).'])/',
1485 "\\1\xff\\2", $glob);
1488 $re = preg_replace('/([^\xff])?\*/', '$1.*', $re);
1489 $re = preg_replace('/([^\xff])?\?/', '$1.', $re);
1490 if (!preg_match('/^[\?\*]/', $glob))
1492 if (!preg_match('/[\?\*]$/', $glob))
1495 // .*? handled above, now escape the rest
1496 //while (strcspn($re, $escape) != strlen($re)) // loop strangely needed
1497 $re = preg_replace('/([^\xff])(['.preg_quote($escape, "/").'])/',
1499 return strtr($re, "\xff", "\\");
1502 function glob_match ($glob, $against, $case_sensitive = true) {
1503 return preg_match('/' . glob_to_pcre($glob) . ($case_sensitive ? '/' : '/i'),
1507 function explodeList($input, $allnames, $glob_style = true, $case_sensitive = true) {
1508 $list = explode(',',$input);
1509 // expand wildcards from list of $allnames
1510 if (preg_match('/[\?\*]/',$input)) {
1511 // Optimizing loop invariants:
1512 // http://phplens.com/lens/php-book/optimizing-debugging-php.php
1513 for ($i = 0, $max = sizeof($list); $i < $max; $i++) {
1515 if (preg_match('/[\?\*]/',$f)) {
1517 $expand = new ListRegexExpand($list,
1518 $glob_style ? glob_to_pcre($f) : $f, $case_sensitive);
1519 $expand->expandRegex($i, $allnames);
1526 // echo implode(":",explodeList("Test*",array("xx","Test1","Test2")));
1527 function explodePageList($input, $include_empty=false, $sortby='pagename',
1528 $limit=false, $exclude=false) {
1529 include_once("lib/PageList.php");
1530 return PageList::explodePageList($input, $include_empty, $sortby, $limit, $exclude);
1533 // Class introspections
1536 * Determine whether object is of a specified type.
1537 * In PHP builtin since 4.2.0 as is_a()
1539 * @param $object object An object.
1540 * @param $class string Class name.
1541 * @return bool True iff $object is a $class
1542 * or a sub-type of $class.
1544 function isa ($object, $class) {
1545 //if (check_php_version(5))
1546 // return $object instanceof $class;
1547 if (check_php_version(4,2) and !check_php_version(5))
1548 return is_a($object, $class);
1550 $lclass = check_php_version(5) ? $class : strtolower($class);
1551 return is_object($object)
1552 && ( strtolower(get_class($object)) == strtolower($class)
1553 || is_subclass_of($object, $lclass) );
1556 /** Determine whether (possible) object has method.
1558 * @param $object mixed Object
1559 * @param $method string Method name
1560 * @return bool True iff $object is an object with has method $method.
1562 function can ($object, $method) {
1563 return is_object($object) && method_exists($object, strtolower($method));
1566 /** Determine whether a function is okay to use.
1568 * Some providers (e.g. Lycos) disable some of PHP functions for
1569 * "security reasons." This makes those functions, of course,
1570 * unusable, despite the fact the function_exists() says they
1573 * This function test to see if a function exists and is not
1574 * disallowed by PHP's disable_functions config setting.
1576 * @param string $function_name Function name
1577 * @return bool True iff function can be used.
1579 function function_usable($function_name) {
1581 if (!is_array($disabled)) {
1582 $disabled = array();
1583 // Use get_cfg_var since ini_get() is one of the disabled functions
1584 // (on Lycos, at least.)
1585 $split = preg_split('/\s*,\s*/', trim(get_cfg_var('disable_functions')));
1586 foreach ($split as $f)
1587 $disabled[strtolower($f)] = true;
1590 return ( function_exists($function_name)
1591 and ! isset($disabled[strtolower($function_name)])
1598 * This is used for generating ETags.
1600 function hash ($x) {
1601 if (is_scalar($x)) {
1604 elseif (is_array($x)) {
1606 return md5(serialize($x));
1608 elseif (is_object($x)) {
1611 trigger_error("Can't hash $x", E_USER_ERROR);
1616 * Seed the random number generator.
1618 * better_srand() ensures the randomizer is seeded only once.
1620 * How random do you want it? See:
1621 * http://www.php.net/manual/en/function.srand.php
1622 * http://www.php.net/manual/en/function.mt-srand.php
1624 function better_srand($seed = '') {
1625 static $wascalled = FALSE;
1627 $seed = $seed === '' ? (double) microtime() * 1000000 : $seed;
1628 function_exists('mt_srand') ? mt_srand($seed) : srand($seed);
1630 //trigger_error("new random seed", E_USER_NOTICE); //debugging
1634 function rand_ascii($length = 1) {
1637 for ($i = 1; $i <= $length; $i++) {
1638 // return only typeable 7 bit ascii, avoid quotes
1639 if (function_exists('mt_rand'))
1640 $s .= chr(mt_rand(40, 126));
1642 // the usually bad glibc srand()
1643 $s .= chr(rand(40, 126));
1649 * Recursively count all non-empty elements
1650 * in array of any dimension or mixed - i.e.
1651 * array('1' => 2, '2' => array('1' => 3, '2' => 4))
1652 * See http://www.php.net/manual/en/function.count.php
1654 function count_all($arg) {
1655 // skip if argument is empty
1657 //print_r($arg); //debugging
1659 // not an array, return 1 (base case)
1662 // else call recursively for all elements $arg
1663 foreach($arg as $key => $val)
1664 $count += count_all($val);
1669 function isSubPage($pagename) {
1670 return (strstr($pagename, SUBPAGE_SEPARATOR));
1673 function subPageSlice($pagename, $pos) {
1674 $pages = explode(SUBPAGE_SEPARATOR,$pagename);
1675 $pages = array_slice($pages,$pos,1);
1682 * Class for "popping up" and alert box. (Except that right now, it doesn't
1686 * This is a hackish and needs to be refactored. However it would be nice to
1687 * unify all the different methods we use for showing Alerts and Dialogs.
1688 * (E.g. "Page deleted", login form, ...)
1693 * @param object $request
1694 * @param mixed $head Header ("title") for alert box.
1695 * @param mixed $body The text in the alert box.
1696 * @param hash $buttons An array mapping button labels to URLs.
1697 * The default is a single "Okay" button pointing to $request->getURLtoSelf().
1699 function Alert($head, $body, $buttons=false) {
1700 if ($buttons === false)
1703 $this->_tokens = array('HEADER' => $head, 'CONTENT' => $body);
1704 $this->_buttons = $buttons;
1708 * Show the alert box.
1713 $tokens = $this->_tokens;
1714 $tokens['BUTTONS'] = $this->_getButtons();
1716 $request->discardOutput();
1717 $tmpl = new Template('dialog', $request, $tokens);
1723 function _getButtons() {
1726 $buttons = $this->_buttons;
1728 $buttons = array(_("Okay") => $request->getURLtoSelf());
1731 foreach ($buttons as $label => $url)
1732 print "$label $url\n";
1733 $out[] = $WikiTheme->makeButton($label, $url, 'wikiaction');
1734 return new XmlContent($out);
1739 // 1.3.9-p1 => 1030.091
1740 // 1.3.10pre => 1030.099
1741 // 1.3.11pre-20041120 => 1030.1120041120
1742 function phpwiki_version() {
1743 static $PHPWIKI_VERSION;
1744 if (!isset($PHPWIKI_VERSION)) {
1745 $arr = explode('.',preg_replace('/\D+$/','', PHPWIKI_VERSION)); // remove the pre
1746 $arr[2] = preg_replace('/\.+/','.',preg_replace('/\D/','.',$arr[2]));
1747 $PHPWIKI_VERSION = $arr[0]*1000 + $arr[1]*10 + 0.01*$arr[2];
1748 if (strstr(PHPWIKI_VERSION, 'pre'))
1749 $PHPWIKI_VERSION -= 0.01;
1751 return $PHPWIKI_VERSION;
1754 function phpwiki_gzhandler($ob) {
1755 if (function_exists('gzencode'))
1756 $ob = gzencode($ob);
1757 $GLOBALS['request']->_ob_get_length = strlen($ob);
1758 if (!headers_sent()) {
1759 header(sprintf("Content-Length: %d", $GLOBALS['request']->_ob_get_length));
1764 function isWikiWord($word) {
1765 global $WikiNameRegexp;
1766 //or preg_match('/\A' . $WikiNameRegexp . '\z/', $word) ??
1767 return preg_match("/^$WikiNameRegexp\$/",$word);
1770 // needed to store serialized objects-values only (perm, pref)
1771 function obj2hash ($obj, $exclude = false, $fields = false) {
1773 if (! $fields ) $fields = get_object_vars($obj);
1774 foreach ($fields as $key => $val) {
1775 if (is_array($exclude)) {
1776 if (in_array($key, $exclude)) continue;
1784 * isUtf8String($string) - cheap utf-8 detection
1786 * segfaults for strings longer than 10kb!
1787 * Use http://www.phpdiscuss.com/article.php?id=565&group=php.i18n or
1788 * checkTitleEncoding() at http://cvs.sourceforge.net/viewcvs.py/wikipedia/phase3/languages/Language.php
1790 function isUtf8String( $s ) {
1791 $ptrASCII = '[\x00-\x7F]';
1792 $ptr2Octet = '[\xC2-\xDF][\x80-\xBF]';
1793 $ptr3Octet = '[\xE0-\xEF][\x80-\xBF]{2}';
1794 $ptr4Octet = '[\xF0-\xF4][\x80-\xBF]{3}';
1795 $ptr5Octet = '[\xF8-\xFB][\x80-\xBF]{4}';
1796 $ptr6Octet = '[\xFC-\xFD][\x80-\xBF]{5}';
1797 return preg_match("/^($ptrASCII|$ptr2Octet|$ptr3Octet|$ptr4Octet|$ptr5Octet|$ptr6Octet)*$/s", $s);
1801 * Check for UTF-8 URLs; Internet Explorer produces these if you
1802 * type non-ASCII chars in the URL bar or follow unescaped links.
1803 * Requires urldecoded pagename.
1804 * Fixes sf.net bug #953949
1806 * src: languages/Language.php:checkTitleEncoding() from mediawiki
1808 function fixTitleEncoding( $s ) {
1813 if (empty($s)) return $s;
1815 $ishigh = preg_match( '/[\x80-\xff]/', $s);
1817 $isutf = ($ishigh ? preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
1818 '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s ) : true );
1820 $isutf = ($ishigh ? isUtf8String($s) : true);
1821 $locharset = strtolower($charset);
1823 if( $locharset != "utf-8" and $ishigh and $isutf )
1824 // if charset == 'iso-8859-1' then simply use utf8_decode()
1825 if ($locharset == 'iso-8859-1')
1826 return utf8_decode( $s );
1828 // TODO: check for iconv support
1829 return iconv( "UTF-8", $charset, $s );
1831 if ($locharset == "utf-8" and $ishigh and !$isutf )
1832 return utf8_encode( $s );
1834 // Other languages can safely leave this function, or replace
1835 // it with one to detect and convert another legacy encoding.
1840 * MySQL fulltext index doesn't grok utf-8, so we
1841 * need to fold cases and convert to hex.
1842 * src: languages/Language.php:stripForSearch() from mediawiki
1845 function stripForSearch( $string ) {
1846 global $wikiLowerChars;
1847 // '/(?:[a-z]|\xc3[\x9f-\xbf]|\xc4[\x81\x83\x85\x87])/' => "a-z\xdf-\xf6\xf8-\xff"
1848 return preg_replace(
1849 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
1850 "'U8' . bin2hex( strtr( \"\$1\", \$wikiLowerChars ) )",
1856 * Workaround for allow_url_fopen, to get the content of an external URI.
1857 * It returns the contents in one slurp. Parsers might want to check for allow_url_fopen
1858 * and use fopen, fread chunkwise. (see lib/XmlParser.php)
1860 function url_get_contents( $uri ) {
1861 if (get_cfg_var('allow_url_fopen')) { // was ini_get('allow_url_fopen'))
1862 return @file_get_contents($uri);
1864 require_once("lib/HttpClient.php");
1865 $bits = parse_url($uri);
1866 $host = $bits['host'];
1867 $port = isset($bits['port']) ? $bits['port'] : 80;
1868 $path = isset($bits['path']) ? $bits['path'] : '/';
1869 if (isset($bits['query'])) {
1870 $path .= '?'.$bits['query'];
1872 $client = new HttpClient($host, $port);
1873 $client->use_gzip = false;
1874 if (!$client->get($path)) {
1877 return $client->getContent();
1883 * Generate consecutively named strings:
1884 * Name, Name2, Name3, ...
1886 function GenerateId($name) {
1887 static $ids = array();
1888 if (empty($ids[$name])) {
1893 return $name . $ids[$name];
1897 // from IncludePage. To be of general use.
1898 // content: string or array of strings
1899 function firstNWordsOfContent( $n, $content ) {
1900 if ($content and $n > 0) {
1901 if (is_array($content)) {
1902 // fixme: return a list of lines then?
1903 //$content = join("\n", $content);
1904 //$return_array = true;
1906 foreach ($content as $line) {
1907 $words = explode(' ', $line);
1908 if ($wordcount + count($words) > $n) {
1909 $new[] = implode(' ', array_slice($words, 0, $n - $wordcount))
1910 . sprintf(_("... (first %s words)"), $n);
1913 $wordcount += count($words);
1919 // fixme: use better whitespace/word seperators
1920 $words = explode(' ', $content);
1921 if (count($words) > $n) {
1922 return join(' ', array_slice($words, 0, $n))
1923 . sprintf(_("... (first %s words)"), $n);
1933 // moved from lib/plugin/IncludePage.php
1934 function extractSection ($section, $content, $page, $quiet = false, $sectionhead = false) {
1935 $qsection = preg_replace('/\s+/', '\s+', preg_quote($section, '/'));
1937 if (preg_match("/ ^(!{1,})\\s*$qsection" // section header
1938 . " \\s*$\\n?" // possible blank lines
1939 . " ( (?: ^.*\\n? )*? )" // some lines
1940 . " (?= ^\\1 | \\Z)/xm", // sec header (same or higher level) (or EOF)
1941 implode("\n", $content),
1943 // Strip trailing blanks lines and ---- <hr>s
1944 $text = preg_replace("/\\s*^-{4,}\\s*$/m", "", $match[2]);
1946 $text = $match[1] . $section ."\n". $text;
1947 return explode("\n", $text);
1950 $mesg = $page ." ". $section;
1953 return array(sprintf(_("<%s: no such section>"), $mesg));
1956 // use this faster version: only load ExternalReferrer if we came from an external referrer
1957 function isExternalReferrer(&$request) {
1958 if ($referrer = $request->get('HTTP_REFERER')) {
1959 $home = SERVER_URL; // SERVER_URL or SCRIPT_NAME, if we want to check sister wiki's also
1960 if (string_starts_with(strtolower($referrer), strtolower($home))) return false;
1961 require_once("lib/ExternalReferrer.php");
1962 $se = new SearchEngines();
1963 return $se->parseSearchQuery($referrer);
1969 * Useful for PECL overrides: cvsclient, ldap, soap, xmlrpc, pdo, pdo_<driver>
1971 function loadPhpExtension($extension) {
1972 if (!extension_loaded($extension)) {
1973 $soname = (isWindows() ? 'php_' : '') . $extension . (isWindows() ? '.dll' : '.so');
1977 return extension_loaded($extension);
1980 function string_starts_with($string, $prefix) {
1981 return (substr($string, 0, strlen($prefix)) == $prefix);
1983 function string_ends_with($string, $suffix) {
1984 return (substr($string, -strlen($suffix)) == $suffix);
1988 * Ensure that the script will have another $secs time left.
1989 * Works only if safe_mode is off.
1990 * For example not to timeout on waiting socket connections.
1991 * Use the socket timeout as arg.
1993 function longer_timeout($secs = 30) {
1994 $timeout = @ini_get("max_execution_time") ? ini_get("max_execution_time") : 30;
1995 $timeleft = $timeout - $GLOBALS['RUNTIMER']->getTime();
1996 if ($timeleft < $secs)
1997 @set_time_limit(max($timeout,(integer)($secs + $timeleft)));
2000 function printSimpleTrace($bt) {
2002 echo "Traceback:\n";
2003 foreach ($bt as $i => $elem) {
2004 if (!array_key_exists('file', $elem)) {
2007 echo join(" ",array_values($elem)),"\n";
2008 //print " " . $elem['file'] . ':' . $elem['line'] . " " .$elem['function']"\n";
2013 * Return the used process memory (in byte?)
2014 * Enable the section which will work for you. (They are very slow)
2015 * Special quirks for Windows: Requires cygwin.
2017 function getMemoryUsage() {
2018 if (function_exists('memory_get_usage') and memory_get_usage()) {
2019 return memory_get_usage();
2020 } elseif (function_exists('getrusage') and ($u = getrusage()) and !empty($u['ru_maxrss'])) {
2021 $mem = $u['ru_maxrss'];
2022 } elseif (substr(PHP_OS,0,3) == 'WIN') { // requires a newer cygwin
2023 // what we want is the process memory only: apache or php
2026 // This works only if it's a cygwin process (apache or php)
2027 //$memstr = exec("cat /proc/$pid/statm |cut -f1");
2029 // if it's native windows use something like this:
2030 // (requires pslist from sysinternals.com)
2031 //$memstr = exec("pslist $pid|grep -A1 Mem|sed 1d|perl -ane\"print \$"."F[5]\"");
2032 return (integer) trim($memstr);
2035 //%MEM: Percentage of total memory in use by this process
2036 //VSZ: Total virtual memory size, in 1K blocks.
2037 //RSS: Real Set Size, the actual amount of physical memory allocated to this process.
2038 //CPU time used by process since it started.
2039 //echo "%",`ps -o%mem,vsz,rss,time -p $pid|sed 1d`,"\n";
2040 $memstr = exec("ps -orss -p $pid|sed 1d");
2041 return (integer) trim($memstr);
2045 // $Log: not supported by cvs2svn $
2046 // Revision 1.244 2005/09/11 13:24:33 rurban
2047 // fix shortname, dont quote twice in ListRegexExpand
2049 // Revision 1.243 2005/08/06 15:01:38 rurban
2050 // workaround php VBASIC alike limitation: allow integer pagenames
2052 // Revision 1.242 2005/08/06 13:07:04 rurban
2053 // quote paths correctly (not the best method though)
2055 // Revision 1.241 2005/05/06 16:54:19 rurban
2056 // support optional EXTERNAL_LINK_TARGET, default: _blank
2058 // Revision 1.240 2005/04/23 11:15:49 rurban
2059 // handle allowed inlined objects within INLINE_IMAGES
2061 // Revision 1.239 2005/04/01 16:11:42 rurban
2064 // Revision 1.238 2005/03/04 16:29:14 rurban
2065 // Fixed bug #994994 (escape / in glob)
2066 // Optimized glob_to_pcre within fileSet() matching.
2068 // Revision 1.237 2005/02/12 17:22:18 rurban
2069 // locale update: missing . : fixed. unified strings
2070 // proper linebreaks
2072 // Revision 1.236 2005/02/08 13:41:32 rurban
2075 // Revision 1.235 2005/02/04 11:54:48 rurban
2078 // Revision 1.234 2005/02/03 05:09:25 rurban
2079 // Talk: + User: fix
2081 // Revision 1.233 2005/02/02 20:40:12 rurban
2082 // fix Talk: and User: names and links
2084 // Revision 1.232 2005/02/02 19:34:09 rurban
2085 // more maps: Talk, User
2087 // Revision 1.231 2005/01/30 19:48:52 rurban
2088 // enable ps memory on unix
2090 // Revision 1.230 2005/01/25 07:10:51 rurban
2091 // add getMemoryUsage to stdlib
2093 // Revision 1.229 2005/01/21 11:51:22 rurban
2096 // Revision 1.228 2005/01/17 20:28:30 rurban
2097 // Allow more pagename chars: Limit only on certain backends.
2098 // Re-Allow : and ; and control chars on non-file backends.
2100 // Revision 1.227 2005/01/14 18:32:08 uckelman
2101 // ConvertOldMarkup did not properly handle links containing pairs of pairs
2102 // of underscores. (E.g., [http://example.com/foo__bar__.html] would be
2103 // munged by the regex for bold text.) Now '__' in links are hidden prior to
2104 // conversion of '__' into '<strong>', and then unhidden afterwards.
2106 // Revision 1.226 2004/12/26 17:12:06 rurban
2107 // avoid stdargs in url, php5 fixes
2109 // Revision 1.225 2004/12/22 19:02:29 rurban
2110 // fix glob for starting * or ?
2112 // Revision 1.224 2004/12/20 12:11:50 rurban
2113 // fix "lib/stdlib.php:1348: Warning[2]: Compilation failed: unmatched parentheses at offset 2"
2114 // not reproducable other than on sf.net, but this seems to fix it.
2116 // Revision 1.223 2004/12/18 16:49:29 rurban
2117 // fix RPC for !USE_PATH_INFO, add debugging helper
2119 // Revision 1.222 2004/12/17 16:40:45 rurban
2120 // add not yet used url helper
2122 // Revision 1.221 2004/12/06 19:49:58 rurban
2123 // enable action=remove which is undoable and seeable in RecentChanges: ADODB ony for now.
2124 // renamed delete_page to purge_page.
2125 // enable action=edit&version=-1 to force creation of a new version.
2126 // added BABYCART_PATH config
2127 // fixed magiqc in adodb.inc.php
2128 // and some more docs
2130 // Revision 1.220 2004/11/30 17:47:41 rurban
2131 // added mt_srand, check for native isa
2133 // Revision 1.219 2004/11/26 18:39:02 rurban
2134 // new regex search parser and SQL backends (90% complete, glob and pcre backends missing)
2136 // Revision 1.218 2004/11/25 08:28:48 rurban
2139 // Revision 1.217 2004/11/16 17:31:03 rurban
2140 // re-enable old block markup conversion
2142 // Revision 1.216 2004/11/11 18:31:26 rurban
2143 // add simple backtrace on such general failures to get at least an idea where
2145 // Revision 1.215 2004/11/11 14:34:12 rurban
2146 // minor clarifications
2148 // Revision 1.214 2004/11/11 11:01:20 rurban
2149 // fix loadPhpExtension
2151 // Revision 1.213 2004/11/01 10:43:57 rurban
2152 // seperate PassUser methods into seperate dir (memory usage)
2153 // fix WikiUser (old) overlarge data session
2154 // remove wikidb arg from various page class methods, use global ->_dbi instead
2157 // Revision 1.212 2004/10/22 09:15:39 rurban
2158 // Alert::show has no arg anymore
2160 // Revision 1.211 2004/10/22 09:05:11 rurban
2161 // added longer_timeout (HttpClient)
2164 // Revision 1.210 2004/10/14 21:06:02 rurban
2165 // fix dumphtml with USE_PATH_INFO (again). fix some PageList refs
2167 // Revision 1.209 2004/10/14 19:19:34 rurban
2168 // loadsave: check if the dumped file will be accessible from outside.
2169 // and some other minor fixes. (cvsclient native not yet ready)
2171 // Revision 1.208 2004/10/12 13:13:20 rurban
2172 // php5 compatibility (5.0.1 ok)
2174 // Revision 1.207 2004/09/26 12:21:40 rurban
2175 // removed old log entries.
2176 // added persistent start_debug on internal links and DEBUG
2177 // added isExternalReferrer (not yet used)
2179 // Revision 1.206 2004/09/25 16:28:36 rurban
2180 // added to TOC, firstNWordsOfContent is now plugin compatible, added extractSection
2182 // Revision 1.205 2004/09/23 13:59:35 rurban
2183 // Before removing a page display a sample of 100 words.
2185 // Revision 1.204 2004/09/17 13:19:15 rurban
2186 // fix LinkPhpwikiURL bug reported in http://phpwiki.sourceforge.net/phpwiki/KnownBugs
2189 // Revision 1.203 2004/09/16 08:00:52 rurban
2190 // just some comments
2192 // Revision 1.202 2004/09/14 10:11:44 rurban
2193 // start 2nd Id with ...Plugin2
2195 // Revision 1.201 2004/09/14 10:06:42 rurban
2196 // generate iterated plugin ids, set plugin span id also
2198 // Revision 1.200 2004/08/05 17:34:26 rurban
2199 // move require to sortby branch
2201 // Revision 1.199 2004/08/05 10:38:15 rurban
2202 // fix Bug #993692: Making Snapshots or Backups doesn't work anymore
2205 // Revision 1.198 2004/07/02 10:30:36 rurban
2206 // always disable getimagesize for < php-4.3 with external png's
2208 // Revision 1.197 2004/07/02 09:55:58 rurban
2209 // more stability fixes: new DISABLE_GETIMAGESIZE if your php crashes when loading LinkIcons: failing getimagesize in old phps; blockparser stabilized
2211 // Revision 1.196 2004/07/01 08:51:22 rurban
2212 // dumphtml: added exclude, print pagename before processing
2214 // Revision 1.195 2004/06/29 08:52:22 rurban
2215 // Use ...version() $need_content argument in WikiDB also:
2216 // To reduce the memory footprint for larger sets of pagelists,
2217 // we don't cache the content (only true or false) and
2218 // we purge the pagedata (_cached_html) also.
2219 // _cached_html is only cached for the current pagename.
2220 // => Vastly improved page existance check, ACL check, ...
2222 // Now only PagedList info=content or size needs the whole content, esp. if sortable.
2224 // Revision 1.194 2004/06/29 06:48:04 rurban
2225 // Improve LDAP auth and GROUP_LDAP membership:
2226 // no error message on false password,
2227 // added two new config vars: LDAP_OU_USERS and LDAP_OU_GROUP with GROUP_METHOD=LDAP
2228 // fixed two group queries (this -> user)
2229 // stdlib: ConvertOldMarkup still flawed
2231 // Revision 1.193 2004/06/28 13:27:03 rurban
2232 // CreateToc disabled for old markup and Apache2 only
2234 // Revision 1.192 2004/06/28 12:47:43 rurban
2235 // skip if non-DEBUG and old markup with CreateToc
2237 // Revision 1.191 2004/06/25 14:31:56 rurban
2238 // avoid debug_skip warning
2240 // Revision 1.190 2004/06/25 14:29:20 rurban
2241 // WikiGroup refactoring:
2242 // global group attached to user, code for not_current user.
2243 // improved helpers for special groups (avoid double invocations)
2244 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
2245 // fixed a XHTML validation error on userprefs.tmpl
2247 // Revision 1.189 2004/06/20 09:45:35 rurban
2248 // php5 isa fix (wrong strtolower)
2250 // Revision 1.188 2004/06/16 10:38:58 rurban
2251 // Disallow refernces in calls if the declaration is a reference
2252 // ("allow_call_time_pass_reference clean").
2253 // PhpWiki is now allow_call_time_pass_reference = Off clean,
2254 // but several external libraries may not.
2255 // In detail these libs look to be affected (not tested):
2259 // Revision 1.187 2004/06/14 11:31:37 rurban
2260 // renamed global $Theme to $WikiTheme (gforge nameclash)
2261 // inherit PageList default options from PageList
2262 // default sortby=pagename
2263 // use options in PageList_Selectable (limit, sortby, ...)
2264 // added action revert, with button at action=diff
2265 // added option regex to WikiAdminSearchReplace
2267 // Revision 1.186 2004/06/13 13:54:25 rurban
2268 // Catch fatals on the four dump calls (as file and zip, as html and mimified)
2269 // FoafViewer: Check against external requirements, instead of fatal.
2270 // Change output for xhtmldumps: using file:// urls to the local fs.
2271 // Catch SOAP fatal by checking for GOOGLE_LICENSE_KEY
2272 // Import GOOGLE_LICENSE_KEY and FORTUNE_DIR from config.ini.
2274 // Revision 1.185 2004/06/11 09:07:30 rurban
2275 // support theme-specific LinkIconAttr: front or after or none
2277 // Revision 1.184 2004/06/04 20:32:53 rurban
2278 // Several locale related improvements suggested by Pierrick Meignen
2279 // LDAP fix by John Cole
2280 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
2282 // Revision 1.183 2004/06/01 10:22:56 rurban
2283 // added url_get_contents() used in XmlParser and elsewhere
2285 // Revision 1.182 2004/05/25 12:40:48 rurban
2286 // trim the pagename
2288 // Revision 1.181 2004/05/25 10:18:44 rurban
2289 // Check for UTF-8 URLs; Internet Explorer produces these if you
2290 // type non-ASCII chars in the URL bar or follow unescaped links.
2291 // Fixes sf.net bug #953949
2292 // src: languages/Language.php:checkTitleEncoding() from mediawiki
2294 // Revision 1.180 2004/05/18 16:23:39 rurban
2295 // rename split_pagename to SplitPagename
2297 // Revision 1.179 2004/05/18 16:18:37 rurban
2298 // AutoSplit at subpage seperators
2299 // RssFeed stability fix for empty feeds or broken connections
2301 // Revision 1.178 2004/05/12 10:49:55 rurban
2302 // require_once fix for those libs which are loaded before FileFinder and
2303 // its automatic include_path fix, and where require_once doesn't grok
2304 // dirname(__FILE__) != './lib'
2305 // upgrade fix with PearDB
2306 // navbar.tmpl: remove spaces for IE button alignment
2308 // Revision 1.177 2004/05/08 14:06:12 rurban
2309 // new support for inlined image attributes: [image.jpg size=50x30 align=right]
2310 // minor stability and portability fixes
2312 // Revision 1.176 2004/05/08 11:25:15 rurban
2315 // Revision 1.175 2004/05/06 17:30:38 rurban
2316 // CategoryGroup: oops, dos2unix eol
2317 // improved phpwiki_version:
2318 // pre -= .0001 (1.3.10pre: 1030.099)
2319 // -p1 += .001 (1.3.9-p1: 1030.091)
2320 // improved InstallTable for mysql and generic SQL versions and all newer tables so far.
2321 // abstracted more ADODB/PearDB methods for action=upgrade stuff:
2322 // backend->backendType(), backend->database(),
2323 // backend->listOfFields(),
2324 // backend->listOfTables(),
2326 // Revision 1.174 2004/05/06 12:02:05 rurban
2327 // fix sf.net bug#949002: [ Link | ] assertion
2329 // Revision 1.173 2004/05/03 15:00:31 rurban
2330 // added more database upgrading: session.sess_ip, page.id autp_increment
2332 // Revision 1.172 2004/04/26 20:44:34 rurban
2333 // locking table specific for better databases
2335 // Revision 1.171 2004/04/19 23:13:03 zorloc
2336 // Connect the rest of PhpWiki to the IniConfig system. Also the keyword regular expression is not a config setting
2338 // Revision 1.170 2004/04/19 18:27:45 rurban
2339 // Prevent from some PHP5 warnings (ref args, no :: object init)
2340 // php5 runs now through, just one wrong XmlElement object init missing
2341 // Removed unneccesary UpgradeUser lines
2342 // Changed WikiLink to omit version if current (RecentChanges)
2344 // Revision 1.169 2004/04/15 21:29:48 rurban
2345 // allow [0] with new markup: link to page "0"
2347 // Revision 1.168 2004/04/10 02:30:49 rurban
2348 // Fixed gettext problem with VIRTUAL_PATH scripts (Windows only probably)
2349 // Fixed "cannot setlocale..." (sf.net problem)
2351 // Revision 1.167 2004/04/02 15:06:55 rurban
2352 // fixed a nasty ADODB_mysql session update bug
2353 // improved UserPreferences layout (tabled hints)
2354 // fixed UserPreferences auth handling
2355 // improved auth stability
2356 // improved old cookie handling: fixed deletion of old cookies with paths
2358 // Revision 1.166 2004/04/01 15:57:10 rurban
2359 // simplified Sidebar theme: table, not absolute css positioning
2360 // added the new box methods.
2361 // remaining problems: large left margin, how to override _autosplitWikiWords in Template only
2363 // Revision 1.165 2004/03/24 19:39:03 rurban
2364 // php5 workaround code (plus some interim debugging code in XmlElement)
2365 // php5 doesn't work yet with the current XmlElement class constructors,
2366 // WikiUserNew does work better than php4.
2367 // rewrote WikiUserNew user upgrading to ease php5 update
2368 // fixed pref handling in WikiUserNew
2369 // added Email Notification
2370 // added simple Email verification
2371 // removed emailVerify userpref subclass: just a email property
2372 // changed pref binary storage layout: numarray => hash of non default values
2373 // print optimize message only if really done.
2374 // forced new cookie policy: delete pref cookies, use only WIKI_ID as plain string.
2375 // prefs should be stored in db or homepage, besides the current session.
2377 // Revision 1.164 2004/03/18 21:41:09 rurban
2378 // fixed sqlite support
2379 // WikiUserNew: PHP5 fixes: don't assign $this (untested)
2381 // Revision 1.163 2004/03/17 18:41:49 rurban
2382 // just reformatting
2384 // Revision 1.162 2004/03/16 15:43:08 rurban
2385 // make fileSet sortable to please PageList
2387 // Revision 1.161 2004/03/12 15:48:07 rurban
2388 // fixed explodePageList: wrong sortby argument order in UnfoldSubpages
2389 // simplified lib/stdlib.php:explodePageList
2391 // Revision 1.160 2004/02/28 21:14:08 rurban
2392 // generally more PHPDOC docs
2393 // see http://xarch.tu-graz.ac.at/home/rurban/phpwiki/xref/
2394 // fxied WikiUserNew pref handling: empty theme not stored, save only
2395 // changed prefs, sql prefs improved, fixed password update,
2396 // removed REPLACE sql (dangerous)
2397 // moved gettext init after the locale was guessed
2398 // + some minor changes
2401 // (c-file-style: "gnu")
2405 // c-basic-offset: 4
2406 // c-hanging-comment-ender-p: nil
2407 // indent-tabs-mode: nil