checkTitleEncoding( $link ); $link = preg_replace( '/[\\x00-\\x1f]/', ' ', $link ); $link = htmlspecialchars( $link ); $r = ($class != '') ? " class='$class'" : " class='external'"; $r .= " title=\"{$link}\""; return $r; } /** @todo document */ function getInternalLinkAttributes( $link, $text, $broken = false ) { $link = urldecode( $link ); $link = str_replace( '_', ' ', $link ); $link = htmlspecialchars( $link ); if( $broken == 'stub' ) { $r = ' class="stub"'; } else if ( $broken == 'yes' ) { $r = ' class="new"'; } else { $r = ''; } $r .= " title=\"{$link}\""; return $r; } /** * @param bool $broken */ function getInternalLinkAttributesObj( &$nt, $text, $broken = false ) { if( $broken == 'stub' ) { $r = ' class="stub"'; } else if ( $broken == 'yes' ) { $r = ' class="new"'; } else { $r = ''; } $r .= ' title="' . $nt->getEscapedText() . '"'; return $r; } /** * This function is a shortcut to makeLinkObj(Title::newFromText($title),...). Do not call * it if you already have a title object handy. See makeLinkObj for further documentation. * * @param string $title The text of the title * @param string $text Link text * @param string $query Optional query part * @param string $trail 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 makeLink( $title, $text = '', $query = '', $trail = '' ) { wfProfileIn( 'Linker::makeLink' ); $nt = Title::newFromText( $title ); if ($nt) { $result = $this->makeLinkObj( Title::newFromText( $title ), $text, $query, $trail ); } else { wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" ); $result = $text == "" ? $title : $text; } wfProfileOut( 'Linker::makeLink' ); return $result; } /** * This function is a shortcut to makeKnownLinkObj(Title::newFromText($title),...). Do not call * it if you already have a title object handy. See makeKnownLinkObj for further documentation. * * @param string $title The text of the title * @param string $text Link text * @param string $query Optional query part * @param string $trail 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 makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') { $nt = Title::newFromText( $title ); if ($nt) { return $this->makeKnownLinkObj( Title::newFromText( $title ), $text, $query, $trail, $prefix , $aprops ); } else { wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" ); return $text == '' ? $title : $text; } } /** * This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call * it if you already have a title object handy. See makeBrokenLinkObj for further documentation. * * @param string $title The text of the title * @param string $text Link text * @param string $query Optional query part * @param string $trail 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 makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) { $nt = Title::newFromText( $title ); if ($nt) { return $this->makeBrokenLinkObj( Title::newFromText( $title ), $text, $query, $trail ); } else { wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" ); return $text == '' ? $title : $text; } } /** * This function is a shortcut to makeStubLinkObj(Title::newFromText($title),...). Do not call * it if you already have a title object handy. See makeStubLinkObj for further documentation. * * @param string $title The text of the title * @param string $text Link text * @param string $query Optional query part * @param string $trail 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 makeStubLink( $title, $text = '', $query = '', $trail = '' ) { $nt = Title::newFromText( $title ); if ($nt) { return $this->makeStubLinkObj( Title::newFromText( $title ), $text, $query, $trail ); } else { wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" ); return $text == '' ? $title : $text; } } /** * Make a link for a title which may or may not be in the database. If you need to * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each * call to this will result in a DB query. * * @param string $title The text of the title * @param string $text Link text * @param string $query Optional query part * @param string $trail 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 makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) { global $wgUser; $fname = 'Linker::makeLinkObj'; wfProfileIn( $fname ); # Fail gracefully if ( ! is_object($nt) ) { # wfDebugDieBacktrace(); wfProfileOut( $fname ); return "{$prefix}{$text}{$trail}"; } $ns = $nt->getNamespace(); $dbkey = $nt->getDBkey(); if ( $nt->isExternal() ) { $u = $nt->getFullURL(); $link = $nt->getPrefixedURL(); if ( '' == $text ) { $text = $nt->getPrefixedText(); } $style = $this->getExternalLinkAttributes( $link, $text, 'extiw' ); $inside = ''; if ( '' != $trail ) { if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) { $inside = $m[1]; $trail = $m[2]; } } # Check for anchors, normalize the anchor $parts = explode( '#', $u, 2 ); if ( count( $parts ) == 2 ) { $anchor = urlencode( Sanitizer::decodeCharReferences( str_replace(' ', '_', $parts[1] ) ) ); $replacearray = array( '%3A' => ':', '%' => '.' ); $u = $parts[0] . '#' . str_replace( array_keys( $replacearray ), array_values( $replacearray ), $anchor ); } $t = "{$text}{$inside}"; wfProfileOut( $fname ); return $t; } elseif ( $nt->isAlwaysKnown() ) { # Image links, special page links and self-links with fragements are always known. $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); } else { wfProfileIn( $fname.'-immediate' ); # Work out link colour immediately $aid = $nt->getArticleID() ; if ( 0 == $aid ) { $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix ); } else { $threshold = $wgUser->getOption('stubthreshold') ; if ( $threshold > 0 ) { $dbr =& wfGetDB( DB_SLAVE ); $s = $dbr->selectRow( array( 'page' ), array( 'page_len', 'page_namespace', 'page_is_redirect' ), array( 'page_id' => $aid ), $fname ) ; if ( $s !== false ) { $size = $s->page_len; if ( $s->page_is_redirect OR $s->page_namespace != NS_MAIN ) { $size = $threshold*2 ; # Really big } } else { $size = $threshold*2 ; # Really big } } else { $size = 1 ; } if ( $size < $threshold ) { $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix ); } else { $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); } } wfProfileOut( $fname.'-immediate' ); } wfProfileOut( $fname ); return $retVal; } /** * Make a link for a title which definitely exists. This is faster than makeLinkObj because * it doesn't have to do a database query. It's also valid for interwiki titles and special * pages. * * @param object Title of target page * @param string Text to replace the title * @param string Link target * @param string Text after link * @param string Text before link text * @param string Extra attributes to the a-element * @return the a-element */ function makeKnownLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '' ) { $fname = 'Linker::makeKnownLinkObj'; wfProfileIn( $fname ); if ( !is_object( $nt ) ) { wfProfileOut( $fname ); return $text; } $u = $nt->escapeLocalURL( $query ); if ( '' != $nt->getFragment() ) { if( $nt->getPrefixedDbkey() == '' ) { $u = ''; if ( '' == $text ) { $text = htmlspecialchars( $nt->getFragment() ); } } $anchor = urlencode( Sanitizer::decodeCharReferences( str_replace( ' ', '_', $nt->getFragment() ) ) ); $replacearray = array( '%3A' => ':', '%' => '.' ); $u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor); } if ( '' == $text ) { $text = htmlspecialchars( $nt->getPrefixedText() ); } $style = $this->getInternalLinkAttributesObj( $nt, $text ); if ( $aprops !== '' ) $aprops = ' ' . $aprops; list( $inside, $trail ) = Linker::splitTrail( $trail ); $r = "{$prefix}{$text}{$inside}{$trail}"; wfProfileOut( $fname ); return $r; } /** * Make a red link to the edit page of a given title. * * @param string $title The text of the title * @param string $text Link text * @param string $query Optional query part * @param string $trail 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( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { # Fail gracefully if ( ! isset($nt) ) { # wfDebugDieBacktrace(); return "{$prefix}{$text}{$trail}"; } $fname = 'Linker::makeBrokenLinkObj'; wfProfileIn( $fname ); if ( '' == $query ) { $q = 'action=edit'; } else { $q = 'action=edit&'.$query; } $u = $nt->escapeLocalURL( $q ); if ( '' == $text ) { $text = htmlspecialchars( $nt->getPrefixedText() ); } $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" ); list( $inside, $trail ) = Linker::splitTrail( $trail ); $s = "{$prefix}{$text}{$inside}{$trail}"; wfProfileOut( $fname ); return $s; } /** * Make a brown link to a short article. * * @param string $title The text of the title * @param string $text Link text * @param string $query Optional query part * @param string $trail 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 makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { $link = $nt->getPrefixedURL(); $u = $nt->escapeLocalURL( $query ); if ( '' == $text ) { $text = htmlspecialchars( $nt->getPrefixedText() ); } $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' ); list( $inside, $trail ) = Linker::splitTrail( $trail ); $s = "{$prefix}{$text}{$inside}{$trail}"; return $s; } /** * Generate either a normal exists-style link or a stub link, depending * on the given page size. * * @param int $size * @param Title $nt * @param string $text * @param string $query * @param string $trail * @param string $prefix * @return string HTML of link */ function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { global $wgUser; $threshold = intval( $wgUser->getOption( 'stubthreshold' ) ); if( $size < $threshold ) { return $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix ); } else { return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); } } /** * 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 "{$prefix}{$text}{$inside}{$trail}"; } /** @todo document */ function fnamePart( $url ) { $basename = strrchr( $url, '/' ); if ( false === $basename ) { $basename = $url; } else { $basename = substr( $basename, 1 ); } return htmlspecialchars( $basename ); } /** Obsolete alias */ function makeImage( $url, $alt = '' ) { return $this->makeExternalImage( $url, $alt ); } /** @todo document */ function makeExternalImage( $url, $alt = '' ) { if ( '' == $alt ) { $alt = $this->fnamePart( $url ); } $s = ''; return $s; } /** @todo document */ function makeImageLinkObj( $nt, $label, $alt, $align = '', $width = false, $height = false, $framed = false, $thumb = false, $manual_thumb = '' ) { global $wgContLang, $wgUser, $wgThumbLimits; $img = new Image( $nt ); if ( !$img->allowInlineDisplay() && $img->exists() ) { return $this->makeKnownLinkObj( $nt ); } $url = $img->getViewURL(); $error = $prefix = $postfix = ''; wfDebug( "makeImageLinkObj: '$width'x'$height'\n" ); if ( 'center' == $align ) { $prefix = '
'
. '' . $title . " |