/**
  * Get the footer with user information (when joined, how
  * many edits/uploads, visit user page and talk page)
  * @return string
  */
 protected function getUserFooterData()
 {
     $fromDate = $this->targetUser->getRegistration();
     $ts = new MWTimestamp(wfTimestamp(TS_UNIX, $fromDate));
     $diff = $ts->diff(new MWTimestamp());
     if ($fromDate === null) {
         // User was registered in pre-historic times when registration wasn't recorded
         $msg = 'mobile-frontend-profile-footer-ancient';
         $units = 0;
         $fromDate = '20010115000000';
         // No users before that date
     } elseif ($diff->y) {
         $msg = 'mobile-frontend-profile-footer-years';
         $units = $diff->y;
     } elseif ($diff->m) {
         $msg = 'mobile-frontend-profile-footer-months';
         $units = $diff->m;
     } else {
         $msg = 'mobile-frontend-profile-footer-days';
         $units = $diff->d;
     }
     $editCount = $this->targetUser->getEditCount();
     $uploadCount = $this->userInfo->countRecentUploads($fromDate);
     // Ensure that the upload count is compatible with the i18n message
     if ($uploadCount > 500) {
         $uploadCount = 500;
     }
     $username = $this->targetUser->getName();
     return array('editsSummary' => $this->msg($msg, $username)->numParams($units, $editCount, $uploadCount)->parse(), 'linkUserPage' => Linker::link($this->targetUser->getUserPage(), $this->msg('mobile-frontend-profile-userpage-link', $username)->escaped()), 'linkTalk' => $this->getTalkLink());
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider provideRelativeTimestampTests
  * @covers MWTimestamp::getRelativeTimestamp
  */
 public function testRelativeTimestamp($tsTime, $currentTime, $timeCorrection, $dateFormat, $expectedOutput, $desc)
 {
     $user = $this->getMock('User');
     $user->expects($this->any())->method('getOption')->with('timecorrection')->will($this->returnValue($timeCorrection));
     $tsTime = new MWTimestamp($tsTime);
     $currentTime = new MWTimestamp($currentTime);
     $this->assertEquals($expectedOutput, $tsTime->getRelativeTimestamp($currentTime, $user), $desc);
 }
 function __construct()
 {
     global $wgModerationTimeToOverrideRejection;
     $mw_ts = new MWTimestamp(time());
     $mw_ts->timestamp->modify('-' . intval($wgModerationTimeToOverrideRejection) . ' seconds');
     $this->earliestReapprovableTimestamp = $mw_ts->getTimestamp(TS_MW);
     $this->mblockCheck = new ModerationBlockCheck();
     parent::__construct('Moderation', 'moderation');
 }
 /**
  * Gets the HTML fragment for a watched page.
  *
  * @param Title $title The title of the watched page
  * @param int $ts When the page was last touched
  * @param string $thumb An HTML fragment for the page's thumbnaiL
  * @return string
  */
 public static function getLineHtml(Title $title, $ts, $thumb)
 {
     $titleText = $title->getPrefixedText();
     if ($ts) {
         $ts = new MWTimestamp($ts);
         $lastModified = wfMessage('mobile-frontend-watchlist-modified', $ts->getHumanTimestamp())->text();
         $className = 'title';
     } else {
         $className = 'title new';
         $lastModified = '';
     }
     $html = Html::openElement('li', array('class' => 'page-summary', 'title' => $titleText, 'data-id' => $title->getArticleId())) . Html::openElement('a', array('href' => $title->getLocalUrl(), 'class' => $className));
     $html .= $thumb;
     $html .= Html::element('h3', array(), $titleText) . Html::element('div', array('class' => 'info'), $lastModified) . Html::closeElement('a') . Html::closeElement('li');
     return $html;
 }
 /** @inheritdoc **/
 protected function getHeaderHtml()
 {
     if ($this->isUserPage) {
         // The heading is just the username without namespace
         $html = Html::rawElement('h1', array('id' => 'section_0'), $this->pageUser->getName());
         $fromDate = $this->pageUser->getRegistration();
         if (is_string($fromDate)) {
             $fromDateTs = new MWTimestamp(wfTimestamp(TS_UNIX, $fromDate));
             $html .= Html::element('div', array('class' => 'tagline'), $this->msg('mobile-frontend-user-page-member-since', $fromDateTs->format('F, Y')));
         }
     } else {
         $html = parent::getHeaderHtml();
         $vars = $this->getSkinConfigVariables();
         $description = $vars['wgMFDescription'];
         if ($description && !$this->getTitle()->isSpecialPage()) {
             $html .= Html::element('div', array('class' => 'tagline'), $description);
         }
     }
     return $html;
 }
Ejemplo n.º 6
0
 public function execute()
 {
     $params = $this->extractRequestParams();
     $token = $params['token'];
     $maxage = $params['maxtokenage'];
     $salts = ApiQueryTokens::getTokenTypeSalts();
     $res = array();
     $tokenObj = ApiQueryTokens::getToken($this->getUser(), $this->getRequest()->getSession(), $salts[$params['type']]);
     if ($tokenObj->match($token, $maxage)) {
         $res['result'] = 'valid';
     } elseif ($maxage !== null && $tokenObj->match($token)) {
         $res['result'] = 'expired';
     } else {
         $res['result'] = 'invalid';
     }
     $ts = MediaWiki\Session\Token::getTimestamp($token);
     if ($ts !== null) {
         $mwts = new MWTimestamp();
         $mwts->timestamp->setTimestamp($ts);
         $res['generated'] = $mwts->getTimestamp(TS_ISO_8601);
     }
     $this->getResult()->addValue(null, $this->getModuleName(), $res);
 }
Ejemplo n.º 7
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()]];
 }
 function getDateCond($year, $month)
 {
     $year = intval($year);
     $month = intval($month);
     // Basic validity checks
     $this->mYear = $year > 0 ? $year : false;
     $this->mMonth = $month > 0 && $month < 13 ? $month : false;
     // Given an optional year and month, we need to generate a timestamp
     // to use as "WHERE rev_timestamp <= result"
     // Examples: year = 2006 equals < 20070101 (+000000)
     // year=2005, month=1    equals < 20050201
     // year=2005, month=12   equals < 20060101
     if (!$this->mYear && !$this->mMonth) {
         return;
     }
     if ($this->mYear) {
         $year = $this->mYear;
     } else {
         // If no year given, assume the current one
         $timestamp = MWTimestamp::getInstance();
         $year = $timestamp->format('Y');
         // If this month hasn't happened yet this year, go back to last year's month
         if ($this->mMonth > $timestamp->format('n')) {
             $year--;
         }
     }
     if ($this->mMonth) {
         $month = $this->mMonth + 1;
         // For December, we want January 1 of the next year
         if ($month > 12) {
             $month = 1;
             $year++;
         }
     } else {
         // No month implies we want up to the end of the year in question
         $month = 1;
         $year++;
     }
     // Y2K38 bug
     if ($year > 2032) {
         $year = 2032;
     }
     $ymd = (int) sprintf("%04d%02d01", $year, $month);
     if ($ymd > 20320101) {
         $ymd = 20320101;
     }
     $this->mOffset = $this->mDb->timestamp("{$ymd}000000");
 }
 /**
  * @covers ReverseChronologicalPager::getDateCond
  */
 public function testGetDateCond()
 {
     $pager = $this->getMockForAbstractClass('ReverseChronologicalPager');
     $timestamp = MWTimestamp::getInstance();
     $db = wfGetDB(DB_MASTER);
     $currYear = $timestamp->format('Y');
     $currMonth = $timestamp->format('n');
     // Test that getDateCond sets and returns mOffset
     $this->assertEquals($pager->getDateCond(2006, 6), $pager->mOffset);
     // Test year and month
     $pager->getDateCond(2006, 6);
     $this->assertEquals($pager->mOffset, $db->timestamp('20060701000000'));
     // Test year, month, and day
     $pager->getDateCond(2006, 6, 5);
     $this->assertEquals($pager->mOffset, $db->timestamp('20060606000000'));
     // Test month overflow into the next year
     $pager->getDateCond(2006, 12);
     $this->assertEquals($pager->mOffset, $db->timestamp('20070101000000'));
     // Test day overflow to the next month
     $pager->getDateCond(2006, 6, 30);
     $this->assertEquals($pager->mOffset, $db->timestamp('20060701000000'));
     // Test invalid month (should use end of year)
     $pager->getDateCond(2006, -1);
     $this->assertEquals($pager->mOffset, $db->timestamp('20070101000000'));
     // Test invalid day (should use end of month)
     $pager->getDateCond(2006, 6, 1337);
     $this->assertEquals($pager->mOffset, $db->timestamp('20060701000000'));
     // Test last day of year
     $pager->getDateCond(2006, 12, 31);
     $this->assertEquals($pager->mOffset, $db->timestamp('20070101000000'));
     // Test invalid day that overflows to next year
     $pager->getDateCond(2006, 12, 32);
     $this->assertEquals($pager->mOffset, $db->timestamp('20070101000000'));
     // Test month past current month (should use previous year)
     if ($currMonth < 5) {
         $pager->getDateCond(-1, 5);
         $this->assertEquals($pager->mOffset, $db->timestamp($currYear - 1 . '0601000000'));
     }
     if ($currMonth < 12) {
         $pager->getDateCond(-1, 12);
         $this->assertEquals($pager->mOffset, $db->timestamp($currYear . '0101000000'));
     }
 }
 /**
  * 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.º 11
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.º 12
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.º 13
0
/**
 * Get a timestamp string in one of various formats
 *
 * @param mixed $outputtype A timestamp in one of the supported formats, the
 *   function will autodetect which format is supplied and act accordingly.
 * @param mixed $ts Optional timestamp to convert, default 0 for the current time
 * @return string|bool String / false The same date in the format specified in $outputtype or false
 */
function wfTimestamp($outputtype = TS_UNIX, $ts = 0)
{
    try {
        $timestamp = new MWTimestamp($ts);
        return $timestamp->getTimestamp($outputtype);
    } catch (TimestampException $e) {
        wfDebug("wfTimestamp() fed bogus time value: TYPE={$outputtype}; VALUE={$ts}\n");
        return false;
    }
}
Ejemplo n.º 14
0
 /**
  * @param $year Integer
  * @param $month Integer
  * @return string Formatted HTML
  */
 public static function dateMenu($year, $month)
 {
     # Offset overrides year/month selection
     if ($month && $month !== -1) {
         $encMonth = intval($month);
     } else {
         $encMonth = '';
     }
     if ($year) {
         $encYear = intval($year);
     } elseif ($encMonth) {
         $timestamp = MWTimestamp::getInstance();
         $thisMonth = intval($timestamp->format('n'));
         $thisYear = intval($timestamp->format('Y'));
         if (intval($encMonth) > $thisMonth) {
             $thisYear--;
         }
         $encYear = $thisYear;
     } else {
         $encYear = '';
     }
     // JRS, upgrade 1.21: Add button classes to date menu
     $inputAttribs = array('id' => 'year', 'maxlength' => 4, 'size' => 7, 'class' => 'input_med');
     return self::label(wfMessage('input-year')->text(), 'year', array('class' => 'input_med noborder')) . ' ' . Html::input('year', $encYear, 'number', $inputAttribs) . '&#160;' . self::label(wfMessage('input-month')->text(), 'month', array('class' => 'input_med noborder')) . ' ' . self::monthSelector($encMonth, -1);
 }
