Wctaiwan has uploaded a new change for review.

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

Change subject: Add ability to deliver to all pages in a category
......................................................................

Add ability to deliver to all pages in a category

Allow a category to be specified as the spamlist, with the targets being
all pages in the category. Subcategories are discarded.

Bug: 57473
Change-Id: I20373726c4db989c194da19aecfff61eb1b956ee
---
M MassMessage.body.php
M MassMessage.i18n.php
2 files changed, 49 insertions(+), 3 deletions(-)


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

diff --git a/MassMessage.body.php b/MassMessage.body.php
index 6405947..c794b7d 100644
--- a/MassMessage.body.php
+++ b/MassMessage.body.php
@@ -159,6 +159,33 @@
        }
 
        /**
+        * Get an array of targets from a category
+        * @param  Title $spamlist
+        * @return array
+        */
+       public static function getCategoryTargets( Title $spamlist ) {
+               global $wgServer;
+
+               $cat = Category::newFromTitle( $spamlist );
+               $members = $cat->getMembers();
+               $targets = array();
+
+               foreach ( $members as $member ) {
+                       if ( $member->inNamespace( NS_CATEGORY ) ) {
+                               continue; // Ignore subcategories
+                       }
+
+                       $target = array();
+                       $target['title'] = $member->getPrefixedText();
+                       $target['site'] = MassMessage::getBaseUrl( $wgServer );
+                       $target['wiki'] = wfWikiID();
+                       $targets[] = $target;
+               }
+
+               return self::normalizeTargets( $targets );
+       }
+
+       /**
         * Get an array of targets via the #target parser function
         * @param  Title $spamlist
         * @param  IContextSource $context
@@ -241,10 +268,19 @@
                $spamlist = self::getSpamlist( $data['spamlist'] );
                if ( $spamlist instanceof Title ) {
                        // Prep the HTML comment message
+                       if ( $spamlist->inNamespace( NS_CATEGORY ) ) {
+                               $url = $spamlist->getFullUrl();
+                       } else {
+                               $url = $spamlist->getFullURL(
+                                       array( 'oldid' => 
$spamlist->getLatestRevID() ),
+                                       false,
+                                       PROTO_CANONICAL
+                               );
+                       }
                        $data['comment'] = array(
                                RequestContext::getMain()->getUser()->getName(),
                                wfWikiID(),
-                               $spamlist->getFullURL( array( 'oldid' => 
$spamlist->getLatestRevID() ), false, PROTO_CANONICAL )
+                               $url
                        );
                } else {
                        $status->fatal( $spamlist );
@@ -269,6 +305,12 @@
         */
        public static function getSpamlist( $title ) {
                $spamlist = Title::newFromText( $title );
+
+               // Simply return the title if it is a category
+               if ( $spamlist !== null && $spamlist->inNamespace( NS_CATEGORY 
) ) {
+                       return $spamlist;
+               }
+
                if ( $spamlist === null || !$spamlist->exists() ) {
                        return 'massmessage-spamlist-doesnotexist';
                } else {
@@ -319,7 +361,11 @@
                $spamlist = self::getSpamlist( $data['spamlist'] );
 
                // Insert it into the job queue.
-               $pages = self::getParserFunctionTargets( $spamlist, $context );
+               if ( $spamlist->inNamespace( NS_CATEGORY ) ) {
+                       $pages = self::getCategoryTargets( $spamlist );
+               } else {
+                       $pages = self::getParserFunctionTargets( $spamlist, 
$context );
+               }
 
                // Log it.
                self::logToWiki( $spamlist, $context->getUser(), 
$data['subject'] );
diff --git a/MassMessage.i18n.php b/MassMessage.i18n.php
index ae745d9..a170c42 100644
--- a/MassMessage.i18n.php
+++ b/MassMessage.i18n.php
@@ -15,7 +15,7 @@
 $messages['en'] = array(
        'massmessage' => 'Send mass message',
        'massmessage-desc' => 'Allows users to easily send a message to a list 
of users',
-       'massmessage-form-spamlist' => 'Page containing list of pages to leave 
a message on:',
+       'massmessage-form-spamlist' => 'Page or category 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:',
        'massmessage-form-preview' => 'Preview',

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I20373726c4db989c194da19aecfff61eb1b956ee
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MassMessage
Gerrit-Branch: master
Gerrit-Owner: Wctaiwan <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to