MediaWiki  master
ApiStructureTest.php
Go to the documentation of this file.
1 <?php
2 
5 
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' ],
59  ApiBase::PARAM_DEPRECATED_VALUES => [ 'array' ],
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 = [
72  ApiBase::PARAM_ISMULTI => true,
74  ],
76  ApiBase::PARAM_ISMULTI => true,
77  ApiBase::PARAM_ISMULTI_LIMIT1 => null,
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' ],
86  ApiBase::PARAM_RANGE_ENFORCE => 'integer',
87  ApiBase::PARAM_VALUE_LINKS => 'array',
89  ApiBase::PARAM_SUBMODULE_MAP => 'submodule',
91  ApiBase::PARAM_ALL => 'array',
92  ApiBase::PARAM_EXTRA_NAMESPACES => 'namespace',
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 ) {
138  $main = self::getMain();
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() {
226  $main = self::getMain();
227  $paths = self::getSubModulePaths( $main->getModuleManager() );
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 ) {
249  $main = self::getMain();
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] ) &&
341  $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(
399  $config[ApiBase::PARAM_ISMULTI_LIMIT1],
400  $config[ApiBase::PARAM_ISMULTI_LIMIT2],
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(
422  $config[ApiBase::PARAM_MAX_CHARS],
423  $config[ApiBase::PARAM_MAX_BYTES],
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(
448  $config2[ApiBase::PARAM_TEMPLATE_VARS],
449  $config[ApiBase::PARAM_TEMPLATE_VARS],
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 = MediaWikiServices::getInstance()->getNamespaceInfo()->
570  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,
577  $config[ApiBase::PARAM_EXTRA_NAMESPACES]
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() {
629  $main = self::getMain();
630  $paths = self::getSubModulePaths( $main->getModuleManager() );
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 }
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:155
getModuleManager()
Overrides to return this instance&#39;s module manager.
Definition: ApiMain.php:2071
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below...
Definition: ApiBase.php:94
const PARAM_MAX_BYTES
(integer) Maximum length of a string in bytes (in UTF-8 encoding).
Definition: ApiBase.php:228
assertType( $type, $actual, $message='')
Asserts the type of the provided value.
static provideDocumentationExists()
validateDefault( $param, $config)
Asserts that $default is a valid default for $type.
This class holds a list of modules and handles instantiation.
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:1982
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2159
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:55
const GET_VALUES_FOR_HELP
getAllowedParams() flag: When set, the result could take longer to generate, but should be more thoro...
Definition: ApiBase.php:272
validateType( $types, $value, $param, $desc)
Throws if $value does not match one of the types specified in $types.
getModule( $moduleName, $group=null, $ignoreCache=false)
Get module instance by name, or instantiate it if it does not exist.
Exception used to abort API execution with an error.
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE &#39;integer&#39; and &#39;limit&#39;.
Definition: ApiBase.php:97
const PARAM_REQUIRED
(boolean) Is the parameter required?
Definition: ApiBase.php:118
const PARAM_HELP_MSG_INFO
(array) Specify additional information tags for the parameter.
Definition: ApiBase.php:148
getNames( $group=null)
Get an array of modules in a specific group or all if no group is set.
$value
const NS_SPECIAL
Definition: Defines.php:49
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 MediaWikiServices
Definition: injection.txt:23
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:164
static provideParameterConsistency()
const PARAM_ALL
(boolean|string) When PARAM_TYPE has a defined set of values and PARAM_ISMULTI is true...
Definition: ApiBase.php:187
testDocumentationExists( $path, array $globals)
provideDocumentationExists
checkMessage( $msg, $what)
Test a message.
const PARAM_ISMULTI_LIMIT1
(integer) Maximum number of values, for normal users.
Definition: ApiBase.php:215
static getSubModulePaths(ApiModuleManager $manager)
Return paths of all submodules in an ApiModuleManager, recursively.
static makeMessage( $msg, IContextSource $context, array $params=null)
Create a Message from a string or array.
Definition: ApiBase.php:1794
const PARAM_MAX_CHARS
(integer) Maximum length of a string in characters (unicode codepoints).
Definition: ApiBase.php:234
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:1982
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
Definition: ApiBase.php:138
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
const PARAM_SUBMODULE_PARAM_PREFIX
(string) When PARAM_TYPE is &#39;submodule&#39;, used to indicate the &#39;g&#39; prefix added by ApiQueryGeneratorBa...
Definition: ApiBase.php:179
static getMain()
Get the RequestContext object associated with the main request.
const PARAM_ISMULTI_LIMIT2
(integer) Maximum number of values, for users with the apihighimits right.
Definition: ApiBase.php:222
const PARAM_RANGE_ENFORCE
(boolean) For PARAM_TYPE &#39;integer&#39;, enforce PARAM_MIN and PARAM_MAX?
Definition: ApiBase.php:124
getModulePath()
Get the path to this module.
Definition: ApiBase.php:583
getContext()
const PARAM_SUBMODULE_MAP
(string[]) When PARAM_TYPE is &#39;submodule&#39;, map parameter values to submodule paths.
Definition: ApiBase.php:172
getContext()
Get the base IContextSource object.
$params
This is the main API class, used for both external and internal processing.
Definition: ApiMain.php:41
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 null
Definition: hooks.txt:780
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right, for PARAM_TYPE &#39;limit&#39;.
Definition: ApiBase.php:103
getModuleFromPath( $path)
Get a module from its module path.
Definition: ApiBase.php:601
Provides a fallback sequence for Config objects.
Definition: MultiConfig.php:28
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown...
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
Definition: distributors.txt:9
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter...
Definition: ApiBase.php:131
testParameterConsistency( $path)
provideParameterConsistency
const PARAM_SENSITIVE
(boolean) Is the parameter sensitive? Note &#39;password&#39;-type fields are always sensitive regardless of ...
Definition: ApiBase.php:200
Checks that all API modules, core and extensions, conform to the conventions:
const PARAM_TEMPLATE_VARS
(array) Indicate that this is a templated parameter, and specify replacements.
Definition: ApiBase.php:252
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:589
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
static getMain()
Initialize/fetch the ApiMain instance for testing.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
static ApiMain $main
const PARAM_DEPRECATED_VALUES
(array) When PARAM_TYPE is an array, this indicates which of the values are deprecated.
Definition: ApiBase.php:209
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:58
const PARAM_EXTRA_NAMESPACES
(int[]) When PARAM_TYPE is &#39;namespace&#39;, include these as additional possible values.
Definition: ApiBase.php:193
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition: ApiBase.php:112
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE &#39;integer&#39; and &#39;limit&#39;.
Definition: ApiBase.php:106
static array static $paramTypes
Values are an array, where each array value is a permitted type.
A Config instance which stores all settings as a member variable.
Definition: HashConfig.php:28
const PARAM_ALLOW_DUPLICATES
(boolean) Allow the same value to be set more than once when PARAM_ISMULTI is true?
Definition: ApiBase.php:109
static array $testGlobals
Sets of globals to test.