Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
ViewAction | |
0.00% |
0 / 22 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
doesWrites | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
showForAction | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getCategories | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace Flow\Actions; |
4 | |
5 | use Article; |
6 | use MediaWiki\Context\IContextSource; |
7 | use MediaWiki\MediaWikiServices; |
8 | use MediaWiki\Output\OutputPage; |
9 | use MediaWiki\Title\Title; |
10 | |
11 | class ViewAction extends FlowAction { |
12 | |
13 | /** |
14 | * @param Article $article |
15 | * @param IContextSource $context |
16 | */ |
17 | public function __construct( Article $article, IContextSource $context ) { |
18 | parent::__construct( $article, $context, 'view' ); |
19 | } |
20 | |
21 | public function doesWrites() { |
22 | return false; |
23 | } |
24 | |
25 | public function showForAction( $action, ?OutputPage $output = null ) { |
26 | parent::showForAction( $action, $output ); |
27 | |
28 | $title = $this->context->getTitle(); |
29 | $watchlistManager = MediaWikiServices::getInstance()->getWatchlistManager(); |
30 | $watchlistManager->clearTitleUserNotifications( $this->context->getUser(), $title ); |
31 | |
32 | $output ??= $this->context->getOutput(); |
33 | $output->addCategoryLinks( $this->getCategories( $title ) ); |
34 | } |
35 | |
36 | protected function getCategories( Title $title ) { |
37 | $id = $title->getArticleID(); |
38 | if ( !$id ) { |
39 | return []; |
40 | } |
41 | |
42 | $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); |
43 | $res = $dbr->newSelectQueryBuilder() |
44 | ->select( [ 'cl_to', 'cl_sortkey' ] ) |
45 | ->from( 'categorylinks' ) |
46 | ->where( [ 'cl_from' => $id ] ) |
47 | ->caller( __METHOD__ ) |
48 | ->fetchResultSet(); |
49 | |
50 | $categories = []; |
51 | foreach ( $res as $row ) { |
52 | $categories[$row->cl_to] = $row->cl_sortkey; |
53 | } |
54 | |
55 | return $categories; |
56 | } |
57 | } |