Ejemplo n.º 1
0
 protected function getFormFields()
 {
     global $wgContLang;
     $timestamp = $this->oldFile->getTimestamp();
     $user = $this->getUser();
     $lang = $this->getLanguage();
     $userDate = $lang->userDate($timestamp, $user);
     $userTime = $lang->userTime($timestamp, $user);
     $siteTs = MWTimestamp::getLocalInstance($timestamp);
     $ts = $siteTs->format('YmdHis');
     $siteDate = $wgContLang->date($ts, false, false);
     $siteTime = $wgContLang->time($ts, false, false);
     $tzMsg = $siteTs->getTimezoneMessage()->inContentLanguage()->text();
     return ['intro' => ['type' => 'info', 'vertical-label' => true, 'raw' => true, 'default' => $this->msg('filerevert-intro', $this->getTitle()->getText(), $userDate, $userTime, wfExpandUrl($this->page->getFile()->getArchiveUrl($this->getRequest()->getText('oldimage')), PROTO_CURRENT))->parseAsBlock()], 'comment' => ['type' => 'text', 'label-message' => 'filerevert-comment', 'default' => $this->msg('filerevert-defaultcomment', $siteDate, $siteTime, $tzMsg)->inContentLanguage()->text()]];
 }
Ejemplo n.º 2
0
	/**
	 * @param $context IContextSource
	 * @return array
	 */
	static function getTimezoneOptions( IContextSource $context ) {
		$opt = array();

		global $wgLocalTZoffset;
		$timestamp = MWTimestamp::getLocalInstance();
		// Check that $wgLocalTZoffset is the same as the local time zone offset
		if ( $wgLocalTZoffset == $timestamp->format( 'Z' ) / 60 ) {
			$server_tz_msg = $context->msg( 'timezoneuseserverdefault', $timestamp->getTimezone()->getName() )->text();
		} else {
			$tzstring = sprintf( '%+03d:%02d', floor( $wgLocalTZoffset / 60 ), abs( $wgLocalTZoffset ) % 60 );
			$server_tz_msg = $context->msg( 'timezoneuseserverdefault', $tzstring )->text();
		}
		$opt[$server_tz_msg] = "System|$wgLocalTZoffset";
		$opt[$context->msg( 'timezoneuseoffset' )->text()] = 'other';
		$opt[$context->msg( 'guesstimezone' )->text()] = 'guess';

		if ( function_exists( 'timezone_identifiers_list' ) ) {
			# Read timezone list
			$tzs = timezone_identifiers_list();
			sort( $tzs );

			$tzRegions = array();
			$tzRegions['Africa'] = $context->msg( 'timezoneregion-africa' )->text();
			$tzRegions['America'] = $context->msg( 'timezoneregion-america' )->text();
			$tzRegions['Antarctica'] = $context->msg( 'timezoneregion-antarctica' )->text();
			$tzRegions['Arctic'] = $context->msg( 'timezoneregion-arctic' )->text();
			$tzRegions['Asia'] = $context->msg( 'timezoneregion-asia' )->text();
			$tzRegions['Atlantic'] = $context->msg( 'timezoneregion-atlantic' )->text();
			$tzRegions['Australia'] = $context->msg( 'timezoneregion-australia' )->text();
			$tzRegions['Europe'] = $context->msg( 'timezoneregion-europe' )->text();
			$tzRegions['Indian'] = $context->msg( 'timezoneregion-indian' )->text();
			$tzRegions['Pacific'] = $context->msg( 'timezoneregion-pacific' )->text();
			asort( $tzRegions );

			$prefill = array_fill_keys( array_values( $tzRegions ), array() );
			$opt = array_merge( $opt, $prefill );

			$now = date_create( 'now' );

			foreach ( $tzs as $tz ) {
				$z = explode( '/', $tz, 2 );

				# timezone_identifiers_list() returns a number of
				# backwards-compatibility entries. This filters them out of the
				# list presented to the user.
				if ( count( $z ) != 2 || !array_key_exists( $z[0], $tzRegions ) ) {
					continue;
				}

				# Localize region
				$z[0] = $tzRegions[$z[0]];

				$minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );

				$display = str_replace( '_', ' ', $z[0] . '/' . $z[1] );
				$value = "ZoneInfo|$minDiff|$tz";

				$opt[$z[0]][$display] = $value;
			}
		}
		return $opt;
	}
Ejemplo n.º 3
0
 /**
  * Get the timestamp from the last revision of a specified page.
  * @param Parser $parser
  * @param string $title Title to get the timestamp from
  * @return string
  * @since 1.23
  */
 public static function revisiontimestamp($parser, $title = null)
 {
     $t = Title::newFromText($title);
     if (is_null($t)) {
         return '';
     }
     // fetch revision from cache/database and return the value
     $rev = self::getCachedRevisionObject($parser, $t);
     return $rev ? MWTimestamp::getLocalInstance($rev->getTimestamp())->format('YmdHis') : '';
 }
Ejemplo n.º 4
0
 /**
  * Pre-save transform helper function
  *
  * @param $text string
  * @param $user User
  *
  * @return string
  */
 private function pstPass2($text, $user)
 {
     global $wgContLang;
     # Note: This is the timestamp saved as hardcoded wikitext to
     # the database, we use $wgContLang here in order to give
     # everyone the same signature and use the default one rather
     # than the one selected in each user's preferences.
     # (see also bug 12815)
     $ts = $this->mOptions->getTimestamp();
     $timestamp = MWTimestamp::getLocalInstance($ts);
     $ts = $timestamp->format('YmdHis');
     $tzMsg = $timestamp->format('T');
     # might vary on DST changeover!
     # Allow translation of timezones through wiki. format() can return
     # whatever crap the system uses, localised or not, so we cannot
     # ship premade translations.
     $key = 'timezone-' . strtolower(trim($tzMsg));
     $msg = wfMessage($key)->inContentLanguage();
     if ($msg->exists()) {
         $tzMsg = $msg->text();
     }
     $d = $wgContLang->timeanddate($ts, false, false) . " ({$tzMsg})";
     # Variable replacement
     # Because mOutputType is OT_WIKI, this will only process {{subst:xxx}} type tags
     $text = $this->replaceVariables($text);
     # This works almost by chance, as the replaceVariables are done before the getUserSig(),
     # which may corrupt this parser instance via its wfMessage()->text() call-
     # Signatures
     $sigText = $this->getUserSig($user);
     $text = strtr($text, array('~~~~~' => $d, '~~~~' => "{$sigText} {$d}", '~~~' => $sigText));
     # Context links ("pipe tricks"): [[|name]] and [[name (context)|]]
     $tc = '[' . Title::legalChars() . ']';
     $nc = '[ _0-9A-Za-z\\x80-\\xff-]';
     # Namespaces can use non-ascii!
     $p1 = "/\\[\\[(:?{$nc}+:|:|)({$tc}+?)( ?\\({$tc}+\\))\\|]]/";
     # [[ns:page (context)|]]
     $p4 = "/\\[\\[(:?{$nc}+:|:|)({$tc}+?)( ?({$tc}+))\\|]]/";
     # [[ns:page(context)|]] (double-width brackets, added in r40257)
     $p3 = "/\\[\\[(:?{$nc}+:|:|)({$tc}+?)( ?\\({$tc}+\\)|)((?:, |,){$tc}+|)\\|]]/";
     # [[ns:page (context), context|]] (using either single or double-width comma)
     $p2 = "/\\[\\[\\|({$tc}+)]]/";
     # [[|page]] (reverse pipe trick: add context from page title)
     # try $p1 first, to turn "[[A, B (C)|]]" into "[[A, B (C)|A, B]]"
     $text = preg_replace($p1, '[[\\1\\2\\3|\\2]]', $text);
     $text = preg_replace($p4, '[[\\1\\2\\3|\\2]]', $text);
     $text = preg_replace($p3, '[[\\1\\2\\3\\4|\\2]]', $text);
     $t = $this->mTitle->getText();
     $m = array();
     if (preg_match("/^({$nc}+:|){$tc}+?( \\({$tc}+\\))\$/", $t, $m)) {
         $text = preg_replace($p2, "[[{$m['1']}\\1{$m['2']}|\\1]]", $text);
     } elseif (preg_match("/^({$nc}+:|){$tc}+?(, {$tc}+|)\$/", $t, $m) && "{$m['1']}{$m['2']}" != '') {
         $text = preg_replace($p2, "[[{$m['1']}\\1{$m['2']}|\\1]]", $text);
     } else {
         # if there's no context, don't bother duplicating the title
         $text = preg_replace($p2, '[[\\1]]', $text);
     }
     # Trim trailing whitespace
     $text = rtrim($text);
     return $text;
 }
 /**
  * Print the history page for an article.
  */
 function onView()
 {
     $out = $this->getOutput();
     $request = $this->getRequest();
     /**
      * Allow client caching.
      */
     if ($out->checkLastModified($this->page->getTouched())) {
         return;
         // Client cache fresh and headers sent, nothing more to do.
     }
     wfProfileIn(__METHOD__);
     $this->preCacheMessages();
     $config = $this->context->getConfig();
     # Fill in the file cache if not set already
     $useFileCache = $config->get('UseFileCache');
     if ($useFileCache && HTMLFileCache::useFileCache($this->getContext())) {
         $cache = HTMLFileCache::newFromTitle($this->getTitle(), 'history');
         if (!$cache->isCacheGood()) {
             ob_start(array(&$cache, 'saveToFileCache'));
         }
     }
     // Setup page variables.
     $out->setFeedAppendQuery('action=history');
     $out->addModules('mediawiki.action.history');
     if ($config->get('UseMediaWikiUIEverywhere')) {
         $out = $this->getOutput();
         $out->addModuleStyles(array('mediawiki.ui.input', 'mediawiki.ui.checkbox'));
     }
     // Handle atom/RSS feeds.
     $feedType = $request->getVal('feed');
     if ($feedType) {
         $this->feed($feedType);
         wfProfileOut(__METHOD__);
         return;
     }
     // Fail nicely if article doesn't exist.
     if (!$this->page->exists()) {
         $out->addWikiMsg('nohistory');
         # show deletion/move log if there is an entry
         LogEventsList::showLogExtract($out, array('delete', 'move'), $this->getTitle(), '', array('lim' => 10, 'conds' => array("log_action != 'revision'"), 'showIfEmpty' => false, 'msgKey' => array('moveddeleted-notice')));
         wfProfileOut(__METHOD__);
         return;
     }
     /**
      * Add date selector to quickly get to a certain time
      */
     $year = $request->getInt('year');
     $month = $request->getInt('month');
     $tagFilter = $request->getVal('tagfilter');
     $tagSelector = ChangeTags::buildTagFilterSelector($tagFilter);
     /**
      * Option to show only revisions that have been (partially) hidden via RevisionDelete
      */
     if ($request->getBool('deleted')) {
         $conds = array('rev_deleted != 0');
     } else {
         $conds = array();
     }
     if ($this->getUser()->isAllowed('deletedhistory')) {
         $checkDeleted = Xml::checkLabel($this->msg('history-show-deleted')->text(), 'deleted', 'mw-show-deleted-only', $request->getBool('deleted')) . "\n";
     } else {
         $checkDeleted = '';
     }
     // Add the general form
     $action = htmlspecialchars(wfScript());
     $out->addHTML("<form action=\"{$action}\" method=\"get\" id=\"mw-history-searchform\">" . Xml::fieldset($this->msg('history-fieldset-title')->text(), false, array('id' => 'mw-history-search')) . Html::hidden('title', $this->getTitle()->getPrefixedDBkey()) . "\n" . Html::hidden('action', 'history') . "\n" . Xml::dateMenu($year == null ? MWTimestamp::getLocalInstance()->format('Y') : $year, $month) . '&#160;' . ($tagSelector ? implode('&#160;', $tagSelector) . '&#160;' : '') . $checkDeleted . Xml::submitButton($this->msg('allpagessubmit')->text()) . "\n" . '</fieldset></form>');
     wfRunHooks('PageHistoryBeforeList', array(&$this->page, $this->getContext()));
     // Create and output the list.
     $pager = new HistoryPager($this, $year, $month, $tagFilter, $conds);
     $out->addHTML($pager->getNavigationBar() . $pager->getBody() . $pager->getNavigationBar());
     $out->preventClickjacking($pager->getPreventClickjacking());
     wfProfileOut(__METHOD__);
 }
