Pppery has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/329055 )
Change subject: Make `Special:Newsletter/id/subscribers` editable. ...................................................................... Make `Special:Newsletter/id/subscribers` editable. Bug: T154080 Change-Id: Ie92818811061568a990facdf9ce43dc274e00a79 --- M i18n/en.json M i18n/qqq.json M includes/specials/SpecialNewsletter.php 3 files changed, 52 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Newsletter refs/changes/55/329055/1 diff --git a/i18n/en.json b/i18n/en.json index 0fd5fe1..4920f2e 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -92,7 +92,9 @@ "newsletter-subscribing": "Subscribing...", "newsletter-unsubscribing": "Unsubscribing...", "newsletter-subscribers" : "Newsletter subscribers", - "newsletter-subscribers-nopermission": "You do not have permission to view the subscribers of this newsletter", + "newsletter-subscribers-nopermission": "You do not have permission to edit the subscribers of this newsletter", + "newsletter-edit-subscribers-nochanges": "No changes have been made to the newsletter's subscribers.", + "newsletter-edit-subscribers-success": "The subscribers of the newsletter have been updated.", "newsletter-available-newsletters-field-label": "Available newsletters", "newsletter-subscribed-newsletters-field-label": "Subscribed newsletters", "newsletter-none-found": "No newsletters exist. You can create a new newsletter through [[Special:CreateNewsletter]].", @@ -112,7 +114,7 @@ "action-newsletter-create": "create newsletters", "right-newsletter-delete": "Delete newsletters", "action-newsletter-delete": "delete newsletters", - "right-newsletter-manage": "Add or remove publishers from and view the subscribers of newsletters", + "right-newsletter-manage": "Add or remove publishers and subscribers from newsletters", "action-newsletter-manage": "manage newsletters", "apihelp-newslettersubscribe-description": "Subscribe to or unsubscribe from a newsletter.", "apihelp-newslettersubscribe-param-id": "ID of the newsletter for which the subscription should be changed.", diff --git a/i18n/qqq.json b/i18n/qqq.json index 4b39c8d..96ca0e2 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -99,6 +99,8 @@ "newsletter-subscribing": "Message shown on Special:Newsletters while subscription is in progress when the user presses subscribe button.", "newsletter-unsubscribing": "Message shown on Special:Newsletters while unsubscription is in progress when the user presses the unsubscribe button.", "newsletter-subscribers": "Header message shown on Special:Newsletter/id/subscribers", + "newsletter-edit-subscribers-success": "Success message shown on Special:Newsletter's manage form when the subscribers list has been modfied.", + "newsletter-edit-subscribers-nochanges": "Message shown on Special:Newsletter if no changes were made to the existing subscribers' list.", "newsletter-subscribers-nopermission": "Error message shown on Special:Newsletter/id/subscribers if the user is not a publisher and does not have the `newsletter-manage` permission.", "newsletter-available-newsletters-field-label": "Label of HTML form field which lists all available newsletters in wiki", "newsletter-subscribed-newsletters-field-label": "Label of HTML form field which lists all newsletters to which user is subscribed to.", diff --git a/includes/specials/SpecialNewsletter.php b/includes/specials/SpecialNewsletter.php index 9cf0aec..93e43f2 100644 --- a/includes/specials/SpecialNewsletter.php +++ b/includes/specials/SpecialNewsletter.php @@ -484,7 +484,6 @@ 'subscribers' => array( 'type' => 'textarea', 'raw' => true, - 'disabled' => true, 'rows' => 10, 'default' => implode( "\n", $subscribersNames ) ), @@ -492,14 +491,54 @@ $form = $this->getHTMLForm( $fields, - function() { - return false; - } - ); - $form->suppressDefaultSubmit(); - $form->show(); + array( $this, 'submitSubscribersForm' ) + ); + if ( $form->show() ){ + $out->addReturnTo( Title::makeTitleSafe( NS_NEWSLETTER, $this->newsletter->getName() ) ); + }; } + public function submitSubscribersForm(array $data){ + $subscriberNames = explode( "\n", $data['subscribers'] ); + // Strip whitespace, then remove blank lines and duplicates + $subscriberNames = array_unique( array_filter( array_map( 'trim', $subscriberNames ) ) ); + + $oldSubscribersIds = $this->newsletter->getSubscribers(); + $newSubscribersIds = array(); + foreach ( $subscriberNames as $subscriberName ) { + $user = User::newFromName( $subscriberName ); + + if ( !$user || !$user->getId() ) { + // Input contains an invalid username + return Status::newFatal( 'newsletter-manage-invalid-publisher', $subscriberName ); + } + + $newSubscribersIds[] = $user->getId(); + + } + + // Do the actual modifications now + $added = array_diff( $newSubscribersIds, $oldSubscribersIds ); + $removed = array_diff( $oldSubscribersIds, $newSubscribersIds ); + + $store = NewsletterStore::getDefaultInstance(); + // @todo Do this in a batch.. + foreach ( $added as $auId ) { + $store->addSubscription( $this->newsletter, User::newFromId( $auId ) ); + } + foreach ( $removed as $ruId ) { + $store->removeSubscription( $this->newsletter, User::newFromId( $ruId ) ); + } + $out = $this->getOutput(); + // Now report to the user + if ( $added || $removed ) { + $out->addWikiMsg( 'newsletter-edit-subscribers-success' ); + } else { + // Submitted without any changes to the existing subscribers + $out->addWikiMsg( 'newsletter-edit-subscribers-nochanges' ); + } + return true; + } /** * Don't list this page in Special:SpecialPages as we just redirect to * Special:Newsletters if no ID was provided. -- To view, visit https://gerrit.wikimedia.org/r/329055 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie92818811061568a990facdf9ce43dc274e00a79 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Newsletter Gerrit-Branch: master Gerrit-Owner: Pppery <maprea...@olum.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits