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
00030
00034 class ApiEmailUser extends ApiBase {
00035
00036 public function __construct($main, $action) {
00037 parent :: __construct($main, $action);
00038 }
00039
00040 public function execute() {
00041 global $wgUser;
00042
00043 if ( !EmailUserForm::userEmailEnabled() )
00044 $this->dieUsageMsg( array( 'usermaildisabled' ) );
00045
00046 $params = $this->extractRequestParams();
00047
00048 if ( !isset( $params['target'] ) )
00049 $this->dieUsageMsg( array( 'missingparam', 'target' ) );
00050 if ( !isset( $params['text'] ) )
00051 $this->dieUsageMsg( array( 'missingparam', 'text' ) );
00052 if ( !isset( $params['token'] ) )
00053 $this->dieUsageMsg( array( 'missingparam', 'token' ) );
00054
00055
00056 $targetUser = EmailUserForm::validateEmailTarget( $params['target'] );
00057 if ( !( $targetUser instanceof User ) )
00058 $this->dieUsageMsg( array( $targetUser ) );
00059
00060
00061 $error = EmailUserForm::getPermissionsError( $wgUser, $params['token'] );
00062 if ( $error )
00063 $this->dieUsageMsg( array( $error ) );
00064
00065
00066 $form = new EmailUserForm( $targetUser, $params['text'], $params['subject'], $params['ccme'] );
00067 $retval = $form->doSubmit();
00068 if ( is_null( $retval ) )
00069 $result = array( 'result' => 'Success' );
00070 else
00071 $result = array( 'result' => 'Failure',
00072 'message' => $retval->getMessage() );
00073
00074 $this->getResult()->addValue( null, $this->getModuleName(), $result );
00075 }
00076
00077 public function mustBePosted() { return true; }
00078
00079 public function isWriteMode() {
00080 return true;
00081 }
00082
00083 public function getAllowedParams() {
00084 return array (
00085 'target' => null,
00086 'subject' => null,
00087 'text' => null,
00088 'token' => null,
00089 'ccme' => false,
00090 );
00091 }
00092
00093 public function getParamDescription() {
00094 return array (
00095 'target' => 'User to send email to',
00096 'subject' => 'Subject header',
00097 'text' => 'Mail body',
00098 'token' => 'A token previously acquired via prop=info',
00099 'ccme' => 'Send a copy of this mail to me',
00100 );
00101 }
00102
00103 public function getDescription() {
00104 return array(
00105 'Email a user.'
00106 );
00107 }
00108
00109 protected function getExamples() {
00110 return array (
00111 'api.php?action=emailuser&target=WikiSysop&text=Content'
00112 );
00113 }
00114
00115 public function getVersion() {
00116 return __CLASS__ . ': $Id: ApiEmailUser.php 48091 2009-03-06 13:49:44Z catrope $';
00117 }
00118 }
00119