MediaWiki  1.28.0
ApiMessage.php
Go to the documentation of this file.
1 <?php
35 interface IApiMessage extends MessageSpecifier {
44  public function getApiCode();
45 
50  public function getApiData();
51 
57  public function setApiCode( $code, array $data = null );
58 
63  public function setApiData( array $data );
64 }
65 
72  protected $apiCode = null;
73  protected $apiData = [];
74 
75  public function getApiCode() {
76  return $this->apiCode === null ? $this->getKey() : $this->apiCode;
77  }
78 
79  public function setApiCode( $code, array $data = null ) {
80  $this->apiCode = $code;
81  if ( $data !== null ) {
82  $this->setApiData( $data );
83  }
84  }
85 
86  public function getApiData() {
87  return $this->apiData;
88  }
89 
90  public function setApiData( array $data ) {
91  $this->apiData = $data;
92  }
93 
94  public function serialize() {
95  return serialize( [
96  'parent' => parent::serialize(),
97  'apiCode' => $this->apiCode,
98  'apiData' => $this->apiData,
99  ] );
100  }
101 
102  public function unserialize( $serialized ) {
103  $data = unserialize( $serialized );
104  parent::unserialize( $data['parent'] );
105  $this->apiCode = $data['apiCode'];
106  $this->apiData = $data['apiData'];
107  }
108 }
109 
115 class ApiMessage extends Message implements IApiMessage {
117 
129  public static function create( $msg, $code = null, array $data = null ) {
130  if ( $msg instanceof IApiMessage ) {
131  return $msg;
132  } elseif ( $msg instanceof RawMessage ) {
133  return new ApiRawMessage( $msg, $code, $data );
134  } else {
135  return new ApiMessage( $msg, $code, $data );
136  }
137  }
138 
148  public function __construct( $msg, $code = null, array $data = null ) {
149  if ( $msg instanceof Message ) {
150  foreach ( get_class_vars( get_class( $this ) ) as $key => $value ) {
151  if ( isset( $msg->$key ) ) {
152  $this->$key = $msg->$key;
153  }
154  }
155  } elseif ( is_array( $msg ) ) {
156  $key = array_shift( $msg );
157  parent::__construct( $key, $msg );
158  } else {
159  parent::__construct( $msg );
160  }
161  $this->apiCode = $code;
162  $this->apiData = (array)$data;
163  }
164 }
165 
171 class ApiRawMessage extends RawMessage implements IApiMessage {
173 
182  public function __construct( $msg, $code = null, array $data = null ) {
183  if ( $msg instanceof RawMessage ) {
184  foreach ( get_class_vars( get_class( $this ) ) as $key => $value ) {
185  if ( isset( $msg->$key ) ) {
186  $this->$key = $msg->$key;
187  }
188  }
189  } elseif ( is_array( $msg ) ) {
190  $key = array_shift( $msg );
191  parent::__construct( $key, $msg );
192  } else {
193  parent::__construct( $msg );
194  }
195  $this->apiCode = $code;
196  $this->apiData = (array)$data;
197  }
198 }
the array() calling protocol came about after MediaWiki 1.4rc1.
__construct($msg, $code=null, array $data=null)
Definition: ApiMessage.php:148
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
setApiCode($code, array $data=null)
Sets the machine-readable code for use by the API.
$apiData
Definition: ApiMessage.php:73
$value
Interface for messages with machine-readable data for use by the API.
Definition: ApiMessage.php:35
unserialize($serialized)
Definition: ApiMessage.php:102
static create($msg, $code=null, array $data=null)
Create an IApiMessage for the message.
Definition: ApiMessage.php:129
getApiCode()
Returns a machine-readable code for use by the API.
string $key
The message key.
Definition: Message.php:180
Extension of Message implementing IApiMessage.
Definition: ApiMessage.php:115
trait ApiMessageTrait
Trait to implement the IApiMessage interface for Message subclasses.
Definition: ApiMessage.php:71
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition: hooks.txt:802
getApiData()
Definition: ApiMessage.php:86
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
setApiCode($code, array $data=null)
Definition: ApiMessage.php:79
setApiData(array $data)
Sets additional machine-readable data about the error condition.
getApiData()
Returns additional machine-readable data about the error condition.
Variant of the Message class.
Definition: Message.php:1242
getApiCode()
Definition: ApiMessage.php:75
Extension of RawMessage implementing IApiMessage.
Definition: ApiMessage.php:171
__construct($msg, $code=null, array $data=null)
Definition: ApiMessage.php:182
serialize()
Definition: ApiMessage.php:94
foreach($res as $row) $serialized
setApiData(array $data)
Definition: ApiMessage.php:90