function Linker() {}
/**
- * OBSOLETE
+ * @deprecated
*/
function postParseLinkColour( $s = NULL ) {
return NULL;
* otherwise the cache won't get updated properly. See LINKCACHE.DOC.
*/
function makeLink( $title, $text = '', $query = '', $trail = '' ) {
- wfProfileIn( 'Skin::makeLink' );
+ wfProfileIn( 'Linker::makeLink' );
$nt = Title::newFromText( $title );
if ($nt) {
$result = $this->makeLinkObj( Title::newFromText( $title ), $text, $query, $trail );
} else {
- wfDebug( 'Invalid title passed to Skin::makeLink(): "'.$title."\"\n" );
+ wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
$result = $text == "" ? $title : $text;
}
- wfProfileOut( 'Skin::makeLink' );
+ wfProfileOut( 'Linker::makeLink' );
return $result;
}
if ($nt) {
return $this->makeKnownLinkObj( Title::newFromText( $title ), $text, $query, $trail, $prefix , $aprops );
} else {
- wfDebug( 'Invalid title passed to Skin::makeKnownLink(): "'.$title."\"\n" );
+ wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
return $text == '' ? $title : $text;
}
}
if ($nt) {
return $this->makeBrokenLinkObj( Title::newFromText( $title ), $text, $query, $trail );
} else {
- wfDebug( 'Invalid title passed to Skin::makeBrokenLink(): "'.$title."\"\n" );
+ wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
return $text == '' ? $title : $text;
}
}
if ($nt) {
return $this->makeStubLinkObj( Title::newFromText( $title ), $text, $query, $trail );
} else {
- wfDebug( 'Invalid title passed to Skin::makeStubLink(): "'.$title."\"\n" );
+ wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
return $text == '' ? $title : $text;
}
}
/**
* Pass a title object, not a title string
*/
- function makeLinkObj( &$nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
- global $wgOut, $wgUser, $wgInputEncoding;
- $fname = 'Skin::makeLinkObj';
+ function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
+ global $wgOut, $wgUser;
+ $fname = 'Linker::makeLinkObj';
wfProfileIn( $fname );
# Fail gracefully
$parts = explode( '#', $u, 2 );
if ( count( $parts ) == 2 ) {
- $anchor = urlencode( do_html_entity_decode( str_replace(' ', '_', $parts[1] ),
- ENT_COMPAT,
- $wgInputEncoding ) );
+ $anchor = urlencode( Sanitizer::decodeCharReferences( str_replace(' ', '_', $parts[1] ) ) );
$replacearray = array(
'%3A' => ':',
'%' => '.'
$t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
+ wfProfileOut( $fname );
return $t;
} elseif ( $nt->isAlwaysKnown() ) {
# Image links, special page links and self-links with fragements are always known.
* Pass a title object, not a title string
*/
function makeKnownLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '' ) {
- global $wgOut, $wgTitle, $wgInputEncoding;
+ global $wgOut, $wgTitle;
- $fname = 'Skin::makeKnownLinkObj';
+ $fname = 'Linker::makeKnownLinkObj';
wfProfileIn( $fname );
if ( !is_object( $nt ) ) {
$text = htmlspecialchars( $nt->getFragment() );
}
}
- $anchor = urlencode( do_html_entity_decode( str_replace(' ', '_', $nt->getFragment()), ENT_COMPAT, $wgInputEncoding ) );
+ $anchor = urlencode( Sanitizer::decodeCharReferences( str_replace( ' ', '_', $nt->getFragment() ) ) );
$replacearray = array(
'%3A' => ':',
'%' => '.'
return "<!-- ERROR -->{$prefix}{$text}{$trail}";
}
- $fname = 'Skin::makeBrokenLinkObj';
+ $fname = 'Linker::makeBrokenLinkObj';
wfProfileIn( $fname );
if ( '' == $query ) {
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 );
+ }
+ }
+
/** @todo document */
function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
$u = $nt->escapeLocalURL( $query );
}
/** @todo document */
- function makeImageLinkObj( &$nt, $label, $alt, $align = '', $width = false, $height = false, $framed = false,
+ function makeImageLinkObj( $nt, $label, $alt, $align = '', $width = false, $height = false, $framed = false,
$thumb = false, $manual_thumb = '' )
{
global $wgContLang, $wgUser, $wgThumbLimits;
$url = $img->getViewURL();
$prefix = $postfix = '';
+ wfDebug( "makeImageLinkObj: '$width'x'$height'\n" );
+
if ( 'center' == $align )
{
$prefix = '<div class="center">';
if ( $height !== false && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) {
$width = $img->getWidth() * $height / $img->getHeight();
}
- if ( '' == $manual_thumb ) {
- $url = $img->createThumb( $width );
+ if ( $manual_thumb == '') {
+ $thumb = $img->getThumbnail( $width );
+ if ( $thumb ) {
+ if( $width > $thumb->width ) {
+ // Requested a display size larger than the actual image;
+ // fake it up!
+ $height = floor($thumb->height * $width / $thumb->width);
+ wfDebug( "makeImageLinkObj: client-size height set to '$height'\n" );
+ } else {
+ $height = $thumb->height;
+ wfDebug( "makeImageLinkObj: thumb height set to '$height'\n" );
+ }
+ $url = $thumb->getUrl();
+ }
}
+ } else {
+ $width = $img->width;
+ $height = $img->height;
}
+ wfDebug( "makeImageLinkObj2: '$width'x'$height'\n" );
$u = $nt->escapeLocalURL();
if ( $url == '' ) {
$s = $this->makeBrokenImageLinkObj( $img->getTitle() );
//$s .= "<br />{$alt}<br />{$url}<br />\n";
} else {
$s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
- '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$u.'" /></a>';
+ '<img src="'.$url.'" alt="'.$alt.'" ' .
+ ( $width
+ ? ( 'width="'.$width.'" height="'.$height.'" ' )
+ : '' ) .
+ 'longdesc="'.$u.'" /></a>';
}
if ( '' != $align ) {
$s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
$boxheight = $height;
$thumbUrl = $url;
} else {
- $h = intval( $height/($width/$boxwidth) );
+ $h = round( $height/($width/$boxwidth) );
$oboxwidth = $boxwidth + 2;
if ( ( ! $boxheight === false ) && ( $h > $boxheight ) )
{
$s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
if ( $thumbUrl == '' ) {
- $s .= $this->makeBrokenImageLinkObj( $img->getTitle );
+ $s .= $this->makeBrokenImageLinkObj( $img->getTitle() );
$zoomicon = '';
} else {
$s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
/**
* Pass a title object, not a title string
*/
- function makeBrokenImageLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
+ function makeBrokenImageLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
# Fail gracefully
if ( ! isset($nt) ) {
# wfDebugDieBacktrace();
return "<!-- ERROR -->{$prefix}{$text}{$trail}";
}
- $fname = 'Skin::makeBrokenImageLinkObj';
+ $fname = 'Linker::makeBrokenImageLinkObj';
wfProfileIn( $fname );
$q = 'wpDestFile=' . urlencode( $nt->getDBkey() );
} else {
$name = $title->getDBKey();
$img = new Image( $title );
- $url = $img->getURL();
- if( $nourl ) {
- $url = str_replace( "http://", "http-noparse://", $url );
+ if( $img->exists() ) {
+ $url = $img->getURL();
+ if( $nourl ) {
+ $url = str_replace( "http://", "http-noparse://", $url );
+ }
+ $class = 'internal';
+ } else {
+ $upload = Title::makeTitle( NS_SPECIAL, 'Upload' );
+ $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $img->getName() ) );
+ $class = 'new';
}
$alt = htmlspecialchars( $title->getText() );
if( $text == '' ) {
$text = $alt;
}
$u = htmlspecialchars( $url );
- return "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$text}</a>";
+ return "<a href=\"{$u}\" class='$class' title=\"{$alt}\">{$text}</a>";
}
}
* temporarily to a value pass. Should be adjusted further. --brion
*/
function formatComment($comment, $title = NULL) {
- $fname = 'Skin::formatComment';
+ $fname = 'Linker::formatComment';
wfProfileIn( $fname );
global $wgContLang;
/** @todo document */
function tocList($toc) {
- return "<div id='toc'>\n"
- . "<div id='toctitle'><h2>" . wfMsg('toc') . "</h2></div>\n"
+ global $wgJsMimeType;
+ return "<table id='toc' class='toc'><tr><td>"
+ . "<div id='toctitle'><h2>" . wfMsgForContent('toc') . "</h2></div>\n"
. $toc
- . "</ul>\n</div>\n"
- . '<script type="text/javascript">'
+ . "</ul>\n</td></tr></table>\n"
+ . '<script type="'.$wgJsMimeType.'">'
. ' if (window.showTocToggle) {'
- . ' var tocShowText = "' . addslashes( wfMsg('showtoc') ) . '";'
- . ' var tocHideText = "' . addslashes( wfMsg('hidetoc') ) . '"; '
+ . ' var tocShowText = "' . wfEscapeJsString( wfMsgForContent('showtoc') ) . '";'
+ . ' var tocHideText = "' . wfEscapeJsString( wfMsgForContent('hidetoc') ) . '";'
. ' showTocToggle();'
. ' } '
- . '</script>'
- . "<div class='visualClear'></div>\n";
+ . "</script>\n";
}
/** @todo document */
/** @todo document */
function editSectionLink( $nt, $section ) {
- global $wgRequest;
global $wgContLang;
- if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
- # Section edit links would be out of sync on an old page.
- # But, if we're diffing to the current page, they'll be
- # correct.
- return '';
- }
-
$editurl = '§ion='.$section;
$url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);