Catrope has uploaded a new change for review.
https://gerrit.wikimedia.org/r/284846
Change subject: Move section methods into a trait
......................................................................
Move section methods into a trait
Change-Id: Ief2005918b92945ff93aea85d17e595c7c38adf2
---
M autoload.php
M includes/formatters/EditUserTalkPresentationModel.php
M includes/formatters/MentionPresentationModel.php
3 files changed, 19 insertions(+), 100 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/46/284846/1
diff --git a/autoload.php b/autoload.php
index 6d636c6..675f7ac 100644
--- a/autoload.php
+++ b/autoload.php
@@ -78,6 +78,7 @@
'EchoRevertedPresentationModel' => __DIR__ .
'/includes/formatters/RevertedPresentationModel.php',
'EchoRevisionLocalCache' => __DIR__ .
'/includes/cache/RevisionLocalCache.php',
'EchoSeenTime' => __DIR__ . '/includes/SeenTime.php',
+ 'EchoSectionPresentationModel' => __DIR__ .
'/includes/formatters/SectionPresentationModel.php',
'EchoSuppressionRowUpdateGenerator' => __DIR__ .
'/includes/schemaUpdate.php',
'EchoTalkPageFunctionalTest' => __DIR__ .
'/tests/phpunit/TalkPageFunctionalTest.php',
'EchoTargetPage' => __DIR__ . '/includes/model/TargetPage.php',
diff --git a/includes/formatters/EditUserTalkPresentationModel.php
b/includes/formatters/EditUserTalkPresentationModel.php
index 27ddf5a..16c5456 100644
--- a/includes/formatters/EditUserTalkPresentationModel.php
+++ b/includes/formatters/EditUserTalkPresentationModel.php
@@ -1,8 +1,7 @@
<?php
class EchoEditUserTalkPresentationModel extends EchoEventPresentationModel {
-
- private $sectionTitle = null;
+ use EchoSectionPresentationModel;
public function canRender() {
return (bool)$this->event->getTitle();
@@ -13,18 +12,9 @@
}
public function getPrimaryLink() {
- $title = $this->event->getTitle();
- if ( !$this->isBundled() && $this->hasSection() ) {
- $title = Title::makeTitle(
- $title->getNamespace(),
- $title->getDBkey(),
- $this->getSection()
- );
- }
-
return array(
// Need FullURL so the section is included
- 'url' => $title->getFullURL(),
+ 'url' => $this->getTitleWithSection()->getFullURL(),
'label' => $this->msg(
'notification-link-text-view-message' )->text()
);
}
@@ -75,29 +65,6 @@
} else {
return false;
}
- }
-
- private function hasSection() {
- return (bool)$this->getSection();
- }
-
- private function getSection() {
- if ( $this->sectionTitle !== null ) {
- return $this->sectionTitle;
- }
- $sectionTitle = $this->event->getExtraParam( 'section-title' );
- if ( !$sectionTitle ) {
- $this->sectionTitle = false;
- return false;
- }
- // Check permissions
- if ( !$this->userCan( Revision::DELETED_TEXT ) ) {
- $this->sectionTitle = false;
- return false;
- }
-
- $this->sectionTitle = $sectionTitle;
- return $this->sectionTitle;
}
private function getDiffLinkUrl() {
diff --git a/includes/formatters/MentionPresentationModel.php
b/includes/formatters/MentionPresentationModel.php
index eafeb0e..74c0d7c 100644
--- a/includes/formatters/MentionPresentationModel.php
+++ b/includes/formatters/MentionPresentationModel.php
@@ -1,30 +1,10 @@
<?php
class EchoMentionPresentationModel extends EchoEventPresentationModel {
- private $sectionTitle = null;
-
+ use EchoSectionPresentationModel;
public function getIconType() {
return 'mention';
- }
-
- private function getSection() {
- if ( $this->sectionTitle !== null ) {
- return $this->sectionTitle;
- }
- $sectionTitle = $this->event->getExtraParam( 'section-title' );
- if ( !$sectionTitle ) {
- $this->sectionTitle = false;
- return false;
- }
- // Check permissions
- if ( !$this->userCan( Revision::DELETED_TEXT ) ) {
- $this->sectionTitle = false;
- return false;
- }
-
- $this->sectionTitle = $sectionTitle;
- return $this->sectionTitle;
}
public function canRender() {
@@ -32,24 +12,22 @@
}
protected function getHeaderMessageKey() {
- $noSection = !$this->getSection();
-
if ( $this->onArticleTalkpage() ) {
- return $noSection ?
-
'notification-header-mention-article-talkpage-nosection' :
- 'notification-header-mention-article-talkpage';
+ return $this->hasSection() ?
+ 'notification-header-mention-article-talkpage' :
+
'notification-header-mention-article-talkpage-nosection';
} elseif ( $this->onAgentTalkpage() ) {
- return $noSection ?
-
'notification-header-mention-agent-talkpage-nosection' :
- 'notification-header-mention-agent-talkpage';
+ return $this->hasSection() ?
+ 'notification-header-mention-agent-talkpage' :
+
'notification-header-mention-agent-talkpage-nosection';
} elseif ( $this->onUserTalkpage() ) {
- return $noSection ?
-
'notification-header-mention-user-talkpage-nosection' :
- 'notification-header-mention-user-talkpage-v2';
+ return $this->hasSection() ?
+ 'notification-header-mention-user-talkpage-v2' :
+
'notification-header-mention-user-talkpage-nosection';
} else {
- return $noSection ?
- 'notification-header-mention-other-nosection' :
- 'notification-header-mention-other';
+ return $this->hasSection() ?
+ 'notification-header-mention-other' :
+ 'notification-header-mention-other-nosection';
}
}
@@ -71,29 +49,11 @@
$msg->params( $this->getTruncatedTitleText(
$this->event->getTitle(), true ) );
}
- $section = $this->getSection();
- if ( $section ) {
- $msg->plaintextParams( $this->getTruncatedSectionTitle(
$section ) );
+ if ( $this->hasSection() ) {
+ $msg->plaintextParams( $this->getTruncatedSectionTitle(
$this->getSection() ) );
}
return $msg;
- }
-
- /**
- * @return Title
- */
- private function getTitleWithSection() {
- $title = $this->event->getTitle();
- $section = $this->getSection();
- if ( $section ) {
- $title = Title::makeTitle(
- $title->getNamespace(),
- $title->getDBkey(),
- $section
- );
- }
-
- return $title;
}
public function getBodyMessage() {
@@ -113,18 +73,9 @@
}
public function getPrimaryLink() {
- $title = $this->event->getTitle();
- $section = $this->getSection();
- if ( $section ) {
- $title = Title::makeTitle(
- $title->getNamespace(),
- $title->getDBkey(),
- $section
- );
- }
return array(
// Need FullURL so the section is included
- 'url' => $title->getFullURL(),
+ 'url' => $this->getTitleWithSection()->getFullURL(),
'label' => $this->msg(
'notification-link-text-view-mention' )->text()
);
}
--
To view, visit https://gerrit.wikimedia.org/r/284846
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ief2005918b92945ff93aea85d17e595c7c38adf2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits