From: <var...@us...> - 2014-12-04 16:12:59
|
Revision: 9418 http://sourceforge.net/p/phpwiki/code/9418 Author: vargenau Date: 2014-12-04 16:12:50 +0000 (Thu, 04 Dec 2014) Log Message: ----------- Harmonize lib/DbSession/*.php Modified Paths: -------------- trunk/lib/DbSession/ADODB.php trunk/lib/DbSession/PDO.php trunk/lib/DbSession/SQL.php trunk/lib/DbSession/dba.php Modified: trunk/lib/DbSession/ADODB.php =================================================================== --- trunk/lib/DbSession/ADODB.php 2014-12-04 15:51:47 UTC (rev 9417) +++ trunk/lib/DbSession/ADODB.php 2014-12-04 16:12:50 UTC (rev 9418) @@ -64,6 +64,7 @@ return $this->_dbh->Execute($sql); } + // adds surrounding quotes function quote($string) { return $this->_dbh->qstr($string); @@ -124,11 +125,12 @@ if (!empty($res) and preg_match('|^[a-zA-Z0-9/+=]+$|', $res)) $res = base64_decode($res); if (strlen($res) > 4000) { - trigger_error("Overlarge session data! " . strlen($res) . - " gt. 4000", E_USER_WARNING); + // trigger_error("Overlarge session data! ".strlen($res). " gt. 4000", E_USER_WARNING); $res = preg_replace('/s:6:"_cache";O:12:"WikiDB_cache".+}$/', "", $res); $res = preg_replace('/s:12:"_cached_html";s:.+",s:4:"hits"/', 's:4:"hits"', $res); - if (strlen($res) > 4000) $res = ''; + if (strlen($res) > 4000) { + $res = ''; + } } return $res; } @@ -232,7 +234,7 @@ return true; } - // WhoIsOnline support. + // WhoIsOnline support // TODO: ip-accesstime dynamic blocking API function currentSessions() { Modified: trunk/lib/DbSession/PDO.php =================================================================== --- trunk/lib/DbSession/PDO.php 2014-12-04 15:51:47 UTC (rev 9417) +++ trunk/lib/DbSession/PDO.php 2014-12-04 16:12:50 UTC (rev 9418) @@ -1,4 +1,23 @@ <?php +/* + * Copyright 2005 $ThePhpWikiProgrammingTeam + * + * This file is part of PhpWiki. + * + * PhpWiki is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * PhpWiki is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with PhpWiki; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ /** * Db sessions for PDO, based on pear DB Sessions. @@ -27,7 +46,7 @@ function & _connect() { - $dbh =& $this->_dbh; + $dbh = &$this->_dbh; if (!$dbh or !is_object($dbh)) { global $DBParams; $db = new WikiDB_backend_PDO($DBParams); @@ -42,6 +61,7 @@ return $this->_backend->query($sql); } + // adds surrounding quotes function quote($string) { return $this->_backend->quote($string); @@ -90,7 +110,6 @@ */ public function read($id) { - //$this->log("_read($id)"); $dbh = $this->_connect(); $table = $this->_table; $sth = $dbh->prepare("SELECT sess_data FROM $table WHERE sess_id=?"); @@ -105,8 +124,7 @@ $res = base64_decode($res); } if (strlen($res) > 4000) { - trigger_error("Overlarge session data! " . strlen($res) . - " gt. 4000", E_USER_WARNING); + // trigger_error("Overlarge session data! ".strlen($res). " gt. 4000", E_USER_WARNING); $res = preg_replace('/s:6:"_cache";O:12:"WikiDB_cache".+}$/', "", $res); $res = preg_replace('/s:12:"_cached_html";s:.+",s:4:"hits"/', 's:4:"hits"', $res); if (strlen($res) > 4000) { @@ -228,7 +246,7 @@ return true; } - // WhoIsOnline support. + // WhoIsOnline support // TODO: ip-accesstime dynamic blocking API function currentSessions() { Modified: trunk/lib/DbSession/SQL.php =================================================================== --- trunk/lib/DbSession/SQL.php 2014-12-04 15:51:47 UTC (rev 9417) +++ trunk/lib/DbSession/SQL.php 2014-12-04 16:12:50 UTC (rev 9418) @@ -1,7 +1,26 @@ <?php +/* + * Copyright 2005 $ThePhpWikiProgrammingTeam + * + * This file is part of PhpWiki. + * + * PhpWiki is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * PhpWiki is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with PhpWiki; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ -/** - * DB sessions for pear DB +/* + * Copyright 2005 $ThePhpWikiProgrammingTeam * * History * @@ -15,9 +34,8 @@ { public $_backend_type = "SQL"; - function __construct(&$dbh, $table) + function __construct($dbh, $table) { - $this->_dbh = $dbh; $this->_table = $table; @@ -106,16 +124,18 @@ $res = $dbh->getOne("SELECT sess_data FROM $table WHERE sess_id=$qid"); $this->_disconnect(); - if (DB::isError($res) || empty($res)) + if (DB::isError($res) || empty($res)) { return ''; + } if (is_a($dbh, 'DB_pgsql')) - //if (preg_match('|^[a-zA-Z0-9/+=]+$|', $res)) $res = base64_decode($res); if (strlen($res) > 4000) { // trigger_error("Overlarge session data! ".strlen($res). " gt. 4000", E_USER_WARNING); $res = preg_replace('/s:6:"_cache";O:12:"WikiDB_cache".+}$/', "", $res); $res = preg_replace('/s:12:"_cached_html";s:.+",s:4:"hits"/', 's:4:"hits"', $res); - if (strlen($res) > 4000) $res = ''; + if (strlen($res) > 4000) { + $res = ''; + } } return $res; } @@ -145,7 +165,6 @@ if (defined("WIKI_XMLRPC") or defined("WIKI_SOAP")) return false; $dbh = $this->_connect(); - //$dbh->unlock(false,1); $table = $this->_table; $qid = $dbh->quote($id); $qip = $dbh->quote($request->get('REMOTE_ADDR')); @@ -158,7 +177,7 @@ $sess_data = base64_encode($sess_data); $qdata = $dbh->quote($sess_data); - /* AffectedRows with sessions seems to be instable on certain platforms. + /* AffectedRows with sessions seems to be unstable on certain platforms. * Enable the safe and slow USE_SAFE_DBSESSION then. */ if (USE_SAFE_DBSESSION) { Modified: trunk/lib/DbSession/dba.php =================================================================== --- trunk/lib/DbSession/dba.php 2014-12-04 15:51:47 UTC (rev 9417) +++ trunk/lib/DbSession/dba.php 2014-12-04 16:12:50 UTC (rev 9418) @@ -1,4 +1,23 @@ <?php +/* + * Copyright 2005 $ThePhpWikiProgrammingTeam + * + * This file is part of PhpWiki. + * + * PhpWiki is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * PhpWiki is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with PhpWiki; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ /** DBA Sessions * session: @@ -15,7 +34,7 @@ { public $_backend_type = "dba"; - function __construct(&$dbh, $table) + function __construct($dbh, $table) { $this->_dbh = $dbh; ini_set('session.save_handler', 'user'); @@ -63,18 +82,41 @@ } } - function open($save_path, $session_name) + /** + * Opens a session. + * + * Actually this function is a fake for session_set_save_handle. + * @param string $save_path a path to stored files + * @param string $session_name a name of the concrete file + * @return boolean true just a variable to notify PHP that everything + * is good. + */ + public function open($save_path, $session_name) { $dbh = $this->_connect(); $dbh->open(); } - function close() + /** + * Closes a session. + * + * This function is called just after <i>write</i> call. + * + * @return boolean true just a variable to notify PHP that everything + * is good. + */ + public function close() { $this->_disconnect(); } - function read($id) + /** + * Reads the session data from DB. + * + * @param string $id an id of current session + * @return string + */ + public function read($id) { $dbh = $this->_connect(); $result = $dbh->get($id); @@ -84,14 +126,29 @@ list(, , $packed) = explode(':', $result, 3); $this->_disconnect(); if (strlen($packed) > 4000) { - trigger_error("Overlarge session data!", E_USER_WARNING); + // trigger_error("Overlarge session data!", E_USER_WARNING); $packed = ''; //$res = preg_replace('/s:6:"_cache";O:12:"WikiDB_cache".+}$/',"",$res); } return $packed; } - function write($id, $sess_data) + /** + * Saves the session data into DB. + * + * Just a comment: The "write" handler is not + * executed until after the output stream is closed. Thus, + * output from debugging statements in the "write" handler + * will never be seen in the browser. If debugging output + * is necessary, it is suggested that the debug output be + * written to a file instead. + * + * @param string $id + * @param string $sess_data + * @return boolean true if data saved successfully and false + * otherwise. + */ + public function write($id, $sess_data) { /** * @var WikiRequest $request @@ -120,7 +177,13 @@ return true; } - function gc($maxlifetime) + /** + * Cleans out all expired sessions. + * + * @param int $maxlifetime session's time to live. + * @return boolean true + */ + public function gc($maxlifetime) { $dbh = $this->_connect(); $threshold = time() - $maxlifetime; @@ -134,7 +197,7 @@ return true; } - // WhoIsOnline support. + // WhoIsOnline support // TODO: ip-accesstime dynamic blocking API function currentSessions() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |