mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-16 12:21:51 +00:00
3c53d6acb9
Use the codesniffer default of length = 120 Change-Id: Ifbfd56b20432e54805d3a9bce22cda888c1fc74d
172 lines
5.2 KiB
PHP
172 lines
5.2 KiB
PHP
<?php
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
class EchoPageLinkedPresentationModel extends EchoEventPresentationModel {
|
|
|
|
private $pageFrom;
|
|
|
|
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() {
|
|
if ( $this->isBundled() ) {
|
|
return false;
|
|
} else {
|
|
return [
|
|
'url' => $this->getPageFrom()->getFullURL(),
|
|
'label' => $this->msg( 'notification-link-text-view-page' )->text(),
|
|
];
|
|
}
|
|
}
|
|
|
|
public function getSecondaryLinks() {
|
|
$whatLinksHereLink = [
|
|
'url' => SpecialPage::getTitleFor( 'Whatlinkshere', $this->event->getTitle()->getPrefixedText() )
|
|
->getFullURL(),
|
|
'label' => $this->msg( 'notification-link-text-what-links-here' )->text(),
|
|
'description' => '',
|
|
'icon' => 'linked',
|
|
'prioritized' => true
|
|
];
|
|
|
|
$revid = $this->event->getExtraParam( 'revid' );
|
|
$diffLink = null;
|
|
if ( $revid !== null ) {
|
|
$diffLink = [
|
|
'url' => $this->getPageFrom()->getFullURL( [ 'diff' => $revid, 'oldid' => 'prev' ] ),
|
|
'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )
|
|
->text(),
|
|
'description' => '',
|
|
'icon' => 'changes',
|
|
'prioritized' => true
|
|
];
|
|
}
|
|
|
|
return [ $whatLinksHereLink, $diffLink, $this->getMuteLink() ];
|
|
}
|
|
|
|
protected function getMuteLink() {
|
|
if ( !MediaWikiServices::getInstance()->getMainConfig()->get( 'EchoPerUserBlacklist' ) ) {
|
|
return null;
|
|
}
|
|
$title = $this->event->getTitle();
|
|
$isPageMuted = EchoNotificationController::isPageLinkedTitleMutedByUser( $title, $this->getUser() );
|
|
$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()
|
|
)->text(),
|
|
null,
|
|
$data,
|
|
[]
|
|
);
|
|
}
|
|
|
|
protected function getHeaderMessageKey() {
|
|
if ( $this->getBundleCount( true, [ $this, 'getLinkedPageId' ] ) > 1 ) {
|
|
return 'notification-bundle-header-page-linked';
|
|
}
|
|
return 'notification-header-page-linked';
|
|
}
|
|
|
|
public function getHeaderMessage() {
|
|
$msg = parent::getHeaderMessage();
|
|
$msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) );
|
|
$msg->params( $this->getTruncatedTitleText( $this->getPageFrom(), true ) );
|
|
$count =
|
|
$this->getNotificationCountForOutput( true, [ $this, 'getLinkedPageId' ] );
|
|
|
|
// Repeat is B/C until unused parameter is removed from translations
|
|
$msg->numParams( $count, $count );
|
|
return $msg;
|
|
}
|
|
|
|
public function getCompactHeaderMessage() {
|
|
$msg = $this->msg( parent::getCompactHeaderMessageKey() );
|
|
$msg->params( $this->getTruncatedTitleText( $this->getPageFrom(), true ) );
|
|
return $msg;
|
|
}
|
|
|
|
/**
|
|
* 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'];
|
|
}
|
|
// Backwards compatibility for events from before https://gerrit.wikimedia.org/r/#/c/63076
|
|
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() {
|
|
if ( !$this->pageFrom ) {
|
|
$this->pageFrom = Title::newFromID( $this->getLinkedPageId( $this->event ) );
|
|
}
|
|
return $this->pageFrom;
|
|
}
|
|
|
|
protected function getSubjectMessageKey() {
|
|
return 'notification-page-linked-email-subject';
|
|
}
|
|
}
|