Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ThreadItemFormatter | |
0.00% |
0 / 14 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| makeLink | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| formatLine | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\DiscussionTools; |
| 4 | |
| 5 | use MediaWiki\Extension\DiscussionTools\ThreadItem\DatabaseThreadItem; |
| 6 | use MediaWiki\Language\MessageLocalizer; |
| 7 | use MediaWiki\Linker\LinkRenderer; |
| 8 | use MediaWiki\Title\TitleValue; |
| 9 | |
| 10 | /** |
| 11 | * Displays links to comments and headings represented as ThreadItems. |
| 12 | */ |
| 13 | class ThreadItemFormatter { |
| 14 | |
| 15 | public function __construct( |
| 16 | private readonly LinkRenderer $linkRenderer, |
| 17 | ) { |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Make a link to a thread item on the page. |
| 22 | */ |
| 23 | public function makeLink( DatabaseThreadItem $item, ?string $text = null ): string { |
| 24 | $title = TitleValue::newFromPage( $item->getPage() )->createFragmentTarget( $item->getId() ); |
| 25 | |
| 26 | $query = []; |
| 27 | if ( !$item->getRevision()->isCurrent() ) { |
| 28 | $query['oldid'] = $item->getRevision()->getId(); |
| 29 | } |
| 30 | |
| 31 | $link = $this->linkRenderer->makeLink( $title, $text, [], $query ); |
| 32 | |
| 33 | return $link; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Make a link to a thread item on the page, with additional information (used on special pages). |
| 38 | */ |
| 39 | public function formatLine( DatabaseThreadItem $item, MessageLocalizer $context ): string { |
| 40 | $contents = []; |
| 41 | |
| 42 | $contents[] = $this->makeLink( $item ); |
| 43 | |
| 44 | if ( !$item->getRevision()->isCurrent() ) { |
| 45 | $contents[] = $context->msg( 'discussiontools-findcomment-results-notcurrent' )->escaped(); |
| 46 | } |
| 47 | |
| 48 | if ( is_string( $item->getTranscludedFrom() ) ) { |
| 49 | $contents[] = $context->msg( 'discussiontools-findcomment-results-transcluded' )->escaped(); |
| 50 | } |
| 51 | |
| 52 | return implode( $context->msg( 'word-separator' )->escaped(), $contents ); |
| 53 | } |
| 54 | |
| 55 | } |