Wctaiwan has uploaded a new change for review.

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

Change subject: [WIP] Various improvements
......................................................................

[WIP] Various improvements

* Separate errors for nonexistent and invalid pages
* Add checks for external targets where forbidden in validation
* Improve target construction
* Other minor changes

Change-Id: Ie9a9497b874707e0484e6533f1a683c7abe19c35
TODO: Improve validation in SpecialEditMassMessageList
---
M i18n/en.json
M i18n/qqq.json
M includes/MassMessage.php
M includes/content/MassMessageListContent.php
M includes/content/MassMessageListContentHandler.php
5 files changed, 26 insertions(+), 9 deletions(-)


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

diff --git a/i18n/en.json b/i18n/en.json
index 028ac36..edda76d 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -17,7 +17,8 @@
        "massmessage-fieldset-preview": "Preview",
        "massmessage-submitted": "Your message delivery to {{PLURAL:$1|$1 
page|$1 pages}} has been queued.",
        "massmessage-just-preview": "This is just a preview. Press 
\"{{int:massmessage-form-submit}}\" to send the message.",
-       "massmessage-spamlist-doesnotexist": "The specified page-list page does 
not exist.",
+       "massmessage-spamlist-doesnotexist": "The specified delivery list page 
or category does not exist.",
+       "massmessage-spamlist-invalid": "The specified page does not contain a 
valid delivery list.",
        "massmessage-empty-subject": "The subject line is empty.",
        "massmessage-empty-message": "The message body is empty.",
        "massmessage-unescaped-langlinks": "Warning: There are unescaped 
language links in your message.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 920b81e..558b656 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -18,7 +18,8 @@
        "massmessage-fieldset-preview": "Label for the fieldset box around the 
page preview.\n{{Identical|Preview}}",
        "massmessage-submitted": "Confirmation message the user sees after the 
form is submitted successfully and the request is queued in the job 
queue.\n\nParameters:\n* $1 - the number of deliveries that have been queued",
        "massmessage-just-preview": "Warning to user that what they are seeing 
is just a preview, and they should hit the send button to actually submit 
it.\n\nRefers to {{msg-mw|Massmessage-form-submit}}.",
-       "massmessage-spamlist-doesnotexist": "Error message the user sees if an 
invalid spamlist is provided.\n\nThe spamlist is the page containing list of 
pages to leave a message on.\n\nThis message probably means that said page, as 
provided by the user, does not exist.",
+       "massmessage-spamlist-doesnotexist": "Error message the user sees if 
the delivery list page or category they entered does not exist.",
+       "massmessage-spamlist-invalid": "Error message the user sees if the 
delivery list page they entered is invalid.",
        "massmessage-empty-subject": "Error message the user sees if the 
\"subject\" field is empty.",
        "massmessage-empty-message": "Error message the user sees if the 
\"message\" field is empty.",
        "massmessage-unescaped-langlinks": "Warning shown to user when 
previewing if their message text has unescaped language links.",
diff --git a/includes/MassMessage.php b/includes/MassMessage.php
index 717934a..de78f73 100644
--- a/includes/MassMessage.php
+++ b/includes/MassMessage.php
@@ -185,10 +185,15 @@
         * @return array
         */
        public static function getMassMessageListContentTargets ( Title 
$spamlist ) {
+               global $wgServer;
+
                $targets = Revision::newFromTitle( $spamlist 
)->getContent()->getTargets();
-               foreach ( $targets as $index => &$target ) {
+               foreach ( $targets as &$target ) {
                        if ( !array_key_exists( 'site', $target ) ) {
+                               $target['site'] = MassMessage::getBaseUrl( 
$wgServer );
                                $target['wiki'] = wfWikiID();
+                       } else {
+                               $target['wiki'] = MassMessage::getDBName( 
$target['site'] );
                        }
                }
                return self::normalizeTargets( $targets );
@@ -291,7 +296,7 @@
                                wfWikiID(),
                                $url
                        );
-               } else {
+               } else { // $spamlist contains a message key for an error 
message
                        $status->fatal( $spamlist );
                }
 
@@ -326,17 +331,20 @@
                        // Page exists, follow a redirect if possible
                        $target = MassMessage::followRedirect( $spamlist );
                        if ( $target === null || !$target->exists() ) {
-                               return 'massmessage-spamlist-doesnotexist'; // 
Interwiki redirect or non-existent page.
+                               return 'massmessage-spamlist-invalid'; // 
Interwiki redirect or non-existent page.
                        } else {
                                $spamlist = $target;
                        }
                }
 
                $contentModel = $spamlist->getContentModel();
+
                if ( $contentModel !== 'MassMessageListContent'
                        && $contentModel !== CONTENT_MODEL_WIKITEXT
+                       || $contentModel === 'MassMessageListContent'
+                       && !Revision::newFromTitle( $spamlist 
)->getContent()->isValid()
                ) {
-                       return 'massmessage-spamlist-doesnotexist';
+                       return 'massmessage-spamlist-invalid';
                }
 
                return $spamlist;
@@ -364,6 +372,7 @@
 
        /**
         * Send out the message!
+        * Note that this function does not perform validation on $data
         *
         * @param IContextSource $context
         * @param array $data
diff --git a/includes/content/MassMessageListContent.php 
b/includes/content/MassMessageListContent.php
index ab01f07..d35949f 100644
--- a/includes/content/MassMessageListContent.php
+++ b/includes/content/MassMessageListContent.php
@@ -34,6 +34,8 @@
         * @return bool Whether the contents are valid
         */
        public function isValid() {
+               global $wgAllowGlobalMessaging;
+
                $this->decode();
                if ( !is_string( $this->description ) || !is_array( 
$this->targets ) ) {
                        return false;
@@ -42,11 +44,15 @@
                        if ( !is_array( $target )
                                || !array_key_exists( 'title', $target )
                                || Title::newFromText( $target['title'] ) === 
null
-                               || array_key_exists( 'site', $target )
-                               && MassMessage::getDBName( $target['site'] ) 
=== null
                        ) {
                                return false;
                        }
+                       if ( array_key_exists( 'site', $target ) ) {
+                               $wiki = MassMessage::getDBName( $target['site'] 
);
+                               if ( $wiki === null || !$wgAllowGlobalMessaging 
&& $wiki !== wfWikiId() ) {
+                                       return false;
+                               }
+                       }
                }
                return true;
        }
diff --git a/includes/content/MassMessageListContentHandler.php 
b/includes/content/MassMessageListContentHandler.php
index e1895c3..34c4710 100644
--- a/includes/content/MassMessageListContentHandler.php
+++ b/includes/content/MassMessageListContentHandler.php
@@ -18,7 +18,7 @@
                $this->checkFormat( $format );
                $content = new MassMessageListContent( $text );
                if ( !$content->isValid() ) {
-                       throw new MWContentSerializationException( 'The 
delivery list is invalid.' );
+                       throw new MWContentSerializationException( 'The 
delivery list content is invalid.' );
                }
                return $content;
        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie9a9497b874707e0484e6533f1a683c7abe19c35
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MassMessage
Gerrit-Branch: contenthandler
Gerrit-Owner: Wctaiwan <wctai...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to