MediaWiki  1.33.0
StatusTest.php
Go to the documentation of this file.
1 <?php
2 
7 
12  public function testNewGood( $value = null ) {
14  $this->assertTrue( $status->isGood() );
15  $this->assertTrue( $status->isOK() );
16  $this->assertEquals( $value, $status->getValue() );
17  }
18 
19  public static function provideValues() {
20  return [
21  [],
22  [ 'foo' ],
23  [ [ 'foo' => 'bar' ] ],
24  [ new Exception() ],
25  [ 1234 ],
26  ];
27  }
28 
32  public function testNewFatalWithMessage() {
33  $message = $this->getMockBuilder( Message::class )
34  ->disableOriginalConstructor()
35  ->getMock();
36 
37  $status = Status::newFatal( $message );
38  $this->assertFalse( $status->isGood() );
39  $this->assertFalse( $status->isOK() );
40  $this->assertEquals( $message, $status->getMessage() );
41  }
42 
46  public function testNewFatalWithString() {
47  $message = 'foo';
48  $status = Status::newFatal( $message );
49  $this->assertFalse( $status->isGood() );
50  $this->assertFalse( $status->isOK() );
51  $this->assertEquals( $message, $status->getMessage()->getKey() );
52  }
53 
59  public function testOkAndErrorsGetters() {
60  $status = Status::newGood( 'foo' );
61  $this->assertTrue( $status->ok );
62  $status = Status::newFatal( 'foo', 1, 2 );
63  $this->assertFalse( $status->ok );
64  $this->assertArrayEquals(
65  [
66  [
67  'type' => 'error',
68  'message' => 'foo',
69  'params' => [ 1, 2 ]
70  ]
71  ],
72  $status->errors
73  );
74  }
75 
81  public function testOkSetter() {
82  $status = new Status();
83  $status->ok = false;
84  $this->assertFalse( $status->isOK() );
85  $status->ok = true;
86  $this->assertTrue( $status->isOK() );
87  }
88 
93  public function testSetResult( $ok, $value = null ) {
94  $status = new Status();
95  $status->setResult( $ok, $value );
96  $this->assertEquals( $ok, $status->isOK() );
97  $this->assertEquals( $value, $status->getValue() );
98  }
99 
100  public static function provideSetResult() {
101  return [
102  [ true ],
103  [ false ],
104  [ true, 'value' ],
105  [ false, 'value' ],
106  ];
107  }
108 
114  public function testIsOk( $ok ) {
115  $status = new Status();
116  $status->setOK( $ok );
117  $this->assertEquals( $ok, $status->isOK() );
118  }
119 
120  public static function provideIsOk() {
121  return [
122  [ true ],
123  [ false ],
124  ];
125  }
126 
130  public function testGetValue() {
131  $status = new Status();
132  $status->value = 'foobar';
133  $this->assertEquals( 'foobar', $status->getValue() );
134  }
135 
140  public function testIsGood( $ok, $errors, $expected ) {
141  $status = new Status();
142  $status->setOK( $ok );
143  foreach ( $errors as $error ) {
144  $status->warning( $error );
145  }
146  $this->assertEquals( $expected, $status->isGood() );
147  }
148 
149  public static function provideIsGood() {
150  return [
151  [ true, [], true ],
152  [ true, [ 'foo' ], false ],
153  [ false, [], false ],
154  [ false, [ 'foo' ], false ],
155  ];
156  }
157 
164  public function testWarningWithMessage( $mockDetails ) {
165  $status = new Status();
166  $messages = $this->getMockMessages( $mockDetails );
167 
168  foreach ( $messages as $message ) {
169  $status->warning( $message );
170  }
171  $warnings = $status->getWarningsArray();
172 
173  $this->assertEquals( count( $messages ), count( $warnings ) );
174  foreach ( $messages as $key => $message ) {
175  $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
176  $this->assertEquals( $warnings[$key], $expectedArray );
177  }
178  }
179 
187  public function testErrorWithMessage( $mockDetails ) {
188  $status = new Status();
189  $messages = $this->getMockMessages( $mockDetails );
190 
191  foreach ( $messages as $message ) {
192  $status->error( $message );
193  }
194  $errors = $status->getErrorsArray();
195 
196  $this->assertEquals( count( $messages ), count( $errors ) );
197  foreach ( $messages as $key => $message ) {
198  $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
199  $this->assertEquals( $errors[$key], $expectedArray );
200  }
201  }
202 
209  public function testFatalWithMessage( $mockDetails ) {
210  $status = new Status();
211  $messages = $this->getMockMessages( $mockDetails );
212 
213  foreach ( $messages as $message ) {
214  $status->fatal( $message );
215  }
216  $errors = $status->getErrorsArray();
217 
218  $this->assertEquals( count( $messages ), count( $errors ) );
219  foreach ( $messages as $key => $message ) {
220  $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
221  $this->assertEquals( $errors[$key], $expectedArray );
222  }
223  $this->assertFalse( $status->isOK() );
224  }
225 
226  protected function getMockMessage( $key = 'key', $params = [] ) {
227  $message = $this->getMockBuilder( Message::class )
228  ->disableOriginalConstructor()
229  ->getMock();
230  $message->expects( $this->atLeastOnce() )
231  ->method( 'getKey' )
232  ->will( $this->returnValue( $key ) );
233  $message->expects( $this->atLeastOnce() )
234  ->method( 'getParams' )
235  ->will( $this->returnValue( $params ) );
236  return $message;
237  }
238 
243  protected function getMockMessages( $messageDetails ) {
244  $messages = [];
245  foreach ( $messageDetails as $key => $paramsArray ) {
246  $messages[] = $this->getMockMessage( $key, $paramsArray );
247  }
248  return $messages;
249  }
250 
251  public static function provideMockMessageDetails() {
252  return [
253  [ [ 'key1' => [ 'foo' => 'bar' ] ] ],
254  [ [ 'key1' => [ 'foo' => 'bar' ], 'key2' => [ 'foo2' => 'bar2' ] ] ],
255  ];
256  }
257 
261  public function testMerge() {
262  $status1 = new Status();
263  $status2 = new Status();
264  $message1 = $this->getMockMessage( 'warn1' );
265  $message2 = $this->getMockMessage( 'error2' );
266  $status1->warning( $message1 );
267  $status2->error( $message2 );
268 
269  $status1->merge( $status2 );
270  $this->assertEquals(
271  2,
272  count( $status1->getWarningsArray() ) + count( $status1->getErrorsArray() )
273  );
274  }
275 
279  public function testMergeWithOverwriteValue() {
280  $status1 = new Status();
281  $status2 = new Status();
282  $message1 = $this->getMockMessage( 'warn1' );
283  $message2 = $this->getMockMessage( 'error2' );
284  $status1->warning( $message1 );
285  $status2->error( $message2 );
286  $status2->value = 'FooValue';
287 
288  $status1->merge( $status2, true );
289  $this->assertEquals(
290  2,
291  count( $status1->getWarningsArray() ) + count( $status1->getErrorsArray() )
292  );
293  $this->assertEquals( 'FooValue', $status1->getValue() );
294  }
295 
299  public function testHasMessage() {
300  $status = new Status();
301  $status->fatal( 'bad' );
302  $status->fatal( wfMessage( 'bad-msg' ) );
303  $this->assertTrue( $status->hasMessage( 'bad' ) );
304  $this->assertTrue( $status->hasMessage( 'bad-msg' ) );
305  $this->assertTrue( $status->hasMessage( wfMessage( 'bad-msg' ) ) );
306  $this->assertFalse( $status->hasMessage( 'good' ) );
307  }
308 
313  public function testCleanParams( $cleanCallback, $params, $expected ) {
314  $method = new ReflectionMethod( Status::class, 'cleanParams' );
315  $method->setAccessible( true );
316  $status = new Status();
317  $status->cleanCallback = $cleanCallback;
318 
319  $this->assertEquals( $expected, $method->invoke( $status, $params ) );
320  }
321 
322  public static function provideCleanParams() {
323  $cleanCallback = function ( $value ) {
324  return '-' . $value . '-';
325  };
326 
327  return [
328  [ false, [ 'foo' => 'bar' ], [ 'foo' => 'bar' ] ],
329  [ $cleanCallback, [ 'foo' => 'bar' ], [ 'foo' => '-bar-' ] ],
330  ];
331  }
332 
337  public function testGetWikiText(
338  Status $status, $wikitext, $wrappedWikitext, $html, $wrappedHtml
339  ) {
340  $this->assertEquals( $wikitext, $status->getWikiText() );
341 
342  $this->assertEquals( $wrappedWikitext, $status->getWikiText( 'wrap-short', 'wrap-long', 'qqx' ) );
343  }
344 
349  public function testGetHtml(
350  Status $status, $wikitext, $wrappedWikitext, $html, $wrappedHtml
351  ) {
352  $this->assertEquals( $html, $status->getHTML() );
353 
354  $this->assertEquals( $wrappedHtml, $status->getHTML( 'wrap-short', 'wrap-long', 'qqx' ) );
355  }
356 
362  public static function provideGetWikiTextAndHtml() {
363  $testCases = [];
364 
365  $testCases['GoodStatus'] = [
366  new Status(),
367  "Internal error: Status::getWikiText called for a good result, this is incorrect\n",
368  "(wrap-short: (internalerror_info: Status::getWikiText called for a good result, " .
369  "this is incorrect\n))",
370  "<p>Internal error: Status::getWikiText called for a good result, this is incorrect\n</p>",
371  "<p>(wrap-short: (internalerror_info: Status::getWikiText called for a good result, " .
372  "this is incorrect\n))\n</p>",
373  ];
374 
375  $status = new Status();
376  $status->setOK( false );
377  $testCases['GoodButNoError'] = [
378  $status,
379  "Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n",
380  "(wrap-short: (internalerror_info: Status::getWikiText: Invalid result object: " .
381  "no error text but not OK\n))",
382  "<p>Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n</p>",
383  "<p>(wrap-short: (internalerror_info: Status::getWikiText: Invalid result object: " .
384  "no error text but not OK\n))\n</p>",
385  ];
386 
387  $status = new Status();
388  $status->warning( 'fooBar!' );
389  $testCases['1StringWarning'] = [
390  $status,
391  "⧼fooBar!⧽",
392  "(wrap-short: (fooBar!))",
393  "<p>⧼fooBar!⧽\n</p>",
394  "<p>(wrap-short: (fooBar!))\n</p>",
395  ];
396 
397  $status = new Status();
398  $status->warning( 'fooBar!' );
399  $status->warning( 'fooBar2!' );
400  $testCases['2StringWarnings'] = [
401  $status,
402  "* ⧼fooBar!⧽\n* ⧼fooBar2!⧽\n",
403  "(wrap-long: * (fooBar!)\n* (fooBar2!)\n)",
404  "<ul><li>⧼fooBar!⧽</li>\n<li>⧼fooBar2!⧽</li></ul>\n",
405  "<p>(wrap-long: * (fooBar!)\n</p>\n<ul><li>(fooBar2!)</li></ul>\n<p>)\n</p>",
406  ];
407 
408  $status = new Status();
409  $status->warning( new Message( 'fooBar!', [ 'foo', 'bar' ] ) );
410  $testCases['1MessageWarning'] = [
411  $status,
412  "⧼fooBar!⧽",
413  "(wrap-short: (fooBar!: foo, bar))",
414  "<p>⧼fooBar!⧽\n</p>",
415  "<p>(wrap-short: (fooBar!: foo, bar))\n</p>",
416  ];
417 
418  $status = new Status();
419  $status->warning( new Message( 'fooBar!', [ 'foo', 'bar' ] ) );
420  $status->warning( new Message( 'fooBar2!' ) );
421  $testCases['2MessageWarnings'] = [
422  $status,
423  "* ⧼fooBar!⧽\n* ⧼fooBar2!⧽\n",
424  "(wrap-long: * (fooBar!: foo, bar)\n* (fooBar2!)\n)",
425  "<ul><li>⧼fooBar!⧽</li>\n<li>⧼fooBar2!⧽</li></ul>\n",
426  "<p>(wrap-long: * (fooBar!: foo, bar)\n</p>\n<ul><li>(fooBar2!)</li></ul>\n<p>)\n</p>",
427  ];
428 
429  return $testCases;
430  }
431 
432  private static function sanitizedMessageParams( Message $message ) {
433  return array_map( function ( $p ) {
434  return $p instanceof Message
435  ? [
436  'key' => $p->getKey(),
437  'params' => self::sanitizedMessageParams( $p ),
438  'lang' => $p->getLanguage()->getCode(),
439  ]
440  : $p;
441  }, $message->getParams() );
442  }
443 
448  public function testGetMessage(
449  Status $status, $expectedParams = [], $expectedKey, $expectedWrapper
450  ) {
451  $message = $status->getMessage( null, null, 'qqx' );
452  $this->assertInstanceOf( Message::class, $message );
453  $this->assertEquals( $expectedParams, self::sanitizedMessageParams( $message ),
454  'Message::getParams' );
455  $this->assertEquals( $expectedKey, $message->getKey(), 'Message::getKey' );
456 
457  $message = $status->getMessage( 'wrapper-short', 'wrapper-long' );
458  $this->assertInstanceOf( Message::class, $message );
459  $this->assertEquals( $expectedWrapper, $message->getKey(), 'Message::getKey with wrappers' );
460  $this->assertCount( 1, $message->getParams(), 'Message::getParams with wrappers' );
461 
462  $message = $status->getMessage( 'wrapper' );
463  $this->assertInstanceOf( Message::class, $message );
464  $this->assertEquals( 'wrapper', $message->getKey(), 'Message::getKey with wrappers' );
465  $this->assertCount( 1, $message->getParams(), 'Message::getParams with wrappers' );
466 
467  $message = $status->getMessage( false, 'wrapper' );
468  $this->assertInstanceOf( Message::class, $message );
469  $this->assertEquals( 'wrapper', $message->getKey(), 'Message::getKey with wrappers' );
470  $this->assertCount( 1, $message->getParams(), 'Message::getParams with wrappers' );
471  }
472 
479  public static function provideGetMessage() {
480  $testCases = [];
481 
482  $testCases['GoodStatus'] = [
483  new Status(),
484  [ "Status::getMessage called for a good result, this is incorrect\n" ],
485  'internalerror_info',
486  'wrapper-short'
487  ];
488 
489  $status = new Status();
490  $status->setOK( false );
491  $testCases['GoodButNoError'] = [
492  $status,
493  [ "Status::getMessage: Invalid result object: no error text but not OK\n" ],
494  'internalerror_info',
495  'wrapper-short'
496  ];
497 
498  $status = new Status();
499  $status->warning( 'fooBar!' );
500  $testCases['1StringWarning'] = [
501  $status,
502  [],
503  'fooBar!',
504  'wrapper-short'
505  ];
506 
507  $status = new Status();
508  $status->warning( 'fooBar!' );
509  $status->warning( 'fooBar2!' );
510  $testCases[ '2StringWarnings' ] = [
511  $status,
512  [
513  [ 'key' => 'fooBar!', 'params' => [], 'lang' => 'qqx' ],
514  [ 'key' => 'fooBar2!', 'params' => [], 'lang' => 'qqx' ]
515  ],
516  "* \$1\n* \$2",
517  'wrapper-long'
518  ];
519 
520  $status = new Status();
521  $status->warning( new Message( 'fooBar!', [ 'foo', 'bar' ] ) );
522  $testCases['1MessageWarning'] = [
523  $status,
524  [ 'foo', 'bar' ],
525  'fooBar!',
526  'wrapper-short'
527  ];
528 
529  $status = new Status();
530  $status->warning( new Message( 'fooBar!', [ 'foo', 'bar' ] ) );
531  $status->warning( new Message( 'fooBar2!' ) );
532  $testCases['2MessageWarnings'] = [
533  $status,
534  [
535  [ 'key' => 'fooBar!', 'params' => [ 'foo', 'bar' ], 'lang' => 'qqx' ],
536  [ 'key' => 'fooBar2!', 'params' => [], 'lang' => 'qqx' ]
537  ],
538  "* \$1\n* \$2",
539  'wrapper-long'
540  ];
541 
542  return $testCases;
543  }
544 
548  public function testReplaceMessage() {
549  $status = new Status();
550  $message = new Message( 'key1', [ 'foo1', 'bar1' ] );
551  $status->error( $message );
552  $newMessage = new Message( 'key2', [ 'foo2', 'bar2' ] );
553 
554  $status->replaceMessage( $message, $newMessage );
555 
556  $this->assertEquals( $newMessage, $status->errors[0]['message'] );
557  }
558 
562  public function testGetErrorMessage() {
563  $method = new ReflectionMethod( Status::class, 'getErrorMessage' );
564  $method->setAccessible( true );
565  $status = new Status();
566  $key = 'foo';
567  $params = [ 'bar' ];
568 
570  $message = $method->invoke( $status, array_merge( [ $key ], $params ) );
571  $this->assertInstanceOf( Message::class, $message );
572  $this->assertEquals( $key, $message->getKey() );
573  $this->assertEquals( $params, $message->getParams() );
574  }
575 
579  public function testGetErrorMessageArray() {
580  $method = new ReflectionMethod( Status::class, 'getErrorMessageArray' );
581  $method->setAccessible( true );
582  $status = new Status();
583  $key = 'foo';
584  $params = [ 'bar' ];
585 
587  $messageArray = $method->invoke(
588  $status,
589  [
590  array_merge( [ $key ], $params ),
591  array_merge( [ $key ], $params )
592  ]
593  );
594 
595  $this->assertInternalType( 'array', $messageArray );
596  $this->assertCount( 2, $messageArray );
597  foreach ( $messageArray as $message ) {
598  $this->assertInstanceOf( Message::class, $message );
599  $this->assertEquals( $key, $message->getKey() );
600  $this->assertEquals( $params, $message->getParams() );
601  }
602  }
603 
607  public function testGetErrorsByType() {
608  $status = new Status();
609  $warning = new Message( 'warning111' );
610  $error = new Message( 'error111' );
611  $status->warning( $warning );
612  $status->error( $error );
613 
614  $warnings = $status->getErrorsByType( 'warning' );
615  $errors = $status->getErrorsByType( 'error' );
616 
617  $this->assertCount( 1, $warnings );
618  $this->assertCount( 1, $errors );
619  $this->assertEquals( $warning, $warnings[0]['message'] );
620  $this->assertEquals( $error, $errors[0]['message'] );
621  }
622 
626  public function testWakeUpSanitizesCallback() {
627  $status = new Status();
628  $status->cleanCallback = function ( $value ) {
629  return '-' . $value . '-';
630  };
631  $status->__wakeup();
632  $this->assertEquals( false, $status->cleanCallback );
633  }
634 
639  public function testGetStatusArrayWithNonObjectMessages( $nonObjMsg ) {
640  $status = new Status();
641  if ( !array_key_exists( 1, $nonObjMsg ) ) {
642  $status->warning( $nonObjMsg[0] );
643  } else {
644  $status->warning( $nonObjMsg[0], $nonObjMsg[1] );
645  }
646 
647  $array = $status->getWarningsArray(); // We use getWarningsArray to access getStatusArray
648 
649  $this->assertEquals( 1, count( $array ) );
650  $this->assertEquals( $nonObjMsg, $array[0] );
651  }
652 
653  public static function provideNonObjectMessages() {
654  return [
655  [ [ 'ImaString', [ 'param1' => 'value1' ] ] ],
656  [ [ 'ImaString' ] ],
657  ];
658  }
659 
665  public function testGetErrorsWarningsOnlyStatus( $errorText, $warningText, $type, $errorResult,
666  $warningResult
667  ) {
669  if ( $errorText ) {
670  $status->fatal( $errorText );
671  }
672  if ( $warningText ) {
673  $status->warning( $warningText );
674  }
675  $testStatus = $status->splitByErrorType()[$type];
676  $this->assertEquals( $errorResult, $testStatus->getErrorsByType( 'error' ) );
677  $this->assertEquals( $warningResult, $testStatus->getErrorsByType( 'warning' ) );
678  }
679 
680  public static function provideErrorsWarningsOnly() {
681  return [
682  [
683  'Just an error',
684  'Just a warning',
685  0,
686  [
687  0 => [
688  'type' => 'error',
689  'message' => 'Just an error',
690  'params' => []
691  ],
692  ],
693  [],
694  ], [
695  'Just an error',
696  'Just a warning',
697  1,
698  [],
699  [
700  0 => [
701  'type' => 'warning',
702  'message' => 'Just a warning',
703  'params' => []
704  ],
705  ],
706  ], [
707  null,
708  null,
709  1,
710  [],
711  [],
712  ], [
713  null,
714  null,
715  0,
716  [],
717  [],
718  ]
719  ];
720  }
721 
722 }
StatusTest\provideSetResult
static provideSetResult()
Definition: StatusTest.php:100
StatusTest\provideGetWikiTextAndHtml
static provideGetWikiTextAndHtml()
Definition: StatusTest.php:362
$status
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
Definition: hooks.txt:1266
StatusTest\provideCleanParams
static provideCleanParams()
Definition: StatusTest.php:322
StatusTest\provideGetMessage
static provideGetMessage()
Definition: StatusTest.php:479
StatusTest\testGetErrorsByType
testGetErrorsByType()
Status::getErrorsByType.
Definition: StatusTest.php:607
MediaWikiTestCase\assertArrayEquals
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Definition: MediaWikiTestCase.php:2070
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
StatusTest\testGetStatusArrayWithNonObjectMessages
testGetStatusArrayWithNonObjectMessages( $nonObjMsg)
provideNonObjectMessages Status::getStatusArray
Definition: StatusTest.php:639
StatusTest\testGetMessage
testGetMessage(Status $status, $expectedParams=[], $expectedKey, $expectedWrapper)
provideGetMessage Status::getMessage
Definition: StatusTest.php:448
StatusTest\testGetWikiText
testGetWikiText(Status $status, $wikitext, $wrappedWikitext, $html, $wrappedHtml)
provideGetWikiTextAndHtml Status::getWikiText
Definition: StatusTest.php:337
captcha-old.count
count
Definition: captcha-old.py:249
StatusTest\getMockMessage
getMockMessage( $key='key', $params=[])
Definition: StatusTest.php:226
StatusTest\provideMockMessageDetails
static provideMockMessageDetails()
Definition: StatusTest.php:251
StatusTest\testNewGood
testNewGood( $value=null)
provideValues Status::newGood
Definition: StatusTest.php:12
StatusTest\provideValues
static provideValues()
Definition: StatusTest.php:19
StatusTest\testSetResult
testSetResult( $ok, $value=null)
provideSetResult Status::setResult
Definition: StatusTest.php:93
StatusValue\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:68
$params
$params
Definition: styleTest.css.php:44
StatusTest\testCleanParams
testCleanParams( $cleanCallback, $params, $expected)
provideCleanParams Status::cleanParams
Definition: StatusTest.php:313
$messages
$messages
Definition: LogTests.i18n.php:8
StatusTest\testErrorWithMessage
testErrorWithMessage( $mockDetails)
provideMockMessageDetails Status::error Status::getErrorsArray Status::getStatusArray Status::getErro...
Definition: StatusTest.php:187
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
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:40
StatusTest
Definition: StatusTest.php:6
$html
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 an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1985
StatusTest\testOkAndErrorsGetters
testOkAndErrorsGetters()
Test 'ok' and 'errors' getters.
Definition: StatusTest.php:59
StatusTest\testGetErrorsWarningsOnlyStatus
testGetErrorsWarningsOnlyStatus( $errorText, $warningText, $type, $errorResult, $warningResult)
provideErrorsWarningsOnly Status::splitByErrorType StatusValue::splitByErrorType
Definition: StatusTest.php:665
StatusTest\testGetErrorMessage
testGetErrorMessage()
Status::getErrorMessage.
Definition: StatusTest.php:562
StatusTest\testReplaceMessage
testReplaceMessage()
Status::replaceMessage.
Definition: StatusTest.php:548
StatusTest\testMergeWithOverwriteValue
testMergeWithOverwriteValue()
Status::merge.
Definition: StatusTest.php:279
$value
$value
Definition: styleTest.css.php:49
StatusTest\testNewFatalWithMessage
testNewFatalWithMessage()
Status::newFatal.
Definition: StatusTest.php:32
StatusTest\testMerge
testMerge()
Status::merge.
Definition: StatusTest.php:261
StatusTest\testGetErrorMessageArray
testGetErrorMessageArray()
Status::getErrorMessageArray.
Definition: StatusTest.php:579
StatusTest\testOkSetter
testOkSetter()
Test 'ok' setter.
Definition: StatusTest.php:81
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:8
StatusTest\testWarningWithMessage
testWarningWithMessage( $mockDetails)
provideMockMessageDetails Status::warning Status::getWarningsArray Status::getStatusArray
Definition: StatusTest.php:164
StatusTest\testIsOk
testIsOk( $ok)
provideIsOk Status::setOK Status::isOK
Definition: StatusTest.php:114
StatusTest\provideIsOk
static provideIsOk()
Definition: StatusTest.php:120
StatusTest\testGetValue
testGetValue()
Status::getValue.
Definition: StatusTest.php:130
StatusTest\provideNonObjectMessages
static provideNonObjectMessages()
Definition: StatusTest.php:653
StatusTest\testNewFatalWithString
testNewFatalWithString()
Status::newFatal.
Definition: StatusTest.php:46
StatusTest\provideIsGood
static provideIsGood()
Definition: StatusTest.php:149
StatusTest\getMockMessages
getMockMessages( $messageDetails)
Definition: StatusTest.php:243
StatusTest\sanitizedMessageParams
static sanitizedMessageParams(Message $message)
Definition: StatusTest.php:432
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:1985
StatusTest\testFatalWithMessage
testFatalWithMessage( $mockDetails)
provideMockMessageDetails Status::fatal Status::getErrorsArray Status::getStatusArray
Definition: StatusTest.php:209
StatusTest\testHasMessage
testHasMessage()
Status::hasMessage.
Definition: StatusTest.php:299
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
StatusTest\provideErrorsWarningsOnly
static provideErrorsWarningsOnly()
Definition: StatusTest.php:680
StatusTest\testWakeUpSanitizesCallback
testWakeUpSanitizesCallback()
Status::__wakeup.
Definition: StatusTest.php:626
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 use $formDescriptor instead 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
StatusTest\testGetHtml
testGetHtml(Status $status, $wikitext, $wrappedWikitext, $html, $wrappedHtml)
provideGetWikiTextAndHtml Status::getHtml
Definition: StatusTest.php:349
StatusTest\testIsGood
testIsGood( $ok, $errors, $expected)
provideIsGood Status::isGood
Definition: StatusTest.php:140
$type
$type
Definition: testCompression.php:48