PageRenderTime 67ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/neymanna/fusionforge
PHP | 2638 lines | 1285 code | 175 blank | 1178 comment | 253 complexity | 65dd65c437575b0f1b41bac0d39117be MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception
  1. <?php //-*-php-*-
  2. rcs_id('$Id: WikiDB.php,v 1.135 2005/09/11 14:19:44 rurban Exp $');
  3. require_once('lib/PageType.php');
  4. /**
  5. * The classes in the file define the interface to the
  6. * page database.
  7. *
  8. * @package WikiDB
  9. * @author Geoffrey T. Dairiki <dairiki@dairiki.org>
  10. * Reini Urban
  11. */
  12. /**
  13. * Force the creation of a new revision.
  14. * @see WikiDB_Page::createRevision()
  15. */
  16. if (!defined('WIKIDB_FORCE_CREATE'))
  17. define('WIKIDB_FORCE_CREATE', -1);
  18. /**
  19. * Abstract base class for the database used by PhpWiki.
  20. *
  21. * A <tt>WikiDB</tt> is a container for <tt>WikiDB_Page</tt>s which in
  22. * turn contain <tt>WikiDB_PageRevision</tt>s.
  23. *
  24. * Conceptually a <tt>WikiDB</tt> contains all possible
  25. * <tt>WikiDB_Page</tt>s, whether they have been initialized or not.
  26. * Since all possible pages are already contained in a WikiDB, a call
  27. * to WikiDB::getPage() will never fail (barring bugs and
  28. * e.g. filesystem or SQL database problems.)
  29. *
  30. * Also each <tt>WikiDB_Page</tt> always contains at least one
  31. * <tt>WikiDB_PageRevision</tt>: the default content (e.g. "Describe
  32. * [PageName] here."). This default content has a version number of
  33. * zero.
  34. *
  35. * <tt>WikiDB_PageRevision</tt>s have read-only semantics. One can
  36. * only create new revisions or delete old ones --- one can not modify
  37. * an existing revision.
  38. */
  39. class WikiDB {
  40. /**
  41. * Open a WikiDB database.
  42. *
  43. * This is a static member function. This function inspects its
  44. * arguments to determine the proper subclass of WikiDB to
  45. * instantiate, and then it instantiates it.
  46. *
  47. * @access public
  48. *
  49. * @param hash $dbparams Database configuration parameters.
  50. * Some pertinent paramters are:
  51. * <dl>
  52. * <dt> dbtype
  53. * <dd> The back-end type. Current supported types are:
  54. * <dl>
  55. * <dt> SQL
  56. * <dd> Generic SQL backend based on the PEAR/DB database abstraction
  57. * library. (More stable and conservative)
  58. * <dt> ADODB
  59. * <dd> Another generic SQL backend. (More current features are tested here. Much faster)
  60. * <dt> dba
  61. * <dd> Dba based backend. The default and by far the fastest.
  62. * <dt> cvs
  63. * <dd>
  64. * <dt> file
  65. * <dd> flat files
  66. * </dl>
  67. *
  68. * <dt> dsn
  69. * <dd> (Used by the SQL and ADODB backends.)
  70. * The DSN specifying which database to connect to.
  71. *
  72. * <dt> prefix
  73. * <dd> Prefix to be prepended to database tables (and file names).
  74. *
  75. * <dt> directory
  76. * <dd> (Used by the dba backend.)
  77. * Which directory db files reside in.
  78. *
  79. * <dt> timeout
  80. * <dd> Used only by the dba backend so far.
  81. * And: When optimizing mysql it closes timed out mysql processes.
  82. * otherwise only used for dba: Timeout in seconds for opening (and
  83. * obtaining lock) on the dbm file.
  84. *
  85. * <dt> dba_handler
  86. * <dd> (Used by the dba backend.)
  87. *
  88. * Which dba handler to use. Good choices are probably either
  89. * 'gdbm' or 'db2'.
  90. * </dl>
  91. *
  92. * @return WikiDB A WikiDB object.
  93. **/
  94. function open ($dbparams) {
  95. $dbtype = $dbparams{'dbtype'};
  96. include_once("lib/WikiDB/$dbtype.php");
  97. $class = 'WikiDB_' . $dbtype;
  98. return new $class ($dbparams);
  99. }
  100. /**
  101. * Constructor.
  102. *
  103. * @access private
  104. * @see open()
  105. */
  106. function WikiDB (&$backend, $dbparams) {
  107. $this->_backend = &$backend;
  108. // don't do the following with the auth_dsn!
  109. if (isset($dbparams['auth_dsn'])) return;
  110. $this->_cache = new WikiDB_cache($backend);
  111. if (!empty($GLOBALS['request'])) $GLOBALS['request']->_dbi = $this;
  112. // If the database doesn't yet have a timestamp, initialize it now.
  113. if ($this->get('_timestamp') === false)
  114. $this->touch();
  115. //FIXME: devel checking.
  116. //$this->_backend->check();
  117. }
  118. /**
  119. * Close database connection.
  120. *
  121. * The database may no longer be used after it is closed.
  122. *
  123. * Closing a WikiDB invalidates all <tt>WikiDB_Page</tt>s,
  124. * <tt>WikiDB_PageRevision</tt>s and <tt>WikiDB_PageIterator</tt>s
  125. * which have been obtained from it.
  126. *
  127. * @access public
  128. */
  129. function close () {
  130. $this->_backend->close();
  131. $this->_cache->close();
  132. }
  133. /**
  134. * Get a WikiDB_Page from a WikiDB.
  135. *
  136. * A {@link WikiDB} consists of the (infinite) set of all possible pages,
  137. * therefore this method never fails.
  138. *
  139. * @access public
  140. * @param string $pagename Which page to get.
  141. * @return WikiDB_Page The requested WikiDB_Page.
  142. */
  143. function getPage($pagename) {
  144. static $error_displayed = false;
  145. $pagename = (string) $pagename;
  146. if (DEBUG) {
  147. if ($pagename === '') {
  148. if ($error_displayed) return false;
  149. $error_displayed = true;
  150. if (function_exists("xdebug_get_function_stack"))
  151. var_dump(xdebug_get_function_stack());
  152. trigger_error("empty pagename", E_USER_WARNING);
  153. return false;
  154. }
  155. } else {
  156. assert($pagename != '');
  157. }
  158. return new WikiDB_Page($this, $pagename);
  159. }
  160. /**
  161. * Determine whether page exists (in non-default form).
  162. *
  163. * <pre>
  164. * $is_page = $dbi->isWikiPage($pagename);
  165. * </pre>
  166. * is equivalent to
  167. * <pre>
  168. * $page = $dbi->getPage($pagename);
  169. * $current = $page->getCurrentRevision();
  170. * $is_page = ! $current->hasDefaultContents();
  171. * </pre>
  172. * however isWikiPage may be implemented in a more efficient
  173. * manner in certain back-ends.
  174. *
  175. * @access public
  176. *
  177. * @param string $pagename string Which page to check.
  178. *
  179. * @return boolean True if the page actually exists with
  180. * non-default contents in the WikiDataBase.
  181. */
  182. function isWikiPage ($pagename) {
  183. $page = $this->getPage($pagename);
  184. return $page->exists();
  185. }
  186. /**
  187. * Delete page from the WikiDB.
  188. *
  189. * Deletes the page from the WikiDB with the possibility to revert and diff.
  190. * //Also resets all page meta-data to the default values.
  191. *
  192. * Note: purgePage() effectively destroys all revisions of the page from the WikiDB.
  193. *
  194. * @access public
  195. *
  196. * @param string $pagename Name of page to delete.
  197. */
  198. function deletePage($pagename) {
  199. // don't create empty revisions of already purged pages.
  200. if ($this->_backend->get_latest_version($pagename))
  201. $result = $this->_cache->delete_page($pagename);
  202. else
  203. $result = -1;
  204. /* Generate notification emails? */
  205. if (! $this->isWikiPage($pagename) and !isa($GLOBALS['request'],'MockRequest')) {
  206. $notify = $this->get('notify');
  207. if (!empty($notify) and is_array($notify)) {
  208. global $request;
  209. //TODO: deferr it (quite a massive load if you remove some pages).
  210. //TODO: notification class which catches all changes,
  211. // and decides at the end of the request what to mail.
  212. // (type, page, who, what, users, emails)
  213. // could be used for PageModeration and RSS2 Cloud xml-rpc also.
  214. $page = new WikiDB_Page($this, $pagename);
  215. list($emails, $userids) = $page->getPageChangeEmails($notify);
  216. if (!empty($emails)) {
  217. $from = $request->_user->getId();
  218. $editedby = sprintf(_("Removed by: %s"), $from);
  219. $emails = join(',', $emails);
  220. $headers = "From: $from <nobody>\r\n" .
  221. "Bcc: $emails\r\n" .
  222. "MIME-Version: 1.0\r\n" .
  223. "Content-Type: text/plain; charset=".CHARSET."; format=flowed\r\n" .
  224. "Content-Transfer-Encoding: 8bit";
  225. $subject = sprintf(_("Page removed %s"), urlencode($pagename));
  226. if (mail("<undisclosed-recipients>","[".WIKI_NAME."] ".$subject,
  227. $subject."\n".
  228. $editedby."\n\n".
  229. "Deleted $pagename",
  230. $headers))
  231. trigger_error(sprintf(_("PageChange Notification of %s sent to %s"),
  232. $pagename, join(',',$userids)), E_USER_NOTICE);
  233. else
  234. trigger_error(sprintf(_("PageChange Notification Error: Couldn't send %s to %s"),
  235. $pagename, join(',',$userids)), E_USER_WARNING);
  236. }
  237. }
  238. }
  239. //How to create a RecentChanges entry with explaining summary? Dynamically
  240. /*
  241. $page = $this->getPage($pagename);
  242. $current = $page->getCurrentRevision();
  243. $meta = $current->_data;
  244. $version = $current->getVersion();
  245. $meta['summary'] = _("removed");
  246. $page->save($current->getPackedContent(), $version + 1, $meta);
  247. */
  248. return $result;
  249. }
  250. /**
  251. * Completely remove the page from the WikiDB, without undo possibility.
  252. */
  253. function purgePage($pagename) {
  254. $result = $this->_cache->purge_page($pagename);
  255. $this->deletePage($pagename); // just for the notification
  256. return $result;
  257. }
  258. /**
  259. * Retrieve all pages.
  260. *
  261. * Gets the set of all pages with non-default contents.
  262. *
  263. * @access public
  264. *
  265. * @param boolean $include_defaulted Normally pages whose most
  266. * recent revision has empty content are considered to be
  267. * non-existant. Unless $include_defaulted is set to true, those
  268. * pages will not be returned.
  269. *
  270. * @return WikiDB_PageIterator A WikiDB_PageIterator which contains all pages
  271. * in the WikiDB which have non-default contents.
  272. */
  273. function getAllPages($include_empty=false, $sortby=false, $limit=false,
  274. $exclude=false)
  275. {
  276. // HACK: memory_limit=8M will fail on too large pagesets. old php on unix only!
  277. if (USECACHE) {
  278. $mem = ini_get("memory_limit");
  279. if ($mem and !$limit and !isWindows() and !check_php_version(4,3)) {
  280. $limit = 450;
  281. $GLOBALS['request']->setArg('limit', $limit);
  282. $GLOBALS['request']->setArg('paging', 'auto');
  283. }
  284. }
  285. $result = $this->_backend->get_all_pages($include_empty, $sortby, $limit,
  286. $exclude);
  287. return new WikiDB_PageIterator($this, $result,
  288. array('include_empty' => $include_empty,
  289. 'exclude' => $exclude,
  290. 'limit' => $limit));
  291. }
  292. /**
  293. * $include_empty = true: include also empty pages
  294. * exclude: comma-seperated list pagenames: TBD: array of pagenames
  295. */
  296. function numPages($include_empty=false, $exclude='') {
  297. if (method_exists($this->_backend, 'numPages'))
  298. // FIXME: currently are all args ignored.
  299. $count = $this->_backend->numPages($include_empty, $exclude);
  300. else {
  301. // FIXME: exclude ignored.
  302. $iter = $this->getAllPages($include_empty, false, false, $exclude);
  303. $count = $iter->count();
  304. $iter->free();
  305. }
  306. return (int)$count;
  307. }
  308. /**
  309. * Title search.
  310. *
  311. * Search for pages containing (or not containing) certain words
  312. * in their names.
  313. *
  314. * Pages are returned in alphabetical order whenever it is
  315. * practical to do so.
  316. *
  317. * FIXME: clarify $search syntax. provide glob=>TextSearchQuery converters
  318. *
  319. * @access public
  320. * @param TextSearchQuery $search A TextSearchQuery object
  321. * @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching pages.
  322. * @see TextSearchQuery
  323. */
  324. function titleSearch($search, $sortby='pagename', $limit=false, $exclude=false) {
  325. $result = $this->_backend->text_search($search, false, $sortby, $limit, $exclude);
  326. return new WikiDB_PageIterator($this, $result,
  327. array('exclude' => $exclude,
  328. 'limit' => $limit));
  329. }
  330. /**
  331. * Full text search.
  332. *
  333. * Search for pages containing (or not containing) certain words
  334. * in their entire text (this includes the page content and the
  335. * page name).
  336. *
  337. * Pages are returned in alphabetical order whenever it is
  338. * practical to do so.
  339. *
  340. * @access public
  341. *
  342. * @param TextSearchQuery $search A TextSearchQuery object.
  343. * @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching pages.
  344. * @see TextSearchQuery
  345. */
  346. function fullSearch($search, $sortby='pagename', $limit=false, $exclude=false) {
  347. $result = $this->_backend->text_search($search, true, $sortby, $limit, $exclude);
  348. return new WikiDB_PageIterator($this, $result,
  349. array('exclude' => $exclude,
  350. 'limit' => $limit,
  351. 'stoplisted' => $result->stoplisted
  352. ));
  353. }
  354. /**
  355. * Find the pages with the greatest hit counts.
  356. *
  357. * Pages are returned in reverse order by hit count.
  358. *
  359. * @access public
  360. *
  361. * @param integer $limit The maximum number of pages to return.
  362. * Set $limit to zero to return all pages. If $limit < 0, pages will
  363. * be sorted in decreasing order of popularity.
  364. *
  365. * @return WikiDB_PageIterator A WikiDB_PageIterator containing the matching
  366. * pages.
  367. */
  368. function mostPopular($limit = 20, $sortby = '-hits') {
  369. $result = $this->_backend->most_popular($limit, $sortby);
  370. return new WikiDB_PageIterator($this, $result);
  371. }
  372. /**
  373. * Find recent page revisions.
  374. *
  375. * Revisions are returned in reverse order by creation time.
  376. *
  377. * @access public
  378. *
  379. * @param hash $params This hash is used to specify various optional
  380. * parameters:
  381. * <dl>
  382. * <dt> limit
  383. * <dd> (integer) At most this many revisions will be returned.
  384. * <dt> since
  385. * <dd> (integer) Only revisions since this time (unix-timestamp) will be returned.
  386. * <dt> include_minor_revisions
  387. * <dd> (boolean) Also include minor revisions. (Default is not to.)
  388. * <dt> exclude_major_revisions
  389. * <dd> (boolean) Don't include non-minor revisions.
  390. * (Exclude_major_revisions implies include_minor_revisions.)
  391. * <dt> include_all_revisions
  392. * <dd> (boolean) Return all matching revisions for each page.
  393. * Normally only the most recent matching revision is returned
  394. * for each page.
  395. * </dl>
  396. *
  397. * @return WikiDB_PageRevisionIterator A WikiDB_PageRevisionIterator containing the
  398. * matching revisions.
  399. */
  400. function mostRecent($params = false) {
  401. $result = $this->_backend->most_recent($params);
  402. return new WikiDB_PageRevisionIterator($this, $result);
  403. }
  404. /**
  405. * @access public
  406. *
  407. * @return Iterator A generic iterator containing rows of (duplicate) pagename, wantedfrom.
  408. */
  409. function wantedPages($exclude_from='', $exclude='', $sortby=false, $limit=false) {
  410. return $this->_backend->wanted_pages($exclude_from, $exclude, $sortby, $limit);
  411. //return new WikiDB_PageIterator($this, $result);
  412. }
  413. /**
  414. * Call the appropriate backend method.
  415. *
  416. * @access public
  417. * @param string $from Page to rename
  418. * @param string $to New name
  419. * @param boolean $updateWikiLinks If the text in all pages should be replaced.
  420. * @return boolean true or false
  421. */
  422. function renamePage($from, $to, $updateWikiLinks = false) {
  423. assert(is_string($from) && $from != '');
  424. assert(is_string($to) && $to != '');
  425. $result = false;
  426. if (method_exists($this->_backend, 'rename_page')) {
  427. $oldpage = $this->getPage($from);
  428. $newpage = $this->getPage($to);
  429. //update all WikiLinks in existing pages
  430. //non-atomic! i.e. if rename fails the links are not undone
  431. if ($updateWikiLinks) {
  432. require_once('lib/plugin/WikiAdminSearchReplace.php');
  433. $links = $oldpage->getBackLinks();
  434. while ($linked_page = $links->next()) {
  435. WikiPlugin_WikiAdminSearchReplace::replaceHelper($this,
  436. $linked_page->getName(),
  437. $from, $to);
  438. }
  439. // ape: Disabled to avoid recursive modification when renaming
  440. // a page like 'PageApe' to 'PageApeTwo'.
  441. //
  442. // $links = $newpage->getBackLinks();
  443. // while ($linked_page = $links->next()) {
  444. // WikiPlugin_WikiAdminSearchReplace::replaceHelper($this,
  445. // $linked_page->getName(),
  446. // $from, $to);
  447. // }
  448. }
  449. if ($oldpage->exists() and ! $newpage->exists()) {
  450. if ($result = $this->_backend->rename_page($from, $to)) {
  451. //create a RecentChanges entry with explaining summary
  452. $page = $this->getPage($to);
  453. $current = $page->getCurrentRevision();
  454. $meta = $current->_data;
  455. $version = $current->getVersion();
  456. $meta['summary'] = sprintf(_("renamed from %s"), $from);
  457. $page->save($current->getPackedContent(), $version + 1, $meta);
  458. }
  459. } elseif (!$oldpage->getCurrentRevision(false) and !$newpage->exists()) {
  460. // if a version 0 exists try it also.
  461. $result = $this->_backend->rename_page($from, $to);
  462. }
  463. } else {
  464. trigger_error(_("WikiDB::renamePage() not yet implemented for this backend"),
  465. E_USER_WARNING);
  466. }
  467. /* Generate notification emails? */
  468. if ($result and !isa($GLOBALS['request'], 'MockRequest')) {
  469. $notify = $this->get('notify');
  470. if (!empty($notify) and is_array($notify)) {
  471. list($emails, $userids) = $oldpage->getPageChangeEmails($notify);
  472. if (!empty($emails)) {
  473. $oldpage->sendPageRenameNotification($to, $meta, $emails, $userids);
  474. }
  475. }
  476. }
  477. return $result;
  478. }
  479. /** Get timestamp when database was last modified.
  480. *
  481. * @return string A string consisting of two integers,
  482. * separated by a space. The first is the time in
  483. * unix timestamp format, the second is a modification
  484. * count for the database.
  485. *
  486. * The idea is that you can cast the return value to an
  487. * int to get a timestamp, or you can use the string value
  488. * as a good hash for the entire database.
  489. */
  490. function getTimestamp() {
  491. $ts = $this->get('_timestamp');
  492. return sprintf("%d %d", $ts[0], $ts[1]);
  493. }
  494. /**
  495. * Update the database timestamp.
  496. *
  497. */
  498. function touch() {
  499. $ts = $this->get('_timestamp');
  500. $this->set('_timestamp', array(time(), $ts[1] + 1));
  501. }
  502. /**
  503. * Access WikiDB global meta-data.
  504. *
  505. * NOTE: this is currently implemented in a hackish and
  506. * not very efficient manner.
  507. *
  508. * @access public
  509. *
  510. * @param string $key Which meta data to get.
  511. * Some reserved meta-data keys are:
  512. * <dl>
  513. * <dt>'_timestamp' <dd> Data used by getTimestamp().
  514. * </dl>
  515. *
  516. * @return scalar The requested value, or false if the requested data
  517. * is not set.
  518. */
  519. function get($key) {
  520. if (!$key || $key[0] == '%')
  521. return false;
  522. /*
  523. * Hack Alert: We can use any page (existing or not) to store
  524. * this data (as long as we always use the same one.)
  525. */
  526. $gd = $this->getPage('global_data');
  527. $data = $gd->get('__global');
  528. if ($data && isset($data[$key]))
  529. return $data[$key];
  530. else
  531. return false;
  532. }
  533. /**
  534. * Set global meta-data.
  535. *
  536. * NOTE: this is currently implemented in a hackish and
  537. * not very efficient manner.
  538. *
  539. * @see get
  540. * @access public
  541. *
  542. * @param string $key Meta-data key to set.
  543. * @param string $newval New value.
  544. */
  545. function set($key, $newval) {
  546. if (!$key || $key[0] == '%')
  547. return;
  548. $gd = $this->getPage('global_data');
  549. $data = $gd->get('__global');
  550. if ($data === false)
  551. $data = array();
  552. if (empty($newval))
  553. unset($data[$key]);
  554. else
  555. $data[$key] = $newval;
  556. $gd->set('__global', $data);
  557. }
  558. /* TODO: these are really backend methods */
  559. // SQL result: for simple select or create/update queries
  560. // returns the database specific resource type
  561. function genericSqlQuery($sql, $args=false) {
  562. if (function_exists('debug_backtrace')) { // >= 4.3.0
  563. echo "<pre>", printSimpleTrace(debug_backtrace()), "</pre>\n";
  564. }
  565. trigger_error("no SQL database", E_USER_ERROR);
  566. return false;
  567. }
  568. // SQL iter: for simple select or create/update queries
  569. // returns the generic iterator object (count,next)
  570. function genericSqlIter($sql, $field_list = NULL) {
  571. if (function_exists('debug_backtrace')) { // >= 4.3.0
  572. echo "<pre>", printSimpleTrace(debug_backtrace()), "</pre>\n";
  573. }
  574. trigger_error("no SQL database", E_USER_ERROR);
  575. return false;
  576. }
  577. // see backend upstream methods
  578. // ADODB adds surrounding quotes, SQL not yet!
  579. function quote ($s) {
  580. return $s;
  581. }
  582. function isOpen () {
  583. global $request;
  584. if (!$request->_dbi) return false;
  585. else return false; /* so far only needed for sql so false it.
  586. later we have to check dba also */
  587. }
  588. function getParam($param) {
  589. global $DBParams;
  590. if (isset($DBParams[$param])) return $DBParams[$param];
  591. elseif ($param == 'prefix') return '';
  592. else return false;
  593. }
  594. function getAuthParam($param) {
  595. global $DBAuthParams;
  596. if (isset($DBAuthParams[$param])) return $DBAuthParams[$param];
  597. elseif ($param == 'USER_AUTH_ORDER') return $GLOBALS['USER_AUTH_ORDER'];
  598. elseif ($param == 'USER_AUTH_POLICY') return $GLOBALS['USER_AUTH_POLICY'];
  599. else return false;
  600. }
  601. };
  602. /**
  603. * An abstract base class which representing a wiki-page within a
  604. * WikiDB.
  605. *
  606. * A WikiDB_Page contains a number (at least one) of
  607. * WikiDB_PageRevisions.
  608. */
  609. class WikiDB_Page
  610. {
  611. function WikiDB_Page(&$wikidb, $pagename) {
  612. $this->_wikidb = &$wikidb;
  613. $this->_pagename = $pagename;
  614. if (DEBUG) {
  615. if (!(is_string($pagename) and $pagename != '')) {
  616. if (function_exists("xdebug_get_function_stack")) {
  617. echo "xdebug_get_function_stack(): "; var_dump(xdebug_get_function_stack());
  618. } elseif (function_exists("debug_backtrace")) { // >= 4.3.0
  619. printSimpleTrace(debug_backtrace());
  620. }
  621. trigger_error("empty pagename", E_USER_WARNING);
  622. return false;
  623. }
  624. } else {
  625. assert(is_string($pagename) and $pagename != '');
  626. }
  627. }
  628. /**
  629. * Get the name of the wiki page.
  630. *
  631. * @access public
  632. *
  633. * @return string The page name.
  634. */
  635. function getName() {
  636. return $this->_pagename;
  637. }
  638. // To reduce the memory footprint for larger sets of pagelists,
  639. // we don't cache the content (only true or false) and
  640. // we purge the pagedata (_cached_html) also
  641. function exists() {
  642. if (isset($this->_wikidb->_cache->_id_cache[$this->_pagename])) return true;
  643. $current = $this->getCurrentRevision(false);
  644. if (!$current) return false;
  645. return ! $current->hasDefaultContents();
  646. }
  647. /**
  648. * Delete an old revision of a WikiDB_Page.
  649. *
  650. * Deletes the specified revision of the page.
  651. * It is a fatal error to attempt to delete the current revision.
  652. *
  653. * @access public
  654. *
  655. * @param integer $version Which revision to delete. (You can also
  656. * use a WikiDB_PageRevision object here.)
  657. */
  658. function deleteRevision($version) {
  659. $backend = &$this->_wikidb->_backend;
  660. $cache = &$this->_wikidb->_cache;
  661. $pagename = &$this->_pagename;
  662. $version = $this->_coerce_to_version($version);
  663. if ($version == 0)
  664. return;
  665. $backend->lock(array('page','version'));
  666. $latestversion = $cache->get_latest_version($pagename);
  667. if ($latestversion && ($version == $latestversion)) {
  668. $backend->unlock(array('page','version'));
  669. trigger_error(sprintf("Attempt to delete most recent revision of '%s'",
  670. $pagename), E_USER_ERROR);
  671. return;
  672. }
  673. $cache->delete_versiondata($pagename, $version);
  674. $backend->unlock(array('page','version'));
  675. }
  676. /*
  677. * Delete a revision, or possibly merge it with a previous
  678. * revision.
  679. *
  680. * The idea is this:
  681. * Suppose an author make a (major) edit to a page. Shortly
  682. * after that the same author makes a minor edit (e.g. to fix
  683. * spelling mistakes he just made.)
  684. *
  685. * Now some time later, where cleaning out old saved revisions,
  686. * and would like to delete his minor revision (since there's
  687. * really no point in keeping minor revisions around for a long
  688. * time.)
  689. *
  690. * Note that the text after the minor revision probably represents
  691. * what the author intended to write better than the text after
  692. * the preceding major edit.
  693. *
  694. * So what we really want to do is merge the minor edit with the
  695. * preceding edit.
  696. *
  697. * We will only do this when:
  698. * <ul>
  699. * <li>The revision being deleted is a minor one, and
  700. * <li>It has the same author as the immediately preceding revision.
  701. * </ul>
  702. */
  703. function mergeRevision($version) {
  704. $backend = &$this->_wikidb->_backend;
  705. $cache = &$this->_wikidb->_cache;
  706. $pagename = &$this->_pagename;
  707. $version = $this->_coerce_to_version($version);
  708. if ($version == 0)
  709. return;
  710. $backend->lock(array('version'));
  711. $latestversion = $cache->get_latest_version($pagename);
  712. if ($latestversion && $version == $latestversion) {
  713. $backend->unlock(array('version'));
  714. trigger_error(sprintf("Attempt to merge most recent revision of '%s'",
  715. $pagename), E_USER_ERROR);
  716. return;
  717. }
  718. $versiondata = $cache->get_versiondata($pagename, $version, true);
  719. if (!$versiondata) {
  720. // Not there? ... we're done!
  721. $backend->unlock(array('version'));
  722. return;
  723. }
  724. if ($versiondata['is_minor_edit']) {
  725. $previous = $backend->get_previous_version($pagename, $version);
  726. if ($previous) {
  727. $prevdata = $cache->get_versiondata($pagename, $previous);
  728. if ($prevdata['author_id'] == $versiondata['author_id']) {
  729. // This is a minor revision, previous version is
  730. // by the same author. We will merge the
  731. // revisions.
  732. $cache->update_versiondata($pagename, $previous,
  733. array('%content' => $versiondata['%content'],
  734. '_supplanted' => $versiondata['_supplanted']));
  735. }
  736. }
  737. }
  738. $cache->delete_versiondata($pagename, $version);
  739. $backend->unlock(array('version'));
  740. }
  741. /**
  742. * Create a new revision of a {@link WikiDB_Page}.
  743. *
  744. * @access public
  745. *
  746. * @param int $version Version number for new revision.
  747. * To ensure proper serialization of edits, $version must be
  748. * exactly one higher than the current latest version.
  749. * (You can defeat this check by setting $version to
  750. * {@link WIKIDB_FORCE_CREATE} --- not usually recommended.)
  751. *
  752. * @param string $content Contents of new revision.
  753. *
  754. * @param hash $metadata Metadata for new revision.
  755. * All values in the hash should be scalars (strings or integers).
  756. *
  757. * @param array $links List of pagenames which this page links to.
  758. *
  759. * @return WikiDB_PageRevision Returns the new WikiDB_PageRevision object. If
  760. * $version was incorrect, returns false
  761. */
  762. function createRevision($version, &$content, $metadata, $links) {
  763. $backend = &$this->_wikidb->_backend;
  764. $cache = &$this->_wikidb->_cache;
  765. $pagename = &$this->_pagename;
  766. $cache->invalidate_cache($pagename);
  767. $backend->lock(array('version','page','recent','link','nonempty'));
  768. $latestversion = $backend->get_latest_version($pagename);
  769. $newversion = ($latestversion ? $latestversion : 0) + 1;
  770. assert($newversion >= 1);
  771. if ($version != WIKIDB_FORCE_CREATE and $version != $newversion) {
  772. $backend->unlock(array('version','page','recent','link','nonempty'));
  773. return false;
  774. }
  775. $data = $metadata;
  776. foreach ($data as $key => $val) {
  777. if (empty($val) || $key[0] == '_' || $key[0] == '%')
  778. unset($data[$key]);
  779. }
  780. assert(!empty($data['author']));
  781. if (empty($data['author_id']))
  782. @$data['author_id'] = $data['author'];
  783. if (empty($data['mtime']))
  784. $data['mtime'] = time();
  785. if ($latestversion and $version != WIKIDB_FORCE_CREATE) {
  786. // Ensure mtimes are monotonic.
  787. $pdata = $cache->get_versiondata($pagename, $latestversion);
  788. if ($data['mtime'] < $pdata['mtime']) {
  789. trigger_error(sprintf(_("%s: Date of new revision is %s"),
  790. $pagename,"'non-monotonic'"),
  791. E_USER_NOTICE);
  792. $data['orig_mtime'] = $data['mtime'];
  793. $data['mtime'] = $pdata['mtime'];
  794. }
  795. // FIXME: use (possibly user specified) 'mtime' time or
  796. // time()?
  797. $cache->update_versiondata($pagename, $latestversion,
  798. array('_supplanted' => $data['mtime']));
  799. }
  800. $data['%content'] = &$content;
  801. $cache->set_versiondata($pagename, $newversion, $data);
  802. //$cache->update_pagedata($pagename, array(':latestversion' => $newversion,
  803. //':deleted' => empty($content)));
  804. $backend->set_links($pagename, $links);
  805. $backend->unlock(array('version','page','recent','link','nonempty'));
  806. return new WikiDB_PageRevision($this->_wikidb, $pagename, $newversion,
  807. $data);
  808. }
  809. /** A higher-level interface to createRevision.
  810. *
  811. * This takes care of computing the links, and storing
  812. * a cached version of the transformed wiki-text.
  813. *
  814. * @param string $wikitext The page content.
  815. *
  816. * @param int $version Version number for new revision.
  817. * To ensure proper serialization of edits, $version must be
  818. * exactly one higher than the current latest version.
  819. * (You can defeat this check by setting $version to
  820. * {@link WIKIDB_FORCE_CREATE} --- not usually recommended.)
  821. *
  822. * @param hash $meta Meta-data for new revision.
  823. */
  824. function save($wikitext, $version, $meta) {
  825. $formatted = new TransformedText($this, $wikitext, $meta);
  826. $type = $formatted->getType();
  827. $meta['pagetype'] = $type->getName();
  828. $links = $formatted->getWikiPageLinks();
  829. $backend = &$this->_wikidb->_backend;
  830. $newrevision = $this->createRevision($version, $wikitext, $meta, $links);
  831. if ($newrevision and !WIKIDB_NOCACHE_MARKUP)
  832. $this->set('_cached_html', $formatted->pack());
  833. // FIXME: probably should have some global state information
  834. // in the backend to control when to optimize.
  835. //
  836. // We're doing this here rather than in createRevision because
  837. // postgresql can't optimize while locked.
  838. if ((DEBUG & _DEBUG_SQL)
  839. or (DATABASE_OPTIMISE_FREQUENCY > 0 and
  840. (time() % DATABASE_OPTIMISE_FREQUENCY == 0))) {
  841. if ($backend->optimize()) {
  842. if (DEBUG)
  843. trigger_error(_("Optimizing database"), E_USER_NOTICE);
  844. }
  845. }
  846. /* Generate notification emails? */
  847. if (isa($newrevision, 'WikiDB_PageRevision')) {
  848. // Save didn't fail because of concurrent updates.
  849. $notify = $this->_wikidb->get('notify');
  850. if (!empty($notify) and is_array($notify) and !isa($GLOBALS['request'],'MockRequest')) {
  851. list($emails, $userids) = $this->getPageChangeEmails($notify);
  852. if (!empty($emails)) {
  853. $this->sendPageChangeNotification($wikitext, $version, $meta, $emails, $userids);
  854. }
  855. }
  856. $newrevision->_transformedContent = $formatted;
  857. }
  858. return $newrevision;
  859. }
  860. function getPageChangeEmails($notify) {
  861. $emails = array(); $userids = array();
  862. foreach ($notify as $page => $users) {
  863. if (glob_match($page, $this->_pagename)) {
  864. foreach ($users as $userid => $user) {
  865. if (!$user) { // handle the case for ModeratePage: no prefs, just userid's.
  866. global $request;
  867. $u = $request->getUser();
  868. if ($u->UserName() == $userid) {
  869. $prefs = $u->getPreferences();
  870. } else {
  871. // not current user
  872. if (ENABLE_USER_NEW) {
  873. $u = WikiUser($userid);
  874. $u->getPreferences();
  875. $prefs = &$u->_prefs;
  876. } else {
  877. $u = new WikiUser($GLOBALS['request'], $userid);
  878. $prefs = $u->getPreferences();
  879. }
  880. }
  881. $emails[] = $prefs->get('email');
  882. $userids[] = $userid;
  883. } else {
  884. if (!empty($user['verified']) and !empty($user['email'])) {
  885. $emails[] = $user['email'];
  886. $userids[] = $userid;
  887. } elseif (!empty($user['email'])) {
  888. global $request;
  889. // do a dynamic emailVerified check update
  890. $u = $request->getUser();
  891. if ($u->UserName() == $userid) {
  892. if ($request->_prefs->get('emailVerified')) {
  893. $emails[] = $user['email'];
  894. $userids[] = $userid;
  895. $notify[$page][$userid]['verified'] = 1;
  896. $request->_dbi->set('notify', $notify);
  897. }
  898. } else {
  899. // not current user
  900. if (ENABLE_USER_NEW) {
  901. $u = WikiUser($userid);
  902. $u->getPreferences();
  903. $prefs = &$u->_prefs;
  904. } else {
  905. $u = new WikiUser($GLOBALS['request'], $userid);
  906. $prefs = $u->getPreferences();
  907. }
  908. if ($prefs->get('emailVerified')) {
  909. $emails[] = $user['email'];
  910. $userids[] = $userid;
  911. $notify[$page][$userid]['verified'] = 1;
  912. $request->_dbi->set('notify', $notify);
  913. }
  914. }
  915. // ignore verification
  916. /*
  917. if (DEBUG) {
  918. if (!in_array($user['email'],$emails))
  919. $emails[] = $user['email'];
  920. }
  921. */
  922. }
  923. }
  924. }
  925. }
  926. }
  927. $emails = array_unique($emails);
  928. $userids = array_unique($userids);
  929. return array($emails, $userids);
  930. }
  931. /**
  932. * Send udiff for a changed page to multiple users.
  933. * See rename and remove methods also
  934. */
  935. function sendPageChangeNotification(&$wikitext, $version, $meta, $emails, $userids) {
  936. global $request;
  937. if (@is_array($request->_deferredPageChangeNotification)) {
  938. // collapse multiple changes (loaddir) into one email
  939. $request->_deferredPageChangeNotification[]
  940. = array($this->_pagename, $emails, $userids);
  941. return;
  942. }
  943. $backend = &$this->_wikidb->_backend;
  944. //$backend = &$request->_dbi->_backend;
  945. $subject = _("Page change").' '.urlencode($this->_pagename);
  946. $previous = $backend->get_previous_version($this->_pagename, $version);
  947. if (!isset($meta['mtime'])) $meta['mtime'] = time();
  948. if ($previous) {
  949. $difflink = WikiURL($this->_pagename, array('action'=>'diff'), true);
  950. $cache = &$this->_wikidb->_cache;
  951. //$cache = &$request->_dbi->_cache;
  952. $this_content = explode("\n", $wikitext);
  953. $prevdata = $cache->get_versiondata($this->_pagename, $previous, true);
  954. if (empty($prevdata['%content']))
  955. $prevdata = $backend->get_versiondata($this->_pagename, $previous, true);
  956. $other_content = explode("\n", $prevdata['%content']);
  957. include_once("lib/difflib.php");
  958. $diff2 = new Diff($other_content, $this_content);
  959. //$context_lines = max(4, count($other_content) + 1,
  960. // count($this_content) + 1);
  961. $fmt = new UnifiedDiffFormatter(/*$context_lines*/);
  962. $content = $this->_pagename . " " . $previous . " " .
  963. Iso8601DateTime($prevdata['mtime']) . "\n";
  964. $content .= $this->_pagename . " " . $version . " " .
  965. Iso8601DateTime($meta['mtime']) . "\n";
  966. $content .= $fmt->format($diff2);
  967. } else {
  968. $difflink = WikiURL($this->_pagename,array(),true);
  969. $content = $this->_pagename . " " . $version . " " .
  970. Iso8601DateTime($meta['mtime']) . "\n";
  971. $content .= _("New page");
  972. }
  973. $from = $request->_user->getId();
  974. $editedby = sprintf(_("Edited by: %s"), $from);
  975. $emails = join(',',$emails);
  976. $headers = "From: $from <nobody>\r\n" .
  977. "Bcc: $emails\r\n" .
  978. "MIME-Version: 1.0\r\n" .
  979. "Content-Type: text/plain; charset=".CHARSET."; format=flowed\r\n" .
  980. "Content-Transfer-Encoding: 8bit";
  981. if (mail("<undisclosed-recipients>",
  982. "[".WIKI_NAME."] ".$subject,
  983. $subject."\n". $editedby."\n". $difflink."\n\n". $content,
  984. $headers))
  985. trigger_error(sprintf(_("PageChange Notification of %s sent to %s"),
  986. $this->_pagename, join(',',$userids)), E_USER_NOTICE);
  987. else
  988. trigger_error(sprintf(_("PageChange Notification Error: Couldn't send %s to %s"),
  989. $this->_pagename, join(',',$userids)), E_USER_WARNING);
  990. }
  991. /** support mass rename / remove (not yet tested)
  992. */
  993. function sendPageRenameNotification($to, &$meta, $emails, $userids) {
  994. global $request;
  995. if (@is_array($request->_deferredPageRenameNotification)) {
  996. $request->_deferredPageRenameNotification[] = array($this->_pagename,
  997. $to, $meta, $emails, $userids);
  998. } else {
  999. $oldname = $this->_pagename;
  1000. $from = $request->_user->getId();
  1001. $editedby = sprintf(_("Edited by: %s"), $from);
  1002. $emails = join(',',$emails);
  1003. $subject = sprintf(_("Page rename %s to %s"), urlencode($oldname), urlencode($to));
  1004. $link = WikiURL($to, true);
  1005. $headers = "From: $from <nobody>\r\n" .
  1006. "Bcc: $emails\r\n" .
  1007. "MIME-Version: 1.0\r\n" .
  1008. "Content-Type: text/plain; charset=".CHARSET."; format=flowed\r\n" .
  1009. "Content-Transfer-Encoding: 8bit";
  1010. if (mail("<undisclosed-recipients>",
  1011. "[".WIKI_NAME."] ".$subject,
  1012. $subject."\n".$editedby."\n".$link."\n\n"."Renamed $from to $to",
  1013. $headers))
  1014. trigger_error(sprintf(_("PageChange Notification of %s sent to %s"),
  1015. $oldname, join(',',$userids)), E_USER_NOTICE);
  1016. else
  1017. trigger_error(sprintf(_("PageChange Notification Error: Couldn't send %s to %s"),
  1018. $oldname, join(',',$userids)), E_USER_WARNING);
  1019. }
  1020. }
  1021. /**
  1022. * Get the most recent revision of a page.
  1023. *
  1024. * @access public
  1025. *
  1026. * @return WikiDB_PageRevision The current WikiDB_PageRevision object.
  1027. */
  1028. function getCurrentRevision ($need_content = true) {
  1029. $backend = &$this->_wikidb->_backend;
  1030. $cache = &$this->_wikidb->_cache;
  1031. $pagename = &$this->_pagename;
  1032. // Prevent deadlock in case of memory exhausted errors
  1033. // Pure selection doesn't really need locking here.
  1034. // sf.net bug#927395
  1035. // I know it would be better to lock, but with lots of pages this deadlock is more
  1036. // severe than occasionally get not the latest revision.
  1037. // In spirit to wikiwiki: read fast, edit slower.
  1038. //$backend->lock();
  1039. $version = $cache->get_latest_version($pagename);
  1040. // getRevision gets the content also!
  1041. $revision = $this->getRevision($version, $need_content);
  1042. //$backend->unlock();
  1043. assert($revision);
  1044. return $revision;
  1045. }
  1046. /**
  1047. * Get a specific revision of a WikiDB_Page.
  1048. *
  1049. * @access public
  1050. *
  1051. * @param integer $version Which revision to get.
  1052. *
  1053. * @return WikiDB_PageRevision The requested WikiDB_PageRevision object, or
  1054. * false if the requested revision does not exist in the {@link WikiDB}.
  1055. * Note that version zero of any page always exists.
  1056. */
  1057. function getRevision ($version, $need_content=true) {
  1058. $cache = &$this->_wikidb->_cache;
  1059. $pagename = &$this->_pagename;
  1060. if (! $version or $version == -1) // 0 or false
  1061. return new WikiDB_PageRevision($this->_wikidb, $pagename, 0);
  1062. assert($version > 0);
  1063. $vdata = $cache->get_versiondata($pagename, $version, $need_content);
  1064. if (!$vdata) {
  1065. return new WikiDB_PageRevision($this->_wikidb, $pagename, 0);
  1066. }
  1067. return new WikiDB_PageRevision($this->_wikidb, $pagename, $version,
  1068. $vdata);
  1069. }
  1070. /**
  1071. * Get previous page revision.
  1072. *
  1073. * This method find the most recent revision before a specified
  1074. * version.
  1075. *
  1076. * @access public
  1077. *
  1078. * @param integer $version Find most recent revision before this version.
  1079. * You can also use a WikiDB_PageRevision object to specify the $version.
  1080. *
  1081. * @return WikiDB_PageRevision The requested WikiDB_PageRevision object, or false if the
  1082. * requested revision does not exist in the {@link WikiDB}. Note that
  1083. * unless $version is greater than zero, a revision (perhaps version zero,
  1084. * the default revision) will always be found.
  1085. */
  1086. function getRevisionBefore ($version=false, $need_content=true) {
  1087. $backend = &$this->_wikidb->_backend;
  1088. $pagename = &$this->_pagename;
  1089. if ($version === false)
  1090. $version = $this->_wikidb->_cache->get_latest_version($pagename);
  1091. else
  1092. $version = $this->_coerce_to_version($version);
  1093. if ($version == 0)
  1094. return false;
  1095. //$backend->lock();
  1096. $previous = $backend->get_previous_version($pagename, $version);
  1097. $revision = $this->getRevision($previous, $need_content);
  1098. //$backend->unlock();
  1099. assert($revision);
  1100. return $revision;
  1101. }
  1102. /**
  1103. * Get all revisions of the WikiDB_Page.
  1104. *
  1105. * This does not include the version zero (default) revision in the
  1106. * returned revision set.
  1107. *
  1108. * @return WikiDB_PageRevisionIterator A
  1109. * WikiDB_PageRevisionIterator containing all revisions of this
  1110. * WikiDB_Page in reverse order by version number.
  1111. */
  1112. function getAllRevisions() {
  1113. $backend = &$this->_wikidb->_backend;
  1114. $revs = $backend->get_all_revisions($this->_pagename);
  1115. return new WikiDB_PageRevisionIterator($this->_wikidb, $revs);
  1116. }
  1117. /**
  1118. * Find pages which link to or are linked from a page.
  1119. *
  1120. * @access public
  1121. *
  1122. * @param boolean $reversed Which links to find: true for backlinks (default).
  1123. *
  1124. * @return WikiDB_PageIterator A WikiDB_PageIterator containing
  1125. * all matching pages.
  1126. */
  1127. function getLinks ($reversed = true, $include_empty=false, $sortby=false,
  1128. $limit=false, $exclude=false) {
  1129. $backend = &$this->_wikidb->_backend;
  1130. $result = $backend->get_links($this->_pagename, $reversed,
  1131. $include_empty, $sortby, $limit, $exclude);
  1132. return new WikiDB_PageIterator($this->_wikidb, $result,
  1133. array('include_empty' => $include_empty,
  1134. 'sortby' => $sortby,
  1135. 'limit' => $limit,
  1136. 'exclude' => $exclude));
  1137. }
  1138. /**
  1139. * All Links from other pages to this page.
  1140. */
  1141. function getBackLinks($include_empty=false, $sortby=false, $limit=false, $exclude=false) {
  1142. return $this->getLinks(true, $include_empty, $sortby, $limit, $exclude);
  1143. }
  1144. /**
  1145. * Forward Links: All Links from this page to other pages.
  1146. */
  1147. function getPageLinks($include_empty=false, $sortby=false, $limit=false, $exclude=false) {
  1148. return $this->getLinks(false, $include_empty, $sortby, $limit, $exclude);
  1149. }
  1150. /**
  1151. * possibly faster link existance check. not yet accelerated.
  1152. */
  1153. function existLink($link, $reversed=false) {
  1154. $backend = &$this->_wikidb->_backend;
  1155. if (method_exists($backend,'exists_link'))
  1156. return $backend->exists_link($this->_pagename, $link, $reversed);
  1157. //$cache = &$this->_wikidb->_cache;
  1158. // TODO: check cache if it is possible
  1159. $iter = $this->getLinks($reversed, false);
  1160. while ($page = $iter->next()) {
  1161. if ($page->getName() == $link)
  1162. return $page;
  1163. }
  1164. $iter->free();
  1165. return false;
  1166. }
  1167. /**
  1168. * Access WikiDB_Page non version-specific meta-data.
  1169. *
  1170. * @access public
  1171. *
  1172. * @param string $key Which meta data to get.
  1173. * Some reserved meta-data keys are:
  1174. * <dl>
  1175. * <dt>'date' <dd> Created as unixtime
  1176. * <dt>'locked'<dd> Is page locked? 'yes' or 'no'
  1177. * <dt>'hits' <dd> Page hit counter.
  1178. * <dt>'_cached_html' <dd> Transformed CachedMarkup object, serialized + optionally gzipped.
  1179. * In SQL stored now in an extra column.
  1180. * Optional data:
  1181. * <dt>'pref' <dd> Users preferences, stored only in homepages.
  1182. * <dt>'owner' <dd> Default: first author_id. We might add a group with a dot here:
  1183. * E.g. "owner.users"
  1184. * <dt>'perm' <dd> Permission flag to authorize read/write/execution of
  1185. * page-headers and content.
  1186. + <dt>'moderation'<dd> ModeratedPage data
  1187. * <dt>'score' <dd> Page score (not yet implement, do we need?)
  1188. * </dl>
  1189. *
  1190. * @return scalar The requested value, or false if the requested data
  1191. * is not set.
  1192. */
  1193. function get($key) {
  1194. $cache = &$this->_wikidb->_cache;
  1195. $backend = &$this->_wikidb->_backend;
  1196. if (!$key || $key[0] == '%')
  1197. return false;
  1198. // several new SQL backends optimize this.
  1199. if (!WIKIDB_NOCACHE_MARKUP
  1200. and $key == '_cached_html'
  1201. and method_exists($backend, 'get_cached_html'))
  1202. {
  1203. return $backend->get_cached_html($this->_pagename);
  1204. }
  1205. $data = $cache->get_pagedata($this->_pagename);
  1206. return isset($data[$key]) ? $data[$key] : false;
  1207. }
  1208. /**
  1209. * Get all the page meta-data as a hash.
  1210. *
  1211. * @return hash The page meta-data.
  1212. */
  1213. function getMetaData() {
  1214. $cache = &$this->_wikidb->_cache;
  1215. $data = $cache->get_pagedata($this->_pagename);
  1216. $meta = array();
  1217. foreach ($data as $key => $val) {
  1218. if (/*!empty($val) &&*/ $key[0] != '%')
  1219. $meta[$key] = $val;
  1220. }
  1221. return $meta;
  1222. }
  1223. /**
  1224. * Set page meta-data.
  1225. *
  1226. * @see get
  1227. * @access public
  1228. *
  1229. * @param string $key Meta-data key to set.
  1230. * @param string $newval New value.
  1231. */
  1232. function set($key, $newval) {
  1233. $cache = &$this->_wikidb->_cache;
  1234. $backend = &$this->_wikidb->_backend;
  1235. $pagename = &$this->_pagename;
  1236. assert($key && $key[0] != '%');
  1237. // several new SQL backends optimize this.
  1238. if (!WIKIDB_NOCACHE_MARKUP
  1239. and $key == '_cached_html'
  1240. and method_exists($backend, 'set_cached_html'))
  1241. {
  1242. return $backend->set_cached_html($pagename, $newval);
  1243. }
  1244. $data = $cache->get_pagedata($pagename);
  1245. if (!empty($newval)) {
  1246. if (!empty($data[$key]) && $data[$key] == $newval)
  1247. return; // values identical, skip update.
  1248. }
  1249. else {
  1250. if (empty($data[$key]))
  1251. return; // values identical, skip update.
  1252. }
  1253. $cache->update_pagedata($pagename, array($key => $newval));
  1254. }
  1255. /**
  1256. * Increase page hit count.
  1257. *
  1258. * FIXME: IS this needed? Probably not.
  1259. *
  1260. * This is a convenience function.
  1261. * <pre> $page->increaseHitCount(); </pre>
  1262. * is functionally identical to
  1263. * <pre> $page->set('hits',$page->get('hits')+1); </pre>
  1264. * but less expensive (ignores the pagadata string)
  1265. *
  1266. * Note that this method may be implemented in more efficient ways
  1267. * in certain backends.
  1268. *
  1269. * @access public
  1270. */
  1271. function increaseHitCount() {
  1272. if (method_exists($this->_wikidb->_backend, 'increaseHitCount'))
  1273. $this->_wikidb->_backend->increaseHitCount($this->_pagename);
  1274. else {
  1275. @$newhits = $this->get('hits') + 1;
  1276. $this->set('hits', $newhits);
  1277. }
  1278. }
  1279. /**
  1280. * Return a string representation of the WikiDB_Page
  1281. *
  1282. * This is really only for debugging.
  1283. *
  1284. * @access public
  1285. *
  1286. * @return string Printable representation of the WikiDB_Page.
  1287. */
  1288. function asString () {
  1289. ob_start();
  1290. printf("[%s:%s\n", get_class($this), $this->getName());
  1291. print_r($this->getMetaData());
  1292. echo "]\n";
  1293. $strval = ob_get_contents();
  1294. ob_end_clean();
  1295. return $strval;
  1296. }
  1297. /**
  1298. * @access private
  1299. * @param integer_or_object $version_or_pagerevision
  1300. * Takes either the version number (and int) or a WikiDB_PageRevision
  1301. * object.
  1302. * @return integer The version number.
  1303. */
  1304. function _coerce_to_version($version_or_pagerevision) {
  1305. if (method_exists($version_or_pagerevision, "getContent"))
  1306. $version = $version_or_pagerevision->getVersion();
  1307. else
  1308. $version = (int) $version_or_pagerevision;
  1309. assert($version >= 0);
  1310. return $version;
  1311. }
  1312. function isUserPage ($include_empty = true) {
  1313. if (!$include_empty and !$this->exists()) return false;
  1314. return $this->get('pref') ? true : false;
  1315. }
  1316. // May be empty. Either the stored owner (/Chown), or the first authorized author
  1317. function getOwner() {
  1318. if ($owner = $this->get('owner'))
  1319. return ($owner == "The PhpWiki programming team") ? ADMIN_USER : $owner;
  1320. // check all revisions forwards for the first author_id
  1321. $backend = &$this->_wikidb->_backend;
  1322. $pagename = &$this->_pagename;
  1323. $latestversion = $backend->get_latest_version($pagename);
  1324. for ($v=1; $v <= $latestversion; $v++) {
  1325. $rev = $this->getRevision($v,false);
  1326. if ($rev and $owner = $rev->get('author_id')) {
  1327. return ($owner == "The PhpWiki programming team") ? ADMIN_USER : $owner;
  1328. }
  1329. }
  1330. return '';
  1331. }
  1332. // The authenticated author of the first revision or empty if not authenticated then.
  1333. function getCreator() {
  1334. if ($current = $this->getRevision(1,false)) return $current->get('author_id');
  1335. else return '';
  1336. }
  1337. // The authenticated author of the current revision.
  1338. function getAuthor() {
  1339. if ($current = $this->getCurrentRevision(false)) return $current->get('author_id');
  1340. else return '';
  1341. }
  1342. };
  1343. /**
  1344. * This class represents a specific revision of a WikiDB_Page within
  1345. * a WikiDB.
  1346. *
  1347. * A WikiDB_PageRevision has read-only semantics. You may only create
  1348. * new revisions (and delete old ones) --- you cannot modify existing
  1349. * revisions.
  1350. */
  1351. class WikiDB_PageRevision
  1352. {
  1353. //var $_transformedContent = false; // set by WikiDB_Page::save()
  1354. function WikiDB_PageRevision(&$wikidb, $pagename, $version, $versiondata = false) {
  1355. $this->_wikidb = &$wikidb;
  1356. $this->_pagename = $pagename;
  1357. $this->_version = $version;
  1358. $this->_data = $versiondata ? $versiondata : array();
  1359. $this->_transformedContent = false; // set by WikiDB_Page::save()
  1360. }
  1361. /**
  1362. * Get the WikiDB_Page which this revision belongs to.
  1363. *
  1364. * @access public
  1365. *
  1366. * @return WikiDB_Page The WikiDB_Page which this revision belongs to.
  1367. */
  1368. function getPage() {
  1369. return new WikiDB_Page($this->_wikidb, $this->_pagename);
  1370. }
  1371. /**
  1372. * Get the version number of this revision.
  1373. *
  1374. * @access public
  1375. *
  1376. * @return integer The version number of this revision.
  1377. */
  1378. function getVersion() {
  1379. return $this->_version;
  1380. }
  1381. /**
  1382. * Determine whether this revision has defaulted content.
  1383. *
  1384. * The default revision (version 0) of each page, as well as any
  1385. * pages which are created with empty content have their content
  1386. * defaulted to something like:
  1387. * <pre>
  1388. * Describe [ThisPage] here.
  1389. * </pre>
  1390. *
  1391. * @access public
  1392. *
  1393. * @return boolean Returns true if the page has default content.
  1394. */
  1395. function hasDefaultContents() {
  1396. $data = &$this->_data;
  1397. return empty($data['%content']); // FIXME: what if it's the number 0? <>'' or === false
  1398. }
  1399. /**
  1400. * Get the content as an array of lines.
  1401. *
  1402. * @access public
  1403. *
  1404. * @return array An array of lines.
  1405. * The lines should contain no trailing white space.
  1406. */
  1407. function getContent() {
  1408. return explode("\n", $this->getPackedContent());
  1409. }
  1410. /**
  1411. * Get the pagename of the revision.
  1412. *
  1413. * @access public
  1414. *
  1415. * @return string pagename.
  1416. */
  1417. function getPageName() {
  1418. return $this->_pagename;
  1419. }
  1420. function getName() {
  1421. return $this->_pagename;
  1422. }
  1423. /**
  1424. * Determine whether revision is the latest.
  1425. *
  1426. * @access public
  1427. *
  1428. * @return boolean True iff the revision is the latest (most recent) one.
  1429. */
  1430. function isCurrent() {
  1431. if (!isset($this->_iscurrent)) {
  1432. $page = $this->getPage();
  1433. $current = $page->getCurrentRevision(false);
  1434. $this->_iscurrent = $this->getVersion() == $current->getVersion();
  1435. }
  1436. return $this->_iscurrent;
  1437. }
  1438. /**
  1439. * Get the transformed content of a page.
  1440. *
  1441. * @param string $pagetype Override the page-type of the revision.
  1442. *
  1443. * @return object An XmlContent-like object containing the page transformed
  1444. * contents.
  1445. */
  1446. function getTransformedContent($pagetype_override=false) {
  1447. $backend = &$this->_wikidb->_backend;
  1448. if ($pagetype_override) {
  1449. // Figure out the normal page-type for this page.
  1450. $type = PageType::GetPageType($this->get('pagetype'));
  1451. if ($type->getName() == $pagetype_override)
  1452. $pagetype_override = false; // Not really an override...
  1453. }
  1454. if ($pagetype_override) {
  1455. // Overriden page type, don't cache (or check cache).
  1456. return new TransformedText($this->getPage(),
  1457. $this->getPackedContent(),
  1458. $this->getMetaData(),
  1459. $pagetype_override);
  1460. }
  1461. $possibly_cache_results = true;
  1462. if (!USECACHE or WIKIDB_NOCACHE_MARKUP) {
  1463. if (WIKIDB_NOCACHE_MARKUP == 'purge') {
  1464. // flush cache for this page.
  1465. $page = $this->getPage();
  1466. $page->set('_cached_html', ''); // ignored with !USECACHE
  1467. }
  1468. $possibly_cache_results = false;
  1469. }
  1470. elseif (USECACHE and !$this->_transformedContent) {
  1471. //$backend->lock();
  1472. if ($this->isCurrent()) {
  1473. $page = $this->getPage();
  1474. $this->_transformedContent = TransformedText::unpack($page->get('_cached_html'));
  1475. }
  1476. else {
  1477. $possibly_cache_results = false;
  1478. }
  1479. //$backend->unlock();
  1480. }
  1481. if (!$this->_transformedContent) {
  1482. $this->_transformedContent
  1483. = new TransformedText($this->getPage(),
  1484. $this->getPackedContent(),
  1485. $this->getMetaData());
  1486. if ($possibly_cache_results and !WIKIDB_NOCACHE_MARKUP) {
  1487. // If we're still the current version, cache the transfomed page.
  1488. //$backend->lock();
  1489. if ($this->isCurrent()) {
  1490. $page->set('_cached_html', $this->_transformedContent->pack());
  1491. }
  1492. //$backend->unlock();
  1493. }
  1494. }
  1495. return $this->_transformedContent;
  1496. }
  1497. /**
  1498. * Get the content as a string.
  1499. *
  1500. * @access public
  1501. *
  1502. * @return string The page content.
  1503. * Lines are separated by new-lines.
  1504. */
  1505. function getPackedContent() {
  1506. $data = &$this->_data;
  1507. if (empty($data['%content'])) {
  1508. include_once('lib/InlineParser.php');
  1509. // A feature similar to taglines at http://www.wlug.org.nz/
  1510. // Lib from http://www.aasted.org/quote/
  1511. if (defined('FORTUNE_DIR')
  1512. and is_dir(FORTUNE_DIR)
  1513. and in_array($GLOBALS['request']->getArg('action'),
  1514. array('create','edit')))
  1515. {
  1516. include_once("lib/fortune.php");
  1517. $fortune = new Fortune();
  1518. $quote = str_replace("\n<br>","\n", $fortune->quoteFromDir(FORTUNE_DIR));
  1519. return sprintf("<verbatim>\n%s</verbatim>\n\n"._("Describe %s here."),
  1520. $quote, "[" . WikiEscape($this->_pagename) . "]");
  1521. }
  1522. // Replace empty content with default value.
  1523. return sprintf(_("Describe %s here."),
  1524. "[" . WikiEscape($this->_pagename) . "]");
  1525. }
  1526. // There is (non-default) content.
  1527. assert($this->_version > 0);
  1528. if (!is_string($data['%content'])) {
  1529. // Content was not provided to us at init time.
  1530. // (This is allowed because for some backends, fetching
  1531. // the content may be expensive, and often is not wanted
  1532. // by the user.)
  1533. //
  1534. // In any case, now we need to get it.
  1535. $data['%content'] = $this->_get_content();
  1536. assert(is_string($data['%content']));
  1537. }
  1538. return $data['%content'];
  1539. }
  1540. function _get_content() {
  1541. $cache = &$this->_wikidb->_cache;
  1542. $pagename = $this->_pagename;
  1543. $version = $this->_version;
  1544. assert($version > 0);
  1545. $newdata = $cache->get_versiondata($pagename, $version, true);
  1546. if ($newdata) {
  1547. assert(is_string($newdata['%content']));
  1548. return $newdata['%content'];
  1549. }
  1550. else {
  1551. // else revision has been deleted... What to do?
  1552. return __sprintf("Oops! Revision %s of %s seems to have been deleted!",
  1553. $version, $pagename);
  1554. }
  1555. }
  1556. /**
  1557. * Get meta-data for this revision.
  1558. *
  1559. *
  1560. * @access public
  1561. *
  1562. * @param string $key Which meta-data to access.
  1563. *
  1564. * Some reserved revision meta-data keys are:
  1565. * <dl>
  1566. * <dt> 'mtime' <dd> Time this revision was created (seconds since midnight Jan 1, 1970.)
  1567. * The 'mtime' meta-value is normally set automatically by the database
  1568. * backend, but it may be specified explicitly when creating a new revision.
  1569. * <dt> orig_mtime
  1570. * <dd> To ensure consistency of RecentChanges, the mtimes of the versions
  1571. * of a page must be monotonically increasing. If an attempt is
  1572. * made to create a new revision with an mtime less than that of
  1573. * the preceeding revision, the new revisions timestamp is force
  1574. * to be equal to that of the preceeding revision. In that case,
  1575. * the originally requested mtime is preserved in 'orig_mtime'.
  1576. * <dt> '_supplanted' <dd> Time this revision ceased to be the most recent.
  1577. * This meta-value is <em>always</em> automatically maintained by the database
  1578. * backend. (It is set from the 'mtime' meta-value of the superceding
  1579. * revision.) '_supplanted' has a value of 'false' for the current revision.
  1580. *
  1581. * FIXME: this could be refactored:
  1582. * <dt> author
  1583. * <dd> Author of the page (as he should be reported in, e.g. RecentChanges.)
  1584. * <dt> author_id
  1585. * <dd> Authenticated author of a page. This is used to identify
  1586. * the distinctness of authors when cleaning old revisions from
  1587. * the database.
  1588. * <dt> 'is_minor_edit' <dd> Set if change was marked as a minor revision by the author.
  1589. * <dt> 'summary' <dd> Short change summary entered by page author.
  1590. * </dl>
  1591. *
  1592. * Meta-data keys must be valid C identifers (they have to start with a letter
  1593. * or underscore, and can contain only alphanumerics and underscores.)
  1594. *
  1595. * @return string The requested value, or false if the requested value
  1596. * is not defined.
  1597. */
  1598. function get($key) {
  1599. if (!$key || $key[0] == '%')
  1600. return false;
  1601. $data = &$this->_data;
  1602. return isset($data[$key]) ? $data[$key] : false;
  1603. }
  1604. /**
  1605. * Get all the revision page meta-data as a hash.
  1606. *
  1607. * @return hash The revision meta-data.
  1608. */
  1609. function getMetaData() {
  1610. $meta = array();
  1611. foreach ($this->_data as $key => $val) {
  1612. if (!empty($val) && $key[0] != '%')
  1613. $meta[$key] = $val;
  1614. }
  1615. return $meta;
  1616. }
  1617. /**
  1618. * Return a string representation of the revision.
  1619. *
  1620. * This is really only for debugging.
  1621. *
  1622. * @access public
  1623. *
  1624. * @return string Printable representation of the WikiDB_Page.
  1625. */
  1626. function asString () {
  1627. ob_start();
  1628. printf("[%s:%d\n", get_class($this), $this->get('version'));
  1629. print_r($this->_data);
  1630. echo $this->getPackedContent() . "\n]\n";
  1631. $strval = ob_get_contents();
  1632. ob_end_clean();
  1633. return $strval;
  1634. }
  1635. };
  1636. /**
  1637. * Class representing a sequence of WikiDB_Pages.
  1638. * TODO: Enhance to php5 iterators
  1639. * TODO:
  1640. * apply filters for options like 'sortby', 'limit', 'exclude'
  1641. * for simple queries like titleSearch, where the backend is not ready yet.
  1642. */
  1643. class WikiDB_PageIterator
  1644. {
  1645. function WikiDB_PageIterator(&$wikidb, &$iter, $options=false) {
  1646. $this->_iter = $iter; // a WikiDB_backend_iterator
  1647. $this->_wikidb = &$wikidb;
  1648. $this->_options = $options;
  1649. }
  1650. function count () {
  1651. return $this->_iter->count();
  1652. }
  1653. /**
  1654. * Get next WikiDB_Page in sequence.
  1655. *
  1656. * @access public
  1657. *
  1658. * @return WikiDB_Page The next WikiDB_Page in the sequence.
  1659. */
  1660. function next () {
  1661. if ( ! ($next = $this->_iter->next()) )
  1662. return false;
  1663. $pagename = &$next['pagename'];
  1664. if (!is_string($pagename)) { // Bug #1327912 fixed by Joachim Lous
  1665. $pagename = strval($pagename);
  1666. }
  1667. if (!$pagename) {
  1668. trigger_error('empty pagename in WikiDB_PageIterator::next()', E_USER_WARNING);
  1669. var_dump($next);
  1670. return false;
  1671. }
  1672. // There's always hits, but we cache only if more
  1673. // (well not with file, cvs and dba)
  1674. if (isset($next['pagedata']) and count($next['pagedata']) > 1) {
  1675. $this->_wikidb->_cache->cache_data($next);
  1676. // cache existing page id's since we iterate over all links in GleanDescription
  1677. // and need them later for LinkExistingWord
  1678. } elseif ($this->_options and array_key_exists('include_empty', $this->_options)
  1679. and !$this->_options['include_empty'] and isset($next['id'])) {
  1680. $this->_wikidb->_cache->_id_cache[$next['pagename']] = $next['id'];
  1681. }
  1682. return new WikiDB_Page($this->_wikidb, $pagename);
  1683. }
  1684. /**
  1685. * Release resources held by this iterator.
  1686. *
  1687. * The iterator may not be used after free() is called.
  1688. *
  1689. * There is no need to call free(), if next() has returned false.
  1690. * (I.e. if you iterate through all the pages in the sequence,
  1691. * you do not need to call free() --- you only need to call it
  1692. * if you stop before the end of the iterator is reached.)
  1693. *
  1694. * @access public
  1695. */
  1696. function free() {
  1697. $this->_iter->free();
  1698. }
  1699. function asArray() {
  1700. $result = array();
  1701. while ($page = $this->next())
  1702. $result[] = $page;
  1703. //$this->reset();
  1704. return $result;
  1705. }
  1706. /**
  1707. * Apply filters for options like 'sortby', 'limit', 'exclude'
  1708. * for simple queries like titleSearch, where the backend is not ready yet.
  1709. * Since iteration is usually destructive for SQL results,
  1710. * we have to generate a copy.
  1711. */
  1712. function applyFilters($options = false) {
  1713. if (!$options) $options = $this->_options;
  1714. if (isset($options['sortby'])) {
  1715. $array = array();
  1716. /* this is destructive */
  1717. while ($page = $this->next())
  1718. $result[] = $page->getName();
  1719. $this->_doSort($array, $options['sortby']);
  1720. }
  1721. /* the rest is not destructive.
  1722. * reconstruct a new iterator
  1723. */
  1724. $pagenames = array(); $i = 0;
  1725. if (isset($options['limit']))
  1726. $limit = $options['limit'];
  1727. else
  1728. $limit = 0;
  1729. if (isset($options['exclude']))
  1730. $exclude = $options['exclude'];
  1731. if (is_string($exclude) and !is_array($exclude))
  1732. $exclude = PageList::explodePageList($exclude, false, false, $limit);
  1733. foreach($array as $pagename) {
  1734. if ($limit and $i++ > $limit)
  1735. return new WikiDB_Array_PageIterator($pagenames);
  1736. if (!empty($exclude) and !in_array($pagename, $exclude))
  1737. $pagenames[] = $pagename;
  1738. elseif (empty($exclude))
  1739. $pagenames[] = $pagename;
  1740. }
  1741. return new WikiDB_Array_PageIterator($pagenames);
  1742. }
  1743. /* pagename only */
  1744. function _doSort(&$array, $sortby) {
  1745. $sortby = PageList::sortby($sortby, 'init');
  1746. if ($sortby == '+pagename')
  1747. sort($array, SORT_STRING);
  1748. elseif ($sortby == '-pagename')
  1749. rsort($array, SORT_STRING);
  1750. reset($array);
  1751. }
  1752. };
  1753. /**
  1754. * A class which represents a sequence of WikiDB_PageRevisions.
  1755. * TODO: Enhance to php5 iterators
  1756. */
  1757. class WikiDB_PageRevisionIterator
  1758. {
  1759. function WikiDB_PageRevisionIterator(&$wikidb, &$revisions, $options=false) {
  1760. $this->_revisions = $revisions;
  1761. $this->_wikidb = &$wikidb;
  1762. $this->_options = $options;
  1763. }
  1764. function count () {
  1765. return $this->_revisions->count();
  1766. }
  1767. /**
  1768. * Get next WikiDB_PageRevision in sequence.
  1769. *
  1770. * @access public
  1771. *
  1772. * @return WikiDB_PageRevision
  1773. * The next WikiDB_PageRevision in the sequence.
  1774. */
  1775. function next () {
  1776. if ( ! ($next = $this->_revisions->next()) )
  1777. return false;
  1778. //$this->_wikidb->_cache->cache_data($next);
  1779. $pagename = $next['pagename'];
  1780. $version = $next['version'];
  1781. $versiondata = $next['versiondata'];
  1782. if (DEBUG) {
  1783. if (!(is_string($pagename) and $pagename != '')) {
  1784. trigger_error("empty pagename",E_USER_WARNING);
  1785. return false;
  1786. }
  1787. } else assert(is_string($pagename) and $pagename != '');
  1788. if (DEBUG) {
  1789. if (!is_array($versiondata)) {
  1790. trigger_error("empty versiondata",E_USER_WARNING);
  1791. return false;
  1792. }
  1793. } else assert(is_array($versiondata));
  1794. if (DEBUG) {
  1795. if (!($version > 0)) {
  1796. trigger_error("invalid version",E_USER_WARNING);
  1797. return false;
  1798. }
  1799. } else assert($version > 0);
  1800. return new WikiDB_PageRevision($this->_wikidb, $pagename, $version,
  1801. $versiondata);
  1802. }
  1803. /**
  1804. * Release resources held by this iterator.
  1805. *
  1806. * The iterator may not be used after free() is called.
  1807. *
  1808. * There is no need to call free(), if next() has returned false.
  1809. * (I.e. if you iterate through all the revisions in the sequence,
  1810. * you do not need to call free() --- you only need to call it
  1811. * if you stop before the end of the iterator is reached.)
  1812. *
  1813. * @access public
  1814. */
  1815. function free() {
  1816. $this->_revisions->free();
  1817. }
  1818. function asArray() {
  1819. $result = array();
  1820. while ($rev = $this->next())
  1821. $result[] = $rev;
  1822. $this->free();
  1823. return $result;
  1824. }
  1825. };
  1826. /** pseudo iterator
  1827. */
  1828. class WikiDB_Array_PageIterator
  1829. {
  1830. function WikiDB_Array_PageIterator($pagenames) {
  1831. global $request;
  1832. $this->_dbi = $request->getDbh();
  1833. $this->_pages = $pagenames;
  1834. reset($this->_pages);
  1835. }
  1836. function next() {
  1837. $c =& current($this->_pages);
  1838. next($this->_pages);
  1839. return $c !== false ? $this->_dbi->getPage($c) : false;
  1840. }
  1841. function count() {
  1842. return count($this->_pages);
  1843. }
  1844. function free() {}
  1845. function asArray() {
  1846. reset($this->_pages);
  1847. return $this->_pages;
  1848. }
  1849. }
  1850. class WikiDB_Array_generic_iter
  1851. {
  1852. function WikiDB_Array_generic_iter($result) {
  1853. // $result may be either an array or a query result
  1854. if (is_array($result)) {
  1855. $this->_array = $result;
  1856. } elseif (is_object($result)) {
  1857. $this->_array = $result->asArray();
  1858. } else {
  1859. $this->_array = array();
  1860. }
  1861. if (!empty($this->_array))
  1862. reset($this->_array);
  1863. }
  1864. function next() {
  1865. $c =& current($this->_array);
  1866. next($this->_array);
  1867. return $c !== false ? $c : false;
  1868. }
  1869. function count() {
  1870. return count($this->_array);
  1871. }
  1872. function free() {}
  1873. function asArray() {
  1874. if (!empty($this->_array))
  1875. reset($this->_array);
  1876. return $this->_array;
  1877. }
  1878. }
  1879. /**
  1880. * Data cache used by WikiDB.
  1881. *
  1882. * FIXME: Maybe rename this to caching_backend (or some such).
  1883. *
  1884. * @access private
  1885. */
  1886. class WikiDB_cache
  1887. {
  1888. // FIXME: beautify versiondata cache. Cache only limited data?
  1889. function WikiDB_cache (&$backend) {
  1890. $this->_backend = &$backend;
  1891. $this->_pagedata_cache = array();
  1892. $this->_versiondata_cache = array();
  1893. array_push ($this->_versiondata_cache, array());
  1894. $this->_glv_cache = array();
  1895. $this->_id_cache = array(); // formerly ->_dbi->_iwpcache (nonempty pages => id)
  1896. }
  1897. function close() {
  1898. $this->_pagedata_cache = array();
  1899. $this->_versiondata_cache = array();
  1900. $this->_glv_cache = array();
  1901. $this->_id_cache = array();
  1902. }
  1903. function get_pagedata($pagename) {
  1904. assert(is_string($pagename) && $pagename != '');
  1905. if (USECACHE) {
  1906. $cache = &$this->_pagedata_cache;
  1907. if (!isset($cache[$pagename]) || !is_array($cache[$pagename])) {
  1908. $cache[$pagename] = $this->_backend->get_pagedata($pagename);
  1909. if (empty($cache[$pagename]))
  1910. $cache[$pagename] = array();
  1911. }
  1912. return $cache[$pagename];
  1913. } else {
  1914. return $this->_backend->get_pagedata($pagename);
  1915. }
  1916. }
  1917. function update_pagedata($pagename, $newdata) {
  1918. assert(is_string($pagename) && $pagename != '');
  1919. $this->_backend->update_pagedata($pagename, $newdata);
  1920. if (USECACHE) {
  1921. if (!empty($this->_pagedata_cache[$pagename])
  1922. and is_array($this->_pagedata_cache[$pagename]))
  1923. {
  1924. $cachedata = &$this->_pagedata_cache[$pagename];
  1925. foreach($newdata as $key => $val)
  1926. $cachedata[$key] = $val;
  1927. } else
  1928. $this->_pagedata_cache[$pagename] = $newdata;
  1929. }
  1930. }
  1931. function invalidate_cache($pagename) {
  1932. unset ($this->_pagedata_cache[$pagename]);
  1933. unset ($this->_versiondata_cache[$pagename]);
  1934. unset ($this->_glv_cache[$pagename]);
  1935. unset ($this->_id_cache[$pagename]);
  1936. //unset ($this->_backend->_page_data);
  1937. }
  1938. function delete_page($pagename) {
  1939. $result = $this->_backend->delete_page($pagename);
  1940. $this->invalidate_cache($pagename);
  1941. return $result;
  1942. }
  1943. function purge_page($pagename) {
  1944. $result = $this->_backend->purge_page($pagename);
  1945. $this->invalidate_cache($pagename);
  1946. return $result;
  1947. }
  1948. // FIXME: ugly and wrong. may overwrite full cache with partial cache
  1949. function cache_data($data) {
  1950. ;
  1951. //if (isset($data['pagedata']))
  1952. // $this->_pagedata_cache[$data['pagename']] = $data['pagedata'];
  1953. }
  1954. function get_versiondata($pagename, $version, $need_content = false) {
  1955. // FIXME: Seriously ugly hackage
  1956. $readdata = false;
  1957. if (USECACHE) { //temporary - for debugging
  1958. assert(is_string($pagename) && $pagename != '');
  1959. // There is a bug here somewhere which results in an assertion failure at line 105
  1960. // of ArchiveCleaner.php It goes away if we use the next line.
  1961. //$need_content = true;
  1962. $nc = $need_content ? '1':'0';
  1963. $cache = &$this->_versiondata_cache;
  1964. if (!isset($cache[$pagename][$version][$nc])
  1965. || !(is_array ($cache[$pagename]))
  1966. || !(is_array ($cache[$pagename][$version])))
  1967. {
  1968. $cache[$pagename][$version][$nc] =
  1969. $this->_backend->get_versiondata($pagename, $version, $need_content);
  1970. $readdata = true;
  1971. // If we have retrieved all data, we may as well set the cache for
  1972. // $need_content = false
  1973. if ($need_content){
  1974. $cache[$pagename][$version]['0'] =& $cache[$pagename][$version]['1'];
  1975. }
  1976. }
  1977. $vdata = $cache[$pagename][$version][$nc];
  1978. } else {
  1979. $vdata = $this->_backend->get_versiondata($pagename, $version, $need_content);
  1980. $readdata = true;
  1981. }
  1982. if ($readdata && $vdata && !empty($vdata['%pagedata'])) {
  1983. $this->_pagedata_cache[$pagename] =& $vdata['%pagedata'];
  1984. }
  1985. return $vdata;
  1986. }
  1987. function set_versiondata($pagename, $version, $data) {
  1988. //unset($this->_versiondata_cache[$pagename][$version]);
  1989. $new = $this->_backend->set_versiondata($pagename, $version, $data);
  1990. // Update the cache
  1991. $this->_versiondata_cache[$pagename][$version]['1'] = $data;
  1992. $this->_versiondata_cache[$pagename][$version]['0'] = $data;
  1993. // Is this necessary?
  1994. unset($this->_glv_cache[$pagename]);
  1995. }
  1996. function update_versiondata($pagename, $version, $data) {
  1997. $new = $this->_backend->update_versiondata($pagename, $version, $data);
  1998. // Update the cache
  1999. $this->_versiondata_cache[$pagename][$version]['1'] = $data;
  2000. // FIXME: hack
  2001. $this->_versiondata_cache[$pagename][$version]['0'] = $data;
  2002. // Is this necessary?
  2003. unset($this->_glv_cache[$pagename]);
  2004. }
  2005. function delete_versiondata($pagename, $version) {
  2006. $new = $this->_backend->delete_versiondata($pagename, $version);
  2007. if (isset($this->_versiondata_cache[$pagename][$version]))
  2008. unset ($this->_versiondata_cache[$pagename][$version]);
  2009. // dirty latest version cache only if latest version gets deleted
  2010. if (isset($this->_glv_cache[$pagename]) and $this->_glv_cache[$pagename] == $version)
  2011. unset ($this->_glv_cache[$pagename]);
  2012. }
  2013. function get_latest_version($pagename) {
  2014. if (USECACHE) {
  2015. assert (is_string($pagename) && $pagename != '');
  2016. $cache = &$this->_glv_cache;
  2017. if (!isset($cache[$pagename])) {
  2018. $cache[$pagename] = $this->_backend->get_latest_version($pagename);
  2019. if (empty($cache[$pagename]))
  2020. $cache[$pagename] = 0;
  2021. }
  2022. return $cache[$pagename];
  2023. } else {
  2024. return $this->_backend->get_latest_version($pagename);
  2025. }
  2026. }
  2027. };
  2028. function _sql_debuglog($msg, $newline=true, $shutdown=false) {
  2029. static $fp = false;
  2030. static $i = 0;
  2031. if (!$fp) {
  2032. $stamp = strftime("%y%m%d-%H%M%S");
  2033. $fp = fopen("/tmp/sql-$stamp.log", "a");
  2034. register_shutdown_function("_sql_debuglog_shutdown_function");
  2035. } elseif ($shutdown) {
  2036. fclose($fp);
  2037. return;
  2038. }
  2039. if ($newline) fputs($fp, "[$i++] $msg");
  2040. else fwrite($fp, $msg);
  2041. }
  2042. function _sql_debuglog_shutdown_function() {
  2043. _sql_debuglog('',false,true);
  2044. }
  2045. // $Log: WikiDB.php,v $
  2046. // fix bug #1327912 numeric pagenames can break plugins (Joachim Lous)
  2047. // pass stoplist through iterator
  2048. //
  2049. // Revision 1.137 2005/10/12 06:16:18 rurban
  2050. // better From header
  2051. //
  2052. // Revision 1.136 2005/10/03 16:14:57 rurban
  2053. // improve description
  2054. //
  2055. // Revision 1.135 2005/09/11 14:19:44 rurban
  2056. // enable LIMIT support for fulltext search
  2057. //
  2058. // Revision 1.134 2005/09/10 21:28:10 rurban
  2059. // applyFilters hack to use filters after methods, which do not support them (titleSearch)
  2060. //
  2061. // Revision 1.133 2005/08/27 09:39:10 rurban
  2062. // dumphtml when not at admin page: dump the current or given page
  2063. //
  2064. // Revision 1.132 2005/08/07 10:10:07 rurban
  2065. // clean whole version cache
  2066. //
  2067. // Revision 1.131 2005/04/23 11:30:12 rurban
  2068. // allow emtpy WikiDB::getRevisionBefore(), for simplier templates (revert)
  2069. //
  2070. // Revision 1.130 2005/04/06 06:19:30 rurban
  2071. // Revert the previous wrong bugfix #1175761: USECACHE was mixed with WIKIDB_NOCACHE_MARKUP.
  2072. // Fix WIKIDB_NOCACHE_MARKUP in main (always set it) and clarify it in WikiDB
  2073. //
  2074. // Revision 1.129 2005/04/06 05:50:29 rurban
  2075. // honor !USECACHE for _cached_html, fixes #1175761
  2076. //
  2077. // Revision 1.128 2005/04/01 16:11:42 rurban
  2078. // just whitespace
  2079. //
  2080. // Revision 1.127 2005/02/18 20:43:40 uckelman
  2081. // WikiDB::genericWarnings() is no longer used.
  2082. //
  2083. // Revision 1.126 2005/02/04 17:58:06 rurban
  2084. // minor versioncache improvement. part 2/3 of Charles Corrigan cache patch. not sure about the 0/1 issue
  2085. //
  2086. // Revision 1.125 2005/02/03 05:08:39 rurban
  2087. // ref fix by Charles Corrigan
  2088. //
  2089. // Revision 1.124 2005/01/29 20:43:32 rurban
  2090. // protect against empty request: on some occasion this happens
  2091. //
  2092. // Revision 1.123 2005/01/25 06:58:21 rurban
  2093. // reformatting
  2094. //
  2095. // Revision 1.122 2005/01/20 10:18:17 rurban
  2096. // reformatting
  2097. //
  2098. // Revision 1.121 2005/01/04 20:25:01 rurban
  2099. // remove old [%pagedata][_cached_html] code
  2100. //
  2101. // Revision 1.120 2004/12/23 14:12:31 rurban
  2102. // dont email on unittest
  2103. //
  2104. // Revision 1.119 2004/12/20 16:05:00 rurban
  2105. // gettext msg unification
  2106. //
  2107. // Revision 1.118 2004/12/13 13:22:57 rurban
  2108. // new BlogArchives plugin for the new blog theme. enable default box method
  2109. // for all plugins. Minor search improvement.
  2110. //
  2111. // Revision 1.117 2004/12/13 08:15:09 rurban
  2112. // false is wrong. null might be better but lets play safe.
  2113. //
  2114. // Revision 1.116 2004/12/10 22:15:00 rurban
  2115. // fix $page->get('_cached_html)
  2116. // refactor upgrade db helper _convert_cached_html() to be able to call them from WikiAdminUtils also.
  2117. // support 2nd genericSqlQuery param (bind huge arg)
  2118. //
  2119. // Revision 1.115 2004/12/10 02:45:27 rurban
  2120. // SQL optimization:
  2121. // put _cached_html from pagedata into a new seperate blob, not huge serialized string.
  2122. // it is only rarelely needed: for current page only, if-not-modified
  2123. // but was extracted for every simple page iteration.
  2124. //
  2125. // Revision 1.114 2004/12/09 22:24:44 rurban
  2126. // optimize on _DEBUG_SQL only. but now again on every 50th request, not just save.
  2127. //
  2128. // Revision 1.113 2004/12/06 19:49:55 rurban
  2129. // enable action=remove which is undoable and seeable in RecentChanges: ADODB ony for now.
  2130. // renamed delete_page to purge_page.
  2131. // enable action=edit&version=-1 to force creation of a new version.
  2132. // added BABYCART_PATH config
  2133. // fixed magiqc in adodb.inc.php
  2134. // and some more docs
  2135. //
  2136. // Revision 1.112 2004/11/30 17:45:53 rurban
  2137. // exists_links backend implementation
  2138. //
  2139. // Revision 1.111 2004/11/28 20:39:43 rurban
  2140. // deactivate pagecache overwrite: it is wrong
  2141. //
  2142. // Revision 1.110 2004/11/26 18:39:01 rurban
  2143. // new regex search parser and SQL backends (90% complete, glob and pcre backends missing)
  2144. //
  2145. // Revision 1.109 2004/11/25 17:20:50 rurban
  2146. // and again a couple of more native db args: backlinks
  2147. //
  2148. // Revision 1.108 2004/11/23 13:35:31 rurban
  2149. // add case_exact search
  2150. //
  2151. // Revision 1.107 2004/11/21 11:59:16 rurban
  2152. // remove final \n to be ob_cache independent
  2153. //
  2154. // Revision 1.106 2004/11/20 17:35:56 rurban
  2155. // improved WantedPages SQL backends
  2156. // PageList::sortby new 3rd arg valid_fields (override db fields)
  2157. // WantedPages sql pager inexact for performance reasons:
  2158. // assume 3 wantedfrom per page, to be correct, no getTotal()
  2159. // support exclude argument for get_all_pages, new _sql_set()
  2160. //
  2161. // Revision 1.105 2004/11/20 09:16:27 rurban
  2162. // Fix bad-style Cut&Paste programming errors, detected by Charles Corrigan.
  2163. //
  2164. // Revision 1.104 2004/11/19 19:22:03 rurban
  2165. // ModeratePage part1: change status
  2166. //
  2167. // Revision 1.103 2004/11/16 17:29:04 rurban
  2168. // fix remove notification error
  2169. // fix creation + update id_cache update
  2170. //
  2171. // Revision 1.102 2004/11/11 18:31:26 rurban
  2172. // add simple backtrace on such general failures to get at least an idea where
  2173. //
  2174. // Revision 1.101 2004/11/10 19:32:22 rurban
  2175. // * optimize increaseHitCount, esp. for mysql.
  2176. // * prepend dirs to the include_path (phpwiki_dir for faster searches)
  2177. // * Pear_DB version logic (awful but needed)
  2178. // * fix broken ADODB quote
  2179. // * _extract_page_data simplification
  2180. //
  2181. // Revision 1.100 2004/11/10 15:29:20 rurban
  2182. // * requires newer Pear_DB (as the internal one): quote() uses now escapeSimple for strings
  2183. // * ACCESS_LOG_SQL: fix cause request not yet initialized
  2184. // * WikiDB: moved SQL specific methods upwards
  2185. // * new Pear_DB quoting: same as ADODB and as newer Pear_DB.
  2186. // fixes all around: WikiGroup, WikiUserNew SQL methods, SQL logging
  2187. //
  2188. // Revision 1.99 2004/11/09 17:11:05 rurban
  2189. // * revert to the wikidb ref passing. there's no memory abuse there.
  2190. // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively
  2191. // store page ids with getPageLinks (GleanDescription) of all existing pages, which
  2192. // are also needed at the rendering for linkExistingWikiWord().
  2193. // pass options to pageiterator.
  2194. // use this cache also for _get_pageid()
  2195. // This saves about 8 SELECT count per page (num all pagelinks).
  2196. // * fix passing of all page fields to the pageiterator.
  2197. // * fix overlarge session data which got broken with the latest ACCESS_LOG_SQL changes
  2198. //
  2199. // Revision 1.98 2004/11/07 18:34:29 rurban
  2200. // more logging fixes
  2201. //
  2202. // Revision 1.97 2004/11/07 16:02:51 rurban
  2203. // new sql access log (for spam prevention), and restructured access log class
  2204. // dbh->quote (generic)
  2205. // pear_db: mysql specific parts seperated (using replace)
  2206. //
  2207. // Revision 1.96 2004/11/05 22:32:15 rurban
  2208. // encode the subject to be 7-bit safe
  2209. //
  2210. // Revision 1.95 2004/11/05 20:53:35 rurban
  2211. // login cleanup: better debug msg on failing login,
  2212. // checked password less immediate login (bogo or anon),
  2213. // checked olduser pref session error,
  2214. // better PersonalPage without password warning on minimal password length=0
  2215. // (which is default now)
  2216. //
  2217. // Revision 1.94 2004/11/01 10:43:56 rurban
  2218. // seperate PassUser methods into seperate dir (memory usage)
  2219. // fix WikiUser (old) overlarge data session
  2220. // remove wikidb arg from various page class methods, use global ->_dbi instead
  2221. // ...
  2222. //
  2223. // Revision 1.93 2004/10/14 17:17:57 rurban
  2224. // remove dbi WikiDB_Page param: use global request object instead. (memory)
  2225. // allow most_popular sortby arguments
  2226. //
  2227. // Revision 1.92 2004/10/05 17:00:04 rurban
  2228. // support paging for simple lists
  2229. // fix RatingDb sql backend.
  2230. // remove pages from AllPages (this is ListPages then)
  2231. //
  2232. // Revision 1.91 2004/10/04 23:41:19 rurban
  2233. // delete notify: fix, @unset syntax error
  2234. //
  2235. // Revision 1.90 2004/09/28 12:50:22 rurban
  2236. // https://sourceforge.net/forum/forum.php?thread_id=1150924&forum_id=18929
  2237. //
  2238. // Revision 1.89 2004/09/26 10:54:42 rurban
  2239. // silence deferred check
  2240. //
  2241. // Revision 1.88 2004/09/25 18:16:40 rurban
  2242. // unset more unneeded _cached_html. (Guess this should fix sf.net now)
  2243. //
  2244. // Revision 1.87 2004/09/25 16:25:40 rurban
  2245. // notify on rename and remove (to be improved)
  2246. //
  2247. // Revision 1.86 2004/09/23 18:52:06 rurban
  2248. // only fortune at create
  2249. //
  2250. // Revision 1.85 2004/09/16 08:00:51 rurban
  2251. // just some comments
  2252. //
  2253. // Revision 1.84 2004/09/14 10:34:30 rurban
  2254. // fix TransformedText call to use refs
  2255. //
  2256. // Revision 1.83 2004/09/08 13:38:00 rurban
  2257. // improve loadfile stability by using markup=2 as default for undefined markup-style.
  2258. // use more refs for huge objects.
  2259. // fix debug=static issue in WikiPluginCached
  2260. //
  2261. // Revision 1.82 2004/09/06 12:08:49 rurban
  2262. // memory_limit on unix workaround
  2263. // VisualWiki: default autosize image
  2264. //
  2265. // Revision 1.81 2004/09/06 08:28:00 rurban
  2266. // rename genericQuery to genericSqlQuery
  2267. //
  2268. // Revision 1.80 2004/07/09 13:05:34 rurban
  2269. // just aesthetics
  2270. //
  2271. // Revision 1.79 2004/07/09 10:06:49 rurban
  2272. // Use backend specific sortby and sortable_columns method, to be able to
  2273. // select between native (Db backend) and custom (PageList) sorting.
  2274. // Fixed PageList::AddPageList (missed the first)
  2275. // Added the author/creator.. name to AllPagesBy...
  2276. // display no pages if none matched.
  2277. // Improved dba and file sortby().
  2278. // Use &$request reference
  2279. //
  2280. // Revision 1.78 2004/07/08 21:32:35 rurban
  2281. // Prevent from more warnings, minor db and sort optimizations
  2282. //
  2283. // Revision 1.77 2004/07/08 19:04:42 rurban
  2284. // more unittest fixes (file backend, metadata RatingsDb)
  2285. //
  2286. // Revision 1.76 2004/07/08 17:31:43 rurban
  2287. // improve numPages for file (fixing AllPagesTest)
  2288. //
  2289. // Revision 1.75 2004/07/05 13:56:22 rurban
  2290. // sqlite autoincrement fix
  2291. //
  2292. // Revision 1.74 2004/07/03 16:51:05 rurban
  2293. // optional DBADMIN_USER:DBADMIN_PASSWD for action=upgrade (if no ALTER permission)
  2294. // added atomic mysql REPLACE for PearDB as in ADODB
  2295. // fixed _lock_tables typo links => link
  2296. // fixes unserialize ADODB bug in line 180
  2297. //
  2298. // Revision 1.73 2004/06/29 08:52:22 rurban
  2299. // Use ...version() $need_content argument in WikiDB also:
  2300. // To reduce the memory footprint for larger sets of pagelists,
  2301. // we don't cache the content (only true or false) and
  2302. // we purge the pagedata (_cached_html) also.
  2303. // _cached_html is only cached for the current pagename.
  2304. // => Vastly improved page existance check, ACL check, ...
  2305. //
  2306. // Now only PagedList info=content or size needs the whole content, esp. if sortable.
  2307. //
  2308. // Revision 1.72 2004/06/25 14:15:08 rurban
  2309. // reduce memory footprint by caching only requested pagedate content (improving most page iterators)
  2310. //
  2311. // Revision 1.71 2004/06/21 16:22:30 rurban
  2312. // add DEFAULT_DUMP_DIR and HTML_DUMP_DIR constants, for easier cmdline dumps,
  2313. // fixed dumping buttons locally (images/buttons/),
  2314. // support pages arg for dumphtml,
  2315. // optional directory arg for dumpserial + dumphtml,
  2316. // fix a AllPages warning,
  2317. // show dump warnings/errors on DEBUG,
  2318. // don't warn just ignore on wikilens pagelist columns, if not loaded.
  2319. // RateIt pagelist column is called "rating", not "ratingwidget" (Dan?)
  2320. //
  2321. // Revision 1.70 2004/06/18 14:39:31 rurban
  2322. // actually check USECACHE
  2323. //
  2324. // Revision 1.69 2004/06/13 15:33:20 rurban
  2325. // new support for arguments owner, author, creator in most relevant
  2326. // PageList plugins. in WikiAdmin* via preSelectS()
  2327. //
  2328. // Revision 1.68 2004/06/08 21:03:20 rurban
  2329. // updated RssParser for XmlParser quirks (store parser object params in globals)
  2330. //
  2331. // Revision 1.67 2004/06/07 19:12:49 rurban
  2332. // fixed rename version=0, bug #966284
  2333. //
  2334. // Revision 1.66 2004/06/07 18:57:27 rurban
  2335. // fix rename: Change pagename in all linked pages
  2336. //
  2337. // Revision 1.65 2004/06/04 20:32:53 rurban
  2338. // Several locale related improvements suggested by Pierrick Meignen
  2339. // LDAP fix by John Cole
  2340. // reanable admin check without ENABLE_PAGEPERM in the admin plugins
  2341. //
  2342. // Revision 1.64 2004/06/04 16:50:00 rurban
  2343. // add random quotes to empty pages
  2344. //
  2345. // Revision 1.63 2004/06/04 11:58:38 rurban
  2346. // added USE_TAGLINES
  2347. //
  2348. // Revision 1.62 2004/06/03 22:24:41 rurban
  2349. // reenable admin check on !ENABLE_PAGEPERM, honor s=Wildcard arg, fix warning after Remove
  2350. //
  2351. // Revision 1.61 2004/06/02 17:13:48 rurban
  2352. // fix getRevisionBefore assertion
  2353. //
  2354. // Revision 1.60 2004/05/28 10:09:58 rurban
  2355. // fix bug #962117, incorrect init of auth_dsn
  2356. //
  2357. // Revision 1.59 2004/05/27 17:49:05 rurban
  2358. // renamed DB_Session to DbSession (in CVS also)
  2359. // added WikiDB->getParam and WikiDB->getAuthParam method to get rid of globals
  2360. // remove leading slash in error message
  2361. // added force_unlock parameter to File_Passwd (no return on stale locks)
  2362. // fixed adodb session AffectedRows
  2363. // added FileFinder helpers to unify local filenames and DATA_PATH names
  2364. // editpage.php: new edit toolbar javascript on ENABLE_EDIT_TOOLBAR
  2365. //
  2366. // Revision 1.58 2004/05/18 13:59:14 rurban
  2367. // rename simpleQuery to genericQuery
  2368. //
  2369. // Revision 1.57 2004/05/16 22:07:35 rurban
  2370. // check more config-default and predefined constants
  2371. // various PagePerm fixes:
  2372. // fix default PagePerms, esp. edit and view for Bogo and Password users
  2373. // implemented Creator and Owner
  2374. // BOGOUSERS renamed to BOGOUSER
  2375. // fixed syntax errors in signin.tmpl
  2376. //
  2377. // Revision 1.56 2004/05/15 22:54:49 rurban
  2378. // fixed important WikiDB bug with DEBUG > 0: wrong assertion
  2379. // improved SetAcl (works) and PagePerms, some WikiGroup helpers.
  2380. //
  2381. // Revision 1.55 2004/05/12 19:27:47 rurban
  2382. // revert wrong inline optimization.
  2383. //
  2384. // Revision 1.54 2004/05/12 10:49:55 rurban
  2385. // require_once fix for those libs which are loaded before FileFinder and
  2386. // its automatic include_path fix, and where require_once doesn't grok
  2387. // dirname(__FILE__) != './lib'
  2388. // upgrade fix with PearDB
  2389. // navbar.tmpl: remove spaces for IE &nbsp; button alignment
  2390. //
  2391. // Revision 1.53 2004/05/08 14:06:12 rurban
  2392. // new support for inlined image attributes: [image.jpg size=50x30 align=right]
  2393. // minor stability and portability fixes
  2394. //
  2395. // Revision 1.52 2004/05/06 19:26:16 rurban
  2396. // improve stability, trying to find the InlineParser endless loop on sf.net
  2397. //
  2398. // remove end-of-zip comments to fix sf.net bug #777278 and probably #859628
  2399. //
  2400. // Revision 1.51 2004/05/06 17:30:37 rurban
  2401. // CategoryGroup: oops, dos2unix eol
  2402. // improved phpwiki_version:
  2403. // pre -= .0001 (1.3.10pre: 1030.099)
  2404. // -p1 += .001 (1.3.9-p1: 1030.091)
  2405. // improved InstallTable for mysql and generic SQL versions and all newer tables so far.
  2406. // abstracted more ADODB/PearDB methods for action=upgrade stuff:
  2407. // backend->backendType(), backend->database(),
  2408. // backend->listOfFields(),
  2409. // backend->listOfTables(),
  2410. //
  2411. // Revision 1.50 2004/05/04 22:34:25 rurban
  2412. // more pdf support
  2413. //
  2414. // Revision 1.49 2004/05/03 11:16:40 rurban
  2415. // fixed sendPageChangeNotification
  2416. // subject rewording
  2417. //
  2418. // Revision 1.48 2004/04/29 23:03:54 rurban
  2419. // fixed sf.net bug #940996
  2420. //
  2421. // Revision 1.47 2004/04/29 19:39:44 rurban
  2422. // special support for formatted plugins (one-liners)
  2423. // like <small><plugin BlaBla ></small>
  2424. // iter->asArray() helper for PopularNearby
  2425. // db_session for older php's (no &func() allowed)
  2426. //
  2427. // Revision 1.46 2004/04/26 20:44:34 rurban
  2428. // locking table specific for better databases
  2429. //
  2430. // Revision 1.45 2004/04/20 00:06:03 rurban
  2431. // themable paging support
  2432. //
  2433. // Revision 1.44 2004/04/19 18:27:45 rurban
  2434. // Prevent from some PHP5 warnings (ref args, no :: object init)
  2435. // php5 runs now through, just one wrong XmlElement object init missing
  2436. // Removed unneccesary UpgradeUser lines
  2437. // Changed WikiLink to omit version if current (RecentChanges)
  2438. //
  2439. // Revision 1.43 2004/04/18 01:34:20 rurban
  2440. // protect most_popular from sortby=mtime
  2441. //
  2442. // Revision 1.42 2004/04/18 01:11:51 rurban
  2443. // more numeric pagename fixes.
  2444. // fixed action=upload with merge conflict warnings.
  2445. // charset changed from constant to global (dynamic utf-8 switching)
  2446. //
  2447. // Local Variables:
  2448. // mode: php
  2449. // tab-width: 8
  2450. // c-basic-offset: 4
  2451. // c-hanging-comment-ender-p: nil
  2452. // indent-tabs-mode: nil
  2453. // End:
  2454. ?>