Ejemplo n.º 15
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.º 16
0
 function showImage()
 {
     global $wgOut;
     $wgOut->disable();
     $info = $this->retrieveCaptcha();
     if ($info) {
         $timestamp = new MWTimestamp();
         $info['viewed'] = $timestamp->getTimestamp();
         $this->storeCaptcha($info);
         $salt = $info['salt'];
         $hash = $info['hash'];
         return $this->getBackend()->streamFile(array('src' => $this->imagePath($salt, $hash), 'headers' => array("Cache-Control: private, s-maxage=0, max-age=3600")))->isOK();
     }
     wfHttpError(500, 'Internal Error', 'Requested bogus captcha image');
     return false;
 }
Ejemplo n.º 17
0
 /**
  * @param int $year
  * @param int $month
  * @return string Formatted HTML
  */
 public static function dateMenu($year, $month)
 {
     # Offset overrides year/month selection
     if ($month && $month !== -1) {
         $encMonth = intval($month);
     } else {
         $encMonth = '';
     }
     if ($year) {
         $encYear = intval($year);
     } elseif ($encMonth) {
         $timestamp = MWTimestamp::getInstance();
         $thisMonth = intval($timestamp->format('n'));
         $thisYear = intval($timestamp->format('Y'));
         if (intval($encMonth) > $thisMonth) {
             $thisYear--;
         }
         $encYear = $thisYear;
     } else {
         $encYear = '';
     }
     $inputAttribs = array('id' => 'year', 'maxlength' => 4, 'size' => 7);
     return self::label(wfMessage('year')->text(), 'year') . ' ' . Html::input('year', $encYear, 'number', $inputAttribs) . ' ' . self::label(wfMessage('month')->text(), 'month') . ' ' . self::monthSelector($encMonth, -1);
 }
