MediaWiki  1.33.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  // Ensure the code is actually valid
110  $this->apiCode = preg_replace( '/[^a-zA-Z0-9_-]/', '_', $this->apiCode );
111  }
112  return $this->apiCode;
113  }
114 
115  public function setApiCode( $code, array $data = null ) {
116  if ( $code !== null && !ApiErrorFormatter::isValidApiCode( $code ) ) {
117  throw new InvalidArgumentException( "Invalid code \"$code\"" );
118  }
119 
120  $this->apiCode = $code;
121  if ( $data !== null ) {
122  $this->setApiData( $data );
123  }
124  }
125 
126  public function getApiData() {
127  return $this->apiData;
128  }
129 
130  public function setApiData( array $data ) {
131  $this->apiData = $data;
132  }
133 
134  public function serialize() {
135  return serialize( [
136  'parent' => parent::serialize(),
137  'apiCode' => $this->apiCode,
138  'apiData' => $this->apiData,
139  ] );
140  }
141 
142  public function unserialize( $serialized ) {
144  parent::unserialize( $data['parent'] );
145  $this->apiCode = $data['apiCode'];
146  $this->apiData = $data['apiData'];
147  }
148 }
setApiData
setApiData(array $data)
Definition: ApiMessageTrait.php:130
ApiErrorFormatter\isValidApiCode
static isValidApiCode( $code)
Test whether a code is a valid API error code.
Definition: ApiErrorFormatter.php:73
$serialized
foreach( $res as $row) $serialized
Definition: testCompression.php:81
serialize
serialize()
Definition: ApiMessageTrait.php:134
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
$data
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
Definition: generatePhpCharToUpperMappings.php:13
$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 When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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:780
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:126
getApiCode
getApiCode()
Definition: ApiMessageTrait.php:93
unserialize
unserialize( $serialized)
Definition: ApiMessageTrait.php:142
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:115