コード例 #1
0
 /**
  * Return information about users present in the chat channel. This method has its internal cache. Method returns
  * an array, where each of the users is described by the following attributes:
  * * username - chatter login
  * * avatarUrl - chatter avatar url
  * * editCount - number of chatter's edits
  * * showSince - flag indicating if we can display the information when the chatter joined the wiki
  * * since_year && since_month - month and year, when chatter joined this wiki
  * * profileUrl - link to chatter talk page (or message wall, if it's enabled)
  * * contribsUrl - link to chatter contribution page
  * @return array array containing chatters info
  */
 public static function getChatUsersInfo()
 {
     ChatHelper::info(__METHOD__ . ': Method called');
     global $wgReadOnly;
     wfProfileIn(__METHOD__);
     $chatters = [];
     if (empty($wgReadOnly)) {
         // cache the whole response
         // individual users are cached anyway, but still we gain performance making just one memcache request instead of several
         $chatters = WikiaDataAccess::cache(self::getChatUsersMemcKey(), ChatEntryPoint::CHAT_USER_LIST_CACHE, function () {
             global $wgEnableWallExt;
             $chatters = [];
             // Gets array of users currently in chat to populate rail module and user stats menus
             $chattersIn = NodeApiClient::getChatters();
             foreach ($chattersIn as $i => $val) {
                 $chatters[$i] = WikiaDataAccess::cache(wfMemcKey('chatavatars', $val, 'v2'), 60 * 60, function () use($wgEnableWallExt, $val) {
                     $chatter = ['username' => $val, 'avatarUrl' => AvatarService::getAvatarUrl($val, ChatRailController::AVATAR_SIZE)];
                     // get stats for edit count and member since
                     $user = User::newFromName($val);
                     if ($user instanceof User) {
                         $userStatsService = new UserStatsService($user->getId());
                         $stats = $userStatsService->getStats();
                         // edit count
                         $chatter['editCount'] = $stats['edits'];
                         // member since
                         $chatter['showSince'] = $chatter['editCount'] != 0;
                         if ($chatter['showSince']) {
                             $date = getdate(strtotime($stats['date']));
                             $chatter['since_year'] = $date['year'];
                             $chatter['since_month'] = $date['mon'];
                         }
                         if (!empty($wgEnableWallExt)) {
                             $chatter['profileUrl'] = Title::makeTitle(NS_USER_WALL, $chatter['username'])->getFullURL();
                         } else {
                             $chatter['profileUrl'] = Title::makeTitle(NS_USER_TALK, $chatter['username'])->getFullURL();
                         }
                         $chatter['contribsUrl'] = SpecialPage::getTitleFor('Contributions', $chatter['username'])->getFullURL();
                     }
                     return $chatter;
                 });
             }
             return $chatters;
         });
     }
     wfProfileOut(__METHOD__);
     return $chatters;
 }
コード例 #2
0
 public function executeGetUsers()
 {
     wfProfileIn(__METHOD__);
     $this->users = ChatEntryPoint::getChatUsersInfo();
     if (count($this->users) === 0) {
         ChatHelper::info(__METHOD__ . ': Method called - no users');
         // CONN-436: If there are no users in the chat, cache the response in varnish for CACHE_STANDARD and on the
         // browser for the default CACHE_DURATION time;
         // Note: Varnish cache will be purged when user opens the chat page
         $this->response->setCacheValidity(WikiaResponse::CACHE_STANDARD, self::CACHE_DURATION);
     } else {
         ChatHelper::info(__METHOD__ . ': Method called - found users', ['chatters' => count($this->users)]);
         // If there are users in the chat, cache both in varnish and browser for default CACHE_DURATION;
         $this->response->setCacheValidity(self::CACHE_DURATION);
     }
     wfProfileOut(__METHOD__);
 }