Ejemplo n.º 18
0
 /**
  * Convert an MWTimestamp into a pretty human-readable timestamp using
  * the given user preferences and relative base time.
  *
  * @see Language::getHumanTimestamp
  * @param MWTimestamp $ts Timestamp to prettify
  * @param MWTimestamp $relativeTo Base timestamp
  * @param User $user User preferences to use
  * @return string Human timestamp
  * @since 1.26
  */
 private function getHumanTimestampInternal(MWTimestamp $ts, MWTimestamp $relativeTo, User $user)
 {
     $diff = $ts->diff($relativeTo);
     $diffDay = (bool) ((int) $ts->timestamp->format('w') - (int) $relativeTo->timestamp->format('w'));
     $days = $diff->days ?: (int) $diffDay;
     if ($diff->invert || $days > 5 && $ts->timestamp->format('Y') !== $relativeTo->timestamp->format('Y')) {
         // Timestamps are in different years: use full timestamp
         // Also do full timestamp for future dates
         /**
          * @todo FIXME: Add better handling of future timestamps.
          */
         $format = $this->getDateFormatString('both', $user->getDatePreference() ?: 'default');
         $ts = $this->sprintfDate($format, $ts->getTimestamp(TS_MW));
     } elseif ($days > 5) {
         // Timestamps are in same year,  but more than 5 days ago: show day and month only.
         $format = $this->getDateFormatString('pretty', $user->getDatePreference() ?: 'default');
         $ts = $this->sprintfDate($format, $ts->getTimestamp(TS_MW));
     } elseif ($days > 1) {
         // Timestamp within the past week: show the day of the week and time
         $format = $this->getDateFormatString('time', $user->getDatePreference() ?: 'default');
         $weekday = self::$mWeekdayMsgs[$ts->timestamp->format('w')];
         // Messages:
         // sunday-at, monday-at, tuesday-at, wednesday-at, thursday-at, friday-at, saturday-at
         $ts = wfMessage("{$weekday}-at")->inLanguage($this)->params($this->sprintfDate($format, $ts->getTimestamp(TS_MW)))->text();
     } elseif ($days == 1) {
         // Timestamp was yesterday: say 'yesterday' and the time.
         $format = $this->getDateFormatString('time', $user->getDatePreference() ?: 'default');
         $ts = wfMessage('yesterday-at')->inLanguage($this)->params($this->sprintfDate($format, $ts->getTimestamp(TS_MW)))->text();
     } elseif ($diff->h > 1 || $diff->h == 1 && $diff->i > 30) {
         // Timestamp was today, but more than 90 minutes ago: say 'today' and the time.
         $format = $this->getDateFormatString('time', $user->getDatePreference() ?: 'default');
         $ts = wfMessage('today-at')->inLanguage($this)->params($this->sprintfDate($format, $ts->getTimestamp(TS_MW)))->text();
         // From here on in, the timestamp was soon enough ago so that we can simply say
         // XX units ago, e.g., "2 hours ago" or "5 minutes ago"
     } elseif ($diff->h == 1) {
         // Less than 90 minutes, but more than an hour ago.
         $ts = wfMessage('hours-ago')->inLanguage($this)->numParams(1)->text();
     } elseif ($diff->i >= 1) {
         // A few minutes ago.
         $ts = wfMessage('minutes-ago')->inLanguage($this)->numParams($diff->i)->text();
     } elseif ($diff->s >= 30) {
         // Less than a minute, but more than 30 sec ago.
         $ts = wfMessage('seconds-ago')->inLanguage($this)->numParams($diff->s)->text();
     } else {
         // Less than 30 seconds ago.
         $ts = wfMessage('just-now')->text();
     }
     return $ts;
 }
Ejemplo n.º 19
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;
 }
Ejemplo n.º 20
0
 function formatValue($name, $value)
 {
     static $msg = null;
     if ($msg === null) {
         $keys = ['anononlyblock', 'createaccountblock', 'noautoblockblock', 'emailblock', 'blocklist-nousertalk', 'unblocklink', 'change-blocklink'];
         foreach ($keys as $key) {
             $msg[$key] = $this->msg($key)->escaped();
         }
     }
     /** @var $row object */
     $row = $this->mCurrentRow;
     $language = $this->getLanguage();
     $formatted = '';
     switch ($name) {
         case 'ipb_timestamp':
             $formatted = htmlspecialchars($language->userTimeAndDate($value, $this->getUser()));
             break;
         case 'ipb_target':
             if ($row->ipb_auto) {
                 $formatted = $this->msg('autoblockid', $row->ipb_id)->parse();
             } else {
                 list($target, $type) = Block::parseTarget($row->ipb_address);
                 switch ($type) {
                     case Block::TYPE_USER:
                     case Block::TYPE_IP:
                         $formatted = Linker::userLink($target->getId(), $target);
                         $formatted .= Linker::userToolLinks($target->getId(), $target, false, Linker::TOOL_LINKS_NOBLOCK);
                         break;
                     case Block::TYPE_RANGE:
                         $formatted = htmlspecialchars($target);
                 }
             }
             break;
         case 'ipb_expiry':
             $formatted = htmlspecialchars($language->formatExpiry($value, true));
             if ($this->getUser()->isAllowed('block')) {
                 if ($row->ipb_auto) {
                     $links[] = Linker::linkKnown(SpecialPage::getTitleFor('Unblock'), $msg['unblocklink'], [], ['wpTarget' => "#{$row->ipb_id}"]);
                 } else {
                     $links[] = Linker::linkKnown(SpecialPage::getTitleFor('Unblock', $row->ipb_address), $msg['unblocklink']);
                     $links[] = Linker::linkKnown(SpecialPage::getTitleFor('Block', $row->ipb_address), $msg['change-blocklink']);
                 }
                 $formatted .= ' ' . Html::rawElement('span', ['class' => 'mw-blocklist-actions'], $this->msg('parentheses')->rawParams($language->pipeList($links))->escaped());
             }
             if ($value !== 'infinity') {
                 $timestamp = new MWTimestamp($value);
                 $formatted .= '<br />' . $this->msg('ipb-blocklist-duration-left', $language->formatDuration($timestamp->getTimestamp() - time(), ['minutes', 'hours', 'days', 'years']))->escaped();
             }
             break;
         case 'ipb_by':
             if (isset($row->by_user_name)) {
                 $formatted = Linker::userLink($value, $row->by_user_name);
                 $formatted .= Linker::userToolLinks($value, $row->by_user_name);
             } else {
                 $formatted = htmlspecialchars($row->ipb_by_text);
                 // foreign user?
             }
             break;
         case 'ipb_reason':
             $formatted = Linker::formatComment($value);
             break;
         case 'ipb_params':
             $properties = [];
             if ($row->ipb_anon_only) {
                 $properties[] = $msg['anononlyblock'];
             }
             if ($row->ipb_create_account) {
                 $properties[] = $msg['createaccountblock'];
             }
             if ($row->ipb_user && !$row->ipb_enable_autoblock) {
                 $properties[] = $msg['noautoblockblock'];
             }
             if ($row->ipb_block_email) {
                 $properties[] = $msg['emailblock'];
             }
             if (!$row->ipb_allow_usertalk) {
                 $properties[] = $msg['blocklist-nousertalk'];
             }
             $formatted = $language->commaList($properties);
             break;
         default:
             $formatted = "Unable to format {$name}";
             break;
     }
     return $formatted;
 }