Ejemplo n.º 6
0
 protected function doQuery($sql)
 {
     wfDebug("SQL: [{$sql}]\n");
     if (!StringUtils::isUtf8($sql)) {
         throw new MWException("SQL encoding is invalid\n{$sql}");
     }
     // handle some oracle specifics
     // remove AS column/table/subquery namings
     if (!$this->getFlag(DBO_DDLMODE)) {
         $sql = preg_replace('/ as /i', ' ', $sql);
     }
     // Oracle has issues with UNION clause if the statement includes LOB fields
     // So we do a UNION ALL and then filter the results array with array_unique
     $union_unique = preg_match('/\\/\\* UNION_UNIQUE \\*\\/ /', $sql) != 0;
     // EXPLAIN syntax in Oracle is EXPLAIN PLAN FOR and it return nothing
     // you have to select data from plan table after explain
     $explain_id = MWTimestamp::getLocalInstance()->format('dmYHis');
     $sql = preg_replace('/^EXPLAIN /', 'EXPLAIN PLAN SET STATEMENT_ID = \'' . $explain_id . '\' FOR', $sql, 1, $explain_count);
     MediaWiki\suppressWarnings();
     $this->mLastResult = $stmt = oci_parse($this->mConn, $sql);
     if ($stmt === false) {
         $e = oci_error($this->mConn);
         $this->reportQueryError($e['message'], $e['code'], $sql, __METHOD__);
         return false;
     }
     if (!oci_execute($stmt, $this->execFlags())) {
         $e = oci_error($stmt);
         if (!$this->ignoreDupValOnIndex || $e['code'] != '1') {
             $this->reportQueryError($e['message'], $e['code'], $sql, __METHOD__);
             return false;
         }
     }
     MediaWiki\restoreWarnings();
     if ($explain_count > 0) {
         return $this->doQuery('SELECT id, cardinality "ROWS" FROM plan_table ' . 'WHERE statement_id = \'' . $explain_id . '\'');
     } elseif (oci_statement_type($stmt) == 'SELECT') {
         return new ORAResult($this, $stmt, $union_unique);
     } else {
         $this->mAffectedRows = oci_num_rows($stmt);
         return true;
     }
 }
Ejemplo n.º 7
0
 /**
  * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
  *
  * @return String
  */
 public static function getCopyrightAndAuthorList()
 {
     global $wgLang;
     if (defined('MEDIAWIKI_INSTALL')) {
         $othersLink = '[//www.mediawiki.org/wiki/Special:Version/Credits ' . wfMessage('version-poweredby-others')->text() . ']';
     } else {
         $othersLink = '[[Special:Version/Credits|' . wfMessage('version-poweredby-others')->text() . ']]';
     }
     $translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' . wfMessage('version-poweredby-translators')->text() . ']';
     $authorList = array('Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker', 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason', 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan', 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking', 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe', 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed', 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso', 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', $othersLink, $translatorsLink);
     return wfMessage('version-poweredby-credits', MWTimestamp::getLocalInstance()->format('Y'), $wgLang->listToText($authorList))->text();
 }
Ejemplo n.º 8
0
 /**
  * This function will perform a direct (authenticated) login to
  * a SMTP Server to use for mail relaying if 'wgSMTP' specifies an
  * array of parameters. It requires PEAR:Mail to do that.
  * Otherwise it just uses the standard PHP 'mail' function.
  *
  * @param MailAddress|MailAddress[] $to Recipient's email (or an array of them)
  * @param MailAddress $from Sender's email
  * @param string $subject Email's subject.
  * @param string $body Email's text or Array of two strings to be the text and html bodies
  * @param MailAddress $replyto Optional reply-to email (default: null).
  * @param string $contentType Optional custom Content-Type (default: text/plain; charset=UTF-8)
  * @throws MWException
  * @throws Exception
  * @return Status
  */
 public static function send($to, $from, $subject, $body, $replyto = null, $contentType = 'text/plain; charset=UTF-8')
 {
     global $wgSMTP, $wgEnotifMaxRecips, $wgAdditionalMailParams, $wgAllowHTMLEmail;
     $mime = null;
     if (!is_array($to)) {
         $to = array($to);
     }
     // mail body must have some content
     $minBodyLen = 10;
     // arbitrary but longer than Array or Object to detect casting error
     // body must either be a string or an array with text and body
     if (!(!is_array($body) && strlen($body) >= $minBodyLen) && !(is_array($body) && isset($body['text']) && isset($body['html']) && strlen($body['text']) >= $minBodyLen && strlen($body['html']) >= $minBodyLen)) {
         // if it is neither we have a problem
         return Status::newFatal('user-mail-no-body');
     }
     if (!$wgAllowHTMLEmail && is_array($body)) {
         // HTML not wanted.  Dump it.
         $body = $body['text'];
     }
     wfDebug(__METHOD__ . ': sending mail to ' . implode(', ', $to) . "\n");
     # Make sure we have at least one address
     $has_address = false;
     foreach ($to as $u) {
         if ($u->address) {
             $has_address = true;
             break;
         }
     }
     if (!$has_address) {
         return Status::newFatal('user-mail-no-addy');
     }
     # Forge email headers
     # -------------------
     #
     # WARNING
     #
     # DO NOT add To: or Subject: headers at this step. They need to be
     # handled differently depending upon the mailer we are going to use.
     #
     # To:
     #  PHP mail() first argument is the mail receiver. The argument is
     #  used as a recipient destination and as a To header.
     #
     #  PEAR mailer has a recipient argument which is only used to
     #  send the mail. If no To header is given, PEAR will set it to
     #  to 'undisclosed-recipients:'.
     #
     #  NOTE: To: is for presentation, the actual recipient is specified
     #  by the mailer using the Rcpt-To: header.
     #
     # Subject:
     #  PHP mail() second argument to pass the subject, passing a Subject
     #  as an additional header will result in a duplicate header.
     #
     #  PEAR mailer should be passed a Subject header.
     #
     # -- hashar 20120218
     $headers['From'] = $from->toString();
     $returnPath = $from->address;
     $extraParams = $wgAdditionalMailParams;
     // Hook to generate custom VERP address for 'Return-Path'
     Hooks::run('UserMailerChangeReturnPath', array($to, &$returnPath));
     # Add the envelope sender address using the -f command line option when PHP mail() is used.
     # Will default to the $from->address when the UserMailerChangeReturnPath hook fails and the
     # generated VERP address when the hook runs effectively.
     $extraParams .= ' -f ' . $returnPath;
     $headers['Return-Path'] = $returnPath;
     if ($replyto) {
         $headers['Reply-To'] = $replyto->toString();
     }
     $headers['Date'] = MWTimestamp::getLocalInstance()->format('r');
     $headers['Message-ID'] = self::makeMsgId();
     $headers['X-Mailer'] = 'MediaWiki mailer';
     # Line endings need to be different on Unix and Windows due to
     # the bug described at http://trac.wordpress.org/ticket/2603
     if (wfIsWindows()) {
         $endl = "\r\n";
     } else {
         $endl = "\n";
     }
     if (is_array($body)) {
         // we are sending a multipart message
         wfDebug("Assembling multipart mime email\n");
         if (!stream_resolve_include_path('Mail/mime.php')) {
             wfDebug("PEAR Mail_Mime package is not installed. Falling back to text email.\n");
             // remove the html body for text email fall back
             $body = $body['text'];
         } else {
             require_once 'Mail/mime.php';
             if (wfIsWindows()) {
                 $body['text'] = str_replace("\n", "\r\n", $body['text']);
                 $body['html'] = str_replace("\n", "\r\n", $body['html']);
             }
             $mime = new Mail_mime(array('eol' => $endl, 'text_charset' => 'UTF-8', 'html_charset' => 'UTF-8'));
             $mime->setTXTBody($body['text']);
             $mime->setHTMLBody($body['html']);
             $body = $mime->get();
             // must call get() before headers()
             $headers = $mime->headers($headers);
         }
     }
     if ($mime === null) {
         // sending text only, either deliberately or as a fallback
         if (wfIsWindows()) {
             $body = str_replace("\n", "\r\n", $body);
         }
         $headers['MIME-Version'] = '1.0';
         $headers['Content-type'] = is_null($contentType) ? 'text/plain; charset=UTF-8' : $contentType;
         $headers['Content-transfer-encoding'] = '8bit';
     }
     $ret = Hooks::run('AlternateUserMailer', array($headers, $to, $from, $subject, $body));
     if ($ret === false) {
         // the hook implementation will return false to skip regular mail sending
         return Status::newGood();
     } elseif ($ret !== true) {
         // the hook implementation will return a string to pass an error message
         return Status::newFatal('php-mail-error', $ret);
     }
     if (is_array($wgSMTP)) {
         #
         # PEAR MAILER
         #
         //start Eli Agbayani Nov 26, 2015
         $path = '/usr/local/Cellar/php53/5.3.29_2/lib/php';
         set_include_path(get_include_path() . PATH_SEPARATOR . $path);
         //end Eli Agbayani
         if (!stream_resolve_include_path('Mail.php')) {
             throw new MWException('PEAR mail package is not installed');
         }
         require_once 'Mail.php';
         wfSuppressWarnings();
         // Create the mail object using the Mail::factory method
         $mail_object =& Mail::factory('smtp', $wgSMTP);
         if (PEAR::isError($mail_object)) {
             wfDebug("PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n");
             wfRestoreWarnings();
             return Status::newFatal('pear-mail-error', $mail_object->getMessage());
         }
         wfDebug("Sending mail via PEAR::Mail\n");
         $headers['Subject'] = self::quotedPrintable($subject);
         # When sending only to one recipient, shows it its email using To:
         if (count($to) == 1) {
             $headers['To'] = $to[0]->toString();
         }
         # Split jobs since SMTP servers tends to limit the maximum
         # number of possible recipients.
         $chunks = array_chunk($to, $wgEnotifMaxRecips);
         foreach ($chunks as $chunk) {
             $status = self::sendWithPear($mail_object, $chunk, $headers, $body);
             # FIXME : some chunks might be sent while others are not!
             if (!$status->isOK()) {
                 wfRestoreWarnings();
                 return $status;
             }
         }
         wfRestoreWarnings();
         return Status::newGood();
     } else {
         #
         # PHP mail()
         #
         if (count($to) > 1) {
             $headers['To'] = 'undisclosed-recipients:;';
         }
         $headers = self::arrayToHeaderString($headers, $endl);
         wfDebug("Sending mail via internal mail() function\n");
         self::$mErrorString = '';
         $html_errors = ini_get('html_errors');
         ini_set('html_errors', '0');
         set_error_handler('UserMailer::errorHandler');
         try {
             $safeMode = wfIniGetBool('safe_mode');
             foreach ($to as $recip) {
                 if ($safeMode) {
                     $sent = mail($recip, self::quotedPrintable($subject), $body, $headers);
                 } else {
                     $sent = mail($recip, self::quotedPrintable($subject), $body, $headers, $extraParams);
                 }
             }
         } catch (Exception $e) {
             restore_error_handler();
             throw $e;
         }
         restore_error_handler();
         ini_set('html_errors', $html_errors);
         if (self::$mErrorString) {
             wfDebug("Error sending mail: " . self::$mErrorString . "\n");
             return Status::newFatal('php-mail-error', self::$mErrorString);
         } elseif (!$sent) {
             // mail function only tells if there's an error
             wfDebug("Unknown error sending mail\n");
             return Status::newFatal('php-mail-error-unknown');
         } else {
             return Status::newGood();
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * @param IContextSource $context
  * @return array
  */
 static function getTimezoneOptions(IContextSource $context)
 {
     $opt = array();
     $localTZoffset = $context->getConfig()->get('LocalTZoffset');
     $timeZoneList = self::getTimeZoneList($context->getLanguage());
     $timestamp = MWTimestamp::getLocalInstance();
     // Check that the LocalTZoffset is the same as the local time zone offset
     if ($localTZoffset == $timestamp->format('Z') / 60) {
         $timezoneName = $timestamp->getTimezone()->getName();
         // Localize timezone
         if (isset($timeZoneList[$timezoneName])) {
             $timezoneName = $timeZoneList[$timezoneName]['name'];
         }
         $server_tz_msg = $context->msg('timezoneuseserverdefault', $timezoneName)->text();
     } else {
         $tzstring = sprintf('%+03d:%02d', floor($localTZoffset / 60), abs($localTZoffset) % 60);
         $server_tz_msg = $context->msg('timezoneuseserverdefault', $tzstring)->text();
     }
     $opt[$server_tz_msg] = "System|{$localTZoffset}";
     $opt[$context->msg('timezoneuseoffset')->text()] = 'other';
     $opt[$context->msg('guesstimezone')->text()] = 'guess';
     foreach ($timeZoneList as $timeZoneInfo) {
         $region = $timeZoneInfo['region'];
         if (!isset($opt[$region])) {
             $opt[$region] = array();
         }
         $opt[$region][$timeZoneInfo['name']] = $timeZoneInfo['timecorrection'];
     }
     return $opt;
 }
Ejemplo n.º 10
0
 /**
  * Helper function fo UserMailer::send() which does the actual sending. It expects a $to
  * list which the UserMailerSplitTo hook would not split further.
  * @param MailAddress[] $to Array of recipients' email addresses
  * @param MailAddress $from Sender's email
  * @param string $subject Email's subject.
  * @param string $body Email's text or Array of two strings to be the text and html bodies
  * @param array $options:
  * 		'replyTo' MailAddress
  * 		'contentType' string default 'text/plain; charset=UTF-8'
  * 		'headers' array Extra headers to set
  *
  * @throws MWException
  * @throws Exception
  * @return Status
  */
 protected static function sendInternal(array $to, MailAddress $from, $subject, $body, $options = array())
 {
     global $wgSMTP, $wgEnotifMaxRecips, $wgAdditionalMailParams;
     $mime = null;
     $replyto = isset($options['replyTo']) ? $options['replyTo'] : null;
     $contentType = isset($options['contentType']) ? $options['contentType'] : 'text/plain; charset=UTF-8';
     $headers = isset($options['headers']) ? $options['headers'] : array();
     // Allow transformation of content, such as encrypting/signing
     $error = false;
     if (!Hooks::run('UserMailerTransformContent', array($to, $from, &$body, &$error))) {
         if ($error) {
             return Status::newFatal('php-mail-error', $error);
         } else {
             return Status::newFatal('php-mail-error-unknown');
         }
     }
     /**
      * Forge email headers
      * -------------------
      *
      * WARNING
      *
      * DO NOT add To: or Subject: headers at this step. They need to be
      * handled differently depending upon the mailer we are going to use.
      *
      * To:
      *  PHP mail() first argument is the mail receiver. The argument is
      *  used as a recipient destination and as a To header.
      *
      *  PEAR mailer has a recipient argument which is only used to
      *  send the mail. If no To header is given, PEAR will set it to
      *  to 'undisclosed-recipients:'.
      *
      *  NOTE: To: is for presentation, the actual recipient is specified
      *  by the mailer using the Rcpt-To: header.
      *
      * Subject:
      *  PHP mail() second argument to pass the subject, passing a Subject
      *  as an additional header will result in a duplicate header.
      *
      *  PEAR mailer should be passed a Subject header.
      *
      * -- hashar 20120218
      */
     $headers['From'] = $from->toString();
     $returnPath = $from->address;
     $extraParams = $wgAdditionalMailParams;
     // Hook to generate custom VERP address for 'Return-Path'
     Hooks::run('UserMailerChangeReturnPath', array($to, &$returnPath));
     // Add the envelope sender address using the -f command line option when PHP mail() is used.
     // Will default to the $from->address when the UserMailerChangeReturnPath hook fails and the
     // generated VERP address when the hook runs effectively.
     $extraParams .= ' -f ' . $returnPath;
     $headers['Return-Path'] = $returnPath;
     if ($replyto) {
         $headers['Reply-To'] = $replyto->toString();
     }
     $headers['Date'] = MWTimestamp::getLocalInstance()->format('r');
     $headers['Message-ID'] = self::makeMsgId();
     $headers['X-Mailer'] = 'MediaWiki mailer';
     $headers['List-Unsubscribe'] = '<' . SpecialPage::getTitleFor('Preferences')->getFullURL('', false, PROTO_CANONICAL) . '>';
     // Line endings need to be different on Unix and Windows due to
     // the bug described at http://trac.wordpress.org/ticket/2603
     if (wfIsWindows()) {
         $endl = "\r\n";
     } else {
         $endl = "\n";
     }
     if (is_array($body)) {
         // we are sending a multipart message
         wfDebug("Assembling multipart mime email\n");
         if (!stream_resolve_include_path('Mail/mime.php')) {
             wfDebug("PEAR Mail_Mime package is not installed. Falling back to text email.\n");
             // remove the html body for text email fall back
             $body = $body['text'];
         } else {
             // Check if pear/mail_mime is already loaded (via composer)
             if (!class_exists('Mail_mime')) {
                 require_once 'Mail/mime.php';
             }
             if (wfIsWindows()) {
                 $body['text'] = str_replace("\n", "\r\n", $body['text']);
                 $body['html'] = str_replace("\n", "\r\n", $body['html']);
             }
             $mime = new Mail_mime(array('eol' => $endl, 'text_charset' => 'UTF-8', 'html_charset' => 'UTF-8'));
             $mime->setTXTBody($body['text']);
             $mime->setHTMLBody($body['html']);
             $body = $mime->get();
             // must call get() before headers()
             $headers = $mime->headers($headers);
         }
     }
     if ($mime === null) {
         // sending text only, either deliberately or as a fallback
         if (wfIsWindows()) {
             $body = str_replace("\n", "\r\n", $body);
         }
         $headers['MIME-Version'] = '1.0';
         $headers['Content-type'] = is_null($contentType) ? 'text/plain; charset=UTF-8' : $contentType;
         $headers['Content-transfer-encoding'] = '8bit';
     }
     // allow transformation of MIME-encoded message
     if (!Hooks::run('UserMailerTransformMessage', array($to, $from, &$subject, &$headers, &$body, &$error))) {
         if ($error) {
             return Status::newFatal('php-mail-error', $error);
         } else {
             return Status::newFatal('php-mail-error-unknown');
         }
     }
     $ret = Hooks::run('AlternateUserMailer', array($headers, $to, $from, $subject, $body));
     if ($ret === false) {
         // the hook implementation will return false to skip regular mail sending
         return Status::newGood();
     } elseif ($ret !== true) {
         // the hook implementation will return a string to pass an error message
         return Status::newFatal('php-mail-error', $ret);
     }
     if (is_array($wgSMTP)) {
         // Check if pear/mail is already loaded (via composer)
         if (!class_exists('Mail')) {
             // PEAR MAILER
             if (!stream_resolve_include_path('Mail.php')) {
                 throw new MWException('PEAR mail package is not installed');
             }
             require_once 'Mail.php';
         }
         MediaWiki\suppressWarnings();
         // Create the mail object using the Mail::factory method
         $mail_object =& Mail::factory('smtp', $wgSMTP);
         if (PEAR::isError($mail_object)) {
             wfDebug("PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n");
             MediaWiki\restoreWarnings();
             return Status::newFatal('pear-mail-error', $mail_object->getMessage());
         }
         wfDebug("Sending mail via PEAR::Mail\n");
         $headers['Subject'] = self::quotedPrintable($subject);
         // When sending only to one recipient, shows it its email using To:
         if (count($to) == 1) {
             $headers['To'] = $to[0]->toString();
         }
         // Split jobs since SMTP servers tends to limit the maximum
         // number of possible recipients.
         $chunks = array_chunk($to, $wgEnotifMaxRecips);
         foreach ($chunks as $chunk) {
             $status = self::sendWithPear($mail_object, $chunk, $headers, $body);
             // FIXME : some chunks might be sent while others are not!
             if (!$status->isOK()) {
                 MediaWiki\restoreWarnings();
                 return $status;
             }
         }
         MediaWiki\restoreWarnings();
         return Status::newGood();
     } else {
         // PHP mail()
         if (count($to) > 1) {
             $headers['To'] = 'undisclosed-recipients:;';
         }
         $headers = self::arrayToHeaderString($headers, $endl);
         wfDebug("Sending mail via internal mail() function\n");
         self::$mErrorString = '';
         $html_errors = ini_get('html_errors');
         ini_set('html_errors', '0');
         set_error_handler('UserMailer::errorHandler');
         try {
             $safeMode = wfIniGetBool('safe_mode');
             foreach ($to as $recip) {
                 if ($safeMode) {
                     $sent = mail($recip, self::quotedPrintable($subject), $body, $headers);
                 } else {
                     $sent = mail($recip, self::quotedPrintable($subject), $body, $headers, $extraParams);
                 }
             }
         } catch (Exception $e) {
             restore_error_handler();
             throw $e;
         }
         restore_error_handler();
         ini_set('html_errors', $html_errors);
         if (self::$mErrorString) {
             wfDebug("Error sending mail: " . self::$mErrorString . "\n");
             return Status::newFatal('php-mail-error', self::$mErrorString);
         } elseif (!$sent) {
             // mail function only tells if there's an error
             wfDebug("Unknown error sending mail\n");
             return Status::newFatal('php-mail-error-unknown');
         } else {
             return Status::newGood();
         }
     }
 }
 public function getSignature($user, $timestamp)
 {
     global $wgContLang, $wgParser;
     // Force unstub
     StubObject::unstub($wgParser);
     $timestamp = MWTimestamp::getLocalInstance($timestamp);
     $ts = $timestamp->format('YmdHis');
     $tzMsg = $timestamp->format('T');
     # might vary on DST changeover!
     # Allow translation of timezones through wiki. format() can return
     # whatever crap the system uses, localised or not, so we cannot
     # ship premade translations.
     $key = 'timezone-' . strtolower(trim($tzMsg));
     $msg = wfMessage($key)->inContentLanguage();
     if ($msg->exists()) {
         $tzMsg = $msg->text();
     }
     $d = $wgContLang->timeanddate($ts, false, false) . " ({$tzMsg})";
     if ($user) {
         return $wgParser->getUserSig($user, false, false) . ' ' . $d;
     } else {
         return "[Unknown user] {$d}";
     }
 }