public function onSuccess()
 {
     if ($this->getUser()->isAllowed('passwordreset') && $this->email != null) {
         // @todo: Logging
         if ($this->result->isGood()) {
             $this->getOutput()->addWikiMsg('passwordreset-emailsent-capture');
         } else {
             $this->getOutput()->addWikiMsg('passwordreset-emailerror-capture', $this->result->getMessage());
         }
         $this->getOutput()->addHTML(Html::rawElement('pre', array(), $this->email->escaped()));
     }
     $this->getOutput()->addWikiMsg('passwordreset-emailsent');
     $this->getOutput()->returnToMain();
 }
 /**
  * @param string $step
  * @param Status $status
  */
 public function endStage($step, $status)
 {
     if ($step == 'extension-tables') {
         $this->endLiveBox();
     }
     $msg = $status->isOk() ? 'config-install-step-done' : 'config-install-step-failed';
     $html = wfMessage('word-separator')->escaped() . wfMessage($msg)->escaped();
     if (!$status->isOk()) {
         $html = "<span class=\"error\">{$html}</span>";
     }
     $this->addHTML($html . "</li>\n");
     if (!$status->isGood()) {
         $this->parent->showStatusBox($status);
     }
 }
 public function onSuccess()
 {
     if ($this->getUser()->isAllowed('passwordreset') && $this->email != null) {
         // @todo Logging
         if ($this->result->isGood()) {
             $this->getOutput()->addWikiMsg('passwordreset-emailsent-capture');
         } else {
             $this->getOutput()->addWikiMsg('passwordreset-emailerror-capture', $this->result->getMessage(), $this->firstUser->getName());
         }
         $this->getOutput()->addHTML(Html::rawElement('pre', [], $this->email->escaped()));
     }
     if ($this->method === 'email') {
         $this->getOutput()->addWikiMsg('passwordreset-emailsentemail');
     } else {
         $this->getOutput()->addWikiMsg('passwordreset-emailsentusername');
     }
     $this->getOutput()->returnToMain();
 }
 public function onSuccess()
 {
     if ($this->getUser()->isAllowed('passwordreset') && $this->passwords) {
         // @todo Logging
         if ($this->result->isGood()) {
             $this->getOutput()->addWikiMsg('passwordreset-emailsent-capture2', count($this->passwords));
         } else {
             $this->getOutput()->addWikiMsg('passwordreset-emailerror-capture2', $this->result->getMessage(), key($this->passwords), count($this->passwords));
         }
         $this->getOutput()->addHTML(Html::openElement('ul'));
         foreach ($this->passwords as $username => $pwd) {
             $this->getOutput()->addHTML(Html::rawElement('li', [], htmlspecialchars($username, ENT_QUOTES) . $this->msg('colon-separator')->text() . htmlspecialchars($pwd, ENT_QUOTES)));
         }
         $this->getOutput()->addHTML(Html::closeElement('ul'));
     }
     if ($this->method === 'email') {
         $this->getOutput()->addWikiMsg('passwordreset-emailsentemail');
     } else {
         $this->getOutput()->addWikiMsg('passwordreset-emailsentusername');
     }
     $this->getOutput()->returnToMain();
 }
Example #5
0
 /**
  * Converts a Status object to an array suitable for addValue
  * @param Status $status
  * @param string $errorType
  * @return array
  */
 public function convertStatusToArray($status, $errorType = 'error')
 {
     if ($status->isGood()) {
         return array();
     }
     $result = array();
     foreach ($status->getErrorsByType($errorType) as $error) {
         $this->setIndexedTagName($error['params'], 'param');
         $result[] = $error;
     }
     $this->setIndexedTagName($result, $errorType);
     return $result;
 }
/**
 * Print status
 * @global integer $failed
 * @param Status $status
 */
function printStatus($status)
{
    global $failed;
    if ($status->isGood()) {
        echo " ... DONE.\n";
    } else {
        $failed++;
        echo " ... FAILED (" . $status->getMessage() . ").\n";
    }
}
 public function arrayFromStatus(Status $status, $type = 'error', $format = null)
 {
     if ($status->isGood() || !$status->errors) {
         return [];
     }
     $result = [];
     foreach ($status->getErrorsByType($type) as $error) {
         if ($error['message'] instanceof Message) {
             $error = ['message' => $error['message']->getKey(), 'params' => $error['message']->getParams()] + $error;
         }
         ApiResult::setIndexedTagName($error['params'], 'param');
         $result[] = $error;
     }
     ApiResult::setIndexedTagName($result, $type);
     return $result;
 }
 /**
  * @dataProvider provideIsGood
  * @covers Status::isGood
  */
 public function testIsGood($ok, $errors, $expected)
 {
     $status = new Status();
     $status->ok = $ok;
     foreach ($errors as $error) {
         $status->warning($error);
     }
     $this->assertEquals($expected, $status->isGood());
 }
