MediaWiki
master
Toggle main menu visibility
ApiMessage.php
Go to the documentation of this file.
1
<?php
6
7
namespace
MediaWiki\Api
;
8
9
use
MediaWiki\Language\RawMessage
;
10
use
MediaWiki\Message\Message
;
11
use Wikimedia\Message\MessageSpecifier;
12
19
class
ApiMessage
extends
Message
implements
IApiMessage
{
20
use
ApiMessageTrait
;
21
35
public
static
function
create
( $msg, $code =
null
, ?array $data =
null
) {
36
if
( is_array( $msg ) ) {
37
// From StatusValue
38
if
( isset( $msg[
'message'
] ) ) {
39
$msg = [ $msg[
'message'
], ...$msg[
'params'
] ?? [] ];
40
}
41
42
// Weirdness that comes in sometimes, including the above
43
if
( $msg[0] instanceof
MessageSpecifier
) {
44
$msg = $msg[0];
45
}
46
}
47
48
if
( $msg instanceof
IApiMessage
) {
49
return
$msg;
50
} elseif ( $msg instanceof
RawMessage
) {
51
return
new
ApiRawMessage
( $msg, $code, $data );
52
}
else
{
53
return
new
ApiMessage
( $msg, $code, $data );
54
}
55
}
56
65
public
function
__construct
( $msg, $code =
null
, ?array $data =
null
) {
66
if
( $msg instanceof
Message
) {
67
foreach
( get_class_vars( get_class( $this ) ) as
$key
=> $value ) {
68
if
( isset( $msg->$key ) ) {
69
$this->
$key
= $msg->$key;
70
}
71
}
72
} elseif ( is_array( $msg ) ) {
73
$key
= array_shift( $msg );
74
parent::__construct(
$key
, $msg );
75
}
else
{
76
parent::__construct( $msg );
77
}
78
$this->
setApiCode
( $code, $data );
79
}
80
}
81
83
class_alias( ApiMessage::class,
'ApiMessage'
);
MediaWiki\Api\ApiMessage
Extension of Message implementing IApiMessage.
Definition
ApiMessage.php:19
MediaWiki\Api\ApiMessage\create
static create( $msg, $code=null, ?array $data=null)
Create an IApiMessage for the message.
Definition
ApiMessage.php:35
MediaWiki\Api\ApiMessage\__construct
__construct( $msg, $code=null, ?array $data=null)
Definition
ApiMessage.php:65
MediaWiki\Api\ApiRawMessage
Extension of RawMessage implementing IApiMessage.
Definition
ApiRawMessage.php:17
MediaWiki\Language\RawMessage
Variant of the Message class.
Definition
RawMessage.php:25
MediaWiki\Message\Message
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition
Message.php:144
MediaWiki\Message\Message\$key
string $key
The message key.
Definition
Message.php:192
MediaWiki\Api\ApiMessageTrait
trait ApiMessageTrait
Trait to implement the IApiMessage interface for Message subclasses.
Definition
ApiMessageTrait.php:19
MediaWiki\Api\IApiMessage
Interface for messages with machine-readable data for use by the API.
Definition
IApiMessage.php:29
MediaWiki\Api\IApiMessage\setApiCode
setApiCode( $code, ?array $data=null)
Sets the machine-readable code for use by the API.
Wikimedia\Message\MessageSpecifier
Definition
MessageSpecifier.php:12
MediaWiki\Api
Definition
ApiAcquireTempUserName.php:8
MediaWiki\Message
includes
Api
ApiMessage.php
Generated on
for MediaWiki by
1.18.0