MediaWiki REL1_31
ApiStructureTest.php
Go to the documentation of this file.
1<?php
2
3use Wikimedia\TestingAccessWrapper;
4
15
17 private static $main;
18
20 private static $testGlobals = [
21 [
22 'MiserMode' => false,
23 ],
24 [
25 'MiserMode' => true,
26 ],
27 ];
28
37 private static $paramTypes = [
38 // ApiBase::PARAM_DFLT => as appropriate for PARAM_TYPE
39 ApiBase::PARAM_ISMULTI => [ 'boolean' ],
40 ApiBase::PARAM_TYPE => [ 'string', [ 'string' ] ],
41 ApiBase::PARAM_MAX => [ 'integer' ],
42 ApiBase::PARAM_MAX2 => [ 'integer' ],
43 ApiBase::PARAM_MIN => [ 'integer' ],
44 ApiBase::PARAM_ALLOW_DUPLICATES => [ 'boolean' ],
45 ApiBase::PARAM_DEPRECATED => [ 'boolean' ],
46 ApiBase::PARAM_REQUIRED => [ 'boolean' ],
47 ApiBase::PARAM_RANGE_ENFORCE => [ 'boolean' ],
48 ApiBase::PARAM_HELP_MSG => [ 'string', 'array', Message::class ],
49 ApiBase::PARAM_HELP_MSG_APPEND => [ [ 'string', 'array', Message::class ] ],
50 ApiBase::PARAM_HELP_MSG_INFO => [ [ 'array' ] ],
51 ApiBase::PARAM_VALUE_LINKS => [ [ 'string' ] ],
52 ApiBase::PARAM_HELP_MSG_PER_VALUE => [ [ 'string', 'array', Message::class ] ],
53 ApiBase::PARAM_SUBMODULE_MAP => [ [ 'string' ] ],
55 ApiBase::PARAM_ALL => [ 'boolean', 'string' ],
56 ApiBase::PARAM_EXTRA_NAMESPACES => [ [ 'integer' ] ],
57 ApiBase::PARAM_SENSITIVE => [ 'boolean' ],
59 ApiBase::PARAM_ISMULTI_LIMIT1 => [ 'integer' ],
60 ApiBase::PARAM_ISMULTI_LIMIT2 => [ 'integer' ],
61 ApiBase::PARAM_MAX_BYTES => [ 'integer' ],
62 ApiBase::PARAM_MAX_CHARS => [ 'integer' ],
63 ];
64
65 // param => [ other param that must be present => required value or null ]
66 private static $paramRequirements = [
72 ],
76 ],
77 ];
78
79 // param => type(s) allowed for this param ('array' is any array)
80 private static $paramAllowedTypes = [
81 ApiBase::PARAM_MAX => [ 'integer', 'limit' ],
82 ApiBase::PARAM_MAX2 => 'limit',
83 ApiBase::PARAM_MIN => [ 'integer', 'limit' ],
87 ApiBase::PARAM_SUBMODULE_MAP => 'submodule',
89 ApiBase::PARAM_ALL => 'array',
92 ApiBase::PARAM_MAX_BYTES => [ 'NULL', 'string', 'text', 'password' ],
93 ApiBase::PARAM_MAX_CHARS => [ 'NULL', 'string', 'text', 'password' ],
94 ];
95
96 private static $paramProhibitedTypes = [
97 ApiBase::PARAM_ISMULTI => [ 'boolean', 'limit', 'upload' ],
98 ApiBase::PARAM_ALL => 'namespace',
99 ApiBase::PARAM_SENSITIVE => 'password',
100 ];
101
102 private static $constantNames = null;
103
108 private static function getMain() {
109 if ( !self::$main ) {
110 self::$main = new ApiMain( RequestContext::getMain() );
111 self::$main->getContext()->setLanguage( 'en' );
112 self::$main->getContext()->setTitle(
113 Title::makeTitle( NS_SPECIAL, 'Badtitle/dummy title for ApiStructureTest' )
114 );
115 }
116 return self::$main;
117 }
118
124 private function checkMessage( $msg, $what ) {
125 $msg = ApiBase::makeMessage( $msg, self::getMain()->getContext() );
126 $this->assertInstanceOf( Message::class, $msg, "$what message" );
127 $this->assertTrue( $msg->exists(), "$what message {$msg->getKey()} exists" );
128 }
129
135 public function testDocumentationExists( $path, array $globals ) {
137
138 // Set configuration variables
139 $main->getContext()->setConfig( new MultiConfig( [
140 new HashConfig( $globals ),
141 RequestContext::getMain()->getConfig(),
142 ] ) );
143 foreach ( $globals as $k => $v ) {
144 $this->setMwGlobals( "wg$k", $v );
145 }
146
147 // Fetch module.
148 $module = TestingAccessWrapper::newFromObject( $main->getModuleFromPath( $path ) );
149
150 // Test messages for flags.
151 foreach ( $module->getHelpFlags() as $flag ) {
152 $this->checkMessage( "api-help-flag-$flag", "Flag $flag" );
153 }
154
155 // Module description messages.
156 $this->checkMessage( $module->getSummaryMessage(), 'Module summary' );
157 $this->checkMessage( $module->getExtendedDescription(), 'Module help top text' );
158
159 // Parameters. Lots of messages in here.
160 $params = $module->getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
161 $tags = [];
162 foreach ( $params as $name => $settings ) {
163 if ( !is_array( $settings ) ) {
164 $settings = [];
165 }
166
167 // Basic description message
168 if ( isset( $settings[ApiBase::PARAM_HELP_MSG] ) ) {
169 $msg = $settings[ApiBase::PARAM_HELP_MSG];
170 } else {
171 $msg = "apihelp-{$path}-param-{$name}";
172 }
173 $this->checkMessage( $msg, "Parameter $name description" );
174
175 // If param-per-value is in use, each value's message
176 if ( isset( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) {
177 $this->assertInternalType( 'array', $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE],
178 "Parameter $name PARAM_HELP_MSG_PER_VALUE is array" );
179 $this->assertInternalType( 'array', $settings[ApiBase::PARAM_TYPE],
180 "Parameter $name PARAM_TYPE is array for msg-per-value mode" );
181 $valueMsgs = $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE];
182 foreach ( $settings[ApiBase::PARAM_TYPE] as $value ) {
183 if ( isset( $valueMsgs[$value] ) ) {
184 $msg = $valueMsgs[$value];
185 } else {
186 $msg = "apihelp-{$path}-paramvalue-{$name}-{$value}";
187 }
188 $this->checkMessage( $msg, "Parameter $name value $value" );
189 }
190 }
191
192 // Appended messages (e.g. "disabled in miser mode")
193 if ( isset( $settings[ApiBase::PARAM_HELP_MSG_APPEND] ) ) {
194 $this->assertInternalType( 'array', $settings[ApiBase::PARAM_HELP_MSG_APPEND],
195 "Parameter $name PARAM_HELP_MSG_APPEND is array" );
196 foreach ( $settings[ApiBase::PARAM_HELP_MSG_APPEND] as $i => $msg ) {
197 $this->checkMessage( $msg, "Parameter $name HELP_MSG_APPEND #$i" );
198 }
199 }
200
201 // Info tags (e.g. "only usable in mode 1") are typically shared by
202 // several parameters, so accumulate them and test them later.
203 if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) {
204 foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) {
205 $tags[array_shift( $i )] = 1;
206 }
207 }
208 }
209
210 // Info tags (e.g. "only usable in mode 1") accumulated above
211 foreach ( $tags as $tag => $dummy ) {
212 $this->checkMessage( "apihelp-{$path}-paraminfo-{$tag}", "HELP_MSG_INFO tag $tag" );
213 }
214
215 // Messages for examples.
216 foreach ( $module->getExamplesMessages() as $qs => $msg ) {
217 $this->assertStringStartsNotWith( 'api.php?', $qs,
218 "Query string must not begin with 'api.php?'" );
219 $this->checkMessage( $msg, "Example $qs" );
220 }
221 }
222
223 public static function provideDocumentationExists() {
225 $paths = self::getSubModulePaths( $main->getModuleManager() );
226 array_unshift( $paths, $main->getModulePath() );
227
228 $ret = [];
229 foreach ( $paths as $path ) {
230 foreach ( self::$testGlobals as $globals ) {
231 $g = [];
232 foreach ( $globals as $k => $v ) {
233 $g[] = "$k=" . var_export( $v, 1 );
234 }
235 $k = "Module $path with " . implode( ', ', $g );
236 $ret[$k] = [ $path, $globals ];
237 }
238 }
239 return $ret;
240 }
241
246 public function testParameterConsistency( $path ) {
248 $module = TestingAccessWrapper::newFromObject( $main->getModuleFromPath( $path ) );
249
250 $paramsPlain = $module->getFinalParams();
251 $paramsForHelp = $module->getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
252
253 // avoid warnings about empty tests when no parameter needs to be checked
254 $this->assertTrue( true );
255
256 if ( self::$constantNames === null ) {
257 self::$constantNames = [];
258
259 foreach ( ( new ReflectionClass( 'ApiBase' ) )->getConstants() as $key => $val ) {
260 if ( substr( $key, 0, 6 ) === 'PARAM_' ) {
261 self::$constantNames[$val] = $key;
262 }
263 }
264 }
265
266 foreach ( [ $paramsPlain, $paramsForHelp ] as $params ) {
267 foreach ( $params as $param => $config ) {
268 if ( !is_array( $config ) ) {
269 $config = [ ApiBase::PARAM_DFLT => $config ];
270 }
271 if ( !isset( $config[ApiBase::PARAM_TYPE] ) ) {
272 $config[ApiBase::PARAM_TYPE] = isset( $config[ApiBase::PARAM_DFLT] )
273 ? gettype( $config[ApiBase::PARAM_DFLT] )
274 : 'NULL';
275 }
276
277 foreach ( self::$paramTypes as $key => $types ) {
278 if ( !isset( $config[$key] ) ) {
279 continue;
280 }
281 $keyName = self::$constantNames[$key];
282 $this->validateType( $types, $config[$key], $param, $keyName );
283 }
284
285 foreach ( self::$paramRequirements as $key => $required ) {
286 if ( !isset( $config[$key] ) ) {
287 continue;
288 }
289 foreach ( $required as $requireKey => $requireVal ) {
290 $this->assertArrayHasKey( $requireKey, $config,
291 "$param: When " . self::$constantNames[$key] . " is set, " .
292 self::$constantNames[$requireKey] . " must also be set" );
293 if ( $requireVal !== null ) {
294 $this->assertSame( $requireVal, $config[$requireKey],
295 "$param: When " . self::$constantNames[$key] . " is set, " .
296 self::$constantNames[$requireKey] . " must equal " .
297 var_export( $requireVal, true ) );
298 }
299 }
300 }
301
302 foreach ( self::$paramAllowedTypes as $key => $allowedTypes ) {
303 if ( !isset( $config[$key] ) ) {
304 continue;
305 }
306
307 $actualType = is_array( $config[ApiBase::PARAM_TYPE] )
308 ? 'array' : $config[ApiBase::PARAM_TYPE];
309
310 $this->assertContains(
311 $actualType,
312 (array)$allowedTypes,
313 "$param: " . self::$constantNames[$key] .
314 " can only be used with PARAM_TYPE " .
315 implode( ', ', (array)$allowedTypes )
316 );
317 }
318
319 foreach ( self::$paramProhibitedTypes as $key => $prohibitedTypes ) {
320 if ( !isset( $config[$key] ) ) {
321 continue;
322 }
323
324 $actualType = is_array( $config[ApiBase::PARAM_TYPE] )
325 ? 'array' : $config[ApiBase::PARAM_TYPE];
326
327 $this->assertNotContains(
328 $actualType,
329 (array)$prohibitedTypes,
330 "$param: " . self::$constantNames[$key] .
331 " cannot be used with PARAM_TYPE " .
332 implode( ', ', (array)$prohibitedTypes )
333 );
334 }
335
336 if ( isset( $config[ApiBase::PARAM_DFLT] ) ) {
337 $this->assertFalse(
338 isset( $config[ApiBase::PARAM_REQUIRED] ) &&
340 "$param: A required parameter cannot have a default" );
341
342 $this->validateDefault( $param, $config );
343 }
344
345 if ( $config[ApiBase::PARAM_TYPE] === 'limit' ) {
346 $this->assertTrue(
347 isset( $config[ApiBase::PARAM_MAX] ) &&
348 isset( $config[ApiBase::PARAM_MAX2] ),
349 "$param: PARAM_MAX and PARAM_MAX2 are required for limits"
350 );
351 $this->assertGreaterThanOrEqual(
352 $config[ApiBase::PARAM_MAX],
353 $config[ApiBase::PARAM_MAX2],
354 "$param: PARAM_MAX cannot be greater than PARAM_MAX2"
355 );
356 }
357
358 if (
359 isset( $config[ApiBase::PARAM_MIN] ) &&
360 isset( $config[ApiBase::PARAM_MAX] )
361 ) {
362 $this->assertGreaterThanOrEqual(
363 $config[ApiBase::PARAM_MIN],
364 $config[ApiBase::PARAM_MAX],
365 "$param: PARAM_MIN cannot be greater than PARAM_MAX"
366 );
367 }
368
369 if ( isset( $config[ApiBase::PARAM_RANGE_ENFORCE] ) ) {
370 $this->assertTrue(
371 isset( $config[ApiBase::PARAM_MIN] ) ||
372 isset( $config[ApiBase::PARAM_MAX] ),
373 "$param: PARAM_RANGE_ENFORCE can only be set together with " .
374 "PARAM_MIN or PARAM_MAX"
375 );
376 }
377
378 if ( isset( $config[ApiBase::PARAM_DEPRECATED_VALUES] ) ) {
379 foreach ( $config[ApiBase::PARAM_DEPRECATED_VALUES] as $key => $unused ) {
380 $this->assertContains( $key, $config[ApiBase::PARAM_TYPE],
381 "$param: Deprecated value \"$key\" is not allowed, " .
382 "how can it be deprecated?" );
383 }
384 }
385
386 if (
387 isset( $config[ApiBase::PARAM_ISMULTI_LIMIT1] ) ||
388 isset( $config[ApiBase::PARAM_ISMULTI_LIMIT2] )
389 ) {
390 $this->assertGreaterThanOrEqual( 0, $config[ApiBase::PARAM_ISMULTI_LIMIT1],
391 "$param: PARAM_ISMULTI_LIMIT1 cannot be negative" );
392 // Zero for both doesn't make sense, but you could have
393 // zero for non-bots
394 $this->assertGreaterThanOrEqual( 1, $config[ApiBase::PARAM_ISMULTI_LIMIT2],
395 "$param: PARAM_ISMULTI_LIMIT2 cannot be negative or zero" );
396 $this->assertGreaterThanOrEqual(
399 "$param: PARAM_ISMULTI limit cannot be smaller for users with " .
400 "apihighlimits rights" );
401 }
402
403 if ( isset( $config[ApiBase::PARAM_MAX_BYTES] ) ) {
404 $this->assertGreaterThanOrEqual( 1, $config[ApiBase::PARAM_MAX_BYTES],
405 "$param: PARAM_MAX_BYTES cannot be negative or zero" );
406 }
407
408 if ( isset( $config[ApiBase::PARAM_MAX_CHARS] ) ) {
409 $this->assertGreaterThanOrEqual( 1, $config[ApiBase::PARAM_MAX_CHARS],
410 "$param: PARAM_MAX_CHARS cannot be negative or zero" );
411 }
412
413 if (
414 isset( $config[ApiBase::PARAM_MAX_BYTES] ) &&
415 isset( $config[ApiBase::PARAM_MAX_CHARS] )
416 ) {
417 // Length of a string in chars is always <= length in bytes,
418 // so PARAM_MAX_CHARS is pointless if > PARAM_MAX_BYTES
419 $this->assertGreaterThanOrEqual(
422 "$param: PARAM_MAX_BYTES cannot be less than PARAM_MAX_CHARS"
423 );
424 }
425 }
426 }
427 }
428
437 private function validateType( $types, $value, $param, $desc ) {
438 if ( count( $types ) === 1 ) {
439 // Only one type allowed
440 if ( is_string( $types[0] ) ) {
441 $this->assertType( $types[0], $value, "$param: $desc type" );
442 } else {
443 // Array whose values have specified types, recurse
444 $this->assertInternalType( 'array', $value, "$param: $desc type" );
445 foreach ( $value as $subvalue ) {
446 $this->validateType( $types[0], $subvalue, $param, "$desc value" );
447 }
448 }
449 } else {
450 // Multiple options
451 foreach ( $types as $type ) {
452 if ( is_string( $type ) ) {
453 if ( class_exists( $type ) || interface_exists( $type ) ) {
454 if ( $value instanceof $type ) {
455 return;
456 }
457 } else {
458 if ( gettype( $value ) === $type ) {
459 return;
460 }
461 }
462 } else {
463 // Array whose values have specified types, recurse
464 try {
465 $this->validateType( [ $type ], $value, $param, "$desc type" );
466 // Didn't throw, so we're good
467 return;
468 } catch ( Exception $unused ) {
469 }
470 }
471 }
472 // Doesn't match any of them
473 $this->fail( "$param: $desc has incorrect type" );
474 }
475 }
476
483 private function validateDefault( $param, $config ) {
484 $type = $config[ApiBase::PARAM_TYPE];
485 $default = $config[ApiBase::PARAM_DFLT];
486
487 if ( !empty( $config[ApiBase::PARAM_ISMULTI] ) ) {
488 if ( $default === '' ) {
489 // The empty array is fine
490 return;
491 }
492 $defaults = explode( '|', $default );
493 $config[ApiBase::PARAM_ISMULTI] = false;
494 foreach ( $defaults as $defaultValue ) {
495 // Only allow integers in their simplest form with no leading
496 // or trailing characters etc.
497 if ( $type === 'integer' && $defaultValue === (string)(int)$defaultValue ) {
498 $defaultValue = (int)$defaultValue;
499 }
500 $config[ApiBase::PARAM_DFLT] = $defaultValue;
501 $this->validateDefault( $param, $config );
502 }
503 return;
504 }
505 switch ( $type ) {
506 case 'boolean':
507 $this->assertFalse( $default,
508 "$param: Boolean params may only default to false" );
509 break;
510
511 case 'integer':
512 $this->assertInternalType( 'integer', $default,
513 "$param: Default $default is not an integer" );
514 break;
515
516 case 'limit':
517 if ( $default === 'max' ) {
518 break;
519 }
520 $this->assertInternalType( 'integer', $default,
521 "$param: Default $default is neither an integer nor \"max\"" );
522 break;
523
524 case 'namespace':
525 $validValues = MWNamespace::getValidNamespaces();
526 if (
527 isset( $config[ApiBase::PARAM_EXTRA_NAMESPACES] ) &&
528 is_array( $config[ApiBase::PARAM_EXTRA_NAMESPACES] )
529 ) {
530 $validValues = array_merge(
531 $validValues,
533 );
534 }
535 $this->assertContains( $default, $validValues,
536 "$param: Default $default is not a valid namespace" );
537 break;
538
539 case 'NULL':
540 case 'password':
541 case 'string':
542 case 'submodule':
543 case 'tags':
544 case 'text':
545 $this->assertInternalType( 'string', $default,
546 "$param: Default $default is not a string" );
547 break;
548
549 case 'timestamp':
550 if ( $default === 'now' ) {
551 return;
552 }
553 $this->assertNotFalse( wfTimestamp( TS_MW, $default ),
554 "$param: Default $default is not a valid timestamp" );
555 break;
556
557 case 'user':
558 // @todo Should we make user validation a public static method
559 // in ApiBase() or something so we don't have to resort to
560 // this? Or in User for that matter.
561 $wrapper = TestingAccessWrapper::newFromObject( new ApiMain() );
562 try {
563 $wrapper->validateUser( $default, '' );
564 } catch ( ApiUsageException $e ) {
565 $this->fail( "$param: Default $default is not a valid username/IP address" );
566 }
567 break;
568
569 default:
570 if ( is_array( $type ) ) {
571 $this->assertContains( $default, $type,
572 "$param: Default $default is not any of " .
573 implode( ', ', $type ) );
574 } else {
575 $this->fail( "Unrecognized type $type" );
576 }
577 }
578 }
579
583 public static function provideParameterConsistency() {
585 $paths = self::getSubModulePaths( $main->getModuleManager() );
586 array_unshift( $paths, $main->getModulePath() );
587
588 $ret = [];
589 foreach ( $paths as $path ) {
590 $ret[] = [ $path ];
591 }
592 return $ret;
593 }
594
600 protected static function getSubModulePaths( ApiModuleManager $manager ) {
601 $paths = [];
602 foreach ( $manager->getNames() as $name ) {
603 $module = $manager->getModule( $name );
604 $paths[] = $module->getModulePath();
605 $subManager = $module->getModuleManager();
606 if ( $subManager ) {
607 $paths = array_merge( $paths, self::getSubModulePaths( $subManager ) );
608 }
609 }
610 return $paths;
611 }
612}
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getContext()
const PARAM_REQUIRED
(boolean) Is the parameter required?
Definition ApiBase.php:111
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
Definition ApiBase.php:96
const PARAM_SUBMODULE_MAP
(string[]) When PARAM_TYPE is 'submodule', map parameter values to submodule paths.
Definition ApiBase.php:165
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition ApiBase.php:105
static makeMessage( $msg, IContextSource $context, array $params=null)
Create a Message from a string or array.
Definition ApiBase.php:1741
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition ApiBase.php:90
const PARAM_DEPRECATED_VALUES
(array) When PARAM_TYPE is an array, this indicates which of the values are deprecated.
Definition ApiBase.php:202
const PARAM_ISMULTI_LIMIT1
(integer) Maximum number of values, for normal users.
Definition ApiBase.php:208
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:87
const PARAM_SENSITIVE
(boolean) Is the parameter sensitive? Note 'password'-type fields are always sensitive regardless of ...
Definition ApiBase.php:193
const PARAM_HELP_MSG_INFO
(array) Specify additional information tags for the parameter.
Definition ApiBase.php:141
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition ApiBase.php:48
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
Definition ApiBase.php:131
const PARAM_ALLOW_DUPLICATES
(boolean) Allow the same value to be set more than once when PARAM_ISMULTI is true?
Definition ApiBase.php:102
const PARAM_VALUE_LINKS
(string[]) When PARAM_TYPE is an array, this may be an array mapping those values to page titles whic...
Definition ApiBase.php:148
const PARAM_ISMULTI_LIMIT2
(integer) Maximum number of values, for users with the apihighimits right.
Definition ApiBase.php:215
const PARAM_MAX_CHARS
(integer) Maximum length of a string in characters (unicode codepoints).
Definition ApiBase.php:227
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
Definition ApiBase.php:157
const PARAM_SUBMODULE_PARAM_PREFIX
(string) When PARAM_TYPE is 'submodule', used to indicate the 'g' prefix added by ApiQueryGeneratorBa...
Definition ApiBase.php:172
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition ApiBase.php:99
const PARAM_MAX_BYTES
(integer) Maximum length of a string in bytes (in UTF-8 encoding).
Definition ApiBase.php:221
const PARAM_RANGE_ENFORCE
(boolean) For PARAM_TYPE 'integer', enforce PARAM_MIN and PARAM_MAX?
Definition ApiBase.php:117
const PARAM_EXTRA_NAMESPACES
(int[]) When PARAM_TYPE is 'namespace', include these as additional possible values.
Definition ApiBase.php:186
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:124
const PARAM_ALL
(boolean|string) When PARAM_TYPE has a defined set of values and PARAM_ISMULTI is true,...
Definition ApiBase.php:180
const GET_VALUES_FOR_HELP
getAllowedParams() flag: When set, the result could take longer to generate, but should be more thoro...
Definition ApiBase.php:247
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:51
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:43
This class holds a list of modules and handles instantiation.
getModule( $moduleName, $group=null, $ignoreCache=false)
Get module instance by name, or instantiate it if it does not exist.
getNames( $group=null)
Get an array of modules in a specific group or all if no group is set.
Checks that all API modules, core and extensions, conform to the conventions:
static provideDocumentationExists()
static array $testGlobals
Sets of globals to test.
static $paramTypes
Values are an array, where each array value is a permitted type.
static provideParameterConsistency()
static ApiMain $main
static getSubModulePaths(ApiModuleManager $manager)
Return paths of all submodules in an ApiModuleManager, recursively.
testDocumentationExists( $path, array $globals)
provideDocumentationExists
testParameterConsistency( $path)
provideParameterConsistency
validateDefault( $param, $config)
Asserts that $default is a valid default for $type.
checkMessage( $msg, $what)
Test a message.
validateType( $types, $value, $param, $desc)
Throws if $value does not match one of the types specified in $types.
static getMain()
Initialize/fetch the ApiMain instance for testing.
Exception used to abort API execution with an error.
A Config instance which stores all settings as a member variable.
assertType( $type, $actual, $message='')
Asserts the type of the provided value.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Provides a fallback sequence for Config objects.
static getMain()
Get the RequestContext object associated with the main request.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition hooks.txt:2006
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition hooks.txt:2005
returning false will NOT prevent logging $e
Definition hooks.txt:2176
const NS_SPECIAL
Definition Defines.php:63
$params