2015-11-17 16:42:40 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-01 22:01:23 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Formatters;
|
|
|
|
|
2022-11-02 03:51:15 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Controller\NotificationController;
|
2022-11-02 21:34:17 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Model\Event;
|
2020-04-28 03:39:40 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\SpecialPage\SpecialPage;
|
2023-08-19 04:14:59 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2020-04-28 03:39:40 +00:00
|
|
|
|
2015-11-17 16:42:40 +00:00
|
|
|
class EchoPageLinkedPresentationModel extends EchoEventPresentationModel {
|
|
|
|
|
2020-12-16 21:31:09 +00:00
|
|
|
/** @var Title|null */
|
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 {
|
2022-12-21 18:57:05 +00:00
|
|
|
$params = [];
|
|
|
|
if ( $this->event->getExtraParam( 'revid' ) ) {
|
|
|
|
$params = [
|
|
|
|
'oldid' => 'prev',
|
|
|
|
'diff' => $this->event->getExtraParam( 'revid' )
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
2022-12-21 18:57:05 +00:00
|
|
|
'url' => $this->getPageFrom()->getFullURL( $params ),
|
2016-09-16 22:23:40 +00:00
|
|
|
'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 = [
|
2020-06-27 10:05:03 +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
|
|
|
|
2022-12-21 18:57:05 +00:00
|
|
|
return [ $whatLinksHereLink, $this->getMuteLink() ];
|
2020-04-28 03:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getMuteLink() {
|
|
|
|
if ( !MediaWikiServices::getInstance()->getMainConfig()->get( 'EchoPerUserBlacklist' ) ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$title = $this->event->getTitle();
|
2022-11-02 03:51:15 +00:00
|
|
|
$isPageMuted = NotificationController::isPageLinkedTitleMutedByUser( $title, $this->getUser() );
|
2020-04-28 03:39:40 +00:00
|
|
|
$action = $isPageMuted ? 'unmute' : 'mute';
|
|
|
|
$prefTitle = SpecialPage::getTitleFor( 'Preferences', false, 'mw-prefsection-echo-mutedpageslist' );
|
|
|
|
$data = [
|
|
|
|
'tokenType' => 'csrf',
|
|
|
|
'params' => [
|
|
|
|
'action' => 'echomute',
|
|
|
|
'type' => 'page-linked-title',
|
|
|
|
],
|
|
|
|
'messages' => [
|
|
|
|
'confirmation' => [
|
|
|
|
// notification-dynamic-actions-mute-page-linked-confirmation
|
|
|
|
// notification-dynamic-actions-unmute-page-linked-confirmation
|
|
|
|
'title' => $this
|
|
|
|
->msg( 'notification-dynamic-actions-' . $action . '-page-linked-confirmation' )
|
|
|
|
->params(
|
|
|
|
$this->getTruncatedTitleText( $title ),
|
|
|
|
$this->getViewingUserForGender()
|
|
|
|
),
|
|
|
|
// notification-dynamic-actions-mute-page-linked-confirmation-description
|
|
|
|
// notification-dynamic-actions-unmute-page-linked-confirmation-description
|
|
|
|
'description' => $this
|
|
|
|
->msg( 'notification-dynamic-actions-' . $action . '-page-linked-confirmation-description' )
|
|
|
|
->params(
|
|
|
|
$prefTitle->getFullURL(),
|
|
|
|
$this->getViewingUserForGender()
|
|
|
|
)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$data['params'][$isPageMuted ? 'unmute' : 'mute'] = $title->getPrefixedText();
|
|
|
|
|
|
|
|
return $this->getDynamicActionLink(
|
|
|
|
$prefTitle,
|
|
|
|
$isPageMuted ? 'bell' : 'unbell',
|
|
|
|
// notification-dynamic-actions-mute-page-linked
|
|
|
|
// notification-dynamic-actions-unmute-page-linked
|
|
|
|
$this->msg( 'notification-dynamic-actions-' . $action . '-page-linked' )
|
|
|
|
->params(
|
|
|
|
$this->getTruncatedTitleText( $title ),
|
|
|
|
$this->getViewingUserForGender()
|
2020-06-06 19:28:08 +00:00
|
|
|
)->text(),
|
2020-04-28 03:39:40 +00:00
|
|
|
null,
|
|
|
|
$data,
|
|
|
|
[]
|
|
|
|
);
|
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' ] );
|
2024-06-24 07:23:25 +00:00
|
|
|
$msg->numParams( $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.
|
2022-11-02 21:34:17 +00:00
|
|
|
* @param Event $event page-linked event
|
2015-11-17 16:42:40 +00:00
|
|
|
* @return int Page ID, or 0 if the page doesn't exist
|
|
|
|
*/
|
2022-11-02 21:34:17 +00:00
|
|
|
public function getLinkedPageId( Event $event ) {
|
2015-11-17 16:42:40 +00:00
|
|
|
$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 ) {
|
2019-06-11 21:43:05 +00:00
|
|
|
return $title->getArticleID();
|
2015-11-17 16:42:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getPageFrom() {
|
2016-06-14 11:30:03 +00:00
|
|
|
if ( !$this->pageFrom ) {
|
2019-06-11 21:43:05 +00:00
|
|
|
$this->pageFrom = Title::newFromID( $this->getLinkedPageId( $this->event ) );
|
2016-06-14 11:30:03 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|