/**
  * Generate a new e-mail confirmation token and send a confirmation
  * mail to the user's given address.
  *
  * @param User $user
  * @param string $ip User IP address
  * @param string $token
  * @param string $expiration
  * @return true|Status True on success, a Status object on failure.
  */
 public static function sendConfirmationMail(User $user, $ip, $token, $expiration)
 {
     global $wgContLang;
     $url = self::confirmationTokenUrl($token);
     $lang = $user->getOption('language');
     return $user->sendMail(wfMessage('requestaccount-email-subj')->inLanguage($lang)->text(), wfMessage('requestaccount-email-body', $ip, $user->getName(), $url, $wgContLang->timeanddate($expiration, false), $wgContLang->date($expiration, false), $wgContLang->time($expiration, false))->inLanguage($lang)->text());
 }
 /**
  * Bug 37963
  * Make sure defaults are loaded when setOption is called.
  * @covers User::loadOptions
  */
 public function testAnonOptions()
 {
     global $wgDefaultUserOptions;
     $this->user->setOption('userjs-someoption', 'test');
     $this->assertEquals($wgDefaultUserOptions['cols'], $this->user->getOption('cols'));
     $this->assertEquals('test', $this->user->getOption('userjs-someoption'));
 }
 /**
  * @param User $user
  * @param Array $defaultPreferences
  * @return bool
  */
 function onGetPreferences($user, &$defaultPreferences)
 {
     global $wgOut, $wgJsMimeType, $wgExtensionsPath, $wgCityId;
     $wgOut->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->getOption('unsubscribe')) {
         $defaultPreferences = self::insert($defaultPreferences, 'watchdefault', $notice, false);
     }
     $defaultPreferences = self::insert($defaultPreferences, 'language', $emailAddress, false);
     return true;
 }
    /**
     * Generate the generic "this page has been changed" e-mail text.
     */
    protected function composeCommonMailtext()
    {
        global $wgPasswordSender, $wgPasswordSenderName, $wgNoReplyAddress;
        global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress;
        global $wgEnotifUseRealName, $wgRequest;
        $this->composed_common = true;
        if ($this->editor->isAnon()) {
            $pageEditor = wfMsgForContent('enotif_anon_editor', $this->editor->getName());
        } else {
            $pageEditor = $wgEnotifUseRealName ? $this->editor->getRealName() : $this->editor->getName();
        }
        // build the subject
        $this->subject = wfMessage('moodbar-enotif-subject')->params($pageEditor)->escaped();
        // build the body
        $targetUserName = $this->targetUser->getName();
        $links = $this->buildEmailLink();
        //text version, no need to escape since client will interpret it as plain text
        $textBody = wfMessage('moodbar-enotif-body')->params($targetUserName, $links['feedbackPageUrl'], $links['editorTalkPageUrl'], $this->response, $links['targetUserTalkPageUrl'], $pageEditor)->text();
        //html version, this is a little bit ugly as we have to make wiki link clickable in emails
        $action = $wgRequest->getVal('action');
        $wgRequest->setVal('action', 'render');
        $htmlBody = wfMsgExt('moodbar-enotif-body', array('parse'), $targetUserName, $links['feedbackPageUrl'], $links['editorTalkPageUrl'], '<div style="margin-left:20px; margin-right:20px;">"' . $this->response . '"</div>', $links['targetUserTalkPageUrl'], $pageEditor);
        $wgRequest->setVal('action', $action);
        // assemble the email body
        $this->body = <<<HTML
--{$this->mime_boundary}
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

{$textBody}

--{$this->mime_boundary}
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<html>
\t<body>
\t\t{$htmlBody}
\t</body>
</html>

--{$this->mime_boundary}--
HTML;
        # 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($wgPasswordSender, $wgPasswordSenderName);
        if ($wgEnotifRevealEditorAddress && $this->editor->getEmail() != '' && $this->editor->getOption('enotifrevealaddr')) {
            $editorAddress = new MailAddress($this->editor);
            if ($wgEnotifFromEditor) {
                $this->from = $editorAddress;
            } else {
                $this->from = $adminAddress;
                $this->replyto = $editorAddress;
            }
        } else {
            $this->from = $adminAddress;
            $this->replyto = new MailAddress($wgNoReplyAddress);
        }
    }
Exemple #5
0
 /**
  * Return the localized pretty price with currency
  * @todo localize the order currency/amount too
  * @param User $user
  * @return string 
  */
 public function getLocalizedPrice($user)
 {
     $language = Language::factory($user->getOption('language'));
     $price = $this->getPrice();
     $amount = $language->formatNum($price['amount']);
     $currency = $price['currency'] == 'EUR' ? '€' : $price['currency'];
     return $amount . $currency;
 }
Exemple #6
0
 /**
  * Get the user's email notification format
  * @return string
  */
 public function getEmailFormat()
 {
     global $wgAllowHTMLEmail;
     if ($wgAllowHTMLEmail) {
         return $this->mUser->getOption('echo-email-format');
     } else {
         return EchoHooks::EMAIL_FORMAT_PLAIN_TEXT;
     }
 }
 /**
  * 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, $group);
     }
     $title = wfMsgReal('swl-email-propschanged', array($changeSet->getEdit()->getTitle()->getFullText()), true, $user->getOption('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');
 }
Exemple #8
0
 /**
  * Adjust the timestamp depending on the given user's preferences.
  *
  * @since 1.22
  *
  * @param User $user User to take preferences from
  * @return DateInterval Offset that was applied to the timestamp
  */
 public function offsetForUser(User $user)
 {
     global $wgLocalTZoffset;
     $option = $user->getOption('timecorrection');
     $data = explode('|', $option, 3);
     // First handle the case of an actual timezone being specified.
     if ($data[0] == 'ZoneInfo') {
         try {
             $tz = new DateTimeZone($data[2]);
         } catch (Exception $e) {
             $tz = false;
         }
         if ($tz) {
             $this->timestamp->setTimezone($tz);
             return new DateInterval('P0Y');
         } else {
             $data[0] = 'Offset';
         }
     }
     $diff = 0;
     // If $option is in fact a pipe-separated value, check the
     // first value.
     if ($data[0] == 'System') {
         // First value is System, so use the system offset.
         if ($wgLocalTZoffset !== null) {
             $diff = $wgLocalTZoffset;
         }
     } elseif ($data[0] == 'Offset') {
         // First value is Offset, so use the specified offset
         $diff = (int) $data[1];
     } else {
         // $option actually isn't a pipe separated value, but instead
         // a comma separated value. Isn't MediaWiki fun?
         $data = explode(':', $option);
         if (count($data) >= 2) {
             // Combination hours and minutes.
             $diff = abs((int) $data[0]) * 60 + (int) $data[1];
             if ((int) $data[0] < 0) {
                 $diff *= -1;
             }
         } else {
             // Just hours.
             $diff = (int) $data[0] * 60;
         }
     }
     $interval = new DateInterval('PT' . abs($diff) . 'M');
     if ($diff < 1) {
         $interval->invert = 1;
     }
     $this->timestamp->add($interval);
     return $interval;
 }
 /**
  * Main function for processinig bundle email
  */
 public function processBundleEmail()
 {
     $emailSetting = intval($this->mUser->getOption('echo-email-frequency'));
     // User has switched to email digest or decided not to receive email,
     // the daily cron will handle events left in the queue
     if ($emailSetting != 0) {
         throw new MWException("User has switched to email digest/no email option!");
     }
     // If there is nothing in the queue, do not update timestamp so next
     // email would be just an instant email
     if ($this->retrieveBaseEvent()) {
         $this->timestamp = wfTimestampNow();
         $this->updateEmailMetadata();
         $this->sendEmail();
         $this->clearProcessedEvent();
     } else {
         throw new MWException("There is no bundle notification to process!");
     }
 }
Exemple #10
0
 function getSignature($user)
 {
     if (is_object($user)) {
         $uid = $user->getId();
         $name = $user->getName();
     } elseif (is_integer($user)) {
         $uid = $user;
         $user = User::newFromId($uid);
         $name = $user->getName();
     } else {
         $user = User::newFromName($user);
         $name = $user->getName();
         $uid = $user->getId();
     }
     if ($this->user->getOption('lqtcustomsignatures')) {
         return $this->getUserSignature($user, $uid, $name);
     } else {
         return $this->getBoringSignature($user, $uid, $name);
         // FIXME: Method not found
     }
 }
 /**
  * Keeps track of recently used message groups per user.
  */
 public static function trackGroup(MessageGroup $group, User $user)
 {
     if ($user->isAnon()) {
         return true;
     }
     $groups = $user->getOption('translate-recent-groups', '');
     if ($groups === '') {
         $groups = array();
     } else {
         $groups = explode('|', $groups);
     }
     if (isset($groups[0]) && $groups[0] === $group->getId()) {
         return true;
     }
     array_unshift($groups, $group->getId());
     $groups = array_unique($groups);
     $groups = array_slice($groups, 0, 5);
     $user->setOption('translate-recent-groups', implode('|', $groups));
     // Promise to persist the data post-send
     DeferredUpdates::addCallableUpdate(function () use($user) {
         $user->saveSettings();
     });
     return true;
 }
 /**
  * @param User $u
  * @param bool $throttle
  * @param string $emailTitle Message name of email title
  * @param string $emailText Message name of email text
  * @return Status
  */
 function mailPasswordInternal($u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext')
 {
     global $wgNewPasswordExpiry;
     if ($u->getEmail() == '') {
         return Status::newFatal('noemail', $u->getName());
     }
     $ip = $this->getRequest()->getIP();
     if (!$ip) {
         return Status::newFatal('badipaddress');
     }
     $currentUser = $this->getUser();
     Hooks::run('User::mailPasswordInternal', array(&$currentUser, &$ip, &$u));
     $np = $u->randomPassword();
     $u->setNewpassword($np, $throttle);
     $u->saveSettings();
     $userLanguage = $u->getOption('language');
     $mainPage = Title::newMainPage();
     $mainPageUrl = $mainPage->getCanonicalURL();
     $m = $this->msg($emailText, $ip, $u->getName(), $np, '<' . $mainPageUrl . '>', round($wgNewPasswordExpiry / 86400))->inLanguage($userLanguage)->text();
     $result = $u->sendMail($this->msg($emailTitle)->inLanguage($userLanguage)->text(), $m);
     return $result;
 }
 /**
  * Sends a reminder to the user.
  * @param User $sender
  * @param User $target
  * @param string $type 'reminder' or 'promotion'
  * @throws MWException
  * @since 2013.12
  */
 public static function sendEmail(User $sender, User $target, $type)
 {
     global $wgNoReplyAddress;
     $targetLang = $target->getOption('language');
     switch ($type) {
         case 'reminder':
             if (!self::isSandboxed($target)) {
                 throw new MWException('Not a sandboxed user');
             }
             $subjectMsg = 'tsb-reminder-title-generic';
             $bodyMsg = 'tsb-reminder-content-generic';
             $targetSpecialPage = 'TranslationStash';
             break;
         case 'promotion':
             $subjectMsg = 'tsb-email-promoted-subject';
             $bodyMsg = 'tsb-email-promoted-body';
             $targetSpecialPage = 'Translate';
             break;
         case 'rejection':
             $subjectMsg = 'tsb-email-rejected-subject';
             $bodyMsg = 'tsb-email-rejected-body';
             $targetSpecialPage = 'TwnMainPage';
             break;
         default:
             throw new MWException("'{$type}' is an invalid type of translate sandbox email");
     }
     $subject = wfMessage($subjectMsg)->inLanguage($targetLang)->text();
     $body = wfMessage($bodyMsg, $target->getName(), SpecialPage::getTitleFor($targetSpecialPage)->getCanonicalUrl(), $sender->getName())->inLanguage($targetLang)->text();
     $params = array('user' => $target->getId(), 'to' => new MailAddress($target), 'from' => new MailAddress($sender), 'replyto' => new MailAddress($wgNoReplyAddress), 'subj' => $subject, 'body' => $body, 'emailType' => $type);
     JobQueueGroup::singleton()->push(TranslateSandboxEmailJob::newJob($params));
 }
 /**
  * Adds Notifications preferences to the echo section
  * @param User $user
  * @param array $preferences
  * @return boolean
  */
 public function onGetPreferences($user, array &$preferences)
 {
     $preferences['MW::Notifications::NotifyNoMinor'] = array('type' => 'toggle', 'label-message' => 'bs-notifications-pref-notifynominor', 'section' => 'echo/echo-extended');
     $preferences['MW::Notifications::Active'] = array('type' => 'toggle', 'label-message' => 'bs-notifications-pref-active', 'section' => 'echo/echo-extended');
     // ugly workaraound for mw's handling of get default options from multivaluefields
     $sNotifyDefault = $user->getOption('MW::Notifications::NotifyNS', false) ? $user->getOption('MW::Notifications::NotifyNS') : array(0);
     $preferences['MW::Notifications::NotifyNS'] = array('type' => 'multiselectex', 'label-message' => 'bs-notifications-pref-notifyns', 'section' => 'echo/echo-extended', 'options' => BsNamespaceHelper::getNamespacesForSelectOptions(array(NS_SPECIAL, NS_MEDIA)), 'default' => $sNotifyDefault);
     return true;
 }
	/**
	 * Helper function for updateUser()
	 */
	private function updateOption( $option, User $user, $force ) {
		return $force === true || ( is_array( $force ) && in_array( $option, $force ) ) ||
			$user->getOption( 'openid-update-on-login-' . $option ) ||
			$user->getOption( 'openid-update-on-login' ); // Back compat with old option
	}
 /**
  * Extract default namespaces to search from the given user's
  * settings, returning a list of index numbers.
  *
  * @param User $user
  * @return array
  * @access private
  */
 function userNamespaces(&$user)
 {
     $arr = array();
     foreach (SearchEngine::searchableNamespaces() as $ns => $name) {
         if ($user->getOption('searchNs' . $ns)) {
             $arr[] = $ns;
         }
     }
     return $arr;
 }
 /**
  * Pull option from a user account. Handles stuff like array-type preferences.
  *
  * @param string $name
  * @param array $info
  * @param User $user
  * @return array|string
  */
 static function getOptionFromUser($name, $info, $user)
 {
     $val = $user->getOption($name);
     // Handling for multiselect preferences
     if (isset($info['type']) && $info['type'] == 'multiselect' || isset($info['class']) && $info['class'] == 'HTMLMultiSelectField') {
         $options = HTMLFormField::flattenOptions($info['options']);
         $prefix = isset($info['prefix']) ? $info['prefix'] : $name;
         $val = array();
         foreach ($options as $value) {
             if ($user->getOption("{$prefix}{$value}")) {
                 $val[] = $value;
             }
         }
     }
     // Handling for checkmatrix preferences
     if (isset($info['type']) && $info['type'] == 'checkmatrix' || isset($info['class']) && $info['class'] == 'HTMLCheckMatrix') {
         $columns = HTMLFormField::flattenOptions($info['columns']);
         $rows = HTMLFormField::flattenOptions($info['rows']);
         $prefix = isset($info['prefix']) ? $info['prefix'] : $name;
         $val = array();
         foreach ($columns as $column) {
             foreach ($rows as $row) {
                 if ($user->getOption("{$prefix}{$column}-{$row}")) {
                     $val[] = "{$column}-{$row}";
                 }
             }
         }
     }
     return $val;
 }
Exemple #18
0
 /**
  * Fetch the user's signature text, if any, and normalize to
  * validated, ready-to-insert wikitext.
  * If you have pre-fetched the nickname or the fancySig option, you can
  * specify them here to save a database query.
  * Do not reuse this parser instance after calling getUserSig(),
  * as it may have changed if it's the $wgParser.
  *
  * @param User $user
  * @param string|bool $nickname Nickname to use or false to use user's default nickname
  * @param bool|null $fancySig whether the nicknname is the complete signature
  *    or null to use default value
  * @return string
  */
 public function getUserSig(&$user, $nickname = false, $fancySig = null)
 {
     global $wgMaxSigChars;
     $username = $user->getName();
     # If not given, retrieve from the user object.
     if ($nickname === false) {
         $nickname = $user->getOption('nickname');
     }
     if (is_null($fancySig)) {
         $fancySig = $user->getBoolOption('fancysig');
     }
     $nickname = $nickname == null ? $username : $nickname;
     if (mb_strlen($nickname) > $wgMaxSigChars) {
         $nickname = $username;
         wfDebug(__METHOD__ . ": {$username} has overlong signature.\n");
     } elseif ($fancySig !== false) {
         # Sig. might contain markup; validate this
         if ($this->validateSig($nickname) !== false) {
             # Validated; clean up (if needed) and return it
             return $this->cleanSig($nickname, true);
         } else {
             # Failed to validate; fall back to the default
             $nickname = $username;
             wfDebug(__METHOD__ . ": {$username} has bad XML tags in signature.\n");
         }
     }
     # Make sure nickname doesnt get a sig in a sig
     $nickname = self::cleanSigInSig($nickname);
     # If we're still here, make it a link to the user page
     $userText = wfEscapeWikiText($username);
     $nickText = wfEscapeWikiText($nickname);
     $msgName = $user->isAnon() ? 'signature-anon' : 'signature';
     return wfMessage($msgName, $userText, $nickText)->inContentLanguage()->title($this->getTitle())->text();
 }
Exemple #19
0
 /**
  * Get user options
  *
  * @param User $user
  * @param Language $lang
  */
 private function initialiseFromUser($user, $lang)
 {
     global $wgInterwikiMagic, $wgAllowExternalImages, $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize, $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures, $wgExternalLinkTarget, $wgExpensiveParserFunctionLimit, $wgMaxGeneratedPPNodeCount, $wgDisableLangConversion, $wgDisableTitleConversion;
     // *UPDATE* ParserOptions::matches() if any of this changes as needed
     $this->mInterwikiMagic = $wgInterwikiMagic;
     $this->mAllowExternalImages = $wgAllowExternalImages;
     $this->mAllowExternalImagesFrom = $wgAllowExternalImagesFrom;
     $this->mEnableImageWhitelist = $wgEnableImageWhitelist;
     $this->mAllowSpecialInclusion = $wgAllowSpecialInclusion;
     $this->mMaxIncludeSize = $wgMaxArticleSize * 1024;
     $this->mMaxPPNodeCount = $wgMaxPPNodeCount;
     $this->mMaxGeneratedPPNodeCount = $wgMaxGeneratedPPNodeCount;
     $this->mMaxPPExpandDepth = $wgMaxPPExpandDepth;
     $this->mMaxTemplateDepth = $wgMaxTemplateDepth;
     $this->mExpensiveParserFunctionLimit = $wgExpensiveParserFunctionLimit;
     $this->mCleanSignatures = $wgCleanSignatures;
     $this->mExternalLinkTarget = $wgExternalLinkTarget;
     $this->mDisableContentConversion = $wgDisableLangConversion;
     $this->mDisableTitleConversion = $wgDisableLangConversion || $wgDisableTitleConversion;
     $this->mUser = $user;
     $this->mNumberHeadings = $user->getOption('numberheadings');
     $this->mThumbSize = $user->getOption('thumbsize');
     $this->mStubThreshold = $user->getStubThreshold();
     $this->mUserLang = $lang;
 }
 /**
  * Update user information in the external authentication database.
  * Return true if successful.
  *
  * @param User $user
  * @return bool
  * @access public
  */
 function updateExternalDB($user)
 {
     global $wgLDAPUpdateLDAP, $wgLDAPWikiDN, $wgLDAPWikiPassword;
     global $wgLDAPSearchStrings;
     if (!$wgLDAPUpdateLDAP) {
         return true;
     }
     $this->email = $user->getEmail();
     $this->realname = $user->getRealName();
     $this->nickname = $user->getOption('nickname');
     $this->language = $user->getOption('language');
     $tmpuserdn = $wgLDAPSearchStrings[$_SESSION['wsDomain']];
     $userdn = str_replace("USER-NAME", $user->getName(), $tmpuserdn);
     echo $userdn;
     $ldapconn = $this->connect();
     if ($ldapconn) {
         ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
         $bind = @ldap_bind($ldapconn, $wgLDAPWikiDN, $wgLDAPWikiPassword);
         if (!$bind) {
             return false;
         }
         if ('' != $this->email) {
             $values["mail"] = $this->email;
         }
         if ('' != $this->nickname) {
             $values["displayname"] = $this->nickname;
         }
         if ('' != $this->realname) {
             $values["cn"] = $this->realname;
         }
         if ('' != $this->language) {
             $values["preferredlanguage"] = $this->language;
         }
         if (0 != sizeof($values) && ldap_modify($ldapconn, $userdn, $values)) {
             @ldap_unbind();
             return true;
         } else {
             @ldap_unbind();
             return false;
         }
     } else {
         return false;
     }
 }
Exemple #21
0
 /**
  * Generate the generic "this page has been changed" e-mail text.
  */
 private function composeCommonMailtext()
 {
     global $wgPasswordSender, $wgNoReplyAddress;
     global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress;
     global $wgEnotifImpersonal, $wgEnotifUseRealName;
     $this->composed_common = true;
     # You as the WikiAdmin and Sysops can make use of plenty of
     # named variables when composing your notification emails while
     # simply editing the Meta pages
     $keys = array();
     $postTransformKeys = array();
     $pageTitleUrl = $this->title->getCanonicalURL();
     $pageTitle = $this->title->getPrefixedText();
     if ($this->oldid) {
         // Always show a link to the diff which triggered the mail. See bug 32210.
         $keys['$NEWPAGE'] = "\n\n" . wfMessage('enotif_lastdiff', $this->title->getCanonicalURL(array('diff' => 'next', 'oldid' => $this->oldid)))->inContentLanguage()->text();
         if (!$wgEnotifImpersonal) {
             // For personal mail, also show a link to the diff of all changes
             // since last visited.
             $keys['$NEWPAGE'] .= "\n\n" . wfMessage('enotif_lastvisited', $this->title->getCanonicalURL(array('diff' => '0', 'oldid' => $this->oldid)))->inContentLanguage()->text();
         }
         $keys['$OLDID'] = $this->oldid;
         // Deprecated since MediaWiki 1.21, not used by default. Kept for backwards-compatibility.
         $keys['$CHANGEDORCREATED'] = wfMessage('changed')->inContentLanguage()->text();
     } else {
         # clear $OLDID placeholder in the message template
         $keys['$OLDID'] = '';
         $keys['$NEWPAGE'] = '';
         // Deprecated since MediaWiki 1.21, not used by default. Kept for backwards-compatibility.
         $keys['$CHANGEDORCREATED'] = wfMessage('created')->inContentLanguage()->text();
     }
     $keys['$PAGETITLE'] = $this->title->getPrefixedText();
     $keys['$PAGETITLE_URL'] = $this->title->getCanonicalURL();
     $keys['$PAGEMINOREDIT'] = $this->minorEdit ? wfMessage('minoredit')->inContentLanguage()->text() : '';
     $keys['$UNWATCHURL'] = $this->title->getCanonicalURL('action=unwatch');
     if ($this->editor->isAnon()) {
         # real anon (user:xxx.xxx.xxx.xxx)
         $keys['$PAGEEDITOR'] = wfMessage('enotif_anon_editor', $this->editor->getName())->inContentLanguage()->text();
         $keys['$PAGEEDITOR_EMAIL'] = wfMessage('noemailtitle')->inContentLanguage()->text();
     } else {
         $keys['$PAGEEDITOR'] = $wgEnotifUseRealName && $this->editor->getRealName() !== '' ? $this->editor->getRealName() : $this->editor->getName();
         $emailPage = SpecialPage::getSafeTitleFor('Emailuser', $this->editor->getName());
         $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getCanonicalURL();
     }
     $keys['$PAGEEDITOR_WIKI'] = $this->editor->getUserPage()->getCanonicalURL();
     $keys['$HELPPAGE'] = wfExpandUrl(Skin::makeInternalOrExternalUrl(wfMessage('helppage')->inContentLanguage()->text()));
     # Replace this after transforming the message, bug 35019
     $postTransformKeys['$PAGESUMMARY'] = $this->summary == '' ? ' - ' : $this->summary;
     // Now build message's subject and body
     // Messages:
     // enotif_subject_deleted, enotif_subject_created, enotif_subject_moved,
     // enotif_subject_restored, enotif_subject_changed
     $this->subject = wfMessage('enotif_subject_' . $this->pageStatus)->inContentLanguage()->params($pageTitle, $keys['$PAGEEDITOR'])->text();
     // Messages:
     // enotif_body_intro_deleted, enotif_body_intro_created, enotif_body_intro_moved,
     // enotif_body_intro_restored, enotif_body_intro_changed
     $keys['$PAGEINTRO'] = wfMessage('enotif_body_intro_' . $this->pageStatus)->inContentLanguage()->params($pageTitle, $keys['$PAGEEDITOR'], $pageTitleUrl)->text();
     $body = wfMessage('enotif_body')->inContentLanguage()->plain();
     $body = strtr($body, $keys);
     $body = MessageCache::singleton()->transform($body, false, null, $this->title);
     $this->body = wordwrap(strtr($body, $postTransformKeys), 72);
     # 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($wgPasswordSender, wfMessage('emailsender')->inContentLanguage()->text());
     if ($wgEnotifRevealEditorAddress && $this->editor->getEmail() != '' && $this->editor->getOption('enotifrevealaddr')) {
         $editorAddress = MailAddress::newFromUser($this->editor);
         if ($wgEnotifFromEditor) {
             $this->from = $editorAddress;
         } else {
             $this->from = $adminAddress;
             $this->replyto = $editorAddress;
         }
     } else {
         $this->from = $adminAddress;
         $this->replyto = new MailAddress($wgNoReplyAddress);
     }
 }
	/**
	 * Register the user viewed the watchlist,
	 * so we know that following chnages should
	 * result into notification emails is desired.
	 * 
	 * @since 0.1
	 * 
	 * @param User $user
	 */
	protected function registerUserView( User $user ) {
		$this->lastViewed = $user->getOption( 'swl_last_view' );
		
		if ( is_null( $this->lastViewed ) ) {
			$this->lastViewed = wfTimestampNow();
		}
		
		$user->setOption( 'swl_last_view', wfTimestampNow() );
		$user->setOption( 'swl_mail_count',0 );
		$user->saveSettings();		
	}
Exemple #23
0
 /**
  * Fetch the user's signature text, if any, and normalize to
  * validated, ready-to-insert wikitext.
  *
  * @param User $user
  * @return string
  * @private
  */
 function getUserSig(&$user)
 {
     global $wgMaxSigChars;
     $username = $user->getName();
     $nickname = $user->getOption('nickname');
     $nickname = $nickname === '' ? $username : $nickname;
     if (mb_strlen($nickname) > $wgMaxSigChars) {
         $nickname = $username;
         wfDebug(__METHOD__ . ": {$username} has overlong signature.\n");
     } elseif ($user->getBoolOption('fancysig') !== false) {
         # Sig. might contain markup; validate this
         if ($this->validateSig($nickname) !== false) {
             # Validated; clean up (if needed) and return it
             return $this->cleanSig($nickname, true);
         } else {
             # Failed to validate; fall back to the default
             $nickname = $username;
             wfDebug(__METHOD__ . ": {$username} has bad XML tags in signature.\n");
         }
     }
     // Make sure nickname doesnt get a sig in a sig
     $nickname = $this->cleanSigInSig($nickname);
     # If we're still here, make it a link to the user page
     $userText = wfEscapeWikiText($username);
     $nickText = wfEscapeWikiText($nickname);
     if ($user->isAnon()) {
         return wfMsgExt('signature-anon', array('content', 'parsemag'), $userText, $nickText);
     } else {
         return wfMsgExt('signature', array('content', 'parsemag'), $userText, $nickText);
     }
 }
Exemple #24
0
 /**
  * Does the per-user customizations to a notification e-mail (name,
  * timestamp in proper timezone, etc) and sends it out.
  * Returns true if the mail was sent successfully.
  *
  * @param User $watchingUser
  * @param object $mail
  * @return bool
  * @private
  */
 function composeAndSendPersonalisedMail($watchingUser)
 {
     global $wgLang;
     // From the PHP manual:
     //     Note:  The to parameter cannot be an address in the form of "Something <*****@*****.**>".
     //     The mail command will not parse this properly while talking with the MTA.
     $to = new MailAddress($watchingUser);
     $body = str_replace('$WATCHINGUSERNAME', $watchingUser->getName(), $this->body);
     $timecorrection = $watchingUser->getOption('timecorrection');
     # $PAGEEDITDATE is the time and date of the page change
     # expressed in terms of individual local time of the notification
     # recipient, i.e. watching user
     $body = str_replace('$PAGEEDITDATE', $wgLang->timeanddate($this->timestamp, true, false, $timecorrection), $body);
     $error = userMailer($to, $this->from, $this->subject, $body, $this->replyto);
     return $error == '';
 }
 /**
  * Get the header for the watchlist page
  * @param User user
  * @return string Parsed HTML
  */
 public static function getWatchlistHeader(User $user)
 {
     $sp = SpecialPage::getTitleFor('Watchlist');
     $attrsList = $attrsFeed = array();
     $view = $user->getOption(SpecialMobileWatchlist::VIEW_OPTION_NAME, 'a-z');
     $filter = $user->getOption(SpecialMobileWatchlist::FILTER_OPTION_NAME, 'all');
     if ($view === 'feed') {
         $attrsList['class'] = MobileUI::buttonClass();
         // FIXME [MediaWiki UI] This probably be described as a different type of mediawiki ui element
         $attrsFeed['class'] = MobileUI::buttonClass('progressive', 'active');
     } else {
         $attrsFeed['class'] = MobileUI::buttonClass();
         // FIXME [MediaWiki UI] This probably be described as a different type of mediawiki ui element
         $attrsList['class'] = MobileUI::buttonClass('progressive', 'active');
     }
     $html = Html::openElement('ul', array('class' => 'button-bar mw-ui-button-group')) . Html::openElement('li', $attrsList) . Linker::link($sp, wfMessage('mobile-frontend-watchlist-a-z')->text(), array('class' => 'button'), array('watchlistview' => 'a-z')) . Html::closeElement('li') . Html::openElement('li', $attrsFeed) . Linker::link($sp, wfMessage('mobile-frontend-watchlist-feed')->text(), array('class' => 'button'), array('watchlistview' => 'feed', 'filter' => $filter)) . Html::closeElement('li') . Html::closeElement('ul');
     return '<div class="content-header">' . $html . '</div>';
 }
 function getOption($option, $defaultOverride = '')
 {
     if ($option === 'fancysig') {
         return $this->ppfz_test->fancySig;
     } elseif ($option === 'nickname') {
         return $this->ppfz_test->nickname;
     } else {
         return parent::getOption($option, $defaultOverride);
     }
 }
Exemple #27
0
 /**
  * Internal helper function for userDate(), userTime() and userTimeAndDate()
  *
  * @param string $type Can be 'date', 'time' or 'both'
  * @param string $ts The time format which needs to be turned into a
  *   date('YmdHis') format with wfTimestamp(TS_MW,$ts)
  * @param User $user User object used to get preferences for timezone and format
  * @param array $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
  *     - int: 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->getOption('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);
 }
 /**
  * send reminder email
  * @param User $user
  * @return Status object
  */
 public function sendConfirmationReminderEmail(&$user)
 {
     if ($user->getOption("cr_mailed", 0) == 1) {
         return false;
     }
     $emailTextTemplate = $this->app->renderView("UserLogin", "GeneralMail", array('language' => $user->getOption('language'), 'type' => 'confirmation-reminder-email'));
     $user->setOption("cr_mailed", "1");
     return $user->sendConfirmationMail(false, 'ConfirmationReminderMail', 'usersignup-confirmation-reminder-email', true, $emailTextTemplate);
 }
 /** Get user options */
 function initialiseFromUser($userInput)
 {
     global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
     global $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion, $wgMaxArticleSize;
     global $wgMaxPPNodeCount, $wgMaxTemplateDepth;
     $fname = 'ParserOptions::initialiseFromUser';
     wfProfileIn($fname);
     if (!$userInput) {
         global $wgUser;
         if (isset($wgUser)) {
             $user = $wgUser;
         } else {
             $user = new User();
         }
     } else {
         $user =& $userInput;
     }
     $this->mUser = $user;
     $this->mUseTeX = $wgUseTeX;
     $this->mUseDynamicDates = $wgUseDynamicDates;
     $this->mInterwikiMagic = $wgInterwikiMagic;
     $this->mAllowExternalImages = $wgAllowExternalImages;
     $this->mAllowExternalImagesFrom = $wgAllowExternalImagesFrom;
     $this->mSkin = null;
     # Deferred
     $this->mDateFormat = null;
     # Deferred
     $this->mEditSection = true;
     $this->mNumberHeadings = $user->getOption('numberheadings');
     $this->mAllowSpecialInclusion = $wgAllowSpecialInclusion;
     $this->mTidy = false;
     $this->mInterfaceMessage = false;
     $this->mMaxIncludeSize = $wgMaxArticleSize * 1024;
     $this->mMaxPPNodeCount = $wgMaxPPNodeCount;
     $this->mMaxTemplateDepth = $wgMaxTemplateDepth;
     $this->mRemoveComments = true;
     $this->mTemplateCallback = array('Parser', 'statelessFetchTemplate');
     $this->mEnableLimitReport = false;
     wfProfileOut($fname);
 }
 /**
  * Update user information in LDAP
  * Return true if successful.
  *
  * @param User $user
  * @return bool
  */
 public function updateExternalDB($user)
 {
     global $wgMemc;
     $this->printDebug("Entering updateExternalDB", NONSENSITIVE);
     if (!$this->getConf('UpdateLDAP') || $this->getSessionDomain() == 'local') {
         $this->printDebug("Either the user is using a local domain, or the wiki isn't allowing updates", NONSENSITIVE);
         // We don't handle local preferences, but we don't want the
         // wiki to return an error.
         return true;
     }
     $writer = $this->getConf('WriterDN');
     if (!$writer) {
         $this->printDebug("The wiki doesn't have wgLDAPWriterDN set", NONSENSITIVE);
         // We can't modify LDAP preferences if we don't have a user
         // capable of editing LDAP attributes.
         return false;
     }
     $this->email = $user->getEmail();
     $this->realname = $user->getRealName();
     $this->nickname = $user->getOption('nickname');
     $this->lang = $user->getOption('language');
     if ($this->connect()) {
         $this->userdn = $this->getSearchString($user->getName());
         $this->printDebug("Binding as the writerDN", NONSENSITIVE);
         $bind = $this->bindAs($writer, $this->getConf('WriterPassword'));
         if (!$bind) {
             return false;
         }
         $values = array();
         if (is_string($this->email)) {
             $values["mail"] = $this->email;
         }
         if (is_string($this->nickname)) {
             $values["displayname"] = $this->nickname;
         }
         if (is_string($this->realname)) {
             $values["cn"] = $this->realname;
         }
         if (is_string($this->lang)) {
             $values["preferredlanguage"] = $this->lang;
         }
         if (count($values) && LdapAuthenticationPlugin::ldap_modify($this->ldapconn, $this->userdn, $values)) {
             // We changed the user, we need to invalidate the memcache key
             $key = wfMemcKey('ldapauthentication', 'userinfo', $this->userdn);
             $wgMemc->delete($key);
             $this->printDebug("Successfully modified the user's attributes", NONSENSITIVE);
             LdapAuthenticationPlugin::ldap_unbind($this->ldapconn);
             return true;
         }
         $this->printDebug("Failed to modify the user's attributes", NONSENSITIVE);
         LdapAuthenticationPlugin::ldap_unbind($this->ldapconn);
     }
     return false;
 }