$retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
} else {
wfProfileIn( $fname.'-immediate' );
+
+ # Handles links to special pages wich do not exist in the database:
+ if( $nt->getNamespace() == NS_SPECIAL ) {
+ if( SpecialPage::exists( $nt->getDbKey() ) ) {
+ $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
+ } else {
+ $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
+ }
+ wfProfileOut( $fname.'-immediate' );
+ wfProfileOut( $fname );
+ return $retVal;
+ }
+
# Work out link colour immediately
$aid = $nt->getArticleID() ;
if ( 0 == $aid ) {
$retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
} else {
$stub = false;
- if ( $nt->getNamespace() == NS_MAIN ) {
+ if ( $nt->isContentPage() ) {
$threshold = $wgUser->getOption('stubthreshold');
if ( $threshold > 0 ) {
$dbr = wfGetDB( DB_SLAVE );
$fname = 'Linker::makeBrokenLinkObj';
wfProfileIn( $fname );
- if ( '' == $query ) {
+ if( $nt->getNamespace() == NS_SPECIAL ) {
+ $q = $query;
+ } else if ( '' == $query ) {
$q = 'action=edit';
} else {
$q = 'action=edit&'.$query;
return $s;
}
- /** @todo document */
+ /** Creates the HTML source for images
+ * @param object $nt
+ * @param string $label label text
+ * @param string $alt alt text
+ * @param string $align horizontal alignment: none, left, center, right)
+ * @param array $params some format keywords: width, height, page, upright, upright_factor, frameless, border
+ * @param boolean $framed shows image in original size in a frame
+ * @param boolean $thumb shows image as thumbnail in a frame
+ * @param string $manual_thumb image name for the manual thumbnail
+ * @param string $valign vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom
+ * @return string
+ */
function makeImageLinkObj( $nt, $label, $alt, $align = '', $params = array(), $framed = false,
- $thumb = false, $manual_thumb = '', $valign = '' )
+ $thumb = false, $manual_thumb = '', $valign = '', $time = false )
{
- global $wgContLang, $wgUser, $wgThumbLimits;
+ global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright;
- $img = new Image( $nt );
+ $img = wfFindFile( $nt, $time );
- if ( !$img->allowInlineDisplay() && $img->exists() ) {
+ if ( $img && !$img->allowInlineDisplay() ) {
+ wfDebug( __METHOD__.': '.$nt->getPrefixedDBkey()." does not allow inline display\n" );
return $this->makeKnownLinkObj( $nt );
}
$postfix = '</div>';
$align = 'none';
}
-
- if ( !isset( $params['width'] ) ) {
+ if ( $img && !isset( $params['width'] ) ) {
$params['width'] = $img->getWidth( $page );
- if( $thumb || $framed ) {
+ if( $thumb || $framed || isset( $params['frameless'] ) ) {
$wopt = $wgUser->getOption( 'thumbsize' );
if( !isset( $wgThumbLimits[$wopt] ) ) {
$wopt = User::getDefaultOption( 'thumbsize' );
}
- $params['width'] = min( $params['width'], $wgThumbLimits[$wopt] );
+ // Reduce width for upright images when parameter 'upright' is used
+ if ( !isset( $params['upright_factor'] ) || $params['upright_factor'] == 0 ) {
+ $params['upright_factor'] = $wgThumbUpright;
+ }
+ // Use width which is smaller: real image width or user preference width
+ // For caching health: If width scaled down due to upright parameter, round to full __0 pixel to avoid the creation of a lot of odd thumbs
+ $params['width'] = min( $params['width'], isset( $params['upright'] ) ? round( $wgThumbLimits[$wopt] * $params['upright_factor'], -1 ) : $wgThumbLimits[$wopt] );
}
}
if ( $align == '' ) {
$align = $wgContLang->isRTL() ? 'left' : 'right';
}
- return $prefix.$this->makeThumbLinkObj( $img, $label, $alt, $align, $params, $framed, $manual_thumb ).$postfix;
+ return $prefix.$this->makeThumbLinkObj( $nt, $img, $label, $alt, $align, $params, $framed, $manual_thumb ).$postfix;
}
- if ( $params['width'] && $img->exists() ) {
+ if ( $img && $params['width'] ) {
# Create a resized image, without the additional thumbnail features
$thumb = $img->transform( $params );
} else {
'alt' => $alt,
'longdesc' => $u
);
+
if ( $valign ) {
$imgAttribs['style'] = "vertical-align: $valign";
}
+ if ( isset( $params['border'] ) ) {
+ $imgAttribs['class'] = "thumbborder";
+ }
$linkAttribs = array(
'href' => $u,
'class' => 'image',
);
if ( !$thumb ) {
- $s = $this->makeBrokenImageLinkObj( $img->getTitle() );
+ $s = $this->makeBrokenImageLinkObj( $nt );
} else {
$s = $thumb->toHtml( $imgAttribs, $linkAttribs );
}
/**
* Make HTML for a thumbnail including image, border and caption
- * $img is an Image object
+ * @param Title $nt
+ * @param Image $img Image object or false if it doesn't exist
*/
- function makeThumbLinkObj( $img, $label = '', $alt, $align = 'right', $params = array(), $framed=false , $manual_thumb = "" ) {
+ function makeThumbLinkObj( Title $nt, $img, $label = '', $alt, $align = 'right', $params = array(), $framed=false , $manual_thumb = "" ) {
global $wgStylePath, $wgContLang;
+ $exists = $img && $img->exists();
$page = isset( $params['page'] ) ? $params['page'] : false;
if ( empty( $params['width'] ) ) {
- $params['width'] = 180;
+ // Reduce width for upright images when parameter 'upright' is used
+ $params['width'] = isset( $params['upright'] ) ? 130 : 180;
}
$thumb = false;
- if ( $manual_thumb != '' ) {
- # Use manually specified thumbnail
- $manual_title = Title::makeTitleSafe( NS_IMAGE, $manual_thumb );
- if( $manual_title ) {
- $manual_img = new Image( $manual_title );
- $thumb = $manual_img->getUnscaledThumb();
- }
- } elseif ( $framed ) {
- // Use image dimensions, don't scale
- $thumb = $img->getUnscaledThumb( $page );
+
+ if ( !$exists ) {
+ $outerWidth = $params['width'] + 2;
} else {
- # Do not present an image bigger than the source, for bitmap-style images
- # This is a hack to maintain compatibility with arbitrary pre-1.10 behaviour
- $srcWidth = $img->getWidth( $page );
- if ( $srcWidth && !$img->mustRender() && $params['width'] > $srcWidth ) {
- $params['width'] = $srcWidth;
+ if ( $manual_thumb != '' ) {
+ # Use manually specified thumbnail
+ $manual_title = Title::makeTitleSafe( NS_IMAGE, $manual_thumb );
+ if( $manual_title ) {
+ $manual_img = wfFindFile( $manual_title );
+ if ( $manual_img ) {
+ $thumb = $manual_img->getUnscaledThumb();
+ } else {
+ $exists = false;
+ }
+ }
+ } elseif ( $framed ) {
+ // Use image dimensions, don't scale
+ $thumb = $img->getUnscaledThumb( $page );
+ } else {
+ # Do not present an image bigger than the source, for bitmap-style images
+ # This is a hack to maintain compatibility with arbitrary pre-1.10 behaviour
+ $srcWidth = $img->getWidth( $page );
+ if ( $srcWidth && !$img->mustRender() && $params['width'] > $srcWidth ) {
+ $params['width'] = $srcWidth;
+ }
+ $thumb = $img->transform( $params );
}
- $thumb = $img->transform( $params );
- }
- if ( $thumb ) {
- $outerWidth = $thumb->getWidth() + 2;
- } else {
- $outerWidth = $params['width'] + 2;
+ if ( $thumb ) {
+ $outerWidth = $thumb->getWidth() + 2;
+ } else {
+ $outerWidth = $params['width'] + 2;
+ }
}
$query = $page ? 'page=' . urlencode( $page ) : '';
- $u = $img->getTitle()->getLocalURL( $query );
+ $u = $nt->getLocalURL( $query );
$more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
$magnifyalign = $wgContLang->isRTL() ? 'left' : 'right';
$textalign = $wgContLang->isRTL() ? ' style="text-align:right"' : '';
$s = "<div class=\"thumb t{$align}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
- if ( !$thumb ) {
- $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
+ if( !$exists ) {
+ $s .= $this->makeBrokenImageLinkObj( $nt );
$zoomicon = '';
- } elseif( !$img->exists() ) {
- $s .= $this->makeBrokenImageLinkObj( $img->getTitle() );
+ } elseif ( !$thumb ) {
+ $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
$zoomicon = '';
} else {
$imgAttribs = array(
return $s;
}
- /** @todo document */
- function makeMediaLink( $name, /* wtf?! */ $url, $alt = '' ) {
+ /** @deprecated use Linker::makeMediaLinkObj() */
+ function makeMediaLink( $name, $unused = '', $text = '' ) {
$nt = Title::makeTitleSafe( NS_IMAGE, $name );
- return $this->makeMediaLinkObj( $nt, $alt );
+ return $this->makeMediaLinkObj( $nt, $text );
}
/**
### HOTFIX. Instead of breaking, return empty string.
return $text;
} else {
- $img = new Image( $title );
- if( $img->exists() ) {
+ $img = wfFindFile( $title );
+ if( $img ) {
$url = $img->getURL();
$class = 'internal';
} else {
$upload = SpecialPage::getTitleFor( 'Upload' );
- $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $img->getName() ) );
+ $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $title->getText() ) );
$class = 'new';
}
$alt = htmlspecialchars( $title->getText() );
function formatComment($comment, $title = NULL, $local = false) {
wfProfileIn( __METHOD__ );
- global $wgContLang;
+ # Sanitize text a bit:
$comment = str_replace( "\n", " ", $comment );
$comment = htmlspecialchars( $comment );
- # The pattern for autogen comments is / * foo * /, which makes for
- # some nasty regex.
- # We look for all comments, match any text before and after the comment,
- # add a separator where needed and format the comment itself with CSS
+ # Render autocomments and make links:
+ $comment = $this->formatAutoComments( $comment, $title, $local );
+ $comment = $this->formatLinksInComment( $comment );
+
+ wfProfileOut( __METHOD__ );
+ return $comment;
+ }
+
+ /**
+ * The pattern for autogen comments is / * foo * /, which makes for
+ * some nasty regex.
+ * We look for all comments, match any text before and after the comment,
+ * add a separator where needed and format the comment itself with CSS
+ * Called by Linker::formatComment.
+ *
+ * @param $comment Comment text
+ * @param $title An optional title object used to links to sections
+ *
+ * @todo Document the $local parameter.
+ */
+ private function formatAutocomments( $comment, $title = NULL, $local = false ) {
$match = array();
- while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
+ while (preg_match('!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment,$match)) {
$pre=$match[1];
$auto=$match[2];
$post=$match[3];
$comment=$pre.$auto.$post;
}
- # format regular and media links - all other wiki formatting
- # is ignored
+ return $comment;
+ }
+
+ /**
+ * Format regular and media links - all other wiki formatting is ignored
+ * Called by Linker::formatComment.
+ * @param $comment The comment text.
+ * @return Comment text with links using HTML.
+ */
+ private function formatLinksInComment( $comment ) {
+ global $wgContLang;
+
$medians = '(?:' . preg_quote( Namespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
$medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):';
+
while(preg_match('/\[\[:?(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
# Handle link renaming [[foo|text]] will show link as "text"
if( "" != $match[3] ) {
}
$comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
}
- wfProfileOut( __METHOD__ );
+
return $comment;
}
return " <span class=\"comment\">($formatted)</span>";
}
}
-
+
/**
* Wrap and format the given revision's comment block, if the current
* user is allowed to view it.