* Pass a title object, not a title string
*/
function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
- global $wgOut, $wgUser;
+ global $wgUser;
$fname = 'Linker::makeLinkObj';
wfProfileIn( $fname );
/**
* Pass a title object, not a title string
+ * @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 = '' ) {
- global $wgOut, $wgTitle;
$fname = 'Linker::makeKnownLinkObj';
wfProfileIn( $fname );
$text = htmlspecialchars( $nt->getPrefixedText() );
}
$style = $this->getInternalLinkAttributesObj( $nt, $text );
+
+ if ( $aprops !== '' ) $aprops = ' ' . $aprops;
list( $inside, $trail ) = Linker::splitTrail( $trail );
$r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
*/
function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
global $wgUser;
- $threshold = IntVal( $wgUser->getOption( 'stubthreshold' ) );
+ $threshold = intval( $wgUser->getOption( 'stubthreshold' ) );
if( $size < $threshold ) {
return $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
} else {
/** @todo document */
function makeExternalImage( $url, $alt = '' ) {
- global $wgOut;
if ( '' == $alt ) {
$alt = $this->fnamePart( $url );
}
$wopt = User::getDefaultOption( 'thumbsize' );
}
- $width = $wgThumbLimits[$wopt];
+ $width = min( $img->getWidth(), $wgThumbLimits[$wopt] );
}
return $prefix.$this->makeThumbLinkObj( $img, $label, $alt, $align, $width, $height, $framed, $manual_thumb ).$postfix;
+ }
- } elseif ( $width ) {
+ if ( $width && $img->exists() ) {
# Create a resized image, without the additional thumbnail
# features
- if ( $height !== false && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) {
- $width = $img->getWidth() * $height / $img->getHeight();
- }
+ if ( $height == false )
+ $height = -1;
if ( $manual_thumb == '') {
- $thumb = $img->getThumbnail( $width );
+ $thumb = $img->getThumbnail( $width, $height );
if ( $thumb ) {
- if( $width > $thumb->width ) {
+ if( $width > $img->width && ( $height == -1 || $height > $img->height )) {
// Requested a display size larger than the actual image;
// fake it up!
- $height = floor($thumb->height * $width / $thumb->width);
+ $height = round($thumb->height * $width / $thumb->width);
wfDebug( "makeImageLinkObj: client-size height set to '$height'\n" );
} else {
+ $width = $thumb->width;
$height = $thumb->height;
wfDebug( "makeImageLinkObj: thumb height set to '$height'\n" );
}
{
// Use image dimensions, don't scale
$boxwidth = $width;
- $oboxwidth = $boxwidth + 2;
$boxheight = $height;
$thumbUrl = $url;
} else {
- $h = round( $height/($width/$boxwidth) );
- $oboxwidth = $boxwidth + 2;
- if ( ( ! $boxheight === false ) && ( $h > $boxheight ) )
- {
- $boxwidth *= $boxheight/$h;
- } else {
- $boxheight = $h;
+ if ( $boxheight === false )
+ $boxheight = -1;
+ if ( '' == $manual_thumb ) {
+ $thumb = $img->getThumbnail( $boxwidth, $boxheight );
+ if ( $thumb ) {
+ $thumbUrl = $thumb->getUrl();
+ $boxwidth = $thumb->width;
+ $boxheight = $thumb->height;
+ }
}
- if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth );
}
+ $oboxwidth = $boxwidth + 2;
if ( $manual_thumb != '' ) # Use manually specified thumbnail
{
$textalign = $wgContLang->isRTL() ? ' style="text-align:right"' : '';
$s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
- if ( $thumbUrl == '' ) {
- $s .= $this->makeBrokenImageLinkObj( $img->getTitle );
+ if( $thumbUrl == '' ) {
+ // Couldn't generate thumbnail? Scale the image client-side.
+ $thumbUrl = $url;
+ }
+ if( !$img->exists() ) {
+ $s .= $this->makeBrokenImageLinkObj( $img->getTitle() );
$zoomicon = '';
} else {
$s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
}
/** @todo document */
- function makeMediaLink( $name, $url, $alt = '' ) {
+ function makeMediaLink( $name, /* wtf?! */ $url, $alt = '' ) {
$nt = Title::makeTitleSafe( NS_IMAGE, $name );
return $this->makeMediaLinkObj( $nt, $alt );
}
if( $img->exists() ) {
$url = $img->getURL();
if( $nourl ) {
- $url = str_replace( "http://", "http-noparse://", $url );
+ $url = str_replace( "http://", UNIQ_PREFIX . "NOPARSEhttp://", $url );
}
$class = 'internal';
} else {
$thelink = $this->makeMediaLink( $submatch[1], "", $text );
} else {
# Other kind of link
- if( preg_match( wfMsgForContent( "linktrail" ), $match[4], $submatch ) ) {
+ if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
$trail = $submatch[1];
} else {
$trail = "";
$match[1] = substr($match[1], 1);
$thelink = $this->makeLink( $match[1], $text, "", $trail );
}
+ # Quote backreferences, then run preg_replace
+ $thelink = strtr( $thelink, array( "\\" => "\\\\", '$' => "\\$" ) );
$comment = preg_replace( $linkRegexp, $thelink, $comment, 1 );
}
wfProfileOut( $fname );
/** @todo document */
function tocList($toc) {
global $wgJsMimeType;
- return "<table id='toc' class='toc'><tr><td>"
- . "<div id='toctitle'><h2>" . wfMsgForContent('toc') . "</h2></div>\n"
- . $toc
- . "</ul>\n</td></tr></table>\n"
- . '<script type="'.$wgJsMimeType.'">'
- . ' if (window.showTocToggle) {'
- . ' var tocShowText = "' . wfEscapeJsString( wfMsgForContent('showtoc') ) . '";'
- . ' var tocHideText = "' . wfEscapeJsString( wfMsgForContent('hidetoc') ) . '";'
- . ' showTocToggle();'
- . ' } '
- . "</script>\n";
+ $title = wfMsgForContent('toc') ;
+ return
+ '<table id="toc" class="toc" summary="' . $title .'"><tr><td>'
+ . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
+ . $toc
+ . "</ul>\n</td></tr></table>\n"
+ . '<script type="' . $wgJsMimeType . '">'
+ . ' if (window.showTocToggle) {'
+ . ' var tocShowText = "' . wfEscapeJsString( wfMsgForContent('showtoc') ) . '";'
+ . ' var tocHideText = "' . wfEscapeJsString( wfMsgForContent('hidetoc') ) . '";'
+ . ' showTocToggle();'
+ . ' } '
+ . "</script>\n";
}
/** @todo document */
function editSectionLinkForOther( $title, $section ) {
- global $wgRequest;
global $wgContLang;
$title = Title::newFromText($title);