本文整理汇总了PHP中Linker::normalizeSubpageLink方法的典型用法代码示例。如果您正苦于以下问题:PHP Linker::normalizeSubpageLink方法的具体用法?PHP Linker::normalizeSubpageLink怎么用?PHP Linker::normalizeSubpageLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Linker
的用法示例。
在下文中一共展示了Linker::normalizeSubpageLink方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: maybeDoSubpageLink
/**
* Handle link to subpage if necessary
*
* @param string $target The source of the link
* @param string &$text The link text, modified as necessary
* @return string The full name of the link
* @private
*/
function maybeDoSubpageLink($target, &$text)
{
return Linker::normalizeSubpageLink($this->mTitle, $target, $text);
}
示例2: normalizeSubpageLink
public function normalizeSubpageLink($contextTitle, $target, &$text)
{
return Linker::normalizeSubpageLink($contextTitle, $target, $text);
}
示例3: formatLinksInComment
/**
* 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);
}
示例4: formatLinksInCommentCallback
protected function formatLinksInCommentCallback($match)
{
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] = str_replace(array('<', '>'), array('<', '>'), urldecode($match[1]));
}
# Handle link renaming [[foo|text]] will show link as "text"
if ($match[3] != "") {
$text = $match[3];
} 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]);
$thelink = $this->makeMediaLinkObj($title, $text);
} else {
# Other kind of link
if (preg_match($wgContLang->linkTrail(), $match[4], $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($this->commentContextTitle, $match[1], $linkText);
$target = Title::newFromText($linkTarget);
if ($target) {
if ($target->getText() == '' && !$this->commentLocal && $this->commentContextTitle) {
$newTarget = clone $this->commentContextTitle;
$newTarget->setFragment('#' . $target->getFragment());
$target = $newTarget;
}
$thelink = $this->link($target, $linkText . $inside) . $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;
}