MediaWiki REL1_32
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 ApiBase::PARAM_TEMPLATE_VARS => [ 'array' ],
64 ];
65
66 // param => [ other param that must be present => required value or null ]
67 private static $paramRequirements = [
73 ],
77 ],
78 ];
79
80 // param => type(s) allowed for this param ('array' is any array)
81 private static $paramAllowedTypes = [
82 ApiBase::PARAM_MAX => [ 'integer', 'limit' ],
83 ApiBase::PARAM_MAX2 => 'limit',
84 ApiBase::PARAM_MIN => [ 'integer', 'limit' ],
88 ApiBase::PARAM_SUBMODULE_MAP => 'submodule',
90 ApiBase::PARAM_ALL => 'array',
93 ApiBase::PARAM_MAX_BYTES => [ 'NULL', 'string', 'text', 'password' ],
94 ApiBase::PARAM_MAX_CHARS => [ 'NULL', 'string', 'text', 'password' ],
95 ];
96
97 private static $paramProhibitedTypes = [
98 ApiBase::PARAM_ISMULTI => [ 'boolean', 'limit', 'upload' ],
99 ApiBase::PARAM_ALL => 'namespace',
100 ApiBase::PARAM_SENSITIVE => 'password',
101 ];
102
103 private static $constantNames = null;
104
109 private static function getMain() {
110 if ( !self::$main ) {
111 self::$main = new ApiMain( RequestContext::getMain() );
112 self::$main->getContext()->setLanguage( 'en' );
113 self::$main->getContext()->setTitle(
114 Title::makeTitle( NS_SPECIAL, 'Badtitle/dummy title for ApiStructureTest' )
115 );
116 }
117 return self::$main;
118 }
119
125 private function checkMessage( $msg, $what ) {
126 $msg = ApiBase::makeMessage( $msg, self::getMain()->getContext() );
127 $this->assertInstanceOf( Message::class, $msg, "$what message" );
128 $this->assertTrue( $msg->exists(), "$what message {$msg->getKey()} exists" );
129 }
130
136 public function testDocumentationExists( $path, array $globals ) {
138
139 // Set configuration variables
140 $main->getContext()->setConfig( new MultiConfig( [
141 new HashConfig( $globals ),
142 RequestContext::getMain()->getConfig(),
143 ] ) );
144 foreach ( $globals as $k => $v ) {
145 $this->setMwGlobals( "wg$k", $v );
146 }
147
148 // Fetch module.
149 $module = TestingAccessWrapper::newFromObject( $main->getModuleFromPath( $path ) );
150
151 // Test messages for flags.
152 foreach ( $module->getHelpFlags() as $flag ) {
153 $this->checkMessage( "api-help-flag-$flag", "Flag $flag" );
154 }
155
156 // Module description messages.
157 $this->checkMessage( $module->getSummaryMessage(), 'Module summary' );
158 $this->checkMessage( $module->getExtendedDescription(), 'Module help top text' );
159
160 // Parameters. Lots of messages in here.
161 $params = $module->getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
162 $tags = [];
163 foreach ( $params as $name => $settings ) {
164 if ( !is_array( $settings ) ) {
165 $settings = [];
166 }
167
168 // Basic description message
169 if ( isset( $settings[ApiBase::PARAM_HELP_MSG] ) ) {
170 $msg = $settings[ApiBase::PARAM_HELP_MSG];
171 } else {
172 $msg = "apihelp-{$path}-param-{$name}";
173 }
174 $this->checkMessage( $msg, "Parameter $name description" );
175
176 // If param-per-value is in use, each value's message
177 if ( isset( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) {
178 $this->assertInternalType( 'array', $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE],
179 "Parameter $name PARAM_HELP_MSG_PER_VALUE is array" );
180 $this->assertInternalType( 'array', $settings[ApiBase::PARAM_TYPE],
181 "Parameter $name PARAM_TYPE is array for msg-per-value mode" );
182 $valueMsgs = $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE];
183 foreach ( $settings[ApiBase::PARAM_TYPE] as $value ) {
184 if ( isset( $valueMsgs[$value] ) ) {
185 $msg = $valueMsgs[$value];
186 } else {
187 $msg = "apihelp-{$path}-paramvalue-{$name}-{$value}";
188 }
189 $this->checkMessage( $msg, "Parameter $name value $value" );
190 }
191 }
192
193 // Appended messages (e.g. "disabled in miser mode")
194 if ( isset( $settings[ApiBase::PARAM_HELP_MSG_APPEND] ) ) {
195 $this->assertInternalType( 'array', $settings[ApiBase::PARAM_HELP_MSG_APPEND],
196 "Parameter $name PARAM_HELP_MSG_APPEND is array" );
197 foreach ( $settings[ApiBase::PARAM_HELP_MSG_APPEND] as $i => $msg ) {
198 $this->checkMessage( $msg, "Parameter $name HELP_MSG_APPEND #$i" );
199 }
200 }
201
202 // Info tags (e.g. "only usable in mode 1") are typically shared by
203 // several parameters, so accumulate them and test them later.
204 if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) {
205 foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) {
206 $tags[array_shift( $i )] = 1;
207 }
208 }
209 }
210
211 // Info tags (e.g. "only usable in mode 1") accumulated above
212 foreach ( $tags as $tag => $dummy ) {
213 $this->checkMessage( "apihelp-{$path}-paraminfo-{$tag}", "HELP_MSG_INFO tag $tag" );
214 }
215
216 // Messages for examples.
217 foreach ( $module->getExamplesMessages() as $qs => $msg ) {
218 $this->assertStringStartsNotWith( 'api.php?', $qs,
219 "Query string must not begin with 'api.php?'" );
220 $this->checkMessage( $msg, "Example $qs" );
221 }
222 }
223
224 public static function provideDocumentationExists() {
227 array_unshift( $paths, $main->getModulePath() );
228
229 $ret = [];
230 foreach ( $paths as $path ) {
231 foreach ( self::$testGlobals as $globals ) {
232 $g = [];
233 foreach ( $globals as $k => $v ) {
234 $g[] = "$k=" . var_export( $v, 1 );
235 }
236 $k = "Module $path with " . implode( ', ', $g );
237 $ret[$k] = [ $path, $globals ];
238 }
239 }
240 return $ret;
241 }
242
247 public function testParameterConsistency( $path ) {
249 $module = TestingAccessWrapper::newFromObject( $main->getModuleFromPath( $path ) );
250
251 $paramsPlain = $module->getFinalParams();
252 $paramsForHelp = $module->getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
253
254 // avoid warnings about empty tests when no parameter needs to be checked
255 $this->assertTrue( true );
256
257 if ( self::$constantNames === null ) {
258 self::$constantNames = [];
259
260 foreach ( ( new ReflectionClass( 'ApiBase' ) )->getConstants() as $key => $val ) {
261 if ( substr( $key, 0, 6 ) === 'PARAM_' ) {
262 self::$constantNames[$val] = $key;
263 }
264 }
265 }
266
267 foreach ( [ $paramsPlain, $paramsForHelp ] as $params ) {
268 foreach ( $params as $param => $config ) {
269 if ( !is_array( $config ) ) {
270 $config = [ ApiBase::PARAM_DFLT => $config ];
271 }
272 if ( !isset( $config[ApiBase::PARAM_TYPE] ) ) {
273 $config[ApiBase::PARAM_TYPE] = isset( $config[ApiBase::PARAM_DFLT] )
274 ? gettype( $config[ApiBase::PARAM_DFLT] )
275 : 'NULL';
276 }
277
278 foreach ( self::$paramTypes as $key => $types ) {
279 if ( !isset( $config[$key] ) ) {
280 continue;
281 }
282 $keyName = self::$constantNames[$key];
283 $this->validateType( $types, $config[$key], $param, $keyName );
284 }
285
286 foreach ( self::$paramRequirements as $key => $required ) {
287 if ( !isset( $config[$key] ) ) {
288 continue;
289 }
290 foreach ( $required as $requireKey => $requireVal ) {
291 $this->assertArrayHasKey( $requireKey, $config,
292 "$param: When " . self::$constantNames[$key] . " is set, " .
293 self::$constantNames[$requireKey] . " must also be set" );
294 if ( $requireVal !== null ) {
295 $this->assertSame( $requireVal, $config[$requireKey],
296 "$param: When " . self::$constantNames[$key] . " is set, " .
297 self::$constantNames[$requireKey] . " must equal " .
298 var_export( $requireVal, true ) );
299 }
300 }
301 }
302
303 foreach ( self::$paramAllowedTypes as $key => $allowedTypes ) {
304 if ( !isset( $config[$key] ) ) {
305 continue;
306 }
307
308 $actualType = is_array( $config[ApiBase::PARAM_TYPE] )
309 ? 'array' : $config[ApiBase::PARAM_TYPE];
310
311 $this->assertContains(
312 $actualType,
313 (array)$allowedTypes,
314 "$param: " . self::$constantNames[$key] .
315 " can only be used with PARAM_TYPE " .
316 implode( ', ', (array)$allowedTypes )
317 );
318 }
319
320 foreach ( self::$paramProhibitedTypes as $key => $prohibitedTypes ) {
321 if ( !isset( $config[$key] ) ) {
322 continue;
323 }
324
325 $actualType = is_array( $config[ApiBase::PARAM_TYPE] )
326 ? 'array' : $config[ApiBase::PARAM_TYPE];
327
328 $this->assertNotContains(
329 $actualType,
330 (array)$prohibitedTypes,
331 "$param: " . self::$constantNames[$key] .
332 " cannot be used with PARAM_TYPE " .
333 implode( ', ', (array)$prohibitedTypes )
334 );
335 }
336
337 if ( isset( $config[ApiBase::PARAM_DFLT] ) ) {
338 $this->assertFalse(
339 isset( $config[ApiBase::PARAM_REQUIRED] ) &&
341 "$param: A required parameter cannot have a default" );
342
343 $this->validateDefault( $param, $config );
344 }
345
346 if ( $config[ApiBase::PARAM_TYPE] === 'limit' ) {
347 $this->assertTrue(
348 isset( $config[ApiBase::PARAM_MAX] ) &&
349 isset( $config[ApiBase::PARAM_MAX2] ),
350 "$param: PARAM_MAX and PARAM_MAX2 are required for limits"
351 );
352 $this->assertGreaterThanOrEqual(
353 $config[ApiBase::PARAM_MAX],
354 $config[ApiBase::PARAM_MAX2],
355 "$param: PARAM_MAX cannot be greater than PARAM_MAX2"
356 );
357 }
358
359 if (
360 isset( $config[ApiBase::PARAM_MIN] ) &&
361 isset( $config[ApiBase::PARAM_MAX] )
362 ) {
363 $this->assertGreaterThanOrEqual(
364 $config[ApiBase::PARAM_MIN],
365 $config[ApiBase::PARAM_MAX],
366 "$param: PARAM_MIN cannot be greater than PARAM_MAX"
367 );
368 }
369
370 if ( isset( $config[ApiBase::PARAM_RANGE_ENFORCE] ) ) {
371 $this->assertTrue(
372 isset( $config[ApiBase::PARAM_MIN] ) ||
373 isset( $config[ApiBase::PARAM_MAX] ),
374 "$param: PARAM_RANGE_ENFORCE can only be set together with " .
375 "PARAM_MIN or PARAM_MAX"
376 );
377 }
378
379 if ( isset( $config[ApiBase::PARAM_DEPRECATED_VALUES] ) ) {
380 foreach ( $config[ApiBase::PARAM_DEPRECATED_VALUES] as $key => $unused ) {
381 $this->assertContains( $key, $config[ApiBase::PARAM_TYPE],
382 "$param: Deprecated value \"$key\" is not allowed, " .
383 "how can it be deprecated?" );
384 }
385 }
386
387 if (
388 isset( $config[ApiBase::PARAM_ISMULTI_LIMIT1] ) ||
389 isset( $config[ApiBase::PARAM_ISMULTI_LIMIT2] )
390 ) {
391 $this->assertGreaterThanOrEqual( 0, $config[ApiBase::PARAM_ISMULTI_LIMIT1],
392 "$param: PARAM_ISMULTI_LIMIT1 cannot be negative" );
393 // Zero for both doesn't make sense, but you could have
394 // zero for non-bots
395 $this->assertGreaterThanOrEqual( 1, $config[ApiBase::PARAM_ISMULTI_LIMIT2],
396 "$param: PARAM_ISMULTI_LIMIT2 cannot be negative or zero" );
397 $this->assertGreaterThanOrEqual(
400 "$param: PARAM_ISMULTI limit cannot be smaller for users with " .
401 "apihighlimits rights" );
402 }
403
404 if ( isset( $config[ApiBase::PARAM_MAX_BYTES] ) ) {
405 $this->assertGreaterThanOrEqual( 1, $config[ApiBase::PARAM_MAX_BYTES],
406 "$param: PARAM_MAX_BYTES cannot be negative or zero" );
407 }
408
409 if ( isset( $config[ApiBase::PARAM_MAX_CHARS] ) ) {
410 $this->assertGreaterThanOrEqual( 1, $config[ApiBase::PARAM_MAX_CHARS],
411 "$param: PARAM_MAX_CHARS cannot be negative or zero" );
412 }
413
414 if (
415 isset( $config[ApiBase::PARAM_MAX_BYTES] ) &&
416 isset( $config[ApiBase::PARAM_MAX_CHARS] )
417 ) {
418 // Length of a string in chars is always <= length in bytes,
419 // so PARAM_MAX_CHARS is pointless if > PARAM_MAX_BYTES
420 $this->assertGreaterThanOrEqual(
423 "$param: PARAM_MAX_BYTES cannot be less than PARAM_MAX_CHARS"
424 );
425 }
426
427 if ( isset( $config[ApiBase::PARAM_TEMPLATE_VARS] ) ) {
428 $this->assertNotSame( [], $config[ApiBase::PARAM_TEMPLATE_VARS],
429 "$param: PARAM_TEMPLATE_VARS cannot be empty" );
430 foreach ( $config[ApiBase::PARAM_TEMPLATE_VARS] as $key => $target ) {
431 $this->assertRegExp( '/^[^{}]+$/', $key,
432 "$param: PARAM_TEMPLATE_VARS key may not contain '{' or '}'" );
433
434 $this->assertContains( '{' . $key . '}', $param,
435 "$param: Name must contain PARAM_TEMPLATE_VARS key {" . $key . "}" );
436 $this->assertArrayHasKey( $target, $params,
437 "$param: PARAM_TEMPLATE_VARS target parameter '$target' does not exist" );
438 $config2 = $params[$target];
439 $this->assertTrue( !empty( $config2[ApiBase::PARAM_ISMULTI] ),
440 "$param: PARAM_TEMPLATE_VARS target parameter '$target' must have PARAM_ISMULTI = true" );
441
442 if ( isset( $config2[ApiBase::PARAM_TEMPLATE_VARS] ) ) {
443 $this->assertNotSame( $param, $target,
444 "$param: PARAM_TEMPLATE_VARS cannot target itself" );
445
446 $this->assertArraySubset(
449 true,
450 "$param: PARAM_TEMPLATE_VARS target parameter '$target': "
451 . "the target's PARAM_TEMPLATE_VARS must be a subset of the original."
452 );
453 }
454 }
455
456 $keys = implode( '|',
457 array_map(
458 function ( $key ) {
459 return preg_quote( $key, '/' );
460 },
461 array_keys( $config[ApiBase::PARAM_TEMPLATE_VARS] )
462 )
463 );
464 $this->assertRegExp( '/^(?>[^{}]+|\{(?:' . $keys . ')\})+$/', $param,
465 "$param: Name may not contain '{' or '}' other than as defined by PARAM_TEMPLATE_VARS" );
466 } else {
467 $this->assertRegExp( '/^[^{}]+$/', $param,
468 "$param: Name may not contain '{' or '}' without PARAM_TEMPLATE_VARS" );
469 }
470 }
471 }
472 }
473
482 private function validateType( $types, $value, $param, $desc ) {
483 if ( count( $types ) === 1 ) {
484 // Only one type allowed
485 if ( is_string( $types[0] ) ) {
486 $this->assertType( $types[0], $value, "$param: $desc type" );
487 } else {
488 // Array whose values have specified types, recurse
489 $this->assertInternalType( 'array', $value, "$param: $desc type" );
490 foreach ( $value as $subvalue ) {
491 $this->validateType( $types[0], $subvalue, $param, "$desc value" );
492 }
493 }
494 } else {
495 // Multiple options
496 foreach ( $types as $type ) {
497 if ( is_string( $type ) ) {
498 if ( class_exists( $type ) || interface_exists( $type ) ) {
499 if ( $value instanceof $type ) {
500 return;
501 }
502 } else {
503 if ( gettype( $value ) === $type ) {
504 return;
505 }
506 }
507 } else {
508 // Array whose values have specified types, recurse
509 try {
510 $this->validateType( [ $type ], $value, $param, "$desc type" );
511 // Didn't throw, so we're good
512 return;
513 } catch ( Exception $unused ) {
514 }
515 }
516 }
517 // Doesn't match any of them
518 $this->fail( "$param: $desc has incorrect type" );
519 }
520 }
521
528 private function validateDefault( $param, $config ) {
529 $type = $config[ApiBase::PARAM_TYPE];
530 $default = $config[ApiBase::PARAM_DFLT];
531
532 if ( !empty( $config[ApiBase::PARAM_ISMULTI] ) ) {
533 if ( $default === '' ) {
534 // The empty array is fine
535 return;
536 }
537 $defaults = explode( '|', $default );
538 $config[ApiBase::PARAM_ISMULTI] = false;
539 foreach ( $defaults as $defaultValue ) {
540 // Only allow integers in their simplest form with no leading
541 // or trailing characters etc.
542 if ( $type === 'integer' && $defaultValue === (string)(int)$defaultValue ) {
543 $defaultValue = (int)$defaultValue;
544 }
545 $config[ApiBase::PARAM_DFLT] = $defaultValue;
546 $this->validateDefault( $param, $config );
547 }
548 return;
549 }
550 switch ( $type ) {
551 case 'boolean':
552 $this->assertFalse( $default,
553 "$param: Boolean params may only default to false" );
554 break;
555
556 case 'integer':
557 $this->assertInternalType( 'integer', $default,
558 "$param: Default $default is not an integer" );
559 break;
560
561 case 'limit':
562 if ( $default === 'max' ) {
563 break;
564 }
565 $this->assertInternalType( 'integer', $default,
566 "$param: Default $default is neither an integer nor \"max\"" );
567 break;
568
569 case 'namespace':
570 $validValues = MWNamespace::getValidNamespaces();
571 if (
572 isset( $config[ApiBase::PARAM_EXTRA_NAMESPACES] ) &&
573 is_array( $config[ApiBase::PARAM_EXTRA_NAMESPACES] )
574 ) {
575 $validValues = array_merge(
576 $validValues,
578 );
579 }
580 $this->assertContains( $default, $validValues,
581 "$param: Default $default is not a valid namespace" );
582 break;
583
584 case 'NULL':
585 case 'password':
586 case 'string':
587 case 'submodule':
588 case 'tags':
589 case 'text':
590 $this->assertInternalType( 'string', $default,
591 "$param: Default $default is not a string" );
592 break;
593
594 case 'timestamp':
595 if ( $default === 'now' ) {
596 return;
597 }
598 $this->assertNotFalse( wfTimestamp( TS_MW, $default ),
599 "$param: Default $default is not a valid timestamp" );
600 break;
601
602 case 'user':
603 // @todo Should we make user validation a public static method
604 // in ApiBase() or something so we don't have to resort to
605 // this? Or in User for that matter.
606 $wrapper = TestingAccessWrapper::newFromObject( new ApiMain() );
607 try {
608 $wrapper->validateUser( $default, '' );
609 } catch ( ApiUsageException $e ) {
610 $this->fail( "$param: Default $default is not a valid username/IP address" );
611 }
612 break;
613
614 default:
615 if ( is_array( $type ) ) {
616 $this->assertContains( $default, $type,
617 "$param: Default $default is not any of " .
618 implode( ', ', $type ) );
619 } else {
620 $this->fail( "Unrecognized type $type" );
621 }
622 }
623 }
624
628 public static function provideParameterConsistency() {
631 array_unshift( $paths, $main->getModulePath() );
632
633 $ret = [];
634 foreach ( $paths as $path ) {
635 $ret[] = [ $path ];
636 }
637 return $ret;
638 }
639
645 protected static function getSubModulePaths( ApiModuleManager $manager ) {
646 $paths = [];
647 foreach ( $manager->getNames() as $name ) {
648 $module = $manager->getModule( $name );
649 $paths[] = $module->getModulePath();
650 $subManager = $module->getModuleManager();
651 if ( $subManager ) {
652 $paths = array_merge( $paths, self::getSubModulePaths( $subManager ) );
653 }
654 }
655 return $paths;
656 }
657}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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
getModuleFromPath( $path)
Get a module from its module path.
Definition ApiBase.php:621
static makeMessage( $msg, IContextSource $context, array $params=null)
Create a Message from a string or array.
Definition ApiBase.php:1818
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_TEMPLATE_VARS
(array) Indicate that this is a templated parameter, and specify replacements.
Definition ApiBase.php:245
getModulePath()
Get the path to this module.
Definition ApiBase.php:603
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:265
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:41
getModuleManager()
Overrides to return this instance's module manager.
Definition ApiMain.php:2026
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.
getContext()
Get the base IContextSource object.
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.
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
const NS_SPECIAL
Definition Defines.php:53
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:2055
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:2054
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
returning false will NOT prevent logging $e
Definition hooks.txt:2226
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
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))
$params