62 public static function wrap( $sv ) {
63 if ( $sv instanceof
static ) {
67 $result =
new static();
68 $result->ok =& $sv->ok;
69 $result->errors =& $sv->errors;
70 $result->value =& $sv->value;
71 $result->successCount =& $sv->successCount;
72 $result->failCount =& $sv->failCount;
73 $result->success =& $sv->success;
74 $result->statusData =& $sv->statusData;
86 public function __get( $name ) {
87 if ( $name ===
'ok' ) {
90 if ( $name ===
'errors' ) {
94 throw new RuntimeException(
"Cannot get '$name' property." );
105 public function __set( $name, $value ) {
106 if ( $name ===
'ok' ) {
108 } elseif ( !property_exists( $this, $name ) ) {
112 throw new RuntimeException(
"Cannot set '$name' property." );
127 $this->messageLocalizer = $messageLocalizer;
142 list( $errorsOnlyStatus, $warningsOnlyStatus ) = parent::splitByErrorType();
144 '@phan-var Status $errorsOnlyStatus';
145 '@phan-var Status $warningsOnlyStatus';
147 if ( $this->messageLocalizer ) {
148 $errorsOnlyStatus->setMessageLocalizer( $this->messageLocalizer );
149 $warningsOnlyStatus->setMessageLocalizer( $this->messageLocalizer );
151 $errorsOnlyStatus->cleanCallback =
152 $warningsOnlyStatus->cleanCallback = $this->cleanCallback;
154 return [ $errorsOnlyStatus, $warningsOnlyStatus ];
171 if ( !$this->cleanCallback ) {
175 foreach ( $params as $i => $param ) {
176 $cleanParams[$i] = call_user_func( $this->cleanCallback, $param );
192 if ( count( $rawErrors ) === 0 ) {
193 if ( $this->
isOK() ) {
194 $this->
fatal(
'internalerror_info',
195 __METHOD__ .
" called for a good result, this is incorrect\n" );
197 $this->
fatal(
'internalerror_info',
198 __METHOD__ .
": Invalid result object: no error text but not OK\n" );
202 if ( count( $rawErrors ) === 1 ) {
204 if ( $shortContext ) {
205 $s = $this->msgInLang( $shortContext,
$lang,
$s )->plain();
206 } elseif ( $longContext ) {
207 $s = $this->msgInLang( $longContext,
$lang,
"* $s\n" )->plain();
211 foreach (
$errors as &$error ) {
212 $error = $error->plain();
214 $s =
'* ' . implode(
"\n* ",
$errors ) .
"\n";
215 if ( $longContext ) {
216 $s = $this->msgInLang( $longContext,
$lang,
$s )->plain();
217 } elseif ( $shortContext ) {
218 $s = $this->msgInLang( $shortContext,
$lang,
"\n$s\n" )->plain();
244 public function getMessage( $shortContext =
false, $longContext =
false,
$lang =
null ) {
246 if ( count( $rawErrors ) === 0 ) {
247 if ( $this->
isOK() ) {
248 $this->
fatal(
'internalerror_info',
249 __METHOD__ .
" called for a good result, this is incorrect\n" );
251 $this->
fatal(
'internalerror_info',
252 __METHOD__ .
": Invalid result object: no error text but not OK\n" );
256 if ( count( $rawErrors ) === 1 ) {
258 if ( $shortContext ) {
259 $s = $this->msgInLang( $shortContext,
$lang,
$s );
260 } elseif ( $longContext ) {
262 $wrapper->params(
$s )->parse();
263 $s = $this->msgInLang( $longContext,
$lang, $wrapper );
267 $msgCount = count( $msgs );
269 $s =
new RawMessage(
'* $' . implode(
"\n* \$", range( 1, $msgCount ) ) );
270 $s->params( $msgs )->parse();
272 if ( $longContext ) {
273 $s = $this->msgInLang( $longContext,
$lang,
$s );
274 } elseif ( $shortContext ) {
277 $s = $this->msgInLang( $shortContext,
$lang, $wrapper );
295 if ( is_array( $error ) ) {
296 if ( isset( $error[
'message'] ) && $error[
'message'] instanceof
Message ) {
298 $msg = $this->msg( $error[
'message'] );
299 } elseif ( isset( $error[
'message'] ) && isset( $error[
'params'] ) ) {
300 $msg = $this->msg( $error[
'message'], array_map(
static function ( $param ) {
304 $msgName = array_shift( $error );
305 $msg = $this->msg( $msgName, array_map(
static function ( $param ) {
309 } elseif ( is_string( $error ) ) {
310 $msg = $this->msg( $error );
312 throw new UnexpectedValueException(
'Got ' . get_class( $error ) .
' for key.' );
316 $msg->inLanguage(
$lang );
329 public function getHTML( $shortContext =
false, $longContext =
false,
$lang =
null ) {
331 $out = MediaWikiServices::getInstance()->getMessageCache()
332 ->parse( $text,
null,
true,
true,
$lang );
334 ? $out->
getText( [
'enableSectionEditLinks' =>
false ] )
345 return array_map(
function ( $e ) use (
$lang ) {
382 $keys = array_keys( get_object_vars( $this ) );
383 return array_diff(
$keys, [
'cleanCallback',
'messageLocalizer' ] );
390 $this->cleanCallback =
false;
391 $this->messageLocalizer =
null;
399 private function msg( $key, ...$params ):
Message {
400 if ( $this->messageLocalizer ) {
401 return $this->messageLocalizer->msg( $key, ...$params );
413 private function msgInLang( $key,
$lang, ...$params ):
Message {
414 $msg = $this->msg( $key, ...$params );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
The Message class deals with fetching and processing of interface message into a variety of formats.
inLanguage( $lang)
Request the message in any language that is supported.
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.
getStatusArray( $type=false)
Returns a list of status messages of the given type (or all if false)
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.
setMessageLocalizer(MessageLocalizer $messageLocalizer)
Makes this Status object use the given localizer instead of the global one.
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
MessageLocalizer null $messageLocalizer
__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.
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.
Interface for localizing messages in MediaWiki.
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s
if(!isset( $args[0])) $lang