linktrail = $wgContLang->linkTrail();
# Cache option lookups done very frequently
$options = array( 'highlightbroken', 'hover' );
foreach( $options as $opt ) {
global $wgUser;
$this->mOptions[$opt] = $wgUser->getOption( $opt );
}
}
/**
* Get/set accessor for delayed link colouring
*/
function postParseLinkColour( $setting = NULL ) {
return wfSetVar( $this->postParseLinkColour, $setting );
}
function getExternalLinkAttributes( $link, $text, $class='' ) {
global $wgContLang;
$same = ($link == $text);
$link = urldecode( $link );
$link = $wgContLang->checkTitleEncoding( $link );
$link = preg_replace( '/[\\x00-\\x1f_]/', ' ', $link );
$link = htmlspecialchars( $link );
$r = ($class != '') ? " class='$class'" : " class='external'";
if( !$same && $this->mOptions['hover'] ) {
$r .= " title=\"{$link}\"";
}
return $r;
}
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 = '';
}
if( $this->mOptions['hover'] ) {
$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 = '';
}
if( $this->mOptions['hover'] ) {
$r .= ' title="' . $nt->getEscapedText() . '"';
}
return $r;
}
/**
* Note: This function MUST call getArticleID() on the link,
* otherwise the cache won't get updated properly. See LINKCACHE.DOC.
*/
function makeLink( $title, $text = '', $query = '', $trail = '' ) {
wfProfileIn( 'Skin::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" );
$result = $text == "" ? $title : $text;
}
wfProfileOut( 'Skin::makeLink' );
return $result;
}
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 Skin::makeKnownLink(): "'.$title."\"\n" );
return $text == '' ? $title : $text;
}
}
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 Skin::makeBrokenLink(): "'.$title."\"\n" );
return $text == '' ? $title : $text;
}
}
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 Skin::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, $wgLinkHolders;
$fname = 'Skin::makeLinkObj';
wfProfileIn( $fname );
# Fail gracefully
if ( ! isset($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];
}
}
$t = "{$text}{$inside}";
if( $this->postParseLinkColour ) {
# There's no existence check, but this will prevent
# interwiki links from being parsed as external links.
global $wgInterwikiLinkHolders;
$nr = array_push($wgInterwikiLinkHolders, $t);
$retVal = '{$trail}";
} else {
return $t;
}
} elseif ( 0 == $ns && "" == $dbkey ) {
# A self-link with a fragment; skip existence check.
$retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
} elseif ( ( NS_SPECIAL == $ns ) || ( NS_IMAGE == $ns ) ) {
# These are always shown as existing, currently.
# Special pages don't exist in the database; images may
# occasionally be present when there is no description
# page per se, so we always shown them.
$retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
} elseif ( $this->postParseLinkColour ) {
wfProfileIn( $fname.'-postparse' );
# Insert a placeholder, and we'll work out the existence checks
# in a big lump later.
$inside = '';
if ( '' != $trail ) {
if ( preg_match( $this->linktrail, $trail, $m ) ) {
$inside = $m[1];
$trail = $m[2];
}
}
# These get picked up by Parser::replaceLinkHolders()
$nr = array_push( $wgLinkHolders['namespaces'], $nt->getNamespace() );
$wgLinkHolders['dbkeys'][] = $dbkey;
$wgLinkHolders['queries'][] = $query;
$wgLinkHolders['texts'][] = $prefix.$text.$inside;
$wgLinkHolders['titles'][] =& $nt;
$retVal = '{$trail}";
wfProfileOut( $fname.'-postparse' );
} 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( 'cur', array( 'LENGTH(cur_text) AS x', 'cur_namespace',
'cur_is_redirect' ), array( 'cur_id' => $aid ), $fname ) ;
if ( $s !== false ) {
$size = $s->x;
if ( $s->cur_is_redirect OR $s->cur_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;
}
/**
* Pass a title object, not a title string
*/
function makeKnownLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '' ) {
global $wgOut, $wgTitle, $wgInputEncoding;
$fname = 'Skin::makeKnownLinkObj';
wfProfileIn( $fname );
if ( !is_object( $nt ) ) {
wfProfileIn( $fname );
return $text;
}
$u = $nt->escapeLocalURL( $query );
if ( '' != $nt->getFragment() ) {
if( $nt->getPrefixedDbkey() == '' ) {
$u = '';
if ( '' == $text ) {
$text = htmlspecialchars( $nt->getFragment() );
}
}
$anchor = urlencode( do_html_entity_decode( str_replace(' ', '_', $nt->getFragment()), ENT_COMPAT, $wgInputEncoding ) );
$replacearray = array(
'%3A' => ':',
'%' => '.'
);
$u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor);
}
if ( '' == $text ) {
$text = htmlspecialchars( $nt->getPrefixedText() );
}
$style = $this->getInternalLinkAttributesObj( $nt, $text );
$inside = '';
if ( '' != $trail ) {
if ( preg_match( $this->linktrail, $trail, $m ) ) {
$inside = $m[1];
$trail = $m[2];
}
}
$r = "{$prefix}{$text}{$inside}{$trail}";
wfProfileOut( $fname );
return $r;
}
/**
* Pass a title object, not a title string
*/
function makeBrokenLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
# Fail gracefully
if ( ! isset($nt) ) {
# wfDebugDieBacktrace();
return "{$prefix}{$text}{$trail}";
}
$fname = 'Skin::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" );
$inside = '';
if ( '' != $trail ) {
if ( preg_match( $this->linktrail, $trail, $m ) ) {
$inside = $m[1];
$trail = $m[2];
}
}
if ( $this->mOptions['highlightbroken'] ) {
$s = "{$prefix}{$text}{$inside}{$trail}";
} else {
$s = "{$prefix}{$text}{$inside}?{$trail}";
}
wfProfileOut( $fname );
return $s;
}
/**
* Pass a title object, not a title string
*/
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' );
$inside = '';
if ( '' != $trail ) {
if ( preg_match( $this->linktrail, $trail, $m ) ) {
$inside = $m[1];
$trail = $m[2];
}
}
if ( $this->mOptions['highlightbroken'] ) {
$s = "{$prefix}{$text}{$inside}{$trail}";
} else {
$s = "{$prefix}{$text}{$inside}!{$trail}";
}
return $s;
}
function makeSelfLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
$u = $nt->escapeLocalURL( $query );
if ( '' == $text ) {
$text = htmlspecialchars( $nt->getPrefixedText() );
}
$inside = '';
if ( '' != $trail ) {
if ( preg_match( $this->linktrail, $trail, $m ) ) {
$inside = $m[1];
$trail = $m[2];
}
}
return "{$prefix}{$text}{$inside}{$trail}";
}
function fnamePart( $url ) {
$basename = strrchr( $url, '/' );
if ( false === $basename ) {
$basename = $url;
} else {
$basename = substr( $basename, 1 );
}
return htmlspecialchars( $basename );
}
function makeImage( $url, $alt = '' ) {
global $wgOut;
if ( '' == $alt ) {
$alt = $this->fnamePart( $url );
}
$s = '';
return $s;
}
function makeImageLink( $name, $url, $alt = '' ) {
$nt = Title::makeTitleSafe( NS_IMAGE, $name );
return $this->makeImageLinkObj( $nt, $alt );
}
function makeImageLinkObj( $nt, $alt = '' ) {
global $wgContLang, $wgUseImageResize;
$img = Image::newFromTitle( $nt );
$url = $img->getViewURL();
$align = '';
$prefix = $postfix = '';
# Check if the alt text is of the form "options|alt text"
# Options are:
# * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
# * left no resizing, just left align. label is used for alt= only
# * right same, but right aligned
# * none same, but not aligned
# * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
# * center center the image
# * framed Keep original image size, no magnify-button.
$part = explode( '|', $alt);
$mwThumb =& MagicWord::get( MAG_IMG_THUMBNAIL );
$mwLeft =& MagicWord::get( MAG_IMG_LEFT );
$mwRight =& MagicWord::get( MAG_IMG_RIGHT );
$mwNone =& MagicWord::get( MAG_IMG_NONE );
$mwWidth =& MagicWord::get( MAG_IMG_WIDTH );
$mwCenter =& MagicWord::get( MAG_IMG_CENTER );
$mwFramed =& MagicWord::get( MAG_IMG_FRAMED );
$alt = '';
$height = $framed = $thumb = false;
$manual_thumb = "" ;
foreach( $part as $key => $val ) {
$val_parts = explode ( "=" , $val , 2 ) ;
$left_part = array_shift ( $val_parts ) ;
if ( $wgUseImageResize && ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
$thumb=true;
} elseif ( $wgUseImageResize && count ( $val_parts ) == 1 && ! is_null( $mwThumb->matchVariableStartToEnd($left_part) ) ) {
# use manually specified thumbnail
$thumb=true;
$manual_thumb = array_shift ( $val_parts ) ;
} elseif ( ! is_null( $mwRight->matchVariableStartToEnd($val) ) ) {
# remember to set an alignment, don't render immediately
$align = 'right';
} elseif ( ! is_null( $mwLeft->matchVariableStartToEnd($val) ) ) {
# remember to set an alignment, don't render immediately
$align = 'left';
} elseif ( ! is_null( $mwCenter->matchVariableStartToEnd($val) ) ) {
# remember to set an alignment, don't render immediately
$align = 'center';
} elseif ( ! is_null( $mwNone->matchVariableStartToEnd($val) ) ) {
# remember to set an alignment, don't render immediately
$align = 'none';
} elseif ( $wgUseImageResize && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
# $match is the image width in pixels
if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
$width = intval( $m[1] );
$height = intval( $m[2] );
} else {
$width = intval($match);
}
} elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
$framed=true;
} else {
$alt = $val;
}
}
if ( 'center' == $align )
{
$prefix = '
'."\n". ''.wfMsgForContent('toc').'' . $hideline . ' |
'."\n". $toc." |