コード例 #3
0
ファイル: ChatHelper.php プロジェクト: schwarer2006/wikia
 /**
  *
  * laod Config of chat from json file (we need to use jsone file becasue w)
  * @param string $name
  */
 static function getChatConfig($name)
 {
     global $wgWikiaLocalSettingsPath, $wgDevelEnvironment, $wgWikiaConfigDirectory;
     wfProfileIn(__METHOD__);
     if (empty(self::$configFile)) {
         $configFilePath = $wgWikiaConfigDirectory . '/ChatConfig.json';
         $string = file_get_contents($configFilePath);
         self::$configFile = json_decode($string, true);
     }
     if (isset(self::$configFile[empty($wgDevelEnvironment) ? 'prod' : 'dev'][$name])) {
         wfProfileOut(__METHOD__);
         return self::$configFile[empty($wgDevelEnvironment) ? 'prod' : 'dev'][$name];
     }
     if (isset(self::$configFile[$name])) {
         wfProfileOut(__METHOD__);
         return self::$configFile[$name];
     }
     wfProfileOut(__METHOD__);
     return false;
 }
コード例 #4
0
 /**
  * @brief this is default method, which in this example just redirects to Hello method
  * @details No parameters
  *
  */
 public function index()
 {
     if (!$this->wg->User->isAllowed('chatfailover')) {
         $this->skipRendering();
         throw new PermissionsError('chatfailover');
     }
     $mode = (bool) ChatHelper::getMode();
     $this->wg->Out->setPageTitle(wfMsg('Chatfailover'));
     if ($this->request->wasPosted()) {
         $reason = $this->request->getVal('reason');
         if (!empty($reason) && $mode == ChatHelper::getMode()) {
             //the mode didn't change
             $mode = !$mode;
             StaffLogger::log("chatfo", "switch", $this->wg->User->getID(), $this->wg->User->getName(), $mode, $mode ? 'regular' : 'failover', $reason);
             ChatHelper::changeMode($mode);
         }
     }
     $this->response->setVal("serversList", ChatHelper::getServersList());
     $this->response->setVal("mode", $mode ? 'regular' : 'failover');
     $this->response->setVal("modeBool", $mode);
 }
コード例 #5
0
 public function execute()
 {
     wfProfileIn(__METHOD__);
     global $wgUser, $wgOut;
     // check if logged in
     if ($wgUser->isLoggedIn()) {
         if (Chat::canChat($wgUser)) {
             ChatHelper::info(__METHOD__ . ': Method called - success');
             Wikia::setVar('OasisEntryControllerName', 'Chat');
             Chat::logChatWindowOpenedEvent();
         } else {
             ChatHelper::info(__METHOD__ . ': Method called - banned');
             $wgOut->showErrorPage('chat-you-are-banned', 'chat-you-are-banned-text');
         }
     } else {
         // TODO: FIXME: Make a link on this page which lets the user login.
         // TODO: FIXME: Make a link on this page which lets the user login.
         ChatHelper::info(__METHOD__ . ': Method called - logged out');
         // $wgOut->permissionRequired( 'chat' ); // this is a really useless message, don't use it.
         $wgOut->showErrorPage('chat-no-login', 'chat-no-login-text');
     }
     wfProfileOut(__METHOD__);
 }
コード例 #6
0
ファイル: ChatHelper.php プロジェクト: Tjorriemorrie/app
 /**
  *
  * Load Config of chat from json file
  *
  * @param string $name
  *
  * @return bool
  */
 static function getChatConfig($name)
 {
     global $wgWikiaEnvironment;
     $configDir = getenv('WIKIA_CONFIG_ROOT');
     if (empty(self::$configFile)) {
         $configFilePath = $configDir . '/ChatConfig.json';
         $string = file_get_contents($configFilePath);
         self::$configFile = json_decode($string, true);
     }
     if (empty(self::$configFile)) {
         return false;
     }
     $env = $wgWikiaEnvironment;
     if (isset(self::$configFile[$env][$name])) {
         return self::$configFile[$env][$name];
     }
     if (isset(self::$configFile[$name])) {
         return self::$configFile[$name];
     }
     return false;
 }
コード例 #7
0
 /**
  * Return the appropriate host and port for the client to connect to.
  * This is based on whether this is dev or prod, but can be overridden
  */
 protected static function getHostAndPort()
 {
     global $wgDevelEnvironment;
     $server = ChatHelper::getServer('Api');
     $server = ChatHelper::getServer('Api');
     $hostAndPort = $server['host'] . ':' . $server['port'];
     return $hostAndPort;
 }
