Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/87613


Change subject: Add a config flag, $wgAllowGlobalMessaging, to allow global 
messaging
......................................................................

Add a config flag, $wgAllowGlobalMessaging, to allow global messaging

If a user tries adding a target that is on a different site, they
will see an error message instead of the link.

Bug: 54954
Change-Id: Ia897bddb909bab700fbe69ee697f577e7e095302
---
M MassMessage.body.php
M MassMessage.hooks.php
M MassMessage.i18n.php
M MassMessage.php
4 files changed, 27 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MassMessage 
refs/changes/13/87613/1

diff --git a/MassMessage.body.php b/MassMessage.body.php
index b799f6c..f1ca5e5 100644
--- a/MassMessage.body.php
+++ b/MassMessage.body.php
@@ -187,14 +187,18 @@
        /**
         * Helper function for MassMessageHooks::ParserFunction
         * Inspired from the Cite extension
-        * @param $msg string message key
+        * @param $key string message key
         * @param $param string parameter for the message
         * @return array
         */
-       public static function parserError( $msg, $param ) {
+       public static function parserError( $key, $param = null ) {
+               $msg = wfMessage( $key );
+               if ( $param ) {
+                       $msg->params( $param );
+               }
                return array (
                        '<strong class="error">' .
-                       wfMessage( $msg )->params( $param )->plain() .
+                       $msg->plain() .
                        '</strong>',
                        'noparse' => false
                );
diff --git a/MassMessage.hooks.php b/MassMessage.hooks.php
index 1d27ff1..ad22e7f 100644
--- a/MassMessage.hooks.php
+++ b/MassMessage.hooks.php
@@ -25,7 +25,7 @@
         * @return array
         */
        public static function ParserFunction( $parser, $page, $site = '' ) {
-               global $wgScript;
+               global $wgScript, $wgAllowGlobalMessaging;
                $data = array( 'site' => $site, 'title' => $page );
                if ( trim( $site ) === '' ) {
                        // Assume it's a local delivery
@@ -42,8 +42,14 @@
                        // Check if the page provided is not valid
                        return MassMessage::parserError( 
'massmessage-parse-badpage', $page );
                }
-               if ( !isset( $data['dbname'] ) && MassMessage::getDBName( 
$data['site'] ) === null ) {
-                       return MassMessage::parserError( 
'massmessage-parse-badurl', $site );
+               if ( !isset( $data['dbname'] ) ) {
+                       $data['dbname'] = MassMessage::getDBName( $data['site'] 
);
+                       if ( $data['dbname'] === null ) {
+                               return MassMessage::parserError( 
'massmessage-parse-badurl', $site );
+                       }
+               }
+               if ( !$wgAllowGlobalMessaging && $data['dbname'] != $wgDBname ) 
{
+                       return MassMessage::parserError( 
'massmessage-global-disallowed' );
                }
                // Use a message so wikis can customize the output
                $msg = wfMessage( 'massmessage-target' )->params( $site, 
$wgScript, $page )->plain();
diff --git a/MassMessage.i18n.php b/MassMessage.i18n.php
index 006f0ae..1230364 100644
--- a/MassMessage.i18n.php
+++ b/MassMessage.i18n.php
@@ -34,6 +34,7 @@
        'massmessage-badhtml' => 'Your message may have {{PLURAL:$2|an unclosed 
HTML tag|unclosed HTML tags}}: $1.',
        'massmessage-parse-badurl' => '"$1" is not a valid site.',
        'massmessage-parse-badpage' => '"$1" is not a valid page title.',
+       'massmessage-global-disallowed' => 'Messages can only be sent to local 
pages.',
        'right-massmessage' => 'Send a message to multiple users at once',
        'action-massmessage' => 'send a message to multiple users at once',
        'log-name-massmessage' => 'Mass message log',
@@ -99,6 +100,7 @@
 * $1 is the url the user provided',
        'massmessage-parse-badpage' => 'Error message shown when the page name 
that the user provides is invalid.
 * $1 is the page title the user provided',
+       'massmessage-global-disallowed' => 'Error message shown if the target 
wiki is not the current wiki and cross-wiki messaging has been disabled (via 
$wgAllowGlobalMessaging).',
        'right-massmessage' => '{{doc-right|massmessage}}
 See also:
 * {{msg-mw|Right-massmessage-global}}',
diff --git a/MassMessage.php b/MassMessage.php
index 7695742..8105398 100644
--- a/MassMessage.php
+++ b/MassMessage.php
@@ -42,6 +42,15 @@
  */
 $wgMassMessageAccountUsername = 'MessengerBot';
 
+/**
+ * Whether to allow sending messages to another wiki
+ *
+ * This can be enabled on a "central" wiki to make it
+ * easier to keep track of where messages are being sent
+ * from.
+ */
+$wgAllowGlobalMessaging = true;
+
 $wgExtensionCredits['specialpage'][] = array(
        'path' => __FILE__,
        'name' => 'MassMessage',

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia897bddb909bab700fbe69ee697f577e7e095302
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

Reply via email to