00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 if ( !defined( 'MEDIAWIKI' ) ) {
00026
00027 require_once ( "ApiBase.php" );
00028 }
00029
00033 class ApiEmailUser extends ApiBase {
00034
00035 public function __construct( $main, $action ) {
00036 parent :: __construct( $main, $action );
00037 }
00038
00039 public function execute() {
00040 global $wgUser;
00041
00042 if ( !EmailUserForm::userEmailEnabled() )
00043 $this->dieUsageMsg( array( 'usermaildisabled' ) );
00044
00045 $params = $this->extractRequestParams();
00046
00047 if ( !isset( $params['target'] ) )
00048 $this->dieUsageMsg( array( 'missingparam', 'target' ) );
00049 if ( !isset( $params['text'] ) )
00050 $this->dieUsageMsg( array( 'missingparam', 'text' ) );
00051
00052
00053 $targetUser = EmailUserForm::validateEmailTarget( $params['target'] );
00054 if ( !( $targetUser instanceof User ) )
00055 $this->dieUsageMsg( array( $targetUser ) );
00056
00057
00058 $error = EmailUserForm::getPermissionsError( $wgUser, $params['token'] );
00059 if ( $error )
00060 $this->dieUsageMsg( array( $error ) );
00061
00062 $form = new EmailUserForm( $targetUser, $params['text'], $params['subject'], $params['ccme'] );
00063 $retval = $form->doSubmit();
00064 if ( is_null( $retval ) )
00065 $result = array( 'result' => 'Success' );
00066 else
00067 $result = array( 'result' => 'Failure',
00068 'message' => $retval->getMessage() );
00069
00070 $this->getResult()->addValue( null, $this->getModuleName(), $result );
00071 }
00072
00073 public function mustBePosted() {
00074 return true;
00075 }
00076
00077 public function isWriteMode() {
00078 return true;
00079 }
00080
00081 public function getAllowedParams() {
00082 return array (
00083 'target' => null,
00084 'subject' => null,
00085 'text' => null,
00086 'token' => null,
00087 'ccme' => false,
00088 );
00089 }
00090
00091 public function getParamDescription() {
00092 return array (
00093 'target' => 'User to send email to',
00094 'subject' => 'Subject header',
00095 'text' => 'Mail body',
00096 'token' => 'A token previously acquired via prop=info',
00097 'ccme' => 'Send a copy of this mail to me',
00098 );
00099 }
00100
00101 public function getDescription() {
00102 return array(
00103 'Email a user.'
00104 );
00105 }
00106
00107 public function getPossibleErrors() {
00108 return array_merge( parent::getPossibleErrors(), array(
00109 array( 'usermaildisabled' ),
00110 array( 'missingparam', 'target' ),
00111 array( 'missingparam', 'text' ),
00112 ) );
00113 }
00114
00115 public function needsToken() {
00116 return true;
00117 }
00118
00119 public function getTokenSalt() {
00120 return '';
00121 }
00122
00123 protected function getExamples() {
00124 return array (
00125 'api.php?action=emailuser&target=WikiSysop&text=Content'
00126 );
00127 }
00128
00129 public function getVersion() {
00130 return __CLASS__ . ': $Id: ApiEmailUser.php 74217 2010-10-03 15:53:07Z reedy $';
00131 }
00132 }
00133