コード例 #8
0
ファイル: ChatAjax.class.php プロジェクト: Tjorriemorrie/app
 function BanModal()
 {
     ChatHelper::info(__METHOD__ . ': Method called');
     global $wgRequest, $wgCityId, $wgLang;
     wfProfileIn(__METHOD__);
     $tmpl = new EasyTemplate(dirname(__FILE__) . '/templates/');
     $userId = $wgRequest->getVal('userId', 0);
     $isChangeBan = false;
     $isoTime = "";
     $fmtTime = "";
     if (!empty($userId) && ($user = User::newFromID($userId))) {
         $ban = Chat::getBanInformation($wgCityId, $user);
         if ($ban !== false) {
             $isChangeBan = true;
             $isoTime = wfTimestamp(TS_ISO_8601, $ban->end_date);
             $fmtTime = $wgLang->timeanddate(wfTimestamp(TS_MW, $ban->end_date), true);
         }
     }
     $tmpl->set_vars(array('options' => Chat::GetBanOptions(), 'isChangeBan' => $isChangeBan, 'isoTime' => $isoTime, 'fmtTime' => $fmtTime));
     $retVal = array();
     $retVal['template'] = $tmpl->render("banModal");
     $retVal['isChangeBan'] = $isChangeBan;
     wfProfileOut(__METHOD__);
     return $retVal;
 }
コード例 #9
0
 public function executeIndex()
 {
     global $wgUser, $wgDevelEnvironment, $wgRequest, $wgCityId, $wgFavicon, $wgOut;
     wfProfileIn(__METHOD__);
     // String replacement logic taken from includes/Skin.php
     $this->wgFavicon = str_replace('images.wikia.com', 'images1.wikia.nocookie.net', $wgFavicon);
     $this->mainPageURL = Title::newMainPage()->getLocalURL();
     // add messages (fetch them using <script> tag)
     F::build('JSMessages')->enqueuePackage('Chat', JSMessages::EXTERNAL);
     // package defined in Chat_setup.php
     $this->jsMessagePackagesUrl = F::build('JSMessages')->getExternalPackagesUrl();
     // Variables for this user
     $this->username = $wgUser->getName();
     $this->avatarUrl = AvatarService::getAvatarUrl($this->username, ChatController::CHAT_AVATAR_DIMENSION);
     // Find the chat for this wiki (or create it, if it isn't there yet).
     $roomName = $roomTopic = "";
     $this->roomId = (int) NodeApiClient::getDefaultRoomId($roomName, $roomTopic);
     $this->roomName = $roomName;
     $this->roomTopic = $roomTopic;
     $this->chatkey = Chat::echoCookies();
     // Set the hostname of the node server that the page will connect to.
     $server = ChatHelper::getServer('Main');
     $this->nodePort = $server['port'];
     $this->nodeHostname = $server['host'];
     // Some building block for URLs that the UI needs.
     $this->pathToProfilePage = Title::makeTitle(!empty($this->wg->EnableWallExt) ? NS_USER_WALL : NS_USER_TALK, '$1')->getFullURL();
     $this->pathToContribsPage = SpecialPage::getTitleFor('Contributions', '$1')->getFullURL();
     $this->bodyClasses = "";
     if ($wgUser->isAllowed('chatmoderator')) {
         $this->isChatMod = 1;
         $this->bodyClasses .= ' chat-mod ';
     } else {
         $this->isChatMod = 0;
     }
     // Adding chatmoderator group for other users. CSS classes added to body tag to hide/show option in menu.
     $userChangeableGroups = $wgUser->changeableGroups();
     if (in_array('chatmoderator', $userChangeableGroups['add'])) {
         $this->bodyClasses .= ' can-give-chat-mod ';
     }
     $this->app->registerHook('MakeGlobalVariablesScript', 'ChatController', 'onMakeGlobalVariablesScript', array(), false, $this);
     $wgOut->getResourceLoader()->getModule('mediawiki');
     $ret = implode("\n", array($wgOut->getHeadLinks(null, true), $wgOut->buildCssLinks(), $wgOut->getHeadScripts(), $wgOut->getHeadItems()));
     $this->globalVariablesScript = $ret;
     //Theme Designer stuff
     $themeSettingObj = new ThemeSettings();
     $themeSettings = $themeSettingObj->getSettings();
     $this->themeSettings = $themeSettings;
     $this->wordmarkThumbnailUrl = '';
     if ($themeSettings['wordmark-type'] == 'graphic') {
         $title = Title::newFromText($themeSettings['wordmark-image-name'], NS_FILE);
         if ($title) {
             $image = wfFindFile($title);
             if ($image) {
                 $this->wordmarkThumbnailUrl = $image->createThumb(self::CHAT_WORDMARK_WIDTH, self::CHAT_WORDMARK_HEIGHT);
             }
         }
         if (empty($this->wordmarkThumbnailUrl)) {
             $this->wordmarkThumbnailUrl = WikiFactory::getLocalEnvURL($themeSettings['wordmark-image-url']);
         }
     }
     wfProfileOut(__METHOD__);
 }
