Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| SpecialGoToComment | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRedirect | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
72 | |||
| 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 | public function __construct( |
| 12 | private readonly ThreadItemStore $threadItemStore, |
| 13 | ) { |
| 14 | parent::__construct( 'GoToComment' ); |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * @inheritDoc |
| 19 | */ |
| 20 | public function getRedirect( $subpage ) { |
| 21 | $results = []; |
| 22 | |
| 23 | // Search for all thread items with the given ID or name, returning results from the latest |
| 24 | // revision of each page they appeared on. |
| 25 | // |
| 26 | // If there is exactly one good result (see isCanonicalPermalink()), redirect to it. |
| 27 | // Otherwise, redirect to full search results on Special:FindComment. |
| 28 | |
| 29 | if ( $subpage ) { |
| 30 | $threadItems = $this->threadItemStore->findNewestRevisionsById( $subpage ); |
| 31 | foreach ( $threadItems as $item ) { |
| 32 | if ( $item->isCanonicalPermalink() ) { |
| 33 | $results[] = $item; |
| 34 | } |
| 35 | } |
| 36 | $threadItems = $this->threadItemStore->findNewestRevisionsByName( $subpage ); |
| 37 | foreach ( $threadItems as $item ) { |
| 38 | if ( $item->isCanonicalPermalink() ) { |
| 39 | $results[] = $item; |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | if ( count( $results ) === 1 ) { |
| 45 | return Title::castFromPageIdentity( $results[0]->getPage() )->createFragmentTarget( $results[0]->getId() ); |
| 46 | } else { |
| 47 | return SpecialPage::getTitleFor( 'FindComment', $subpage ?: false ); |
| 48 | } |
| 49 | } |
| 50 | } |