Ejemplo n.º 21
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();
         }
     }
 }
Ejemplo n.º 22
0
 /**
  * Pick a random name in the temp zone and store a file to it.
  * Returns a FileRepoStatus object with the file Virtual URL in the value,
  * file can later be disposed using FileRepo::freeTemp().
  *
  * @param string $originalName The base name of the file as specified
  *   by the user. The file extension will be maintained.
  * @param string $srcPath The current location of the file.
  * @return FileRepoStatus Object with the URL in the value.
  */
 public function storeTemp($originalName, $srcPath)
 {
     $this->assertWritableRepo();
     // fail out if read-only
     $date = MWTimestamp::getInstance()->format('YmdHis');
     $hashPath = $this->getHashPath($originalName);
     $dstUrlRel = $hashPath . $date . '!' . rawurlencode($originalName);
     $virtualUrl = $this->getVirtualUrl('temp') . '/' . $dstUrlRel;
     $result = $this->quickImport($srcPath, $virtualUrl);
     $result->value = $virtualUrl;
     return $result;
 }
Ejemplo n.º 23
0
 /**
  * Convert dates like "Tue, 03 Jan 2012 22:01:04 GMT"/"2013-05-11T07:37:27.678360Z".
  * Dates might also come in like "2013-05-11T07:37:27.678360" from Swift listings,
  * missing the timezone suffix (though Ceph RGW does not appear to have this bug).
  *
  * @param string $ts
  * @param int $format Output format (TS_* constant)
  * @return string
  * @throws FileBackendError
  */
 protected function convertSwiftDate($ts, $format = TS_MW)
 {
     try {
         $timestamp = new MWTimestamp($ts);
         return $timestamp->getTimestamp($format);
     } catch (Exception $e) {
         throw new FileBackendError($e->getMessage());
     }
 }
Ejemplo n.º 24
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.º 25
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') : '';
 }
 public function execute()
 {
     $user = $this->getUser();
     if (!$user->isAllowed('abusefilter-view')) {
         $this->dieUsage('You don\'t have permission to view abuse filters', 'permissiondenied');
     }
     $params = $this->extractRequestParams();
     $prop = array_flip($params['prop']);
     $fld_id = isset($prop['id']);
     $fld_desc = isset($prop['description']);
     $fld_pattern = isset($prop['pattern']);
     $fld_actions = isset($prop['actions']);
     $fld_hits = isset($prop['hits']);
     $fld_comments = isset($prop['comments']);
     $fld_user = isset($prop['lasteditor']);
     $fld_time = isset($prop['lastedittime']);
     $fld_status = isset($prop['status']);
     $fld_private = isset($prop['private']);
     $result = $this->getResult();
     $this->addTables('abuse_filter');
     $this->addFields('af_id');
     $this->addFields('af_hidden');
     $this->addFieldsIf('af_hit_count', $fld_hits);
     $this->addFieldsIf('af_enabled', $fld_status);
     $this->addFieldsIf('af_deleted', $fld_status);
     $this->addFieldsIf('af_public_comments', $fld_desc);
     $this->addFieldsIf('af_pattern', $fld_pattern);
     $this->addFieldsIf('af_actions', $fld_actions);
     $this->addFieldsIf('af_comments', $fld_comments);
     $this->addFieldsIf('af_user_text', $fld_user);
     $this->addFieldsIf('af_timestamp', $fld_time);
     $this->addOption('LIMIT', $params['limit'] + 1);
     $this->addWhereRange('af_id', $params['dir'], $params['startid'], $params['endid']);
     if (!is_null($params['show'])) {
         $show = array_flip($params['show']);
         /* Check for conflicting parameters. */
         if (isset($show['enabled']) && isset($show['!enabled']) || isset($show['deleted']) && isset($show['!deleted']) || isset($show['private']) && isset($show['!private'])) {
             $this->dieUsage('Incorrect parameter - mutually exclusive values may not be supplied', 'show');
         }
         $this->addWhereIf('af_enabled = 0', isset($show['!enabled']));
         $this->addWhereIf('af_enabled != 0', isset($show['enabled']));
         $this->addWhereIf('af_deleted = 0', isset($show['!deleted']));
         $this->addWhereIf('af_deleted != 0', isset($show['deleted']));
         $this->addWhereIf('af_hidden = 0', isset($show['!private']));
         $this->addWhereIf('af_hidden != 0', isset($show['private']));
     }
     $res = $this->select(__METHOD__);
     $showhidden = $user->isAllowed('abusefilter-modify');
     $count = 0;
     foreach ($res as $row) {
         if (++$count > $params['limit']) {
             // We've had enough
             $this->setContinueEnumParameter('startid', $row->af_id);
             break;
         }
         $entry = array();
         if ($fld_id) {
             $entry['id'] = intval($row->af_id);
         }
         if ($fld_desc) {
             $entry['description'] = $row->af_public_comments;
         }
         if ($fld_pattern && (!$row->af_hidden || $showhidden)) {
             $entry['pattern'] = $row->af_pattern;
         }
         if ($fld_actions) {
             $entry['actions'] = $row->af_actions;
         }
         if ($fld_hits) {
             $entry['hits'] = intval($row->af_hit_count);
         }
         if ($fld_comments && (!$row->af_hidden || $showhidden)) {
             $entry['comments'] = $row->af_comments;
         }
         if ($fld_user) {
             $entry['lasteditor'] = $row->af_user_text;
         }
         if ($fld_time) {
             $ts = new MWTimestamp($row->af_timestamp);
             $entry['lastedittime'] = $ts->getTimestamp(TS_ISO_8601);
         }
         if ($fld_private && $row->af_hidden) {
             $entry['private'] = '';
         }
         if ($fld_status) {
             if ($row->af_enabled) {
                 $entry['enabled'] = '';
             }
             if ($row->af_deleted) {
                 $entry['deleted'] = '';
             }
         }
         if ($entry) {
             $fit = $result->addValue(array('query', $this->getModuleName()), null, $entry);
             if (!$fit) {
                 $this->setContinueEnumParameter('startid', $row->af_id);
                 break;
             }
         }
     }
     $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'filter');
 }
