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; } }
/** * @dataProvider provideNonObjectMessages * @covers Status::getStatusArray */ public function testGetStatusArrayWithNonObjectMessages($nonObjMsg) { $status = new Status(); if (!array_key_exists(1, $nonObjMsg)) { $status->warning($nonObjMsg[0]); } else { $status->warning($nonObjMsg[0], $nonObjMsg[1]); } $array = $status->getWarningsArray(); // We use getWarningsArray to access getStatusArray $this->assertEquals(1, count($array)); $this->assertEquals($nonObjMsg, $array[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()); }
/** * 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); } }
/** * @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()); }