| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Notifications\Formatters; |
| 4 |
|
| 5 |
use MediaWiki\MediaWikiServices; |
| 6 |
use MediaWiki\SpecialPage\SpecialPage; |
| 7 |
use MediaWiki\Title\Title; |
| 8 |
|
| 9 |
class EchoWatchlistChangePresentationModel extends EchoEventPresentationModel { |
| 10 |
|
| 11 |
public function getIconType() { |
| 12 |
return 'watchlist-progressive'; |
| 13 |
} |
| 14 |
|
| 15 |
public function getHeaderMessage() { |
| 16 |
if ( $this->isMultiTypeBundle() ) { |
| 17 |
$status = "changed"; |
| 18 |
} else { |
| 19 |
$status = $this->event->getExtraParam( 'status' ); |
| 20 |
} |
| 21 |
if ( $this->isMultiUserBundle() ) { |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
$msg = $this->msg( "notification-header-watchlist-multiuser-" . $status ); |
| 28 |
} else { |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
$msg = $this->getMessageWithAgent( "notification-header-watchlist-" . $status ); |
| 35 |
} |
| 36 |
$msg->params( $this->getTruncatedTitleText( $this->getEventTitle(), true ) ); |
| 37 |
$msg->params( $this->getViewingUserForGender() ); |
| 38 |
$msg->numParams( $this->getBundleCount() ); |
| 39 |
return $msg; |
| 40 |
} |
| 41 |
|
| 42 |
public function getPrimaryLink() { |
| 43 |
if ( $this->isBundled() ) { |
| 44 |
return [ |
| 45 |
'url' => $this->getEventTitle()->getLocalUrl(), |
| 46 |
'label' => $this->msg( 'notification-link-text-view-page' )->text() |
| 47 |
]; |
| 48 |
} |
| 49 |
return [ |
| 50 |
'url' => $this->getViewChangesUrl(), |
| 51 |
'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() ) |
| 52 |
->text(), |
| 53 |
]; |
| 54 |
} |
| 55 |
|
| 56 |
public function getSecondaryLinks() { |
| 57 |
if ( $this->isBundled() ) { |
| 58 |
if ( $this->isMultiUserBundle() ) { |
| 59 |
return []; |
| 60 |
} else { |
| 61 |
return [ $this->getAgentLink() ]; |
| 62 |
} |
| 63 |
} else { |
| 64 |
$viewChangesLink = [ |
| 65 |
'url' => $this->getViewChangesUrl(), |
| 66 |
'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() ) |
| 67 |
->text(), |
| 68 |
'description' => '', |
| 69 |
'icon' => 'changes', |
| 70 |
'prioritized' => true, |
| 71 |
]; |
| 72 |
return [ $this->getAgentLink(), $viewChangesLink ]; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
public function getBodyMessage() { |
| 77 |
if ( $this->event->getExtraParam( 'emailonce' ) && $this->getDistributionType() == 'email' ) { |
| 78 |
return $this->msg( 'notification-body-watchlist-once', $this->getViewingUserForGender() ); |
| 79 |
} |
| 80 |
return false; |
| 81 |
} |
| 82 |
|
| 83 |
private function isMultiUserBundle() { |
| 84 |
foreach ( $this->getBundledEvents() as $bundled ) { |
| 85 |
if ( !$bundled->getAgent()->equals( $this->event->getAgent() ) ) { |
| 86 |
return true; |
| 87 |
} |
| 88 |
} |
| 89 |
return false; |
| 90 |
} |
| 91 |
|
| 92 |
private function isMultiTypeBundle() { |
| 93 |
foreach ( $this->getBundledEvents() as $bundled ) { |
| 94 |
if ( $bundled->getExtraParam( 'status' ) !== $this->event->getExtraParam( 'status' ) ) { |
| 95 |
return true; |
| 96 |
} |
| 97 |
} |
| 98 |
return false; |
| 99 |
} |
| 100 |
|
| 101 |
private function getViewChangesUrl() { |
| 102 |
$revid = $this->event->getExtraParam( 'revid' ); |
| 103 |
if ( $revid === 0 ) { |
| 104 |
$url = SpecialPage::getTitleFor( 'Log' )->getLocalUrl( [ |
| 105 |
'logid' => $this->event->getExtraParam( 'logid' ) |
| 106 |
] ); |
| 107 |
} else { |
| 108 |
$url = $this->getEventTitle()->getLocalURL( [ |
| 109 |
'oldid' => 'prev', |
| 110 |
'diff' => $revid |
| 111 |
] ); |
| 112 |
} |
| 113 |
return $url; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
private function getEventTitle(): Title { |
| 123 |
$title = $this->event->getTitle(); |
| 124 |
if ( !$title ) { |
| 125 |
$pageId = $this->event->getPageId(); |
| 126 |
if ( $pageId ) { |
| 127 |
$dbr = MediaWikiServices::getInstance() |
| 128 |
->getDBLoadBalancer() |
| 129 |
->getMaintenanceConnectionRef( DB_REPLICA ); |
| 130 |
$row = $dbr->selectRow( |
| 131 |
'archive', |
| 132 |
[ 'ar_title', 'ar_namespace' ], |
| 133 |
[ 'ar_page_id' => $pageId ], |
| 134 |
__METHOD__, |
| 135 |
[ 'MAX' => 'ar_id', 'ar_id DESC' ] |
| 136 |
); |
| 137 |
if ( $row ) { |
| 138 |
$title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title ); |
| 139 |
} |
| 140 |
} |
| 141 |
if ( !$title ) { |
| 142 |
$title = Title::makeTitleSafe( NS_MAIN, 'UNKNOWN TITLE, SEE THE T286192 BUG FOR DETAILS' ); |
| 143 |
} |
| 144 |
if ( !$title ) { |
| 145 |
|
| 146 |
$title = Title::newMainPage(); |
| 147 |
} |
| 148 |
} |
| 149 |
return $title; |
| 150 |
} |
| 151 |
} |