Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -504,6 +504,10 @@ |
505 | 505 | $url: string value as output (out parameter, can modify) |
506 | 506 | $query: query options passed to Title::getInternalURL() |
507 | 507 | |
| 508 | +'GetLinkColours': modify the CSS class of an array of page links |
| 509 | +$linkcolour_ids: array of prefixed DB keys of the pages linked to, indexed by page_id. |
| 510 | +&$colours: (output) array of CSS classes, indexed by prefixed DB keys |
| 511 | + |
508 | 512 | 'GetLocalURL': modify local URLs as output into page links |
509 | 513 | $title: Title object of page |
510 | 514 | $url: string value as output (out parameter, can modify) |
Index: trunk/phase3/includes/Linker.php |
— | — | @@ -52,19 +52,11 @@ |
53 | 53 | } |
54 | 54 | |
55 | 55 | /** @todo document */ |
56 | | - function getInternalLinkAttributes( $link, $text, $broken = false ) { |
| 56 | + function getInternalLinkAttributes( $link, $text, $class='' ) { |
57 | 57 | $link = urldecode( $link ); |
58 | 58 | $link = str_replace( '_', ' ', $link ); |
59 | 59 | $link = htmlspecialchars( $link ); |
60 | | - |
61 | | - if( $broken == 'stub' ) { |
62 | | - $r = ' class="stub"'; |
63 | | - } else if ( $broken == 'yes' ) { |
64 | | - $r = ' class="new"'; |
65 | | - } else { |
66 | | - $r = ''; |
67 | | - } |
68 | | - |
| 60 | + $r = ($class != '') ? ' class="' . htmlspecialchars( $class ) . '"' : ''; |
69 | 61 | $r .= " title=\"{$link}\""; |
70 | 62 | return $r; |
71 | 63 | } |
— | — | @@ -72,22 +64,35 @@ |
73 | 65 | /** |
74 | 66 | * @param $nt Title object. |
75 | 67 | * @param $text String: FIXME |
76 | | - * @param $broken Boolean: FIXME, default 'false'. |
| 68 | + * @param $class String: CSS class of the link, default ''. |
77 | 69 | */ |
78 | | - function getInternalLinkAttributesObj( &$nt, $text, $broken = false ) { |
79 | | - if( $broken == 'stub' ) { |
80 | | - $r = ' class="stub"'; |
81 | | - } else if ( $broken == 'yes' ) { |
82 | | - $r = ' class="new"'; |
83 | | - } else { |
84 | | - $r = ''; |
85 | | - } |
86 | | - |
| 70 | + function getInternalLinkAttributesObj( &$nt, $text, $class='' ) { |
| 71 | + $r = ($class != '') ? ' class="' . htmlspecialchars( $class ) . '"' : ''; |
87 | 72 | $r .= ' title="' . $nt->getEscapedText() . '"'; |
88 | 73 | return $r; |
89 | 74 | } |
90 | 75 | |
91 | 76 | /** |
| 77 | + * Return the CSS colour of a known link |
| 78 | + * |
| 79 | + * @param mixed $s |
| 80 | + * @param integer $id |
| 81 | + * @param integer $threshold |
| 82 | + */ |
| 83 | + function getLinkColour( $s, $threshold ) { |
| 84 | + if( $threshold > 0 && $s!=false ) { |
| 85 | + $colour = ( $s->page_len >= $threshold || |
| 86 | + $s->page_is_redirect || |
| 87 | + !Namespace::isContent( $s->page_namespace ) |
| 88 | + ? '' : 'stub' ); |
| 89 | + } |
| 90 | + else { |
| 91 | + $colour = ''; |
| 92 | + } |
| 93 | + return $colour; |
| 94 | + } |
| 95 | + |
| 96 | + /** |
92 | 97 | * This function is a shortcut to makeLinkObj(Title::newFromText($title),...). Do not call |
93 | 98 | * it if you already have a title object handy. See makeLinkObj for further documentation. |
94 | 99 | * |
— | — | @@ -155,6 +160,8 @@ |
156 | 161 | } |
157 | 162 | |
158 | 163 | /** |
| 164 | + * @deprecated use makeColouredLinkObj |
| 165 | + * |
159 | 166 | * This function is a shortcut to makeStubLinkObj(Title::newFromText($title),...). Do not call |
160 | 167 | * it if you already have a title object handy. See makeStubLinkObj for further documentation. |
161 | 168 | * |
— | — | @@ -240,7 +247,7 @@ |
241 | 248 | if ( 0 == $aid ) { |
242 | 249 | $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix ); |
243 | 250 | } else { |
244 | | - $stub = false; |
| 251 | + $colour = ''; |
245 | 252 | if ( $nt->isContentPage() ) { |
246 | 253 | $threshold = $wgUser->getOption('stubthreshold'); |
247 | 254 | if ( $threshold > 0 ) { |
— | — | @@ -250,15 +257,10 @@ |
251 | 258 | array( 'page_len', |
252 | 259 | 'page_is_redirect' ), |
253 | 260 | array( 'page_id' => $aid ), __METHOD__ ) ; |
254 | | - $stub = ( $s !== false && !$s->page_is_redirect && |
255 | | - $s->page_len < $threshold ); |
| 261 | + $colour=$this->getLinkColour( $s, $threshold ); |
256 | 262 | } |
257 | 263 | } |
258 | | - if ( $stub ) { |
259 | | - $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix ); |
260 | | - } else { |
261 | | - $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); |
262 | | - } |
| 264 | + $retVal = $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix ); |
263 | 265 | } |
264 | 266 | wfProfileOut( __METHOD__.'-immediate' ); |
265 | 267 | } |
— | — | @@ -345,7 +347,7 @@ |
346 | 348 | if ( '' == $text ) { |
347 | 349 | $text = htmlspecialchars( $nt->getPrefixedText() ); |
348 | 350 | } |
349 | | - $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" ); |
| 351 | + $style = $this->getInternalLinkAttributesObj( $nt, $text, 'new' ); |
350 | 352 | |
351 | 353 | list( $inside, $trail ) = Linker::splitTrail( $trail ); |
352 | 354 | $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}"; |
— | — | @@ -355,6 +357,8 @@ |
356 | 358 | } |
357 | 359 | |
358 | 360 | /** |
| 361 | + * @deprecated use makeColouredLinkObj |
| 362 | + * |
359 | 363 | * Make a brown link to a short article. |
360 | 364 | * |
361 | 365 | * @param $title String: the text of the title |
— | — | @@ -365,7 +369,25 @@ |
366 | 370 | * the end of the link. |
367 | 371 | */ |
368 | 372 | function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { |
369 | | - $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' ); |
| 373 | + makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix ); |
| 374 | + } |
| 375 | + |
| 376 | + /** |
| 377 | + * Make a coloured link. |
| 378 | + * |
| 379 | + * @param $title String: the text of the title |
| 380 | + * @param $colour Integer: colour of the link |
| 381 | + * @param $text String: link text |
| 382 | + * @param $query String: optional query part |
| 383 | + * @param $trail String: optional trail. Alphabetic characters at the start of this string will |
| 384 | + * be included in the link text. Other characters will be appended after |
| 385 | + * the end of the link. |
| 386 | + */ |
| 387 | + function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) { |
| 388 | + |
| 389 | + if($colour != ''){ |
| 390 | + $style = $this->getInternalLinkAttributesObj( $nt, $text, $colour ); |
| 391 | + } else $style = ''; |
370 | 392 | return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style ); |
371 | 393 | } |
372 | 394 | |
— | — | @@ -384,11 +406,8 @@ |
385 | 407 | function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { |
386 | 408 | global $wgUser; |
387 | 409 | $threshold = intval( $wgUser->getOption( 'stubthreshold' ) ); |
388 | | - if( $size < $threshold ) { |
389 | | - return $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix ); |
390 | | - } else { |
391 | | - return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); |
392 | | - } |
| 410 | + $colour = ( $size < $threshold ) ? 'stub' : ''; |
| 411 | + return $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix ); |
393 | 412 | } |
394 | 413 | |
395 | 414 | /** |
— | — | @@ -709,7 +728,7 @@ |
710 | 729 | if( $query != '' ) |
711 | 730 | $q .= '&' . $query; |
712 | 731 | list( $inside, $trail ) = self::splitTrail( $trail ); |
713 | | - $style = $this->getInternalLinkAttributesObj( $title, $text, 'yes' ); |
| 732 | + $style = $this->getInternalLinkAttributesObj( $title, $text, 'new' ); |
714 | 733 | wfProfileOut( __METHOD__ ); |
715 | 734 | return '<a href="' . $upload->escapeLocalUrl( $q ) . '"' |
716 | 735 | . $style . '>' . $prefix . $text . $inside . '</a>' . $trail; |
Index: trunk/phase3/includes/Parser.php |
— | — | @@ -4315,10 +4315,7 @@ |
4316 | 4316 | /** |
4317 | 4317 | * Replace <!--LINK--> link placeholders with actual links, in the buffer |
4318 | 4318 | * Placeholders created in Skin::makeLinkObj() |
4319 | | - * Returns an array of links found, indexed by PDBK: |
4320 | | - * 0 - broken |
4321 | | - * 1 - normal link |
4322 | | - * 2 - stub |
| 4319 | + * Returns an array of link CSS classes, indexed by PDBK. |
4323 | 4320 | * $options is a bit field, RLH_FOR_UPDATE to select for update |
4324 | 4321 | */ |
4325 | 4322 | function replaceLinkHolders( &$text, $options = 0 ) { |
— | — | @@ -4330,6 +4327,7 @@ |
4331 | 4328 | |
4332 | 4329 | $pdbks = array(); |
4333 | 4330 | $colours = array(); |
| 4331 | + $linkcolour_ids = array(); |
4334 | 4332 | $sk = $this->mOptions->getSkin(); |
4335 | 4333 | $linkCache =& LinkCache::singleton(); |
4336 | 4334 | |
— | — | @@ -4358,14 +4356,14 @@ |
4359 | 4357 | |
4360 | 4358 | # Check if it's a static known link, e.g. interwiki |
4361 | 4359 | if ( $title->isAlwaysKnown() ) { |
4362 | | - $colours[$pdbk] = 1; |
| 4360 | + $colours[$pdbk] = ''; |
4363 | 4361 | } elseif ( ( $id = $linkCache->getGoodLinkID( $pdbk ) ) != 0 ) { |
4364 | | - $colours[$pdbk] = 1; |
| 4362 | + $colours[$pdbk] = ''; |
4365 | 4363 | $this->mOutput->addLink( $title, $id ); |
4366 | 4364 | } elseif ( $linkCache->isBadLink( $pdbk ) ) { |
4367 | | - $colours[$pdbk] = 0; |
| 4365 | + $colours[$pdbk] = 'new'; |
4368 | 4366 | } elseif ( $title->getNamespace() == NS_SPECIAL && !SpecialPage::exists( $pdbk ) ) { |
4369 | | - $colours[$pdbk] = 0; |
| 4367 | + $colours[$pdbk] = 'new'; |
4370 | 4368 | } else { |
4371 | 4369 | # Not in the link cache, add it to the query |
4372 | 4370 | if ( !isset( $current ) ) { |
— | — | @@ -4395,20 +4393,17 @@ |
4396 | 4394 | |
4397 | 4395 | # Fetch data and form into an associative array |
4398 | 4396 | # non-existent = broken |
4399 | | - # 1 = known |
4400 | | - # 2 = stub |
4401 | 4397 | while ( $s = $dbr->fetchObject($res) ) { |
4402 | 4398 | $title = Title::makeTitle( $s->page_namespace, $s->page_title ); |
4403 | 4399 | $pdbk = $title->getPrefixedDBkey(); |
4404 | 4400 | $linkCache->addGoodLinkObj( $s->page_id, $title ); |
4405 | 4401 | $this->mOutput->addLink( $title, $s->page_id ); |
4406 | | - |
4407 | | - $colours[$pdbk] = ( $threshold == 0 || ( |
4408 | | - $s->page_len >= $threshold || # always true if $threshold <= 0 |
4409 | | - $s->page_is_redirect || |
4410 | | - !Namespace::isContent( $s->page_namespace ) ) |
4411 | | - ? 1 : 2 ); |
| 4402 | + $colours[$pdbk] = $sk->getLinkColour( $s, $threshold ); |
| 4403 | + //add id to the extension todolist |
| 4404 | + $linkcolour_ids[$s->page_id] = $pdbk; |
4412 | 4405 | } |
| 4406 | + //pass an array of page_ids to an extension |
| 4407 | + wfRunHooks( 'GetLinkColours', array( $linkcolour_ids, &$colours ) ); |
4413 | 4408 | } |
4414 | 4409 | wfProfileOut( $fname.'-check' ); |
4415 | 4410 | |
— | — | @@ -4504,18 +4499,10 @@ |
4505 | 4500 | |
4506 | 4501 | // set pdbk and colour |
4507 | 4502 | $pdbks[$key] = $varPdbk; |
4508 | | - if ( $threshold > 0 ) { |
4509 | | - $size = $s->page_len; |
4510 | | - if ( $s->page_is_redirect || $s->page_namespace != 0 || $size >= $threshold ) { |
4511 | | - $colours[$varPdbk] = 1; |
4512 | | - } else { |
4513 | | - $colours[$varPdbk] = 2; |
4514 | | - } |
4515 | | - } |
4516 | | - else { |
4517 | | - $colours[$varPdbk] = 1; |
4518 | | - } |
| 4503 | + $colours[$varPdbk] = $sk->getLinkColour( $s, $threshold ); |
| 4504 | + $linkcolour_ids[$s->page_id] = $pdbk; |
4519 | 4505 | } |
| 4506 | + wfRunHooks( 'GetLinkColours', array( $linkcolour_ids, &$colours ) ); |
4520 | 4507 | } |
4521 | 4508 | |
4522 | 4509 | // check if the object is a variant of a category |
— | — | @@ -4548,21 +4535,17 @@ |
4549 | 4536 | $pdbk = $pdbks[$key]; |
4550 | 4537 | $searchkey = "<!--LINK $key-->"; |
4551 | 4538 | $title = $this->mLinkHolders['titles'][$key]; |
4552 | | - if ( empty( $colours[$pdbk] ) ) { |
| 4539 | + if ( !isset( $colours[$pdbk] ) ) { |
4553 | 4540 | $linkCache->addBadLinkObj( $title ); |
4554 | | - $colours[$pdbk] = 0; |
| 4541 | + $colours[$pdbk] = 'new'; |
4555 | 4542 | $this->mOutput->addLink( $title, 0 ); |
4556 | 4543 | $replacePairs[$searchkey] = $sk->makeBrokenLinkObj( $title, |
4557 | 4544 | $this->mLinkHolders['texts'][$key], |
4558 | 4545 | $this->mLinkHolders['queries'][$key] ); |
4559 | | - } elseif ( $colours[$pdbk] == 1 ) { |
4560 | | - $replacePairs[$searchkey] = $sk->makeKnownLinkObj( $title, |
| 4546 | + } else { |
| 4547 | + $replacePairs[$searchkey] = $sk->makeColouredLinkObj( $title, $colours[$pdbk], |
4561 | 4548 | $this->mLinkHolders['texts'][$key], |
4562 | 4549 | $this->mLinkHolders['queries'][$key] ); |
4563 | | - } elseif ( $colours[$pdbk] == 2 ) { |
4564 | | - $replacePairs[$searchkey] = $sk->makeStubLinkObj( $title, |
4565 | | - $this->mLinkHolders['texts'][$key], |
4566 | | - $this->mLinkHolders['queries'][$key] ); |
4567 | 4550 | } |
4568 | 4551 | } |
4569 | 4552 | $replacer = new HashtableReplacer( $replacePairs, 1 ); |