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