mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-27 17:20:40 +00:00
Presentation model for page-linked
Bug: T116843 Change-Id: Id9894b98a0dd7554a529ff763aaf0f719e36152b
This commit is contained in:
parent
65638384fc
commit
a9f307ceab
3
Echo.php
3
Echo.php
|
@ -354,6 +354,7 @@ $wgEchoNotifications = array(
|
|||
'icon' => 'revert',
|
||||
),
|
||||
'page-linked' => array(
|
||||
'presentation-model' => 'EchoPageLinkedPresentationModel',
|
||||
'user-locators' => array(
|
||||
'EchoUserLocator::locateArticleCreator',
|
||||
),
|
||||
|
@ -367,8 +368,6 @@ $wgEchoNotifications = array(
|
|||
'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',
|
||||
|
|
|
@ -76,6 +76,7 @@ $wgAutoloadClasses += array(
|
|||
'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',
|
||||
|
|
|
@ -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": "--",
|
||||
|
|
|
@ -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",
|
||||
|
|
79
includes/formatters/PageLinkedPresentationModel.php
Normal file
79
includes/formatters/PageLinkedPresentationModel.php
Normal file
|
@ -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 ) );
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue