mediawiki-extensions-Echo/includes/formatters/EditUserTalkPresentationModel.php
Roan Kattouw 6eea6d93a1 Used parsed section titles for anchors
This allows us to link to the right section when the section
title contains templates or magic words.

* Add getParsedSectionTitle()
* Use it in getTitleWithSection()
** Stop using Parser::guessSectionNameFromWikiText() because it
   wants preprocessed wikitext, not fully parsed and stripped text
* Move getTruncatedSectionTitle() from EventPresentationModel to
  PresentationModelSectionTrait and make it use getParsedSectionTitle()

Bug: T134216
Change-Id: I877ff6b0ce4e64400f6e5f6284ae47a11cd4335b
2016-09-27 16:17:59 -07:00

91 lines
2.7 KiB
PHP

<?php
class EchoEditUserTalkPresentationModel extends EchoEventPresentationModel {
use EchoPresentationModelSectionTrait;
public function canRender() {
return (bool)$this->event->getTitle();
}
public function getIconType() {
return 'edit-user-talk';
}
public function getPrimaryLink() {
return array(
// Need FullURL so the section is included
'url' => $this->getTitleWithSection()->getFullURL(),
'label' => $this->msg( 'notification-link-text-view-message' )->text()
);
}
public function getSecondaryLinks() {
$diffLink = array(
'url' => $this->getDiffLinkUrl(),
'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text(),
'description' => '',
'icon' => 'changes',
'prioritized' => true
);
if ( $this->isBundled() ) {
return array( $diffLink );
} else {
return array( $this->getAgentLink(), $diffLink );
}
}
public function getHeaderMessage() {
if ( $this->isBundled() ) {
$msg = $this->msg( "notification-bundle-header-{$this->type}-v2" );
$count = $this->getNotificationCountForOutput();
// Repeat is B/C until unused parameter is removed from translations
$msg->numParams( $count, $count );
$msg->params( $this->getViewingUserForGender() );
return $msg;
} elseif ( $this->hasSection() ) {
$msg = $this->getMessageWithAgent( "notification-header-{$this->type}-with-section" );
$msg->params( $this->getViewingUserForGender() );
$msg->plaintextParams( $this->getTruncatedSectionTitle() );
return $msg;
} else {
$msg = parent::getHeaderMessage();
$msg->params( $this->getViewingUserForGender() );
return $msg;
}
}
public function getBodyMessage() {
$sectionText = $this->event->getExtraParam( 'section-text' );
if ( !$this->isBundled() && $this->hasSection() && $sectionText !== null ) {
$msg = $this->msg( 'notification-body-edit-user-talk-with-section' );
// section-text is safe to use here, because hasSection() returns false if the revision is deleted
$msg->plaintextParams( $sectionText );
return $msg;
} else {
return false;
}
}
private function getDiffLinkUrl() {
$revId = $this->event->getExtraParam( 'revid' );
$oldId = $this->isBundled() ? $this->getRevBeforeFirstNotification() : 'prev';
$query = array(
'oldid' => $oldId,
'diff' => $revId,
);
return $this->event->getTitle()->getFullURL( $query );
}
private function getRevBeforeFirstNotification() {
$events = $this->getBundledEvents();
$firstNotificationRevId = end( $events )->getExtraParam( 'revid' );
return $this->event->getTitle()->getPreviousRevisionID( $firstNotificationRevId );
}
protected function getSubjectMessageKey() {
return 'notification-edit-talk-page-email-subject2';
}
}