本文整理汇总了PHP中MWTimestamp类的典型用法代码示例。如果您正苦于以下问题:PHP MWTimestamp类的具体用法?PHP MWTimestamp怎么用?PHP MWTimestamp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MWTimestamp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUserFooterData
/**
* 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());
}
示例2: testRelativeTimestamp
/**
* @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);
}
示例3: __construct
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');
}
示例4: getLineHtml
/**
* 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;
}
开发者ID:GoProjectOwner,项目名称:mediawiki-extensions-MobileFrontend,代码行数:24,代码来源:SpecialMobileEditWatchlist.php
示例5: getHeaderHtml
/** @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;
}
示例6: execute
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);
}
示例7: getFormFields
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()]];
}
示例8: getDateCond
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");
}
示例9: testGetDateCond
/**
* @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'));
}
}
示例10: onView
/**
* 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) . ' ' . ($tagSelector ? implode(' ', $tagSelector) . ' ' : '') . $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__);
}
示例11: doQuery
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;
}
}
示例12: getCopyrightAndAuthorList
/**
* 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();
}
示例13: wfTimestamp
/**
* 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;
}
}
示例14: dateMenu
/**
* @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) . ' ' . self::label(wfMessage('input-month')->text(), 'month', array('class' => 'input_med noborder')) . ' ' . self::monthSelector($encMonth, -1);
}
示例15: send
/**
* 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')) {
//.........这里部分代码省略.........