|

- 帖子
- 35
- 积分
- 79
- 威望
- 0
- 金币
- 34 个
- 体力
- 50
- 注册时间
- 2005-8-20
|

修改过的代码
【修改过的文件】
请自行查找行号,我的修改变了
1、/extensions/Auth_UC/Auth_Discuz.php- <?php
- /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
- /**
- * This file makes MediaWiki use a SMF user database to
- * authenticate with. This forces users to have a SMF account
- * in order to log into the wiki. This should also force the user to
- * be in a group called wiki.
- *
- * This program 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.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @package MediaWiki
- * @subpackage Auth_SMF
- * @author Nicholas Dunnaway
- * @copyright 2004-2006 php|uber.leet
- * @license http://www.gnu.org/copyleft/gpl.html
- * @CVS: $Id: Auth_SMF.php,v 1.3 2007/04/05 22:17:56 nkd Exp $
- * @link http://uber.leetphp.com
- * @version $Revision: 1.3 $
- *
- *
- * @Modified By Hopesoft
- * @link http://www.51ajax.com
- * @2007-11-11
- *
- *
- * @Modified By outcrop
- * @email outcrop@163.com
- * @2008-04-07
- */
- error_reporting(E_ALL); // Debug
- include './extensions/Auth_UC/config.inc.php';
- include './extensions/Auth_UC/client/client.php';
- // First check if class has already been defined.
- if (!class_exists('AuthPlugin'))
- {
- /**
- * Auth Plugin
- *
- */
- require_once './includes/AuthPlugin.php';
- }
- /**
- * Handles the Authentication with the Discuz database.
- *
- * @package MediaWiki
- * @subpackage Auth_Discuz
- */
- class Auth_Discuz extends AuthPlugin
- {
- /**
- * Add a user to the external authentication database.
- * Return true if successful.
- *
- * NOTE: We are not allowed to add users to Discuz from the
- * wiki so this always returns false.
- *
- * @param User $user
- * @param string $password
- * @return bool
- * @access public
- */
- function addUser( $user, $password )
- {
- return false;
- }
- /**
- * Can users change their passwords?
- *
- * @return bool
- */
- function allowPasswordChange()
- {
- return true;
- }
- /**
- * Check if a username+password pair is a valid login.
- * The name will be normalized to MediaWiki's requirements, so
- * you might need to munge it (for instance, for lowercase initial
- * letters).
- *
- * @param string $username
- * @param string $password
- * @return bool
- * @access public
- * @todo Check if the password is being changed when it contains a slash or an escape char.
- */
- function authenticate($username, $password)
- {
- // Clean $username and force lowercase username.
- //echo "
- Authenticate Start";
- $username = htmlentities(strtolower($username), ENT_QUOTES, 'UTF-8');
- $username = str_replace(''', '\\\'', $username); // Allow apostrophes (Escape them though)
- //调用client的uc_user_login判断用户密码,由于MediaWiki为utf8编码,因此转换为GBK后判断,主要是中文ID
- list($uid, $username1, $password, $email) = uc_user_login(iconv("UTF-8", "GBK", $username), $password);
- setcookie('WIKI_auth', '', -86400);
- if ($uid > 0 && $this->isMemberOfWikiGroup($username)) {
- //用户登陆成功,设置 Cookie,加密直接用 uc_authcode 函数,用户使用自己的函数
- setcookie('WIKI_auth', uc_authcode($uid."\t".$username1, 'ENCODE'));
- //生成同步登录的代码
- //由于uc_user_synlogin返回string,必须要echo一下才能成功同步登陆
- echo uc_user_synlogin($uid);
- if(uc_pm_checknew($uid)) {
- //echo "You have new message....";
- }
- return true;
- }
- if ($uid== -1){
- echo "No this username for login, please confirm";
- return false;
- }
- if ($uid== -2){
- echo "assword Error";
- return false;
- }
- }
- /**
- * Return true if the wiki should create a new local account automatically
- * when asked to login a user who doesn't exist locally but does in the
- * external auth database.
- *
- * If you don't automatically create accounts, you must still create
- * accounts in some way. It's not possible to authenticate without
- * a local account.
- *
- * This is just a question, and shouldn't perform any actions.
- *
- * NOTE: I have set this to true to allow the wiki to create accounts.
- * Without an accout in the wiki database a user will never be
- * able to login and use the wiki. I think the password does not
- * matter as long as authenticate() returns true.
- *
- * @return bool
- * @access public
- */
- function autoCreate()
- {
- return true;
- }
- /**
- * Check to see if external accounts can be created.
- * Return true if external accounts can be created.
- *
- * NOTE: We are not allowed to add users to Discuz from the
- * wiki so this always returns false.
- *
- * @return bool
- * @access public
- */
- function canCreateAccounts()
- {
- return false;
- }
-
- /**
- * Connect to the database. All of these settings are from the
- * LocalSettings.php file. This assumes that the Discuz uses the same
- * database/server as the wiki.
- *
- * {@source }
- * @return resource
- */
- function connect()
- {
- //echo "
- ----connecting----";
- $dbcharset = $GLOBALS['wgDiscuz_Charset'];
- //echo "Charset: ".$dbcharset;
-
- // Check if the Discuz tables are in a different database then the Wiki.
- if ($GLOBALS['wgDiscuz_UseExtDatabase'] == true) {
- // Connect to database. I supress the error here.
- $fresMySQLConnection = @mysql_connect($GLOBALS['wgDiscuz_MySQL_Host'],
- $GLOBALS['wgDiscuz_MySQL_Username'],
- $GLOBALS['wgDiscuz_MySQL_Password'],
- true);
- if (mysql_get_server_info()>= 4.1)
- if($dbcharset) {
- mysql_query("SET character_set_connection=$dbcharset, character_set_results=$dbcharset, character_set_client=binary");
- }
-
- // Check if we are connected to the database.
- if (!$fresMySQLConnection)
- {
- $this->mySQLError('There was a problem when connecting to the Discuz database.
- ' .
- 'Check your Host, Username, and Password settings.
- ');
- }
- // Select Database
- $db_selected = mysql_select_db($GLOBALS['wgDiscuz_MySQL_Database'], $fresMySQLConnection);
- // Check if we were able to select the database.
- if (!$db_selected)
- {
- $this->mySQLError('There was a problem when connecting to the Discuz database.
- ' .
- 'The database ' . $GLOBALS['wgDiscuz_MySQL_Database'] .
- ' was not found.
- ');
- }
- }
- else
- {
- // Connect to database.
- $fresMySQLConnection = mysql_connect($GLOBALS['wgDBserver'],
- $GLOBALS['wgDBuser'],
- $GLOBALS['wgDBpassword'],
- true);
- // Check if we are connected to the database.
- if (!$fresMySQLConnection)
- {
- $this->mySQLError('There was a problem when connecting to the Discuz database.
- ' .
- 'Check your Host, Username, and Password settings.
- ');
- }
- // Select Database: This assumes the wiki and Discuz are in the same database.
- $db_selected = mysql_select_db($GLOBALS['wgDBname']);
- // Check if we were able to select the database.
- if (!$db_selected)
- {
- $this->mySQLError('There was a problem when connecting to the Discuz database.
- ' .
- 'The database ' . $GLOBALS['wgDBname'] . ' was not found.
- ');
- }
- }
- $GLOBALS['gstrMySQLVersion'] = substr(mysql_get_server_info(), 0, 3); // Get the mysql version.
- return $fresMySQLConnection;
- }
- /**
- * If you want to munge the case of an account name before the final
- * check, now is your chance.
- */
- function getCanonicalName( $username )
- {
- return $username;
- }
- /**
- * When creating a user account, optionally fill in preferences and such.
- * For instance, you might pull the email address or real name from the
- * external user database.
- *
- * The User object is passed by reference so it can be modified; don't
- * forget the & on your function declaration.
- *
- * NOTE: This gets the email address from Discuz for the wiki account.
- *
- * @param User $user
- * @access public
- */
- function initUser(&$user)
- {
- //echo "
- initUser Start";
- $username = htmlentities(strtolower($user->mName), ENT_QUOTES, 'UTF-8');
- $username = str_replace(''', '\\\'', $username); // Allow apostrophes (Escape them though)
-
- //echo "
- Start init---";
-
- if($data = uc_get_user(iconv("UTF-8", "GBK", $username))) { //Get information from UC
- //if($data = uc_get_user($username)) { //Get information from UC
- list($uid, $username1, $email) = $data;
- //$username=iconv("GBK", "UTF-8", $username);
- //echo "init uname1:".$username1;
- //echo $email.$uid;
- $user->mEmail=$email; //Get email from UC
- $user->mid=$uid; //Get address from UC
- } else {
- echo 'No such user for initial: '.$username;
- }
- //$username=iconv("GBK", "UTF-8", $username);
- }
- /**
- * Checks if the user is a member of the Discuz group called wiki.
- *
- * @param string $username
- * @access public
- * @return bool
- * @todo Remove 2nd connection to database. For function isMemberOfWikiGroup()
- *
- */
- function isMemberOfWikiGroup($username)
- {
- // In LocalSettings.php you can control if being
- //echo "
- ---IsMember Start---";
- // a member of a wiki is required or not.
- //return false;
- if (isset($GLOBALS['wgDiscuz_UseWikiGroup']) && $GLOBALS['wgDiscuz_UseWikiGroup'] === false)
- {
- return true;
- }
- // Connect to the database.
- $fresMySQLConnection = $this->connect();
- // Check MySQL Version
- if ($GLOBALS['gstrMySQLVersion'] >= 4.1)
- {
- // Get all the groups the user is a member of.
- $fstrMySQLQuery = 'SELECT `adminid`, `groupid`
- FROM `' . $GLOBALS['wgDiscuz_UserTB'] . '`
- WHERE `username` = CONVERT( _utf8 \'' . $username . '\' USING utf8 )
-
- LIMIT 1';
- }
- else
- {
- // Get all the groups the user is a member of.
- $fstrMySQLQuery = 'SELECT `adminid`, `groupid`
- FROM `' . $GLOBALS['wgDiscuz_UserTB'] . '`
- WHERE `username` = \'' . $username . '\'
- LIMIT 1';
- }
- // Query Database.
- $fresMySQLResult = mysql_query($fstrMySQLQuery, $fresMySQLConnection)
- or die($this->mySQLError('Unable to view external table_2'));
- //echo $fstrMySQLQuery;
- while($faryMySQLResult = mysql_fetch_array($fresMySQLResult))
- {
- $GroupID = $faryMySQLResult['groupid'];
- // echo "groupID is: ".$GroupID;
- $AdminID = $faryMySQLResult['adminid'];
- }
-
- $wgDiscuz_WikiGroupIDArray=explode(',',$GLOBALS['wgDiscuz_WikiGroupID']);
- if (in_array($GroupID,$wgDiscuz_WikiGroupIDArray ) || $AdminID =="1") {
- return true;
- }
- else
- {
- return false;
- }
- }
- /**
- * Modify options in the login template.
- *
- * NOTE: Turned off some Template stuff here. Anyone who knows where
- * to find all the template options please let me know. I was only able
- * to find a few.
- *
- * @param UserLoginTemplate $template
- * @access public
- */
- function modifyUITemplate( &$template )
- {
- $template->set('usedomain', false); // We do not want a domain name.
- $template->set('create', false); // Remove option to create new accounts from the wiki.
- $template->set('useemail', false); // Disable the mail new password box.
- }
- /**
- * This prints an error when a MySQL error is found.
- *
- * @param string $message
- * @access public
- */
- function mySQLError( $message )
- {
- echo $message . '
- ';
- echo 'MySQL Error Number: ' . mysql_errno() . '
- ';
- echo 'MySQL Error Message: ' . mysql_error() . '
- ';
- exit;
- }
- /**
- * Set the domain this plugin is supposed to use when authenticating.
- *
- * NOTE: We do not use this.
- *
- * @param string $domain
- * @access public
- */
- function setDomain( $domain )
- {
- $this->domain = $domain;
- }
- /**
- * Set the given password in the authentication database.
- * Return true if successful.
- *
- * NOTE: We only allow the user to change their password via phpBB.
- *
- * @param string $password
- * @return bool
- * @access public
- */
- function setPassword( $password )
- {
- return true;
- }
- /**
- * Return true to prevent logins that don't authenticate here from being
- * checked against the local database's password fields.
- *
- * This is just a question, and shouldn't perform any actions.
- *
- * Note: This forces a user to pass Authentication with the above
- * function authenticate(). So if a user changes their Discuz
- * password, their old one will not work to log into the wiki.
- * Wiki does not have a way to update it's password when Discuz
- * does. This however does not matter.
- *
- * @return bool
- * @access public
- */
- function strict()
- {
- return true;
- }
- /**
- * Update user information in the external authentication database.
- * Return true if successful.
- *
- * @param $user User object.
- * @return bool
- * @public
- */
- function updateExternalDB( $user )
- {
- return true;
- }
- /**
- * When a user logs in, optionally fill in preferences and such.
- * For instance, you might pull the email address or real name from the
- * external user database.
- *
- * The User object is passed by reference so it can be modified; don't
- * forget the & on your function declaration.
- *
- * NOTE: Not useing right now.
- *
- * @param User $user
- * @access public
- */
- function updateUser( &$user )
- {
- return true;
- }
- /**
- * Check whether there exists a user account with the given name.
- * The name will be normalized to MediaWiki's requirements, so
- * you might need to munge it (for instance, for lowercase initial
- * letters).
- *
- * NOTE: MediaWiki checks its database for the username. If it has
- * no record of the username it then asks. "Is this really a
- * valid username?" If not then MediaWiki fails Authentication.
- *
- * @param string $username
- * @return bool
- * @access public
- * @todo write this function.
- */
- function userExists($username)
- {
- // Clean $username and force lowercase username.
- //echo "
- userExists Start";
- $username = htmlentities(strtolower($username), ENT_QUOTES, 'UTF-8');
- $username = str_replace(''', '\\\'', $username); // Allow apostrophes (Escape them though)
- //$username=iconv("UTF-8", "GBK", $username);
- //echo "
- Start Exist---";
-
- //---------------------------------------------------------------------------------------------------
- if($data = uc_get_user(iconv("UTF-8", "GBK", $username))) {
- list($uid, $username1, $email) = $data;
- //$username=iconv("GBK", "UTF-8", $username);
- //echo "Exist username :".$username;
- //echo "---Exist username1 :".$username1;
- return true;
- } else {
- echo 'No such user:'.$username;
- //echo iconv("UTF-8", "GBK", $username);
- return false;
- }
- }
- /**
- * Check to see if the specific domain is a valid domain.
- *
- * @param string $domain
- * @return bool
- * @access public
- */
- function validDomain( $domain )
- {
- return true;
- }
- }
- ?>
复制代码 2、./includes/Database.php第818行添加mysql_query("SET NAMES 'utf8';", $this->mConn );
修改这个主要是我的中文ID会出问题,不一定要求- /*private*/ function doQuery( $sql ) {
- if( $this->bufferResults() ) {
- mysql_query("SET NAMES 'utf8';", $this->mConn );
- $ret = mysql_query( $sql, $this->mConn );
- } else {
- $ret = mysql_unbuffered_query( $sql, $this->mConn );
- }
- return $ret;
- }
复制代码 3、./extensions/Auth_UC/client/lib/db.class.php 第71行和78行,分别设置了mysql_query方式,我的GBK对utf8,所以修改这里,utf8的dz和ucenter就不必了- function query($sql, $type = '', $cachetime = FALSE) {
- mysql_query("SET NAMES 'GBK'"); //设定UC查询编码为GBK,避免编码冲突
- $func = $type == 'UNBUFFERED' && function_exists('mysql_unbuffered_query') ? 'mysql_unbuffered_query' : 'mysql_query';
- if(!($query = $func($sql, $this->link)) && $type != 'SILENT') {
- $this->halt('MySQL Query Error', $sql);
- }
- $this->querynum++;
- $this->histories[] = $sql;
- mysql_query("SET NAMES 'utf8'");//还原MW系统查询编码为UTF-8,避免编码冲突
- return $query;
- }
复制代码 |
|