Example #1
0
 public function showStatusMessage(Status $status)
 {
     $warnings = array_merge($status->getWarningsArray(), $status->getErrorsArray());
     if (count($warnings) !== 0) {
         foreach ($warnings as $w) {
             call_user_func_array(array($this, 'showMessage'), $w);
         }
     }
     if (!$status->isOk()) {
         echo "\n";
         exit;
     }
 }
Example #2
0
 /**
  * Get error (as code, string) from a Status object.
  *
  * @since 1.23
  * @param Status $status
  * @return array Array of code and error string
  * @throws MWException
  */
 public function getErrorFromStatus($status)
 {
     if ($status->isGood()) {
         throw new MWException('Successful status passed to ApiBase::dieStatus');
     }
     $errors = $status->getErrorsArray();
     if (!$errors) {
         // No errors? Assume the warnings should be treated as errors
         $errors = $status->getWarningsArray();
     }
     if (!$errors) {
         // Still no errors? Punt
         $errors = array(array('unknownerror-nocode'));
     }
     // Cannot use dieUsageMsg() because extensions might return custom
     // error messages.
     if ($errors[0] instanceof Message) {
         $msg = $errors[0];
         $code = $msg->getKey();
     } else {
         $code = array_shift($errors[0]);
         $msg = wfMessage($code, $errors[0]);
     }
     if (isset(ApiBase::$messageMap[$code])) {
         // Translate message to code, for backwards compatibility
         $code = ApiBase::$messageMap[$code]['code'];
     }
     return array($code, $msg->inLanguage('en')->useDatabase(false)->plain());
 }
 /**
  * @covers Status::merge
  */
 public function testMergeWithOverwriteValue()
 {
     $status1 = new Status();
     $status2 = new Status();
     $message1 = $this->getMockMessage('warn1');
     $message2 = $this->getMockMessage('error2');
     $status1->warning($message1);
     $status2->error($message2);
     $status2->value = 'FooValue';
     $status1->merge($status2, true);
     $this->assertEquals(2, count($status1->getWarningsArray()) + count($status1->getErrorsArray()));
     $this->assertEquals('FooValue', $status1->getValue());
 }
 /**
  * Returns wikitext of status error message in content language
  *
  * @param Status $s
  * @return String
  */
 private function errorText(Status $s)
 {
     $errors = array_merge($s->getErrorsArray(), $s->getWarningsArray());
     if (!count($errors)) {
         return '';
     }
     $err = $errors[0];
     $message = array_shift($err);
     return wfMessage($message)->params($err)->inContentLanguage()->plain();
 }
 /**
  * @param $status Status
  */
 public function showStatusMessage(Status $status)
 {
     $errors = array_merge($status->getErrorsArray(), $status->getWarningsArray());
     foreach ($errors as $error) {
         call_user_func_array(array($this, 'showMessage'), $error);
     }
 }
Example #6
0
 /**
  * Leave a message on the user talk page or in the session according to
  * $params['leaveMessage'].
  *
  * @param Status $status
  */
 protected function leaveMessage($status)
 {
     if ($this->params['leaveMessage']) {
         if ($status->isGood()) {
             // @todo FIXME: user->leaveUserMessage does not exist.
             $this->user->leaveUserMessage(wfMessage('upload-success-subj')->text(), wfMessage('upload-success-msg', $this->upload->getTitle()->getText(), $this->params['url'])->text());
         } else {
             // @todo FIXME: user->leaveUserMessage does not exist.
             $this->user->leaveUserMessage(wfMessage('upload-failure-subj')->text(), wfMessage('upload-failure-msg', $status->getWikiText(), $this->params['url'])->text());
         }
     } else {
         wfSetupSession($this->params['sessionId']);
         if ($status->isOk()) {
             $this->storeResultInSession('Success', 'filename', $this->upload->getLocalFile()->getName());
         } else {
             $this->storeResultInSession('Failure', 'errors', $status->getErrorsArray());
         }
         session_write_close();
     }
 }
 /**
  * This is attached to the MediaWiki 'EditPage::attemptSave:after' hook.
  *
  * @param EditPage $editPage
  * @param Status $status
  * @return boolean
  */
 public static function editPageAttemptSaveAfter(EditPage $editPage, Status $status)
 {
     $article = $editPage->getArticle();
     $request = $article->getContext()->getRequest();
     if ($request->getVal('editingStatsId')) {
         $data = array();
         $data['editingSessionId'] = $request->getVal('editingStatsId');
         if ($status->isOK()) {
             $action = 'saveSuccess';
         } else {
             $action = 'saveFailure';
             $errors = $status->getErrorsArray();
             if (isset($errors[0][0])) {
                 $data['action.saveFailure.message'] = $errors[0][0];
             }
             if ($status->value === EditPage::AS_CONFLICT_DETECTED) {
                 $data['action.saveFailure.type'] = 'editConflict';
             } elseif ($status->value === EditPage::AS_ARTICLE_WAS_DELETED) {
                 $data['action.saveFailure.type'] = 'editPageDeleted';
             } elseif (isset($errors[0][0]) && $errors[0][0] === 'abusefilter-disallowed') {
                 $data['action.saveFailure.type'] = 'extensionAbuseFilter';
             } elseif (isset($editPage->getArticle()->getPage()->ConfirmEdit_ActivateCaptcha)) {
                 // TODO: :(
                 $data['action.saveFailure.type'] = 'extensionCaptcha';
             } elseif (isset($errors[0][0]) && $errors[0][0] === 'spamprotectiontext') {
                 $data['action.saveFailure.type'] = 'extensionSpamBlacklist';
             } else {
                 // Catch everything else... We don't seem to get userBadToken or
                 // userNewUser through this hook.
                 $data['action.saveFailure.type'] = 'responseUnknown';
             }
         }
         self::doEventLogging($action, $article, $data);
     }
     return true;
 }
Example #8
0
 /**
  * Leave a message on the user talk page or in the session according to
  * $params['leaveMessage'].
  *
  * @param Status $status
  */
 protected function leaveMessage($status)
 {
     if ($this->params['leaveMessage']) {
         if ($status->isGood()) {
             // @todo FIXME: user->leaveUserMessage does not exist.
             $this->user->leaveUserMessage(wfMessage('upload-success-subj')->text(), wfMessage('upload-success-msg', $this->upload->getTitle()->getText(), $this->params['url'])->text());
         } else {
             // @todo FIXME: user->leaveUserMessage does not exist.
             $this->user->leaveUserMessage(wfMessage('upload-failure-subj')->text(), wfMessage('upload-failure-msg', $status->getWikiText(), $this->params['url'])->text());
         }
     } else {
         $session = MediaWiki\Session\SessionManager::singleton()->getSessionById($this->params['sessionId']);
         if ($status->isOk()) {
             $this->storeResultInSession($session, 'Success', 'filename', $this->upload->getLocalFile()->getName());
         } else {
             $this->storeResultInSession($session, 'Failure', 'errors', $status->getErrorsArray());
         }
     }
 }