mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-28 01:30:15 +00:00
Cleanup transition flags
$wgEchoSectionTransition was introduced when we moved some notification types between sections (alert, message). $wgEchoBundleTransition was introduced when we made bundles dynamic and expandable. Both flags have been OFF for years and are not needed anymore. This patch removes all traces of them. Bug: T140710 Change-Id: I16a5d54b09e71997f80208db6f4fbdb040d03ab1
This commit is contained in:
parent
5796d46565
commit
1017054b88
|
@ -452,12 +452,6 @@
|
|||
"EchoSharedTrackingCluster": {
|
||||
"value": false
|
||||
},
|
||||
"EchoSectionTransition": {
|
||||
"value": false
|
||||
},
|
||||
"EchoBundleTransition": {
|
||||
"value": false
|
||||
},
|
||||
"EchoMaxUpdateCount": {
|
||||
"value": 2000
|
||||
},
|
||||
|
|
|
@ -640,87 +640,15 @@ class MWEchoNotifUser {
|
|||
return $this->foreignNotifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data about foreign notifications from the foreign wikis' APIs.
|
||||
*
|
||||
* This is used when $wgEchoSectionTransition or $wgEchoBundleTransition is enabled,
|
||||
* to deal with untrustworthy echo_unread_wikis entries. This method fetches the list of
|
||||
* wikis that have any unread notifications at all from the echo_unread_wikis table, then
|
||||
* queries their APIs to find the per-section counts and timestamps for those wikis.
|
||||
*
|
||||
* The results of this function are cached in the NotifUser object.
|
||||
* @return array[] [ (str) wiki => [ (str) section => [ 'count' => (int) count, 'timestamp' => (str) ts ] ] ]
|
||||
*/
|
||||
protected function getForeignData() {
|
||||
if ( $this->mForeignData ) {
|
||||
return $this->mForeignData;
|
||||
}
|
||||
|
||||
$potentialWikis = $this->getForeignNotifications()->getWikis();
|
||||
$foreignReq = new EchoForeignWikiRequest(
|
||||
$this->mUser,
|
||||
[
|
||||
'action' => 'query',
|
||||
'meta' => 'notifications',
|
||||
'notprop' => 'count|list',
|
||||
'notgroupbysection' => '1',
|
||||
'notunreadfirst' => '1',
|
||||
],
|
||||
$potentialWikis,
|
||||
'notwikis'
|
||||
);
|
||||
$foreignResults = $foreignReq->execute();
|
||||
|
||||
$this->mForeignData = [];
|
||||
foreach ( $foreignResults as $wiki => $result ) {
|
||||
if ( !isset( $result['query']['notifications'] ) ) {
|
||||
continue;
|
||||
}
|
||||
$data = $result['query']['notifications'];
|
||||
foreach ( EchoAttributeManager::$sections as $section ) {
|
||||
if ( isset( $data[$section]['rawcount'] ) ) {
|
||||
$this->mForeignData[$wiki][$section]['count'] = $data[$section]['rawcount'];
|
||||
}
|
||||
if ( isset( $data[$section]['list'][0] ) ) {
|
||||
$this->mForeignData[$wiki][$section]['timestamp'] = $data[$section]['list'][0]['timestamp']['mw'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->mForeignData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of foreign notifications in a given section.
|
||||
* @param string $section One of EchoAttributeManager::$sections
|
||||
* @return int Number of foreign notifications
|
||||
*/
|
||||
protected function getForeignCount( $section = EchoAttributeManager::ALL ) {
|
||||
global $wgEchoSectionTransition, $wgEchoBundleTransition;
|
||||
$count = 0;
|
||||
if (
|
||||
// In section transition mode, we don't trust the individual echo_unread_wikis rows
|
||||
// but we do trust that alert+message=all. In bundle transition mode, we don't trust
|
||||
// that either, but we do trust that wikis with rows in the table have unread notifications
|
||||
// and wikis without rows in the table don't.
|
||||
( $wgEchoSectionTransition && $section !== EchoAttributeManager::ALL ) ||
|
||||
$wgEchoBundleTransition
|
||||
) {
|
||||
$foreignData = $this->getForeignData();
|
||||
foreach ( $foreignData as $data ) {
|
||||
if ( $section === EchoAttributeManager::ALL ) {
|
||||
foreach ( $data as $subData ) {
|
||||
if ( isset( $subData['count'] ) ) {
|
||||
$count += $subData['count'];
|
||||
}
|
||||
}
|
||||
} elseif ( isset( $data[$section]['count'] ) ) {
|
||||
$count += $data[$section]['count'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$count += $this->getForeignNotifications()->getCount( $section );
|
||||
}
|
||||
return self::capNotificationCount( $count );
|
||||
return self::capNotificationCount(
|
||||
$this->getForeignNotifications()->getCount( $section )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -730,34 +658,7 @@ class MWEchoNotifUser {
|
|||
* there aren't any
|
||||
*/
|
||||
protected function getForeignTimestamp( $section = EchoAttributeManager::ALL ) {
|
||||
global $wgEchoSectionTransition, $wgEchoBundleTransition;
|
||||
|
||||
if (
|
||||
// In section transition mode, we don't trust the individual echo_unread_wikis rows
|
||||
// but we do trust that alert+message=all. In bundle transition mode, we don't trust
|
||||
// that either, but we do trust that wikis with rows in the table have unread notifications
|
||||
// and wikis without rows in the table don't.
|
||||
( $wgEchoSectionTransition && $section !== EchoAttributeManager::ALL ) ||
|
||||
$wgEchoBundleTransition
|
||||
) {
|
||||
$foreignTime = -1;
|
||||
$foreignData = $this->getForeignData();
|
||||
foreach ( $foreignData as $data ) {
|
||||
if ( $section === EchoAttributeManager::ALL ) {
|
||||
foreach ( $data as $subData ) {
|
||||
if ( isset( $subData['timestamp'] ) ) {
|
||||
$foreignTime = max( $foreignTime, $subData['timestamp'] );
|
||||
}
|
||||
}
|
||||
} elseif ( isset( $data[$section]['timestamp'] ) ) {
|
||||
$foreignTime = max( $foreignTime, $data[$section]['timestamp'] );
|
||||
}
|
||||
}
|
||||
$foreignTime = $foreignTime === -1 ? false : new MWTimestamp( $foreignTime );
|
||||
} else {
|
||||
$foreignTime = $this->getForeignNotifications()->getTimestamp( $section );
|
||||
}
|
||||
return $foreignTime;
|
||||
return $this->getForeignNotifications()->getTimestamp( $section );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -371,54 +371,6 @@ class ApiEchoNotifications extends ApiQueryBase {
|
|||
$format,
|
||||
$section = EchoAttributeManager::ALL
|
||||
) {
|
||||
global $wgEchoSectionTransition, $wgEchoBundleTransition;
|
||||
if (
|
||||
( $wgEchoSectionTransition && $section !== EchoAttributeManager::ALL ) ||
|
||||
$wgEchoBundleTransition
|
||||
) {
|
||||
// In section transition mode we trust that echo_unread_wikis is accurate for the total of alerts+messages,
|
||||
// but not for each section individually (i.e. we don't trust that notifications won't be misclassified).
|
||||
// We get all wikis that have any notifications at all according to the euw table,
|
||||
// and query them to find out what's really there.
|
||||
// In bundle transition mode, we trust that notifications are classified correctly, but we don't
|
||||
// trust the counts in the table.
|
||||
$potentialWikis = $this->getForeignNotifications()->getWikis(
|
||||
$wgEchoSectionTransition ? EchoAttributeManager::ALL : $section );
|
||||
if ( !$potentialWikis ) {
|
||||
return false;
|
||||
}
|
||||
$foreignResults = $this->getFromForeign( $potentialWikis,
|
||||
[ $this->getModulePrefix() . 'filter' => '!read' ] );
|
||||
|
||||
$countsByWiki = [];
|
||||
$timestampsByWiki = [];
|
||||
foreach ( $foreignResults as $wiki => $result ) {
|
||||
if ( isset( $result['query']['notifications']['list'] ) ) {
|
||||
$notifs = $result['query']['notifications']['list'];
|
||||
$countsByWiki[$wiki] = intval( $result['query']['notifications']['count'] );
|
||||
} elseif ( isset( $result['query']['notifications'][$section]['list'] ) ) {
|
||||
$notifs = $result['query']['notifications'][$section]['list'];
|
||||
$countsByWiki[$wiki] = intval( $result['query']['notifications'][$section]['count'] );
|
||||
} else {
|
||||
$notifs = false;
|
||||
$countsByWiki[$wiki] = 0;
|
||||
}
|
||||
if ( $notifs ) {
|
||||
$timestamps = array_filter( array_map( function ( $n ) {
|
||||
return $n['timestamp']['mw'];
|
||||
}, $notifs ) );
|
||||
$timestampsByWiki[$wiki] = $timestamps ? max( $timestamps ) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
$wikis = array_keys( $timestampsByWiki );
|
||||
$count = array_sum( $countsByWiki );
|
||||
$maxTimestamp = new MWTimestamp( $timestampsByWiki ? max( $timestampsByWiki ) : 0 );
|
||||
$timestampsByWiki = array_map( function ( $ts ) {
|
||||
return new MWTimestamp( $ts );
|
||||
}, $timestampsByWiki );
|
||||
} else {
|
||||
// In non-transition mode, or when querying all sections, we can trust the euw table
|
||||
$wikis = $this->getForeignNotifications()->getWikis( $section );
|
||||
$count = $this->getForeignNotifications()->getCount( $section );
|
||||
$maxTimestamp = $this->getForeignNotifications()->getTimestamp( $section );
|
||||
|
@ -426,7 +378,6 @@ class ApiEchoNotifications extends ApiQueryBase {
|
|||
foreach ( $wikis as $wiki ) {
|
||||
$timestampsByWiki[$wiki] = $this->getForeignNotifications()->getWikiTimestamp( $wiki, $section );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $count === 0 || $wikis === [] ) {
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue