| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
namespace MediaWiki\Extension\DiscussionTools\Notifications; |
| 11 |
|
| 12 |
use MediaWiki\Extension\Notifications\DiscussionParser; |
| 13 |
use MediaWiki\Extension\Notifications\Formatters\EchoPresentationModelSection; |
| 14 |
use MediaWiki\Extension\Notifications\Model\Event; |
| 15 |
use MediaWiki\Language\Language; |
| 16 |
use MediaWiki\Revision\RevisionRecord; |
| 17 |
use MediaWiki\WikiMap\WikiMap; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
trait DiscussionToolsEventTrait { |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
abstract protected function userCan( $type ); |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
abstract protected function isBundled(); |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
abstract protected function getBundledEvents(); |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
abstract protected function getBundledIds(); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
protected function getCommentLink(): ?string { |
| 55 |
if ( !$this->userCan( RevisionRecord::DELETED_TEXT ) ) { |
| 56 |
return null; |
| 57 |
} |
| 58 |
if ( !$this->isBundled() ) { |
| 59 |
|
| 60 |
|
| 61 |
$commentId = $this->event->getExtraParam( 'comment-id' ); |
| 62 |
if ( !$commentId ) { |
| 63 |
return null; |
| 64 |
} |
| 65 |
$title = $this->event->getTitle(); |
| 66 |
return $title->createFragmentTarget( $commentId )->getFullURL(); |
| 67 |
} else { |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
$bundledEvents = $this->getBundledEvents(); |
| 84 |
$oldestEvent = end( $bundledEvents ); |
| 85 |
$params = [ 'dtnewcommentssince' => $oldestEvent->getExtraParam( 'comment-id' ) ]; |
| 86 |
if ( $this->event->getType() === 'dt-added-topic' ) { |
| 87 |
|
| 88 |
$params[ 'dtsincethread' ] = 1; |
| 89 |
} elseif ( $this->event->getExtraParam( 'subscribed-comment-name' ) ) { |
| 90 |
|
| 91 |
$params[ 'dtinthread' ] = 1; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
$titleWithOptionalSection = $this->section->getTitleWithSection(); |
| 97 |
return $titleWithOptionalSection->getFullURL( $params ); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
protected function getContentSnippet(): string { |
| 107 |
if ( !$this->userCan( RevisionRecord::DELETED_TEXT ) ) { |
| 108 |
return ''; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
$content = $this->event->getExtraParam( 'content' ); |
| 113 |
if ( !$content ) { |
| 114 |
return ''; |
| 115 |
} |
| 116 |
return $this->language->truncateForVisual( $content, DiscussionParser::DEFAULT_SNIPPET_LENGTH ); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
protected function addMarkAsRead( $link ) { |
| 129 |
global $wgEchoCrossWikiNotifications; |
| 130 |
if ( $link ) { |
| 131 |
$eventIds = [ $this->event->getId() ]; |
| 132 |
if ( $this->getBundledIds() ) { |
| 133 |
$eventIds = array_merge( $eventIds, $this->getBundledIds() ); |
| 134 |
} |
| 135 |
|
| 136 |
$queryParams = [ 'markasread' => implode( '|', $eventIds ) ]; |
| 137 |
if ( $wgEchoCrossWikiNotifications ) { |
| 138 |
$queryParams['markasreadwiki'] = WikiMap::getCurrentWikiId(); |
| 139 |
} |
| 140 |
|
| 141 |
$link['url'] = wfAppendQuery( $link['url'], $queryParams ); |
| 142 |
} |
| 143 |
return $link; |
| 144 |
} |
| 145 |
|
| 146 |
} |