Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
TwlEligiblePresentationModel | |
0.00% |
0 / 25 |
|
0.00% |
0 / 6 |
72 | |
0.00% |
0 / 1 |
getIconType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHeaderMessageKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getBodyMessage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPrimaryLink | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getSecondaryLinks | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSecondaryLinkWithMarkAsRead | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | namespace MediaWiki\Extension\TheWikipediaLibrary; |
3 | |
4 | use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel; |
5 | use MediaWiki\MediaWikiServices; |
6 | use MediaWiki\WikiMap\WikiMap; |
7 | |
8 | /* |
9 | When creating a new notification type for Echo, you need to |
10 | create a PresentationModel. |
11 | For more information, see: https://www.mediawiki.org/wiki/Extension:Echo/Creating_a_new_notification_type |
12 | |
13 | */ |
14 | class TwlEligiblePresentationModel extends EchoEventPresentationModel { |
15 | |
16 | /** |
17 | * @inheritDoc |
18 | */ |
19 | public function getIconType() { |
20 | return 'twl-eligible'; |
21 | } |
22 | |
23 | /** |
24 | * @inheritDoc |
25 | */ |
26 | public function getHeaderMessageKey() { |
27 | return 'notification-header-twl-eligiblity'; |
28 | } |
29 | |
30 | /** |
31 | * @inheritDoc |
32 | */ |
33 | public function getBodyMessage() { |
34 | return $this->msg( 'notification-body-twl-eligiblity' ); |
35 | } |
36 | |
37 | /** |
38 | * @inheritDoc |
39 | */ |
40 | public function getPrimaryLink() { |
41 | $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'TheWikipediaLibrary' ); |
42 | return [ |
43 | 'url' => $config->get( 'TwlUserPrimaryUrl' ), |
44 | 'label' => null, |
45 | ]; |
46 | } |
47 | |
48 | /** |
49 | * @inheritDoc |
50 | */ |
51 | public function getSecondaryLinks() { |
52 | return [ $this->getSecondaryLinkWithMarkAsRead() ]; |
53 | } |
54 | |
55 | /** |
56 | * Like getPrimaryLinkWithMarkAsRead(), but for a secondary link. |
57 | * It alters the URL to add ?markasread=XYZ. When this link is followed, |
58 | * the notification is marked as read. |
59 | * |
60 | * If the notification is a bundle, the notification IDs are added to the parameter value |
61 | * separated by a "|". If cross-wiki notifications are enabled, a markasreadwiki parameter is |
62 | * added. |
63 | * |
64 | * @return array |
65 | */ |
66 | final public function getSecondaryLinkWithMarkAsRead() { |
67 | global $wgEchoCrossWikiNotifications; |
68 | $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'TheWikipediaLibrary' ); |
69 | $secondaryLink = [ |
70 | 'url' => $config->get( 'TwlUserSecondaryUrl' ), |
71 | 'label' => $this->msg( 'notification-twl-eligiblity-secondarylink-text' )->text(), |
72 | 'icon' => 'article', |
73 | ]; |
74 | '@phan-var array $secondaryLink'; |
75 | $eventIds = [ $this->event->getId() ]; |
76 | if ( $this->getBundledIds() ) { |
77 | $eventIds = array_merge( $eventIds, $this->getBundledIds() ); |
78 | } |
79 | |
80 | $queryParams = [ 'markasread' => implode( '|', $eventIds ) ]; |
81 | if ( $wgEchoCrossWikiNotifications ) { |
82 | $queryParams['markasreadwiki'] = WikiMap::getCurrentWikiId(); |
83 | } |
84 | |
85 | $secondaryLink['url'] = wfAppendQuery( $secondaryLink['url'], $queryParams ); |
86 | return $secondaryLink; |
87 | } |
88 | } |