Sbisson has uploaded a new change for review. https://gerrit.wikimedia.org/r/253599
Change subject: Presentation model for edit-user-talk ...................................................................... Presentation model for edit-user-talk Bug: T116843 Change-Id: Ia11f5b57747ed0be5d4b00c75925d5fcdde87c43 --- M Echo.php M autoload.php M i18n/en.json M i18n/qqq.json A includes/formatters/EditUserTalkPresentationModel.php 5 files changed, 132 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo refs/changes/99/253599/1 diff --git a/Echo.php b/Echo.php index 7e38a40..741701d 100644 --- a/Echo.php +++ b/Echo.php @@ -302,6 +302,7 @@ 'icon' => 'site', ), 'edit-user-talk' => array( + 'presentation-model' => 'EchoEditUserTalkPresentationModel', 'user-locators' => array( 'EchoUserLocator::locateTalkPageOwner', ), diff --git a/autoload.php b/autoload.php index 681690a..ab29eb5 100644 --- a/autoload.php +++ b/autoload.php @@ -38,6 +38,7 @@ 'EchoDiscussionParserTest' => __DIR__ . '/tests/phpunit/DiscussionParserTest.php', 'EchoEditFormatter' => __DIR__ . '/includes/formatters/EditFormatter.php', 'EchoEditUserTalkFormatter' => __DIR__ . '/includes/formatters/EditUserTalkFormatter.php', + 'EchoEditUserTalkPresentationModel' => __DIR__ . '/includes/formatters/EditUserTalkPresentationModel.php', 'EchoEmailDecorator' => __DIR__ . '/includes/EmailFormatter.php', 'EchoEmailDigest' => __DIR__ . '/includes/EmailFormatter.php', 'EchoEmailFormatter' => __DIR__ . '/includes/EmailFormatter.php', diff --git a/i18n/en.json b/i18n/en.json index 43c97b7..c27a724 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -59,8 +59,9 @@ "notification-link-text-view-edit": "View edit", "notification-edit-talk-page2": "[[User:$1|$1]] {{GENDER:$1|left}} a message on your [[User talk:$2#$3|talk page]].", "notification-edit-talk-page-with-section": "[[User:$1|$1]] {{GENDER:$1|left}} a message on your talk page in \"[[User talk:$2#$3|$4]]\".", - "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-header-edit-user-talk": "$1 {{GENDER:$2|left}} a message on your talk page.", + "notification-header-edit-user-talk-with-section": "$1 {{GENDER:$2|left}} a message on your talk page in \"$3\".", + "notification-body-edit-user-talk-with-section": "$1", "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-add-comment2": "[[User:$1|$1]] {{GENDER:$1|commented}} on \"[[$3|$2]]\" on the \"$4\" talk page.", diff --git a/i18n/qqq.json b/i18n/qqq.json index b66dfcb..7074f6f 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -80,8 +80,9 @@ "notification-link-text-view-edit": "Label for button that links to a \"diff\" view showing an edit made to a page. This is an alternative to the wording in {{msg-mw|notification-link-text-view-changes}}, which serves essentially the same function.", "notification-edit-talk-page2": "Format for displaying notifications of a user talk page being edited. Parameters:\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-page-flyout2}}\n* {{msg-mw|Notification-add-talkpage-topic2}}\n* left is for verb left.", "notification-edit-talk-page-with-section": "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-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-header-edit-user-talk": "Flyout-specific format for displaying notification header of a user talk page being edited.\n\nParameters:\n* $1 - the formatted username of the person who edited.\n* $2 - the username for GENDER\nSee also:\n* {{msg-mw|Notification-edit-talk-page2}}\n* {{msg-mw|Notification-add-talkpage-topic2}}", + "notification-header-edit-user-talk-with-section": "Flyout-specific format for displaying notification header of a user talk page being edited with a new section or new comment.\n\nParameters:\n* $1 - the formatted username of the person who edited.\n* $2 - the username for GENDER\n* $3 - the raw section title text\nSee also:\n* {{msg-mw|Notification-edit-talk-page2}}\n* {{msg-mw|Notification-add-talkpage-topic2}}", + "notification-body-edit-user-talk-with-section": "Flyout-specific format for displaying notification body of a user talk page being edited with a new section or new comment.\n\nParameters:\n* $1 - comment left on the user talk page.\n* {{msg-mw|Notification-edit-talk-page2}}\n* {{msg-mw|Notification-add-talkpage-topic2}}", "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-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}}", diff --git a/includes/formatters/EditUserTalkPresentationModel.php b/includes/formatters/EditUserTalkPresentationModel.php new file mode 100644 index 0000000..a087b32 --- /dev/null +++ b/includes/formatters/EditUserTalkPresentationModel.php @@ -0,0 +1,124 @@ +<?php + +class EchoEditUserTalkPresentationModel extends EchoEventPresentationModel { + + public function canRender() { + return (bool)$this->event->getTitle(); + } + + public function getIconType() { + return 'chat'; + } + + public function getPrimaryLink() { + $title = $this->event->getTitle(); + if ( $this->hasSection() ) { + $title = Title::makeTitleSafe( + $title->getNamespace(), + $title->getDBkey(), + $this->formatSubjectAnchor() + ); + } + + return array( + $title->getFullURL(), + $this->msg( 'notification-link-text-view-message' )->text() + ); + } + + public function getSecondaryLinks() { + if ( $this->hasSection() ) { + $url = $this->getDiffLinkUrl(); + $msg = $this->msg( 'notification-link-text-view-changes' ); + return array( + $url => $msg->text() + ); + } else { + return parent::getSecondaryLinks(); + } + } + + public function getHeaderMessage() { + if ( $this->hasSection() ) { + $msg = $this->msg( 'notification-header-edit-user-talk-with-section' ); + list( $formattedName, $genderName ) = $this->getAgentForOutput(); + $msg->params( $formattedName, $genderName ); + $msg->params( $this->getSectionTitleSnippet() ); + return $msg; + } else { + return parent::getHeaderMessage(); + } + } + + public function getBodyMessage() { + if ( $this->hasSection() ) { + $msg = $this->msg( 'notification-body-edit-user-talk-with-section' ); + $msg->params( $this->getRevisionSnippet() ); + return $msg; + } else { + return false; + } + } + + private function hasSection() { + return (bool)$this->event->getExtraParam( 'section-title' ); + } + + /** + * Get the section title for a talk page post + * @return string + */ + private function getSectionTitleSnippet() { + if ( $this->userCan( Revision::DELETED_TEXT ) ) { + return EchoDiscussionParser::getTextSnippet( + $this->event->getExtraParam( 'section-title' ), + $this->language, + 30 + ); + } else { + return $this->msg( 'echo-rev-deleted-text-view' )->text(); + } + } + + private function getRevisionSnippet() { + $sectionText = $this->event->getExtraParam( 'section-text' ); + if ( !$sectionText || !$this->userCan( Revision::DELETED_TEXT ) ) { + return ''; + } + + return trim( $sectionText ); + } + + /** + * Extract the subject anchor (linkable portion of the edited page) from + * the event. + * + * @return string The anchor on page, or an empty string + */ + private function formatSubjectAnchor() { + global $wgParser; + + if ( !$this->userCan( Revision::DELETED_TEXT ) ) { + return $this->msg( 'echo-rev-deleted-text-view' )->text(); + } + $sectionTitle = $this->event->getExtraParam( 'section-title' ); + if ( !$sectionTitle ) { + return ''; + } + + // Strip out # + return substr( $wgParser->guessLegacySectionNameFromWikiText( $sectionTitle ), 1 ); + } + + private function getDiffLinkUrl() { + $query = array(); + $revId = $this->event->getExtraParam( 'revid' ); + if ( $revId ) { + $query = array( + 'oldid' => 'prev', + 'diff' => $revId, + ); + } + return $this->event->getTitle()->getFullURL( $query ); + } +} -- To view, visit https://gerrit.wikimedia.org/r/253599 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia11f5b57747ed0be5d4b00c75925d5fcdde87c43 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Echo Gerrit-Branch: master Gerrit-Owner: Sbisson <sbis...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits