Actually respect notnoforn parameter

The parameter was added, but it wasn't looked at by any code at all.

Change-Id: Ib6b13e520621ad7c230a297ebae61d6a16dce57a
This commit is contained in:
Roan Kattouw 2016-01-15 01:19:40 -08:00 committed by Matthias Mullie
parent e55754857c
commit e22ca687dc

View file

@ -18,7 +18,11 @@ class ApiEchoNotifications extends ApiQueryBase {
$params = $this->extractRequestParams(); $params = $this->extractRequestParams();
$prop = $params['prop']; $prop = $params['prop'];
$foreignNotifications = new EchoForeignNotifications( $user ); if ( $params['noforn'] ) {
$foreignNotifications = null;
} else {
$foreignNotifications = new EchoForeignNotifications( $user );
}
$result = array(); $result = array();
if ( in_array( 'list', $prop ) ) { if ( in_array( 'list', $prop ) ) {
@ -30,7 +34,7 @@ class ApiEchoNotifications extends ApiQueryBase {
$params[$section . 'continue'], $params['format'], $params[$section . 'unreadfirst'] $params[$section . 'continue'], $params['format'], $params[$section . 'unreadfirst']
); );
if ( $foreignNotifications->getCount( $section ) > 0 ) { if ( $foreignNotifications && $foreignNotifications->getCount( $section ) > 0 ) {
// insert fake notification for foreign notifications // insert fake notification for foreign notifications
$result[$section]['list'][-1] = $this->makeForeignNotification( $user, $params['format'], $foreignNotifications, $section ); $result[$section]['list'][-1] = $this->makeForeignNotification( $user, $params['format'], $foreignNotifications, $section );
} }
@ -50,10 +54,12 @@ class ApiEchoNotifications extends ApiQueryBase {
$params['filter'], $params['limit'], $params['continue'], $params['format'] $params['filter'], $params['limit'], $params['continue'], $params['format']
); );
// insert fake notifications for foreign notifications if ( $foreignNotifications ) {
foreach ( EchoAttributeManager::$sections as $i => $section ) { // insert fake notifications for foreign notifications
if ( $foreignNotifications->getCount( $section ) > 0 ) { foreach ( EchoAttributeManager::$sections as $i => $section ) {
$result['list'][-$i-1] = $this->makeForeignNotification( $user, $params['format'], $foreignNotifications, $section ); if ( $foreignNotifications->getCount( $section ) > 0 ) {
$result['list'][-$i-1] = $this->makeForeignNotification( $user, $params['format'], $foreignNotifications, $section );
}
} }
} }
@ -67,7 +73,9 @@ class ApiEchoNotifications extends ApiQueryBase {
// add API endpoint for each of the wikis where notification data // add API endpoint for each of the wikis where notification data
// can be queried from // can be queried from
$result['sources'] = $foreignNotifications->getApiEndpoints( $foreignNotifications->getWikis() ); if ( $foreignNotifications ) {
$result['sources'] = $foreignNotifications->getApiEndpoints( $foreignNotifications->getWikis() );
}
} }
if ( in_array( 'count', $prop ) ) { if ( in_array( 'count', $prop ) ) {
@ -214,22 +222,26 @@ class ApiEchoNotifications extends ApiQueryBase {
* @param User $user * @param User $user
* @param string[] $sections * @param string[] $sections
* @param boolean $groupBySection * @param boolean $groupBySection
* @param EchoForeignNotifications $foreignNotifications * @param EchoForeignNotifications|null $foreignNotifications
* @return array * @return array
*/ */
protected function getPropCount( User $user, array $sections, $groupBySection, EchoForeignNotifications $foreignNotifications ) { protected function getPropCount( User $user, array $sections, $groupBySection, EchoForeignNotifications $foreignNotifications = null ) {
$result = array(); $result = array();
$notifUser = MWEchoNotifUser::newFromUser( $user ); $notifUser = MWEchoNotifUser::newFromUser( $user );
// Always get total count // Always get total count
$rawCount = $notifUser->getNotificationCount(); $rawCount = $notifUser->getNotificationCount();
$rawCount += $foreignNotifications->getCount(); if ( $foreignNotifications ) {
$rawCount += $foreignNotifications->getCount();
}
$result['rawcount'] = $rawCount; $result['rawcount'] = $rawCount;
$result['count'] = EchoNotificationController::formatNotificationCount( $rawCount ); $result['count'] = EchoNotificationController::formatNotificationCount( $rawCount );
if ( $groupBySection ) { if ( $groupBySection ) {
foreach ( $sections as $section ) { foreach ( $sections as $section ) {
$rawCount = $notifUser->getNotificationCount( /* $tryCache = */true, DB_SLAVE, $section ); $rawCount = $notifUser->getNotificationCount( /* $tryCache = */true, DB_SLAVE, $section );
$rawCount += $foreignNotifications->getCount( $section ); if ( $foreignNotifications ) {
$rawCount += $foreignNotifications->getCount( $section );
}
$result[$section]['rawcount'] = $rawCount; $result[$section]['rawcount'] = $rawCount;
$result[$section]['count'] = EchoNotificationController::formatNotificationCount( $rawCount ); $result[$section]['count'] = EchoNotificationController::formatNotificationCount( $rawCount );
} }