Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/265464
Change subject: Support using the sender's account to deliver messages in the
backend
......................................................................
Support using the sender's account to deliver messages in the backend
MassMessageJob now supports using the sender's account to deliver
messages, provided they have a local account on that wiki. This
functionality is not yet exposed in the frontend, only in the backend.
Bug: T71954
Change-Id: I736f4c675583d3db21ee4a1a259b961494337ef3
---
M includes/MassMessage.php
M includes/job/MassMessageJob.php
2 files changed, 35 insertions(+), 7 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MassMessage
refs/changes/64/265464/1
diff --git a/includes/MassMessage.php b/includes/MassMessage.php
index 11f4869..93fdfbf 100644
--- a/includes/MassMessage.php
+++ b/includes/MassMessage.php
@@ -314,6 +314,12 @@
// Log it.
self::logToWiki( $spamlist, $user, $data['subject'] );
+ $data += array(
+ 'userId' => CentralIdLookup::factory()
+ ->centralIdFromLocalUser( $user,
CentralIdLookup::AUDIENCE_RAW ),
+ 'originWiki' => wfWikiID(),
+ );
+
// Insert it into the job queue.
$params = array(
'data' => $data,
diff --git a/includes/job/MassMessageJob.php b/includes/job/MassMessageJob.php
index beee3d5..642f53e 100644
--- a/includes/job/MassMessageJob.php
+++ b/includes/job/MassMessageJob.php
@@ -14,6 +14,11 @@
const STRIP_TILDES = true;
+ /**
+ * @var bool Whether to use sender account (if possible)
+ */
+ private $useSenderUser = false;
+
public function __construct( Title $title, array $params, $id = 0 ) {
// Create a fresh Title object so namespaces are evaluated
// in the context of the target site. See bug 57464.
@@ -38,6 +43,24 @@
return false;
}
return true;
+ }
+
+ /**
+ * @return User
+ */
+ protected function getUser() {
+ if ( $this->useSenderUser && isset( $this->params['userId'] ) )
{
+ $centralIdLookup = CentralIdLookup::factory();
+ $user = $centralIdLookup->localUserFromCentralId(
+ $this->params['userId'],
+ CentralIdLookup::AUDIENCE_RAW
+ );
+ if ( $user ) {
+ return $user;
+ }
+ }
+
+ return MassMessage::getMessengerUser();
}
/**
@@ -87,7 +110,7 @@
*/
protected function logLocalSkip( $reason ) {
$logEntry = new ManualLogEntry( 'massmessage', $reason );
- $logEntry->setPerformer( MassMessage::getMessengerUser() );
+ $logEntry->setPerformer( $this->getUser() );
$logEntry->setTarget( $this->title );
$logEntry->setParameters( array(
'4::subject' => $this->params['subject']
@@ -97,7 +120,6 @@
$logEntry->publish( $logid );
}
-
/**
* Log any message failures on the target site.
*
@@ -106,7 +128,7 @@
protected function logLocalFailure( $reason ) {
$logEntry = new ManualLogEntry( 'massmessage', 'failure' );
- $logEntry->setPerformer( MassMessage::getMessengerUser() );
+ $logEntry->setPerformer( $this->getUser() );
$logEntry->setTarget( $this->title );
$logEntry->setParameters( array(
'4::subject' => $this->params['subject'],
@@ -168,7 +190,7 @@
}
protected function editPage() {
- $user = MassMessage::getMessengerUser();
+ $user = $this->getUser();
$params = array(
'action' => 'edit',
'title' => $this->title->getPrefixedText(),
@@ -187,7 +209,7 @@
}
protected function addLQTThread() {
- $user = MassMessage::getMessengerUser();
+ $user = $this->getUser();
$params = array(
'action' => 'threadaction',
'threadaction' => 'newthread',
@@ -201,7 +223,7 @@
}
protected function addFlowTopic() {
- $user = MassMessage::getMessengerUser();
+ $user = $this->getUser();
$params = array(
'action' => 'flow',
'page' => $this->title->getPrefixedText(),
@@ -250,7 +272,7 @@
);
// New user objects will use $wgRequest, so we set that
// to our DerivativeRequest, so we don't run into any issues
- $wgUser = MassMessage::getMessengerUser();
+ $wgUser = $this->getUser();
$wgUser->clearInstanceCache(); // Force rights reload (for IP
block exemption)
$context = RequestContext::getMain();
--
To view, visit https://gerrit.wikimedia.org/r/265464
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I736f4c675583d3db21ee4a1a259b961494337ef3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MassMessage
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits