}
/** @todo document */
- function getInternalLinkAttributes( $link, $text, $broken = false ) {
+ function getInternalLinkAttributes( $link, $text, $class='' ) {
$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 = ($class != '') ? ' class="' . htmlspecialchars( $class ) . '"' : '';
$r .= " title=\"{$link}\"";
return $r;
}
/**
* @param $nt Title object.
* @param $text String: FIXME
- * @param $broken Boolean: FIXME, default 'false'.
+ * @param $class String: CSS class of the link, default ''.
*/
- function getInternalLinkAttributesObj( &$nt, $text, $broken = false ) {
- if( $broken == 'stub' ) {
- $r = ' class="stub"';
- } else if ( $broken == 'yes' ) {
- $r = ' class="new"';
- } else {
- $r = '';
- }
-
+ function getInternalLinkAttributesObj( &$nt, $text, $class='' ) {
+ $r = ($class != '') ? ' class="' . htmlspecialchars( $class ) . '"' : '';
$r .= ' title="' . $nt->getEscapedText() . '"';
return $r;
}
+ /**
+ * Return the CSS colour of a known link
+ *
+ * @param mixed $s
+ * @param integer $id
+ * @param integer $threshold
+ */
+ function getLinkColour( $s, $threshold ) {
+ if( $threshold > 0 && $s!=false ) {
+ $colour = ( $s->page_len >= $threshold ||
+ $s->page_is_redirect ||
+ !Namespace::isContent( $s->page_namespace )
+ ? '' : 'stub' );
+ }
+ else {
+ $colour = '';
+ }
+ return $colour;
+ }
+
/**
* 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.
}
/**
+ * @deprecated use makeColouredLinkObj
+ *
* 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.
*
if ( 0 == $aid ) {
$retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
} else {
- $stub = false;
+ $colour = '';
if ( $nt->isContentPage() ) {
$threshold = $wgUser->getOption('stubthreshold');
if ( $threshold > 0 ) {
array( 'page_len',
'page_is_redirect' ),
array( 'page_id' => $aid ), __METHOD__ ) ;
- $stub = ( $s !== false && !$s->page_is_redirect &&
- $s->page_len < $threshold );
+ $colour=$this->getLinkColour( $s, $threshold );
}
}
- if ( $stub ) {
- $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
- } else {
- $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
- }
+ $retVal = $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
}
wfProfileOut( __METHOD__.'-immediate' );
}
if ( '' == $text ) {
$text = htmlspecialchars( $nt->getPrefixedText() );
}
- $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
+ $style = $this->getInternalLinkAttributesObj( $nt, $text, 'new' );
list( $inside, $trail ) = Linker::splitTrail( $trail );
$s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
}
/**
+ * @deprecated use makeColouredLinkObj
+ *
* Make a brown link to a short article.
*
* @param $title String: the text of the title
* the end of the link.
*/
function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
- $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' );
+ makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix );
+ }
+
+ /**
+ * Make a coloured link.
+ *
+ * @param $title String: the text of the title
+ * @param $colour Integer: colour of the link
+ * @param $text String: link text
+ * @param $query String: optional query part
+ * @param $trail String: 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 makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
+
+ if($colour != ''){
+ $style = $this->getInternalLinkAttributesObj( $nt, $text, $colour );
+ } else $style = '';
return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
}
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 );
- }
+ $colour = ( $size < $threshold ) ? 'stub' : '';
+ return $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
}
/**
if( $query != '' )
$q .= '&' . $query;
list( $inside, $trail ) = self::splitTrail( $trail );
- $style = $this->getInternalLinkAttributesObj( $title, $text, 'yes' );
+ $style = $this->getInternalLinkAttributesObj( $title, $text, 'new' );
wfProfileOut( __METHOD__ );
return '<a href="' . $upload->escapeLocalUrl( $q ) . '"'
. $style . '>' . $prefix . $text . $inside . '</a>' . $trail;
/**
* Replace <!--LINK--> link placeholders with actual links, in the buffer
* Placeholders created in Skin::makeLinkObj()
- * Returns an array of links found, indexed by PDBK:
- * 0 - broken
- * 1 - normal link
- * 2 - stub
+ * Returns an array of link CSS classes, indexed by PDBK.
* $options is a bit field, RLH_FOR_UPDATE to select for update
*/
function replaceLinkHolders( &$text, $options = 0 ) {
$pdbks = array();
$colours = array();
+ $linkcolour_ids = array();
$sk = $this->mOptions->getSkin();
$linkCache =& LinkCache::singleton();
# Check if it's a static known link, e.g. interwiki
if ( $title->isAlwaysKnown() ) {
- $colours[$pdbk] = 1;
+ $colours[$pdbk] = '';
} elseif ( ( $id = $linkCache->getGoodLinkID( $pdbk ) ) != 0 ) {
- $colours[$pdbk] = 1;
+ $colours[$pdbk] = '';
$this->mOutput->addLink( $title, $id );
} elseif ( $linkCache->isBadLink( $pdbk ) ) {
- $colours[$pdbk] = 0;
+ $colours[$pdbk] = 'new';
} elseif ( $title->getNamespace() == NS_SPECIAL && !SpecialPage::exists( $pdbk ) ) {
- $colours[$pdbk] = 0;
+ $colours[$pdbk] = 'new';
} else {
# Not in the link cache, add it to the query
if ( !isset( $current ) ) {
# Fetch data and form into an associative array
# non-existent = broken
- # 1 = known
- # 2 = stub
while ( $s = $dbr->fetchObject($res) ) {
$title = Title::makeTitle( $s->page_namespace, $s->page_title );
$pdbk = $title->getPrefixedDBkey();
$linkCache->addGoodLinkObj( $s->page_id, $title );
$this->mOutput->addLink( $title, $s->page_id );
-
- $colours[$pdbk] = ( $threshold == 0 || (
- $s->page_len >= $threshold || # always true if $threshold <= 0
- $s->page_is_redirect ||
- !Namespace::isContent( $s->page_namespace ) )
- ? 1 : 2 );
+ $colours[$pdbk] = $sk->getLinkColour( $s, $threshold );
+ //add id to the extension todolist
+ $linkcolour_ids[$s->page_id] = $pdbk;
}
+ //pass an array of page_ids to an extension
+ wfRunHooks( 'GetLinkColours', array( $linkcolour_ids, &$colours ) );
}
wfProfileOut( $fname.'-check' );
// set pdbk and colour
$pdbks[$key] = $varPdbk;
- if ( $threshold > 0 ) {
- $size = $s->page_len;
- if ( $s->page_is_redirect || $s->page_namespace != 0 || $size >= $threshold ) {
- $colours[$varPdbk] = 1;
- } else {
- $colours[$varPdbk] = 2;
- }
- }
- else {
- $colours[$varPdbk] = 1;
- }
+ $colours[$varPdbk] = $sk->getLinkColour( $s, $threshold );
+ $linkcolour_ids[$s->page_id] = $pdbk;
}
+ wfRunHooks( 'GetLinkColours', array( $linkcolour_ids, &$colours ) );
}
// check if the object is a variant of a category
$pdbk = $pdbks[$key];
$searchkey = "<!--LINK $key-->";
$title = $this->mLinkHolders['titles'][$key];
- if ( empty( $colours[$pdbk] ) ) {
+ if ( !isset( $colours[$pdbk] ) ) {
$linkCache->addBadLinkObj( $title );
- $colours[$pdbk] = 0;
+ $colours[$pdbk] = 'new';
$this->mOutput->addLink( $title, 0 );
$replacePairs[$searchkey] = $sk->makeBrokenLinkObj( $title,
$this->mLinkHolders['texts'][$key],
$this->mLinkHolders['queries'][$key] );
- } elseif ( $colours[$pdbk] == 1 ) {
- $replacePairs[$searchkey] = $sk->makeKnownLinkObj( $title,
- $this->mLinkHolders['texts'][$key],
- $this->mLinkHolders['queries'][$key] );
- } elseif ( $colours[$pdbk] == 2 ) {
- $replacePairs[$searchkey] = $sk->makeStubLinkObj( $title,
+ } else {
+ $replacePairs[$searchkey] = $sk->makeColouredLinkObj( $title, $colours[$pdbk],
$this->mLinkHolders['texts'][$key],
$this->mLinkHolders['queries'][$key] );
}