PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/gforge/plugins/wiki/www/lib/stdlib.php

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