MediaWiki  1.32.0
ApiMessageTrait.php
Go to the documentation of this file.
1 <?php
27 
32  protected static $messageMap = [
33  'actionthrottledtext' => 'ratelimited',
34  'autoblockedtext' => 'autoblocked',
35  'badaccess-group0' => 'permissiondenied',
36  'badaccess-groups' => 'permissiondenied',
37  'badipaddress' => 'invalidip',
38  'blankpage' => 'emptypage',
39  'blockedtext' => 'blocked',
40  'cannotdelete' => 'cantdelete',
41  'cannotundelete' => 'cantundelete',
42  'cantmove-titleprotected' => 'protectedtitle',
43  'cantrollback' => 'onlyauthor',
44  'confirmedittext' => 'confirmemail',
45  'content-not-allowed-here' => 'contentnotallowedhere',
46  'deleteprotected' => 'cantedit',
47  'delete-toobig' => 'bigdelete',
48  'edit-conflict' => 'editconflict',
49  'imagenocrossnamespace' => 'nonfilenamespace',
50  'imagetypemismatch' => 'filetypemismatch',
51  'importbadinterwiki' => 'badinterwiki',
52  'importcantopen' => 'cantopenfile',
53  'import-noarticle' => 'badinterwiki',
54  'importnofile' => 'nofile',
55  'importuploaderrorpartial' => 'partialupload',
56  'importuploaderrorsize' => 'filetoobig',
57  'importuploaderrortemp' => 'notempdir',
58  'ipb_already_blocked' => 'alreadyblocked',
59  'ipb_blocked_as_range' => 'blockedasrange',
60  'ipb_cant_unblock' => 'cantunblock',
61  'ipb_expiry_invalid' => 'invalidexpiry',
62  'ip_range_invalid' => 'invalidrange',
63  'mailnologin' => 'cantsend',
64  'markedaspatrollederror-noautopatrol' => 'noautopatrol',
65  'movenologintext' => 'cantmove-anon',
66  'movenotallowed' => 'cantmove',
67  'movenotallowedfile' => 'cantmovefile',
68  'namespaceprotected' => 'protectednamespace',
69  'nocreate-loggedin' => 'cantcreate',
70  'nocreatetext' => 'cantcreate-anon',
71  'noname' => 'invaliduser',
72  'nosuchusershort' => 'nosuchuser',
73  'notanarticle' => 'missingtitle',
74  'nouserspecified' => 'invaliduser',
75  'ns-specialprotected' => 'unsupportednamespace',
76  'protect-cantedit' => 'cantedit',
77  'protectedinterface' => 'protectednamespace-interface',
78  'protectedpagetext' => 'protectedpage',
79  'range_block_disabled' => 'rangedisabled',
80  'rcpatroldisabled' => 'patroldisabled',
81  'readonlytext' => 'readonly',
82  'sessionfailure' => 'badtoken',
83  'systemblockedtext' => 'blocked',
84  'titleprotected' => 'protectedtitle',
85  'undo-failure' => 'undofailure',
86  'userrights-nodatabase' => 'nosuchdatabase',
87  'userrights-no-interwiki' => 'nointerwikiuserrights',
88  ];
89 
90  protected $apiCode = null;
91  protected $apiData = [];
92 
93  public function getApiCode() {
94  if ( $this->apiCode === null ) {
95  $key = $this->getKey();
96  if ( isset( self::$messageMap[$key] ) ) {
97  $this->apiCode = self::$messageMap[$key];
98  } elseif ( $key === 'apierror-missingparam' ) {
100  $this->apiCode = 'no' . $this->getParams()[0];
101  } elseif ( substr( $key, 0, 8 ) === 'apiwarn-' ) {
102  $this->apiCode = substr( $key, 8 );
103  } elseif ( substr( $key, 0, 9 ) === 'apierror-' ) {
104  $this->apiCode = substr( $key, 9 );
105  } else {
106  $this->apiCode = $key;
107  }
108  }
109  return $this->apiCode;
110  }
111 
112  public function setApiCode( $code, array $data = null ) {
113  if ( $code !== null && !( is_string( $code ) && $code !== '' ) ) {
114  throw new InvalidArgumentException( "Invalid code \"$code\"" );
115  }
116 
117  $this->apiCode = $code;
118  if ( $data !== null ) {
119  $this->setApiData( $data );
120  }
121  }
122 
123  public function getApiData() {
124  return $this->apiData;
125  }
126 
127  public function setApiData( array $data ) {
128  $this->apiData = $data;
129  }
130 
131  public function serialize() {
132  return serialize( [
133  'parent' => parent::serialize(),
134  'apiCode' => $this->apiCode,
135  'apiData' => $this->apiData,
136  ] );
137  }
138 
139  public function unserialize( $serialized ) {
140  $data = unserialize( $serialized );
141  parent::unserialize( $data['parent'] );
142  $this->apiCode = $data['apiCode'];
143  $this->apiData = $data['apiData'];
144  }
145 }
setApiData
setApiData(array $data)
Definition: ApiMessageTrait.php:127
$serialized
foreach( $res as $row) $serialized
Definition: testCompression.php:81
serialize
serialize()
Definition: ApiMessageTrait.php:131
php
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
$apiCode
$apiCode
Definition: ApiMessageTrait.php:90
$code
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:813
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
getApiData
getApiData()
Definition: ApiMessageTrait.php:123
getApiCode
getApiCode()
Definition: ApiMessageTrait.php:93
unserialize
unserialize( $serialized)
Definition: ApiMessageTrait.php:139
ApiMessageTrait
trait ApiMessageTrait
Trait to implement the IApiMessage interface for Message subclasses.
Definition: ApiMessageTrait.php:26
$apiData
$apiData
Definition: ApiMessageTrait.php:91
setApiCode
setApiCode( $code, array $data=null)
Definition: ApiMessageTrait.php:112