MediaWiki  1.29.1
ApiMainTest.php
Go to the documentation of this file.
1 <?php
2 
3 use Wikimedia\TestingAccessWrapper;
4 
12 class ApiMainTest extends ApiTestCase {
13 
17  public function testApi() {
18  $api = new ApiMain(
19  new FauxRequest( [ 'action' => 'query', 'meta' => 'siteinfo' ] )
20  );
21  $api->execute();
22  $data = $api->getResult()->getResultData();
23  $this->assertInternalType( 'array', $data );
24  $this->assertArrayHasKey( 'query', $data );
25  }
26 
27  public static function provideAssert() {
28  return [
29  [ false, [], 'user', 'assertuserfailed' ],
30  [ true, [], 'user', false ],
31  [ true, [], 'bot', 'assertbotfailed' ],
32  [ true, [ 'bot' ], 'user', false ],
33  [ true, [ 'bot' ], 'bot', false ],
34  ];
35  }
36 
47  public function testAssert( $registered, $rights, $assert, $error ) {
48  $user = new User();
49  if ( $registered ) {
50  $user->setId( 1 );
51  }
52  $user->mRights = $rights;
53  try {
54  $this->doApiRequest( [
55  'action' => 'query',
56  'assert' => $assert,
57  ], null, null, $user );
58  $this->assertFalse( $error ); // That no error was expected
59  } catch ( ApiUsageException $e ) {
60  $this->assertTrue( self::apiExceptionHasCode( $e, $error ) );
61  }
62  }
63 
69  public function testAssertUser() {
70  $user = $this->getTestUser()->getUser();
71  $this->doApiRequest( [
72  'action' => 'query',
73  'assertuser' => $user->getName(),
74  ], null, null, $user );
75 
76  try {
77  $this->doApiRequest( [
78  'action' => 'query',
79  'assertuser' => $user->getName() . 'X',
80  ], null, null, $user );
81  $this->fail( 'Expected exception not thrown' );
82  } catch ( ApiUsageException $e ) {
83  $this->assertTrue( self::apiExceptionHasCode( $e, 'assertnameduserfailed' ) );
84  }
85  }
86 
90  public function testClassNamesInModuleManager() {
91  $api = new ApiMain(
92  new FauxRequest( [ 'action' => 'query', 'meta' => 'siteinfo' ] )
93  );
94  $modules = $api->getModuleManager()->getNamesWithClasses();
95 
96  foreach ( $modules as $name => $class ) {
97  $this->assertTrue(
98  class_exists( $class ),
99  'Class ' . $class . ' for api module ' . $name . ' does not exist (with exact case)'
100  );
101  }
102  }
103 
115  $headers, $conditions, $status, $post = false
116  ) {
117  $request = new FauxRequest( [ 'action' => 'query', 'meta' => 'siteinfo' ], $post );
118  $request->setHeaders( $headers );
119  $request->response()->statusHeader( 200 ); // Why doesn't it default?
120 
121  $context = $this->apiContext->newTestContext( $request, null );
122  $api = new ApiMain( $context );
123  $priv = TestingAccessWrapper::newFromObject( $api );
124  $priv->mInternalMode = false;
125 
126  $module = $this->getMockBuilder( 'ApiBase' )
127  ->setConstructorArgs( [ $api, 'mock' ] )
128  ->setMethods( [ 'getConditionalRequestData' ] )
129  ->getMockForAbstractClass();
130  $module->expects( $this->any() )
131  ->method( 'getConditionalRequestData' )
132  ->will( $this->returnCallback( function ( $condition ) use ( $conditions ) {
133  return isset( $conditions[$condition] ) ? $conditions[$condition] : null;
134  } ) );
135 
136  $ret = $priv->checkConditionalRequestHeaders( $module );
137 
138  $this->assertSame( $status, $request->response()->getStatusCode() );
139  $this->assertSame( $status === 200, $ret );
140  }
141 
142  public static function provideCheckConditionalRequestHeaders() {
143  $now = time();
144 
145  return [
146  // Non-existing from module is ignored
147  [ [ 'If-None-Match' => '"foo", "bar"' ], [], 200 ],
148  [ [ 'If-Modified-Since' => 'Tue, 18 Aug 2015 00:00:00 GMT' ], [], 200 ],
149 
150  // No headers
151  [
152  [],
153  [
154  'etag' => '""',
155  'last-modified' => '20150815000000',
156  ],
157  200
158  ],
159 
160  // Basic If-None-Match
161  [ [ 'If-None-Match' => '"foo", "bar"' ], [ 'etag' => '"bar"' ], 304 ],
162  [ [ 'If-None-Match' => '"foo", "bar"' ], [ 'etag' => '"baz"' ], 200 ],
163  [ [ 'If-None-Match' => '"foo"' ], [ 'etag' => 'W/"foo"' ], 304 ],
164  [ [ 'If-None-Match' => 'W/"foo"' ], [ 'etag' => '"foo"' ], 304 ],
165  [ [ 'If-None-Match' => 'W/"foo"' ], [ 'etag' => 'W/"foo"' ], 304 ],
166 
167  // Pointless, but supported
168  [ [ 'If-None-Match' => '*' ], [], 304 ],
169 
170  // Basic If-Modified-Since
171  [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now ) ],
172  [ 'last-modified' => wfTimestamp( TS_MW, $now - 1 ) ], 304 ],
173  [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now ) ],
174  [ 'last-modified' => wfTimestamp( TS_MW, $now ) ], 304 ],
175  [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now ) ],
176  [ 'last-modified' => wfTimestamp( TS_MW, $now + 1 ) ], 200 ],
177 
178  // If-Modified-Since ignored when If-None-Match is given too
179  [ [ 'If-None-Match' => '""', 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now ) ],
180  [ 'etag' => '"x"', 'last-modified' => wfTimestamp( TS_MW, $now - 1 ) ], 200 ],
181  [ [ 'If-None-Match' => '""', 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now ) ],
182  [ 'last-modified' => wfTimestamp( TS_MW, $now - 1 ) ], 304 ],
183 
184  // Ignored for POST
185  [ [ 'If-None-Match' => '"foo", "bar"' ], [ 'etag' => '"bar"' ], 200, true ],
186  [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now ) ],
187  [ 'last-modified' => wfTimestamp( TS_MW, $now - 1 ) ], 200, true ],
188 
189  // Other date formats allowed by the RFC
190  [ [ 'If-Modified-Since' => gmdate( 'l, d-M-y H:i:s', $now ) . ' GMT' ],
191  [ 'last-modified' => wfTimestamp( TS_MW, $now - 1 ) ], 304 ],
192  [ [ 'If-Modified-Since' => gmdate( 'D M j H:i:s Y', $now ) ],
193  [ 'last-modified' => wfTimestamp( TS_MW, $now - 1 ) ], 304 ],
194 
195  // Old browser extension to HTTP/1.0
196  [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now ) . '; length=123' ],
197  [ 'last-modified' => wfTimestamp( TS_MW, $now - 1 ) ], 304 ],
198 
199  // Invalid date formats should be ignored
200  [ [ 'If-Modified-Since' => gmdate( 'Y-m-d H:i:s', $now ) . ' GMT' ],
201  [ 'last-modified' => wfTimestamp( TS_MW, $now - 1 ) ], 200 ],
202  ];
203  }
204 
214  $conditions, $headers, $isError = false, $post = false
215  ) {
216  $request = new FauxRequest( [ 'action' => 'query', 'meta' => 'siteinfo' ], $post );
217  $response = $request->response();
218 
219  $api = new ApiMain( $request );
220  $priv = TestingAccessWrapper::newFromObject( $api );
221  $priv->mInternalMode = false;
222 
223  $module = $this->getMockBuilder( 'ApiBase' )
224  ->setConstructorArgs( [ $api, 'mock' ] )
225  ->setMethods( [ 'getConditionalRequestData' ] )
226  ->getMockForAbstractClass();
227  $module->expects( $this->any() )
228  ->method( 'getConditionalRequestData' )
229  ->will( $this->returnCallback( function ( $condition ) use ( $conditions ) {
230  return isset( $conditions[$condition] ) ? $conditions[$condition] : null;
231  } ) );
232  $priv->mModule = $module;
233 
234  $priv->sendCacheHeaders( $isError );
235 
236  foreach ( [ 'Last-Modified', 'ETag' ] as $header ) {
237  $this->assertEquals(
238  isset( $headers[$header] ) ? $headers[$header] : null,
239  $response->getHeader( $header ),
240  $header
241  );
242  }
243  }
244 
245  public static function provideConditionalRequestHeadersOutput() {
246  return [
247  [
248  [],
249  []
250  ],
251  [
252  [ 'etag' => '"foo"' ],
253  [ 'ETag' => '"foo"' ]
254  ],
255  [
256  [ 'last-modified' => '20150818000102' ],
257  [ 'Last-Modified' => 'Tue, 18 Aug 2015 00:01:02 GMT' ]
258  ],
259  [
260  [ 'etag' => '"foo"', 'last-modified' => '20150818000102' ],
261  [ 'ETag' => '"foo"', 'Last-Modified' => 'Tue, 18 Aug 2015 00:01:02 GMT' ]
262  ],
263  [
264  [ 'etag' => '"foo"', 'last-modified' => '20150818000102' ],
265  [],
266  true,
267  ],
268  [
269  [ 'etag' => '"foo"', 'last-modified' => '20150818000102' ],
270  [],
271  false,
272  true,
273  ],
274  ];
275  }
276 
280  public function testLacksSameOriginSecurity() {
281  // Basic test
282  $main = new ApiMain( new FauxRequest( [ 'action' => 'query', 'meta' => 'siteinfo' ] ) );
283  $this->assertFalse( $main->lacksSameOriginSecurity(), 'Basic test, should have security' );
284 
285  // JSONp
286  $main = new ApiMain(
287  new FauxRequest( [ 'action' => 'query', 'format' => 'xml', 'callback' => 'foo' ] )
288  );
289  $this->assertTrue( $main->lacksSameOriginSecurity(), 'JSONp, should lack security' );
290 
291  // Header
292  $request = new FauxRequest( [ 'action' => 'query', 'meta' => 'siteinfo' ] );
293  $request->setHeader( 'TrEaT-As-UnTrUsTeD', '' ); // With falsey value!
294  $main = new ApiMain( $request );
295  $this->assertTrue( $main->lacksSameOriginSecurity(), 'Header supplied, should lack security' );
296 
297  // Hook
298  $this->mergeMwGlobalArrayValue( 'wgHooks', [
299  'RequestHasSameOriginSecurity' => [ function () {
300  return false;
301  } ]
302  ] );
303  $main = new ApiMain( new FauxRequest( [ 'action' => 'query', 'meta' => 'siteinfo' ] ) );
304  $this->assertTrue( $main->lacksSameOriginSecurity(), 'Hook, should lack security' );
305  }
306 
319  public function testApiErrorFormatterCreation( array $request, array $expect ) {
320  $context = new RequestContext();
321  $context->setRequest( new FauxRequest( $request ) );
322  $context->setLanguage( 'ru' );
323 
324  $main = new ApiMain( $context );
325  $formatter = $main->getErrorFormatter();
326  $wrappedFormatter = TestingAccessWrapper::newFromObject( $formatter );
327 
328  $this->assertSame( $expect['uselang'], $main->getLanguage()->getCode() );
329  $this->assertInstanceOf( $expect['class'], $formatter );
330  $this->assertSame( $expect['lang'], $formatter->getLanguage()->getCode() );
331  $this->assertSame( $expect['format'], $wrappedFormatter->format );
332  $this->assertSame( $expect['usedb'], $wrappedFormatter->useDB );
333  }
334 
335  public static function provideApiErrorFormatterCreation() {
336  return [
337  'Default (BC)' => [ [], [
338  'uselang' => 'ru',
340  'lang' => 'en',
341  'format' => 'none',
342  'usedb' => false,
343  ] ],
344  'BC ignores fields' => [ [ 'errorlang' => 'de', 'errorsuselocal' => 1 ], [
345  'uselang' => 'ru',
347  'lang' => 'en',
348  'format' => 'none',
349  'usedb' => false,
350  ] ],
351  'Explicit BC' => [ [ 'errorformat' => 'bc' ], [
352  'uselang' => 'ru',
354  'lang' => 'en',
355  'format' => 'none',
356  'usedb' => false,
357  ] ],
358  'Basic' => [ [ 'errorformat' => 'wikitext' ], [
359  'uselang' => 'ru',
360  'class' => ApiErrorFormatter::class,
361  'lang' => 'ru',
362  'format' => 'wikitext',
363  'usedb' => false,
364  ] ],
365  'Follows uselang' => [ [ 'uselang' => 'fr', 'errorformat' => 'plaintext' ], [
366  'uselang' => 'fr',
367  'class' => ApiErrorFormatter::class,
368  'lang' => 'fr',
369  'format' => 'plaintext',
370  'usedb' => false,
371  ] ],
372  'Explicitly follows uselang' => [
373  [ 'uselang' => 'fr', 'errorlang' => 'uselang', 'errorformat' => 'plaintext' ],
374  [
375  'uselang' => 'fr',
376  'class' => ApiErrorFormatter::class,
377  'lang' => 'fr',
378  'format' => 'plaintext',
379  'usedb' => false,
380  ]
381  ],
382  'uselang=content' => [
383  [ 'uselang' => 'content', 'errorformat' => 'plaintext' ],
384  [
385  'uselang' => 'en',
386  'class' => ApiErrorFormatter::class,
387  'lang' => 'en',
388  'format' => 'plaintext',
389  'usedb' => false,
390  ]
391  ],
392  'errorlang=content' => [
393  [ 'errorlang' => 'content', 'errorformat' => 'plaintext' ],
394  [
395  'uselang' => 'ru',
396  'class' => ApiErrorFormatter::class,
397  'lang' => 'en',
398  'format' => 'plaintext',
399  'usedb' => false,
400  ]
401  ],
402  'Explicit parameters' => [
403  [ 'errorlang' => 'de', 'errorformat' => 'html', 'errorsuselocal' => 1 ],
404  [
405  'uselang' => 'ru',
406  'class' => ApiErrorFormatter::class,
407  'lang' => 'de',
408  'format' => 'html',
409  'usedb' => true,
410  ]
411  ],
412  'Explicit parameters override uselang' => [
413  [ 'errorlang' => 'de', 'uselang' => 'fr', 'errorformat' => 'raw' ],
414  [
415  'uselang' => 'fr',
416  'class' => ApiErrorFormatter::class,
417  'lang' => 'de',
418  'format' => 'raw',
419  'usedb' => false,
420  ]
421  ],
422  'Bogus language doesn\'t explode' => [
423  [ 'errorlang' => '<bogus1>', 'uselang' => '<bogus2>', 'errorformat' => 'none' ],
424  [
425  'uselang' => 'en',
426  'class' => ApiErrorFormatter::class,
427  'lang' => 'en',
428  'format' => 'none',
429  'usedb' => false,
430  ]
431  ],
432  'Bogus format doesn\'t explode' => [ [ 'errorformat' => 'bogus' ], [
433  'uselang' => 'ru',
435  'lang' => 'en',
436  'format' => 'none',
437  'usedb' => false,
438  ] ],
439  ];
440  }
441 
450  public function testExceptionErrors( $error, $expectReturn, $expectResult ) {
451  $context = new RequestContext();
452  $context->setRequest( new FauxRequest( [ 'errorformat' => 'plaintext' ] ) );
453  $context->setLanguage( 'en' );
454  $context->setConfig( new MultiConfig( [
455  new HashConfig( [
456  'ShowHostnames' => true, 'ShowSQLErrors' => false,
457  'ShowExceptionDetails' => true, 'ShowDBErrorBacktrace' => true,
458  ] ),
460  ] ) );
461 
462  $main = new ApiMain( $context );
463  $main->addWarning( new RawMessage( 'existing warning' ), 'existing-warning' );
464  $main->addError( new RawMessage( 'existing error' ), 'existing-error' );
465 
466  $ret = TestingAccessWrapper::newFromObject( $main )->substituteResultWithError( $error );
467  $this->assertSame( $expectReturn, $ret );
468 
469  // PHPUnit sometimes adds some SplObjectStorage garbage to the arrays,
470  // so let's try ->assertEquals().
471  $this->assertEquals(
472  $expectResult,
473  $main->getResult()->getResultData( [], [ 'Strip' => 'all' ] )
474  );
475  }
476 
477  // Not static so $this can be used
478  public function provideExceptionErrors() {
479  $reqId = WebRequest::getRequestId();
480  $doclink = wfExpandUrl( wfScript( 'api' ) );
481 
482  $ex = new InvalidArgumentException( 'Random exception' );
483  $trace = wfMessage( 'api-exception-trace',
484  get_class( $ex ),
485  $ex->getFile(),
486  $ex->getLine(),
488  )->inLanguage( 'en' )->useDatabase( false )->text();
489 
490  $dbex = new DBQueryError(
491  $this->createMock( 'IDatabase' ),
492  'error', 1234, 'SELECT 1', __METHOD__ );
493  $dbtrace = wfMessage( 'api-exception-trace',
494  get_class( $dbex ),
495  $dbex->getFile(),
496  $dbex->getLine(),
498  )->inLanguage( 'en' )->useDatabase( false )->text();
499 
500  $apiEx1 = new ApiUsageException( null,
501  StatusValue::newFatal( new ApiRawMessage( 'An error', 'sv-error1' ) ) );
502  TestingAccessWrapper::newFromObject( $apiEx1 )->modulePath = 'foo+bar';
503  $apiEx1->getStatusValue()->warning( new ApiRawMessage( 'A warning', 'sv-warn1' ) );
504  $apiEx1->getStatusValue()->warning( new ApiRawMessage( 'Another warning', 'sv-warn2' ) );
505  $apiEx1->getStatusValue()->fatal( new ApiRawMessage( 'Another error', 'sv-error2' ) );
506 
507  return [
508  [
509  $ex,
510  [ 'existing-error', 'internal_api_error_InvalidArgumentException' ],
511  [
512  'warnings' => [
513  [ 'code' => 'existing-warning', 'text' => 'existing warning', 'module' => 'main' ],
514  ],
515  'errors' => [
516  [ 'code' => 'existing-error', 'text' => 'existing error', 'module' => 'main' ],
517  [
518  'code' => 'internal_api_error_InvalidArgumentException',
519  'text' => "[$reqId] Exception caught: Random exception",
520  ]
521  ],
522  'trace' => $trace,
523  'servedby' => wfHostname(),
524  ]
525  ],
526  [
527  $dbex,
528  [ 'existing-error', 'internal_api_error_DBQueryError' ],
529  [
530  'warnings' => [
531  [ 'code' => 'existing-warning', 'text' => 'existing warning', 'module' => 'main' ],
532  ],
533  'errors' => [
534  [ 'code' => 'existing-error', 'text' => 'existing error', 'module' => 'main' ],
535  [
536  'code' => 'internal_api_error_DBQueryError',
537  'text' => "[$reqId] Database query error.",
538  ]
539  ],
540  'trace' => $dbtrace,
541  'servedby' => wfHostname(),
542  ]
543  ],
544  [
545  new UsageException( 'Usage exception!', 'ue', 0, [ 'foo' => 'bar' ] ),
546  [ 'existing-error', 'ue' ],
547  [
548  'warnings' => [
549  [ 'code' => 'existing-warning', 'text' => 'existing warning', 'module' => 'main' ],
550  ],
551  'errors' => [
552  [ 'code' => 'existing-error', 'text' => 'existing error', 'module' => 'main' ],
553  [ 'code' => 'ue', 'text' => "Usage exception!", 'data' => [ 'foo' => 'bar' ] ]
554  ],
555  'docref' => "See $doclink for API usage. Subscribe to the mediawiki-api-announce mailing " .
556  "list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; " .
557  "for notice of API deprecations and breaking changes.",
558  'servedby' => wfHostname(),
559  ]
560  ],
561  [
562  $apiEx1,
563  [ 'existing-error', 'sv-error1', 'sv-error2' ],
564  [
565  'warnings' => [
566  [ 'code' => 'existing-warning', 'text' => 'existing warning', 'module' => 'main' ],
567  [ 'code' => 'sv-warn1', 'text' => 'A warning', 'module' => 'foo+bar' ],
568  [ 'code' => 'sv-warn2', 'text' => 'Another warning', 'module' => 'foo+bar' ],
569  ],
570  'errors' => [
571  [ 'code' => 'existing-error', 'text' => 'existing error', 'module' => 'main' ],
572  [ 'code' => 'sv-error1', 'text' => 'An error', 'module' => 'foo+bar' ],
573  [ 'code' => 'sv-error2', 'text' => 'Another error', 'module' => 'foo+bar' ],
574  ],
575  'docref' => "See $doclink for API usage. Subscribe to the mediawiki-api-announce mailing " .
576  "list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; " .
577  "for notice of API deprecations and breaking changes.",
578  'servedby' => wfHostname(),
579  ]
580  ],
581  ];
582  }
583 }
ApiMain
This is the main API class, used for both external and internal processing.
Definition: ApiMain.php:45
ContextSource\getConfig
getConfig()
Get the Config object.
Definition: ContextSource.php:68
$context
error also a ContextSource you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2612
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
ApiUsageException
Exception used to abort API execution with an error.
Definition: ApiUsageException.php:98
$request
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2612
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
MediaWikiTestCase\mergeMwGlobalArrayValue
mergeMwGlobalArrayValue( $name, $values)
Merges the given values into a MW global array variable.
Definition: MediaWikiTestCase.php:766
MediaWikiTestCase\getTestUser
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
Definition: MediaWikiTestCase.php:146
MultiConfig
Provides a fallback sequence for Config objects.
Definition: MultiConfig.php:28
HashConfig
A Config instance which stores all settings as a member variable.
Definition: HashConfig.php:28
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1994
$status
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup 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
Definition: hooks.txt:1049
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
ApiMainTest\testApi
testApi()
Test that the API will accept a FauxRequest and execute.
Definition: ApiMainTest.php:17
$user
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 account $user
Definition: hooks.txt:246
StatusValue\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:63
ApiMainTest\testConditionalRequestHeadersOutput
testConditionalRequestHeadersOutput( $conditions, $headers, $isError=false, $post=false)
Test conditional headers output provideConditionalRequestHeadersOutput.
Definition: ApiMainTest.php:213
wfHostname
wfHostname()
Fetch server name for use in error reporting etc.
Definition: GlobalFunctions.php:1435
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:304
User
User
Definition: All_system_messages.txt:425
php
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
ApiRawMessage
Extension of RawMessage implementing IApiMessage.
Definition: ApiMessage.php:268
ApiMainTest\provideCheckConditionalRequestHeaders
static provideCheckConditionalRequestHeaders()
Definition: ApiMainTest.php:142
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:3138
UsageException
This exception will be thrown when dieUsage is called to stop module execution.
Definition: ApiUsageException.php:28
ApiMainTest\testAssertUser
testAssertUser()
Tests the assertuser= functionality.
Definition: ApiMainTest.php:69
$modules
$modules
Definition: HTMLFormElement.php:12
ApiMainTest\testLacksSameOriginSecurity
testLacksSameOriginSecurity()
ApiMain::lacksSameOriginSecurity.
Definition: ApiMainTest.php:280
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:33
ApiMainTest
API Database medium.
Definition: ApiMainTest.php:12
ApiMainTest\testCheckConditionalRequestHeaders
testCheckConditionalRequestHeaders( $headers, $conditions, $status, $post=false)
Test HTTP precondition headers.
Definition: ApiMainTest.php:114
any
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition: COPYING.txt:326
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2122
ApiTestCase
Definition: ApiTestCase.php:3
$header
$header
Definition: updateCredits.php:35
$ret
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:1956
$response
this hook is for auditing only $response
Definition: hooks.txt:783
ApiTestCase\doApiRequest
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null)
Does the API request and returns the result.
Definition: ApiTestCase.php:73
ApiMainTest\testExceptionErrors
testExceptionErrors( $error, $expectReturn, $expectResult)
ApiMain::errorMessagesFromException ApiMain::substituteResultWithError provideExceptionErrors.
Definition: ApiMainTest.php:450
WebRequest\getRequestId
static getRequestId()
Get the unique request ID.
Definition: WebRequest.php:272
as
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
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 just before the function returns a value If you return true
Definition: hooks.txt:1956
wfMessage
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
class
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
ApiMainTest\provideAssert
static provideAssert()
Definition: ApiMainTest.php:27
ApiMainTest\provideApiErrorFormatterCreation
static provideApiErrorFormatterCreation()
Definition: ApiMainTest.php:335
ApiMainTest\testAssert
testAssert( $registered, $rights, $assert, $error)
Tests the assert={user|bot} functionality.
Definition: ApiMainTest.php:47
MWExceptionHandler\getRedactedTraceAsString
static getRedactedTraceAsString( $e)
Generate a string representation of an exception's stack trace.
Definition: MWExceptionHandler.php:313
ApiMainTest\provideExceptionErrors
provideExceptionErrors()
Definition: ApiMainTest.php:478
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:552
array
the array() calling protocol came about after MediaWiki 1.4rc1.
ApiMainTest\provideConditionalRequestHeadersOutput
static provideConditionalRequestHeadersOutput()
Definition: ApiMainTest.php:245
ApiMainTest\testApiErrorFormatterCreation
testApiErrorFormatterCreation(array $request, array $expect)
Test proper creation of the ApiErrorFormatter ApiMain::__construct provideApiErrorFormatterCreation.
Definition: ApiMainTest.php:319
ApiMainTest\testClassNamesInModuleManager
testClassNamesInModuleManager()
Test if all classes in the main module manager exists.
Definition: ApiMainTest.php:90