Wctaiwan has uploaded a new change for review. https://gerrit.wikimedia.org/r/161683
Change subject: Integrate normalizeTargets into getTargets ...................................................................... Integrate normalizeTargets into getTargets Change-Id: Ie2c3813c916df51a06140b3d5fd532047debe210 --- M includes/MassMessage.php M includes/MassMessageTargets.php M includes/SpecialCreateMassMessageList.php M includes/SpecialMassMessage.php M tests/MassMessageTargetsTest.php 5 files changed, 22 insertions(+), 17 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MassMessage refs/changes/83/161683/1 diff --git a/includes/MassMessage.php b/includes/MassMessage.php index 215bdda..a5f915c 100644 --- a/includes/MassMessage.php +++ b/includes/MassMessage.php @@ -316,9 +316,7 @@ $spamlist = self::getSpamlist( $data['spamlist'] ); // Get the array of pages to deliver to. - $pages = MassMessageTargets::normalizeTargets( - MassMessageTargets::getTargets( $spamlist ) - ); + $pages = MassMessageTargets::getTargets( $spamlist ); // Log it. self::logToWiki( $spamlist, $user, $data['subject'] ); diff --git a/includes/MassMessageTargets.php b/includes/MassMessageTargets.php index 714a4ff..cc46bcc 100644 --- a/includes/MassMessageTargets.php +++ b/includes/MassMessageTargets.php @@ -15,30 +15,41 @@ * site: The hostname and port (if exists) of the wiki * * @param Title $spamlist + * @param $normalize Whether to normalize and deduplicate the targets * @return array|null */ - public static function getTargets( Title $spamlist ) { + public static function getTargets( Title $spamlist, $normalize = true ) { if ( !$spamlist->exists() && !$spamlist->inNamespace( NS_CATEGORY ) ) { return null; } if ( $spamlist->inNamespace( NS_CATEGORY ) ) { - return self::getCategoryTargets( $spamlist ); + $targets = self::getCategoryTargets( $spamlist ); } elseif ( $spamlist->hasContentModel( 'MassMessageListContent' ) ) { - return self::getMassMessageListContentTargets( $spamlist ); + $targets = self::getMassMessageListContentTargets( $spamlist ); } elseif ( $spamlist->hasContentModel( CONTENT_MODEL_WIKITEXT ) ) { - return self::getParserFunctionTargets( $spamlist ); + $targets = self::getParserFunctionTargets( $spamlist ); } else { - return null; + $targets = null; + } + + if ( !$targets ) { + return $targets; // null or empty array + } + + if ( $normalize ) { + return self::normalizeTargets( $targets ); + } else { + return $targets; } } /** * Get array of normalized targets with duplicates removed - * @param array $data + * @param array $data * @return array */ - public static function normalizeTargets( array $data ) { + protected static function normalizeTargets( array $data ) { global $wgNamespacesToConvert; foreach ( $data as &$target ) { diff --git a/includes/SpecialCreateMassMessageList.php b/includes/SpecialCreateMassMessageList.php index cfa1afe..60386e8 100644 --- a/includes/SpecialCreateMassMessageList.php +++ b/includes/SpecialCreateMassMessageList.php @@ -113,7 +113,7 @@ * @return array|null */ protected function getTargets( Title $source ) { - $pages = MassMessageTargets::getTargets( $source ); + $pages = MassMessageTargets::getTargets( $source, /* $normalize = */ false ); if ( $pages === null ) { return null; } diff --git a/includes/SpecialMassMessage.php b/includes/SpecialMassMessage.php index e53f328..08d084e 100644 --- a/includes/SpecialMassMessage.php +++ b/includes/SpecialMassMessage.php @@ -264,9 +264,7 @@ // Output the number of recipients $spamlist = MassMessage::getSpamlist( $data['spamlist'] ); - $targets = MassMessageTargets::normalizeTargets( - MassMessageTargets::getTargets( $spamlist ) - ); + $targets = MassMessageTargets::getTargets( $spamlist ); $infoFieldset = Xml::fieldset( $this->msg( 'massmessage-fieldset-info' )->text(), $this->msg( 'massmessage-preview-count' )->numParams( count( $targets ) )->parse() diff --git a/tests/MassMessageTargetsTest.php b/tests/MassMessageTargetsTest.php index 8ce1e38..19489b7 100644 --- a/tests/MassMessageTargetsTest.php +++ b/tests/MassMessageTargetsTest.php @@ -45,9 +45,7 @@ public function testGetParserFunctionTargets( $text, $check ) { $title = Title::newFromText( 'Input list' ); MassMessageTest::updatePage( $title, $text ); - $data = MassMessageTargets::normalizeTargets( - MassMessageTargets::getTargets( $title ) - ); + $data = MassMessageTargets::getTargets( $title ); if ( empty( $check ) ) { // Check that the spamlist is empty -- To view, visit https://gerrit.wikimedia.org/r/161683 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie2c3813c916df51a06140b3d5fd532047debe210 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MassMessage Gerrit-Branch: master Gerrit-Owner: Wctaiwan <wctai...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits