[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] CVS: wiki/lib category.php,1.2,1.3 db.php,1.2,1.3 def
From: |
Ralf Becker <address@hidden> |
Subject: |
[Phpgroupware-cvs] CVS: wiki/lib category.php,1.2,1.3 db.php,1.2,1.3 defaults.php,1.2,1.3 defaults.php.backup,1.1.3.1,1.2 diff.php,1.2,1.3 headers.php,1.2,1.3 init.php,1.2,1.3 main.php,1.2,1.3 messages.php,1.2,1.3 page.php,1.2,1.3 pagestore.php,1.2,1.3 rate.php,1.2,1.3 |
Date: |
Mon, 03 Mar 2003 09:16:27 -0500 |
Update of /cvsroot/phpgroupware/wiki/lib
In directory subversions:/tmp/cvs-serv15091/lib
Modified Files:
category.php db.php defaults.php defaults.php.backup diff.php
headers.php init.php main.php messages.php page.php
pagestore.php rate.php
Log Message:
first version of phpgw port, includes:
- automatic install by setup(3)
- some example data
Index: category.php
===================================================================
RCS file: /cvsroot/phpgroupware/wiki/lib/category.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
Index: db.php
===================================================================
RCS file: /cvsroot/phpgroupware/wiki/lib/db.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** db.php 3 Mar 2003 13:37:05 -0000 1.2
--- db.php 3 Mar 2003 14:16:24 -0000 1.3
***************
*** 1,40 ****
! <?php
! // $Id$
!
! // MySQL database abstractor. It should be easy to port this to other
! // databases, such as PostgreSQL.
! class WikiDB
! {
! var $handle;
!
! function WikiDB($persistent, $server, $user, $pass, $database)
! {
! global $ErrorDatabaseConnect, $ErrorDatabaseSelect;
!
! if($persistent)
! { $this->handle = mysql_pconnect($server, $user, $pass); }
! else
! { $this->handle = mysql_connect($server, $user, $pass); }
!
! if($this->handle <= 0)
! { die($ErrorDatabaseConnect); }
!
! if(mysql_select_db($database, $this->handle) == false)
! { die($ErrorDatabaseSelect); }
! }
!
! function query($text)
! {
! global $ErrorDatabaseQuery;
!
! if(!($qid = mysql_query($text, $this->handle)))
! { die($ErrorDatabaseQuery); }
! return $qid;
! }
!
! function result($qid)
! {
! return mysql_fetch_row($qid);
! }
! }
! ?>
--- 1,47 ----
! <?php
! // $Id$
!
! // MySQL database abstractor. It should be easy to port this to other
! // databases, such as PostgreSQL.
! class WikiDB
! {
! var $handle;
!
! function WikiDB($persistent, $server, $user, $pass, $database)
! {
! /*
! global $ErrorDatabaseConnect, $ErrorDatabaseSelect;
!
! if($persistent)
! { $this->handle = mysql_pconnect($server, $user, $pass); }
! else
! { $this->handle = mysql_connect($server, $user, $pass); }
!
! if($this->handle <= 0)
! { die($ErrorDatabaseConnect); }
!
! if(mysql_select_db($database, $this->handle) == false)
! { die($ErrorDatabaseSelect); }
! */
! $this->handle = $GLOBALS['phpgw']->db;
! }
!
! function query($text,$line='',$file='')
! {
! /*
! global $ErrorDatabaseQuery;
!
! if(!($qid = mysql_query($text, $this->handle)))
! { die($ErrorDatabaseQuery.", '$text'"); }
! return $qid;
! */
! return $this->handle->query($text,$line,$file);
! }
!
! function result($qid)
! {
! // return mysql_fetch_row($qid);
! return $this->handle->next_record() ? $this->handle->Record : False;
! }
! }
! ?>
Index: defaults.php
===================================================================
RCS file: /cvsroot/phpgroupware/wiki/lib/defaults.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
Index: defaults.php.backup
===================================================================
RCS file: /cvsroot/phpgroupware/wiki/lib/defaults.php.backup,v
retrieving revision 1.1.3.1
retrieving revision 1.2
diff -C2 -r1.1.3.1 -r1.2
Index: diff.php
===================================================================
RCS file: /cvsroot/phpgroupware/wiki/lib/diff.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** diff.php 3 Mar 2003 13:37:05 -0000 1.2
--- diff.php 3 Mar 2003 14:16:24 -0000 1.3
***************
*** 1,40 ****
! <?php
! // $Id$
!
! // Compute the difference between two sets of text.
! function diff_compute($text1, $text2)
! {
! global $TempDir, $DiffCmd, $ErrorCreatingTemp, $ErrorWritingTemp;
!
! $num = posix_getpid(); // Comment if running on Windows.
! // $num = rand(); // Uncomment if running on Windows.
!
! $temp1 = $TempDir . '/wiki_' . $num . '_1.txt';
! $temp2 = $TempDir . '/wiki_' . $num . '_2.txt';
!
! if(!($h1 = fopen($temp1, 'w')) || !($h2 = fopen($temp2, 'w')))
! { die($ErrorCreatingTemp); }
!
! if(fwrite($h1, $text1) < 0 || fwrite($h2, $text2) < 0)
! { die($ErrorWritingTemp); }
!
! fclose($h1);
! fclose($h2);
!
! $diff = `$DiffCmd $temp1 $temp2`;
!
! unlink($temp1);
! unlink($temp2);
!
! return $diff;
! }
!
! // Parse diff output into nice HTML.
! function diff_parse($text)
! {
! global $DiffEngine;
!
! return parseText($text, $DiffEngine, '');
! }
!
! ?>
--- 1,41 ----
! <?php
! // $Id$
!
! // Compute the difference between two sets of text.
! function diff_compute($text1, $text2)
! {
! global $TempDir, $DiffCmd, $ErrorCreatingTemp, $ErrorWritingTemp;
!
! //$num = rand(); // Comment if running on Windows.
! // $num = rand(); // Uncomment if running on Windows.
! $num = strncmp(PHP_OS,'WIN',3) ? posix_getpid() : rand();
!
! $temp1 = $TempDir . '/wiki_' . $num . '_1.txt';
! $temp2 = $TempDir . '/wiki_' . $num . '_2.txt';
!
! if(!($h1 = fopen($temp1, 'w')) || !($h2 = fopen($temp2, 'w')))
! { die($ErrorCreatingTemp); }
!
! if(fwrite($h1, $text1) < 0 || fwrite($h2, $text2) < 0)
! { die($ErrorWritingTemp); }
!
! fclose($h1);
! fclose($h2);
!
! $diff = `$DiffCmd $temp1 $temp2`;
!
! unlink($temp1);
! unlink($temp2);
!
! return $diff;
! }
!
! // Parse diff output into nice HTML.
! function diff_parse($text)
! {
! global $DiffEngine;
!
! return parseText($text, $DiffEngine, '');
! }
!
! ?>
Index: headers.php
===================================================================
RCS file: /cvsroot/phpgroupware/wiki/lib/headers.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
Index: init.php
===================================================================
RCS file: /cvsroot/phpgroupware/wiki/lib/init.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
Index: main.php
===================================================================
RCS file: /cvsroot/phpgroupware/wiki/lib/main.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
Index: messages.php
===================================================================
RCS file: /cvsroot/phpgroupware/wiki/lib/messages.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
Index: page.php
===================================================================
RCS file: /cvsroot/phpgroupware/wiki/lib/page.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** page.php 3 Mar 2003 13:37:05 -0000 1.2
--- page.php 3 Mar 2003 14:16:24 -0000 1.3
***************
*** 1,97 ****
! <?php
! // $Id$
!
! // Abstractor to read and write wiki pages.
! class WikiPage
! {
! var $name = ''; // Name of page.
! var $dbname = ''; // Name used in DB queries.
! var $text = ''; // Page's text in wiki markup form.
! var $time = ''; // Page's modification time.
! var $hostname = ''; // Hostname of last editor.
! var $username = ''; // Username of last editor.
! var $comment = ''; // Description of last edit.
! var $version = -1; // Version number of page.
! var $mutable = 1; // Whether page may be edited.
! var $exists = 0; // Whether page already exists.
! var $db; // Database object.
!
! function WikiPage($db_, $name_ = '')
! {
! $this->db = $db_;
! $this->name = $name_;
! $this->dbname = str_replace('\\', '\\\\', $name_);
! $this->dbname = str_replace('\'', '\\\'', $this->dbname);
! }
!
! // Check whether a page exists.
! // Returns: nonzero if page exists in database.
!
! function exists()
! {
! global $PgTbl;
!
! $qid = $this->db->query("SELECT MAX(version) FROM $PgTbl " .
! "WHERE title='$this->dbname'");
! return !!(($result = $this->db->result($qid)) && $result[0]);
! }
!
! // Read in a page's contents.
! // Returns: contents of the page.
!
! function read()
! {
! global $PgTbl;
!
! $query = "SELECT title, time, author, body, mutable, version, " .
! "username, comment " .
! "FROM $PgTbl WHERE title = '$this->dbname' ";
! if($this->version != -1)
! { $query = $query . "AND version = '$this->version'"; }
! else
! { $query = $query . "ORDER BY version DESC"; }
!
! $qid = $this->db->query($query);
!
! if(!($result = $this->db->result($qid)))
! { return ""; }
!
! $this->time = $result[1];
! $this->hostname = $result[2];
! $this->exists = 1;
! $this->version = $result[5];
! $this->mutable = ($result[4] == 'on');
! $this->username = $result[6];
! $this->text = $result[3];
! $this->comment = $result[7];
!
! return $this->text;
! }
!
! // Write out a page's contents.
! // Note: caller is responsible for performing locking.
! // Note: it is assumed that the 'time' member actually contains the
! // modification-time for the *previous* version. It is expected that
! // the previous version will have been read into the same object.
! // Yes, this is a tiny kludge. :-)
!
! function write()
! {
! global $PgTbl;
!
! $this->db->query("INSERT INTO $PgTbl (title, version, time, supercede, " .
! "mutable, username, author, comment, body) " .
! "VALUES('$this->dbname', $this->version, NULL, NULL, '" .
! ($this->mutable ? 'on' : 'off') . "', " .
! "'$this->username', '$this->hostname', " .
! "'$this->comment', '$this->text')");
!
! if($this->version > 1)
! {
! $this->db->query("UPDATE $PgTbl SET time=$this->time, " .
! "supercede=NULL WHERE title='$this->dbname' " .
! "AND version=" . ($this->version - 1));
! }
! }
! }
! ?>
--- 1,97 ----
! <?php
! // $Id$
!
! // Abstractor to read and write wiki pages.
! class WikiPage
! {
! var $name = ''; // Name of page.
! var $dbname = ''; // Name used in DB queries.
! var $text = ''; // Page's text in wiki markup form.
! var $time = ''; // Page's modification time.
! var $hostname = ''; // Hostname of last editor.
! var $username = ''; // Username of last editor.
! var $comment = ''; // Description of last edit.
! var $version = -1; // Version number of page.
! var $mutable = 1; // Whether page may be edited.
! var $exists = 0; // Whether page already exists.
! var $db; // Database object.
!
! function WikiPage($db_, $name_ = '')
! {
! $this->db = $db_;
! $this->name = $name_;
! $this->dbname = str_replace('\\', '\\\\', $name_);
! $this->dbname = str_replace('\'', '\\\'', $this->dbname);
! }
!
! // Check whether a page exists.
! // Returns: nonzero if page exists in database.
!
! function exists()
! {
! global $PgTbl;
!
! $qid = $this->db->query("SELECT MAX(version) FROM $PgTbl " .
! "WHERE title='$this->dbname'",__LINE__,__FILE__);
! return !!(($result = $this->db->result($qid)) && $result[0]);
! }
!
! // Read in a page's contents.
! // Returns: contents of the page.
!
! function read()
! {
! global $PgTbl;
!
! $query = "SELECT title, time, author, body, mutable, version, " .
! "username, comment " .
! "FROM $PgTbl WHERE title = '$this->dbname' ";
! if($this->version != -1)
! { $query = $query . "AND version = '$this->version'"; }
! else
! { $query = $query . "ORDER BY version DESC"; }
!
! $qid = $this->db->query($query,__LINE__,__FILE__);
!
! if(!($result = $this->db->result($qid)))
! { return ""; }
!
! $this->time = $result[1];
! $this->hostname = $result[2];
! $this->exists = 1;
! $this->version = $result[5];
! $this->mutable = ($result[4] == 'on');
! $this->username = $result[6];
! $this->text = $result[3];
! $this->comment = $result[7];
!
! return $this->text;
! }
!
! // Write out a page's contents.
! // Note: caller is responsible for performing locking.
! // Note: it is assumed that the 'time' member actually contains the
! // modification-time for the *previous* version. It is expected that
! // the previous version will have been read into the same object.
! // Yes, this is a tiny kludge. :-)
!
! function write()
! {
! global $PgTbl;
!
! $this->db->query("INSERT INTO $PgTbl (title, version, time, supercede, " .
! "mutable, username, author, comment, body) " .
! "VALUES('$this->dbname', $this->version,
".time().','.time(). /*NULL, NULL*/", '" .
! ($this->mutable ? 'on' : 'off') . "', " .
! "'$this->username', '$this->hostname', " .
! "'$this->comment', '$this->text')",__LINE__,__FILE__);
!
! if($this->version > 1)
! {
! $this->db->query("UPDATE $PgTbl SET time=$this->time, " .
! "supercede=".time()./*NULL*/" WHERE
title='$this->dbname' " .
! "AND version=" . ($this->version -
1),__LINE__,__FILE__);
! }
! }
! }
! ?>
Index: pagestore.php
===================================================================
RCS file: /cvsroot/phpgroupware/wiki/lib/pagestore.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** pagestore.php 3 Mar 2003 13:37:05 -0000 1.2
--- pagestore.php 3 Mar 2003 14:16:24 -0000 1.3
***************
*** 1,326 ****
! <?php
! // $Id$
!
! require('lib/db.php');
! require('lib/page.php');
!
! // Abstractor for the page database. Note that page.php contains the actual
! // code to read/write pages; this serves more general query functions.
! class PageStore
! {
! var $dbh;
!
! function PageStore()
! {
! global $DBPersist, $DBServer, $DBUser, $DBPasswd, $DBName;
!
! $this->dbh = new WikiDB($DBPersist, $DBServer, $DBUser, $DBPasswd,
$DBName);
! }
!
! // Create a page object.
! function page($name = '')
! {
! return new WikiPage($this->dbh, $name);
! }
!
! // Find text in the database.
! function find($text)
! {
! global $PgTbl;
!
! $qid = $this->dbh->query("SELECT t1.title, t1.body, t1.version, " .
! "MAX(t2.version) " .
! "FROM $PgTbl AS t1, $PgTbl AS t2 " .
! "WHERE t1.title = t2.title " .
! "GROUP BY t2.title, t1.version " .
! "HAVING t1.version = MAX(t2.version) " .
! "AND (body LIKE '%$text%' OR title LIKE
'%$text%')");
!
!
! $list = array();
! while(($result = $this->dbh->result($qid)))
! {
! $list[] = $result[0];
! }
!
! return $list;
! }
!
! // Retrieve a page's edit history.
! function history($page)
! {
! global $PgTbl;
!
! $page = addslashes($page);
! $qid = $this->dbh->query("SELECT time, author, version, username, " .
! "comment " .
! "FROM $PgTbl WHERE title='$page' " .
! "ORDER BY version DESC");
!
! $list = array();
! while(($result = $this->dbh->result($qid)))
! {
! $list[] = array($result[0], $result[1], $result[2], $result[3],
! $result[4]);
! }
!
! return $list;
! }
!
! // Look up an interwiki prefix.
! function interwiki($name)
! {
! global $IwTbl;
!
! $name = addslashes($name);
! $qid = $this->dbh->query("SELECT url FROM $IwTbl WHERE prefix='$name'");
! if(($result = $this->dbh->result($qid)))
! { return $result[0]; }
! return '';
! }
!
! // Clear all the links cached for a particular page.
! function clear_link($page)
! {
! global $LkTbl;
!
! $page = addslashes($page);
! $this->dbh->query("DELETE FROM $LkTbl WHERE page='$page'");
! }
!
! // Clear all the interwiki definitions for a particular page.
! function clear_interwiki($page)
! {
! global $IwTbl;
!
! $page = addslashes($page);
! $this->dbh->query("DELETE FROM $IwTbl WHERE where_defined='$page'");
! }
!
! // Clear all the sisterwiki definitions for a particular page.
! function clear_sisterwiki($page)
! {
! global $SwTbl;
!
! $page = addslashes($page);
! $this->dbh->query("DELETE FROM $SwTbl WHERE where_defined='$page'");
! }
!
! // Add a link for a given page to the link table.
! function new_link($page, $link)
! {
! // Assumption: this will only ever be called with one page per
! // script invocation. If this assumption should change, $links should
! // be made a 2-dimensional array.
!
! global $LkTbl;
! static $links = array();
!
! $page = addslashes($page);
! $link = addslashes($link);
!
! if(empty($links[$link]))
! {
! $this->dbh->query("INSERT INTO $LkTbl VALUES('$page', '$link', 1)");
! $links[$link] = 1;
! }
! else
! {
! $links[$link]++;
! $this->dbh->query("UPDATE $LkTbl SET count=" . $links[$link] .
! " WHERE page='$page' AND link='$link'");
! }
! }
!
! // Add an interwiki definition for a particular page.
! function new_interwiki($where_defined, $prefix, $url)
! {
! global $IwTbl;
!
! $url = str_replace("'", "\\'", $url);
! $url = str_replace("&", "&", $url);
!
! $where_defined = addslashes($where_defined);
!
! $qid = $this->dbh->query("SELECT where_defined FROM $IwTbl " .
! "WHERE prefix='$prefix'");
! if($this->dbh->result($qid))
! {
! $this->dbh->query("UPDATE $IwTbl SET where_defined='$where_defined', " .
! "url='$url' WHERE prefix='$prefix'");
! }
! else
! {
! $this->dbh->query("INSERT INTO $IwTbl(prefix, where_defined, url) " .
! "VALUES('$prefix', '$where_defined', '$url')");
! }
! }
!
! // Add a sisterwiki definition for a particular page.
! function new_sisterwiki($where_defined, $prefix, $url)
! {
! global $SwTbl;
!
! $url = str_replace("'", "\\'", $url);
! $url = str_replace("&", "&", $url);
!
! $where_defined = addslashes($where_defined);
!
! $qid = $this->dbh->query("SELECT where_defined FROM $SwTbl " .
! "WHERE prefix='$prefix'");
! if($this->dbh->result($qid))
! {
! $this->dbh->query("UPDATE $SwTbl SET where_defined='$where_defined', " .
! "url='$url' WHERE prefix='$prefix'");
! }
! else
! {
! $this->dbh->query("INSERT INTO $SwTbl(prefix, where_defined, url) " .
! "VALUES('$prefix', '$where_defined', '$url')");
! }
! }
!
! // Find all twins of a page at sisterwiki sites.
! function twinpages($page)
! {
! global $RemTbl;
!
! $list = array();
! $page = addslashes($page);
! $q2 = $this->dbh->query("SELECT site, page FROM $RemTbl " .
! "WHERE page LIKE '$page'");
! while(($twin = $this->dbh->result($q2)))
! { $list[] = array($twin[0], $twin[1]); }
!
! return $list;
! }
!
! // Lock the database tables.
! function lock()
! {
! global $PgTbl, $IwTbl, $SwTbl, $LkTbl;
!
! $this->dbh->query("LOCK TABLES $PgTbl WRITE, $IwTbl WRITE, $SwTbl WRITE,
" .
! "$LkTbl WRITE");
! }
!
! // Unlock the database tables.
! function unlock()
! {
! $this->dbh->query("UNLOCK TABLES");
! }
!
! // Retrieve a list of all of the pages in the wiki.
! function allpages()
! {
! global $PgTbl;
!
! $qid = $this->dbh->query("SELECT t1.title, t1.version, t1.author,
t1.time, " .
! "t1.username, LENGTH(t1.body), t1.comment, " .
! "t1.mutable, MAX(t2.version) " .
! "FROM $PgTbl AS t1, $PgTbl AS t2 " .
! "WHERE t1.title = t2.title " .
! "GROUP BY t2.title, t1.version " .
! "HAVING t1.version = MAX(t2.version)");
!
! $list = array();
! while(($result = $this->dbh->result($qid)))
! {
! $list[] = array($result[3], $result[0], $result[2], $result[4],
! $result[5], $result[6], $result[7] == 'on', $result[1]);
! }
!
! return $list;
! }
!
! // Retrieve a list of all new pages in the wiki.
! function newpages()
! {
! global $PgTbl;
!
! $qid = $this->dbh->query("SELECT title, author, time, username, " .
! "LENGTH(body), comment " .
! "FROM $PgTbl WHERE version=1");
!
! $list = array();
! while(($result = $this->dbh->result($qid)))
! {
! $list[] = array($result[2], $result[0], $result[1], $result[3],
! $result[4], $result[5]);
! }
!
! return $list;
! }
!
! // Return a list of all empty (deleted) pages in the wiki.
! function emptypages()
! {
! global $PgTbl;
!
! $qid = $this->dbh->query("SELECT t1.title, t1.version, t1.author, " .
! "t1.time, t1.username, t1.comment, t1.body, " .
! "MAX(t2.version) " .
! "FROM $PgTbl AS t1, $PgTbl AS t2 " .
! "WHERE t1.title = t2.title " .
! "GROUP BY t2.title, t1.version " .
! "HAVING t1.version = MAX(t2.version) " .
! "AND t1.body=''");
!
! $list = array();
! while(($result = $this->dbh->result($qid)))
! {
! $list[] = array($result[3], $result[0], $result[2],
! $result[4], 0, $result[5]);
! }
!
! return $list;
! }
!
! // Return a list of information about a particular set of pages.
! function givenpages($names)
! {
! global $PgTbl;
!
! $list = array();
! foreach($names as $page)
! {
! $esc_page = addslashes($page);
! $qid = $this->dbh->query("SELECT time, author, username, LENGTH(body),
" .
! "comment FROM $PgTbl WHERE title='$esc_page' "
.
! "ORDER BY version DESC");
!
! if(!($result = $this->dbh->result($qid)))
! { continue; }
!
! $list[] = array($result[0], $page, $result[1], $result[2],
! $result[3], $result[4]);
! }
!
! return $list;
! }
!
! // Expire old versions of pages.
! function maintain()
! {
! global $PgTbl, $RtTbl, $ExpireLen, $RatePeriod;
!
! $qid = $this->dbh->query("SELECT title, MAX(version) FROM $PgTbl " .
! "GROUP BY title");
!
! while(($result = $this->dbh->result($qid)))
! {
! $result[0] = addslashes($result[0]);
! $this->dbh->query("DELETE FROM $PgTbl WHERE title='$result[0]' AND " .
! "(version < $result[1] OR body='') AND " .
! "TO_DAYS(NOW()) - TO_DAYS(supercede) > $ExpireLen");
! }
!
! if($RatePeriod)
! {
! $this->dbh->query("DELETE FROM $RtTbl " .
! "WHERE ip NOT LIKE '%.*' " .
! "AND TO_DAYS(NOW()) > TO_DAYS(time)");
! }
! }
! }
! ?>
--- 1,328 ----
! <?php
! // $Id$
!
! require('lib/db.php');
! require('lib/page.php');
!
! // Abstractor for the page database. Note that page.php contains the actual
! // code to read/write pages; this serves more general query functions.
! class PageStore
! {
! var $dbh;
!
! function PageStore()
! {
! global $DBPersist, $DBServer, $DBUser, $DBPasswd, $DBName;
!
! $this->dbh = new WikiDB($DBPersist, $DBServer, $DBUser, $DBPasswd,
$DBName);
! }
!
! // Create a page object.
! function page($name = '')
! {
! return new WikiPage($this->dbh, $name);
! }
!
! // Find text in the database.
! function find($text)
! {
! global $PgTbl;
!
! $qid = $this->dbh->query("SELECT t1.title, t1.body, t1.version, " .
! "MAX(t2.version) " .
! "FROM $PgTbl AS t1, $PgTbl AS t2 " .
! "WHERE t1.title = t2.title " .
! "GROUP BY t2.title, t1.version " .
! "HAVING t1.version = MAX(t2.version) " .
! "AND (body LIKE '%$text%' OR title LIKE
'%$text%')");
!
!
! $list = array();
! while(($result = $this->dbh->result($qid)))
! {
! $list[] = $result[0];
! }
!
! return $list;
! }
!
! // Retrieve a page's edit history.
! function history($page)
! {
! global $PgTbl;
!
! $page = addslashes($page);
! $qid = $this->dbh->query("SELECT time, author, version, username, " .
! "comment " .
! "FROM $PgTbl WHERE title='$page' " .
! "ORDER BY version DESC");
!
! $list = array();
! while(($result = $this->dbh->result($qid)))
! {
! $list[] = array($result[0], $result[1], $result[2], $result[3],
! $result[4]);
! }
!
! return $list;
! }
!
! // Look up an interwiki prefix.
! function interwiki($name)
! {
! global $IwTbl;
!
! $name = addslashes($name);
! $qid = $this->dbh->query("SELECT url FROM $IwTbl WHERE
prefix='$name'",__LINE__,__FILE__);
! if(($result = $this->dbh->result($qid)))
! { return $result[0]; }
! return '';
! }
!
! // Clear all the links cached for a particular page.
! function clear_link($page)
! {
! global $LkTbl;
!
! $page = addslashes($page);
! $this->dbh->query("DELETE FROM $LkTbl WHERE
page='$page'",__LINE__,__FILE__);
! }
!
! // Clear all the interwiki definitions for a particular page.
! function clear_interwiki($page)
! {
! global $IwTbl;
!
! $page = addslashes($page);
! $this->dbh->query("DELETE FROM $IwTbl WHERE
where_defined='$page'",__LINE__,__FILE__);
! }
!
! // Clear all the sisterwiki definitions for a particular page.
! function clear_sisterwiki($page)
! {
! global $SwTbl;
!
! $page = addslashes($page);
! $this->dbh->query("DELETE FROM $SwTbl WHERE
where_defined='$page'",__LINE__,__FILE__);
! }
!
! // Add a link for a given page to the link table.
! function new_link($page, $link)
! {
! // Assumption: this will only ever be called with one page per
! // script invocation. If this assumption should change, $links should
! // be made a 2-dimensional array.
!
! global $LkTbl;
! static $links = array();
!
! $page = addslashes($page);
! $link = addslashes($link);
!
! if(empty($links[$link]))
! {
! $this->dbh->query("INSERT INTO $LkTbl VALUES('$page', '$link',
1)",__LINE__,__FILE__);
! $links[$link] = 1;
! }
! else
! {
! $links[$link]++;
! $this->dbh->query("UPDATE $LkTbl SET count=" . $links[$link] .
! " WHERE page='$page' AND
link='$link'",__LINE__,__FILE__);
! }
! }
!
! // Add an interwiki definition for a particular page.
! function new_interwiki($where_defined, $prefix, $url)
! {
! global $IwTbl;
!
! $url = str_replace("'", "\\'", $url);
! $url = str_replace("&", "&", $url);
!
! $where_defined = addslashes($where_defined);
!
! $qid = $this->dbh->query("SELECT where_defined FROM $IwTbl " .
! "WHERE prefix='$prefix'",__LINE__,__FILE__);
! if($this->dbh->result($qid))
! {
! $this->dbh->query("UPDATE $IwTbl SET where_defined='$where_defined', " .
! "url='$url' WHERE
prefix='$prefix'",__LINE__,__FILE__);
! }
! else
! {
! $this->dbh->query("INSERT INTO $IwTbl(prefix, where_defined, url) " .
! "VALUES('$prefix', '$where_defined',
'$url')",__LINE__,__FILE__);
! }
! }
!
! // Add a sisterwiki definition for a particular page.
! function new_sisterwiki($where_defined, $prefix, $url)
! {
! global $SwTbl;
!
! $url = str_replace("'", "\\'", $url);
! $url = str_replace("&", "&", $url);
!
! $where_defined = addslashes($where_defined);
!
! $qid = $this->dbh->query("SELECT where_defined FROM $SwTbl " .
! "WHERE prefix='$prefix'",__LINE__,__FILE__);
! if($this->dbh->result($qid))
! {
! $this->dbh->query("UPDATE $SwTbl SET where_defined='$where_defined', " .
! "url='$url' WHERE
prefix='$prefix'",__LINE__,__FILE__);
! }
! else
! {
! $this->dbh->query("INSERT INTO $SwTbl(prefix, where_defined, url) " .
! "VALUES('$prefix', '$where_defined',
'$url')",__LINE__,__FILE__);
! }
! }
!
! // Find all twins of a page at sisterwiki sites.
! function twinpages($page)
! {
! global $RemTbl;
!
! $list = array();
! $page = addslashes($page);
! $q2 = $this->dbh->query("SELECT site, page FROM $RemTbl " .
! "WHERE page LIKE '$page'",__LINE__,__FILE__);
! while(($twin = $this->dbh->result($q2)))
! { $list[] = array($twin[0], $twin[1]); }
!
! return $list;
! }
!
! // Lock the database tables.
! function lock()
! {
! global $PgTbl, $IwTbl, $SwTbl, $LkTbl;
!
! $this->dbh->query("LOCK TABLES $PgTbl WRITE, $IwTbl WRITE, $SwTbl WRITE,
" .
! "$LkTbl WRITE",__LINE__,__FILE__);
! }
!
! // Unlock the database tables.
! function unlock()
! {
! $this->dbh->query("UNLOCK TABLES",__LINE__,__FILE__);
! }
!
! // Retrieve a list of all of the pages in the wiki.
! function allpages()
! {
! global $PgTbl;
!
! $qid = $this->dbh->query("SELECT t1.title, t1.version, t1.author,
t1.time, " .
! "t1.username, LENGTH(t1.body), t1.comment, " .
! "t1.mutable, MAX(t2.version) " .
! "FROM $PgTbl AS t1, $PgTbl AS t2 " .
! "WHERE t1.title = t2.title " .
! "GROUP BY t2.title, t1.version " .
! "HAVING t1.version =
MAX(t2.version)",__LINE__,__FILE__);
!
! $list = array();
! while(($result = $this->dbh->result($qid)))
! {
! $list[] = array($result[3], $result[0], $result[2], $result[4],
! $result[5], $result[6], $result[7] == 'on', $result[1]);
! }
!
! return $list;
! }
!
! // Retrieve a list of all new pages in the wiki.
! function newpages()
! {
! global $PgTbl;
!
! $qid = $this->dbh->query("SELECT title, author, time, username, " .
! "LENGTH(body), comment " .
! "FROM $PgTbl WHERE version=1",__LINE__,__FILE__);
!
! $list = array();
! while(($result = $this->dbh->result($qid)))
! {
! $list[] = array($result[2], $result[0], $result[1], $result[3],
! $result[4], $result[5]);
! }
!
! return $list;
! }
!
! // Return a list of all empty (deleted) pages in the wiki.
! function emptypages()
! {
! global $PgTbl;
!
! $qid = $this->dbh->query("SELECT t1.title, t1.version, t1.author, " .
! "t1.time, t1.username, t1.comment, t1.body, " .
! "MAX(t2.version) " .
! "FROM $PgTbl AS t1, $PgTbl AS t2 " .
! "WHERE t1.title = t2.title " .
! "GROUP BY t2.title, t1.version " .
! "HAVING t1.version = MAX(t2.version) " .
! "AND t1.body=''",__LINE__,__FILE__);
!
! $list = array();
! while(($result = $this->dbh->result($qid)))
! {
! $list[] = array($result[3], $result[0], $result[2],
! $result[4], 0, $result[5]);
! }
!
! return $list;
! }
!
! // Return a list of information about a particular set of pages.
! function givenpages($names)
! {
! global $PgTbl;
!
! $list = array();
! foreach($names as $page)
! {
! $esc_page = addslashes($page);
! $qid = $this->dbh->query("SELECT time, author, username, LENGTH(body),
" .
! "comment FROM $PgTbl WHERE title='$esc_page' "
.
! "ORDER BY version DESC",__LINE__,__FILE__);
!
! if(!($result = $this->dbh->result($qid)))
! { continue; }
!
! $list[] = array($result[0], $page, $result[1], $result[2],
! $result[3], $result[4]);
! }
!
! return $list;
! }
!
! // Expire old versions of pages.
! function maintain()
! {
! global $PgTbl, $RtTbl, $ExpireLen, $RatePeriod;
!
! $qid = $this->dbh->query("SELECT title, MAX(version) FROM $PgTbl " .
! "GROUP BY title",__LINE__,__FILE__);
!
! while(($result = $this->dbh->result($qid)))
! {
! $result[0] = addslashes($result[0]);
! $this->dbh->query("DELETE FROM $PgTbl WHERE title='$result[0]' AND " .
! "(version < $result[1] OR body='') AND " .
! //"TO_DAYS(NOW()) - TO_DAYS(supercede) >
$ExpireLen",__LINE__,__FILE__);
!
intval(time()/86400-$ExpireLen)."<supercede/86400",__LINE__,__FILE__);
! }
!
! if($RatePeriod)
! {
! $this->dbh->query("DELETE FROM $RtTbl " .
! "WHERE ip NOT LIKE '%.*' " .
! //"AND TO_DAYS(NOW()) >
TO_DAYS(time)",__LINE__,__FILE__);
! "AND ".intval(time()/86400)." >
time/86400",__LINE__,__FILE__);
! }
! }
! }
! ?>
Index: rate.php
===================================================================
RCS file: /cvsroot/phpgroupware/wiki/lib/rate.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** rate.php 3 Mar 2003 13:37:05 -0000 1.2
--- rate.php 3 Mar 2003 14:16:24 -0000 1.3
***************
*** 1,114 ****
! <?php
! // $Id$
!
! // Perform a lookup on an IP addresses edit-rate.
! function rateCheck($db, $type)
! {
! global $RatePeriod, $RateView, $RateSearch, $RateEdit, $REMOTE_ADDR;
! global $ErrorDeniedAccess, $ErrorRateExceeded, $RtTbl;
!
! $fields = explode(".", $REMOTE_ADDR);
! if($RatePeriod == 0)
! { return; }
!
! $db->query("LOCK TABLES $RtTbl WRITE");
!
! // Make sure this IP address hasn't been excluded.
!
! $qid = $db->query("SELECT * FROM $RtTbl WHERE ip='$fields[0].*'");
! if($db->result($qid))
! { die($ErrorDeniedAccess); }
! $qid = $db->query("SELECT * FROM $RtTbl WHERE
ip='$fields[0].$fields[1].*'");
! if($db->result($qid))
! { die($ErrorDeniedAccess); }
! $qid = $db->query("SELECT * FROM $RtTbl " .
! "WHERE ip='$fields[0].$fields[1].$fields[2].*'");
! if($db->result($qid))
! { die($ErrorDeniedAccess); }
!
! // Now check how many more actions we can perform.
!
! $qid = $db->query("SELECT TIME_TO_SEC(NOW()) - TIME_TO_SEC(time), " .
! "viewLimit, searchLimit, editLimit FROM $RtTbl " .
! "WHERE ip='$REMOTE_ADDR'");
! if(!($result = $db->result($qid)))
! { $result = array(-1, $RateView, $RateSearch, $RateEdit); }
! else
! {
! if($result[0] < 0)
! { $result[0] = $RatePeriod; }
! $result[1] = min($result[1] + $result[0] * $RateView / $RatePeriod,
! $RateView);
! $result[2] = min($result[2] + $result[0] * $RateSearch / $RatePeriod,
! $RateSearch);
! $result[3] = min($result[3] + $result[0] * $RateEdit / $RatePeriod,
! $RateEdit);
! }
!
! if($type == 'view')
! { $result[1]--; }
! else if($type == 'search')
! { $result[2]--; }
! else if($type == 'edit')
! { $result[3]--; }
!
! if($result[1] < 0 || $result[2] < 0 || $result[3] < 0)
! { die($ErrorRateExceeded); }
!
! // Record this action.
!
! if($result[0] == -1)
! {
! $db->query("INSERT INTO $RtTbl VALUES('$REMOTE_ADDR', " .
! "NULL, $result[1], $result[2], $result[3])");
! }
! else
! {
! $db->query("UPDATE $RtTbl SET viewLimit=$result[1], " .
! "searchLimit=$result[2], editLimit=$result[3] " .
! "WHERE ip='$REMOTE_ADDR'");
! }
!
! $db->query("UNLOCK TABLES");
! }
!
! // Return a list of blocked address ranges.
! function rateBlockList($db)
! {
! global $RatePeriod, $RtTbl;
!
! $list = array();
!
! if($RatePeriod == 0)
! { return $list; }
!
! $qid = $db->query("SELECT ip FROM $RtTbl");
! while(($result = $db->result($qid)))
! {
! if(preg_match('/^\\d+\\.(\\d+\\.(\\d+\\.)?)?\\*$/', $result[0]))
! { $list[] = $result[0]; }
! }
!
! return $list;
! }
!
! // Block an address range.
! function rateBlockAdd($db, $address)
! {
! global $RtTbl;
!
! if(!preg_match('/^\\d+\\.(\\d+\\.(\\d+\\.)?)?\\*$/', $address))
! { return; }
! $qid = $db->query("SELECT * FROM $RtTbl WHERE ip='$address'");
! if($db->result($qid))
! { return; }
! $db->query("INSERT INTO $RtTbl(ip) VALUES('$address')");
! }
!
! function rateBlockRemove($db, $address)
! {
! global $RtTbl;
!
! $db->query("DELETE FROM $RtTbl WHERE ip='$address'");
! }
! ?>
--- 1,118 ----
! <?php
! // $Id$
!
! // Perform a lookup on an IP addresses edit-rate.
! function rateCheck($db, $type)
! {
! global $RatePeriod, $RateView, $RateSearch, $RateEdit, $REMOTE_ADDR;
! global $ErrorDeniedAccess, $ErrorRateExceeded, $RtTbl;
!
! $fields = explode(".", $REMOTE_ADDR);
! if($RatePeriod == 0)
! { return; }
!
! $db->query("LOCK TABLES $RtTbl WRITE",__LINE__,__FILE__);
!
! // Make sure this IP address hasn't been excluded.
!
! $qid = $db->query("SELECT * FROM $RtTbl WHERE
ip='$fields[0].*'",__LINE__,__FILE__);
! if($db->result($qid))
! { die($ErrorDeniedAccess); }
! $qid = $db->query("SELECT * FROM $RtTbl WHERE
ip='$fields[0].$fields[1].*'",__LINE__,__FILE__);
! if($db->result($qid))
! { die($ErrorDeniedAccess); }
! $qid = $db->query("SELECT * FROM $RtTbl " .
! "WHERE
ip='$fields[0].$fields[1].$fields[2].*'",__LINE__,__FILE__);
! if($db->result($qid))
! { die($ErrorDeniedAccess); }
!
! // Now check how many more actions we can perform.
!
! $qid = $db->query(//"SELECT TIME_TO_SEC(NOW()) - TIME_TO_SEC(time), " .
! "SELECT time, " .
! "viewLimit, searchLimit, editLimit FROM $RtTbl " .
! "WHERE ip='$REMOTE_ADDR'",__LINE__,__FILE__);
!
! if(!($result = $db->result($qid)))
! { $result = array(-1, $RateView, $RateSearch, $RateEdit); }
! else
! {
! $result[0] = time()-$result[0];
! if($result[0] < 0)
! { $result[0] = $RatePeriod; }
! $result[1] = min($result[1] + $result[0] * $RateView / $RatePeriod,
! $RateView);
! $result[2] = min($result[2] + $result[0] * $RateSearch / $RatePeriod,
! $RateSearch);
! $result[3] = min($result[3] + $result[0] * $RateEdit / $RatePeriod,
! $RateEdit);
! }
!
! if($type == 'view')
! { $result[1]--; }
! else if($type == 'search')
! { $result[2]--; }
! else if($type == 'edit')
! { $result[3]--; }
!
! if($result[1] < 0 || $result[2] < 0 || $result[3] < 0)
! { die($ErrorRateExceeded); }
!
! // Record this action.
!
! if($result[0] == -1)
! {
! $db->query("INSERT INTO $RtTbl VALUES('$REMOTE_ADDR', " .
! time()./*"NULL*/", $result[1], $result[2],
$result[3])",__LINE__,__FILE__);
! }
! else
! {
! $db->query("UPDATE $RtTbl SET viewLimit=$result[1], " .
! "searchLimit=$result[2], editLimit=$result[3] " .
! ', time='.time().' '.
! "WHERE ip='$REMOTE_ADDR'",__LINE__,__FILE__);
! }
!
! $db->query("UNLOCK TABLES",__LINE__,__FILE__);
! }
!
! // Return a list of blocked address ranges.
! function rateBlockList($db)
! {
! global $RatePeriod, $RtTbl;
!
! $list = array();
!
! if($RatePeriod == 0)
! { return $list; }
!
! $qid = $db->query("SELECT ip FROM $RtTbl",__LINE__,__FILE__);
! while(($result = $db->result($qid)))
! {
! if(preg_match('/^\\d+\\.(\\d+\\.(\\d+\\.)?)?\\*$/', $result[0]))
! { $list[] = $result[0]; }
! }
!
! return $list;
! }
!
! // Block an address range.
! function rateBlockAdd($db, $address)
! {
! global $RtTbl;
!
! if(!preg_match('/^\\d+\\.(\\d+\\.(\\d+\\.)?)?\\*$/', $address))
! { return; }
! $qid = $db->query("SELECT * FROM $RtTbl WHERE
ip='$address'",__LINE__,__FILE__);
! if($db->result($qid))
! { return; }
! $db->query("INSERT INTO $RtTbl(ip,time)
VALUES('$address',".time().")",__LINE__,__FILE__);
! }
!
! function rateBlockRemove($db, $address)
! {
! global $RtTbl;
!
! $db->query("DELETE FROM $RtTbl WHERE ip='$address'",__LINE__,__FILE__);
! }
! ?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] CVS: wiki/lib category.php,1.2,1.3 db.php,1.2,1.3 defaults.php,1.2,1.3 defaults.php.backup,1.1.3.1,1.2 diff.php,1.2,1.3 headers.php,1.2,1.3 init.php,1.2,1.3 main.php,1.2,1.3 messages.php,1.2,1.3 page.php,1.2,1.3 pagestore.php,1.2,1.3 rate.php,1.2,1.3,
Ralf Becker <address@hidden> <=
- Prev by Date:
[Phpgroupware-cvs] CVS: wiki/setup - New directory
- Next by Date:
[Phpgroupware-cvs] CVS: wiki/template admin.php,1.2,1.3 common.php,1.2,1.3 conflict.php,1.2,1.3 diff.php,1.2,1.3 edit.php,1.2,1.3 find.php,1.2,1.3 history.php,1.2,1.3 prefs.php,1.2,1.3 preview.php,1.2,1.3 rss.php,1.2,1.3 save.php,1.2,1.3 view.php,1.2,1.3 wiki.css,1.2,1.3
- Previous by thread:
[Phpgroupware-cvs] CVS: wiki/setup - New directory
- Next by thread:
[Phpgroupware-cvs] CVS: wiki/template admin.php,1.2,1.3 common.php,1.2,1.3 conflict.php,1.2,1.3 diff.php,1.2,1.3 edit.php,1.2,1.3 find.php,1.2,1.3 history.php,1.2,1.3 prefs.php,1.2,1.3 preview.php,1.2,1.3 rss.php,1.2,1.3 save.php,1.2,1.3 view.php,1.2,1.3 wiki.css,1.2,1.3
- Index(es):