From e8d1f6a88833c039bdf5d97654ece082d60c0df3 Mon Sep 17 00:00:00 2001 From: Matthias Mullie Date: Thu, 21 Apr 2016 11:13:02 +0200 Subject: [PATCH] Remove param index It's (mostly) unused, and it would become problematic once we have notifications from multiple places (where those ids could conflict) Change-Id: Ib3bb5ae1e5689037b38290c9ce3d8691f52582b0 --- i18n/en.json | 1 - i18n/qqq.json | 1 - includes/api/ApiEchoNotifications.php | 29 ------------------- modules/api/mw.echo.api.APIHandler.js | 2 +- modules/special/ext.echo.special.js | 12 ++++---- .../phpunit/api/ApiEchoNotificationsTest.php | 7 ++--- 6 files changed, 8 insertions(+), 44 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index 854af07c0..799829eb6 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -232,7 +232,6 @@ "apihelp-query+notifications-paramvalue-format-flyout": "Deprecated. Use $1format=model for raw data", "apihelp-query+notifications-paramvalue-format-html": "Deprecated. Use $1format=model for raw data", "apihelp-query+notifications-param-limit": "The maximum number of notifications to return.", - "apihelp-query+notifications-param-index": "If specified, a list of notification IDs, in order, will be returned.", "apihelp-query+notifications-param-noforn": "True to opt out of data about notifications on foreign wikis.", "apihelp-query+notifications-param-alertcontinue": "When more alert results are available, use this to continue.", "apihelp-query+notifications-param-unreadfirst": "Whether to show unread notifications first (only used if groupbysection is not set).", diff --git a/i18n/qqq.json b/i18n/qqq.json index 5bb22f550..39ebbb945 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -223,7 +223,6 @@ "apihelp-query+notifications-paramvalue-format-flyout": "Deprecated", "apihelp-query+notifications-paramvalue-format-html": "Deprecated", "apihelp-query+notifications-param-limit": "{{doc-apihelp-param|query+notifications|limit}}", - "apihelp-query+notifications-param-index": "{{doc-apihelp-param|query+notifications|index}}", "apihelp-query+notifications-param-noforn": "{{doc-apihelp-param|query+notifications|noforn}}", "apihelp-query+notifications-param-alertcontinue": "{{doc-apihelp-param|query+notifications|alertcontinue}}", "apihelp-query+notifications-param-unreadfirst": "{{doc-apihelp-param|query+notifications|unreadfirst}}", diff --git a/includes/api/ApiEchoNotifications.php b/includes/api/ApiEchoNotifications.php index 4dbed4750..5897e2786 100644 --- a/includes/api/ApiEchoNotifications.php +++ b/includes/api/ApiEchoNotifications.php @@ -54,11 +54,6 @@ class ApiEchoNotifications extends ApiQueryBase { } $this->getResult()->setIndexedTagName( $result[$section]['list'], 'notification' ); - // 'index' is built on top of 'list' - if ( in_array( 'index', $prop ) ) { - $result[$section]['index'] = $this->getPropIndex( $result[$section]['list'] ); - $this->getResult()->setIndexedTagName( $result[$section]['index'], 'id' ); - } } } else { $attributeManager = EchoAttributeManager::newFromGlobalVars(); @@ -79,11 +74,6 @@ class ApiEchoNotifications extends ApiQueryBase { } $this->getResult()->setIndexedTagName( $result['list'], 'notification' ); - // 'index' is built on top of 'list' - if ( in_array( 'index', $prop ) ) { - $result['index'] = $this->getPropIndex( $result['list'] ); - $this->getResult()->setIndexedTagName( $result['index'], 'id' ); - } } } @@ -259,23 +249,6 @@ class ApiEchoNotifications extends ApiQueryBase { return $result; } - /** - * Internal helper method for getting property 'index' data - * @param array $list - * @return array - */ - protected function getPropIndex( $list ) { - $result = array(); - foreach ( array_keys( $list ) as $key ) { - // Don't include the XML tag name ('_element' key) - if ( $key != '_element' ) { - $result[] = $key; - } - } - - return $result; - } - protected function makeForeignNotification( User $user, $format, EchoForeignNotifications $foreignNotifications, $section = null ) { $wikis = $foreignNotifications->getWikis( $section ); $count = $foreignNotifications->getCount( $section ); @@ -340,7 +313,6 @@ class ApiEchoNotifications extends ApiQueryBase { ApiBase::PARAM_TYPE => array( 'list', 'count', - 'index', ), ApiBase::PARAM_DFLT => 'list', ), @@ -371,7 +343,6 @@ class ApiEchoNotifications extends ApiQueryBase { ApiBase::PARAM_MAX => ApiBase::LIMIT_SML1, ApiBase::PARAM_MAX2 => ApiBase::LIMIT_SML2, ), - 'index' => false, 'continue' => array( ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', ), diff --git a/modules/api/mw.echo.api.APIHandler.js b/modules/api/mw.echo.api.APIHandler.js index fb3b2d92b..0100e9aeb 100644 --- a/modules/api/mw.echo.api.APIHandler.js +++ b/modules/api/mw.echo.api.APIHandler.js @@ -68,7 +68,7 @@ notformat: 'model', notlimit: this.limit, notunreadfirst: 1, - notprop: 'index|list|count', + notprop: 'list|count', uselang: this.userLang }, this.getTypeParams( type ) ); diff --git a/modules/special/ext.echo.special.js b/modules/special/ext.echo.special.js index feaba07d6..30c401eee 100644 --- a/modules/special/ext.echo.special.js +++ b/modules/special/ext.echo.special.js @@ -59,7 +59,7 @@ * Load more notification records. */ loadMore: function () { - var notifications, data, container, $li, + var notifications, container, $li, api = new mw.Api( { ajax: { cache: false } } ), seenTime = mw.config.get( 'wgEchoSeenTime' ), that = this, @@ -68,7 +68,7 @@ action: 'query', meta: 'notifications', notformat: 'special', - notprop: 'index|list', + notprop: 'list', notcontinue: this.notcontinue, notlimit: mw.config.get( 'wgEchoDisplayNum' ), uselang: useLang @@ -79,9 +79,7 @@ notifications = result.query.notifications; unread = []; - $.each( notifications.index, function ( index, id ) { - data = notifications.list[ id ]; - + $.each( notifications.list, function ( index, data ) { if ( that.header !== data.timestamp.date ) { that.header = data.timestamp.date; $( '
  • ' ).addClass( 'mw-echo-date-section' ).append( that.header ).appendTo( container ); @@ -89,7 +87,7 @@ $li = $( '
  • ' ) .data( 'details', data ) - .data( 'id', id ) + .data( 'id', data.id ) .addClass( 'mw-echo-notification' ) .attr( { 'data-notification-category': data.category, @@ -101,7 +99,7 @@ if ( !data.read ) { $li.addClass( 'mw-echo-unread' ); - unread.push( id ); + unread.push( data.id ); } if ( seenTime !== null && data.timestamp.mw > seenTime ) { diff --git a/tests/phpunit/api/ApiEchoNotificationsTest.php b/tests/phpunit/api/ApiEchoNotificationsTest.php index cd1a9732f..3ce3726fc 100644 --- a/tests/phpunit/api/ApiEchoNotificationsTest.php +++ b/tests/phpunit/api/ApiEchoNotificationsTest.php @@ -15,7 +15,7 @@ class ApiEchoNotificationsTest extends ApiTestCase { 'notsections' => 'alert|message', 'notgroupbysection' => 1, 'notlimit' => 10, - 'notprop' => 'index|list|count' ) ); + 'notprop' => 'list|count' ) ); $this->assertArrayHasKey( 'query', $data[0] ); $this->assertArrayHasKey( 'notifications', $data[0]['query'] ); @@ -31,7 +31,6 @@ class ApiEchoNotificationsTest extends ApiTestCase { $alert = $result['alert']; $this->assertArrayHasKey( 'list', $alert ); $this->assertArrayHasKey( 'continue', $alert ); - $this->assertArrayHasKey( 'index', $alert ); $this->assertArrayHasKey( 'rawcount', $alert ); $this->assertArrayHasKey( 'count', $alert ); @@ -40,7 +39,6 @@ class ApiEchoNotificationsTest extends ApiTestCase { $message = $result['message']; $this->assertArrayHasKey( 'list', $message ); $this->assertArrayHasKey( 'continue', $message ); - $this->assertArrayHasKey( 'index', $message ); $this->assertArrayHasKey( 'rawcount', $message ); $this->assertArrayHasKey( 'count', $message ); } @@ -51,7 +49,7 @@ class ApiEchoNotificationsTest extends ApiTestCase { 'meta' => 'notifications', 'notsections' => 'alert|message', 'notlimit' => 10, - 'notprop' => 'index|list|count' ) ); + 'notprop' => 'list|count' ) ); $this->assertArrayHasKey( 'query', $data[0] ); $this->assertArrayHasKey( 'notifications', $data[0]['query'] ); @@ -62,7 +60,6 @@ class ApiEchoNotificationsTest extends ApiTestCase { $this->assertArrayHasKey( 'rawcount', $result ); $this->assertArrayHasKey( 'list', $result ); $this->assertArrayHasKey( 'continue', $result ); - $this->assertArrayHasKey( 'index', $result ); $this->assertTrue( !isset( $result['alert'] ) ); $this->assertTrue( !isset( $result['message'] ) );