jenkins-bot has submitted this change and it was merged.
Change subject: Presentation model for page-linked
......................................................................
Presentation model for page-linked
Bug: T116843
Change-Id: Id9894b98a0dd7554a529ff763aaf0f719e36152b
---
M Echo.php
M autoload.php
M i18n/en.json
M i18n/qqq.json
A includes/formatters/PageLinkedPresentationModel.php
5 files changed, 87 insertions(+), 6 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Echo.php b/Echo.php
index fe5a3ae..baf7c8c 100644
--- a/Echo.php
+++ b/Echo.php
@@ -354,6 +354,7 @@
'icon' => 'revert',
),
'page-linked' => array(
+ 'presentation-model' => 'EchoPageLinkedPresentationModel',
'user-locators' => array(
'EchoUserLocator::locateArticleCreator',
),
@@ -367,8 +368,6 @@
'title-params' => array( 'agent', 'title', 'link-from-page' ),
'bundle-message' => 'notification-page-linked-bundle',
'bundle-params' => array( 'agent', 'title', 'link-from-page',
'link-from-page-other-display', 'link-from-page-other-count' ),
- 'flyout-message' => 'notification-page-linked-flyout',
- 'flyout-params' => array( 'agent', 'title', 'link-from-page' ),
'email-subject-message' =>
'notification-page-linked-email-subject',
'email-subject-params' => array(),
'email-body-batch-message' =>
'notification-page-linked-email-batch-body',
diff --git a/autoload.php b/autoload.php
index dd2867d..63ee9a9 100644
--- a/autoload.php
+++ b/autoload.php
@@ -76,6 +76,7 @@
'EchoNotifier' => __DIR__ . '/Notifier.php',
'EchoOnWikiList' => __DIR__ . '/includes/ContainmentSet.php',
'EchoPageLinkFormatter' => __DIR__ .
'/includes/formatters/PageLinkFormatter.php',
+ 'EchoPageLinkedPresentationModel' => __DIR__ .
'/includes/formatters/PageLinkedPresentationModel.php',
'EchoRevertedPresentationModel' => __DIR__ .
'/includes/formatters/RevertedPresentationModel.php',
'EchoRevisionLocalCache' => __DIR__ .
'/includes/cache/RevisionLocalCache.php',
'EchoRowUpdateGenerator' => __DIR__ . '/includes/BatchRowUpdate.php',
diff --git a/i18n/en.json b/i18n/en.json
index 14ae53e..445e580 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -62,7 +62,9 @@
"notification-edit-talk-page-flyout2": "$1 {{GENDER:$1|left}} a message
on your [[User talk:$2#$3|talk page]].",
"notification-edit-talk-page-flyout-with-section": "$1
{{GENDER:$1|left}} a message on your talk page in \"[[User talk:$2#$3|$4]]\".",
"notification-page-linked": "[[:$2]] was {{GENDER:$1|linked}} from
[[:$3]]. [[Special:WhatLinksHere/$2|See all links to this page]].",
- "notification-page-linked-flyout": "[[:$2]] was {{GENDER:$1|linked}}
from [[:$3]].",
+ "notification-header-page-linked": "$3 was {{GENDER:$2|linked}} from
$4.",
+ "notification-bundle-header-page-linked": "$3 was {{GENDER:$2|linked}}
from $4 and $5 other {{PLURAL:$6|page|pages}}.",
+ "notification-link-text-what-links-here": "See all links to this page",
"notification-add-comment2": "[[User:$1|$1]] {{GENDER:$1|commented}} on
\"[[$3|$2]]\" on the \"$4\" talk page.",
"notification-add-talkpage-topic2": "[[User:$1|$1]]
{{GENDER:$1|posted}} a new topic \"$2\" on [[$3]].",
"notification-add-talkpage-topic-yours2": "[[User:$1|$1]]
{{GENDER:$1|sent}} you a message: \"[[$3#$2|$2]]\".",
@@ -113,7 +115,6 @@
"echo-date-yesterday": "Yesterday",
"echo-load-more-error": "An error occurred while fetching more
results.",
"notification-edit-talk-page-bundle": "$1 and $3
{{PLURAL:$4|other|others}} {{GENDER:$1|left}} a message on your [[User
talk:$2|talk page]].",
- "notification-page-linked-bundle": "$2 was {{GENDER:$1|linked}} from $3
and $4 other {{PLURAL:$5|page|pages}}. [[Special:WhatLinksHere/$2|See all links
to this page]]",
"notification-edit-user-talk-email-batch-bundle-body": "$1 and $2
{{PLURAL:$3|other|others}} {{GENDER:$1|left}} a message on your talk page.",
"notification-page-linked-email-batch-bundle-body": "$2 was
{{GENDER:$1|linked}} from $3 and $4 other {{PLURAL:$5|page|pages}}.",
"echo-email-batch-separator": "--",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 89cf271..a0a98f0 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -83,7 +83,9 @@
"notification-edit-talk-page-flyout2": "Flyout-specific format for
displaying notifications of a user talk page being edited.\n\nParameters:\n* $1
- the username of the person who edited, plain text. Can be used for GENDER.\n*
$2 - the current user's name, used in the link to their talk page\n* $3 - the
section title of the discussion, if any, used in the link to their talk
page\nSee also:\n* {{msg-mw|Notification-edit-talk-page2}}\n*
{{msg-mw|Notification-add-talkpage-topic2}}",
"notification-edit-talk-page-flyout-with-section": "Flyout-specific
format for displaying notifications of a user talk page being edited with a new
section or new comment.\n\nParameters:\n* $1 - the username of the person who
edited, plain text. Can be used for GENDER.\n* $2 - the username of current
user, used in the link to their talk page\n* $3 - the section title of the
discussion, if any, used in the link to their talk page\n* $4 - the raw section
title text",
"notification-page-linked": "Format for displaying notifications of
articles being linked. Parameters:\n* $1 - the username of the person who
linked the page, plain text. Can be used for GENDER.\n* $2 - the page being
linked\n* $3 - the page linked from\nSee also:\n*
{{msg-mw|Notification-page-linked-flyout}}\n*
{{msg-mw|Notification-page-linked-email-batch-body}}\n*
{{msg-mw|Notification-page-linked-email-subject}}",
- "notification-page-linked-flyout": "Flyout-specific format for
displaying notifications of articles being linked.\n\nParameters:\n* $1 - the
username of the person who linked the page, plain text. Can be used for
GENDER.\n* $2 - the page being linked\n* $3 - the page linked from\nSee
also:\n* {{msg-mw|Notification-page-linked}}\n*
{{msg-mw|Notification-page-linked-email-batch-body}}\n*
{{msg-mw|Notification-page-linked-email-subject}}",
+ "notification-header-page-linked": "Flyout-specific format for
displaying notifications of articles being linked.\n\nParameters:\n* $1 - the
formatted username of the person who linked the page. \n* $2 - the username for
GENDER\n* $3 - the page being linked\n* $4 - the page linked from\nSee also:\n*
{{msg-mw|Notification-page-linked}}\n*
{{msg-mw|Notification-page-linked-email-batch-body}}\n*
{{msg-mw|Notification-page-linked-email-subject}}",
+ "notification-bundle-header-page-linked": "Bundled message for
page-linked notification. Parameters:\n* $1 - the formatted username of the
person who linked the page. \n* $2 - the username for GENDER\n* $3 - the page
title\n* $4 - the page linked from\n* $5 - the count of other action
performers, could be number or {{msg-mw|Echo-notification-count}}. e.g. 7 or
99+\n* $6 - a number used for plural support (numeric version of $5)\nSee
also:\n* {{msg-mw|Notification-page-linked}}\n*
{{msg-mw|Notification-page-linked-flyout}}\n*
{{msg-mw|Notification-page-linked-email-batch-body}}\n*
{{msg-mw|Notification-page-linked-email-subject}}",
+ "notification-link-text-what-links-here": "Label for link to the
WhatLinksHere special page for the page being linked in this notification.",
"notification-add-comment2": "Format for displaying notifications of a
comment being added to an existing discussion.\n\nParameters:\n* $1 - the
username of the person who edited, plain text. Can be used for GENDER.\n* $2 -
the section title of the discussion\n* $3 - a link to a page and section\n* $4
- the page on which the discussion exists, plain text\nSee also:\n*
{{msg-mw|Notification-add-comment-yours2}}",
"notification-add-talkpage-topic2": "Format for displaying
notifications of a new discussion being added. Parameters:\n* $1 - the username
of the person who edited, plain text. Can be used for GENDER.\n* $2 - the
section title of the discussion\n* $3 - the page on which the discussion was
added, plain text\nSee also:\n* {{msg-mw|Notification-edit-talk-page2}}\n*
{{msg-mw|Notification-edit-talk-page-flyout2}}",
"notification-add-talkpage-topic-yours2": "Parameters:\n* $1 - a
username, plain text. Can be used for GENDER.\n* $2 - a page section\n* $3 - a
page title",
@@ -134,7 +136,6 @@
"echo-date-yesterday": "The header text for yesterday's notification
section.\n{{Identical|Yesterday}}",
"echo-load-more-error": "Error message for errors in loading more
notifications",
"notification-edit-talk-page-bundle": "Bundled message for
edit-user-talk notification. Parameters:\n* $1 - the name of the user who
performed the action, which can be used for gender support\n* $2 - the name of
the user being addressed\n* $3 - the count of other action performers, could be
a number or {{msg-mw|Echo-notification-count}}. e.g. \"7\" or \"99+\"\n* $4 - a
number used for plural support relating to $3 (likely identical to $3 it that
is a number, and 100 otherwise)\nSee also:\n*
{{msg-mw|Notification-edit-talk-page2}}\n*
{{msg-mw|Notification-edit-talk-page-email-batch-body2}}\n*
{{msg-mw|Notification-edit-talk-page-email-subject2}}",
- "notification-page-linked-bundle": "Bundled message for page-linked
notification. Parameters:\n* $1 - the username who performs the action, which
can be used for gender support\n* $2 - the page title\n* $3 - the page linked
from\n* $4 - the count of other action performers, could be number or
{{msg-mw|Echo-notification-count}}. e.g. 7 others or 99+ others\n* $5 - a
number used for plural support (numeric version of $4)\nSee also:\n*
{{msg-mw|Notification-page-linked}}\n*
{{msg-mw|Notification-page-linked-flyout}}\n*
{{msg-mw|Notification-page-linked-email-batch-body}}\n*
{{msg-mw|Notification-page-linked-email-subject}}",
"notification-edit-user-talk-email-batch-bundle-body": "Bundled message
for edit-user-talk email digest notification. Parameters:\n* $1 - the username
who performs the action, which can be used for gender support\n* $2 - the count
of other action performers, could be number or
{{msg-mw|echo-notification-count}}\n* $3 - a number used for plural
support\n\nSee also:\n* {{msg-mw|Notification-edit-talk-page2}}\n*
{{msg-mw|Notification-edit-talk-page-flyout2}}\n*
{{msg-mw|Notification-edit-talk-page-email-batch-body2}}\n*
{{msg-mw|Notification-edit-talk-page-email-subject2}}",
"notification-page-linked-email-batch-bundle-body": "Bundled message
for page-linked email digest notification. Parameters:\n* $1 - the username
who performs the action, which can be used for gender support\n* $2 - the
link-to page title\n* $3 - the link-from page title\n* $4 - the count of other
link-from page title, can be number or {{msg-mw|echo-notification-count}}\n* $5
- a number used for plural support (numeric version of $4)\n\nSee also:\n*
{{msg-mw|Notification-page-linked}}\n*
{{msg-mw|Notification-page-linked-flyout}}\n*
{{msg-mw|Notification-page-linked-email-batch-body}}\n*
{{msg-mw|Notification-page-linked-email-subject}}",
"echo-email-batch-separator": "{{optional}}\nEmail batch content
separator",
diff --git a/includes/formatters/PageLinkedPresentationModel.php
b/includes/formatters/PageLinkedPresentationModel.php
new file mode 100644
index 0000000..ba6c8de
--- /dev/null
+++ b/includes/formatters/PageLinkedPresentationModel.php
@@ -0,0 +1,79 @@
+<?php
+
+class EchoPageLinkedPresentationModel extends EchoEventPresentationModel {
+
+ public function getIconType() {
+ return 'linked';
+ }
+
+ /**
+ * The page containing the link may be a new page
+ * that is not yet replicated.
+ * This event won't be rendered unless/until
+ * both pages are available.
+ * @return bool
+ */
+ public function canRender() {
+ $pageTo = $this->event->getTitle();
+ $pageFrom = $this->getPageFrom();
+ return (bool)$pageTo && (bool)$pageFrom;
+ }
+
+ public function getPrimaryLink() {
+ return array(
+ 'url' => $this->getPageFrom()->getFullURL(),
+ 'label' => $this->msg(
'notification-link-text-view-page' )->text(),
+ );
+ }
+
+ public function getSecondaryLinks() {
+ $whatLinksHereLink = array(
+ 'url' => SpecialPage::getTitleFor( 'WhatLinkshere',
$this->event->getTitle()->getPrefixedText() )->getFullURL(),
+ 'label' => $this->msg(
'notification-link-text-what-links-here' )->text(),
+ 'prioritized' => true
+ );
+ return array( $whatLinksHereLink );
+ }
+
+ protected function getHeaderMessageKey() {
+ if ( $this->getBundleCount( true, array( $this,
'getLinkedPageId' ) ) > 1 ) {
+ return "notification-bundle-header-{$this->type}";
+ }
+ return "notification-header-{$this->type}";
+ }
+
+ public function getHeaderMessage() {
+ $msg = parent::getHeaderMessage();
+ $msg->params( $this->event->getTitle()->getPrefixedText() );
+ $msg->params( $this->getPageFrom()->getPrefixedText() );
+ list( $formattedCount, $countForPlural ) =
+ $this->getNotificationCountForOutput( false, array(
$this, 'getLinkedPageId' ) );
+ $msg->params( $formattedCount );
+ $msg->params( $countForPlural );
+ return $msg;
+ }
+
+ /**
+ * Get the page ID of the linked-from page for a given event.
+ * @param EchoEvent $event page-linked event
+ * @return int Page ID, or 0 if the page doesn't exist
+ */
+ public function getLinkedPageId( EchoEvent $event ) {
+ $extra = $event->getExtra();
+ if ( isset( $extra['link-from-page-id'] ) ) {
+ return $extra['link-from-page-id'];
+ }
+ // Backwards compatiblity for events from before
https://gerrit.wikimedia.org/r/#/c/63076
+ if ( isset( $extra['link-from-namespace'] ) && isset(
$extra['link-from-title'] ) ) {
+ $title = Title::makeTitleSafe(
$extra['link-from-namespace'], $extra['link-from-title'] );
+ if ( $title ) {
+ return $title->getArticleId();
+ }
+ }
+ return 0;
+ }
+
+ private function getPageFrom() {
+ return Title::newFromId( $this->getLinkedPageId( $this->event )
);
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/253634
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id9894b98a0dd7554a529ff763aaf0f719e36152b
Gerrit-PatchSet: 15
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Sbisson <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Sbisson <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits