/** * Find the user by their Facebook ID. * If there is no user found for the given id, returns null. */ public static function getUser($fbid) { $prefix = self::getPrefix(); // NOTE: Do not just pass this dbr into getUserByDB since that function prevents // rewriting of the database name for shared tables. $dbr = wfGetDB(DB_SLAVE, array(), self::sharedDB()); $id = $dbr->selectField(array("{$prefix}user_fbconnect"), array('user_id'), array('user_fbid' => $fbid), __METHOD__); if ($id) { /* Wikia change - begin */ global $wgExternalAuthType; $user = User::newFromId($id); if ($wgExternalAuthType) { $user->load(); if ($user->getId() == 0) { $mExtUser = ExternalUser::newFromId($id); if (is_object($mExtUser) && $mExtUser->getId() != 0) { $mExtUser->linkToLocal($mExtUser->getId()); $user->setId($id); } } } return $user; /* Wikia change - end */ } else { return null; } }
/** * Show the special page * * @param $subpage Mixed: parameter passed to the page or null */ public function execute($subpage) { global $wgRequest, $wgUser, $wgExternalAuthType; $this->setHeaders(); # If the user doesn't have the required 'lookupuser' permission, display an error if (!$wgUser->isAllowed('lookupuser')) { $this->displayRestrictionError(); return; } if ($subpage) { $target = $subpage; } else { $target = $wgRequest->getText('target'); } $id = ''; $byIdInvalidUser = false; if ($wgRequest->getText('mode') == 'by_id') { $id = $target; if ($wgExternalAuthType == 'ExternalUser_Wikia') { $u = ExternalUser::newFromId($id); if (is_object($u) && $u->getId() != 0) { #overwrite text $target = $u->getName(); } else { // User with that ID doesn't exist, notify user // Stops trying to display form with a user by that name which is confusing $byIdInvalidUser = true; } } else { $u = User::newFromId($id); #create if ($u->loadFromId()) { #overwrite text $target = $u->getName(); } else { // User with that ID doesn't exist, notify user // Stops trying to display form with a user by that name which is confusing $byIdInvalidUser = true; } } } $emailUser = $wgRequest->getText('email_user'); if ($emailUser) { $this->showForm($emailUser, $id, $target, $byIdInvalidUser); } else { $this->showForm($target, $id, '', $byIdInvalidUser); } if ($target && !$byIdInvalidUser) { $this->showInfo($target, $emailUser); } }
/** * @param $user User * @param $s ResultWrapper */ public static function onUserLoadFromDatabase($user, &$s) { /* wikia change */ global $wgExternalAuthType; if ($wgExternalAuthType) { $mExtUser = ExternalUser::newFromId($user->mId); if (is_object($mExtUser) && 0 != $mExtUser->getId()) { $mExtUser->linkToLocal($mExtUser->getId()); $s = $mExtUser->getLocalUser(false); } } return true; }
/** * Returns a Wikia User object for the current (or passed) Facebook ID * * @param int|null $fbId [optional] A Facebook ID * * @return null|User * @throws MWException */ public function getWikiaUser($fbId = null) { if (empty($fbId)) { $fbId = $this->getUserId(); if (empty($fbId)) { return null; } } $map = FacebookMapModel::lookupFromFacebookID($fbId); if (empty($map)) { return null; } // Create a new mapping that includes the app ID. Leave the default App ID behind // as there is no way to tell what other apps this user had connected, and removing this // default mapping will force the user to reconnect on those apps. if ($map->isDefaultAppId()) { $this->migrateMapping($map); } // Update the business token for this user if not already set. The business token // gives us a unique ID across all apps that we can use to reference a user. if (!$map->getBizToken()) { $this->updateBizTokenMapping($map); } $wikiUserId = $map->getWikiaUserId(); if (!$wikiUserId) { return null; } $user = User::newFromId($wikiUserId); // This handles the case when a user record doesn’t exist on wikicities_c3 yet and it has to be created if (F::app()->wg->ExternalAuthType) { $user->load(); if ($user->getId() == 0) { $mExtUser = ExternalUser::newFromId($wikiUserId); if (is_object($mExtUser) && $mExtUser->getId() != 0) { $mExtUser->linkToLocal($mExtUser->getId()); $user->setId($wikiUserId); } } } return $user; }
/** * @param int $userID * @return null|User */ private function getUserObject($userID) { if (\F::app()->wg->ExternalAuthType) { $mExtUser = ExternalUser::newFromId($userID); if (is_object($mExtUser) && 0 != $mExtUser->getId()) { $mExtUser->linkToLocal($mExtUser->getId()); $user = $mExtUser->getLocalUser(); } else { $user = null; } } else { $user = User::newFromId($userID); } return $user; }
<?php ini_set("include_path", dirname(__FILE__) . "/.."); require_once 'commandLine.inc'; $userid = isset($options['u']) ? $options['u'] : 0; if ($userid == 0) { die('invalid user ID'); } $mExtUser = ExternalUser::newFromId($userid); if (is_object($mExtUser) && 0 != $mExtUser->getId()) { $mExtUser->linkToLocal($mExtUser->getId()); }