23 $mock = TestingAccessWrapper::newFromObject(
new MockApi() );
30 [
null,
'getModuleManager' ],
31 [
null,
'getCustomPrinter' ],
32 [ [],
'getHelpUrls' ],
35 [
true,
'shouldCheckMaxLag' ],
36 [
true,
'isReadMode' ],
37 [
false,
'isWriteMode' ],
38 [
false,
'mustBePosted' ],
39 [
false,
'isDeprecated' ],
40 [
false,
'isInternal' ],
41 [
false,
'needsToken' ],
42 [
null,
'getWebUITokenSalt', [ [] ] ],
43 [
null,
'getConditionalRequestData', [
'etag' ] ],
44 [
null,
'dynamicParameterDocumentation' ],
50 $mock->requireOnlyOneParameter(
51 [
"filename" =>
"foo.txt",
"enablechunks" =>
false ],
52 "filename",
"enablechunks"
62 $mock->requireOnlyOneParameter(
63 [
"filename" =>
"foo.txt",
"enablechunks" => 0 ],
64 "filename",
"enablechunks"
73 $mock->requireOnlyOneParameter(
74 [
"filename" =>
"foo.txt",
"enablechunks" =>
true ],
75 "filename",
"enablechunks"
81 'One of the parameters "foo" and "bar" is required.' );
83 $mock->requireOnlyOneParameter(
84 [
"filename" =>
"foo.txt",
"enablechunks" =>
false ],
90 $mock->requireMaxOneParameter(
91 [
'foo' =>
'bar',
'baz' =>
'quz' ],
98 $mock->requireMaxOneParameter(
99 [
'foo' =>
'bar',
'baz' =>
'quz' ],
106 'The parameters "foo" and "baz" can not be used together.' );
108 $mock->requireMaxOneParameter(
109 [
'foo' =>
'bar',
'baz' =>
'quz' ],
115 'At least one of the parameters "foo" and "bar" is required.' );
117 $mock->requireAtLeastOneParameter(
118 [
'a' =>
'b',
'c' =>
'd' ],
124 $mock->requireAtLeastOneParameter(
125 [
'a' =>
'b',
'c' =>
'd' ],
132 $mock->requireAtLeastOneParameter(
133 [
'a' =>
'b',
'c' =>
'd' ],
140 'The parameters "title" and "pageid" can not be used together.' );
142 $mock->getTitleOrPageId( [
'title' =>
'a',
'pageid' => 7 ] );
147 $result = $mock->getTitleOrPageId( [
'title' =>
'Foo' ] );
149 $this->
assertSame(
'Foo', $result->getTitle()->getPrefixedText() );
156 $mock->getTitleOrPageId( [
'title' =>
'|' ] );
161 "Namespace doesn't allow actual pages." );
163 $mock->getTitleOrPageId( [
'title' =>
'Special:RandomPage' ] );
168 $result = (
new MockApi() )->getTitleOrPageId(
169 [
'pageid' => $page->getId() ] );
172 $page->getTitle()->getPrefixedText(),
173 $result->getTitle()->getPrefixedText()
182 'There is no page with ID 2147483648.' );
184 $mock->getTitleOrPageId( [
'pageid' => 2147483648 ] );
189 'The parameters "title" and "pageid" can not be used together.' );
191 $mock->getTitleFromTitleOrPageId( [
'title' =>
'a',
'pageid' => 7 ] );
196 $result = $mock->getTitleFromTitleOrPageId( [
'title' =>
'Foo' ] );
198 $this->
assertSame(
'Foo', $result->getPrefixedText() );
205 $mock->getTitleFromTitleOrPageId( [
'title' =>
'|' ] );
210 $result = (
new MockApi() )->getTitleFromTitleOrPageId(
211 [
'pageid' => $page->getId() ] );
213 $this->
assertSame( $page->getTitle()->getPrefixedText(), $result->getPrefixedText() );
218 'There is no page with ID 298401643.' );
220 $mock->getTitleFromTitleOrPageId( [
'pageid' => 298401643 ] );
225 ->setMethods( [
'getAllowedParams' ] )
227 $mock->method(
'getAllowedParams' )->willReturn( [
235 $wrapper = TestingAccessWrapper::newFromObject( $mock );
242 $this->
assertSame(
'value', $wrapper->getParameter(
'bar' ) );
246 $wrapper->getParameter(
'foo' );
247 $this->fail(
'Expected exception not thrown' );
254 $mock->extractRequestParams();
255 $this->fail(
'Expected exception not thrown' );
276 $wrapper = TestingAccessWrapper::newFromObject( $mock );
278 $wrapper->mModulePrefix =
'my';
279 $paramName =
'Param';
281 $paramName =
'myParam';
289 $parseLimits =
$options[
'parseLimits'] ??
true;
291 if ( !empty(
$options[
'apihighlimits'] ) ) {
292 $context->setUser( self::$users[
'sysop']->getUser() );
296 $mainWrapper = TestingAccessWrapper::newFromObject( $wrapper->mMainModule );
297 $mainWrapper->mInternalMode =
false;
308 if ( $expected instanceof Exception ) {
310 $wrapper->getParameterFromSettings( $paramName, $paramSettings,
312 $this->fail(
'No exception thrown' );
313 }
catch ( Exception $ex ) {
317 $result = $wrapper->getParameterFromSettings( $paramName,
318 $paramSettings, $parseLimits );
328 "Result $result differs from expected $expected by " .
329 'more than one second' );
333 $actualWarnings =
array_map(
function ( $warn ) {
334 return $warn instanceof
Message
335 ?
array_merge( [ $warn->getKey() ], $warn->getParams() )
337 }, $mock->warnings );
338 $this->
assertSame( $warnings, $actualWarnings );
345 $mainWrapper = TestingAccessWrapper::newFromObject( $wrapper->getMain() );
347 $mainWrapper->getSensitiveParams() );
375 [
'apiwarn-badutf8',
'myParam' ],
380 for ( $i = 0; $i < 32; $i++ ) {
382 $enc .= ( $i === 9 || $i === 10 || $i === 13 )
388 'Basic param' => [
'bar',
null,
'bar', [] ],
389 'Basic param, C0 controls' => [
$c0,
null,
$enc, $warnings ],
390 'String param' => [
'bar',
'',
'bar', [] ],
391 'String param, defaulted' => [
null,
'',
'', [] ],
392 'String param, empty' => [
'',
'default',
'', [] ],
393 'String param, required, empty' => [
397 [
'apierror-missingparam',
'myParam' ] ),
400 'Multi-valued parameter' => [
406 'Multi-valued parameter, alternative separator' => [
412 'Multi-valued parameter, other C0 controls' => [
418 'Multi-valued parameter, other C0 controls (2)' => [
421 [
substr( $enc, 0, -3 ),
'' ],
424 'Multi-valued parameter with limits' => [
433 'Multi-valued parameter with exceeded limits' => [
440 null, [
'apierror-toomanyvalues',
'myParam', 2 ],
'too-many-myParam'
444 'Multi-valued parameter with exceeded limits for non-bot' => [
452 null, [
'apierror-toomanyvalues',
'myParam', 2 ],
'too-many-myParam'
456 'Multi-valued parameter with non-exceeded limits for bot' => [
465 [
'apihighlimits' =>
true ],
467 'Multi-valued parameter with prohibited duplicates' => [
472 [ 0 =>
'a', 1 =>
'b', 3 =>
'c' ],
475 'Multi-valued parameter with allowed duplicates' => [
484 'Empty boolean param' => [
490 'Boolean param 0' => [
496 'Boolean param false' => [
502 'Boolean multi-param' => [
509 'Internal error in ApiBase::getParameterFromSettings: ' .
510 'Multi-values not supported for myParam'
514 'Empty boolean param with non-false default' => [
521 'Internal error in ApiBase::getParameterFromSettings: ' .
522 "Boolean param myParam's default is set to '1'. " .
523 'Boolean parameters must default to false.' ),
526 'Deprecated parameter' => [
530 [ [
'apiwarn-deprecation-parameter',
'myParam' ] ],
532 'Deprecated parameter with default, unspecified' => [
538 'Deprecated parameter with default, specified' => [
542 [ [
'apiwarn-deprecation-parameter',
'myParam' ] ],
544 'Deprecated parameter value' => [
548 [ [
'apiwarn-deprecation-parameter',
'myParam=a' ] ],
550 'Deprecated parameter value as default, unspecified' => [
556 'Deprecated parameter value as default, specified' => [
560 [ [
'apiwarn-deprecation-parameter',
'myParam=a' ] ],
562 'Multiple deprecated parameter values' => [
565 [
'b' =>
true,
'd' =>
true ],
567 [
'a',
'b',
'c',
'd' ],
569 [
'apiwarn-deprecation-parameter',
'myParam=b' ],
570 [
'apiwarn-deprecation-parameter',
'myParam=d' ],
573 'Deprecated parameter value with custom warning' => [
579 '"*" when wildcard not allowed' => [
584 [ [
'apiwarn-unrecognizedvalues',
'myParam',
585 [
'list' => [
'*' ],
'type' =>
'comma' ], 1 ] ],
597 'Wildcard "*" with multiples not allowed' => [
604 [
'apierror-unrecognizedvalue',
'myParam',
'*' ],
608 'Wildcard "*" with unrestricted type' => [
627 'Wildcard conflicting with allowed value' => [
635 'Internal error in ApiBase::getParameterFromSettings: ' .
636 'For param myParam, PARAM_ALL collides with a possible ' .
640 'Namespace with wildcard' => [
646 MWNamespace::getValidNamespaces(),
650 'Namespace with wildcard suppressed' => [
657 MWNamespace::getValidNamespaces(),
660 'Namespace with wildcard "x"' => [
668 [ [
'apiwarn-unrecognizedvalues',
'myParam',
669 [
'list' => [
'x' ],
'type' =>
'comma' ], 1 ] ],
672 'dDy+G?e?txnr.1:(@[Ru',
674 'dDy+G?e?txnr.1:(@[Ru',
677 'Sensitive field' => [
678 'I am fond of pineapples',
680 'I am fond of pineapples',
683 'Upload with default' => [
690 'Internal error in ApiBase::getParameterFromSettings: ' .
691 "File upload param myParam's default is set to ''. " .
692 'File upload parameters may not have a default.' ),
695 'Multiple upload' => [
702 'Internal error in ApiBase::getParameterFromSettings: ' .
703 'Multi-values not supported for myParam' ),
711 [
'apierror-unrecognizedvalue',
'myParam',
'-1' ],
715 'Extra namespace -1' => [
726 'Nonexistent module' => [
731 [
'foo' =>
'foo',
'bar' =>
'foo+bar' ],
736 'apierror-unrecognizedvalue',
744 '\\x1f with multiples not allowed' => [
748 'apierror-badvalue-notmultivalue',
749 'badvalue_notmultivalue' ),
752 'Integer with unenforced min' => [
759 [ [
'apierror-integeroutofrange-belowminimum',
'myParam', -1,
762 'Integer with enforced min' => [
770 [
'apierror-integeroutofrange-belowminimum',
'myParam',
771 '-1',
'-2' ],
'integeroutofrange',
772 [
'min' => -1,
'max' =>
null,
'botMax' =>
null ] ),
775 'Integer with unenforced max (internal mode)' => [
784 'Integer with enforced max (internal mode)' => [
794 'Integer with unenforced max (non-internal mode)' => [
801 [ [
'apierror-integeroutofrange-abovemax',
'myParam', 7, 8 ] ],
802 [
'internalmode' =>
false ],
804 'Integer with enforced max (non-internal mode)' => [
813 [
'apierror-integeroutofrange-abovemax',
'myParam',
'7',
'8' ],
815 [
'min' =>
null,
'max' => 7,
'botMax' => 7 ]
818 [
'internalmode' =>
false ],
820 'Array of integers' => [
829 'Array of integers with unenforced min/max (internal mode)' => [
838 [ [
'apierror-integeroutofrange-belowminimum',
'myParam', 0, -1 ] ],
840 'Array of integers with enforced min/max (internal mode)' => [
851 [
'apierror-integeroutofrange-belowminimum',
'myParam', 0, -1 ],
853 [
'min' => 0,
'max' => 100,
'botMax' => 100 ]
857 'Array of integers with unenforced min/max (non-internal mode)' => [
867 [
'apierror-integeroutofrange-abovemax',
'myParam', 100, 966 ],
868 [
'apierror-integeroutofrange-belowminimum',
'myParam', 0, -1 ]
870 [
'internalmode' =>
false ],
872 'Array of integers with enforced min/max (non-internal mode)' => [
883 [
'apierror-integeroutofrange-abovemax',
'myParam', 100, 966 ],
885 [
'min' => 0,
'max' => 100,
'botMax' => 100 ]
888 [
'internalmode' =>
false ],
890 'Limit with parseLimits false' => [
895 [
'parseLimits' =>
false ],
897 'Limit with no max' => [
905 'Internal error in ApiBase::getParameterFromSettings: ' .
906 'MAX1 or MAX2 are not defined for the limit myParam' ),
909 'Limit with no max2' => [
917 'Internal error in ApiBase::getParameterFromSettings: ' .
918 'MAX1 or MAX2 are not defined for the limit myParam' ),
921 'Limit with multi-value' => [
930 'Internal error in ApiBase::getParameterFromSettings: ' .
931 'Multi-values not supported for myParam' ),
954 'Limit max for apihighlimits' => [
963 [
'apihighlimits' =>
true ],
965 'Limit too large (internal mode)' => [
975 'Limit okay for apihighlimits (internal mode)' => [
984 [
'apihighlimits' =>
true ],
986 'Limit too large for apihighlimits (internal mode)' => [
995 [
'apihighlimits' =>
true ],
997 'Limit too large (non-internal mode)' => [
1005 [ [
'apierror-integeroutofrange-abovemax',
'myParam', 100, 101 ] ],
1006 [
'internalmode' =>
false ],
1008 'Limit okay for apihighlimits (non-internal mode)' => [
1017 [
'internalmode' =>
false,
'apihighlimits' =>
true ],
1019 'Limit too large for apihighlimits (non-internal mode)' => [
1027 [ [
'apierror-integeroutofrange-abovebotmax',
'myParam', 101, 102 ] ],
1028 [
'internalmode' =>
false,
'apihighlimits' =>
true ],
1030 'Limit too small' => [
1039 [ [
'apierror-integeroutofrange-belowminimum',
'myParam', -1,
1053 [ [
'apiwarn-unclearnowtimestamp',
'myParam',
'0' ] ],
1055 'Timestamp empty' => [
1059 [ [
'apiwarn-unclearnowtimestamp',
'myParam',
'' ] ],
1068 'Timestamp now' => [
1074 'Invalid timestamp' => [
1079 [
'apierror-badtimestamp',
'myParam',
'a potato' ],
1080 'badtimestamp_myParam'
1084 'Timestamp array' => [
1099 'User prefixed with "User:"' => [
1105 'Invalid username "|"' => [
1109 [
'apierror-baduser',
'myParam',
'|' ],
1110 'baduser_myParam' ),
1113 'Invalid username "300.300.300.300"' => [
1117 [
'apierror-baduser',
'myParam',
'300.300.300.300' ],
1118 'baduser_myParam' ),
1121 'IP range as username' => [
1127 'IPv6 as username' => [
1133 'Obsolete cloaked usemod IP address as username' => [
1139 'Invalid username containing IP address' => [
1140 'This is [not] valid 1.2.3.xxx, ha!',
1144 [
'apierror-baduser',
'myParam',
'This is [not] valid 1.2.3.xxx, ha!' ],
1149 'External username' => [
1155 'Array of usernames' => [
1170 'Array of one tag' => [
1179 'Array of tags' => [
1192 Status::newFatal(
'tags-apply-not-allowed-one',
1193 'invalid tag', 1 ) ),
1196 'Unrecognized type' => [
1200 'Internal error in ApiBase::getParameterFromSettings: ' .
1201 "Param myParam's type is unknown - nonexistenttype" ),
1204 'Too many bytes' => [
1211 [
'apierror-maxbytes',
'myParam', 0 ] ),
1214 'Too many chars' => [
1221 [
'apierror-maxchars',
'myParam', 1 ] ),
1224 'Omitted required param' => [
1228 [
'apierror-missingparam',
'myParam' ] ),
1231 'Empty multi-value' => [
1237 'Multi-value \x1f' => [
1243 'Allowed non-multi-value with "|"' => [
1249 'Prohibited multi-value' => [
1254 'apierror-multival-only-one-of',
1256 Message::listParam( [
'<kbd>a</kbd>',
'<kbd>b</kbd>' ] ),
1273 [
"\t1", 1,
'\t1' ],
1274 [
"\r1", 1,
'\r1' ],
1275 [
"\f1", 0,
'\f1',
'badutf-8' ],
1276 [
"\n1", 1,
'\n1' ],
1277 [
"\v1", 0,
'\v1',
'badutf-8' ],
1278 [
"\e1", 0,
'\e1',
'badutf-8' ],
1279 [
"\x001", 0,
'\x001',
'badutf-8' ],
1282 foreach ( $integerTests as $test ) {
1283 $desc = $test[2] ?? $test[0];
1284 $warnings =
isset( $test[3] ) ?
1285 [ [
'apiwarn-badutf8',
'myParam' ] ] : [];
1286 $returnArray[
"\"$desc\" as integer"] = [
1300 $msg =
new Message(
'mainpage' );
1303 $expect = Status::newGood();
1304 $this->
assertEquals( $expect, $mock->errorArrayToStatus( [] ) );
1307 $expect = Status::newGood();
1308 $expect->fatal(
'blockedtext' );
1309 $expect->fatal(
'autoblockedtext' );
1310 $expect->fatal(
'systemblockedtext' );
1311 $expect->fatal(
'mainpage' );
1312 $expect->fatal( $msg );
1313 $expect->fatal( $msg,
'foobar' );
1314 $expect->fatal(
'parentheses',
'foobar' );
1315 $this->
assertEquals( $expect, $mock->errorArrayToStatus( [
1317 [
'autoblockedtext' ],
1318 [
'systemblockedtext' ],
1322 [
'parentheses',
'foobar' ],
1328 'address' => $user->getName(),
1329 'user' => $user->getID(),
1330 'by' => $this->getTestSysop()->getUser()->getId(),
1331 'reason' => __METHOD__,
1332 'expiry' => time() + 100500,
1337 $expect = Status::newGood();
1339 $expect->fatal(
ApiMessage::create(
'apierror-autoblocked',
'autoblocked', $blockinfo ) );
1340 $expect->fatal(
ApiMessage::create(
'apierror-systemblocked',
'blocked', $blockinfo ) );
1341 $expect->fatal(
'mainpage' );
1342 $expect->fatal( $msg );
1343 $expect->fatal( $msg,
'foobar' );
1344 $expect->fatal(
'parentheses',
'foobar' );
1345 $this->
assertEquals( $expect, $mock->errorArrayToStatus( [
1347 [
'autoblockedtext' ],
1348 [
'systemblockedtext' ],
1352 [
'parentheses',
'foobar' ],
1359 $msg =
new Message(
'mainpage' );
1362 $expect = Status::newGood();
1363 $test = Status::newGood();
1364 $mock->addBlockInfoToStatus( $test );
1368 $expect = Status::newGood();
1369 $expect->fatal(
'blockedtext' );
1370 $expect->fatal(
'autoblockedtext' );
1371 $expect->fatal(
'systemblockedtext' );
1372 $expect->fatal(
'mainpage' );
1373 $expect->fatal( $msg );
1374 $expect->fatal( $msg,
'foobar' );
1375 $expect->fatal(
'parentheses',
'foobar' );
1376 $test = clone $expect;
1377 $mock->addBlockInfoToStatus( $test );
1383 'address' => $user->getName(),
1384 'user' => $user->getID(),
1385 'by' => $this->getTestSysop()->getUser()->getId(),
1386 'reason' => __METHOD__,
1387 'expiry' => time() + 100500,
1392 $expect = Status::newGood();
1394 $expect->fatal(
ApiMessage::create(
'apierror-autoblocked',
'autoblocked', $blockinfo ) );
1395 $expect->fatal(
ApiMessage::create(
'apierror-systemblocked',
'blocked', $blockinfo ) );
1396 $expect->fatal(
'mainpage' );
1397 $expect->fatal( $msg );
1398 $expect->fatal( $msg,
'foobar' );
1399 $expect->fatal(
'parentheses',
'foobar' );
1400 $test = Status::newGood();
1401 $test->fatal(
'blockedtext' );
1402 $test->fatal(
'autoblockedtext' );
1403 $test->fatal(
'systemblockedtext' );
1404 $test->fatal(
'mainpage' );
1405 $test->fatal( $msg );
1406 $test->fatal( $msg,
'foobar' );
1407 $test->fatal(
'parentheses',
'foobar' );
1408 $mock->addBlockInfoToStatus( $test, $user );
1415 $status = StatusValue::newGood();
1420 $this->fail(
'Expected exception not thrown' );
1426 $status = StatusValue::newGood();
1431 $this->fail(
'Expected exception not thrown' );
1437 $status = StatusValue::newGood();
1441 $this->fail(
'Expected exception not thrown' );
1444 'Exception has "unknownerror-nocode"' );
1453 'xxexists' =>
'exists!',
1454 'xxmulti' =>
'a|b|c|d|{bad}',
1456 'xxtemplate-a' =>
'A!',
1457 'xxtemplate-b' =>
'B1|B2|B3',
1458 'xxtemplate-c' =>
'',
1459 'xxrecursivetemplate-b-B1' =>
'X',
1460 'xxrecursivetemplate-b-B3' =>
'Y',
1461 'xxrecursivetemplate-b-B4' =>
'?',
1462 'xxemptytemplate-' =>
'nope',
1465 'errorformat' =>
'raw',
1472 ->setConstructorArgs( [ $main,
'test',
'xx' ] )
1473 ->setMethods( [
'getAllowedParams' ] )
1474 ->getMockForAbstractClass();
1475 $mock->method(
'getAllowedParams' )->willReturn( [
1476 'notexists' =>
null,
1488 'recursivetemplate-{m}-{t}' => [
1491 'emptytemplate-{m}' => [
1495 'badtemplate-{e}' => [
1498 'badtemplate2-{e}' => [
1501 'badtemplate3-{x}' => [
1507 'notexists' =>
null,
1508 'exists' =>
'exists!',
1509 'multi' => [
'a',
'b',
'c',
'd',
'{bad}' ],
1511 'template-a' => [
'A!' ],
1512 'template-b' => [
'B1',
'B2',
'B3' ],
1514 'template-d' =>
null,
1515 'recursivetemplate-a-A!' =>
null,
1516 'recursivetemplate-b-B1' =>
'X',
1517 'recursivetemplate-b-B2' =>
null,
1518 'recursivetemplate-b-B3' =>
'Y',
1519 ], $mock->extractRequestParams() );
1521 $used = TestingAccessWrapper::newFromObject( $main )->getParamsUsed();
1528 'xxrecursivetemplate-a-A!',
1529 'xxrecursivetemplate-b-B1',
1530 'xxrecursivetemplate-b-B2',
1531 'xxrecursivetemplate-b-B3',
1538 $warnings = $mock->getResult()->getResultData(
'warnings', [
'Strip' =>
'all' ] );
1540 $this->
assertSame(
'ignoring-invalid-templated-value', $warnings[0][
'code'] );
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.
testGetTitleOrPageIdTitle()
testGetTitleOrPageIdPageId()
testRequireMaxOneParameterTwo()
testRequireMaxOneParameterOne()
testGetParameterFromSettings_prefix( $input, $paramSettings, $expected, $warnings, $options=[])
provideGetParameterFromSettings
testGetTitleOrPageIdInvalidPageId()
testRequireOnlyOneParameterDefault()
testGetTitleOrPageIdBadParams()
testGetTitleOrPageIdSpecialTitle()
testAddBlockInfoToStatus()
testGetTitleOrPageIdInvalidTitle()
testRequireOnlyOneParameterZero()
ApiUsageException.
testRequireAtLeastOneParameterTwo()
testGetTitleFromTitleOrPageIdBadParams()
testRequireAtLeastOneParameterZero()
static provideGetParameterFromSettings()
testStubMethods( $expected, $method, $args=[])
This covers a variety of stub methods that return a fixed value.
testRequireOnlyOneParameterMissing()
testRequireAtLeastOneParameterOne()
testGetTitleFromTitleOrPageIdInvalidPageId()
testGetTitleFromTitleOrPageIdInvalidTitle()
testGetTitleFromTitleOrPageIdTitle()
testRequireOnlyOneParameterTrue()
ApiUsageException.
testGetTitleFromTitleOrPageIdPageId()
testGetParameterFromSettings_noprefix( $input, $paramSettings, $expected, $warnings, $options=[])
provideGetParameterFromSettings
testRequireMaxOneParameterZero()
doGetParameterFromSettings( $input, $paramSettings, $expected, $warnings, $options=[])
testExtractRequestParams()
ApiBase::extractRequestParams.
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)?
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_DFLT
(null|boolean|integer|string) Default value of the parameter.
const PARAM_ALLOW_DUPLICATES
(boolean) Allow the same value to be set more than once when PARAM_ISMULTI is true?
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_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_ALL
(boolean|string) When PARAM_TYPE has a defined set of values and PARAM_ISMULTI is true,...
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.
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
static getBlockInfo(Block $block)
Get basic info about a given block.
static apiExceptionHasCode(ApiUsageException $ex, $code)
Exception used to abort API execution with an error.
static newWithMessage(ApiBase $module=null, $msg, $code=null, $data=null, $httpCode=0)
An IContextSource implementation which will inherit context from another source but allow individual ...
WebRequest clone which takes values from a provided array.
The Message class provides methods which fulfil two basic services:
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
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
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy: boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as
patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
processing should stop and the error should be shown to the user * false
if(is_array($mode)) switch( $mode) $input