Ejemplo n.º 27
0
 /**
  * Check selected RFC 7232 precondition headers
  *
  * RFC 7232 envisions a particular model where you send your request to "a
  * resource", and for write requests that you can read "the resource" by
  * changing the method to GET. When the API receives a GET request, it
  * works out even though "the resource" from RFC 7232's perspective might
  * be many resources from MediaWiki's perspective. But it totally fails for
  * a POST, since what HTTP sees as "the resource" is probably just
  * "/api.php" with all the interesting bits in the body.
  *
  * Therefore, we only support RFC 7232 precondition headers for GET (and
  * HEAD). That means we don't need to bother with If-Match and
  * If-Unmodified-Since since they only apply to modification requests.
  *
  * And since we don't support Range, If-Range is ignored too.
  *
  * @since 1.26
  * @param ApiBase $module Api module being used
  * @return bool True on success, false should exit immediately
  */
 protected function checkConditionalRequestHeaders($module)
 {
     if ($this->mInternalMode) {
         // No headers to check in internal mode
         return true;
     }
     if ($this->getRequest()->getMethod() !== 'GET' && $this->getRequest()->getMethod() !== 'HEAD') {
         // Don't check POSTs
         return true;
     }
     $return304 = false;
     $ifNoneMatch = array_diff($this->getRequest()->getHeader('If-None-Match', WebRequest::GETHEADER_LIST) ?: array(), array(''));
     if ($ifNoneMatch) {
         if ($ifNoneMatch === array('*')) {
             // API responses always "exist"
             $etag = '*';
         } else {
             $etag = $module->getConditionalRequestData('etag');
         }
     }
     if ($ifNoneMatch && $etag !== null) {
         $test = substr($etag, 0, 2) === 'W/' ? substr($etag, 2) : $etag;
         $match = array_map(function ($s) {
             return substr($s, 0, 2) === 'W/' ? substr($s, 2) : $s;
         }, $ifNoneMatch);
         $return304 = in_array($test, $match, true);
     } else {
         $value = trim($this->getRequest()->getHeader('If-Modified-Since'));
         // Some old browsers sends sizes after the date, like this:
         //  Wed, 20 Aug 2003 06:51:19 GMT; length=5202
         // Ignore that.
         $i = strpos($value, ';');
         if ($i !== false) {
             $value = trim(substr($value, 0, $i));
         }
         if ($value !== '') {
             try {
                 $ts = new MWTimestamp($value);
                 if ($ts->getTimestamp(TS_RFC2822) === $value || $ts->format('l, d-M-y H:i:s') . ' GMT' === $value || $ts->format('D M j H:i:s Y') === $value || $ts->format('D M  j H:i:s Y') === $value) {
                     $lastMod = $module->getConditionalRequestData('last-modified');
                     if ($lastMod !== null) {
                         // Mix in some MediaWiki modification times
                         $modifiedTimes = array('page' => $lastMod, 'user' => $this->getUser()->getTouched(), 'epoch' => $this->getConfig()->get('CacheEpoch'));
                         if ($this->getConfig()->get('UseSquid')) {
                             // T46570: the core page itself may not change, but resources might
                             $modifiedTimes['sepoch'] = wfTimestamp(TS_MW, time() - $this->getConfig()->get('SquidMaxage'));
                         }
                         Hooks::run('OutputPageCheckLastModified', array(&$modifiedTimes));
                         $lastMod = max($modifiedTimes);
                         $return304 = wfTimestamp(TS_MW, $lastMod) <= $ts->getTimestamp(TS_MW);
                     }
                 }
             } catch (TimestampException $e) {
                 // Invalid timestamp, ignore it
             }
         }
     }
     if ($return304) {
         $this->getRequest()->response()->statusHeader(304);
         // Avoid outputting the compressed representation of a zero-length body
         MediaWiki\suppressWarnings();
         ini_set('zlib.output_compression', 0);
         MediaWiki\restoreWarnings();
         wfClearOutputBuffers();
         return false;
     }
     return true;
 }
