本文整理汇总了PHP中MWTimestamp::getHumanTimestamp方法的典型用法代码示例。如果您正苦于以下问题:PHP MWTimestamp::getHumanTimestamp方法的具体用法?PHP MWTimestamp::getHumanTimestamp怎么用?PHP MWTimestamp::getHumanTimestamp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MWTimestamp
的用法示例。
在下文中一共展示了MWTimestamp::getHumanTimestamp方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHumanTimestamp
/**
* @test
* @dataProvider provideHumanTimestampTests
*/
public function testHumanTimestamp($tsTime, $currentTime, $timeCorrection, $dateFormat, $expectedOutput, $desc)
{
$user = $this->getMock('User');
$user->expects($this->any())->method('getOption')->with('timecorrection')->will($this->returnValue($timeCorrection));
$user->expects($this->any())->method('getDatePreference')->will($this->returnValue($dateFormat));
$tsTime = new MWTimestamp($tsTime);
$currentTime = new MWTimestamp($currentTime);
$this->assertEquals($expectedOutput, $tsTime->getHumanTimestamp($currentTime, $user), $desc);
}
示例2: 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
示例3: testHumanOutput
/**
* Test human readable timestamp format.
*/
function testHumanOutput()
{
$timestamp = new MWTimestamp(time() - 3600);
$this->assertEquals("1 hour ago", $timestamp->getHumanTimestamp()->inLanguage('en')->text());
}
示例4: execute
function execute($par)
{
if (!in_array('staff', $this->getUser()->getGroups())) {
$this->getOutput()->showErrorPage('nosuchspecialpage', 'nospecialpagetext');
return;
}
$target = $this->getRequest()->getVal("target");
if ($target) {
if (is_numeric($target)) {
$target = User::whoIs(intval($target));
} else {
$target = User::newFromName($target);
}
}
$month_1 = $this->padVar("month_1") ?: date("m");
$day_1 = $this->padVar("day_1") ?: date("d");
$hour_1 = $this->padVar("hour_1") ?: "00";
$month_2 = $this->padVar("month_2") ?: "";
$day_2 = $this->padVar("day_2") ?: "";
$hour_2 = $this->padVar("hour_2") ?: "00";
$this->getOutput()->addHTML("\n\t\t\t<form action='/Special:UnpatrolTips' method='POST'>\n\t\t\t\tUsername: <input type='text' name='target' value='{$target}'/> <br/><br/>\n\t\t\t\tStart date: Year: " . date("Y") . " Month: <input type='text' name='month_1' size='2' value='" . $month_1 . "'/>\n\t\t\t\t\t\tDay: <input type='text' name='day_1' size='2' value='" . $day_1 . "'>\n\t\t\t\t\t\tHour (GMT): <input type='text' name='hour_1' size='2' value='" . $hour_1 . "'> <br/><br/>\n\t\t\t\tEnd date (optional): Year: " . date("Y") . " <input type='text' name='month_2' size='2' value='" . $month_2 . "'>\n\t\t\t\t\t\tDay: <input type='text' name='day_2' size='2' value='" . $day_2 . "'>\n\t\t\t\t\t\tHour (GMT): <input type='text' name='hour_2' size='2' value='" . $hour_2 . "'> <br/><br/>\n\t\t\t\t<input type='submit' name='count' value='Count'/>\n\t\t\t\t<input type='submit' name='view' value='View'/>\n\t\t\t\t<input type='submit' name='update' value='Submit'/>\n\t\t\t</form>\t");
if ($this->getRequest()->wasPosted()) {
$user = $target;
if (!$user || $user->getID() == 0) {
$this->getOutput()->addHTML("Invalid user. {$this->getRequest()->getVal('username', '')}");
return;
}
$start = date("Y") . $month_1 . $day_1 . $hour_1 . "0000";
$cutoff = wfTimestamp(TS_MW, $start);
$cutoffDisplay = new MWTimestamp($start);
$humanCutoff = $cutoffDisplay->getHumanTimestamp();
$end = null;
$cutoff2 = null;
if ($month_2) {
$end = date("Y") . $month_2 . $day_2 . $hour_2 . "0000";
$cutoffDisplay2 = new MWTimestamp($end);
$humanCutoff2 = $cutoff2->getHumanTimestamp();
$cutoff2 = wfTimestamp(TS_MW, $end);
}
if ($this->getRequest()->getVal("count")) {
if (!$end) {
$this->getOutput()->addHTML("changes by {$user} since {$humanCutoff}<br/>");
} else {
$this->getOutput()->addHTML("changes by {$user} between {$humanCutoff} and {$humanCutoff} <br/>");
}
$results = $this->revertTips($user, $cutoff, $cutoff2, false, false);
$this->getOutput()->addHTML("<br/>");
if ($results > 0) {
$this->getOutput()->addHTML("there are " . $results . " tips sent to QG by {$user->getName()} for this date range<br/>");
} else {
$this->getOutput()->addHTML("There were no tips patrolled to show for this time frame.<br/>");
}
} else {
if ($this->getRequest()->getVal("view")) {
if (!$end) {
$this->getOutput()->addHTML("showing changes by {$user} since {$humanCutoff}<br/>");
} else {
$this->getOutput()->addHTML("showing changes by {$user} between {$humanCutoff} and {$humanCutoff} <br/>");
}
$results = $this->revertTips($user, $cutoff, $cutoff2, false, true);
$this->getOutput()->addHTML("<br/>");
if ($results > 0) {
$this->getOutput()->addHTML("showing " . $results . " tips sent to QG by {$user->getName()} for this date range</br>");
} else {
$this->getOutput()->addHTML("There were no tips patrolled to show for this time frame.<br/>");
}
} else {
$this->getOutput()->addHTML("<br/>");
if (!$end) {
$this->getOutput()->addHTML("reverting changes by {$user} since {$humanCutoff}<br/>");
} else {
$this->getOutput()->addHTML("reverting changes by {$user} between {$humanCutoff} and {$humanCutoff} <br/>");
}
$unpatrolled = $this->revertTips($user, $cutoff, $cutoff2, true);
if ($unpatrolled > 0) {
$this->getOutput()->addHTML("Undid " . $unpatrolled . " tips patrolled by {$user->getName()}\n");
} else {
$this->getOutput()->addHTML("There were no tips unpatrolled.<br/>");
}
}
}
}
return;
}
示例5: testHumanOutput
/**
* Test human readable timestamp format.
*/
function testHumanOutput()
{
$timestamp = new MWTimestamp(time() - 3600);
$this->assertEquals("1 hour ago", $timestamp->getHumanTimestamp()->toString());
}
示例6: getHumanTimestamp
public function getHumanTimestamp($timestamp)
{
$ts = new \MWTimestamp($timestamp);
return $ts->getHumanTimestamp();
}
示例7: showHeader
/**
* Render the header of a diff page including:
* Name with url to page
* Bytes added/removed
* Day and time of edit
* Edit Comment
*/
function showHeader()
{
$title = $this->targetTitle;
if ($this->prevRev) {
$bytesChanged = $this->rev->getSize() - $this->prevRev->getSize();
} else {
$bytesChanged = $this->rev->getSize();
}
if ($bytesChanged > 0) {
$changeMsg = 'mobile-frontend-diffview-bytesadded';
$sizeClass = MobileUI::iconClass('bytesadded', 'before', 'icon-12px meta mw-mf-bytesadded');
} elseif ($bytesChanged === 0) {
$changeMsg = 'mobile-frontend-diffview-bytesnochange';
$sizeClass = MobileUI::iconClass('bytesneutral', 'before', 'icon-12px meta mw-mf-bytesneutral');
} else {
$changeMsg = 'mobile-frontend-diffview-bytesremoved';
$sizeClass = MobileUI::iconClass('bytesremoved', 'before', 'icon-12px meta mw-mf-bytesremoved');
$bytesChanged = abs($bytesChanged);
}
if ($this->rev->isMinor()) {
$minor = ChangesList::flag('minor');
} else {
$minor = '';
}
if ($this->rev->getComment() !== '') {
$comment = Linker::formatComment($this->rev->getComment(), $title);
} else {
$comment = $this->msg('mobile-frontend-changeslist-nocomment')->escaped();
}
$ts = new MWTimestamp($this->rev->getTimestamp());
$this->getOutput()->addHtml(Html::openElement('div', array('id' => 'mw-mf-diff-info', 'class' => 'page-summary')) . Html::openElement('h2', array()) . Html::element('a', array('href' => $title->getLocalURL()), $title->getPrefixedText()) . Html::closeElement('h2') . $this->msg('mobile-frontend-diffview-comma')->rawParams(Html::element('span', array('class' => $sizeClass), $this->msg($changeMsg)->numParams($bytesChanged)->text()), Html::element('span', array('class' => 'mw-mf-diff-date meta'), $ts->getHumanTimestamp()))->text() . Html::closeElement('div') . $minor . Html::rawElement('div', array('id' => 'mw-mf-diff-comment'), $comment));
}
示例8: makeRequestItem
protected function makeRequestItem($request)
{
$requestdataEnc = htmlspecialchars(FormatJson::encode($request));
$nameEnc = htmlspecialchars($request['username']);
$nameEncForId = htmlspecialchars(Sanitizer::escapeId($request['username']));
$emailEnc = htmlspecialchars($request['email']);
$countEnc = htmlspecialchars($request['translations']);
$timestamp = new MWTimestamp($request['registrationdate']);
$agoEnc = htmlspecialchars($timestamp->getHumanTimestamp());
return <<<HTML
<div class="row request" data-data="{$requestdataEnc}" id="tsb-request-{$nameEncForId}">
\t<div class="two columns amount">
\t\t<div class="translation-count">{$countEnc}</div>
\t</div>
\t<div class="seven columns request-info">
\t\t<div class="row username">{$nameEnc}</div>
\t\t<div class="row email">{$emailEnc}</div>
\t</div>
\t<div class="three columns approval center">
\t\t<input class="row request-selector" name="request" type="checkbox" />
\t\t<div class="row signup-age">{$agoEnc}</div>
\t</div>
</div>
HTML;
}
示例9: formatTimestamp
/**
* Formats a timestamp in a human-readable format
* @param $ts string Timestamp in some format compatible with wfTimestamp()
* @return string Human-readable timestamp
*/
protected function formatTimestamp($ts)
{
$timestamp = new MWTimestamp($ts);
$ts = $timestamp->getHumanTimestamp();
return $ts;
}
示例10: testTimeUnit
/** @dataProvider providerTimeUnit */
function testTimeUnit($language, $tsTime, $currentTime, $expectedOutput, $desc)
{
$tsTime = new MWTimestamp($tsTime);
$currentTime = new MWTimestamp($currentTime);
$this->assertEquals($expectedOutput, $tsTime->getHumanTimestamp($currentTime, null, Language::factory($language)), $desc);
}