Debian Codegraph @

extensions/Echo/includes/Formatters/EchoEditUserPagePresentationModel.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\Notifications\Formatters;
4
5 use MediaWiki\Language\RawMessage;
6 use MediaWiki\MediaWikiServices;
7 use MediaWiki\Message\Message;
8 use MediaWiki\Parser\Sanitizer;
9 use MediaWiki\Revision\RevisionRecord;
10
11 class EchoEditUserPagePresentationModel extends EchoEventPresentationModel {
12
13 public function canRender() {
14 return (bool)$this->event->getTitle();
15 }
16
17 public function getIconType() {
18 return 'edit-user-page';
19 }
20
21 public function getPrimaryLink() {
22 return [
23 'url' => $this->getDiffLinkUrl(),
24 'label' => $this->msg( 'notification-link-text-view-edit' )->text()
25 ];
26 }
27
28 public function getSecondaryLinks() {
29 if ( $this->isBundled() ) {
30 return [];
31 } else {
32 return [ $this->getAgentLink() ];
33 }
34 }
35
36 public function getHeaderMessage() {
37 if ( $this->isBundled() ) {
38 $msg = $this->msg( 'notification-bundle-header-edit-user-page' );
39 $count = $this->getNotificationCountForOutput();
40
41 $msg->numParams( $count );
42 $msg->params( $this->getViewingUserForGender() );
43 return $msg;
44 } else {
45 // Messages: notification-header-edit-user-page
46 $msg = parent::getHeaderMessage();
47 $msg->params( $this->getViewingUserForGender() );
48 return $msg;
49 }
50 }
51
52 public function getCompactHeaderMessage() {
53 $msg = $this->getMessageWithAgent( 'notification-compact-header-edit-user-page' );
54 $msg->params( $this->getViewingUserForGender() );
55 return $msg;
56 }
57
58 public function getBodyMessage() {
59 $revision = $this->event->getRevision();
60 if ( $revision && $revision->getComment() && $this->userCan( RevisionRecord::DELETED_COMMENT ) ) {
61 $summary = $revision->getComment()->text;
62 $summary = MediaWikiServices::getInstance()->getCommentFormatter()->format( $summary );
63 $summary = Sanitizer::stripAllTags( $summary );
64 } else {
65 $summary = $this->msg( 'rev-deleted-comment' )->text();
66 }
67 if ( !$this->isBundled() ) {
68 return new RawMessage( '$1', [ Message::plaintextParam( $summary ) ] );
69 }
70 return false;
71 }
72
73 private function getDiffLinkUrl() {
74 $revId = $this->event->getExtraParam( 'revid' );
75 $oldId = $this->isBundled() ? $this->getRevBeforeFirstNotification() : 'prev';
76 $query = [
77 'oldid' => $oldId,
78 'diff' => $revId,
79 ];
80 return $this->event->getTitle()->getFullURL( $query );
81 }
82
83 private function getRevBeforeFirstNotification() {
84 $events = $this->getBundledEvents();
85 $firstNotificationRevId = end( $events )->getExtraParam( 'revid' );
86 $revisionLookup = MediaWikiServices::getInstance()->getRevisionLookup();
87 $revisionRecord = $revisionLookup->getRevisionById( $firstNotificationRevId );
88 $previousRevision = $revisionRecord ? $revisionLookup->getPreviousRevision( $revisionRecord ) : null;
89 $oldRevisionID = $previousRevision ? $previousRevision->getId() : 0;
90
91 return $oldRevisionID;
92 }
93
94 protected function getSubjectMessageKey() {
95 return 'notification-edit-user-page-email-subject';
96 }
97 }