2015-11-17 16:42:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class EchoPageLinkedPresentationModel extends EchoEventPresentationModel {
|
|
|
|
|
2016-06-14 11:30:03 +00:00
|
|
|
private $pageFrom;
|
|
|
|
|
2015-11-17 16:42:40 +00:00
|
|
|
public function getIconType() {
|
|
|
|
return 'linked';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The page containing the link may be a new page
|
|
|
|
* that is not yet replicated.
|
|
|
|
* This event won't be rendered unless/until
|
|
|
|
* both pages are available.
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function canRender() {
|
|
|
|
$pageTo = $this->event->getTitle();
|
|
|
|
$pageFrom = $this->getPageFrom();
|
|
|
|
return (bool)$pageTo && (bool)$pageFrom;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPrimaryLink() {
|
2016-09-16 22:23:40 +00:00
|
|
|
if ( $this->isBundled() ) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
2016-09-16 22:23:40 +00:00
|
|
|
'url' => $this->getPageFrom()->getFullURL(),
|
|
|
|
'label' => $this->msg( 'notification-link-text-view-page' )->text(),
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2016-09-16 22:23:40 +00:00
|
|
|
}
|
2015-11-17 16:42:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSecondaryLinks() {
|
2016-12-05 18:51:07 +00:00
|
|
|
$whatLinksHereLink = [
|
2015-12-23 18:04:01 +00:00
|
|
|
'url' => SpecialPage::getTitleFor( 'Whatlinkshere', $this->event->getTitle()->getPrefixedText() )->getFullURL(),
|
2015-11-17 16:42:40 +00:00
|
|
|
'label' => $this->msg( 'notification-link-text-what-links-here' )->text(),
|
2015-12-16 16:52:02 +00:00
|
|
|
'description' => '',
|
2015-12-22 19:51:45 +00:00
|
|
|
'icon' => 'linked',
|
2015-11-17 16:42:40 +00:00
|
|
|
'prioritized' => true
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2016-05-23 19:22:41 +00:00
|
|
|
|
|
|
|
$revid = $this->event->getExtraParam( 'revid' );
|
|
|
|
$diffLink = null;
|
|
|
|
if ( $revid !== null ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$diffLink = [
|
|
|
|
'url' => $this->getPageFrom()->getFullURL( [ 'diff' => $revid, 'oldid' => 'prev' ] ),
|
2016-06-20 15:14:45 +00:00
|
|
|
'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text(),
|
2016-05-23 19:22:41 +00:00
|
|
|
'description' => '',
|
|
|
|
'icon' => 'changes',
|
|
|
|
'prioritized' => true
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2016-05-23 19:22:41 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
return [ $whatLinksHereLink, $diffLink ];
|
2015-11-17 16:42:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getHeaderMessageKey() {
|
2016-12-05 18:51:07 +00:00
|
|
|
if ( $this->getBundleCount( true, [ $this, 'getLinkedPageId' ] ) > 1 ) {
|
2019-04-06 00:33:28 +00:00
|
|
|
return 'notification-bundle-header-page-linked';
|
2015-11-17 16:42:40 +00:00
|
|
|
}
|
2019-04-06 00:33:28 +00:00
|
|
|
return 'notification-header-page-linked';
|
2015-11-17 16:42:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getHeaderMessage() {
|
|
|
|
$msg = parent::getHeaderMessage();
|
2016-01-20 21:19:54 +00:00
|
|
|
$msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) );
|
|
|
|
$msg->params( $this->getTruncatedTitleText( $this->getPageFrom(), true ) );
|
2016-03-09 04:50:31 +00:00
|
|
|
$count =
|
2016-12-05 18:51:07 +00:00
|
|
|
$this->getNotificationCountForOutput( true, [ $this, 'getLinkedPageId' ] );
|
2016-03-09 04:50:31 +00:00
|
|
|
|
|
|
|
// Repeat is B/C until unused parameter is removed from translations
|
|
|
|
$msg->numParams( $count, $count );
|
2015-11-17 16:42:40 +00:00
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
2016-06-07 20:08:16 +00:00
|
|
|
public function getCompactHeaderMessage() {
|
|
|
|
$msg = $this->msg( parent::getCompactHeaderMessageKey() );
|
|
|
|
$msg->params( $this->getTruncatedTitleText( $this->getPageFrom(), true ) );
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
2015-11-17 16:42:40 +00:00
|
|
|
/**
|
|
|
|
* Get the page ID of the linked-from page for a given event.
|
|
|
|
* @param EchoEvent $event page-linked event
|
|
|
|
* @return int Page ID, or 0 if the page doesn't exist
|
|
|
|
*/
|
|
|
|
public function getLinkedPageId( EchoEvent $event ) {
|
|
|
|
$extra = $event->getExtra();
|
|
|
|
if ( isset( $extra['link-from-page-id'] ) ) {
|
|
|
|
return $extra['link-from-page-id'];
|
|
|
|
}
|
2018-03-09 21:22:43 +00:00
|
|
|
// Backwards compatibility for events from before https://gerrit.wikimedia.org/r/#/c/63076
|
2015-11-17 16:42:40 +00:00
|
|
|
if ( isset( $extra['link-from-namespace'] ) && isset( $extra['link-from-title'] ) ) {
|
|
|
|
$title = Title::makeTitleSafe( $extra['link-from-namespace'], $extra['link-from-title'] );
|
|
|
|
if ( $title ) {
|
|
|
|
return $title->getArticleId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getPageFrom() {
|
2016-06-14 11:30:03 +00:00
|
|
|
if ( !$this->pageFrom ) {
|
|
|
|
$this->pageFrom = Title::newFromId( $this->getLinkedPageId( $this->event ) );
|
|
|
|
}
|
|
|
|
return $this->pageFrom;
|
2015-11-17 16:42:40 +00:00
|
|
|
}
|
2016-05-05 13:05:03 +00:00
|
|
|
|
|
|
|
protected function getSubjectMessageKey() {
|
|
|
|
return 'notification-page-linked-email-subject';
|
|
|
|
}
|
2015-11-17 16:42:40 +00:00
|
|
|
}
|