Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -76,6 +76,7 @@ |
77 | 77 | 'unblock' => 'ApiUnblock', |
78 | 78 | 'move' => 'ApiMove', |
79 | 79 | 'edit' => 'ApiEditPage', |
| 80 | + 'emailuser' => 'ApiEmailUser', |
80 | 81 | ); |
81 | 82 | |
82 | 83 | /** |
Index: trunk/phase3/includes/api/ApiEmailUser.php |
— | — | @@ -0,0 +1,117 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * Created on June 1, 2008 |
| 6 | + * API for MediaWiki 1.8+ |
| 7 | + * |
| 8 | + * Copyright (C) 2008 Bryan Tong Minh <Bryan.TongMinh@Gmail.com> |
| 9 | + * |
| 10 | + * This program is free software; you can redistribute it and/or modify |
| 11 | + * it under the terms of the GNU General Public License as published by |
| 12 | + * the Free Software Foundation; either version 2 of the License, or |
| 13 | + * (at your option) any later version. |
| 14 | + * |
| 15 | + * This program is distributed in the hope that it will be useful, |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | + * GNU General Public License for more details. |
| 19 | + * |
| 20 | + * You should have received a copy of the GNU General Public License along |
| 21 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 23 | + * http://www.gnu.org/copyleft/gpl.html |
| 24 | + */ |
| 25 | + |
| 26 | +if (!defined('MEDIAWIKI')) { |
| 27 | + // Eclipse helper - will be ignored in production |
| 28 | + require_once ("ApiBase.php"); |
| 29 | +} |
| 30 | + |
| 31 | + |
| 32 | +/** |
| 33 | + * @ingroup API |
| 34 | + */ |
| 35 | +class ApiEmailUser extends ApiBase { |
| 36 | + |
| 37 | + public function __construct($main, $action) { |
| 38 | + parent :: __construct($main, $action); |
| 39 | + } |
| 40 | + |
| 41 | + public function execute() { |
| 42 | + global $wgUser; |
| 43 | + $this->getMain()->requestWriteMode(); |
| 44 | + $params = $this->extractRequestParams(); |
| 45 | + |
| 46 | + // Check required parameters |
| 47 | + if ( !isset( $params['target'] ) ) |
| 48 | + $this->dieUsageMsg( array( 'missingparam', 'target' ) ); |
| 49 | + if ( !isset( $params['text'] ) ) |
| 50 | + $this->dieUsageMsg( array( 'missingparam', 'text' ) ); |
| 51 | + if ( !isset( $params['token'] ) ) |
| 52 | + $this->dieUsageMsg( array( 'missingparam', 'token' ) ); |
| 53 | + |
| 54 | + // Match edit token |
| 55 | + if( !$wgUser->matchEditToken( $params['token'] ) ) |
| 56 | + $this->dieUsageMsg( array( 'sessionfailure' ) ); |
| 57 | + |
| 58 | + // Check permissions |
| 59 | + $errors = EmailUserForm::getPermissionsError( $params['target'] ); |
| 60 | + if ( $errors ) |
| 61 | + $this->dieUsageMsg( $errors[0] ); |
| 62 | + |
| 63 | + // Rate limiter |
| 64 | + if( $wgUser->pingLimiter( 'emailuser' ) ) |
| 65 | + $this->dieUsageMsg( 'actionthrottledtext' ); |
| 66 | + |
| 67 | + $form = EmailUserForm::newFromURL( $params['target'], |
| 68 | + $params['text'], $params['subject'], $params['ccme'] ); |
| 69 | + $retval = $form->doSubmit(); |
| 70 | + if ( is_null( $retval ) ) |
| 71 | + $result = array(); |
| 72 | + else |
| 73 | + $result = array( 'result' => 'Failure', |
| 74 | + 'message' => $retval->getMessage() ); |
| 75 | + |
| 76 | + $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
| 77 | + } |
| 78 | + |
| 79 | + public function mustBePosted() { return true; } |
| 80 | + |
| 81 | + public function getAllowedParams() { |
| 82 | + return array ( |
| 83 | + 'target' => null, |
| 84 | + 'subject' => null, |
| 85 | + 'text' => null, |
| 86 | + 'token' => null, |
| 87 | + 'ccme' => false, |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + public function getParamDescription() { |
| 92 | + return array ( |
| 93 | + 'target' => 'User to send email to', |
| 94 | + 'subject' => 'Subject header', |
| 95 | + 'text' => 'Mail body', |
| 96 | + // FIXME: How to properly get a token? |
| 97 | + 'token' => 'A token previously acquired via prop=info', |
| 98 | + 'ccme' => 'Send a copy of this mail to me', |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + public function getDescription() { |
| 103 | + return array( |
| 104 | + 'Emails a user.' |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + protected function getExamples() { |
| 109 | + return array ( |
| 110 | + 'api.php?action=emailuser&target=WikiSysop&text=Content' |
| 111 | + ); |
| 112 | + } |
| 113 | + |
| 114 | + public function getVersion() { |
| 115 | + return __CLASS__ . ': $Id: $'; |
| 116 | + } |
| 117 | +} |
| 118 | + |
\ No newline at end of file |
Property changes on: trunk/phase3/includes/api/ApiEmailUser.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 119 | + native |
Index: trunk/phase3/includes/SpecialEmailuser.php |
— | — | @@ -188,7 +188,7 @@ |
189 | 189 | // We can either show them an error, or we can say everything was fine, |
190 | 190 | // or we can say we sort of failed AND sort of succeeded. Of these options, |
191 | 191 | // simply saying there was an error is probably best. |
192 | | - return $ccResult->getMessage(); |
| 192 | + return $ccResult; |
193 | 193 | } |
194 | 194 | } |
195 | 195 | } |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -336,6 +336,7 @@ |
337 | 337 | |
338 | 338 | # API |
339 | 339 | 'ApiBase' => 'includes/api/ApiBase.php', |
| 340 | + 'ApiEmailUser' => 'includes/api/ApiEmailUser.php', |
340 | 341 | 'ApiExpandTemplates' => 'includes/api/ApiExpandTemplates.php', |
341 | 342 | 'ApiFeedWatchlist' => 'includes/api/ApiFeedWatchlist.php', |
342 | 343 | 'ApiFormatBase' => 'includes/api/ApiFormatBase.php', |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -389,6 +389,7 @@ |
390 | 390 | * action=block now returns an ISO8601 timestamp, like all other modules do |
391 | 391 | * Added md5 parameter to action=edit |
392 | 392 | * (bug 14335) Logging in to unified account using API not possible |
| 393 | +* Added action=emailuser to send an email to a user |
393 | 394 | |
394 | 395 | === Languages updated in 1.13 === |
395 | 396 | |