| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\DiscussionTools; |
| 4 |
|
| 5 |
use MediaWiki\SpecialPage\RedirectSpecialPage; |
| 6 |
use MediaWiki\SpecialPage\SpecialPage; |
| 7 |
use MediaWiki\Title\Title; |
| 8 |
|
| 9 |
class SpecialGoToComment extends RedirectSpecialPage { |
| 10 |
|
| 11 |
private ThreadItemStore $threadItemStore; |
| 12 |
|
| 13 |
public function __construct( |
| 14 |
ThreadItemStore $threadItemStore |
| 15 |
) { |
| 16 |
parent::__construct( 'GoToComment' ); |
| 17 |
$this->threadItemStore = $threadItemStore; |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
public function getRedirect( $subpage ) { |
| 24 |
$results = []; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
if ( $subpage ) { |
| 33 |
$threadItems = $this->threadItemStore->findNewestRevisionsById( $subpage ); |
| 34 |
foreach ( $threadItems as $item ) { |
| 35 |
if ( $item->isCanonicalPermalink() ) { |
| 36 |
$results[] = $item; |
| 37 |
} |
| 38 |
} |
| 39 |
$threadItems = $this->threadItemStore->findNewestRevisionsByName( $subpage ); |
| 40 |
foreach ( $threadItems as $item ) { |
| 41 |
if ( $item->isCanonicalPermalink() ) { |
| 42 |
$results[] = $item; |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
if ( count( $results ) === 1 ) { |
| 48 |
return Title::castFromPageIdentity( $results[0]->getPage() )->createFragmentTarget( $results[0]->getId() ); |
| 49 |
} else { |
| 50 |
return SpecialPage::getTitleFor( 'FindComment', $subpage ?: false ); |
| 51 |
} |
| 52 |
} |
| 53 |
} |