public function hasPersonalAnnotations() { if (!isset($this->hasPersonalAnnotations)) { $this->hasPersonalAnnotations = !$this->viewerUser->isAnon() && $this->viewerUser->getId() == $this->ownerUser->getId() && AchAwardingService::canEarnBadges($this->viewerUser) && !$this->viewerUser->getGlobalPreference('hidepersonalachievements'); } return $this->hasPersonalAnnotations; }
/** * @param User $user * @param Array $defaultPreferences * @return bool */ public static function onGetPreferences($user, &$defaultPreferences) { global $wgJsMimeType, $wgExtensionsPath, $wgCityId; F::app()->wg->Out->addScript("<script type=\"{$wgJsMimeType}\" src=\"{$wgExtensionsPath}/wikia/SpecialUnsubscribe/UnsubscribePreferences.js\"></script>"); $unsubscribe = array('unsubscribed' => array('type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'unsubscribe-preferences-toggle')); $notice = array('no-email-notice-followedpages' => array('type' => 'info', 'section' => 'watchlist/basic', 'default' => wfMsg('unsubscribe-preferences-notice'))); // move e-mail options higher up $emailAddress = array('emailaddress' => $defaultPreferences['emailaddress']); unset($defaultPreferences['emailaddress']); $defaultPreferences = self::insert($defaultPreferences, 'language', $emailAddress, false); // move founder emails higher up $founderEmailsFirstKey = "adoptionmails-label-{$wgCityId}"; if (!empty($defaultPreferences[$founderEmailsFirstKey])) { $founderEmails = array($founderEmailsFirstKey => $defaultPreferences[$founderEmailsFirstKey]); unset($defaultPreferences[$founderEmailsFirstKey]); $defaultPreferences = self::insert($defaultPreferences, 'emailaddress', $founderEmails); } // add the unsubscribe checkbox $defaultPreferences = self::insert($defaultPreferences, 'emailauthentication', $unsubscribe); // add a notice if needed if ($user->getGlobalPreference('unsubscribe')) { $defaultPreferences = self::insert($defaultPreferences, 'watchdefault', $notice, false); } $defaultPreferences = self::insert($defaultPreferences, 'language', $emailAddress, false); return true; }
private function saveBadges() { wfProfileIn(__METHOD__); if (count($this->mNewBadges) > 0) { $dbw = wfGetDB(DB_MASTER); // Doing replace instead of insert prevents dupes in case of slave lag or other errors foreach ($this->mNewBadges as $key => $val) { $this->mNewBadges[$key]['user_id'] = $this->mUser->getId(); $dbw->replace('ach_user_badges', null, $this->mNewBadges[$key], __METHOD__); } $dbw->commit(); //notify the user only if he wants to be notified if (!$this->mUser->getGlobalPreference('hidepersonalachievements')) { $_SESSION['achievementsNewBadges'] = true; $achNotificationService = new AchNotificationService($this->mUser); $achNotificationService->addBadges($this->mNewBadges); // Hook to give backend stuff something to latch onto at award-time rather than notifcation-time. // NOTE: This has the limitation that it is only called for a max of one badge per page. // If the user earned multiple badges on the same page, the hook will only be run on the badge which getBadgeToNotify() determines is more important. global $wgWikiaForceAIAFdebug; Wikia::log(__METHOD__, "", "Saving a new badge. About to run hook if badge can be re-loaded.", $wgWikiaForceAIAFdebug); $badge = $achNotificationService->getBadge(false); if ($badge !== null) { wfRunHooks('AchievementEarned', array($this->mUser, $badge)); } } //touch user when badges are given $this->mUser->invalidateCache(); //purge the user page to update counters/ranking/badges/score, FB#2872 $this->mUser->getUserPage()->purgeSquid(); //run a hook to let other extensions know when Achievements-related cache should be purged wfRunHooks('AchievementsInvalidateCache', array($this->mUser)); } wfProfileOut(__METHOD__); }
public function enabled(User $admin, $wikiId = null) { // disable if all Wikia email disabled if ((bool) $admin->getGlobalPreference('unsubscribed')) { return false; } // This type of email cannot be disabled or avoided without unsubscribing from all email return true; }
/** * Check if the user hasn't been subscribed to a watchlist * and if he agreed to receive marketing information * @param \User $oUser A user's object * @return bool */ private function checkAutoFollowConditions(\User $oUser) { global $wgAutoFollowFlag; if ((bool) $oUser->getGlobalFlag($wgAutoFollowFlag) === true) { return false; } elseif ((bool) $oUser->getGlobalPreference('marketingallowed') === false) { return false; } return true; }
/** * Logs the results of all add-to-watchlist actions * @param \User $oUser A user's object * @param Array $aWatchSuccess An array of successfully watched articles' titles * @param Array $aWatchFail An array of articles' titles that failed from being watched */ private function logResults(\User $oUser, array $aWatchSuccess, array $aWatchFail) { global $wgSitename; $iFailures = count($aWatchFail); $sUserName = $oUser->getName(); $aLogParams = ['failures' => $iFailures, 'user_id' => $oUser->getId(), 'user_name' => $sUserName, 'user_lang' => $oUser->getGlobalPreference('language'), 'watched' => $aWatchSuccess, 'watched_failed' => $aWatchFail]; if ($iFailures === 0) { WikiaLogger::instance()->info("AutoFollow log: User {$sUserName} added to watchlist at {$wgSitename}.", $aLogParams); } else { WikiaLogger::instance()->error("AutoFollow log: {$iFailures} happened when adding {$sUserName} to watchlist at {$wgSitename}.", $aLogParams); } }
/** * Notifies a single user of the changes made to properties in a single edit. * * @since 0.1 * * @param SWLGroup $group * @param User $user * @param SWLChangeSet $changeSet * @param boolean $describeChanges * * @return Status */ public static function notifyUser(SWLGroup $group, User $user, SWLChangeSet $changeSet, $describeChanges) { global $wgLang, $wgPasswordSender, $wgPasswordSenderName; $emailText = wfMsgExt('swl-email-propschanged-long', 'parse', $GLOBALS['wgSitename'], $changeSet->getEdit()->getUser()->getName(), SpecialPage::getTitleFor('SemanticWatchlist')->getFullURL(), $wgLang->time($changeSet->getEdit()->getTime()), $wgLang->date($changeSet->getEdit()->getTime())); if ($describeChanges) { $emailText .= '<h3> ' . wfMsgExt('swl-email-changes', 'parse', $changeSet->getEdit()->getTitle()->getFullText(), $changeSet->getEdit()->getTitle()->getFullURL()) . ' </h3>'; $emailText .= self::getChangeListHTML($changeSet); } $title = wfMsgReal('swl-email-propschanged', array($changeSet->getEdit()->getTitle()->getFullText()), true, $user->getGlobalPreference('language')); wfRunHooks('SWLBeforeEmailNotify', array($group, $user, $changeSet, $describeChanges, &$title, &$emailText)); return UserMailer::send(new MailAddress($user), new MailAddress($wgPasswordSender, $wgPasswordSenderName), $title, $emailText, null, 'text/html; charset=ISO-8859-1'); }
public function enabled(User $admin, $wikiId = null) { $wikiId = empty($wikiId) ? F::app()->wg->CityId : $wikiId; if (self::isAnswersWiki($wikiId)) { return false; } if ($admin->getLocalPreference("founderemails-complete-digest", $wikiId)) { return true; } // disable if all Wikia email disabled if ((bool) $admin->getGlobalPreference('unsubscribed')) { return false; } return false; }
private function setReplyToAndFromAddresses() { # Reveal the page editor's address as REPLY-TO address only if # the user has not opted-out and the option is enabled at the # global configuration level. $adminAddress = new MailAddress(F::app()->wg->PasswordSender, F::app()->wg->PasswordSenderName); if (F::app()->wg->EnotifRevealEditorAddress && $this->editor->getEmail() != '' && $this->editor->getGlobalPreference('enotifrevealaddr')) { $editorAddress = new MailAddress($this->editor); if (F::app()->wg->EnotifFromEditor) { $this->from = $editorAddress; } else { $this->from = $adminAddress; $this->replyto = $editorAddress; } } else { $this->from = $adminAddress; $this->replyto = new MailAddress(F::app()->wg->NoReplyAddress); } }
/** * Send an HTML/text email * * @param User object $user * @param string $category * @param string $msgSubject * @param string $msgBody * @param array $emailParams * @param string $templateType * @param string $template * @param int $priority * * @return Status */ public function sendEmail(User $user, $category, $msgSubject, $msgBody, $emailParams, $templateType, $template = 'GeneralMail', $priority = 0) { $subject = strtr(wfMessage($msgSubject)->escaped(), $emailParams); $body = strtr(wfMessage($msgBody)->escaped(), $emailParams); if (empty($this->wg->EnableRichEmails)) { $bodyHTML = null; } else { $emailTextTemplate = $this->app->renderView("UserLogin", $template, array('language' => $user->getGlobalPreference('language'), 'type' => $templateType)); $bodyHTML = strtr($emailTextTemplate, $emailParams); } return $user->sendMail($subject, $body, null, null, $category, $bodyHTML, $priority); }
/** * @static * @param User $user * @param Array $defaultPreferences * @return bool */ public static function onGetPreferences($user, &$defaultPreferences) { global $wgEnableAnswers, $wgForceSkin, $wgAdminSkin, $wgDefaultSkin, $wgSkinPreviewPage, $wgSkipSkins, $wgSkipOldSkins, $wgEnableUserPreferencesV2Ext; // hide default MediaWiki skin fieldset unset($defaultPreferences['skin']); $mSkin = $user->getGlobalPreference('skin'); // hacks for Answers if (!empty($wgEnableAnswers)) { $mSkin = 'answers'; } // no skin settings at all when skin is forced if (!empty($wgForceSkin)) { return true; } if (!empty($wgAdminSkin)) { $defaultSkinKey = $wgAdminSkin; } else { if (!empty($wgDefaultTheme)) { $defaultSkinKey = $wgDefaultSkin . '-' . $wgDefaultTheme; } else { $defaultSkinKey = $wgDefaultSkin; } } // load list of skin names $validSkinNames = Skin::getSkinNames(); // and sort them foreach ($validSkinNames as $skinkey => &$skinname) { if (isset($skinNames[$skinkey])) { $skinname = $skinNames[$skinkey]; } } asort($validSkinNames); $previewtext = wfMsg('skin-preview'); if (isset($wgSkinPreviewPage) && is_string($wgSkinPreviewPage)) { $previewLinkTemplate = Title::newFromText($wgSkinPreviewPage)->getLocalURL('useskin='); } else { $mptitle = Title::newMainPage(); $previewLinkTemplate = $mptitle->getLocalURL('useskin='); } $oldSkinNames = array(); foreach ($validSkinNames as $skinKey => $skinVal) { if ($skinKey == 'oasis' || (in_array($skinKey, $wgSkipSkins) || in_array($skinKey, $wgSkipOldSkins)) && !($skinKey == $mSkin)) { continue; } $oldSkinNames[$skinKey] = $skinVal; } $skins = array(); $skins[wfMsg('new-look')] = 'oasis'; // display radio buttons for rest of skin if (count($oldSkinNames) > 0) { foreach ($oldSkinNames as $skinKey => $skinVal) { $previewlink = $wgEnableUserPreferencesV2Ext ? '' : ' <a target="_blank" href="' . htmlspecialchars($previewLinkTemplate . $skinKey) . '">' . $previewtext . '</a>'; $skins[$skinVal . $previewlink . ($skinKey == $defaultSkinKey ? ' (' . wfMsg('default') . ')' : '')] = $skinKey; } } $defaultPreferencesTemp = array(); foreach ($defaultPreferences as $k => $v) { $defaultPreferencesTemp[$k] = $v; if ($k == 'oldsig') { $defaultPreferencesTemp['skin'] = array('type' => 'radio', 'options' => $skins, 'label' => ' ', 'section' => 'personal/layout'); $defaultPreferencesTemp['showAds'] = array('type' => 'toggle', 'label-message' => 'tog-showAds', 'section' => 'personal/layout'); } } $defaultPreferences = $defaultPreferencesTemp; return true; }
/** * Prepares array of user properties fields needed to be passed by API * @param User $oUser * @return array */ public function prepareUserPropertiesParams(\User $oUser) { $aUserPropertiesParams = ['marketingallowed' => $oUser->getGlobalPreference('marketingallowed'), 'unsubscribed' => $oUser->getGlobalPreference('unsubscribed'), 'language' => $oUser->getGlobalPreference('language')]; return $aUserPropertiesParams; }
/** * Before resetting the options, save the masthead info so we can restore it in onSpecialPreferencesAfterResetUserOptions * * @param $storage - storage in which we can save some options, it will be passed in onSpecialPreferencesAfterResetUserOptions hook call * @param User $user */ public static function onSpecialPreferencesBeforeResetUserOptions($preferences, &$user, &$storage) { // user identity box/masthead $userIdentityObject = new UserIdentityBox($user); $mastheadOptions = $userIdentityObject->getFullData(); $masthead = new Masthead($user); if (!empty($masthead->mUser->mOptionOverrides['avatar'])) { $mastheadOptions['avatar'] = $masthead->mUser->mOptionOverrides['avatar']; } $storage[self::MASTHEAD_OPTIONS_STORAGE_ARRAY_KEY_NAME] = $mastheadOptions; // customize toolbar/myToolbar $oasisToolbarService = new SharedToolbarService(); $toolbarNameInUserOptions = $oasisToolbarService->getToolbarOptionName(); $toolbarCurrentList = $user->getGlobalPreference($oasisToolbarService->getToolbarOptionName()); $storage[self::MY_TOOLBAR_OPTIONS_STORAGE_ARRAY_KEY_NAME] = array($toolbarNameInUserOptions => $toolbarCurrentList); return true; }
protected function canSendToWatcher(User $watcher, $entityKey) { if ($watcher->getId() == 0) { return false; } // Don't send an email to users that unsubscribed their email address if ((bool) $watcher->getGlobalPreference('unsubscribed') === true) { return false; } $mode = $watcher->getGlobalPreference('enotifwallthread'); if (empty($mode)) { return false; } if ($mode == WALL_EMAIL_EVERY) { return true; } if ($mode == WALL_EMAIL_SINCEVISITED) { return empty($this->uniqueUsers[$entityKey][$watcher->getId()]); } return false; }
/** * Internal helper function for userDate(), userTime() and userTimeAndDate() * * @param $type String: can be 'date', 'time' or 'both' * @param $ts Mixed: the time format which needs to be turned into a * date('YmdHis') format with wfTimestamp(TS_MW,$ts) * @param $user User object used to get preferences for timezone and format * @param $options Array, can contain the following keys: * - 'timecorrection': time correction, can have the following values: * - true: use user's preference * - false: don't use time correction * - integer: value of time correction in minutes * - 'format': format to use, can have the following values: * - true: use user's preference * - false: use default preference * - string: format to use * @since 1.19 * @return String */ private function internalUserTimeAndDate($type, $ts, User $user, array $options) { $ts = wfTimestamp(TS_MW, $ts); $options += array('timecorrection' => true, 'format' => true); if ($options['timecorrection'] !== false) { if ($options['timecorrection'] === true) { $offset = $user->getGlobalPreference('timecorrection'); } else { $offset = $options['timecorrection']; } $ts = $this->userAdjust($ts, $offset); } if ($options['format'] === true) { $format = $user->getDatePreference(); } else { $format = $options['format']; } $df = $this->getDateFormatString($type, $this->dateFormat($format)); return $this->sprintfDate($df, $ts); }
/** * @param User $user * @throws Exception */ private function checkIfSubscribedToWeeklyDigest(\User $user) { if (!(bool) $user->getGlobalPreference('watchlistdigest')) { throw new Exception('Not subscribed to weekly digest'); } }
/** * When the notification to the user is called (at the bottom of the page), attach the * achievement-earning to our best guess at what the associated RecentChange is. * * To account for race-conditions between RecentChanges and Achievements: currently, this * is done by recording when an RC is saved. If it happens on this page before this * function is called, then this function will load that RC by id. If this function gets * called before any RCs have been recorded, then a serialized copy of the badge is stored * and can be inserted later (when the RC actually does get saved). * * @param User $user * @param AchBadge $badge */ public static function attachAchievementToRc($user, $badge) { global $wgWikiaForceAIAFdebug; wfProfileIn(__METHOD__); // If user has 'hidepersonalachievements' set, then they probably don't want to play. // Also, other users may see that someone won, then click the username and look around for a way to see what achievements a user has... // then when they can't find it (since users with this option won't have theirs displayed), they might assume that there is no way to see // achievements. It would be better to do this check at display-time rather than save-time, but we don't have access to the badge's user // at that point. Wikia::log(__METHOD__, "", "Noticed an achievement", $wgWikiaForceAIAFdebug); if ($badge->getTypeId() != BADGE_WELCOME && !$user->getGlobalPreference('hidepersonalachievements')) { Wikia::log(__METHOD__, "", "Attaching badge to recent change...", $wgWikiaForceAIAFdebug); // Make sure this Achievement gets added to its corresponding RecentChange (whether that has // been saved already during this pageload or is still pending). global $wgARecentChangeHasBeenSaved, $wgAchievementToAddToRc; Wikia::log(__METHOD__, "", "About to see if there is an existing RC. RC: " . print_r($wgARecentChangeHasBeenSaved, true), $wgWikiaForceAIAFdebug); if (!empty($wgARecentChangeHasBeenSaved)) { // Due to slave-lag, instead of storing the rc_id and looking it up (which didn't always work, even with a retry-loop), store entire RC. Wikia::log(__METHOD__, "", "Attaching badge to existing RecentChange from earlier in pageload.", $wgWikiaForceAIAFdebug); $rc = $wgARecentChangeHasBeenSaved; if ($rc) { Wikia::log(__METHOD__, "", "Found recent change to attach to.", $wgWikiaForceAIAFdebug); // Add the (serialized) badge into the rc_params field. $rc_data = array(); $rc_data['Badge'] = serialize($badge); MyHome::storeAdditionalRcData($rc_data, $rc); } } else { // Spool this achievement for when its corresponding RecentChange shows up (later in this pageload). $wgAchievementToAddToRc = serialize($badge); Wikia::log(__METHOD__, "", "RecentChange hasn't been saved yet, storing the badge for later.", $wgWikiaForceAIAFdebug); } } wfProfileOut(__METHOD__); return true; }