Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ViewAction
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 doesWrites
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 showForAction
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 getCategories
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace Flow\Actions;
4
5use Article;
6use IContextSource;
7use MediaWiki\MediaWikiServices;
8use MediaWiki\Output\OutputPage;
9use MediaWiki\Title\Title;
10
11class 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->select(
44            /* from */ 'categorylinks',
45            /* select */ [ 'cl_to', 'cl_sortkey' ],
46            /* conditions */ [ 'cl_from' => $id ],
47            __METHOD__
48        );
49
50        $categories = [];
51        foreach ( $res as $row ) {
52            $categories[$row->cl_to] = $row->cl_sortkey;
53        }
54
55        return $categories;
56    }
57}