Ejemplo n.º 28
0
 public function execute()
 {
     $user = $this->getUser();
     $errors = $this->getTitle()->getUserPermissionsErrors('abusefilter-log', $user);
     if (count($errors)) {
         $this->dieUsageMsg($errors[0]);
         return;
     }
     $params = $this->extractRequestParams();
     $prop = array_flip($params['prop']);
     $fld_ids = isset($prop['ids']);
     $fld_filter = isset($prop['filter']);
     $fld_user = isset($prop['user']);
     $fld_ip = isset($prop['ip']);
     $fld_title = isset($prop['title']);
     $fld_action = isset($prop['action']);
     $fld_details = isset($prop['details']);
     $fld_result = isset($prop['result']);
     $fld_timestamp = isset($prop['timestamp']);
     $fld_hidden = isset($prop['hidden']);
     $fld_revid = isset($prop['revid']);
     if ($fld_ip && !$user->isAllowed('abusefilter-private')) {
         $this->dieUsage('You don\'t have permission to view IP addresses', 'permissiondenied');
     }
     if ($fld_details && !$user->isAllowed('abusefilter-log-detail')) {
         $this->dieUsage('You don\'t have permission to view detailed abuse log entries', 'permissiondenied');
     }
     // Match permissions for viewing events on private filters to SpecialAbuseLog (bug 42814)
     if ($params['filter'] && !(AbuseFilterView::canViewPrivate() || $user->isAllowed('abusefilter-log-private'))) {
         // A specific filter parameter is set but the user isn't allowed to view all filters
         if (!is_array($params['filter'])) {
             $params['filter'] = array($params['filter']);
         }
         foreach ($params['filter'] as $filter) {
             if (AbuseFilter::filterHidden($filter)) {
                 $this->dieUsage('You don\'t have permission to view log entries for private filters', 'permissiondenied');
             }
         }
     }
     $result = $this->getResult();
     $this->addTables('abuse_filter_log');
     $this->addFields('afl_timestamp');
     $this->addFields('afl_rev_id');
     $this->addFields('afl_deleted');
     $this->addFields('afl_filter');
     $this->addFieldsIf('afl_id', $fld_ids);
     $this->addFieldsIf('afl_user_text', $fld_user);
     $this->addFieldsIf('afl_ip', $fld_ip);
     $this->addFieldsIf(array('afl_namespace', 'afl_title'), $fld_title);
     $this->addFieldsIf('afl_action', $fld_action);
     $this->addFieldsIf('afl_var_dump', $fld_details);
     $this->addFieldsIf('afl_actions', $fld_result);
     if ($fld_filter) {
         $this->addTables('abuse_filter');
         $this->addFields('af_public_comments');
         $this->addJoinConds(array('abuse_filter' => array('LEFT JOIN', 'af_id=afl_filter')));
     }
     $this->addOption('LIMIT', $params['limit'] + 1);
     $this->addWhereRange('afl_timestamp', $params['dir'], $params['start'], $params['end']);
     $db = $this->getDB();
     $notDeletedCond = SpecialAbuseLog::getNotDeletedCond($db);
     if (isset($params['user'])) {
         $u = User::newFromName($params['user']);
         if ($u) {
             // Username normalisation
             $params['user'] = $u->getName();
             $userId = $u->getId();
         } elseif (IP::isIPAddress($params['user'])) {
             // It's an IP, sanitize it
             $params['user'] = IP::sanitizeIP($params['user']);
             $userId = 0;
         }
         if (isset($userId)) {
             // Only add the WHERE for user in case it's either a valid user (but not necessary an existing one) or an IP
             $this->addWhere(array('afl_user' => $userId, 'afl_user_text' => $params['user']));
         }
     }
     $this->addWhereIf(array('afl_filter' => $params['filter']), isset($params['filter']));
     $this->addWhereIf($notDeletedCond, !SpecialAbuseLog::canSeeHidden($user));
     $title = $params['title'];
     if (!is_null($title)) {
         $titleObj = Title::newFromText($title);
         if (is_null($titleObj)) {
             $this->dieUsageMsg(array('invalidtitle', $title));
         }
         $this->addWhereFld('afl_namespace', $titleObj->getNamespace());
         $this->addWhereFld('afl_title', $titleObj->getDBkey());
     }
     $res = $this->select(__METHOD__);
     $count = 0;
     foreach ($res as $row) {
         if (++$count > $params['limit']) {
             // We've had enough
             $ts = new MWTimestamp($row->afl_timestamp);
             $this->setContinueEnumParameter('start', $ts->getTimestamp(TS_ISO_8601));
             break;
         }
         if (SpecialAbuseLog::isHidden($row) && !SpecialAbuseLog::canSeeHidden($user)) {
             continue;
         }
         $canSeeDetails = SpecialAbuseLog::canSeeDetails($row->afl_filter);
         $entry = array();
         if ($fld_ids) {
             $entry['id'] = intval($row->afl_id);
             $entry['filter_id'] = '';
             if ($canSeeDetails) {
                 $entry['filter_id'] = $row->afl_filter;
             }
         }
         if ($fld_filter) {
             $entry['filter'] = $row->af_public_comments;
         }
         if ($fld_user) {
             $entry['user'] = $row->afl_user_text;
         }
         if ($fld_ip) {
             $entry['ip'] = $row->afl_ip;
         }
         if ($fld_title) {
             $title = Title::makeTitle($row->afl_namespace, $row->afl_title);
             ApiQueryBase::addTitleInfo($entry, $title);
         }
         if ($fld_action) {
             $entry['action'] = $row->afl_action;
         }
         if ($fld_result) {
             $entry['result'] = $row->afl_actions;
         }
         if ($fld_revid && !is_null($row->afl_rev_id)) {
             $entry['revid'] = '';
             if ($canSeeDetails) {
                 $entry['revid'] = $row->afl_rev_id;
             }
         }
         if ($fld_timestamp) {
             $ts = new MWTimestamp($row->afl_timestamp);
             $entry['timestamp'] = $ts->getTimestamp(TS_ISO_8601);
         }
         if ($fld_details) {
             $entry['details'] = array();
             if ($canSeeDetails) {
                 $vars = AbuseFilter::loadVarDump($row->afl_var_dump);
                 if ($vars instanceof AbuseFilterVariableHolder) {
                     $entry['details'] = $vars->exportAllVars();
                 } else {
                     $entry['details'] = array_change_key_case($vars, CASE_LOWER);
                 }
             }
         }
         if ($fld_hidden) {
             $val = SpecialAbuseLog::isHidden($row);
             if ($val) {
                 $entry['hidden'] = $val;
             }
         }
         if ($entry) {
             $fit = $result->addValue(array('query', $this->getModuleName()), null, $entry);
             if (!$fit) {
                 $ts = new MWTimestamp($row->afl_timestamp);
                 $this->setContinueEnumParameter('start', $ts->getTimestamp(TS_ISO_8601));
                 break;
             }
         }
     }
     $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'item');
 }
