mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-24 08:23:52 +00:00
Add 'legacyPrimary' links to API data for users without DT-enhanced HTML
The 'legacyPrimary' links will take you to the section the comment is in and should be used when you don't have access to comment IDs. Bug: T296018 Change-Id: I944feb90e7c3a69f81366f42fa110c58cac26dbb
This commit is contained in:
parent
69ba8582a9
commit
dd896deb45
|
@ -36,6 +36,11 @@ trait DiscussionToolsEventTrait {
|
|||
*/
|
||||
abstract protected function getBundledEvents();
|
||||
|
||||
/**
|
||||
* @return int[]|false
|
||||
*/
|
||||
abstract protected function getBundledIds();
|
||||
|
||||
/**
|
||||
* Get a link to the individual comment, if available.
|
||||
*
|
||||
|
@ -104,4 +109,31 @@ trait DiscussionToolsEventTrait {
|
|||
return $this->language->truncateForVisual( $content, EchoDiscussionParser::DEFAULT_SNIPPET_LENGTH );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add mark-as-read params to a link array
|
||||
*
|
||||
* Taken from EchoEventPresentationModel::getPrimaryLinkWithMarkAsRead
|
||||
* TODO: Upstream to Echo?
|
||||
*
|
||||
* @param array $link Link
|
||||
* @return array
|
||||
*/
|
||||
protected function addMarkAsRead( $link ) {
|
||||
global $wgEchoCrossWikiNotifications;
|
||||
if ( $link ) {
|
||||
$eventIds = [ $this->event->getId() ];
|
||||
if ( $this->getBundledIds() ) {
|
||||
$eventIds = array_merge( $eventIds, $this->getBundledIds() );
|
||||
}
|
||||
|
||||
$queryParams = [ 'markasread' => implode( '|', $eventIds ) ];
|
||||
if ( $wgEchoCrossWikiNotifications ) {
|
||||
$queryParams['markasreadwiki'] = wfWikiID();
|
||||
}
|
||||
|
||||
$link['url'] = wfAppendQuery( $link['url'], $queryParams );
|
||||
}
|
||||
return $link;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,4 +44,15 @@ class EnhancedEchoEditUserTalkPresentationModel extends EchoEditUserTalkPresenta
|
|||
}
|
||||
return parent::getBodyMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function jsonSerialize() {
|
||||
$array = parent::jsonSerialize();
|
||||
|
||||
$array['links']['legacyPrimary'] = $this->addMarkAsRead( parent::getPrimaryLink() ) ?: [];
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,4 +27,15 @@ class EnhancedEchoMentionPresentationModel extends EchoMentionPresentationModel
|
|||
}
|
||||
return $linkInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function jsonSerialize() {
|
||||
$array = parent::jsonSerialize();
|
||||
|
||||
$array['links']['legacyPrimary'] = $this->addMarkAsRead( parent::getPrimaryLink() ) ?: [];
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,19 @@ class SubscribedNewCommentPresentationModel extends EchoEventPresentationModel {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function jsonSerialize() {
|
||||
$array = parent::jsonSerialize();
|
||||
|
||||
$legacyPrimaryLink = $this->getPrimaryLink();
|
||||
$legacyPrimaryLink['url'] = $this->section->getTitleWithSection()->getFullURL();
|
||||
$array['links']['legacyPrimary'] = $this->addMarkAsRead( $legacyPrimaryLink ) ?: [];
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue