Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
FeedItemFormatter
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 2
56
0.00% covered (danger)
0.00%
0 / 1
 getHistoryType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 format
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 1
42
1<?php
2
3namespace Flow\Formatter;
4
5use Flow\Exception\FlowException;
6use MediaWiki\Context\IContextSource;
7use MediaWiki\Feed\FeedItem;
8
9class FeedItemFormatter extends AbstractFormatter {
10    protected function getHistoryType() {
11        return 'feeditem';
12    }
13
14    /**
15     * @param FormatterRow $row With properties workflow, revision, previous_revision
16     * @param IContextSource $ctx
17     * @return FeedItem|false The requested format, or false on failure
18     * @throws FlowException
19     */
20    public function format( FormatterRow $row, IContextSource $ctx ) {
21        $this->serializer->setIncludeHistoryProperties( true );
22        $data = $this->serializer->formatApi( $row, $ctx, 'contributions' );
23        if ( !$data ) {
24            return false;
25        }
26
27        $preferredLinks = [
28            'header-revision',
29            'post-revision', 'post',
30            'topic-revision', 'topic',
31            'board'
32        ];
33        $url = '';
34        foreach ( $preferredLinks as $link ) {
35            if ( isset( $data['links'][$link] ) ) {
36                $url = $data['links'][$link]->getFullURL();
37                break;
38            }
39        }
40        // If we didn't choose anything just take the first.
41        // @todo perhaps just a convention that the first link
42        // is always the most specific, we use a similar pattern
43        // to above in TemplateHelper::historyTimestamp too.
44        if ( $url === '' && $data['links'] ) {
45            $keys = array_keys( $data['links'] );
46            $link = reset( $keys );
47            $url = $data['links'][$link]->getFullURL();
48        }
49
50        return new FeedItem(
51            $row->workflow->getArticleTitle()->getPrefixedText(),
52            $this->formatDescription( $data, $ctx ),
53            $url,
54            $data['timestamp'],
55            $data['author']['name'],
56            $row->workflow->getOwnerTitle()->getFullURL()
57        );
58    }
59}