本文整理汇总了PHP中SearchResult::getByteSize方法的典型用法代码示例。如果您正苦于以下问题:PHP SearchResult::getByteSize方法的具体用法?PHP SearchResult::getByteSize怎么用?PHP SearchResult::getByteSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SearchResult
的用法示例。
在下文中一共展示了SearchResult::getByteSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: showHit
/**
* Format a single hit result
*
* @param SearchResult $result
* @param array $terms Terms to highlight
*
* @return string
*/
protected function showHit($result, $terms)
{
$profile = new ProfileSection(__METHOD__);
if ($result->isBrokenTitle()) {
return '';
}
$title = $result->getTitle();
$titleSnippet = $result->getTitleSnippet($terms);
if ($titleSnippet == '') {
$titleSnippet = null;
}
$link_t = clone $title;
wfRunHooks('ShowSearchHitTitle', array(&$link_t, &$titleSnippet, $result, $terms, $this));
$link = Linker::linkKnown($link_t, $titleSnippet);
//If page content is not readable, just return the title.
//This is not quite safe, but better than showing excerpts from non-readable pages
//Note that hiding the entry entirely would screw up paging.
if (!$title->userCan('read', $this->getUser())) {
return "<li>{$link}</li>\n";
}
// If the page doesn't *exist*... our search index is out of date.
// The least confusing at this point is to drop the result.
// You may get less results, but... oh well. :P
if ($result->isMissingRevision()) {
return '';
}
// format redirects / relevant sections
$redirectTitle = $result->getRedirectTitle();
$redirectText = $result->getRedirectSnippet($terms);
$sectionTitle = $result->getSectionTitle();
$sectionText = $result->getSectionSnippet($terms);
$redirect = '';
if (!is_null($redirectTitle)) {
if ($redirectText == '') {
$redirectText = null;
}
$redirect = "<span class='searchalttitle'>" . $this->msg('search-redirect')->rawParams(Linker::linkKnown($redirectTitle, $redirectText))->text() . "</span>";
}
$section = '';
if (!is_null($sectionTitle)) {
if ($sectionText == '') {
$sectionText = null;
}
$section = "<span class='searchalttitle'>" . $this->msg('search-section')->rawParams(Linker::linkKnown($sectionTitle, $sectionText))->text() . "</span>";
}
// format text extract
$extract = "<div class='searchresult'>" . $result->getTextSnippet($terms) . "</div>";
$lang = $this->getLanguage();
// format description
$byteSize = $result->getByteSize();
$wordCount = $result->getWordCount();
$timestamp = $result->getTimestamp();
$size = $this->msg('search-result-size', $lang->formatSize($byteSize))->numParams($wordCount)->escaped();
if ($title->getNamespace() == NS_CATEGORY) {
$cat = Category::newFromTitle($title);
$size = $this->msg('search-result-category-size')->numParams($cat->getPageCount(), $cat->getSubcatCount(), $cat->getFileCount())->escaped();
}
$date = $lang->userTimeAndDate($timestamp, $this->getUser());
$fileMatch = '';
// Include a thumbnail for media files...
if ($title->getNamespace() == NS_FILE) {
$img = $result->getFile();
$img = $img ?: wfFindFile($title);
if ($result->isFileMatch()) {
$fileMatch = "<span class='searchalttitle'>" . $this->msg('search-file-match')->escaped() . "</span>";
}
if ($img) {
$thumb = $img->transform(array('width' => 120, 'height' => 120));
if ($thumb) {
$desc = $this->msg('parentheses')->rawParams($img->getShortDesc())->escaped();
// Float doesn't seem to interact well with the bullets.
// Table messes up vertical alignment of the bullets.
// Bullets are therefore disabled (didn't look great anyway).
return "<li>" . '<table class="searchResultImage">' . '<tr>' . '<td style="width: 120px; text-align: center; vertical-align: top;">' . $thumb->toHtml(array('desc-link' => true)) . '</td>' . '<td style="vertical-align: top;">' . "{$link} {$redirect} {$section} {$fileMatch}" . $extract . "<div class='mw-search-result-data'>{$desc} - {$date}</div>" . '</td>' . '</tr>' . '</table>' . "</li>\n";
}
}
}
$html = null;
$score = '';
if (wfRunHooks('ShowSearchHit', array($this, $result, $terms, &$link, &$redirect, &$section, &$extract, &$score, &$size, &$date, &$related, &$html))) {
$html = "<li><div class='mw-search-result-heading'>" . "{$link} {$redirect} {$section} {$fileMatch}</div> {$extract}\n" . "<div class='mw-search-result-data'>{$size} - {$date}</div>" . "</li>\n";
}
return $html;
}
示例2: showHit
/**
* Format a single hit result
* @param SearchResult $result
* @param array $terms terms to highlight
*/
protected function showHit($result, $terms)
{
global $wgContLang, $wgLang, $wgUser;
wfProfileIn(__METHOD__);
if ($result->isBrokenTitle()) {
wfProfileOut(__METHOD__);
return "<!-- Broken link in search result -->\n";
}
$sk = $wgUser->getSkin();
$t = $result->getTitle();
$titleSnippet = $result->getTitleSnippet($terms);
if ($titleSnippet == '') {
$titleSnippet = null;
}
$link_t = clone $t;
wfRunHooks('ShowSearchHitTitle', array(&$link_t, &$titleSnippet, $result, $terms, $this));
$link = $this->sk->linkKnown($link_t, $titleSnippet);
//If page content is not readable, just return the title.
//This is not quite safe, but better than showing excerpts from non-readable pages
//Note that hiding the entry entirely would screw up paging.
if (!$t->userCanRead()) {
wfProfileOut(__METHOD__);
return "<li>{$link}</li>\n";
}
// If the page doesn't *exist*... our search index is out of date.
// The least confusing at this point is to drop the result.
// You may get less results, but... oh well. :P
if ($result->isMissingRevision()) {
wfProfileOut(__METHOD__);
return "<!-- missing page " . htmlspecialchars($t->getPrefixedText()) . "-->\n";
}
// format redirects / relevant sections
$redirectTitle = $result->getRedirectTitle();
$redirectText = $result->getRedirectSnippet($terms);
$sectionTitle = $result->getSectionTitle();
$sectionText = $result->getSectionSnippet($terms);
$redirect = '';
if (!is_null($redirectTitle)) {
if ($redirectText == '') {
$redirectText = null;
}
$redirect = "<span class='searchalttitle'>" . wfMsg('search-redirect', $this->sk->linkKnown($redirectTitle, $redirectText)) . "</span>";
}
$section = '';
if (!is_null($sectionTitle)) {
if ($sectionText == '') {
$sectionText = null;
}
$section = "<span class='searchalttitle'>" . wfMsg('search-section', $this->sk->linkKnown($sectionTitle, $sectionText)) . "</span>";
}
// format text extract
$extract = "<div class='searchresult'>" . $result->getTextSnippet($terms) . "</div>";
// format score
if (is_null($result->getScore())) {
// Search engine doesn't report scoring info
$score = '';
} else {
$percent = sprintf('%2.1f', $result->getScore() * 100);
$score = wfMsg('search-result-score', $wgLang->formatNum($percent)) . ' - ';
}
// format description
$byteSize = $result->getByteSize();
$wordCount = $result->getWordCount();
$timestamp = $result->getTimestamp();
$size = wfMsgExt('search-result-size', array('parsemag', 'escape'), $this->sk->formatSize($byteSize), $wgLang->formatNum($wordCount));
$date = $wgLang->timeanddate($timestamp);
// link to related articles if supported
$related = '';
if ($result->hasRelated()) {
$st = SpecialPage::getTitleFor('Search');
$stParams = array_merge($this->powerSearchOptions(), array('search' => wfMsgForContent('searchrelated') . ':' . $t->getPrefixedText(), 'fulltext' => wfMsg('search')));
$related = ' -- ' . $sk->linkKnown($st, wfMsg('search-relatedarticle'), array(), $stParams);
}
// Include a thumbnail for media files...
if ($t->getNamespace() == NS_FILE) {
$img = wfFindFile($t);
if ($img) {
$thumb = $img->transform(array('width' => 120, 'height' => 120));
if ($thumb) {
$desc = $img->getShortDesc();
wfProfileOut(__METHOD__);
// Float doesn't seem to interact well with the bullets.
// Table messes up vertical alignment of the bullets.
// Bullets are therefore disabled (didn't look great anyway).
return "<li>" . '<table class="searchResultImage">' . '<tr>' . '<td width="120" align="center" valign="top">' . $thumb->toHtml(array('desc-link' => true)) . '</td>' . '<td valign="top">' . $link . $extract . "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" . '</td>' . '</tr>' . '</table>' . "</li>\n";
}
}
}
wfProfileOut(__METHOD__);
return "<li>{$link} {$redirect} {$section} {$extract}\n" . "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" . "</li>\n";
}
示例3: getByteSize
function getByteSize()
{
if (is_null($this->mSize)) {
return parent::getByteSize();
}
return $this->mSize;
}