mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-27 17:20:40 +00:00
a0ca1d89c6
Changes to the use statements done automatically via script Addition of missing use statements done manually Change-Id: Iad87245bf8082193be72f7e482f29e9f1bad11fc
97 lines
2.7 KiB
PHP
97 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\Notifications\Formatters;
|
|
|
|
use MediaWiki\Language\RawMessage;
|
|
use MediaWiki\MediaWikiServices;
|
|
use MediaWiki\Parser\Sanitizer;
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
use Message;
|
|
|
|
class EchoEditUserPagePresentationModel extends EchoEventPresentationModel {
|
|
|
|
public function canRender() {
|
|
return (bool)$this->event->getTitle();
|
|
}
|
|
|
|
public function getIconType() {
|
|
return 'edit-user-page';
|
|
}
|
|
|
|
public function getPrimaryLink() {
|
|
return [
|
|
'url' => $this->getDiffLinkUrl(),
|
|
'label' => $this->msg( 'notification-link-text-view-edit' )->text()
|
|
];
|
|
}
|
|
|
|
public function getSecondaryLinks() {
|
|
if ( $this->isBundled() ) {
|
|
return [];
|
|
} else {
|
|
return [ $this->getAgentLink() ];
|
|
}
|
|
}
|
|
|
|
public function getHeaderMessage() {
|
|
if ( $this->isBundled() ) {
|
|
$msg = $this->msg( 'notification-bundle-header-edit-user-page' );
|
|
$count = $this->getNotificationCountForOutput();
|
|
|
|
$msg->numParams( $count );
|
|
$msg->params( $this->getViewingUserForGender() );
|
|
return $msg;
|
|
} else {
|
|
$msg = parent::getHeaderMessage();
|
|
$msg->params( $this->getViewingUserForGender() );
|
|
return $msg;
|
|
}
|
|
}
|
|
|
|
public function getCompactHeaderMessage() {
|
|
$msg = $this->getMessageWithAgent( 'notification-compact-header-edit-user-page' );
|
|
$msg->params( $this->getViewingUserForGender() );
|
|
return $msg;
|
|
}
|
|
|
|
public function getBodyMessage() {
|
|
$revision = $this->event->getRevision();
|
|
if ( $revision && $revision->getComment() && $this->userCan( RevisionRecord::DELETED_COMMENT ) ) {
|
|
$summary = $revision->getComment()->text;
|
|
$summary = MediaWikiServices::getInstance()->getCommentFormatter()->format( $summary );
|
|
$summary = Sanitizer::stripAllTags( $summary );
|
|
} else {
|
|
$summary = false;
|
|
}
|
|
if ( !$this->isBundled() ) {
|
|
return new RawMessage( '$1', [ Message::plaintextParam( $summary ) ] );
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private function getDiffLinkUrl() {
|
|
$revId = $this->event->getExtraParam( 'revid' );
|
|
$oldId = $this->isBundled() ? $this->getRevBeforeFirstNotification() : 'prev';
|
|
$query = [
|
|
'oldid' => $oldId,
|
|
'diff' => $revId,
|
|
];
|
|
return $this->event->getTitle()->getFullURL( $query );
|
|
}
|
|
|
|
private function getRevBeforeFirstNotification() {
|
|
$events = $this->getBundledEvents();
|
|
$firstNotificationRevId = end( $events )->getExtraParam( 'revid' );
|
|
$revisionLookup = MediaWikiServices::getInstance()->getRevisionLookup();
|
|
$revisionRecord = $revisionLookup->getRevisionById( $firstNotificationRevId );
|
|
$previousRevision = $revisionRecord ? $revisionLookup->getPreviousRevision( $revisionRecord ) : null;
|
|
$oldRevisionID = $previousRevision ? $previousRevision->getId() : 0;
|
|
|
|
return $oldRevisionID;
|
|
}
|
|
|
|
protected function getSubjectMessageKey() {
|
|
return 'notification-edit-user-page-email-subject';
|
|
}
|
|
}
|