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 | class TwlEligiblePresentationModel extends EchoEventPresentationModel { |
| 14 | |
| 15 | /** |
| 16 | * @inheritDoc |
| 17 | */ |
| 18 | public function getIconType() { |
| 19 | return 'twl-eligible'; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * @inheritDoc |
| 24 | */ |
| 25 | public function getHeaderMessageKey() { |
| 26 | return 'notification-header-twl-eligiblity'; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @inheritDoc |
| 31 | */ |
| 32 | public function getBodyMessage() { |
| 33 | return $this->msg( 'notification-body-twl-eligiblity' ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @inheritDoc |
| 38 | */ |
| 39 | public function getPrimaryLink() { |
| 40 | $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'TheWikipediaLibrary' ); |
| 41 | return [ |
| 42 | 'url' => $config->get( 'TwlUserPrimaryUrl' ), |
| 43 | 'label' => null, |
| 44 | ]; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @inheritDoc |
| 49 | */ |
| 50 | public function getSecondaryLinks() { |
| 51 | return [ $this->getSecondaryLinkWithMarkAsRead() ]; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Like getPrimaryLinkWithMarkAsRead(), but for a secondary link. |
| 56 | * It alters the URL to add ?markasread=XYZ. When this link is followed, |
| 57 | * the notification is marked as read. |
| 58 | * |
| 59 | * If the notification is a bundle, the notification IDs are added to the parameter value |
| 60 | * separated by a "|". If cross-wiki notifications are enabled, a markasreadwiki parameter is |
| 61 | * added. |
| 62 | * |
| 63 | * @return array |
| 64 | */ |
| 65 | final public function getSecondaryLinkWithMarkAsRead() { |
| 66 | global $wgEchoCrossWikiNotifications; |
| 67 | $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'TheWikipediaLibrary' ); |
| 68 | $secondaryLink = [ |
| 69 | 'url' => $config->get( 'TwlUserSecondaryUrl' ), |
| 70 | 'label' => $this->msg( 'notification-twl-eligiblity-secondarylink-text' )->text(), |
| 71 | 'icon' => 'article', |
| 72 | ]; |
| 73 | '@phan-var array $secondaryLink'; |
| 74 | $eventIds = [ $this->event->getId() ]; |
| 75 | if ( $this->getBundledIds() ) { |
| 76 | $eventIds = array_merge( $eventIds, $this->getBundledIds() ); |
| 77 | } |
| 78 | |
| 79 | $queryParams = [ 'markasread' => implode( '|', $eventIds ) ]; |
| 80 | if ( $wgEchoCrossWikiNotifications ) { |
| 81 | $queryParams['markasreadwiki'] = WikiMap::getCurrentWikiId(); |
| 82 | } |
| 83 | |
| 84 | $secondaryLink['url'] = wfAppendQuery( $secondaryLink['url'], $queryParams ); |
| 85 | return $secondaryLink; |
| 86 | } |
| 87 | } |