Ejemplo n.º 29
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.º 30
0
 /**
  * Reset the notification timestamp of this entry
  *
  * @param $force Whether to force the write query to be executed even if the
  *        page is not watched or the notification timestamp is already NULL.
  * @param int $oldid The revision id being viewed. If not given or 0, latest revision is assumed.
  */
 public function resetNotificationTimestamp($force = '', $oldid = 0)
 {
     // Only loggedin user can have a watchlist
     if (wfReadOnly() || $this->mUser->isAnon() || !$this->isAllowed('editmywatchlist')) {
         return;
     }
     if ($force != 'force') {
         $this->load();
         if (!$this->watched || $this->timestamp === null) {
             return;
         }
     }
     $title = $this->getTitle();
     if (!$oldid) {
         // No oldid given, assuming latest revision; clear the timestamp.
         $notificationTimestamp = null;
     } elseif (!$title->getNextRevisionID($oldid)) {
         // Oldid given and is the latest revision for this title; clear the timestamp.
         $notificationTimestamp = null;
     } else {
         // See if the version marked as read is more recent than the one we're viewing.
         // Call load() if it wasn't called before due to $force.
         $this->load();
         if ($this->timestamp === null) {
             // This can only happen if $force is enabled.
             $notificationTimestamp = null;
         } else {
             // Oldid given and isn't the latest; update the timestamp.
             // This will result in no further notification emails being sent!
             $dbr = wfGetDB(DB_SLAVE);
             $notificationTimestamp = $dbr->selectField('revision', 'rev_timestamp', array('rev_page' => $title->getArticleID(), 'rev_id' => $oldid));
             // We need to go one second to the future because of various strict comparisons
             // throughout the codebase
             $ts = new MWTimestamp($notificationTimestamp);
             $ts->timestamp->add(new DateInterval('PT1S'));
             $notificationTimestamp = $ts->getTimestamp(TS_MW);
             if ($notificationTimestamp < $this->timestamp) {
                 if ($force != 'force') {
                     return;
                 } else {
                     // This is a little silly…
                     $notificationTimestamp = $this->timestamp;
                 }
             }
         }
     }
     // If the page is watched by the user (or may be watched), update the timestamp on any
     // any matching rows
     $dbw = wfGetDB(DB_MASTER);
     $dbw->update('watchlist', array('wl_notificationtimestamp' => $notificationTimestamp), $this->dbCond(), __METHOD__);
     $this->timestamp = null;
 }