예제 #1
0
 public function execute()
 {
     $params = $this->extractRequestParams();
     // Validate target
     $targetUser = SpecialEmailUser::getTarget($params['target']);
     if (!$targetUser instanceof User) {
         $this->dieUsageMsg([$targetUser]);
     }
     // Check permissions and errors
     $error = SpecialEmailUser::getPermissionsError($this->getUser(), $params['token'], $this->getConfig());
     if ($error) {
         $this->dieUsageMsg([$error]);
     }
     $data = ['Target' => $targetUser->getName(), 'Text' => $params['text'], 'Subject' => $params['subject'], 'CCMe' => $params['ccme']];
     $retval = SpecialEmailUser::submit($data, $this->getContext());
     if ($retval instanceof Status) {
         // SpecialEmailUser sometimes returns a status
         // sometimes it doesn't.
         if ($retval->isGood()) {
             $retval = true;
         } else {
             $retval = $retval->getErrorsArray();
         }
     }
     if ($retval === true) {
         $result = ['result' => 'Success'];
     } else {
         $result = ['result' => 'Failure', 'message' => $retval];
     }
     $this->getResult()->addValue(null, $this->getModuleName(), $result);
 }
 function execute($par)
 {
     global $wgOut, $wgUser, $wgEmailAuthentication;
     $this->setHeaders();
     if (!$this->userCanExecute($wgUser)) {
         $this->displayRestrictionError();
         return;
     }
     $error = SpecialEmailUser::getPermissionsError($wgUser, $wgUser->editToken());
     if ($error) {
         switch ($error) {
             case 'blockedemailuser':
                 $wgOut->blockedPage();
                 return;
             case 'actionthrottledtext':
                 $wgOut->rateLimited();
                 return;
             case 'mailnologin':
                 $wgOut->showErrorPage('mailnologin', 'mailnologintext');
                 return;
             default:
                 list($title, $msg, $params) = $error;
                 $wgOut->showErrorPage($title, $msg, $params);
                 return;
         }
     }
     $dbr = wfGetDB(DB_SLAVE);
     # $conds can be not that strict but cannot be too strict.
     $conds = array("user_email <> ''");
     if ($wgEmailAuthentication) {
         $conds[] = 'user_email_authenticated IS NOT NULL';
     }
     $res = $dbr->select('user', '*', $conds);
     $users = UserArray::newFromResult($res);
     $usernames = array();
     foreach ($users as $user) {
         if ($user->canReceiveEmail() && $user->getId() != $wgUser->getId()) {
             $usernames[$user->getName()] = $user->getId();
         }
     }
     $this->userIds = array_values($usernames);
     if (empty($usernames)) {
         # No one to send mail to
         $wgOut->addWikiMsg('emailusers-norecipient');
         $wgOut->returnToMain();
         return;
     }
     $form = array('target' => array('type' => 'multiselect', 'label-message' => 'emailto', 'options' => $usernames, 'validation-callback' => array($this, 'validateTarget')), 'target-reverse' => array('type' => 'check', 'default' => true, 'label-message' => 'emailusers-target-reverse'), 'subject' => array('type' => 'text', 'default' => wfMsg('defemailsubject'), 'label-message' => 'emailsubject'), 'text' => array('type' => 'textarea', 'label-message' => 'emailmessage'), 'ccme' => array('type' => 'check', 'default' => $wgUser->getOption('ccmeonemails'), 'label-message' => 'emailccme'));
     $htmlForm = new HTMLForm($form);
     $htmlForm->setTitle($this->getTitle($par));
     $htmlForm->setSubmitCallback(array($this, 'submit'));
     $this->outputHeader();
     if ($htmlForm->show()) {
         $wgOut->addWikiMsg('emailsenttext');
         $htmlForm->displayForm(false);
     }
 }
 /**
  * Adds resources to ResourceLoader
  * @param OutputPage $out
  * @param Skin $skin
  * @return boolean Always true to keep hook running
  */
 public function onBeforePageDisplay(&$out, &$skin)
 {
     $out->addModules('ext.bluespice.contextmenu');
     //We check if the current user can send Mails trough the wiki
     //TODO: Maybe move to BSF?
     $mEMailPermissioErrors = SpecialEmailUser::getPermissionsError($this->getUser(), $this->getUser()->getEditToken());
     $bUserCanSendMail = false;
     if ($mEMailPermissioErrors === null) {
         $bUserCanSendMail = true;
     }
     $out->addJsConfigVars('bsUserCanSendMail', $bUserCanSendMail);
     return true;
 }