MediaWiki
REL1_19
|
00001 <?php 00031 class ApiEmailUser extends ApiBase { 00032 00033 public function __construct( $main, $action ) { 00034 parent::__construct( $main, $action ); 00035 } 00036 00037 public function execute() { 00038 $params = $this->extractRequestParams(); 00039 00040 // Validate target 00041 $targetUser = SpecialEmailUser::getTarget( $params['target'] ); 00042 if ( !( $targetUser instanceof User ) ) { 00043 $this->dieUsageMsg( array( $targetUser ) ); 00044 } 00045 00046 // Check permissions and errors 00047 $error = SpecialEmailUser::getPermissionsError( $this->getUser(), $params['token'] ); 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 ); 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 'token' => null, 00102 'ccme' => false, 00103 ); 00104 } 00105 00106 public function getParamDescription() { 00107 return array( 00108 'target' => 'User to send email to', 00109 'subject' => 'Subject header', 00110 'text' => 'Mail body', 00111 'token' => 'A token previously acquired via prop=info', 00112 'ccme' => 'Send a copy of this mail to me', 00113 ); 00114 } 00115 00116 public function getDescription() { 00117 return 'Email a user.'; 00118 } 00119 00120 public function getPossibleErrors() { 00121 return array_merge( parent::getPossibleErrors(), array( 00122 array( 'usermaildisabled' ), 00123 ) ); 00124 } 00125 00126 public function needsToken() { 00127 return true; 00128 } 00129 00130 public function getTokenSalt() { 00131 return ''; 00132 } 00133 00134 public function getExamples() { 00135 return array( 00136 'api.php?action=emailuser&target=WikiSysop&text=Content' => 'Send an email to the User "WikiSysop" with the text "Content"', 00137 ); 00138 } 00139 00140 public function getHelpUrls() { 00141 return 'https://www.mediawiki.org/wiki/API:E-mail'; 00142 } 00143 00144 public function getVersion() { 00145 return __CLASS__ . ': $Id$'; 00146 } 00147 }