Example #9
0
 /**
  * Output an error or warning box using a Status object.
  *
  * @param Status $status
  */
 public function showStatusBox($status)
 {
     if (!$status->isGood()) {
         $text = $status->getWikiText();
         if ($status->isOk()) {
             $box = $this->getWarningBox($text);
         } else {
             $box = $this->getErrorBox($text);
         }
         $this->output->addHTML($box);
     }
 }
Example #10
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());
         }
     }
 }
Example #11
0
 /**
  * Run hooks that can filter edits just before they get saved.
  *
  * @param Content $content The Content to filter.
  * @param Status $status For reporting the outcome to the caller
  * @param User $user The user performing the edit
  *
  * @return bool
  */
 protected function runPostMergeFilters(Content $content, Status $status, User $user)
 {
     // Run old style post-section-merge edit filter
     if (!ContentHandler::runLegacyHooks('EditFilterMerged', array($this, $content, &$this->hookError, $this->summary))) {
         # Error messages etc. could be handled within the hook...
         $status->fatal('hookaborted');
         $status->value = self::AS_HOOK_ERROR;
         return false;
     } elseif ($this->hookError != '') {
         # ...or the hook could be expecting us to produce an error
         $status->fatal('hookaborted');
         $status->value = self::AS_HOOK_ERROR_EXPECTED;
         return false;
     }
     // Run new style post-section-merge edit filter
     if (!Hooks::run('EditFilterMergedContent', array($this->mArticle->getContext(), $content, $status, $this->summary, $user, $this->minoredit))) {
         # Error messages etc. could be handled within the hook...
         if ($status->isGood()) {
             $status->fatal('hookaborted');
             // Not setting $this->hookError here is a hack to allow the hook
             // to cause a return to the edit page without $this->hookError
             // being set. This is used by ConfirmEdit to display a captcha
             // without any error message cruft.
         } else {
             $this->hookError = $status->getWikiText();
         }
         // Use the existing $status->value if the hook set it
         if (!$status->value) {
             $status->value = self::AS_HOOK_ERROR;
         }
         return false;
     } elseif (!$status->isOK()) {
         # ...or the hook could be expecting us to produce an error
         // FIXME this sucks, we should just use the Status object throughout
         $this->hookError = $status->getWikiText();
         $status->fatal('hookaborted');
         $status->value = self::AS_HOOK_ERROR_EXPECTED;
         return false;
     }
     return true;
 }
Example #12
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();
     }
 }
Example #13
0
 /**
  * Get error (as code, string) from a Status object.
  *
  * @since 1.23
  * @param Status $status
  * @param array|null &$extraData Set if extra data from IApiMessage is available (since 1.27)
  * @return array Array of code and error string
  * @throws MWException
  */
 public function getErrorFromStatus($status, &$extraData = null)
 {
     if ($status->isGood()) {
         throw new MWException('Successful status passed to ApiBase::dieStatus');
     }
     $errors = $status->getErrorsByType('error');
     if (!$errors) {
         // No errors? Assume the warnings should be treated as errors
         $errors = $status->getErrorsByType('warning');
     }
     if (!$errors) {
         // Still no errors? Punt
         $errors = [['message' => 'unknownerror-nocode', 'params' => []]];
     }
     // Cannot use dieUsageMsg() because extensions might return custom
     // error messages.
     if ($errors[0]['message'] instanceof Message) {
         $msg = $errors[0]['message'];
         if ($msg instanceof IApiMessage) {
             $extraData = $msg->getApiData();
             $code = $msg->getApiCode();
         } else {
             $code = $msg->getKey();
         }
     } else {
         $code = $errors[0]['message'];
         $msg = wfMessage($code, $errors[0]['params']);
     }
     if (isset(ApiBase::$messageMap[$code])) {
         // Translate message to code, for backwards compatibility
         $code = ApiBase::$messageMap[$code]['code'];
     }
     return [$code, $msg->inLanguage('en')->useDatabase(false)->plain()];
 }
Example #14
0
 /**
  * @param string|array|Status $elements
  * @param string $elementsType
  * @return string
  */
 function getErrorsOrWarnings($elements, $elementsType)
 {
     if (!in_array($elementsType, ['error', 'warning'])) {
         throw new DomainException($elementsType . ' is not a valid type.');
     }
     if (!$elements) {
         $errors = [];
     } elseif ($elements instanceof Status) {
         if ($elements->isGood()) {
             $errors = [];
         } else {
             $errors = $elements->getErrorsByType($elementsType);
             foreach ($errors as &$error) {
                 // Input:  [ 'message' => 'foo', 'errors' => [ 'a', 'b', 'c' ] ]
                 // Output: [ 'foo', 'a', 'b', 'c' ]
                 $error = array_merge([$error['message']], $error['params']);
             }
         }
     } elseif ($elementsType === 'errors') {
         $errors = $elements;
         if (!is_array($errors)) {
             $errors = [$errors];
         }
     } else {
         $errors = [];
     }
     foreach ($errors as &$error) {
         $error = $this->getMessage($error)->parse();
         $error = new OOUI\HtmlSnippet($error);
     }
     // Used in getBody()
     if ($elementsType === 'error') {
         $this->oouiErrors = $errors;
     } else {
         $this->oouiWarnings = $errors;
     }
     return '';
 }
 public function assertGoodStatus(\Status $status)
 {
     if (!$status->isGood()) {
         $msg = wfMessage("email-error-bad-status", $status->getMessage())->escaped();
         throw new Fatal($msg);
     }
 }
