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