|
From: <var...@us...> - 2021-06-22 09:09:12
|
Revision: 10312
http://sourceforge.net/p/phpwiki/code/10312
Author: vargenau
Date: 2021-06-22 09:09:11 +0000 (Tue, 22 Jun 2021)
Log Message:
-----------
Remove specific getPreferences and setPreferences for databases so that preferences work
Modified Paths:
--------------
trunk/lib/WikiUser/AdoDb.php
trunk/lib/WikiUser/PdoDb.php
trunk/lib/WikiUser/PearDb.php
trunk/lib/WikiUser.php
trunk/lib/plugin/UserPreferences.php
Modified: trunk/lib/WikiUser/AdoDb.php
===================================================================
--- trunk/lib/WikiUser/AdoDb.php 2021-06-21 15:24:45 UTC (rev 10311)
+++ trunk/lib/WikiUser/AdoDb.php 2021-06-22 09:09:11 UTC (rev 10312)
@@ -63,83 +63,6 @@
return $this;
}
- function getPreferences()
- {
- // override the generic slow method here for efficiency
- _AnonUser::getPreferences();
- $this->getAuthDbh();
- if (isset($this->_prefs->_select)) {
- $dbh = & $this->_auth_dbi;
- $rs = $dbh->Execute(sprintf($this->_prefs->_select, $dbh->qstr($this->_userid)));
- if ($rs->EOF) {
- $rs->Close();
- } else {
- $prefs_blob = @$rs->fields['prefs'];
- $rs->Close();
- if ($restored_from_db = $this->_prefs->retrieve($prefs_blob)) {
- $this->_prefs->updatePrefs($restored_from_db);
- return $this->_prefs;
- }
- }
- }
- if (!empty($this->_HomePagehandle)) {
- if ($restored_from_page = $this->_prefs->retrieve
- ($this->_HomePagehandle->get('pref'))
- ) {
- $this->_prefs->updatePrefs($restored_from_page);
- return $this->_prefs;
- }
- }
- return $this->_prefs;
- }
-
- function setPreferences($prefs, $id_only = false)
- {
- // if the prefs are changed
- if (_AnonUser::setPreferences($prefs, 1)) {
- global $request;
- $packed = $this->_prefs->store();
- //$user = $request->_user;
- //unset($user->_auth_dbi);
- if (!$id_only and isset($this->_prefs->_update)) {
- $this->getAuthDbh();
- $dbh = &$this->_auth_dbi;
- // check if the user already exists (not needed with mysql REPLACE)
- $rs = $dbh->Execute(sprintf($this->_prefs->_select, $dbh->qstr($this->_userid)));
- if ($rs->EOF) {
- $rs->Close();
- $prefs_blob = false;
- } else {
- $prefs_blob = @$rs->fields['prefs'];
- $rs->Close();
- }
- if ($prefs_blob) {
- $db_result = $dbh->Execute(sprintf($this->_prefs->_update,
- $dbh->qstr($packed),
- $dbh->qstr($this->_userid)));
- } else {
- // Otherwise, insert a record for them and set it to the defaults.
- $dbi = $request->getDbh();
- $this->_prefs->_insert = $this->prepare($dbi->getAuthParam('pref_insert'),
- array("pref_blob", "userid"));
- $db_result = $dbh->Execute(sprintf($this->_prefs->_insert,
- $dbh->qstr($packed),
- $dbh->qstr($this->_userid)));
- }
- $db_result->Close();
- // delete pageprefs:
- if ($this->_HomePagehandle and $this->_HomePagehandle->get('pref'))
- $this->_HomePagehandle->set('pref', '');
- } else {
- //store prefs in homepage, not in cookie
- if ($this->_HomePagehandle and !$id_only)
- $this->_HomePagehandle->set('pref', $packed);
- }
- return count($this->_prefs->unpack($packed));
- }
- return 0;
- }
-
function userExists()
{
/**
Modified: trunk/lib/WikiUser/PdoDb.php
===================================================================
--- trunk/lib/WikiUser/PdoDb.php 2021-06-21 15:24:45 UTC (rev 10311)
+++ trunk/lib/WikiUser/PdoDb.php 2021-06-22 09:09:11 UTC (rev 10312)
@@ -62,64 +62,6 @@
return $this;
}
- function getPreferences()
- {
- // override the generic slow method here for efficiency and not to
- // clutter the homepage metadata with prefs.
- _AnonUser::getPreferences();
- $this->getAuthDbh();
- if (isset($this->_prefs->_select)) {
- $dbh = &$this->_auth_dbi;
- $db_result = $dbh->query(sprintf($this->_prefs->_select, $dbh->quote($this->_userid)));
- // patched by fre...@pa...
- $prefs = $db_result->fetch(PDO::FETCH_BOTH);
- $prefs_blob = @$prefs["prefs"];
- if ($restored_from_db = $this->_prefs->retrieve($prefs_blob)) {
- $this->_prefs->updatePrefs($restored_from_db);
- return $this->_prefs;
- }
- }
- if (isset($this->_HomePagehandle) && $this->_HomePagehandle) {
- if ($restored_from_page = $this->_prefs->retrieve
- ($this->_HomePagehandle->get('pref'))
- ) {
- $this->_prefs->updatePrefs($restored_from_page);
- return $this->_prefs;
- }
- }
- return $this->_prefs;
- }
-
- function setPreferences($prefs, $id_only = false)
- {
- // if the prefs are changed
- if ($count = _AnonUser::setPreferences($prefs, 1)) {
- $this->getAuthDbh();
- $packed = $this->_prefs->store();
- if (!$id_only and isset($this->_prefs->_update)) {
- $dbh =& $this->_auth_dbi;
- try {
- $sth = $dbh->prepare($this->_prefs->_update);
- $sth->bindParam("prefs", $packed);
- $sth->bindParam("user", $this->_userid);
- $sth->execute();
- } catch (PDOException $e) {
- trigger_error("SQL Error: " . $e->getMessage(), E_USER_WARNING);
- return false;
- }
- //delete pageprefs:
- if (isset($this->_HomePagehandle) && $this->_HomePagehandle and $this->_HomePagehandle->get('pref'))
- $this->_HomePagehandle->set('pref', '');
- } else {
- //store prefs in homepage, not in cookie
- if (isset($this->_HomePagehandle) && $this->_HomePagehandle and !$id_only)
- $this->_HomePagehandle->set('pref', $packed);
- }
- return $count;
- }
- return 0;
- }
-
function userExists()
{
/**
Modified: trunk/lib/WikiUser/PearDb.php
===================================================================
--- trunk/lib/WikiUser/PearDb.php 2021-06-21 15:24:45 UTC (rev 10311)
+++ trunk/lib/WikiUser/PearDb.php 2021-06-22 09:09:11 UTC (rev 10312)
@@ -61,79 +61,6 @@
return $this;
}
- function getPreferences()
- {
- // override the generic slow method here for efficiency and not to
- // clutter the homepage metadata with prefs.
- _AnonUser::getPreferences();
- $this->getAuthDbh();
- if (isset($this->_prefs->_select)) {
- $dbh = &$this->_auth_dbi;
- $db_result = $dbh->query(sprintf($this->_prefs->_select, $dbh->quote($this->_userid)));
- // patched by fre...@pa...
- $prefs = $db_result->fetchRow();
- $prefs_blob = @$prefs["prefs"];
- if ($restored_from_db = $this->_prefs->retrieve($prefs_blob)) {
- $this->_prefs->updatePrefs($restored_from_db);
- return $this->_prefs;
- }
- }
- if (isset($this->_HomePagehandle) && $this->_HomePagehandle) {
- if ($restored_from_page = $this->_prefs->retrieve
- ($this->_HomePagehandle->get('pref'))
- ) {
- $this->_prefs->updatePrefs($restored_from_page);
- return $this->_prefs;
- }
- }
- return $this->_prefs;
- }
-
- function setPreferences($prefs, $id_only = false)
- {
- /**
- * @var WikiRequest $request
- */
- global $request;
-
- // if the prefs are changed
- if ($count = _AnonUser::setPreferences($prefs, 1)) {
- $this->getAuthDbh();
- $packed = $this->_prefs->store();
- if (!$id_only and isset($this->_prefs->_update)) {
- $dbh = &$this->_auth_dbi;
- // check if the user already exists (not needed with mysql REPLACE)
- $db_result = $dbh->query(sprintf($this->_prefs->_select,
- $dbh->quote($this->_userid)));
- $prefs = $db_result->fetchRow();
- $prefs_blob = @$prefs["prefs"];
- // If there are prefs for the user, update them.
- if ($prefs_blob != "") {
- $dbh->simpleQuery(sprintf($this->_prefs->_update,
- $dbh->quote($packed),
- $dbh->quote($this->_userid)));
- } else {
- // Otherwise, insert a record for them and set it to the defaults.
- // jo...@de...
- $dbi = $request->getDbh();
- $this->_prefs->_insert = $this->prepare($dbi->getAuthParam('pref_insert'),
- array("pref_blob", "userid"));
- $dbh->simpleQuery(sprintf($this->_prefs->_insert,
- $dbh->quote($packed), $dbh->quote($this->_userid)));
- }
- //delete pageprefs:
- if (isset($this->_HomePagehandle) && $this->_HomePagehandle and $this->_HomePagehandle->get('pref'))
- $this->_HomePagehandle->set('pref', '');
- } else {
- //store prefs in homepage, not in cookie
- if (isset($this->_HomePagehandle) && $this->_HomePagehandle and !$id_only)
- $this->_HomePagehandle->set('pref', $packed);
- }
- return $count;
- }
- return 0;
- }
-
function userExists()
{
/**
Modified: trunk/lib/WikiUser.php
===================================================================
--- trunk/lib/WikiUser.php 2021-06-21 15:24:45 UTC (rev 10311)
+++ trunk/lib/WikiUser.php 2021-06-22 09:09:11 UTC (rev 10312)
@@ -1099,29 +1099,6 @@
function getPreferences()
{
- if (!empty($this->_prefs->_method)) {
- if ($this->_prefs->_method == 'ADODB') {
- // FIXME: strange why this should be needed...
- include_once 'lib/WikiUser/Db.php';
- include_once 'lib/WikiUser/AdoDb.php';
- $user = new _AdoDbPassUser();
- $this->_prefs = $user->getPreferences();
- return $this->_prefs;
- } elseif ($this->_prefs->_method == 'SQL') {
- include_once 'lib/WikiUser/Db.php';
- include_once 'lib/WikiUser/PearDb.php';
- $user = new _PearDbPassUser();
- $this->_prefs = $user->getPreferences();
- return $this->_prefs;
- } elseif ($this->_prefs->_method == 'PDO') {
- include_once 'lib/WikiUser/Db.php';
- include_once 'lib/WikiUser/PdoDb.php';
- $user = new _PdoDbPassUser();
- $this->_prefs = $user->getPreferences();
- return $this->_prefs;
- }
- }
-
// We don't necessarily have to read the cookie first. Since
// the user has a password, the prefs stored in the homepage
// cannot be arbitrarily altered by other Bogo users.
@@ -1146,28 +1123,6 @@
*/
global $request;
- if (!empty($this->_prefs->_method)) {
- if ($this->_prefs->_method == 'ADODB') {
- // FIXME: strange why this should be needed...
- include_once 'lib/WikiUser/Db.php';
- include_once 'lib/WikiUser/AdoDb.php';
- $user = new _AdoDbPassUser();
- $this->_prefs = $user->setPreferences($prefs, $id_only);
- return $this->_prefs;
- } elseif ($this->_prefs->_method == 'SQL') {
- include_once 'lib/WikiUser/Db.php';
- include_once 'lib/WikiUser/PearDb.php';
- $user = new _PearDbPassUser();
- $this->_prefs = $user->setPreferences($prefs, $id_only);
- return $this->_prefs;
- } elseif ($this->_prefs->_method == 'PDO') {
- include_once 'lib/WikiUser/Db.php';
- include_once 'lib/WikiUser/PdoDb.php';
- $user = new _PdoDbPassUser();
- $this->_prefs = $user->setPreferences($prefs, $id_only);
- return $this->_prefs;
- }
- }
if ($updated = _AnonUser::setPreferences($prefs, $id_only)) {
// Encode only the _prefs array of the UserPreference object
// If no DB method exists to store the prefs we must store it in the page, not in the cookies.
Modified: trunk/lib/plugin/UserPreferences.php
===================================================================
--- trunk/lib/plugin/UserPreferences.php 2021-06-21 15:24:45 UTC (rev 10311)
+++ trunk/lib/plugin/UserPreferences.php 2021-06-22 09:09:11 UTC (rev 10312)
@@ -87,9 +87,8 @@
}
if ((!isActionPage($request->getArg('pagename'))
and (!isset($user->_prefs->_method)
- or !in_array($user->_prefs->_method, array('ADODB', 'SQL', 'PDO'))))
or (in_array($request->getArg('action'), array('zip', 'ziphtml', 'dumphtml')))
- or (is_a($user, '_ForbiddenUser'))
+ or (is_a($user, '_ForbiddenUser'))))
) {
$no_args = $this->getDefaultArguments();
$no_args['errmsg'] = HTML::p(array('class' => 'error'),
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|