Example #16
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());
 }
 /**
  * @dataProvider provideIsGood
  * @covers Status::isGood
  */
 public function testIsGood($ok, $errors, $expected)
 {
     $status = new Status();
     $status->ok = $ok;
     $status->errors = $errors;
     $this->assertEquals($expected, $status->isGood());
 }
 public function onSubmit(array $data)
 {
     global $wgContLang;
     if ($data['pagetitle'] === '') {
         // Initial form view of special page, pass
         return false;
     }
     // At this point, it has to be a POST request. This is enforced by HTMLForm,
     // but lets be safe verify that.
     if (!$this->getRequest()->wasPosted()) {
         throw new RuntimeException("Form submission was not POSTed");
     }
     $this->title = Title::newFromText($data['pagetitle']);
     $titleWithNewContentModel = clone $this->title;
     $titleWithNewContentModel->setContentModel($data['model']);
     $user = $this->getUser();
     // Check permissions and make sure the user has permission to:
     $errors = wfMergeErrorArrays($this->title->getUserPermissionsErrors('editcontentmodel', $user), $this->title->getUserPermissionsErrors('edit', $user), $titleWithNewContentModel->getUserPermissionsErrors('editcontentmodel', $user), $titleWithNewContentModel->getUserPermissionsErrors('edit', $user));
     if ($errors) {
         $out = $this->getOutput();
         $wikitext = $out->formatPermissionsErrorMessage($errors);
         // Hack to get our wikitext parsed
         return Status::newFatal(new RawMessage('$1', [$wikitext]));
     }
     $page = WikiPage::factory($this->title);
     if ($this->oldRevision === null) {
         $this->oldRevision = $page->getRevision() ?: false;
     }
     $oldModel = $this->title->getContentModel();
     if ($this->oldRevision) {
         $oldContent = $this->oldRevision->getContent();
         try {
             $newContent = ContentHandler::makeContent($oldContent->getNativeData(), $this->title, $data['model']);
         } catch (MWException $e) {
             return Status::newFatal($this->msg('changecontentmodel-cannot-convert')->params($this->title->getPrefixedText(), ContentHandler::getLocalizedName($data['model'])));
         }
     } else {
         // Page doesn't exist, create an empty content object
         $newContent = ContentHandler::getForModelID($data['model'])->makeEmptyContent();
     }
     // All other checks have passed, let's check rate limits
     if ($user->pingLimiter('editcontentmodel')) {
         throw new ThrottledError();
     }
     $flags = $this->oldRevision ? EDIT_UPDATE : EDIT_NEW;
     $flags |= EDIT_INTERNAL;
     if ($user->isAllowed('bot')) {
         $flags |= EDIT_FORCE_BOT;
     }
     $log = new ManualLogEntry('contentmodel', $this->oldRevision ? 'change' : 'new');
     $log->setPerformer($user);
     $log->setTarget($this->title);
     $log->setComment($data['reason']);
     $log->setParameters(['4::oldmodel' => $oldModel, '5::newmodel' => $data['model']]);
     $formatter = LogFormatter::newFromEntry($log);
     $formatter->setContext(RequestContext::newExtraneousContext($this->title));
     $reason = $formatter->getPlainActionText();
     if ($data['reason'] !== '') {
         $reason .= $this->msg('colon-separator')->inContentLanguage()->text() . $data['reason'];
     }
     # Truncate for whole multibyte characters.
     $reason = $wgContLang->truncate($reason, 255);
     // Run edit filters
     $derivativeContext = new DerivativeContext($this->getContext());
     $derivativeContext->setTitle($this->title);
     $derivativeContext->setWikiPage($page);
     $status = new Status();
     if (!Hooks::run('EditFilterMergedContent', [$derivativeContext, $newContent, $status, $reason, $user, false])) {
         if ($status->isGood()) {
             // TODO: extensions should really specify an error message
             $status->fatal('hookaborted');
         }
         return $status;
     }
     $status = $page->doEditContent($newContent, $reason, $flags, $this->oldRevision ? $this->oldRevision->getId() : false, $user);
     if (!$status->isOK()) {
         return $status;
     }
     $logid = $log->insert();
     $log->publish($logid);
     return $status;
 }