Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
SpecialGoToComment | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
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 | private ThreadItemStore $threadItemStore; |
12 | |
13 | public function __construct( |
14 | ThreadItemStore $threadItemStore |
15 | ) { |
16 | parent::__construct( 'GoToComment' ); |
17 | $this->threadItemStore = $threadItemStore; |
18 | } |
19 | |
20 | /** |
21 | * @inheritDoc |
22 | */ |
23 | public function getRedirect( $subpage ) { |
24 | $results = []; |
25 | |
26 | // Search for all thread items with the given ID or name, returning results from the latest |
27 | // revision of each page they appeared on. |
28 | // |
29 | // If there is exactly one good result (see isCanonicalPermalink()), redirect to it. |
30 | // Otherwise, redirect to full search results on Special:FindComment. |
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 | } |