| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\DiscussionTools; |
| 4 |
|
| 5 |
use MediaWiki\Extension\DiscussionTools\ThreadItem\DatabaseThreadItem; |
| 6 |
use MediaWiki\Linker\LinkRenderer; |
| 7 |
use MediaWiki\Title\TitleValue; |
| 8 |
use MessageLocalizer; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class ThreadItemFormatter { |
| 14 |
|
| 15 |
private LinkRenderer $linkRenderer; |
| 16 |
|
| 17 |
public function __construct( |
| 18 |
LinkRenderer $linkRenderer |
| 19 |
) { |
| 20 |
$this->linkRenderer = $linkRenderer; |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public function makeLink( DatabaseThreadItem $item, ?string $text = null ): string { |
| 27 |
$title = TitleValue::newFromPage( $item->getPage() )->createFragmentTarget( $item->getId() ); |
| 28 |
|
| 29 |
$query = []; |
| 30 |
if ( !$item->getRevision()->isCurrent() ) { |
| 31 |
$query['oldid'] = $item->getRevision()->getId(); |
| 32 |
} |
| 33 |
|
| 34 |
$link = $this->linkRenderer->makeLink( $title, $text, [], $query ); |
| 35 |
|
| 36 |
return $link; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public function formatLine( DatabaseThreadItem $item, MessageLocalizer $context ): string { |
| 43 |
$contents = []; |
| 44 |
|
| 45 |
$contents[] = $this->makeLink( $item ); |
| 46 |
|
| 47 |
if ( !$item->getRevision()->isCurrent() ) { |
| 48 |
$contents[] = $context->msg( 'discussiontools-findcomment-results-notcurrent' )->escaped(); |
| 49 |
} |
| 50 |
|
| 51 |
if ( is_string( $item->getTranscludedFrom() ) ) { |
| 52 |
$contents[] = $context->msg( 'discussiontools-findcomment-results-transcluded' )->escaped(); |
| 53 |
} |
| 54 |
|
| 55 |
return implode( $context->msg( 'word-separator' )->escaped(), $contents ); |
| 56 |
} |
| 57 |
|
| 58 |
} |