diff options
author | Brion Vibber <brion@users.mediawiki.org> | 2004-06-13 01:15:16 +0000 |
---|---|---|
committer | Brion Vibber <brion@users.mediawiki.org> | 2004-06-13 01:15:16 +0000 |
commit | 1d6017272668b85e6944039381854a3851b6ae01 (patch) | |
tree | 04f07e820d7f8ee252fbe5c1b1f8f0b84a3ab95b /includes/ObjectCache.php | |
parent | aeac600626ab9b92f8c09c919ba05f1e62d19cd8 (diff) | |
download | mediawikicore-1d6017272668b85e6944039381854a3851b6ae01.tar.gz mediawikicore-1d6017272668b85e6944039381854a3851b6ae01.zip |
Merge 1.3.0beta3 from HEAD
Notes
Notes:
http://mediawiki.org/wiki/Special:Code/MediaWiki/4051
Diffstat (limited to 'includes/ObjectCache.php')
-rw-r--r-- | includes/ObjectCache.php | 56 |
1 files changed, 23 insertions, 33 deletions
diff --git a/includes/ObjectCache.php b/includes/ObjectCache.php index 00864c6b16b1..ce511ff37b10 100644 --- a/includes/ObjectCache.php +++ b/includes/ObjectCache.php @@ -1,4 +1,6 @@ <?php +# $Id$ +# # Copyright (C) 2003-2004 Brion Vibber <brion@pobox.com> # http://www.mediawiki.org/ # @@ -69,8 +71,10 @@ class /* abstract */ BagOStuff { } function add($key, $value, $exptime=0) { - if( $this->get($key) === false ) + if( $this->get($key) == false ) { $this->set($key, $value, $exptime); + return true; + } } function add_multi($hash, $exptime=0) { @@ -114,7 +118,7 @@ class /* abstract */ BagOStuff { function _debug($text) { if($this->debugmode) - echo "\ndebug: $text\n"; + wfDebug("BagOStuff debug: $text\n"); } } @@ -187,9 +191,9 @@ class /* abstract */ SqlBagOStuff extends BagOStuff { $this->_debug("get: ** error: " . $this->_dberror($res) . " **"); return false; } - if($arr = $this->_fetchrow($res)) { - $this->_debug("get: retrieved data; exp time is " . $arr['exptime']); - return unserialize($arr['value']); + if($row=$this->_fetchobject($res)) { + $this->_debug("get: retrieved data; exp time is " . $row->exptime); + return unserialize($row->value); } else { $this->_debug("get: no matching rows"); } @@ -208,8 +212,8 @@ class /* abstract */ SqlBagOStuff extends BagOStuff { } $this->delete( $key ); $this->_query( - "INSERT INTO $0 (keyname,value,exptime) VALUES('$1','$2',$exp)", - $key, serialize(&$value)); + "INSERT INTO $0 (keyname,value,exptime) VALUES('$1','$2','$exp')", + $key, serialize($value)); return true; /* ? */ } @@ -230,7 +234,7 @@ class /* abstract */ SqlBagOStuff extends BagOStuff { $sql); } $res = $this->_doquery($sql); - if($res === false) { + if($res == false) { $this->_debug("query failed: " . $this->_dberror($res)); } return $res; @@ -269,7 +273,8 @@ class /* abstract */ SqlBagOStuff extends BagOStuff { function expireall() { /* Remove any items that have expired */ - $this->_query( "DELETE FROM $0 WHERE exptime<=NOW()" ); + $now=$this->_fromunixtime(time()); + $this->_query( "DELETE FROM $0 WHERE exptime<'$now'" ); } function deleteall() { @@ -278,42 +283,27 @@ class /* abstract */ SqlBagOStuff extends BagOStuff { } } -class MysqlBagOStuff extends SqlBagOStuff { +class MediaWikiBagOStuff extends SqlBagOStuff { function _doquery($sql) { - return mysql_query($sql); + return wfQuery($sql, DB_READ, "MediaWikiBagOStuff:_doquery"); } - function _fetchrow($result) { - return mysql_fetch_array($result); + function _fetchobject($result) { + return wfFetchObject($result); } function _freeresult($result) { - return mysql_free_result($result); + return wfFreeResult($result); } function _dberror($result) { - if($result) - return mysql_error($result); - else - return mysql_error(); + return wfLastError(); } - function _maxdatetime() { - return "'9999-12-31 12:59:59'"; + return "9999-12-31 12:59:59"; } - function _fromunixtime($ts) { - return "FROM_UNIXTIME($ts)"; + return gmdate( "Y-m-d H:i:s", $ts ); } - function _strencode($s) { - return mysql_escape_string($s); - } -} - -class MediaWikiBagOStuff extends MysqlBagOStuff { - function _doquery($sql) { - return wfQuery($sql, DB_READ, "MediaWikiBagOStuff:_doquery"); - } - function _freeresult($result) { - return wfFreeResult($result); + return wfStrEncode($s); } } |