MediaWiki REL1_28
ApiMessage.php
Go to the documentation of this file.
1<?php
35interface 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
115class 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
171class 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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
getApiCode()
serialize()
setApiData(array $data)
unserialize( $serialized)
$apiData
getApiData()
setApiCode( $code, array $data=null)
Extension of Message implementing IApiMessage.
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
__construct( $msg, $code=null, array $data=null)
Extension of RawMessage implementing IApiMessage.
__construct( $msg, $code=null, array $data=null)
The Message class provides methods which fulfil two basic services:
Definition Message.php:159
string $key
The message key.
Definition Message.php:180
Variant of the Message class.
Definition Message.php:1260
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
trait ApiMessageTrait
Trait to implement the IApiMessage interface for Message subclasses.
the array() calling protocol came about after MediaWiki 1.4rc1.
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:887
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:37
Interface for messages with machine-readable data for use by the API.
setApiCode( $code, array $data=null)
Sets the machine-readable code for use by the API.
getApiCode()
Returns a machine-readable code for use by the API.
setApiData(array $data)
Sets additional machine-readable data about the error condition.
getApiData()
Returns additional machine-readable data about the error condition.
foreach( $res as $row) $serialized