コード例 #10
0
ファイル: ChatAjax.class.php プロジェクト: schwarer2006/wikia
 /**
  *  injecting data from chat to memcache
  */
 public static function setUsersList()
 {
     global $wgRequest;
     wfProfileIn(__METHOD__);
     if (ChatHelper::getChatCommunicationToken() != $wgRequest->getVal('token')) {
         wfProfileOut(__METHOD__);
         return array('status' => false);
     }
     NodeApiClient::setChatters($wgRequest->getArray('users'));
     wfProfileOut(__METHOD__);
     return array('status' => $wgRequest->getArray('users'));
 }
コード例 #11
0
 public function executeIndex()
 {
     ChatHelper::info(__METHOD__ . ': Method called');
     global $wgUser, $wgFavicon, $wgOut, $wgHooks, $wgSitename;
     wfProfileIn(__METHOD__);
     // String replacement logic taken from includes/Skin.php
     $this->wgFavicon = str_replace('images.wikia.com', 'images1.wikia.nocookie.net', $wgFavicon);
     $this->mainPageURL = Title::newMainPage()->getLocalURL();
     // add messages (fetch them using <script> tag)
     JSMessages::enqueuePackage('Chat', JSMessages::EXTERNAL);
     // package defined in Chat_setup.php
     $this->jsMessagePackagesUrl = JSMessages::getExternalPackagesUrl();
     // Variables for this user
     $this->username = $wgUser->getName();
     $this->avatarUrl = AvatarService::getAvatarUrl($this->username, ChatController::CHAT_AVATAR_DIMENSION);
     // Find the chat for this wiki (or create it, if it isn't there yet).
     $this->roomId = (int) NodeApiClient::getDefaultRoomId();
     // we overwrite here data from redis since it causes a bug DAR-1532
     $this->roomName = $wgSitename;
     $this->roomTopic = wfMsg('chat-default-topic', $wgSitename);
     $this->chatkey = Chat::echoCookies();
     // Set the hostname of the node server that the page will connect to.
     $chathost = ChatHelper::getChatConfig('ChatHost');
     $server = explode(":", $chathost);
     $this->nodeHostname = $server[0];
     $this->nodePort = $server[1];
     $chatmain = ChatHelper::getServer('Main');
     $this->nodeInstance = $chatmain['serverId'];
     // Some building block for URLs that the UI needs.
     $this->pathToProfilePage = Title::makeTitle(!empty($this->wg->EnableWallExt) ? NS_USER_WALL : NS_USER_TALK, '$1')->getFullURL();
     $this->pathToContribsPage = SpecialPage::getTitleFor('Contributions', '$1')->getFullURL();
     $this->bodyClasses = "";
     if ($wgUser->isAllowed('chatmoderator')) {
         $this->isChatMod = 1;
         $this->bodyClasses .= ' chat-mod ';
     } else {
         $this->isChatMod = 0;
     }
     // Adding chatmoderator group for other users. CSS classes added to body tag to hide/show option in menu.
     $userChangeableGroups = $wgUser->changeableGroups();
     if (in_array('chatmoderator', $userChangeableGroups['add'])) {
         $this->bodyClasses .= ' can-give-chat-mod ';
     }
     // set up global js variables just for the chat page
     $wgHooks['MakeGlobalVariablesScript'][] = array($this, 'onMakeGlobalVariablesScript');
     $wgOut->getResourceLoader()->getModule('mediawiki');
     $ret = implode("\n", array($wgOut->getHeadLinks(null, true), $wgOut->buildCssLinks(), $wgOut->getHeadScripts(), $wgOut->getHeadItems()));
     $this->globalVariablesScript = $ret;
     //Theme Designer stuff
     $themeSettingObj = new ThemeSettings();
     $themeSettings = $themeSettingObj->getSettings();
     $this->themeSettings = $themeSettings;
     $this->wordmarkThumbnailUrl = '';
     if ($themeSettings['wordmark-type'] == 'graphic') {
         $title = Title::newFromText($themeSettings['wordmark-image-name'], NS_FILE);
         if ($title) {
             $image = wfFindFile($title);
             if ($image) {
                 $this->wordmarkThumbnailUrl = $image->createThumb(self::CHAT_WORDMARK_WIDTH, self::CHAT_WORDMARK_HEIGHT);
             }
         }
         if (empty($this->wordmarkThumbnailUrl)) {
             $this->wordmarkThumbnailUrl = WikiFactory::getLocalEnvURL($themeSettings['wordmark-image-url']);
         }
     }
     // CONN-436: Invalidate Varnish cache for ChatRail:GetUsers
     ChatRailController::purgeMethod('GetUsers', ['format' => 'json']);
     wfProfileOut(__METHOD__);
 }
