function formatResult($skin, $result) { global $wgContLang; $nt = Title::makeTitle($result->namespace, $result->title); $text = $wgContLang->convert($nt->getText()); $plink = Linker::link(Title::newFromText($nt->getPrefixedText()), htmlspecialchars($text)); $download = Linker::makeMediaLinkObj($nt, wfMsgHtml('download')); $lang = $this->getLanguage(); $bytes = htmlspecialchars($lang->formatSize($result->img_size)); $dimensions = htmlspecialchars(wfMsg('widthheight', $lang->formatNum($result->img_width), $lang->formatNum($result->img_height))); $user = Linker::link(Title::makeTitle(NS_USER, $result->img_user_text), htmlspecialchars($result->img_user_text)); $time = htmlspecialchars($lang->timeanddate($result->img_timestamp)); return "({$download}) {$plink} . . {$dimensions} . . {$bytes} . . {$user} . . {$time}"; }
function formatResult($skin, $result) { global $wgContLang; $nt = Title::makeTitle($result->namespace, $result->title); $text = $wgContLang->convert($nt->getText()); $plink = Linker::link(Title::newFromText($nt->getPrefixedText()), htmlspecialchars($text)); $download = Linker::makeMediaLinkObj($nt, $this->msg('download')->escaped()); $download = $this->msg('parentheses')->rawParams($download)->escaped(); $lang = $this->getLanguage(); $bytes = htmlspecialchars($lang->formatSize($result->img_size)); $dimensions = $this->msg('widthheight')->numParams($result->img_width, $result->img_height)->escaped(); $user = Linker::link(Title::makeTitle(NS_USER, $result->img_user_text), htmlspecialchars($result->img_user_text)); $time = htmlspecialchars($lang->userTimeAndDate($result->img_timestamp, $this->getUser())); return "{$download} {$plink} . . {$dimensions} . . {$bytes} . . {$user} . . {$time}"; }
/** * Formats wiki links and media links in text; all other wiki formatting * is ignored * * @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser * @param string $comment Text to format links in. WARNING! Since the output of this * function is html, $comment must be sanitized for use as html. You probably want * to pass $comment through Sanitizer::escapeHtmlAllowEntities() before calling * this function. * @param Title|null $title An optional title object used to links to sections * @param bool $local Whether section links should refer to local page * @param string|null $wikiId Id of the wiki to link to (if not the local wiki), * as used by WikiMap. * * @return string */ public static function formatLinksInComment($comment, $title = null, $local = false, $wikiId = null) { return preg_replace_callback('/ \\[\\[ :? # ignore optional leading colon ([^\\]|]+) # 1. link target; page names cannot include ] or | (?:\\| # 2. a pipe-separated substring; only the last is captured # Stop matching at | and ]] without relying on backtracking. ((?:]?[^\\]|])*+) )* \\]\\] ([^[]*) # 3. link trail (the text up until the next link) /x', function ($match) use($title, $local, $wikiId) { global $wgContLang; $medians = '(?:' . preg_quote(MWNamespace::getCanonicalName(NS_MEDIA), '/') . '|'; $medians .= preg_quote($wgContLang->getNsText(NS_MEDIA), '/') . '):'; $comment = $match[0]; # fix up urlencoded title texts (copied from Parser::replaceInternalLinks) if (strpos($match[1], '%') !== false) { $match[1] = strtr(rawurldecode($match[1]), array('<' => '<', '>' => '>')); } # Handle link renaming [[foo|text]] will show link as "text" if ($match[2] != "") { $text = $match[2]; } else { $text = $match[1]; } $submatch = array(); $thelink = null; if (preg_match('/^' . $medians . '(.*)$/i', $match[1], $submatch)) { # Media link; trail not supported. $linkRegexp = '/\\[\\[(.*?)\\]\\]/'; $title = Title::makeTitleSafe(NS_FILE, $submatch[1]); if ($title) { $thelink = Linker::makeMediaLinkObj($title, $text); } } else { # Other kind of link if (preg_match($wgContLang->linkTrail(), $match[3], $submatch)) { $trail = $submatch[1]; } else { $trail = ""; } $linkRegexp = '/\\[\\[(.*?)\\]\\]' . preg_quote($trail, '/') . '/'; if (isset($match[1][0]) && $match[1][0] == ':') { $match[1] = substr($match[1], 1); } list($inside, $trail) = Linker::splitTrail($trail); $linkText = $text; $linkTarget = Linker::normalizeSubpageLink($title, $match[1], $linkText); $target = Title::newFromText($linkTarget); if ($target) { if ($target->getText() == '' && !$target->isExternal() && !$local && $title) { $newTarget = clone $title; $newTarget->setFragment('#' . $target->getFragment()); $target = $newTarget; } $thelink = Linker::makeCommentLink($target, $linkText . $inside, $wikiId) . $trail; } } if ($thelink) { // If the link is still valid, go ahead and replace it in! $comment = preg_replace($linkRegexp, StringUtils::escapeRegexReplacement($thelink), $comment, 1); } return $comment; }, $comment); }
public function makeMediaLinkObj($title, $html = '', $time = false) { return Linker::makeMediaLinkObj($title, $html, $time); }
/** * Generates a media, external or file link for a given result * @param object $oDocument Apache_Solr_Document * @param object $oTitle Title of wiki page * @return string Anchor media, external or file link */ private function getFileLink($oDocument, $oTitle) { if ($oDocument->overall_type == 'repo') { $sSearchLink = Linker::makeMediaLinkObj($oTitle); } elseif ($oDocument->overall_type == 'special-linked') { $sTitle = $oDocument->title; $sLink = $oDocument->path; $sSearchLink = Linker::makeExternalLink($sLink, $sTitle, ''); $sSearchLink = str_replace('<a', '<a target="_blank"', $sSearchLink); } else { $sTitle = $oDocument->title; $sLink = $oDocument->path; $sSearchLink = '<a target="_blank" href="file:///' . $sLink . '">' . $sTitle . '</a>'; } return $sSearchLink; }