Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
ArticleChangedPresentationModel | |
0.00% |
0 / 45 |
|
0.00% |
0 / 7 |
72 | |
0.00% |
0 / 1 |
getIconType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHeaderMessage | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getPrimaryLink | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSecondaryLinks | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
getArticleTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getArticleDiffLink | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
6 | |||
getStoryBuilderEditLink | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Wikistories\Notifications; |
4 | |
5 | use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel; |
6 | use MediaWiki\Extension\Wikistories\Hooks\EchoNotificationsHandlers; |
7 | use MediaWiki\MediaWikiServices; |
8 | use MediaWiki\SpecialPage\SpecialPage; |
9 | use MediaWiki\Title\Title; |
10 | |
11 | class ArticleChangedPresentationModel extends EchoEventPresentationModel { |
12 | |
13 | /** |
14 | * @return string The symbolic icon name as defined in $wgEchoNotificationIcons |
15 | */ |
16 | public function getIconType() { |
17 | return EchoNotificationsHandlers::NOTIFICATION_TYPE; |
18 | } |
19 | |
20 | /** |
21 | * @inheritDoc |
22 | */ |
23 | public function getHeaderMessage() { |
24 | $title = $this->getTruncatedTitleText( $this->getArticleTitle() ); |
25 | $msg = $this->msg( 'wikistories-notification-articlechanged-header' ); |
26 | $msg->params( $title ); |
27 | $msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) ); |
28 | return $msg; |
29 | } |
30 | |
31 | /** |
32 | * Array of primary link details, with possibly-relative URL & label. |
33 | * |
34 | * @return array|false Array of link data, or false for no link: |
35 | * ['url' => (string) url, 'label' => (string) link text (non-escaped)] |
36 | */ |
37 | public function getPrimaryLink() { |
38 | return $this->getStoryBuilderEditLink(); |
39 | } |
40 | |
41 | /** |
42 | * @inheritDoc |
43 | */ |
44 | public function getSecondaryLinks() { |
45 | $agentLink = $this->getAgentLink(); |
46 | $agentLink[ 'prioritized' ] = false; |
47 | return [ |
48 | $this->getArticleDiffLink(), |
49 | $this->getPageLink( $this->event->getTitle(), '', false ), |
50 | $this->getPageLink( $this->getArticleTitle(), '', false ), |
51 | $agentLink, |
52 | ]; |
53 | } |
54 | |
55 | /** |
56 | * @return Title |
57 | */ |
58 | private function getArticleTitle(): Title { |
59 | return Title::newFromText( $this->event->getExtraParam( 'articleTitle' ) ); |
60 | } |
61 | |
62 | /** |
63 | * @return array |
64 | */ |
65 | private function getArticleDiffLink(): array { |
66 | $title = $this->getArticleTitle(); |
67 | $articleTopRev = $this->event->getExtraParam( 'articleRevId' ); |
68 | if ( $this->isBundled() ) { |
69 | $bundledEvents = $this->getBundledEvents(); |
70 | $oldestEvent = end( $bundledEvents ); |
71 | $revisionLookup = MediaWikiServices::getInstance()->getRevisionLookup(); |
72 | $rev = $revisionLookup->getRevisionById( $oldestEvent->getExtraParam( 'articleRevId' ) ); |
73 | $previousRev = $revisionLookup->getPreviousRevision( $rev ); |
74 | $params = [ |
75 | 'diff' => $articleTopRev, |
76 | 'oldid' => $previousRev->getId(), |
77 | ]; |
78 | } else { |
79 | $params = [ |
80 | 'diff' => 'prev', |
81 | 'oldid' => $articleTopRev, |
82 | ]; |
83 | } |
84 | return [ |
85 | 'url' => $title->getFullURL( $params ), |
86 | 'label' => $this->msg( 'diff' ), |
87 | 'description' => '', |
88 | 'prioritized' => true, |
89 | ]; |
90 | } |
91 | |
92 | /** |
93 | * @return array |
94 | */ |
95 | private function getStoryBuilderEditLink(): array { |
96 | $url = SpecialPage::getTitleFor( 'StoryBuilder', $this->event->getTitle() )->getFullURL(); |
97 | return [ |
98 | 'url' => $url, |
99 | 'label' => '', |
100 | 'description' => '', |
101 | 'prioritized' => true, |
102 | ]; |
103 | } |
104 | } |