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