コード例 #12
0
ファイル: Chat.class.php プロジェクト: Tjorriemorrie/app
 /**
  * Attempts to add the 'chatmoderator' group to the user whose name is provided
  * in 'userNameToPromote'.
  *
  * @param string $userNameToPromote
  * @param User $promotingUser
  *
  * @return bool true on success, returns an error message as a string on failure.
  */
 public static function promoteChatModerator($userNameToPromote, $promotingUser)
 {
     ChatHelper::info(__METHOD__ . ': Method called', ['userNameToPromote' => $userNameToPromote, 'promotingUser' => $promotingUser]);
     $CHAT_MOD_GROUP = 'chatmoderator';
     $userToPromote = User::newFromName($userNameToPromote);
     if (!$userToPromote instanceof User) {
         $errorMsg = wfMessage('chat-err-invalid-username-chatmod', $userNameToPromote)->text();
         return $errorMsg;
     }
     // Check if the userToPromote is already in the chatmoderator group.
     $errorMsg = '';
     if (in_array($CHAT_MOD_GROUP, $userToPromote->getEffectiveGroups())) {
         $errorMsg = wfMessage("chat-err-already-chatmod", $userNameToPromote, $CHAT_MOD_GROUP)->text();
     } else {
         $changeableGroups = $promotingUser->changeableGroups();
         $promotingUserName = $promotingUser->getName();
         $isSelf = $userToPromote->getName() == $promotingUserName;
         $addableGroups = array_merge($changeableGroups['add'], $isSelf ? $changeableGroups['add-self'] : []);
         if (in_array($CHAT_MOD_GROUP, $addableGroups)) {
             // Adding the group is allowed. Add the group, clear the cache, run necessary hooks, and log the change.
             $oldGroups = $userToPromote->getGroups();
             $userToPromote->addGroup($CHAT_MOD_GROUP);
             $userToPromote->invalidateCache();
             if ($userToPromote instanceof User) {
                 $removegroups = [];
                 $addgroups = [$CHAT_MOD_GROUP];
                 wfRunHooks('UserRights', [&$userToPromote, $addgroups, $removegroups]);
             }
             // Update user-rights log.
             $newGroups = array_merge($oldGroups, [$CHAT_MOD_GROUP]);
             // Log the rights-change.
             Chat::addLogEntry($userToPromote, $promotingUser, [Chat::makeGroupNameListForLog($oldGroups), Chat::makeGroupNameListForLog($newGroups)], 'chatmoderator');
         } else {
             $errorMsg = wfMessage("chat-err-no-permission-to-add-chatmod", $CHAT_MOD_GROUP)->text();
         }
     }
     return $errorMsg == "" ? true : $errorMsg;
 }