jenkins-bot has submitted this change and it was merged.

Change subject: Hardcode the bot's username as $wgMassMessageAccountUsername
......................................................................


Hardcode the bot's username as $wgMassMessageAccountUsername

Hooks were added to add the username to $wgReservedUsernames,
and to prevent the account from being renamed.

There are various issues with using a message, letting local
admins override it, etc, so it is just easier to set it as
a global variable.

Change-Id: I4e95ef97d693ba62d69758ac96401064e1b0f097
---
M MassMessage.body.php
M MassMessage.hooks.php
M MassMessage.i18n.php
M MassMessage.php
4 files changed, 42 insertions(+), 4 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/MassMessage.body.php b/MassMessage.body.php
index e6f0c36..d42c8cb 100644
--- a/MassMessage.body.php
+++ b/MassMessage.body.php
@@ -42,11 +42,11 @@
         * Sets up the messenger account for our use if it hasn't been already.
         *
         * @return User
-        * @fixme This should use the langage for the target site, not 
submission site
         */
        public static function getMessengerUser() {
+               global $wgMassMessageAccountUsername;
                // Function kinda copied from the AbuseFilter
-               $user = User::newFromName( wfMessage( 'massmessage-sender' 
)->inContentLanguage()->text() );
+               $user = User::newFromName( $wgMassMessageAccountUsername );
                $user->load();
                if ( $user->getId() && $user->mPassword == '' ) {
                        // We've already stolen the account
diff --git a/MassMessage.hooks.php b/MassMessage.hooks.php
index 9c6ac63..0c0d064 100644
--- a/MassMessage.hooks.php
+++ b/MassMessage.hooks.php
@@ -13,7 +13,6 @@
         */
        public static function onParserFirstCallInit( Parser &$parser ) {
                $parser->setFunctionHook( 'target', 
'MassMessageHooks::ParserFunction' );
-
                return true;
        }
 
@@ -52,6 +51,32 @@
        }
 
        /**
+        * Add our username to the list of reserved ones
+        * @param $reservedUsernames array
+        * @return bool
+        */
+       public static function onUserGetReservedNames( &$reservedUsernames ) {
+               global $wgMassMessageAccountUsername;
+               $reservedUsernames[] = $wgMassMessageAccountUsername;
+               return true;
+       }
+
+       /**
+        * If someone is trying to rename the bot, don't let them.
+        * @param $uid int
+        * @param $oldName string
+        * @param $newName string
+        * @return bool|string
+        */
+       public static function onRenameUserPreRename( $uid, $oldName, $newName 
) {
+               global $wgMassMessageAccountUsername;
+               if ( $oldName == $wgMassMessageAccountUsername ) {
+                       return wfMessage( 'massmessage-cannot-rename' )->text() 
;
+               }
+               return true;
+       }
+
+       /**
         * Add a row with the number of queued messages to Special:Statistics
         * @param  array $extraStats
         * @return bool
diff --git a/MassMessage.i18n.php b/MassMessage.i18n.php
index 52d85ed..400beab 100644
--- a/MassMessage.i18n.php
+++ b/MassMessage.i18n.php
@@ -15,7 +15,6 @@
 $messages['en'] = array(
        'massmessage' => 'Send mass message',
        'massmessage-desc' => 'Allows users to easily send a message to a list 
of users',
-       'massmessage-sender' => 'MessengerBot',
        'massmessage-form-spamlist' => 'Page containing list of pages to leave 
a message on:',
        'massmessage-form-subject' => 'Subject of the message (Also used as the 
edit summary):',
        'massmessage-form-message' => 'Body of the message:',
@@ -38,6 +37,7 @@
        'log-name-massmessage' => 'Mass message log',
        'log-description-massmessage' => 'These events track users sending 
messages through [[Special:MassMessage]].',
        'logentry-massmessage-send' => '$1 {{GENDER:$2|sent a message}} to $3',
+       'massmessage-cannot-rename' => 'This is a system account and cannot be 
renamed.',
 );
 
 /** Message documentation (Message documentation)
@@ -87,6 +87,7 @@
        'log-name-massmessage' => 'Log page title',
        'log-description-massmessage' => 'Log page description',
        'logentry-massmessage-send' => '{{logentry}}',
+       'massmessage-cannot-rename' => 'Error message a user sees when they try 
renaming the bot account.',
 );
 
 /** Bengali (বাংলা)
diff --git a/MassMessage.php b/MassMessage.php
index 7e1de24..51a7dd4 100644
--- a/MassMessage.php
+++ b/MassMessage.php
@@ -34,6 +34,14 @@
  */
 $wgNamespacesToConvert = array( NS_USER => NS_USER_TALK );
 
+/*
+ * Username of the messenger bot
+ *
+ * This ensures that local administrators cannot change the bot's username
+ * by editing a system message, which would interfere with global messages
+ */
+$wgMassMessageAccountUsername = 'MessengerBot';
+
 $wgExtensionCredits['specialpage'][] = array(
        'path' => __FILE__,
        'name' => 'MassMessage',
@@ -56,6 +64,8 @@
 
 $wgHooks['ParserFirstCallInit'][] = 'MassMessageHooks::onParserFirstCallInit';
 $wgHooks['SpecialStatsAddExtra'][] = 
'MassMessageHooks::onSpecialStatsAddExtra';
+$wgHooks['RenameUserPreRename'][] = 'MassMessageHooks::onRenameUserPreRename';
+$wgHooks['UserGetReservedNames'][] = 
'MassMessageHooks::onUserGetReservedNames';
 $wgHooks['UnitTestsList'][] = 'MassMessageHooks::onUnitTestsList';
 
 $wgResourceModules['ext.MassMessage.special'] = array(
@@ -69,6 +79,8 @@
 
 $wgLogTypes[] = 'massmessage';
 $wgLogActionsHandlers['massmessage/*'] = 'LogFormatter';
+
+// User rights
 $wgAvailableRights[] = 'massmessage'; // Local messaging
 $wgAvailableRights[] = 'massmessage-global'; // Cross-wiki messaging
 $wgGroupPermissions['messenger']['massmessage'] = true;

-- 
To view, visit https://gerrit.wikimedia.org/r/74938
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4e95ef97d693ba62d69758ac96401064e1b0f097
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/MassMessage
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Emufarmers <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: MZMcBride <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Yuvipanda <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to