From 57d27f84940e5d4297e0291db6dad3df1e5d1f5d Mon Sep 17 00:00:00 2001 From: jdarwood007 Date: Sat, 29 Apr 2017 15:46:12 -0700 Subject: [PATCH] =?UTF-8?q?We=20should=20be=20able=20to=20support=20multip?= =?UTF-8?q?le=20databases=20by=20using=20SMF=E2=80=99s=20database=20layer.?= =?UTF-8?q?=20=20At=20this=20time=20Postgresql=20is=20untested?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jdarwood007 --- Auth_SMF.php | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/Auth_SMF.php b/Auth_SMF.php index d411bd4..9b81c05 100644 --- a/Auth_SMF.php +++ b/Auth_SMF.php @@ -112,6 +112,8 @@ $smf_settings['db_passwd'] = $db_passwd; $smf_settings['db_prefix'] = $db_prefix; $smf_settings['debug_wiki'] = $wgSMFDebug; +$smf_settings['sourcedir'] = $sourcedir; +$smf_settings['db_type'] = $db_type; /** * Check the SMF cookie and automatically log the user into the wiki. @@ -977,25 +979,25 @@ public function isGroupAllowed($username, &$user) */ public function connect() { - global $smf_settings; + global $smf_settings, $smcFunc; - // Connect to database. - $this->conn = @mysql_pconnect($smf_settings['db_server'], $smf_settings['db_user'], - $smf_settings['db_passwd'], true); + $db_type = !empty($smf_settings['db_type']) && file_exists($smf_settings['sourcedir'] . '/Subs-Db-' . $smf_settings['db_type'] . '.php') ? $smf_settings['db_type'] : 'mysql'; - // Check if we are connected to the database. - if (!$this->conn) - $this->mysqlerror("SMF was unable to connect to the database.
\n"); + if (!defined('SMF')) + define('SMF', 'WIKI'); + if (!isset($smcFunc)) + $smcFunc = array(); - // Select database: this assumes the wiki and smf are in the same database. - $db_selected = @mysql_select_db($smf_settings['db_name'], $this->conn); + require_once($smf_settings['sourcedir'] . '/Subs-Db-' . $smf_settings['db_type'] . '.php'); - // Check if we were able to select the database. - if (!$db_selected) - $this->mysqlerror("SMF was unable to connect to the database.
\n"); + $this->conn = smf_db_initiate($smf_settings['db_server'], $smf_settings['db_name'], $smf_settings['db_user'], $smf_settings['db_passwd'], $smf_settings['db_prefix']); // As of now, we don't suport anything other than UTF8 with SMF. - mysql_query('SET NAMES UTF8', $this->conn); + $smcFunc['db_query']('set_character_set', ' + SET NAMES UTF8', + array( + ) + ); } /** @@ -1006,7 +1008,7 @@ public function connect() */ public function query($query) { - $request = mysql_query($query, $this->conn); + $request = $smcFunc['db_query']('', $query, array(), $this->conn); if(!$request) $this->mysqlerror('Unable to view external table.'); @@ -1059,3 +1061,25 @@ function wfProfileSMFID($user, &$saveOptions) return true; } + +/** + * Because we don't fully load SMF, this doesn't exist, so handle this should an error occur.. + * + * @param string $query + * @return resource + */ +if (!function_exists('display_db_error')) +{ + function display_db_error() + { + global $wgSMFDebug; + + echo $message . "

\n\n"; + + // Only if we are debugging. + if ($wgSMFDebug) + echo 'mySQL error number: ', mysql_errno(), "
\n", 'mySQL error message: ', mysql_error(), "

\n\n"; + + exit; + } +} \ No newline at end of file