Matthias Mullie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/284676
Change subject: Change (opt-out) noforn to (opt-in) crosswikisummary
......................................................................
Change (opt-out) noforn to (opt-in) crosswikisummary
I thought the name was confusing, and would be even more so
if we get real notifications from other sources.
Meanwhile also split $crossWikiSummary into 2 properties:
- 1 with the class
- 1 to indicate if it should be used
Change-Id: I0e83be7924c8c77680ea1ada3f2bd6a190ce6149
---
M i18n/en.json
M i18n/qqq.json
M includes/api/ApiEchoNotifications.php
M modules/api/mw.echo.api.ForeignAPIHandler.js
M modules/api/mw.echo.api.LocalAPIHandler.js
5 files changed, 60 insertions(+), 49 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/76/284676/1
diff --git a/i18n/en.json b/i18n/en.json
index 854af07..b6f6a87 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -233,7 +233,7 @@
"apihelp-query+notifications-paramvalue-format-html": "<span
class=\"apihelp-deprecated\">Deprecated</span>. Use <kbd>$1format=model</kbd>
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-crosswikisummary": "True to opt in
to a summary notification of 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).",
"apihelp-query+notifications-param-alertunreadfirst": "Whether to show
unread message notifications first (only used if groupbysection is set).",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 5bb22f5..c73a01a 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -224,7 +224,7 @@
"apihelp-query+notifications-paramvalue-format-html": "<span
class=\"apihelp-deprecated\">Deprecated</span>",
"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-crosswikisummary":
"{{doc-apihelp-param|query+notifications|crosswikisummary}}",
"apihelp-query+notifications-param-alertcontinue":
"{{doc-apihelp-param|query+notifications|alertcontinue}}",
"apihelp-query+notifications-param-unreadfirst":
"{{doc-apihelp-param|query+notifications|unreadfirst}}",
"apihelp-query+notifications-param-alertunreadfirst":
"{{doc-apihelp-param|query+notifications|alertunreadfirst}}",
diff --git a/includes/api/ApiEchoNotifications.php
b/includes/api/ApiEchoNotifications.php
index 2166fd9..9c14f76 100644
--- a/includes/api/ApiEchoNotifications.php
+++ b/includes/api/ApiEchoNotifications.php
@@ -1,6 +1,15 @@
<?php
class ApiEchoNotifications extends ApiQueryBase {
+ /**
+ * @var EchoForeignNotifications
+ */
+ protected $foreignNotifications;
+
+ /**
+ * @var bool
+ */
+ protected $crossWikiSummary = false;
public function __construct( $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'not' );
@@ -32,11 +41,8 @@
);
}
- if ( $params['noforn'] ) {
- $foreignNotifications = null;
- } else {
- $foreignNotifications = new EchoForeignNotifications(
$user );
- }
+ $this->foreignNotifications = new EchoForeignNotifications(
$this->getUser() );
+ $this->crossWikiSummary = $params['crosswikisummary'];
$result = array();
if ( in_array( 'list', $prop ) ) {
@@ -48,9 +54,9 @@
$params[$section . 'continue'],
$params['format'], $params[$section . 'unreadfirst']
);
- if ( $foreignNotifications &&
$foreignNotifications->getCount( $section ) > 0 ) {
+ if ( $this->crossWikiSummary &&
$this->foreignNotifications->getCount( $section ) > 0 ) {
// insert fake notification for
foreign notifications
- array_unshift(
$result[$section]['list'], $this->makeForeignNotification( $user,
$params['format'], $foreignNotifications, $section ) );
+ array_unshift(
$result[$section]['list'], $this->makeForeignNotification( $user,
$params['format'], $section ) );
}
$this->getResult()->setIndexedTagName(
$result[$section]['list'], 'notification' );
@@ -63,14 +69,11 @@
$params['filter'], $params['limit'],
$params['continue'], $params['format'], $params['unreadfirst']
);
- if ( $foreignNotifications ) {
- // if exactly 1 section is specified,
we consider only that section, otherwise
- // we pass 'null' to consider all
foreign notifications
- $section = count( $params['sections'] )
=== 1 ? reset( $params['sections'] ) : null;
-
- if ( $foreignNotifications->getCount(
$section ) > 0 ) {
- array_unshift( $result['list'],
$this->makeForeignNotification( $user, $params['format'],
$foreignNotifications, $section ) );
- }
+ // if exactly 1 section is specified, we
consider only that section, otherwise
+ // we pass 'null' to consider all foreign
notifications
+ $section = count( $params['sections'] ) === 1 ?
reset( $params['sections'] ) : null;
+ if ( $this->crossWikiSummary &&
$this->foreignNotifications->getCount( $section ) > 0 ) {
+ array_unshift( $result['list'],
$this->makeForeignNotification( $user, $params['format'], $section ) );
}
$this->getResult()->setIndexedTagName(
$result['list'], 'notification' );
@@ -80,7 +83,7 @@
if ( in_array( 'count', $prop ) ) {
$result = array_merge_recursive(
$result,
- $this->getPropCount( $user,
$params['sections'], $params['groupbysection'], $foreignNotifications )
+ $this->getPropCount( $user,
$params['sections'], $params['groupbysection'] )
);
}
@@ -221,16 +224,15 @@
* @param User $user
* @param string[] $sections
* @param boolean $groupBySection
- * @param EchoForeignNotifications|null $foreignNotifications
* @return array
*/
- protected function getPropCount( User $user, array $sections,
$groupBySection, EchoForeignNotifications $foreignNotifications = null ) {
+ protected function getPropCount( User $user, array $sections,
$groupBySection ) {
$result = array();
$notifUser = MWEchoNotifUser::newFromUser( $user );
// Always get total count
$rawCount = $notifUser->getNotificationCount();
- if ( $foreignNotifications ) {
- $rawCount += $foreignNotifications->getCount();
+ if ( $this->crossWikiSummary ) {
+ $rawCount += $this->foreignNotifications->getCount();
}
$result['rawcount'] = $rawCount;
$result['count'] =
EchoNotificationController::formatNotificationCount( $rawCount );
@@ -238,8 +240,8 @@
if ( $groupBySection ) {
foreach ( $sections as $section ) {
$rawCount = $notifUser->getNotificationCount(
/* $tryCache = */true, DB_SLAVE, $section );
- if ( $foreignNotifications ) {
- $rawCount +=
$foreignNotifications->getCount( $section );
+ if ( $this->crossWikiSummary ) {
+ $rawCount +=
$this->foreignNotifications->getCount( $section );
}
$result[$section]['rawcount'] = $rawCount;
$result[$section]['count'] =
EchoNotificationController::formatNotificationCount( $rawCount );
@@ -249,11 +251,12 @@
return $result;
}
- protected function makeForeignNotification( User $user, $format,
EchoForeignNotifications $foreignNotifications, $section = null ) {
- $wikis = $foreignNotifications->getWikis( $section );
- $count = $foreignNotifications->getCount( $section );
+ protected function makeForeignNotification( User $user, $format,
$section = null ) {
+ $wikis = $this->foreignNotifications->getWikis( $section );
+ $count = $this->foreignNotifications->getCount( $section );
// Sort wikis by timestamp, in descending order (newest first)
+ $foreignNotifications = $this->foreignNotifications;
usort( $wikis, function ( $a, $b ) use ( $foreignNotifications,
$section ) {
$aTimestamp = $foreignNotifications->getWikiTimestamp(
$a, $section ) ?: new MWTimestamp( 0 );
$bTimestamp = $foreignNotifications->getWikiTimestamp(
$b, $section ) ?: new MWTimestamp( 0 );
@@ -276,7 +279,7 @@
) );
$row->notification_user = $user->getId();
- $row->notification_timestamp =
$foreignNotifications->getTimestamp( $section );
+ $row->notification_timestamp =
$this->foreignNotifications->getTimestamp( $section );
$row->notification_read_timestamp = null;
$row->notification_bundle_base = 1;
$row->notification_bundle_hash = md5( 'bogus' );
@@ -289,10 +292,10 @@
// Add cross-wiki-specific data
$output['section'] = $section ?: 'all';
$output['count'] = $count;
- $output['sources'] = $foreignNotifications->getApiEndpoints(
$wikis );
+ $output['sources'] =
$this->foreignNotifications->getApiEndpoints( $wikis );
// Add timestamp information
foreach ( $output['sources'] as $wiki => &$data ) {
- $data['ts'] = $foreignNotifications->getWikiTimestamp(
$wiki, $section )->getTimestamp( TS_MW );
+ $data['ts'] =
$this->foreignNotifications->getWikiTimestamp( $wiki, $section )->getTimestamp(
TS_MW );
}
return $output;
}
@@ -335,7 +338,12 @@
),
ApiBase::PARAM_HELP_MSG_PER_VALUE => array(),
),
- 'noforn' => false,
+ // create "x notifications from y wikis" notification
bundle &
+ // include unread counts from other wikis in prop=count
results
+ 'crosswikisummary' => array(
+ ApiBase::PARAM_TYPE => 'boolean',
+ ApiBase::PARAM_DFLT => false,
+ ),
'limit' => array(
ApiBase::PARAM_TYPE => 'limit',
ApiBase::PARAM_DFLT => 20,
diff --git a/modules/api/mw.echo.api.ForeignAPIHandler.js
b/modules/api/mw.echo.api.ForeignAPIHandler.js
index 5abc835..5c89667 100644
--- a/modules/api/mw.echo.api.ForeignAPIHandler.js
+++ b/modules/api/mw.echo.api.ForeignAPIHandler.js
@@ -16,26 +16,19 @@
// Parent constructor
mw.echo.api.ForeignAPIHandler.parent.call( this, config );
- // Add 'noforn' setting to foreign APIs
- $.extend( true, this.typeParams, {
- message: {
- notnoforn: 1,
- notfilter: '!read'
- },
- alert: {
- notnoforn: 1,
- notfilter: '!read'
- },
- all: {
- notnoforn: 1,
- notfilter: '!read'
- }
- } );
-
this.api = new mw.ForeignApi( apiUrl );
};
/* Setup */
OO.inheritClass( mw.echo.api.ForeignAPIHandler,
mw.echo.api.LocalAPIHandler );
+
+ /**
+ * @inheritdoc
+ */
+ mw.echo.api.ForeignAPIHandler.prototype.getTypeParams = function ( type
) {
+ return $.extend( {}, this.typeParams[ type ], {
+ notfilter: '!read'
+ } );
+ }
} )( mediaWiki, jQuery );
diff --git a/modules/api/mw.echo.api.LocalAPIHandler.js
b/modules/api/mw.echo.api.LocalAPIHandler.js
index 737683e..025f91e 100644
--- a/modules/api/mw.echo.api.LocalAPIHandler.js
+++ b/modules/api/mw.echo.api.LocalAPIHandler.js
@@ -1,4 +1,4 @@
-( function ( mw ) {
+( function ( mw, $ ) {
/**
* Notification API handler
*
@@ -91,6 +91,7 @@
notmessageunreadfirst: 1,
notlimit: this.limit,
notprop: 'count',
+ notcrosswikisummary: 1,
uselang: this.userLang
};
@@ -103,4 +104,13 @@
}
} );
};
-} )( mediaWiki );
+
+ /**
+ * @inheritdoc
+ */
+ mw.echo.api.LocalAPIHandler.prototype.getTypeParams = function ( type )
{
+ return $.extend( {}, this.typeParams[ type ], {
+ notcrosswikisummary: 1
+ } );
+ }
+} )( mediaWiki, jQuery );
--
To view, visit https://gerrit.wikimedia.org/r/284676
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0e83be7924c8c77680ea1ada3f2bd6a190ce6149
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits