Index: trunk/extensions/Contest/Contest.php |
— | — | @@ -51,6 +51,7 @@ |
52 | 52 | |
53 | 53 | $wgAutoloadClasses['ApiContestQuery'] = dirname( __FILE__ ) . '/api/ApiContestQuery.php'; |
54 | 54 | $wgAutoloadClasses['ApiDeleteContest'] = dirname( __FILE__ ) . '/api/ApiDeleteContest.php'; |
| 55 | +$wgAutoloadClasses['ApiMailContestants'] = dirname( __FILE__ ) . '/api/ApiMailContestants.php'; |
55 | 56 | $wgAutoloadClasses['ApiQueryChallenges'] = dirname( __FILE__ ) . '/api/ApiQueryChallenges.php'; |
56 | 57 | $wgAutoloadClasses['ApiQueryContestants'] = dirname( __FILE__ ) . '/api/ApiQueryContestants.php'; |
57 | 58 | $wgAutoloadClasses['ApiQueryContestComments'] = dirname( __FILE__ ) . '/api/ApiQueryContestComments.php'; |
— | — | @@ -93,6 +94,7 @@ |
94 | 95 | |
95 | 96 | // API |
96 | 97 | $wgAPIModules['deletecontest'] = 'ApiDeleteContest'; |
| 98 | +// $wgAPIModules['mailcontestants'] = 'ApiMailContestants'; // TODO |
97 | 99 | $wgAPIListModules['challenges'] = 'ApiQueryChallenges'; |
98 | 100 | $wgAPIListModules['contestants'] = 'ApiQueryContestants'; |
99 | 101 | $wgAPIListModules['contestcomments'] = 'ApiQueryContestComments'; |
Index: trunk/extensions/Contest/api/ApiMailContestants.php |
— | — | @@ -0,0 +1,183 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to mail contestants. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file ApiMailContestants.php |
| 10 | + * @ingroup Contest |
| 11 | + * @ingroup API |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class ApiMailContestants extends ApiBase { |
| 17 | + |
| 18 | + public function __construct( $main, $action ) { |
| 19 | + parent::__construct( $main, $action ); |
| 20 | + } |
| 21 | + |
| 22 | + public function execute() { |
| 23 | + global $wgUser; |
| 24 | + |
| 25 | + if ( !$wgUser->isAllowed( 'contestadmin' ) || $wgUser->isBlocked() ) { |
| 26 | + $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
| 27 | + } |
| 28 | + |
| 29 | + $params = $this->extractRequestParams(); |
| 30 | + |
| 31 | + $everythingOk = true; |
| 32 | + |
| 33 | + $contestIds = array(); |
| 34 | + $challengeIds = array(); |
| 35 | + |
| 36 | + if ( !is_null( 'challengetitles' ) ) { |
| 37 | + |
| 38 | + } |
| 39 | + |
| 40 | + if ( !is_null( 'contestnames' ) ) { |
| 41 | + |
| 42 | + } |
| 43 | + |
| 44 | + $conditions = array(); |
| 45 | + // TODO |
| 46 | + if ( count( $contestIds ) > 0 ) { |
| 47 | + $conditions[] = array( 'contest_id' => $contestIds ); |
| 48 | + } |
| 49 | + |
| 50 | + if ( count( $challengeIds ) > 0 ) { |
| 51 | + $conditions[] = array( 'challenge_id' => $challengeIds ); |
| 52 | + } |
| 53 | + |
| 54 | + if ( !is_null( $params['ids'] ) && count( $params['ids'] ) > 0 ) { |
| 55 | + $conditions[] = array( 'id' => $params['ids'] ); |
| 56 | + } |
| 57 | + |
| 58 | + $contestants = ContestContestant::s()->select( 'email', $conditions ); |
| 59 | + |
| 60 | + if ( $contestants !== false && count( $contestants ) > 0 ) { |
| 61 | + $recipients = array(); |
| 62 | + |
| 63 | + foreach ( $contestants as /* ContestContestant */ $contestant ) { |
| 64 | + $recipients[] = $contestant->getField( 'email' ); |
| 65 | + } |
| 66 | + |
| 67 | + $everythingOk = $this->sendReminderEmail( $recipients ); |
| 68 | + } |
| 69 | + |
| 70 | + $this->getResult()->addValue( |
| 71 | + null, |
| 72 | + 'success', |
| 73 | + $everythingOk |
| 74 | + ); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * TODO |
| 79 | + * |
| 80 | + * Send a reminder email. |
| 81 | + * |
| 82 | + * @since 0.1 |
| 83 | + * |
| 84 | + * @return Status |
| 85 | + */ |
| 86 | + public function sendReminderEmail( array $recipients ) { |
| 87 | + global $wgPasswordSender, $wgPasswordSenderName; |
| 88 | + |
| 89 | + $title = wfMsgExt( 'contest-email-reminder-title', 'parsemag', $this->getContest()->getDaysLeft() ); |
| 90 | + $emailText = ContestUtils::getParsedArticleContent( $this->getContest()->getField( 'reminder_email' ) ); |
| 91 | + $user = $this->getUser(); |
| 92 | + $sender = $wgPasswordSender; |
| 93 | + $senderName = $wgPasswordSenderName; |
| 94 | + |
| 95 | + wfRunHooks( 'ContestBeforeReminderEmail', array( &$this, &$title, &$emailText, &$user, &$sender, &$senderName ) ); |
| 96 | + |
| 97 | + return UserMailer::send( |
| 98 | + new MailAddress( $user ), |
| 99 | + new MailAddress( $sender, $senderName ), |
| 100 | + $title, |
| 101 | + $emailText, |
| 102 | + null, |
| 103 | + 'text/html; charset=ISO-8859-1' |
| 104 | + ); |
| 105 | + } |
| 106 | + /* |
| 107 | + public function needsToken() { |
| 108 | + return true; |
| 109 | + } |
| 110 | + |
| 111 | + public function getTokenSalt() { |
| 112 | + $params = $this->extractRequestParams(); |
| 113 | + return 'deletecontest' . implode( '|', $params['ids'] ); // TODO |
| 114 | + } |
| 115 | + |
| 116 | + public function mustBePosted() { |
| 117 | + return true; |
| 118 | + } |
| 119 | + */ |
| 120 | + public function getAllowedParams() { |
| 121 | + return array( |
| 122 | + 'ids' => array( |
| 123 | + ApiBase::PARAM_TYPE => 'integer', |
| 124 | + ApiBase::PARAM_REQUIRED => false, |
| 125 | + ApiBase::PARAM_ISMULTI => true, |
| 126 | + ), |
| 127 | + 'contestids' => array( |
| 128 | + ApiBase::PARAM_TYPE => 'integer', |
| 129 | + ApiBase::PARAM_REQUIRED => false, |
| 130 | + ApiBase::PARAM_ISMULTI => true, |
| 131 | + ), |
| 132 | + 'contestnames' => array( |
| 133 | + ApiBase::PARAM_TYPE => 'integer', |
| 134 | + ApiBase::PARAM_REQUIRED => false, |
| 135 | + ApiBase::PARAM_ISMULTI => true, |
| 136 | + ), |
| 137 | + 'challengeids' => array( |
| 138 | + ApiBase::PARAM_TYPE => 'integer', |
| 139 | + ApiBase::PARAM_REQUIRED => false, |
| 140 | + ApiBase::PARAM_ISMULTI => true, |
| 141 | + ), |
| 142 | + 'challengetitles' => array( |
| 143 | + ApiBase::PARAM_TYPE => 'integer', |
| 144 | + ApiBase::PARAM_REQUIRED => false, |
| 145 | + ApiBase::PARAM_ISMULTI => true, |
| 146 | + ), |
| 147 | + 'token' => null, |
| 148 | + ); |
| 149 | + } |
| 150 | + |
| 151 | + public function getParamDescription() { |
| 152 | + return array( |
| 153 | + 'ids' => 'The IDs of the contestants to mail', |
| 154 | + 'token' => 'Edit token', |
| 155 | + ); |
| 156 | + } |
| 157 | + |
| 158 | + public function getDescription() { |
| 159 | + return array( |
| 160 | + 'API module for mailing contestants. The provided conditions such as contest ids and challenge titles will be joined with AND.' |
| 161 | + ); |
| 162 | + } |
| 163 | + |
| 164 | + public function getPossibleErrors() { |
| 165 | + return array_merge( parent::getPossibleErrors(), array( |
| 166 | + array( 'missingparam', 'ids' ), |
| 167 | + ) ); |
| 168 | + } |
| 169 | + |
| 170 | + protected function getExamples() { |
| 171 | + return array( |
| 172 | + 'api.php?action=mailcontestants&ids=42', |
| 173 | + 'api.php?action=mailcontestants&ids=4|2', |
| 174 | + 'api.php?action=mailcontestants&contestids=42', |
| 175 | + 'api.php?action=mailcontestants&contestnames=Weekend of Code', |
| 176 | + 'api.php?action=mailcontestants&challengetitles=foo|bar|baz', |
| 177 | + ); |
| 178 | + } |
| 179 | + |
| 180 | + public function getVersion() { |
| 181 | + return __CLASS__ . ': $Id: $'; |
| 182 | + } |
| 183 | + |
| 184 | +} |
Property changes on: trunk/extensions/Contest/api/ApiMailContestants.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 185 | + native |