mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-23 23:44:53 +00:00
Merge "Add seen time to output of API, in ISO 8601 format"
This commit is contained in:
commit
3fd553a152
|
@ -39,10 +39,12 @@ class EchoSeenTime {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $type Type of seen time to get
|
||||
* @param int $flags BagOStuff::READ_LATEST to use the master
|
||||
* @return string|bool false if no stored time
|
||||
* @param int $format Format to return time in, defaults to TS_MW
|
||||
* @return string|bool Timestamp in specified format, or false if no stored time
|
||||
*/
|
||||
public function getTime( $type = 'all', $flags = 0 ) {
|
||||
public function getTime( $type = 'all', $flags = 0, $format = TS_MW ) {
|
||||
$vals = array();
|
||||
if ( $type === 'all' ) {
|
||||
foreach ( self::$allowedTypes as $allowed ) {
|
||||
|
@ -62,7 +64,13 @@ class EchoSeenTime {
|
|||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
if ( $data !== false ) {
|
||||
$formattedData = wfTimestamp( $format, $data );
|
||||
} else {
|
||||
$formattedData = $data;
|
||||
}
|
||||
|
||||
return $formattedData;
|
||||
}
|
||||
|
||||
public function setTime( $time, $type = 'all' ) {
|
||||
|
|
|
@ -131,6 +131,13 @@ class ApiEchoNotifications extends ApiCrossWikiBase {
|
|||
);
|
||||
}
|
||||
|
||||
if ( in_array( 'seenTime', $prop ) ) {
|
||||
$result = array_merge_recursive(
|
||||
$result,
|
||||
$this->getPropSeenTime( $user, $params['sections'], $params['groupbysection'] )
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -301,6 +308,31 @@ class ApiEchoNotifications extends ApiCrossWikiBase {
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal helper method for getting property 'seenTime' data
|
||||
* @param User $user
|
||||
* @param string[] $sections
|
||||
* @param boolean $groupBySection
|
||||
* @return array
|
||||
*/
|
||||
protected function getPropSeenTime( User $user, array $sections, $groupBySection ) {
|
||||
$result = array();
|
||||
$seenTimeHelper = EchoSeenTime::newFromUser( $user );
|
||||
|
||||
if ( $groupBySection ) {
|
||||
foreach ( $sections as $section ) {
|
||||
$result[$section]['seenTime'] = $seenTimeHelper->getTime( $section, /*flags*/ 0, TS_ISO_8601 );
|
||||
}
|
||||
} else {
|
||||
$result['seenTime'] = array();
|
||||
foreach ( $sections as $section ) {
|
||||
$result['seenTime'][$section] = $seenTimeHelper->getTime( $section, /*flags*/ 0, TS_ISO_8601 );
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and format a "fake" notification to represent foreign notifications.
|
||||
* @param User $user
|
||||
|
@ -529,6 +561,7 @@ class ApiEchoNotifications extends ApiCrossWikiBase {
|
|||
ApiBase::PARAM_TYPE => array(
|
||||
'list',
|
||||
'count',
|
||||
'seenTime',
|
||||
),
|
||||
ApiBase::PARAM_DFLT => 'list',
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue