MediaWiki  1.30.0
StatusTest.php
Go to the documentation of this file.
1 <?php
2 
7 
8  public function testCanConstruct() {
9  new Status();
10  $this->assertTrue( true );
11  }
12 
17  public function testNewGood( $value = null ) {
19  $this->assertTrue( $status->isGood() );
20  $this->assertTrue( $status->isOK() );
21  $this->assertEquals( $value, $status->getValue() );
22  }
23 
24  public static function provideValues() {
25  return [
26  [],
27  [ 'foo' ],
28  [ [ 'foo' => 'bar' ] ],
29  [ new Exception() ],
30  [ 1234 ],
31  ];
32  }
33 
37  public function testNewFatalWithMessage() {
38  $message = $this->getMockBuilder( 'Message' )
39  ->disableOriginalConstructor()
40  ->getMock();
41 
42  $status = Status::newFatal( $message );
43  $this->assertFalse( $status->isGood() );
44  $this->assertFalse( $status->isOK() );
45  $this->assertEquals( $message, $status->getMessage() );
46  }
47 
51  public function testNewFatalWithString() {
52  $message = 'foo';
53  $status = Status::newFatal( $message );
54  $this->assertFalse( $status->isGood() );
55  $this->assertFalse( $status->isOK() );
56  $this->assertEquals( $message, $status->getMessage()->getKey() );
57  }
58 
64  public function testOkAndErrorsGetters() {
65  $status = Status::newGood( 'foo' );
66  $this->assertTrue( $status->ok );
67  $status = Status::newFatal( 'foo', 1, 2 );
68  $this->assertFalse( $status->ok );
69  $this->assertArrayEquals(
70  [
71  [
72  'type' => 'error',
73  'message' => 'foo',
74  'params' => [ 1, 2 ]
75  ]
76  ],
77  $status->errors
78  );
79  }
80 
86  public function testOkSetter() {
87  $status = new Status();
88  $status->ok = false;
89  $this->assertFalse( $status->isOK() );
90  $status->ok = true;
91  $this->assertTrue( $status->isOK() );
92  }
93 
98  public function testSetResult( $ok, $value = null ) {
99  $status = new Status();
100  $status->setResult( $ok, $value );
101  $this->assertEquals( $ok, $status->isOK() );
102  $this->assertEquals( $value, $status->getValue() );
103  }
104 
105  public static function provideSetResult() {
106  return [
107  [ true ],
108  [ false ],
109  [ true, 'value' ],
110  [ false, 'value' ],
111  ];
112  }
113 
119  public function testIsOk( $ok ) {
120  $status = new Status();
121  $status->setOK( $ok );
122  $this->assertEquals( $ok, $status->isOK() );
123  }
124 
125  public static function provideIsOk() {
126  return [
127  [ true ],
128  [ false ],
129  ];
130  }
131 
135  public function testGetValue() {
136  $status = new Status();
137  $status->value = 'foobar';
138  $this->assertEquals( 'foobar', $status->getValue() );
139  }
140 
145  public function testIsGood( $ok, $errors, $expected ) {
146  $status = new Status();
147  $status->setOK( $ok );
148  foreach ( $errors as $error ) {
149  $status->warning( $error );
150  }
151  $this->assertEquals( $expected, $status->isGood() );
152  }
153 
154  public static function provideIsGood() {
155  return [
156  [ true, [], true ],
157  [ true, [ 'foo' ], false ],
158  [ false, [], false ],
159  [ false, [ 'foo' ], false ],
160  ];
161  }
162 
169  public function testWarningWithMessage( $mockDetails ) {
170  $status = new Status();
171  $messages = $this->getMockMessages( $mockDetails );
172 
173  foreach ( $messages as $message ) {
174  $status->warning( $message );
175  }
176  $warnings = $status->getWarningsArray();
177 
178  $this->assertEquals( count( $messages ), count( $warnings ) );
179  foreach ( $messages as $key => $message ) {
180  $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
181  $this->assertEquals( $warnings[$key], $expectedArray );
182  }
183  }
184 
192  public function testErrorWithMessage( $mockDetails ) {
193  $status = new Status();
194  $messages = $this->getMockMessages( $mockDetails );
195 
196  foreach ( $messages as $message ) {
197  $status->error( $message );
198  }
199  $errors = $status->getErrorsArray();
200 
201  $this->assertEquals( count( $messages ), count( $errors ) );
202  foreach ( $messages as $key => $message ) {
203  $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
204  $this->assertEquals( $errors[$key], $expectedArray );
205  }
206  }
207 
214  public function testFatalWithMessage( $mockDetails ) {
215  $status = new Status();
216  $messages = $this->getMockMessages( $mockDetails );
217 
218  foreach ( $messages as $message ) {
219  $status->fatal( $message );
220  }
221  $errors = $status->getErrorsArray();
222 
223  $this->assertEquals( count( $messages ), count( $errors ) );
224  foreach ( $messages as $key => $message ) {
225  $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() );
226  $this->assertEquals( $errors[$key], $expectedArray );
227  }
228  $this->assertFalse( $status->isOK() );
229  }
230 
231  protected function getMockMessage( $key = 'key', $params = [] ) {
232  $message = $this->getMockBuilder( 'Message' )
233  ->disableOriginalConstructor()
234  ->getMock();
235  $message->expects( $this->atLeastOnce() )
236  ->method( 'getKey' )
237  ->will( $this->returnValue( $key ) );
238  $message->expects( $this->atLeastOnce() )
239  ->method( 'getParams' )
240  ->will( $this->returnValue( $params ) );
241  return $message;
242  }
243 
248  protected function getMockMessages( $messageDetails ) {
249  $messages = [];
250  foreach ( $messageDetails as $key => $paramsArray ) {
251  $messages[] = $this->getMockMessage( $key, $paramsArray );
252  }
253  return $messages;
254  }
255 
256  public static function provideMockMessageDetails() {
257  return [
258  [ [ 'key1' => [ 'foo' => 'bar' ] ] ],
259  [ [ 'key1' => [ 'foo' => 'bar' ], 'key2' => [ 'foo2' => 'bar2' ] ] ],
260  ];
261  }
262 
266  public function testMerge() {
267  $status1 = new Status();
268  $status2 = new Status();
269  $message1 = $this->getMockMessage( 'warn1' );
270  $message2 = $this->getMockMessage( 'error2' );
271  $status1->warning( $message1 );
272  $status2->error( $message2 );
273 
274  $status1->merge( $status2 );
275  $this->assertEquals(
276  2,
277  count( $status1->getWarningsArray() ) + count( $status1->getErrorsArray() )
278  );
279  }
280 
284  public function testMergeWithOverwriteValue() {
285  $status1 = new Status();
286  $status2 = new Status();
287  $message1 = $this->getMockMessage( 'warn1' );
288  $message2 = $this->getMockMessage( 'error2' );
289  $status1->warning( $message1 );
290  $status2->error( $message2 );
291  $status2->value = 'FooValue';
292 
293  $status1->merge( $status2, true );
294  $this->assertEquals(
295  2,
296  count( $status1->getWarningsArray() ) + count( $status1->getErrorsArray() )
297  );
298  $this->assertEquals( 'FooValue', $status1->getValue() );
299  }
300 
304  public function testHasMessage() {
305  $status = new Status();
306  $status->fatal( 'bad' );
307  $status->fatal( wfMessage( 'bad-msg' ) );
308  $this->assertTrue( $status->hasMessage( 'bad' ) );
309  $this->assertTrue( $status->hasMessage( 'bad-msg' ) );
310  $this->assertTrue( $status->hasMessage( wfMessage( 'bad-msg' ) ) );
311  $this->assertFalse( $status->hasMessage( 'good' ) );
312  }
313 
318  public function testCleanParams( $cleanCallback, $params, $expected ) {
319  $method = new ReflectionMethod( 'Status', 'cleanParams' );
320  $method->setAccessible( true );
321  $status = new Status();
322  $status->cleanCallback = $cleanCallback;
323 
324  $this->assertEquals( $expected, $method->invoke( $status, $params ) );
325  }
326 
327  public static function provideCleanParams() {
328  $cleanCallback = function ( $value ) {
329  return '-' . $value . '-';
330  };
331 
332  return [
333  [ false, [ 'foo' => 'bar' ], [ 'foo' => 'bar' ] ],
334  [ $cleanCallback, [ 'foo' => 'bar' ], [ 'foo' => '-bar-' ] ],
335  ];
336  }
337 
342  public function testGetWikiText(
343  Status $status, $wikitext, $wrappedWikitext, $html, $wrappedHtml
344  ) {
345  $this->assertEquals( $wikitext, $status->getWikiText() );
346 
347  $this->assertEquals( $wrappedWikitext, $status->getWikiText( 'wrap-short', 'wrap-long', 'qqx' ) );
348  }
349 
354  public function testGetHtml(
355  Status $status, $wikitext, $wrappedWikitext, $html, $wrappedHtml
356  ) {
357  $this->assertEquals( $html, $status->getHTML() );
358 
359  $this->assertEquals( $wrappedHtml, $status->getHTML( 'wrap-short', 'wrap-long', 'qqx' ) );
360  }
361 
367  public static function provideGetWikiTextAndHtml() {
368  $testCases = [];
369 
370  $testCases['GoodStatus'] = [
371  new Status(),
372  "Internal error: Status::getWikiText called for a good result, this is incorrect\n",
373  "(wrap-short: (internalerror_info: Status::getWikiText called for a good result, " .
374  "this is incorrect\n))",
375  "<p>Internal error: Status::getWikiText called for a good result, this is incorrect\n</p>",
376  "<p>(wrap-short: (internalerror_info: Status::getWikiText called for a good result, " .
377  "this is incorrect\n))\n</p>",
378  ];
379 
380  $status = new Status();
381  $status->setOK( false );
382  $testCases['GoodButNoError'] = [
383  $status,
384  "Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n",
385  "(wrap-short: (internalerror_info: Status::getWikiText: Invalid result object: " .
386  "no error text but not OK\n))",
387  "<p>Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n</p>",
388  "<p>(wrap-short: (internalerror_info: Status::getWikiText: Invalid result object: " .
389  "no error text but not OK\n))\n</p>",
390  ];
391 
392  $status = new Status();
393  $status->warning( 'fooBar!' );
394  $testCases['1StringWarning'] = [
395  $status,
396  "⧼fooBar!⧽",
397  "(wrap-short: (fooBar!))",
398  "<p>⧼fooBar!⧽\n</p>",
399  "<p>(wrap-short: (fooBar!))\n</p>",
400  ];
401 
402  $status = new Status();
403  $status->warning( 'fooBar!' );
404  $status->warning( 'fooBar2!' );
405  $testCases['2StringWarnings'] = [
406  $status,
407  "* ⧼fooBar!⧽\n* ⧼fooBar2!⧽\n",
408  "(wrap-long: * (fooBar!)\n* (fooBar2!)\n)",
409  "<ul><li> ⧼fooBar!⧽</li>\n<li> ⧼fooBar2!⧽</li></ul>\n",
410  "<p>(wrap-long: * (fooBar!)\n</p>\n<ul><li> (fooBar2!)</li></ul>\n<p>)\n</p>",
411  ];
412 
413  $status = new Status();
414  $status->warning( new Message( 'fooBar!', [ 'foo', 'bar' ] ) );
415  $testCases['1MessageWarning'] = [
416  $status,
417  "⧼fooBar!⧽",
418  "(wrap-short: (fooBar!: foo, bar))",
419  "<p>⧼fooBar!⧽\n</p>",
420  "<p>(wrap-short: (fooBar!: foo, bar))\n</p>",
421  ];
422 
423  $status = new Status();
424  $status->warning( new Message( 'fooBar!', [ 'foo', 'bar' ] ) );
425  $status->warning( new Message( 'fooBar2!' ) );
426  $testCases['2MessageWarnings'] = [
427  $status,
428  "* ⧼fooBar!⧽\n* ⧼fooBar2!⧽\n",
429  "(wrap-long: * (fooBar!: foo, bar)\n* (fooBar2!)\n)",
430  "<ul><li> ⧼fooBar!⧽</li>\n<li> ⧼fooBar2!⧽</li></ul>\n",
431  "<p>(wrap-long: * (fooBar!: foo, bar)\n</p>\n<ul><li> (fooBar2!)</li></ul>\n<p>)\n</p>",
432  ];
433 
434  return $testCases;
435  }
436 
437  private static function sanitizedMessageParams( Message $message ) {
438  return array_map( function ( $p ) {
439  return $p instanceof Message
440  ? [
441  'key' => $p->getKey(),
442  'params' => self::sanitizedMessageParams( $p ),
443  'lang' => $p->getLanguage()->getCode(),
444  ]
445  : $p;
446  }, $message->getParams() );
447  }
448 
453  public function testGetMessage(
454  Status $status, $expectedParams = [], $expectedKey, $expectedWrapper
455  ) {
456  $message = $status->getMessage( null, null, 'qqx' );
457  $this->assertInstanceOf( 'Message', $message );
458  $this->assertEquals( $expectedParams, self::sanitizedMessageParams( $message ),
459  'Message::getParams' );
460  $this->assertEquals( $expectedKey, $message->getKey(), 'Message::getKey' );
461 
462  $message = $status->getMessage( 'wrapper-short', 'wrapper-long' );
463  $this->assertInstanceOf( 'Message', $message );
464  $this->assertEquals( $expectedWrapper, $message->getKey(), 'Message::getKey with wrappers' );
465  $this->assertCount( 1, $message->getParams(), 'Message::getParams with wrappers' );
466 
467  $message = $status->getMessage( 'wrapper' );
468  $this->assertInstanceOf( 'Message', $message );
469  $this->assertEquals( 'wrapper', $message->getKey(), 'Message::getKey with wrappers' );
470  $this->assertCount( 1, $message->getParams(), 'Message::getParams with wrappers' );
471 
472  $message = $status->getMessage( false, 'wrapper' );
473  $this->assertInstanceOf( 'Message', $message );
474  $this->assertEquals( 'wrapper', $message->getKey(), 'Message::getKey with wrappers' );
475  $this->assertCount( 1, $message->getParams(), 'Message::getParams with wrappers' );
476  }
477 
484  public static function provideGetMessage() {
485  $testCases = [];
486 
487  $testCases['GoodStatus'] = [
488  new Status(),
489  [ "Status::getMessage called for a good result, this is incorrect\n" ],
490  'internalerror_info',
491  'wrapper-short'
492  ];
493 
494  $status = new Status();
495  $status->setOK( false );
496  $testCases['GoodButNoError'] = [
497  $status,
498  [ "Status::getMessage: Invalid result object: no error text but not OK\n" ],
499  'internalerror_info',
500  'wrapper-short'
501  ];
502 
503  $status = new Status();
504  $status->warning( 'fooBar!' );
505  $testCases['1StringWarning'] = [
506  $status,
507  [],
508  'fooBar!',
509  'wrapper-short'
510  ];
511 
512  $status = new Status();
513  $status->warning( 'fooBar!' );
514  $status->warning( 'fooBar2!' );
515  $testCases[ '2StringWarnings' ] = [
516  $status,
517  [
518  [ 'key' => 'fooBar!', 'params' => [], 'lang' => 'qqx' ],
519  [ 'key' => 'fooBar2!', 'params' => [], 'lang' => 'qqx' ]
520  ],
521  "* \$1\n* \$2",
522  'wrapper-long'
523  ];
524 
525  $status = new Status();
526  $status->warning( new Message( 'fooBar!', [ 'foo', 'bar' ] ) );
527  $testCases['1MessageWarning'] = [
528  $status,
529  [ 'foo', 'bar' ],
530  'fooBar!',
531  'wrapper-short'
532  ];
533 
534  $status = new Status();
535  $status->warning( new Message( 'fooBar!', [ 'foo', 'bar' ] ) );
536  $status->warning( new Message( 'fooBar2!' ) );
537  $testCases['2MessageWarnings'] = [
538  $status,
539  [
540  [ 'key' => 'fooBar!', 'params' => [ 'foo', 'bar' ], 'lang' => 'qqx' ],
541  [ 'key' => 'fooBar2!', 'params' => [], 'lang' => 'qqx' ]
542  ],
543  "* \$1\n* \$2",
544  'wrapper-long'
545  ];
546 
547  return $testCases;
548  }
549 
553  public function testReplaceMessage() {
554  $status = new Status();
555  $message = new Message( 'key1', [ 'foo1', 'bar1' ] );
556  $status->error( $message );
557  $newMessage = new Message( 'key2', [ 'foo2', 'bar2' ] );
558 
559  $status->replaceMessage( $message, $newMessage );
560 
561  $this->assertEquals( $newMessage, $status->errors[0]['message'] );
562  }
563 
567  public function testGetErrorMessage() {
568  $method = new ReflectionMethod( 'Status', 'getErrorMessage' );
569  $method->setAccessible( true );
570  $status = new Status();
571  $key = 'foo';
572  $params = [ 'bar' ];
573 
575  $message = $method->invoke( $status, array_merge( [ $key ], $params ) );
576  $this->assertInstanceOf( 'Message', $message );
577  $this->assertEquals( $key, $message->getKey() );
578  $this->assertEquals( $params, $message->getParams() );
579  }
580 
584  public function testGetErrorMessageArray() {
585  $method = new ReflectionMethod( 'Status', 'getErrorMessageArray' );
586  $method->setAccessible( true );
587  $status = new Status();
588  $key = 'foo';
589  $params = [ 'bar' ];
590 
592  $messageArray = $method->invoke(
593  $status,
594  [
595  array_merge( [ $key ], $params ),
596  array_merge( [ $key ], $params )
597  ]
598  );
599 
600  $this->assertInternalType( 'array', $messageArray );
601  $this->assertCount( 2, $messageArray );
602  foreach ( $messageArray as $message ) {
603  $this->assertInstanceOf( 'Message', $message );
604  $this->assertEquals( $key, $message->getKey() );
605  $this->assertEquals( $params, $message->getParams() );
606  }
607  }
608 
612  public function testGetErrorsByType() {
613  $status = new Status();
614  $warning = new Message( 'warning111' );
615  $error = new Message( 'error111' );
616  $status->warning( $warning );
617  $status->error( $error );
618 
619  $warnings = $status->getErrorsByType( 'warning' );
620  $errors = $status->getErrorsByType( 'error' );
621 
622  $this->assertCount( 1, $warnings );
623  $this->assertCount( 1, $errors );
624  $this->assertEquals( $warning, $warnings[0]['message'] );
625  $this->assertEquals( $error, $errors[0]['message'] );
626  }
627 
631  public function testWakeUpSanitizesCallback() {
632  $status = new Status();
633  $status->cleanCallback = function ( $value ) {
634  return '-' . $value . '-';
635  };
636  $status->__wakeup();
637  $this->assertEquals( false, $status->cleanCallback );
638  }
639 
644  public function testGetStatusArrayWithNonObjectMessages( $nonObjMsg ) {
645  $status = new Status();
646  if ( !array_key_exists( 1, $nonObjMsg ) ) {
647  $status->warning( $nonObjMsg[0] );
648  } else {
649  $status->warning( $nonObjMsg[0], $nonObjMsg[1] );
650  }
651 
652  $array = $status->getWarningsArray(); // We use getWarningsArray to access getStatusArray
653 
654  $this->assertEquals( 1, count( $array ) );
655  $this->assertEquals( $nonObjMsg, $array[0] );
656  }
657 
658  public static function provideNonObjectMessages() {
659  return [
660  [ [ 'ImaString', [ 'param1' => 'value1' ] ] ],
661  [ [ 'ImaString' ] ],
662  ];
663  }
664 
670  public function testGetErrorsWarningsOnlyStatus( $errorText, $warningText, $type, $errorResult,
671  $warningResult
672  ) {
674  if ( $errorText ) {
675  $status->fatal( $errorText );
676  }
677  if ( $warningText ) {
678  $status->warning( $warningText );
679  }
680  $testStatus = $status->splitByErrorType()[$type];
681  $this->assertEquals( $errorResult, $testStatus->getErrorsByType( 'error' ) );
682  $this->assertEquals( $warningResult, $testStatus->getErrorsByType( 'warning' ) );
683  }
684 
685  public static function provideErrorsWarningsOnly() {
686  return [
687  [
688  'Just an error',
689  'Just a warning',
690  0,
691  [
692  0 => [
693  'type' => 'error',
694  'message' => 'Just an error',
695  'params' => []
696  ],
697  ],
698  [],
699  ], [
700  'Just an error',
701  'Just a warning',
702  1,
703  [],
704  [
705  0 => [
706  'type' => 'warning',
707  'message' => 'Just a warning',
708  'params' => []
709  ],
710  ],
711  ], [
712  null,
713  null,
714  1,
715  [],
716  [],
717  ], [
718  null,
719  null,
720  0,
721  [],
722  [],
723  ]
724  ];
725  }
726 
727 }
StatusTest\provideSetResult
static provideSetResult()
Definition: StatusTest.php:105
StatusTest\provideGetWikiTextAndHtml
static provideGetWikiTextAndHtml()
Definition: StatusTest.php:367
StatusTest\provideCleanParams
static provideCleanParams()
Definition: StatusTest.php:327
StatusTest\provideGetMessage
static provideGetMessage()
Definition: StatusTest.php:484
StatusTest\testGetErrorsByType
testGetErrorsByType()
Status::getErrorsByType.
Definition: StatusTest.php:612
MediaWikiTestCase\assertArrayEquals
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Definition: MediaWikiTestCase.php:1552
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:644
StatusTest\testGetMessage
testGetMessage(Status $status, $expectedParams=[], $expectedKey, $expectedWrapper)
provideGetMessage Status::getMessage
Definition: StatusTest.php:453
StatusTest\testGetWikiText
testGetWikiText(Status $status, $wikitext, $wrappedWikitext, $html, $wrappedHtml)
provideGetWikiTextAndHtml Status::getWikiText
Definition: StatusTest.php:342
captcha-old.count
count
Definition: captcha-old.py:249
StatusTest\getMockMessage
getMockMessage( $key='key', $params=[])
Definition: StatusTest.php:231
StatusTest\provideMockMessageDetails
static provideMockMessageDetails()
Definition: StatusTest.php:256
$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. '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). '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:1245
StatusTest\testNewGood
testNewGood( $value=null)
provideValues Status::newGood
Definition: StatusTest.php:17
StatusTest\provideValues
static provideValues()
Definition: StatusTest.php:24
StatusTest\testSetResult
testSetResult( $ok, $value=null)
provideSetResult Status::setResult
Definition: StatusTest.php:98
StatusValue\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:68
$params
$params
Definition: styleTest.css.php:40
StatusTest\testCleanParams
testCleanParams( $cleanCallback, $params, $expected)
provideCleanParams Status::cleanParams
Definition: StatusTest.php:318
$messages
$messages
Definition: LogTests.i18n.php:8
StatusTest\testErrorWithMessage
testErrorWithMessage( $mockDetails)
provideMockMessageDetails Status::error Status::getErrorsArray Status::getStatusArray Status::getErro...
Definition: StatusTest.php:192
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:1965
StatusTest\testOkAndErrorsGetters
testOkAndErrorsGetters()
Test 'ok' and 'errors' getters.
Definition: StatusTest.php:64
StatusTest\testGetErrorsWarningsOnlyStatus
testGetErrorsWarningsOnlyStatus( $errorText, $warningText, $type, $errorResult, $warningResult)
provideErrorsWarningsOnly Status::splitByErrorType StatusValue::splitByErrorType
Definition: StatusTest.php:670
StatusTest\testGetErrorMessage
testGetErrorMessage()
Status::getErrorMessage.
Definition: StatusTest.php:567
StatusTest\testCanConstruct
testCanConstruct()
Definition: StatusTest.php:8
StatusTest\testReplaceMessage
testReplaceMessage()
Status::replaceMessage.
Definition: StatusTest.php:553
StatusTest\testMergeWithOverwriteValue
testMergeWithOverwriteValue()
Status::merge.
Definition: StatusTest.php:284
$value
$value
Definition: styleTest.css.php:45
StatusTest\testNewFatalWithMessage
testNewFatalWithMessage()
Status::newFatal.
Definition: StatusTest.php:37
StatusTest\testMerge
testMerge()
Status::merge.
Definition: StatusTest.php:266
StatusTest\testGetErrorMessageArray
testGetErrorMessageArray()
Status::getErrorMessageArray.
Definition: StatusTest.php:584
StatusTest\testOkSetter
testOkSetter()
Test 'ok' setter.
Definition: StatusTest.php:86
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:6
StatusTest\testWarningWithMessage
testWarningWithMessage( $mockDetails)
provideMockMessageDetails Status::warning Status::getWarningsArray Status::getStatusArray
Definition: StatusTest.php:169
StatusTest\testIsOk
testIsOk( $ok)
provideIsOk Status::setOK Status::isOK
Definition: StatusTest.php:119
StatusTest\provideIsOk
static provideIsOk()
Definition: StatusTest.php:125
StatusTest\testGetValue
testGetValue()
Status::getValue.
Definition: StatusTest.php:135
StatusTest\provideNonObjectMessages
static provideNonObjectMessages()
Definition: StatusTest.php:658
StatusTest\testNewFatalWithString
testNewFatalWithString()
Status::newFatal.
Definition: StatusTest.php:51
StatusTest\provideIsGood
static provideIsGood()
Definition: StatusTest.php:154
StatusTest\getMockMessages
getMockMessages( $messageDetails)
Definition: StatusTest.php:248
StatusTest\sanitizedMessageParams
static sanitizedMessageParams(Message $message)
Definition: StatusTest.php:437
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:1965
StatusTest\testFatalWithMessage
testFatalWithMessage( $mockDetails)
provideMockMessageDetails Status::fatal Status::getErrorsArray Status::getStatusArray
Definition: StatusTest.php:214
StatusTest\testHasMessage
testHasMessage()
Status::hasMessage.
Definition: StatusTest.php:304
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
StatusTest\provideErrorsWarningsOnly
static provideErrorsWarningsOnly()
Definition: StatusTest.php:685
StatusTest\testWakeUpSanitizesCallback
testWakeUpSanitizesCallback()
Status::__wakeup.
Definition: StatusTest.php:631
StatusTest\testGetHtml
testGetHtml(Status $status, $wikitext, $wrappedWikitext, $html, $wrappedHtml)
provideGetWikiTextAndHtml Status::getHtml
Definition: StatusTest.php:354
StatusTest\testIsGood
testIsGood( $ok, $errors, $expected)
provideIsGood Status::isGood
Definition: StatusTest.php:145
$type
$type
Definition: testCompression.php:48