55 public static function wrap( $sv ) {
56 if ( $sv instanceof
static ) {
60 $result =
new static();
61 $result->ok =& $sv->ok;
62 $result->errors =& $sv->errors;
63 $result->value =& $sv->value;
64 $result->successCount =& $sv->successCount;
65 $result->failCount =& $sv->failCount;
66 $result->success =& $sv->success;
79 if ( $name ===
'ok' ) {
82 if ( $name ===
'errors' ) {
86 throw new RuntimeException(
"Cannot get '$name' property." );
97 function __set( $name, $value ) {
98 if ( $name ===
'ok' ) {
100 } elseif ( !property_exists( $this, $name ) ) {
104 throw new RuntimeException(
"Cannot set '$name' property." );
121 list( $errorsOnlyStatus, $warningsOnlyStatus ) = parent::splitByErrorType();
122 $errorsOnlyStatus->cleanCallback =
123 $warningsOnlyStatus->cleanCallback = $this->cleanCallback;
125 return [ $errorsOnlyStatus, $warningsOnlyStatus ];
142 if ( !$this->cleanCallback ) {
146 foreach ( $params as $i => $param ) {
147 $cleanParams[$i] = call_user_func( $this->cleanCallback, $param );
158 if (
$lang ===
null ) {
159 return RequestContext::getMain()->getLanguage();
164 return Language::factory(
$lang );
180 if ( count( $rawErrors ) === 0 ) {
181 if ( $this->
isOK() ) {
182 $this->
fatal(
'internalerror_info',
183 __METHOD__ .
" called for a good result, this is incorrect\n" );
185 $this->
fatal(
'internalerror_info',
186 __METHOD__ .
": Invalid result object: no error text but not OK\n" );
190 if ( count( $rawErrors ) === 1 ) {
192 if ( $shortContext ) {
194 } elseif ( $longContext ) {
199 foreach (
$errors as &$error ) {
200 $error = $error->plain();
202 $s =
'* ' . implode(
"\n* ",
$errors ) .
"\n";
203 if ( $longContext ) {
205 } elseif ( $shortContext ) {
232 public function getMessage( $shortContext =
false, $longContext =
false,
$lang =
null ) {
236 if ( count( $rawErrors ) === 0 ) {
237 if ( $this->
isOK() ) {
238 $this->
fatal(
'internalerror_info',
239 __METHOD__ .
" called for a good result, this is incorrect\n" );
241 $this->
fatal(
'internalerror_info',
242 __METHOD__ .
": Invalid result object: no error text but not OK\n" );
246 if ( count( $rawErrors ) === 1 ) {
248 if ( $shortContext ) {
250 } elseif ( $longContext ) {
252 $wrapper->params(
$s )->parse();
257 $msgCount = count( $msgs );
259 $s =
new RawMessage(
'* $' . implode(
"\n* \$", range( 1, $msgCount ) ) );
260 $s->params( $msgs )->parse();
262 if ( $longContext ) {
264 } elseif ( $shortContext ) {
285 if ( is_array( $error ) ) {
286 if ( isset( $error[
'message'] ) && $error[
'message'] instanceof
Message ) {
287 $msg = $error[
'message'];
288 } elseif ( isset( $error[
'message'] ) && isset( $error[
'params'] ) ) {
290 array_map(
'wfEscapeWikiText', $this->
cleanParams( $error[
'params'] ) ) );
292 $msgName = array_shift( $error );
294 array_map(
'wfEscapeWikiText', $this->
cleanParams( $error ) ) );
296 } elseif ( is_string( $error ) ) {
299 throw new UnexpectedValueException(
'Got ' . get_class( $error ) .
' for key.' );
314 public function getHTML( $shortContext =
false, $longContext =
false,
$lang =
null ) {
317 $out = MessageCache::singleton()->parse( $text,
null,
true,
true,
$lang );
319 ? $out->
getText( [
'enableSectionEditLinks' =>
false ] )
331 return array_map(
function ( $e ) use (
$lang ) {
369 foreach ( $this->
getErrors() as $error ) {
370 if (
$type ===
false || $error[
'type'] ===
$type ) {
372 $result[] = array_merge(
373 [ $error[
'message']->getKey() ],
374 $error[
'message']->getParams()
376 } elseif ( $error[
'params'] ) {
377 $result[] = array_merge( [ $error[
'message'] ], $error[
'params'] );
379 $result[] = [ $error[
'message'] ];
393 $keys = array_keys( get_object_vars( $this ) );
394 return array_diff(
$keys, [
'cleanCallback' ] );
401 $this->cleanCallback =
false;
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Internationalisation code.
The Message class provides methods which fulfil two basic services:
getText( $options=[])
Get the output HTML.
Variant of the Message class.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
getErrors()
Get the list of errors.
setOK( $ok)
Change operation status.
isOK()
Returns whether the operation completed.
fatal( $message,... $parameters)
Add an error and set OK to false, indicating that the operation as a whole was fatal.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
static wrap( $sv)
Succinct helper method to wrap a StatusValue.
getWikiText( $shortContext=false, $longContext=false, $lang=null)
Get the error list as a wikitext formatted list.
splitByErrorType()
Splits this Status object into two new Status objects, one which contains only the error messages,...
getErrorsArray()
Get the list of errors (but not warnings)
getErrorMessage( $error, $lang=null)
Return the message for a single error.
callable false $cleanCallback
__sleep()
Don't save the callback when serializing, because Closures can't be serialized and we're going to cle...
cleanParams(array $params)
__set( $name, $value)
Change operation result Backwards compatibility logic.
getErrorMessageArray( $errors, $lang=null)
Return an array with a Message object for each error.
getWarningsArray()
Get the list of warnings (but not errors)
getStatusValue()
Returns the wrapped StatusValue object.
languageFromParam( $lang)
getStatusArray( $type=false)
Returns a list of status messages of the given type (or all if false)
getHTML( $shortContext=false, $longContext=false, $lang=null)
Get the error message as HTML.
__wakeup()
Sanitize the callback parameter on wakeup, to avoid arbitrary execution.
__get( $name)
Backwards compatibility logic.
getMessage( $shortContext=false, $longContext=false, $lang=null)
Get a bullet list of the errors as a Message object.
Stub object for the user language.
if(!isset( $args[0])) $lang