16 new FauxRequest( [
'action' =>
'query',
'meta' =>
'siteinfo' ] )
19 $data = $api->getResult()->getResultData();
20 $this->assertInternalType(
'array', $data );
21 $this->assertArrayHasKey(
'query', $data );
26 [
false, [],
'user',
'assertuserfailed' ],
27 [
true, [],
'user',
false ],
28 [
true, [],
'bot',
'assertbotfailed' ],
29 [
true, [
'bot' ],
'user',
false ],
30 [
true, [
'bot' ],
'bot',
false ],
44 public function testAssert( $registered, $rights, $assert, $error ) {
49 $user->mRights = $rights;
54 ],
null,
null,
$user );
55 $this->assertFalse( $error );
57 $this->assertEquals(
$e->getCodeString(), $error );
70 'assertuser' =>
$user->getName(),
71 ],
null,
null,
$user );
76 'assertuser' =>
$user->getName() .
'X',
77 ],
null,
null,
$user );
78 $this->fail(
'Expected exception not thrown' );
80 $this->assertEquals(
$e->getCodeString(),
'assertnameduserfailed' );
94 new FauxRequest( [
'action' =>
'query',
'meta' =>
'siteinfo' ] )
96 $modules = $api->getModuleManager()->getNamesWithClasses();
98 $this->assertArrayHasKey(
101 'Class ' . $class .
' for api module ' .
$name .
' not in autoloader (with exact case)'
117 $headers, $conditions, $status, $post =
false
121 $request->response()->statusHeader( 200 );
125 $priv = TestingAccessWrapper::newFromObject( $api );
126 $priv->mInternalMode =
false;
128 $module = $this->getMockBuilder(
'ApiBase' )
129 ->setConstructorArgs( [ $api,
'mock' ] )
130 ->setMethods( [
'getConditionalRequestData' ] )
131 ->getMockForAbstractClass();
132 $module->expects( $this->any() )
133 ->method(
'getConditionalRequestData' )
134 ->will( $this->returnCallback(
function ( $condition )
use ( $conditions ) {
135 return isset( $conditions[$condition] ) ? $conditions[$condition] :
null;
138 $ret = $priv->checkConditionalRequestHeaders( $module );
149 [ [
'If-None-Match' =>
'"foo", "bar"' ], [], 200 ],
150 [ [
'If-Modified-Since' =>
'Tue, 18 Aug 2015 00:00:00 GMT' ], [], 200 ],
157 'last-modified' =>
'20150815000000',
163 [ [
'If-None-Match' =>
'"foo", "bar"' ], [
'etag' =>
'"bar"' ], 304 ],
164 [ [
'If-None-Match' =>
'"foo", "bar"' ], [
'etag' =>
'"baz"' ], 200 ],
165 [ [
'If-None-Match' =>
'"foo"' ], [
'etag' =>
'W/"foo"' ], 304 ],
166 [ [
'If-None-Match' =>
'W/"foo"' ], [
'etag' =>
'"foo"' ], 304 ],
167 [ [
'If-None-Match' =>
'W/"foo"' ], [
'etag' =>
'W/"foo"' ], 304 ],
170 [ [
'If-None-Match' =>
'*' ], [], 304 ],
182 [
'etag' =>
'"x"',
'last-modified' =>
wfTimestamp(
TS_MW, $now - 1 ) ], 200 ],
187 [ [
'If-None-Match' =>
'"foo", "bar"' ], [
'etag' =>
'"bar"' ], 200,
true ],
192 [ [
'If-Modified-Since' => gmdate(
'l, d-M-y H:i:s', $now ) .
' GMT' ],
194 [ [
'If-Modified-Since' => gmdate(
'D M j H:i:s Y', $now ) ],
202 [ [
'If-Modified-Since' => gmdate(
'Y-m-d H:i:s', $now ) .
' GMT' ],
216 $conditions, $headers, $isError =
false, $post =
false
222 $priv = TestingAccessWrapper::newFromObject( $api );
223 $priv->mInternalMode =
false;
225 $module = $this->getMockBuilder(
'ApiBase' )
226 ->setConstructorArgs( [ $api,
'mock' ] )
227 ->setMethods( [
'getConditionalRequestData' ] )
228 ->getMockForAbstractClass();
229 $module->expects( $this->any() )
230 ->method(
'getConditionalRequestData' )
231 ->will( $this->returnCallback(
function ( $condition )
use ( $conditions ) {
232 return isset( $conditions[$condition] ) ? $conditions[$condition] :
null;
234 $priv->mModule = $module;
236 $priv->sendCacheHeaders( $isError );
238 foreach ( [
'Last-Modified',
'ETag' ]
as $header ) {
254 [
'etag' =>
'"foo"' ],
255 [
'ETag' =>
'"foo"' ]
258 [
'last-modified' =>
'20150818000102' ],
259 [
'Last-Modified' =>
'Tue, 18 Aug 2015 00:01:02 GMT' ]
262 [
'etag' =>
'"foo"',
'last-modified' =>
'20150818000102' ],
263 [
'ETag' =>
'"foo"',
'Last-Modified' =>
'Tue, 18 Aug 2015 00:01:02 GMT' ]
266 [
'etag' =>
'"foo"',
'last-modified' =>
'20150818000102' ],
271 [
'etag' =>
'"foo"',
'last-modified' =>
'20150818000102' ],
284 $main =
new ApiMain(
new FauxRequest( [
'action' =>
'query',
'meta' =>
'siteinfo' ] ) );
285 $this->assertFalse( $main->lacksSameOriginSecurity(),
'Basic test, should have security' );
289 new FauxRequest( [
'action' =>
'query',
'format' =>
'xml',
'callback' =>
'foo' ] )
291 $this->assertTrue( $main->lacksSameOriginSecurity(),
'JSONp, should lack security' );
295 $request->setHeader(
'TrEaT-As-UnTrUsTeD',
'' );
297 $this->assertTrue( $main->lacksSameOriginSecurity(),
'Header supplied, should lack security' );
301 'RequestHasSameOriginSecurity' => [
function () {
305 $main =
new ApiMain(
new FauxRequest( [
'action' =>
'query',
'meta' =>
'siteinfo' ] ) );
306 $this->assertTrue( $main->lacksSameOriginSecurity(),
'Hook, should lack security' );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgAutoloadClasses
Array mapping class names to filenames, for autoloading.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
global $wgAutoloadLocalClasses
testLacksSameOriginSecurity()
ApiMain::lacksSameOriginSecurity.
testClassNamesInModuleManager()
Test if all classes in the main module manager exists.
testCheckConditionalRequestHeaders( $headers, $conditions, $status, $post=false)
Test HTTP precondition headers.
testApi()
Test that the API will accept a FauxRequest and execute.
testConditionalRequestHeadersOutput( $conditions, $headers, $isError=false, $post=false)
Test conditional headers output provideConditionalRequestHeadersOutput.
static provideConditionalRequestHeadersOutput()
testAssert( $registered, $rights, $assert, $error)
Tests the assert={user|bot} functionality.
testAssertUser()
Tests the assertuser= functionality.
static provideCheckConditionalRequestHeaders()
This is the main API class, used for both external and internal processing.
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null)
Does the API request and returns the result.
WebRequest clone which takes values from a provided array.
This exception will be thrown when dieUsage is called to stop module execution.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
when a variable name is used in a it is silently declared as a new local masking the global
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
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
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
error also a ContextSource 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 noclasses & $ret
this hook is for auditing only $response
Allows to change the fields on the form that will be generated $name
processing should stop and the error should be shown to the user * false
returning false will NOT prevent logging $e
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
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
const TS_RFC2822
RFC 2822 format, for E-mail and HTTP headers.