/** * Make a link placeholder. The text returned can be later resolved to a real link with * replaceLinkHolders(). This is done for two reasons: firstly to avoid further * parsing of interwiki links, and secondly to allow all existence checks and * article length checks (for stub links) to be bundled into a single query. * */ function makeHolder($nt, $text = '', $query = '', $trail = '', $prefix = '') { wfProfileIn(__METHOD__); if (!is_object($nt)) { # Fail gracefully $retVal = "<!-- ERROR -->{$prefix}{$text}{$trail}"; } else { # Separate the link trail from the rest of the link list($inside, $trail) = Linker::splitTrail($trail); $entry = array('title' => $nt, 'text' => $prefix . $text . $inside, 'pdbk' => $nt->getPrefixedDBkey()); if ($query !== '') { $entry['query'] = $query; } if ($nt->isExternal()) { // Use a globally unique ID to keep the objects mergable $key = $this->parent->nextLinkID(); $this->interwikis[$key] = $entry; $retVal = "<!--IWLINK {$key}-->{$trail}"; } else { $key = $this->parent->nextLinkID(); $ns = $nt->getNamespace(); $this->internals[$ns][$key] = $entry; $retVal = "<!--LINK {$ns}:{$key}-->{$trail}"; } $this->size++; } wfProfileOut(__METHOD__); return $retVal; }
/** * Render a forced-blue link inline; protect against double expansion of * URLs if we're in a mode that prepends full URL prefixes to internal links. * Since this little disaster has to split off the trail text to avoid * breaking URLs in the following text without breaking trails on the * wiki links, it's been made into a horrible function. * * @param Title $nt * @param string $text * @param array|string $query * @param string $trail * @param string $prefix * @return string HTML-wikitext mix oh yuck */ function makeKnownLinkHolder($nt, $text = '', $query = array(), $trail = '', $prefix = '') { list($inside, $trail) = Linker::splitTrail($trail); if (is_string($query)) { $query = wfCgiToArray($query); } if ($text == '') { $text = htmlspecialchars($nt->getPrefixedText()); } $link = Linker::linkKnown($nt, "{$prefix}{$text}{$inside}", array(), $query); return $this->armorLinks($link) . $trail; }
/** * Render a forced-blue link inline; protect against double expansion of * URLs if we're in a mode that prepends full URL prefixes to internal links. * Since this little disaster has to split off the trail text to avoid * breaking URLs in the following text without breaking trails on the * wiki links, it's been made into a horrible function. * * @param Title $nt * @param string $text * @param string $query * @param string $trail * @param string $prefix * @return string HTML-wikitext mix oh yuck */ function makeKnownLinkHolder($nt, $text = '', $query = '', $trail = '', $prefix = '') { list($inside, $trail) = Linker::splitTrail($trail); $sk = $this->mOptions->getSkin(); $link = $sk->makeKnownLinkObj($nt, $text, $query, $inside, $prefix); return $this->armorLinks($link) . $trail; }
/** * 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 splitTrail($trail) { return Linker::splitTrail($trail); }
function makeSelfLinkObj($nt, $text = '', $query = '', $trail = '', $prefix = '') { $args = ''; if ('' == $text) { $text = $nt->mDbkeyform; } list($inside, $trail) = Linker::splitTrail($trail); $title = "{$prefix}{$text}"; if ($text == 'RTENOTITLE') { // 2223 $args .= '_fcknotitle="true" '; $title = $nt->mDbkeyform; } return "<a {$args}href=\"" . $nt->mDbkeyform . "\" class=\"selflink\">{$title}</a>{$inside}{$trail}"; }
/** * Render a forced-blue link inline; protect against double expansion of * URLs if we're in a mode that prepends full URL prefixes to internal links. * Since this little disaster has to split off the trail text to avoid * breaking URLs in the following text without breaking trails on the * wiki links, it's been made into a horrible function. * * @param Title $nt * @param string $text * @param string $trail * @param string $prefix * @return string HTML-wikitext mix oh yuck */ protected function makeKnownLinkHolder($nt, $text = '', $trail = '', $prefix = '') { list($inside, $trail) = Linker::splitTrail($trail); if ($text == '') { $text = htmlspecialchars($nt->getPrefixedText()); } $link = $this->getLinkRenderer()->makeKnownLink($nt, new HtmlArmor("{$prefix}{$text}{$inside}")); return $this->armorLinks($link) . $trail; }
/** * Pass a title object, not a title string */ function makeBrokenImageLinkObj($nt, $text = '', $query = '', $trail = '', $prefix = '') { # Fail gracefully if (!isset($nt)) { # wfDebugDieBacktrace(); return "<!-- ERROR -->{$prefix}{$text}{$trail}"; } $fname = 'Linker::makeBrokenImageLinkObj'; wfProfileIn($fname); $q = 'wpDestFile=' . urlencode($nt->getDBkey()); if ('' != $query) { $q .= "&{$query}"; } $uploadTitle = Title::makeTitle(NS_SPECIAL, 'Upload'); $url = $uploadTitle->escapeLocalURL($q); if ('' == $text) { $text = htmlspecialchars($nt->getPrefixedText()); } $style = $this->getInternalLinkAttributesObj($nt, $text, "yes"); list($inside, $trail) = Linker::splitTrail($trail); $s = "<a href=\"{$url}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}"; wfProfileOut($fname); return $s; }
/** * Make appropriate markup for a link to the current article. This is currently rendered * as the bold link text. The calling sequence is the same as the other make*LinkObj functions, * despite $query not being used. */ function makeSelfLinkObj($nt, $text = '', $query = '', $trail = '', $prefix = '') { if ('' == $text) { $text = htmlspecialchars($nt->getPrefixedText()); } list($inside, $trail) = Linker::splitTrail($trail); return "<strong class=\"selflink\">{$prefix}{$text}{$inside}</strong>{$trail}"; }
/** * @deprecated Use link() * * Make a red link to the edit page of a given title. * * @param $nt Title object of the target page * @param $text String: Link text * @param $query String: Optional query part * @param $trail String: Optional trail. Alphabetic characters at the start of this string will * be included in the link text. Other characters will be appended after * the end of the link. */ function makeBrokenLinkObj($title, $text = '', $query = '', $trail = '', $prefix = '') { wfProfileIn(__METHOD__); list($inside, $trail) = Linker::splitTrail($trail); if ($text === '') { $text = $this->linkText($title); } $nt = $this->normaliseSpecialPage($title); $ret = $this->link($title, "{$prefix}{$text}{$inside}", array(), wfCgiToArray($query), 'broken') . $trail; wfProfileOut(__METHOD__); return $ret; }
/** * Render a forced-blue link inline; protect against double expansion of * URLs if we're in a mode that prepends full URL prefixes to internal links. * Since this little disaster has to split off the trail text to avoid * breaking URLs in the following text without breaking trails on the * wiki links, it's been made into a horrible function. * * @param $nt Title * @param $text String * @param $query String * @param $trail String * @param $prefix String * @return String: HTML-wikitext mix oh yuck */ function makeKnownLinkHolder($nt, $text = '', $query = '', $trail = '', $prefix = '') { list($inside, $trail) = Linker::splitTrail($trail); $sk = $this->mOptions->getSkin($this->mTitle); # FIXME: use link() instead of deprecated makeKnownLinkObj() $link = $sk->makeKnownLinkObj($nt, $text, $query, $inside, $prefix); return $this->armorLinks($link) . $trail; }