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' )
129 $this->
assertTrue( $msg->exists(),
"$what message {$msg->getKey()} exists" );
143 RequestContext::getMain()->getConfig(),
145 foreach ( $globals as $k => $v ) {
150 $module = TestingAccessWrapper::newFromObject(
$main->getModuleFromPath( $path ) );
153 foreach ( $module->getHelpFlags() as $flag ) {
154 $this->
checkMessage(
"api-help-flag-$flag",
"Flag $flag" );
158 $this->
checkMessage( $module->getSummaryMessage(),
'Module summary' );
159 $this->
checkMessage( $module->getExtendedDescription(),
'Module help top text' );
164 foreach (
$params as $name => $settings ) {
173 $msg =
"apihelp-{$path}-param-{$name}";
175 $this->
checkMessage( $msg,
"Parameter $name description" );
180 "Parameter $name PARAM_HELP_MSG_PER_VALUE is array" );
182 "Parameter $name PARAM_TYPE is array for msg-per-value mode" );
186 $msg = $valueMsgs[
$value];
188 $msg =
"apihelp-{$path}-paramvalue-{$name}-{$value}";
190 $this->
checkMessage( $msg,
"Parameter $name value $value" );
197 "Parameter $name PARAM_HELP_MSG_APPEND is array" );
199 $this->
checkMessage( $msg,
"Parameter $name HELP_MSG_APPEND #$i" );
213 foreach ( $tags as $tag => $dummy ) {
214 $this->
checkMessage(
"apihelp-{$path}-paraminfo-{$tag}",
"HELP_MSG_INFO tag $tag" );
218 foreach ( $module->getExamplesMessages() as $qs => $msg ) {
220 "Query string must not begin with 'api.php?'" );
231 foreach ( $paths as $path ) {
232 foreach ( self::$testGlobals as $globals ) {
234 foreach ( $globals as $k => $v ) {
237 $k =
"Module $path with " . implode(
', ', $g );
250 $module = TestingAccessWrapper::newFromObject(
$main->getModuleFromPath( $path ) );
252 $paramsPlain = $module->getFinalParams();
258 if ( self::$constantNames ===
null ) {
259 self::$constantNames = [];
262 if (
substr( $key, 0, 6 ) ===
'PARAM_' ) {
263 self::$constantNames[
$val] = $key;
268 foreach ( [ $paramsPlain, $paramsForHelp ] as
$params ) {
269 foreach (
$params as $param => $config ) {
279 foreach ( self::$paramTypes as $key => $types ) {
280 if ( !
isset( $config[$key] ) ) {
283 $keyName = self::$constantNames[$key];
284 $this->
validateType( $types, $config[$key], $param, $keyName );
287 foreach ( self::$paramRequirements as $key => $required ) {
288 if ( !
isset( $config[$key] ) ) {
291 foreach ( $required as $requireKey => $requireVal ) {
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 " .
304 foreach ( self::$paramAllowedTypes as $key => $allowedTypes ) {
305 if ( !
isset( $config[$key] ) ) {
314 (
array)$allowedTypes,
315 "$param: " . self::$constantNames[$key] .
316 " can only be used with PARAM_TYPE " .
317 implode(
', ', (
array)$allowedTypes )
321 foreach ( self::$paramProhibitedTypes as $key => $prohibitedTypes ) {
322 if ( !
isset( $config[$key] ) ) {
331 (
array)$prohibitedTypes,
332 "$param: " . self::$constantNames[$key] .
333 " cannot be used with PARAM_TYPE " .
334 implode(
', ', (
array)$prohibitedTypes )
342 "$param: A required parameter cannot have a default" );
351 "$param: PARAM_MAX and PARAM_MAX2 are required for limits"
356 "$param: PARAM_MAX cannot be greater than PARAM_MAX2"
367 "$param: PARAM_MIN cannot be greater than PARAM_MAX"
375 "$param: PARAM_RANGE_ENFORCE can only be set together with " .
376 "PARAM_MIN or PARAM_MAX"
383 "$param: Deprecated value \"$key\" is not allowed, " .
384 "how can it be deprecated?" );
393 "$param: PARAM_ISMULTI_LIMIT1 cannot be negative" );
397 "$param: PARAM_ISMULTI_LIMIT2 cannot be negative or zero" );
401 "$param: PARAM_ISMULTI limit cannot be smaller for users with " .
402 "apihighlimits rights" );
407 "$param: PARAM_MAX_BYTES cannot be negative or zero" );
412 "$param: PARAM_MAX_CHARS cannot be negative or zero" );
424 "$param: PARAM_MAX_BYTES cannot be less than PARAM_MAX_CHARS"
430 "$param: PARAM_TEMPLATE_VARS cannot be empty" );
433 "$param: PARAM_TEMPLATE_VARS key may not contain '{' or '}'" );
436 "$param: Name must contain PARAM_TEMPLATE_VARS key {" . $key .
"}" );
438 "$param: PARAM_TEMPLATE_VARS target parameter '$target' does not exist" );
441 "$param: PARAM_TEMPLATE_VARS target parameter '$target' must have PARAM_ISMULTI = true" );
445 "$param: PARAM_TEMPLATE_VARS cannot target itself" );
451 "$param: PARAM_TEMPLATE_VARS target parameter '$target': "
452 .
"the target's PARAM_TEMPLATE_VARS must be a subset of the original."
457 $keys = implode(
'|',
466 "$param: Name may not contain '{' or '}' other than as defined by PARAM_TEMPLATE_VARS" );
469 "$param: Name may not contain '{' or '}' without PARAM_TEMPLATE_VARS" );
484 if ( count( $types ) === 1 ) {
491 foreach (
$value as $subvalue ) {
492 $this->
validateType( $types[0], $subvalue, $param,
"$desc value" );
497 foreach ( $types as
$type ) {
512 }
catch ( Exception $unused ) {
517 $this->fail(
"$param: $desc has incorrect type" );
532 if ( $default ===
'' ) {
536 $defaults = explode(
'|', $default );
538 foreach ( $defaults as $defaultValue ) {
541 if (
$type ===
'integer' && $defaultValue === (
string)(
int)$defaultValue ) {
542 $defaultValue = (
int)$defaultValue;
552 "$param: Boolean params may only default to false" );
557 "$param: Default $default is not an integer" );
561 if ( $default ===
'max' ) {
565 "$param: Default $default is neither an integer nor \"max\"" );
569 $validValues = MWNamespace::getValidNamespaces();
580 "$param: Default $default is not a valid namespace" );
590 "$param: Default $default is not a string" );
594 if ( $default ===
'now' ) {
598 "$param: Default $default is not a valid timestamp" );
605 $wrapper = TestingAccessWrapper::newFromObject(
new ApiMain() );
607 $wrapper->validateUser( $default,
'' );
609 $this->fail(
"$param: Default $default is not a valid username/IP address" );
616 "$param: Default $default is not any of " .
617 implode(
', ',
$type ) );
619 $this->fail(
"Unrecognized type $type" );
633 foreach ( $paths as $path ) {
646 foreach ( $manager->
getNames() as $name ) {
648 $paths[] = $module->getModulePath();
649 $subManager = $module->getModuleManager();
651 $paths =
array_merge( $paths, self::getSubModulePaths( $subManager ) );
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
const PARAM_REQUIRED
(boolean) Is the parameter required?
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
const PARAM_SUBMODULE_MAP
(string[]) When PARAM_TYPE is 'submodule', map parameter values to submodule paths.
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
static makeMessage( $msg, IContextSource $context, array $params=null)
Create a Message from a string or array.
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
const PARAM_DEPRECATED_VALUES
(array) When PARAM_TYPE is an array, this indicates which of the values are deprecated.
const PARAM_ISMULTI_LIMIT1
(integer) Maximum number of values, for normal users.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_SENSITIVE
(boolean) Is the parameter sensitive? Note 'password'-type fields are always sensitive regardless of ...
const PARAM_HELP_MSG_INFO
(array) Specify additional information tags for the parameter.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
const PARAM_ALLOW_DUPLICATES
(boolean) Allow the same value to be set more than once when PARAM_ISMULTI is true?
const PARAM_VALUE_LINKS
(string[]) When PARAM_TYPE is an array, this may be an array mapping those values to page titles whic...
const PARAM_ISMULTI_LIMIT2
(integer) Maximum number of values, for users with the apihighimits right.
const PARAM_MAX_CHARS
(integer) Maximum length of a string in characters (unicode codepoints).
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
const PARAM_SUBMODULE_PARAM_PREFIX
(string) When PARAM_TYPE is 'submodule', used to indicate the 'g' prefix added by ApiQueryGeneratorBa...
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
const PARAM_MAX_BYTES
(integer) Maximum length of a string in bytes (in UTF-8 encoding).
const PARAM_TEMPLATE_VARS
(array) Indicate that this is a templated parameter, and specify replacements.
const PARAM_RANGE_ENFORCE
(boolean) For PARAM_TYPE 'integer', enforce PARAM_MIN and PARAM_MAX?
const PARAM_EXTRA_NAMESPACES
(int[]) When PARAM_TYPE is 'namespace', include these as additional possible values.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const PARAM_ALL
(boolean|string) When PARAM_TYPE has a defined set of values and PARAM_ISMULTI is true,...
const GET_VALUES_FOR_HELP
getAllowedParams() flag: When set, the result could take longer to generate, but should be more thoro...
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
This is the main API class, used for both external and internal processing.
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 $paramAllowedTypes
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 getSubModulePaths(ApiModuleManager $manager)
Return paths of all submodules in an ApiModuleManager, recursively.
testDocumentationExists( $path, array $globals)
provideDocumentationExists
static $paramProhibitedTypes
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 $paramRequirements
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.
Provides a fallback sequence for Config objects.
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
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
returning false will NOT prevent logging $e
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))