MediaWiki
REL1_24
|
00001 <?php 00031 class ApiEmailUser extends ApiBase { 00032 00033 public function execute() { 00034 $params = $this->extractRequestParams(); 00035 00036 // Validate target 00037 $targetUser = SpecialEmailUser::getTarget( $params['target'] ); 00038 if ( !( $targetUser instanceof User ) ) { 00039 $this->dieUsageMsg( array( $targetUser ) ); 00040 } 00041 00042 // Check permissions and errors 00043 $error = SpecialEmailUser::getPermissionsError( 00044 $this->getUser(), 00045 $params['token'], 00046 $this->getConfig() 00047 ); 00048 if ( $error ) { 00049 $this->dieUsageMsg( array( $error ) ); 00050 } 00051 00052 $data = array( 00053 'Target' => $targetUser->getName(), 00054 'Text' => $params['text'], 00055 'Subject' => $params['subject'], 00056 'CCMe' => $params['ccme'], 00057 ); 00058 $retval = SpecialEmailUser::submit( $data, $this->getContext() ); 00059 00060 if ( $retval instanceof Status ) { 00061 // SpecialEmailUser sometimes returns a status 00062 // sometimes it doesn't. 00063 if ( $retval->isGood() ) { 00064 $retval = true; 00065 } else { 00066 $retval = $retval->getErrorsArray(); 00067 } 00068 } 00069 00070 if ( $retval === true ) { 00071 $result = array( 'result' => 'Success' ); 00072 } else { 00073 $result = array( 00074 'result' => 'Failure', 00075 'message' => $retval 00076 ); 00077 } 00078 00079 $this->getResult()->addValue( null, $this->getModuleName(), $result ); 00080 } 00081 00082 public function mustBePosted() { 00083 return true; 00084 } 00085 00086 public function isWriteMode() { 00087 return true; 00088 } 00089 00090 public function getAllowedParams() { 00091 return array( 00092 'target' => array( 00093 ApiBase::PARAM_TYPE => 'string', 00094 ApiBase::PARAM_REQUIRED => true 00095 ), 00096 'subject' => null, 00097 'text' => array( 00098 ApiBase::PARAM_TYPE => 'string', 00099 ApiBase::PARAM_REQUIRED => true 00100 ), 00101 'ccme' => false, 00102 ); 00103 } 00104 00105 public function getParamDescription() { 00106 return array( 00107 'target' => 'User to send email to', 00108 'subject' => 'Subject header', 00109 'text' => 'Mail body', 00110 'ccme' => 'Send a copy of this mail to me', 00111 ); 00112 } 00113 00114 public function getDescription() { 00115 return 'Email a user.'; 00116 } 00117 00118 public function needsToken() { 00119 return 'csrf'; 00120 } 00121 00122 public function getExamples() { 00123 return array( 00124 'api.php?action=emailuser&target=WikiSysop&text=Content&token=123ABC' 00125 => 'Send an email to the User "WikiSysop" with the text "Content"', 00126 ); 00127 } 00128 00129 public function getHelpUrls() { 00130 return 'https://www.mediawiki.org/wiki/API:Email'; 00131 } 00132 }