MediaWiki  1.32.5
CommentStoreTest.php
Go to the documentation of this file.
1 <?php
2 
4 use Wikimedia\ScopedCallback;
5 use Wikimedia\TestingAccessWrapper;
6 
13 
14  protected $tablesUsed = [
15  'revision',
16  'revision_comment_temp',
17  'ipblocks',
18  'comment',
19  ];
20 
26  protected function makeStore( $stage ) {
27  $store = new CommentStore( MediaWikiServices::getInstance()->getContentLanguage(), $stage );
28  return $store;
29  }
30 
37  protected function makeStoreWithKey( $stage, $key ) {
38  $this->hideDeprecated( 'CommentStore::newKey' );
39  $store = CommentStore::newKey( $key );
40  TestingAccessWrapper::newFromObject( $store )->stage = $stage;
41  return $store;
42  }
43 
50  public function testGetFields_withKeyConstruction( $stage, $key, $expect ) {
51  $store = $this->makeStoreWithKey( $stage, $key );
52  $result = $store->getFields();
53  $this->assertEquals( $expect, $result );
54  }
55 
62  public function testGetFields( $stage, $key, $expect ) {
63  $store = $this->makeStore( $stage );
64  $result = $store->getFields( $key );
65  $this->assertEquals( $expect, $result );
66  }
67 
68  public static function provideGetFields() {
69  return [
70  'Simple table, old' => [
71  MIGRATION_OLD, 'ipb_reason',
72  [ 'ipb_reason_text' => 'ipb_reason', 'ipb_reason_data' => 'NULL', 'ipb_reason_cid' => 'NULL' ],
73  ],
74  'Simple table, write-both' => [
75  MIGRATION_WRITE_BOTH, 'ipb_reason',
76  [ 'ipb_reason_old' => 'ipb_reason', 'ipb_reason_id' => 'ipb_reason_id' ],
77  ],
78  'Simple table, write-new' => [
79  MIGRATION_WRITE_NEW, 'ipb_reason',
80  [ 'ipb_reason_old' => 'ipb_reason', 'ipb_reason_id' => 'ipb_reason_id' ],
81  ],
82  'Simple table, new' => [
83  MIGRATION_NEW, 'ipb_reason',
84  [ 'ipb_reason_id' => 'ipb_reason_id' ],
85  ],
86 
87  'Revision, old' => [
88  MIGRATION_OLD, 'rev_comment',
89  [
90  'rev_comment_text' => 'rev_comment',
91  'rev_comment_data' => 'NULL',
92  'rev_comment_cid' => 'NULL',
93  ],
94  ],
95  'Revision, write-both' => [
96  MIGRATION_WRITE_BOTH, 'rev_comment',
97  [ 'rev_comment_old' => 'rev_comment', 'rev_comment_pk' => 'rev_id' ],
98  ],
99  'Revision, write-new' => [
100  MIGRATION_WRITE_NEW, 'rev_comment',
101  [ 'rev_comment_old' => 'rev_comment', 'rev_comment_pk' => 'rev_id' ],
102  ],
103  'Revision, new' => [
104  MIGRATION_NEW, 'rev_comment',
105  [ 'rev_comment_pk' => 'rev_id' ],
106  ],
107 
108  'Image, old' => [
109  MIGRATION_OLD, 'img_description',
110  [
111  'img_description_text' => 'img_description',
112  'img_description_data' => 'NULL',
113  'img_description_cid' => 'NULL',
114  ],
115  ],
116  'Image, write-both' => [
117  MIGRATION_WRITE_BOTH, 'img_description',
118  [
119  'img_description_old' => 'img_description',
120  'img_description_id' => 'img_description_id'
121  ],
122  ],
123  'Image, write-new' => [
124  MIGRATION_WRITE_NEW, 'img_description',
125  [
126  'img_description_old' => 'img_description',
127  'img_description_id' => 'img_description_id'
128  ],
129  ],
130  'Image, new' => [
131  MIGRATION_NEW, 'img_description',
132  [
133  'img_description_id' => 'img_description_id'
134  ],
135  ],
136  ];
137  }
138 
145  public function testGetJoin_withKeyConstruction( $stage, $key, $expect ) {
146  $store = $this->makeStoreWithKey( $stage, $key );
147  $result = $store->getJoin();
148  $this->assertEquals( $expect, $result );
149  }
150 
157  public function testGetJoin( $stage, $key, $expect ) {
158  $store = $this->makeStore( $stage );
159  $result = $store->getJoin( $key );
160  $this->assertEquals( $expect, $result );
161  }
162 
163  public static function provideGetJoin() {
164  return [
165  'Simple table, old' => [
166  MIGRATION_OLD, 'ipb_reason', [
167  'tables' => [],
168  'fields' => [
169  'ipb_reason_text' => 'ipb_reason',
170  'ipb_reason_data' => 'NULL',
171  'ipb_reason_cid' => 'NULL',
172  ],
173  'joins' => [],
174  ],
175  ],
176  'Simple table, write-both' => [
177  MIGRATION_WRITE_BOTH, 'ipb_reason', [
178  'tables' => [ 'comment_ipb_reason' => 'comment' ],
179  'fields' => [
180  'ipb_reason_text' => 'COALESCE( comment_ipb_reason.comment_text, ipb_reason )',
181  'ipb_reason_data' => 'comment_ipb_reason.comment_data',
182  'ipb_reason_cid' => 'comment_ipb_reason.comment_id',
183  ],
184  'joins' => [
185  'comment_ipb_reason' => [ 'LEFT JOIN', 'comment_ipb_reason.comment_id = ipb_reason_id' ],
186  ],
187  ],
188  ],
189  'Simple table, write-new' => [
190  MIGRATION_WRITE_NEW, 'ipb_reason', [
191  'tables' => [ 'comment_ipb_reason' => 'comment' ],
192  'fields' => [
193  'ipb_reason_text' => 'COALESCE( comment_ipb_reason.comment_text, ipb_reason )',
194  'ipb_reason_data' => 'comment_ipb_reason.comment_data',
195  'ipb_reason_cid' => 'comment_ipb_reason.comment_id',
196  ],
197  'joins' => [
198  'comment_ipb_reason' => [ 'LEFT JOIN', 'comment_ipb_reason.comment_id = ipb_reason_id' ],
199  ],
200  ],
201  ],
202  'Simple table, new' => [
203  MIGRATION_NEW, 'ipb_reason', [
204  'tables' => [ 'comment_ipb_reason' => 'comment' ],
205  'fields' => [
206  'ipb_reason_text' => 'comment_ipb_reason.comment_text',
207  'ipb_reason_data' => 'comment_ipb_reason.comment_data',
208  'ipb_reason_cid' => 'comment_ipb_reason.comment_id',
209  ],
210  'joins' => [
211  'comment_ipb_reason' => [ 'JOIN', 'comment_ipb_reason.comment_id = ipb_reason_id' ],
212  ],
213  ],
214  ],
215 
216  'Revision, old' => [
217  MIGRATION_OLD, 'rev_comment', [
218  'tables' => [],
219  'fields' => [
220  'rev_comment_text' => 'rev_comment',
221  'rev_comment_data' => 'NULL',
222  'rev_comment_cid' => 'NULL',
223  ],
224  'joins' => [],
225  ],
226  ],
227  'Revision, write-both' => [
228  MIGRATION_WRITE_BOTH, 'rev_comment', [
229  'tables' => [
230  'temp_rev_comment' => 'revision_comment_temp',
231  'comment_rev_comment' => 'comment',
232  ],
233  'fields' => [
234  'rev_comment_text' => 'COALESCE( comment_rev_comment.comment_text, rev_comment )',
235  'rev_comment_data' => 'comment_rev_comment.comment_data',
236  'rev_comment_cid' => 'comment_rev_comment.comment_id',
237  ],
238  'joins' => [
239  'temp_rev_comment' => [ 'LEFT JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
240  'comment_rev_comment' => [ 'LEFT JOIN',
241  'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
242  ],
243  ],
244  ],
245  'Revision, write-new' => [
246  MIGRATION_WRITE_NEW, 'rev_comment', [
247  'tables' => [
248  'temp_rev_comment' => 'revision_comment_temp',
249  'comment_rev_comment' => 'comment',
250  ],
251  'fields' => [
252  'rev_comment_text' => 'COALESCE( comment_rev_comment.comment_text, rev_comment )',
253  'rev_comment_data' => 'comment_rev_comment.comment_data',
254  'rev_comment_cid' => 'comment_rev_comment.comment_id',
255  ],
256  'joins' => [
257  'temp_rev_comment' => [ 'LEFT JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
258  'comment_rev_comment' => [ 'LEFT JOIN',
259  'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
260  ],
261  ],
262  ],
263  'Revision, new' => [
264  MIGRATION_NEW, 'rev_comment', [
265  'tables' => [
266  'temp_rev_comment' => 'revision_comment_temp',
267  'comment_rev_comment' => 'comment',
268  ],
269  'fields' => [
270  'rev_comment_text' => 'comment_rev_comment.comment_text',
271  'rev_comment_data' => 'comment_rev_comment.comment_data',
272  'rev_comment_cid' => 'comment_rev_comment.comment_id',
273  ],
274  'joins' => [
275  'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
276  'comment_rev_comment' => [ 'JOIN',
277  'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
278  ],
279  ],
280  ],
281 
282  'Image, old' => [
283  MIGRATION_OLD, 'img_description', [
284  'tables' => [],
285  'fields' => [
286  'img_description_text' => 'img_description',
287  'img_description_data' => 'NULL',
288  'img_description_cid' => 'NULL',
289  ],
290  'joins' => [],
291  ],
292  ],
293  'Image, write-both' => [
294  MIGRATION_WRITE_BOTH, 'img_description', [
295  'tables' => [
296  'comment_img_description' => 'comment',
297  ],
298  'fields' => [
299  'img_description_text' => 'COALESCE( comment_img_description.comment_text, img_description )',
300  'img_description_data' => 'comment_img_description.comment_data',
301  'img_description_cid' => 'comment_img_description.comment_id',
302  ],
303  'joins' => [
304  'comment_img_description' => [ 'LEFT JOIN',
305  'comment_img_description.comment_id = img_description_id',
306  ],
307  ],
308  ],
309  ],
310  'Image, write-new' => [
311  MIGRATION_WRITE_NEW, 'img_description', [
312  'tables' => [
313  'comment_img_description' => 'comment',
314  ],
315  'fields' => [
316  'img_description_text' => 'COALESCE( comment_img_description.comment_text, img_description )',
317  'img_description_data' => 'comment_img_description.comment_data',
318  'img_description_cid' => 'comment_img_description.comment_id',
319  ],
320  'joins' => [
321  'comment_img_description' => [ 'LEFT JOIN',
322  'comment_img_description.comment_id = img_description_id',
323  ],
324  ],
325  ],
326  ],
327  'Image, new' => [
328  MIGRATION_NEW, 'img_description', [
329  'tables' => [
330  'comment_img_description' => 'comment',
331  ],
332  'fields' => [
333  'img_description_text' => 'comment_img_description.comment_text',
334  'img_description_data' => 'comment_img_description.comment_data',
335  'img_description_cid' => 'comment_img_description.comment_id',
336  ],
337  'joins' => [
338  'comment_img_description' => [ 'JOIN',
339  'comment_img_description.comment_id = img_description_id',
340  ],
341  ],
342  ],
343  ],
344  ];
345  }
346 
347  private function assertComment( $expect, $actual, $from ) {
348  $this->assertSame( $expect['text'], $actual->text, "text $from" );
349  $this->assertInstanceOf( get_class( $expect['message'] ), $actual->message,
350  "message class $from" );
351  $this->assertSame( $expect['message']->getKeysToTry(), $actual->message->getKeysToTry(),
352  "message keys $from" );
353  $this->assertEquals( $expect['message']->text(), $actual->message->text(),
354  "message rendering $from" );
355  $this->assertEquals( $expect['data'], $actual->data, "data $from" );
356  }
357 
368  public function testInsertRoundTrip( $table, $key, $pk, $extraFields, $comment, $data, $expect ) {
369  $expectOld = [
370  'text' => $expect['text'],
371  'message' => new RawMessage( '$1', [ $expect['text'] ] ),
372  'data' => null,
373  ];
374 
375  $stages = [
378  MIGRATION_NEW ],
381  ];
382 
383  foreach ( $stages as $writeStage => $possibleReadStages ) {
384  if ( $key === 'ipb_reason' ) {
385  $extraFields['ipb_address'] = __CLASS__ . "#$writeStage";
386  }
387 
388  $wstore = $this->makeStore( $writeStage );
389  $usesTemp = $key === 'rev_comment';
390 
391  if ( $usesTemp ) {
392  list( $fields, $callback ) = $wstore->insertWithTempTable(
393  $this->db, $key, $comment, $data
394  );
395  } else {
396  $fields = $wstore->insert( $this->db, $key, $comment, $data );
397  }
398 
399  if ( $writeStage <= MIGRATION_WRITE_BOTH ) {
400  $this->assertSame( $expect['text'], $fields[$key], "old field, stage=$writeStage" );
401  } else {
402  $this->assertArrayNotHasKey( $key, $fields, "old field, stage=$writeStage" );
403  }
404  if ( $writeStage >= MIGRATION_WRITE_BOTH && !$usesTemp ) {
405  $this->assertArrayHasKey( "{$key}_id", $fields, "new field, stage=$writeStage" );
406  } else {
407  $this->assertArrayNotHasKey( "{$key}_id", $fields, "new field, stage=$writeStage" );
408  }
409 
410  $this->db->insert( $table, $extraFields + $fields, __METHOD__ );
411  $id = $this->db->insertId();
412  if ( $usesTemp ) {
413  $callback( $id );
414  }
415 
416  foreach ( $possibleReadStages as $readStage ) {
417  $rstore = $this->makeStore( $readStage );
418 
419  $fieldRow = $this->db->selectRow(
420  $table,
421  $rstore->getFields( $key ),
422  [ $pk => $id ],
423  __METHOD__
424  );
425 
426  $queryInfo = $rstore->getJoin( $key );
427  $joinRow = $this->db->selectRow(
428  [ $table ] + $queryInfo['tables'],
429  $queryInfo['fields'],
430  [ $pk => $id ],
431  __METHOD__,
432  [],
433  $queryInfo['joins']
434  );
435 
436  $this->assertComment(
437  $writeStage === MIGRATION_OLD || $readStage === MIGRATION_OLD ? $expectOld : $expect,
438  $rstore->getCommentLegacy( $this->db, $key, $fieldRow ),
439  "w=$writeStage, r=$readStage, from getFields()"
440  );
441  $this->assertComment(
442  $writeStage === MIGRATION_OLD || $readStage === MIGRATION_OLD ? $expectOld : $expect,
443  $rstore->getComment( $key, $joinRow ),
444  "w=$writeStage, r=$readStage, from getJoin()"
445  );
446  }
447  }
448  }
449 
461  $table, $key, $pk, $extraFields, $comment, $data, $expect
462  ) {
463  $expectOld = [
464  'text' => $expect['text'],
465  'message' => new RawMessage( '$1', [ $expect['text'] ] ),
466  'data' => null,
467  ];
468 
469  $stages = [
472  MIGRATION_NEW ],
475  ];
476 
477  foreach ( $stages as $writeStage => $possibleReadStages ) {
478  if ( $key === 'ipb_reason' ) {
479  $extraFields['ipb_address'] = __CLASS__ . "#$writeStage";
480  }
481 
482  $wstore = $this->makeStoreWithKey( $writeStage, $key );
483  $usesTemp = $key === 'rev_comment';
484 
485  if ( $usesTemp ) {
486  list( $fields, $callback ) = $wstore->insertWithTempTable(
487  $this->db, $comment, $data
488  );
489  } else {
490  $fields = $wstore->insert( $this->db, $comment, $data );
491  }
492 
493  if ( $writeStage <= MIGRATION_WRITE_BOTH ) {
494  $this->assertSame( $expect['text'], $fields[$key], "old field, stage=$writeStage" );
495  } else {
496  $this->assertArrayNotHasKey( $key, $fields, "old field, stage=$writeStage" );
497  }
498  if ( $writeStage >= MIGRATION_WRITE_BOTH && !$usesTemp ) {
499  $this->assertArrayHasKey( "{$key}_id", $fields, "new field, stage=$writeStage" );
500  } else {
501  $this->assertArrayNotHasKey( "{$key}_id", $fields, "new field, stage=$writeStage" );
502  }
503 
504  $this->db->insert( $table, $extraFields + $fields, __METHOD__ );
505  $id = $this->db->insertId();
506  if ( $usesTemp ) {
507  $callback( $id );
508  }
509 
510  foreach ( $possibleReadStages as $readStage ) {
511  $rstore = $this->makeStoreWithKey( $readStage, $key );
512 
513  $fieldRow = $this->db->selectRow(
514  $table,
515  $rstore->getFields(),
516  [ $pk => $id ],
517  __METHOD__
518  );
519 
520  $queryInfo = $rstore->getJoin();
521  $joinRow = $this->db->selectRow(
522  [ $table ] + $queryInfo['tables'],
523  $queryInfo['fields'],
524  [ $pk => $id ],
525  __METHOD__,
526  [],
527  $queryInfo['joins']
528  );
529 
530  $this->assertComment(
531  $writeStage === MIGRATION_OLD || $readStage === MIGRATION_OLD ? $expectOld : $expect,
532  $rstore->getCommentLegacy( $this->db, $fieldRow ),
533  "w=$writeStage, r=$readStage, from getFields()"
534  );
535  $this->assertComment(
536  $writeStage === MIGRATION_OLD || $readStage === MIGRATION_OLD ? $expectOld : $expect,
537  $rstore->getComment( $joinRow ),
538  "w=$writeStage, r=$readStage, from getJoin()"
539  );
540  }
541  }
542  }
543 
544  public static function provideInsertRoundTrip() {
545  $db = wfGetDB( DB_REPLICA ); // for timestamps
546 
547  $msgComment = new Message( 'parentheses', [ 'message comment' ] );
548  $textCommentMsg = new RawMessage( '$1', [ 'text comment' ] );
549  $nestedMsgComment = new Message( [ 'parentheses', 'rawmessage' ], [ new Message( 'mainpage' ) ] );
550  $ipbfields = [
551  'ipb_range_start' => '',
552  'ipb_range_end' => '',
553  'ipb_timestamp' => $db->timestamp(),
554  'ipb_expiry' => $db->getInfinity(),
555  ];
556  $revfields = [
557  'rev_page' => 42,
558  'rev_text_id' => 42,
559  'rev_len' => 0,
560  'rev_timestamp' => $db->timestamp(),
561  ];
562  $comStoreComment = new CommentStoreComment(
563  null, 'comment store comment', null, [ 'foo' => 'bar' ]
564  );
565 
566  return [
567  'Simple table, text comment' => [
568  'ipblocks', 'ipb_reason', 'ipb_id', $ipbfields, 'text comment', null, [
569  'text' => 'text comment',
570  'message' => $textCommentMsg,
571  'data' => null,
572  ]
573  ],
574  'Simple table, text comment with data' => [
575  'ipblocks', 'ipb_reason', 'ipb_id', $ipbfields, 'text comment', [ 'message' => 42 ], [
576  'text' => 'text comment',
577  'message' => $textCommentMsg,
578  'data' => [ 'message' => 42 ],
579  ]
580  ],
581  'Simple table, message comment' => [
582  'ipblocks', 'ipb_reason', 'ipb_id', $ipbfields, $msgComment, null, [
583  'text' => '(message comment)',
584  'message' => $msgComment,
585  'data' => null,
586  ]
587  ],
588  'Simple table, message comment with data' => [
589  'ipblocks', 'ipb_reason', 'ipb_id', $ipbfields, $msgComment, [ 'message' => 42 ], [
590  'text' => '(message comment)',
591  'message' => $msgComment,
592  'data' => [ 'message' => 42 ],
593  ]
594  ],
595  'Simple table, nested message comment' => [
596  'ipblocks', 'ipb_reason', 'ipb_id', $ipbfields, $nestedMsgComment, null, [
597  'text' => '(Main Page)',
598  'message' => $nestedMsgComment,
599  'data' => null,
600  ]
601  ],
602  'Simple table, CommentStoreComment' => [
603  'ipblocks', 'ipb_reason', 'ipb_id', $ipbfields, clone $comStoreComment, [ 'baz' => 'baz' ], [
604  'text' => 'comment store comment',
605  'message' => $comStoreComment->message,
606  'data' => [ 'foo' => 'bar' ],
607  ]
608  ],
609 
610  'Revision, text comment' => [
611  'revision', 'rev_comment', 'rev_id', $revfields, 'text comment', null, [
612  'text' => 'text comment',
613  'message' => $textCommentMsg,
614  'data' => null,
615  ]
616  ],
617  'Revision, text comment with data' => [
618  'revision', 'rev_comment', 'rev_id', $revfields, 'text comment', [ 'message' => 42 ], [
619  'text' => 'text comment',
620  'message' => $textCommentMsg,
621  'data' => [ 'message' => 42 ],
622  ]
623  ],
624  'Revision, message comment' => [
625  'revision', 'rev_comment', 'rev_id', $revfields, $msgComment, null, [
626  'text' => '(message comment)',
627  'message' => $msgComment,
628  'data' => null,
629  ]
630  ],
631  'Revision, message comment with data' => [
632  'revision', 'rev_comment', 'rev_id', $revfields, $msgComment, [ 'message' => 42 ], [
633  'text' => '(message comment)',
634  'message' => $msgComment,
635  'data' => [ 'message' => 42 ],
636  ]
637  ],
638  'Revision, nested message comment' => [
639  'revision', 'rev_comment', 'rev_id', $revfields, $nestedMsgComment, null, [
640  'text' => '(Main Page)',
641  'message' => $nestedMsgComment,
642  'data' => null,
643  ]
644  ],
645  'Revision, CommentStoreComment' => [
646  'revision', 'rev_comment', 'rev_id', $revfields, clone $comStoreComment, [ 'baz' => 'baz' ], [
647  'text' => 'comment store comment',
648  'message' => $comStoreComment->message,
649  'data' => [ 'foo' => 'bar' ],
650  ]
651  ],
652  ];
653  }
654 
655  public function testGetCommentErrors() {
656  Wikimedia\suppressWarnings();
657  $reset = new ScopedCallback( 'Wikimedia\restoreWarnings' );
658 
659  $store = $this->makeStore( MIGRATION_OLD );
660  $res = $store->getComment( 'dummy', [ 'dummy' => 'comment' ] );
661  $this->assertSame( '', $res->text );
662  $res = $store->getComment( 'dummy', [ 'dummy' => 'comment' ], true );
663  $this->assertSame( 'comment', $res->text );
664 
665  $store = $this->makeStore( MIGRATION_NEW );
666  try {
667  $store->getComment( 'dummy', [ 'dummy' => 'comment' ] );
668  $this->fail( 'Expected exception not thrown' );
669  } catch ( InvalidArgumentException $ex ) {
670  $this->assertSame( '$row does not contain fields needed for comment dummy', $ex->getMessage() );
671  }
672  $res = $store->getComment( 'dummy', [ 'dummy' => 'comment' ], true );
673  $this->assertSame( 'comment', $res->text );
674  try {
675  $store->getComment( 'dummy', [ 'dummy_id' => 1 ] );
676  $this->fail( 'Expected exception not thrown' );
677  } catch ( InvalidArgumentException $ex ) {
678  $this->assertSame(
679  '$row does not contain fields needed for comment dummy and getComment(), '
680  . 'but does have fields for getCommentLegacy()',
681  $ex->getMessage()
682  );
683  }
684 
685  $store = $this->makeStore( MIGRATION_NEW );
686  try {
687  $store->getComment( 'rev_comment', [ 'rev_comment' => 'comment' ] );
688  $this->fail( 'Expected exception not thrown' );
689  } catch ( InvalidArgumentException $ex ) {
690  $this->assertSame(
691  '$row does not contain fields needed for comment rev_comment', $ex->getMessage()
692  );
693  }
694  $res = $store->getComment( 'rev_comment', [ 'rev_comment' => 'comment' ], true );
695  $this->assertSame( 'comment', $res->text );
696  try {
697  $store->getComment( 'rev_comment', [ 'rev_comment_pk' => 1 ] );
698  $this->fail( 'Expected exception not thrown' );
699  } catch ( InvalidArgumentException $ex ) {
700  $this->assertSame(
701  '$row does not contain fields needed for comment rev_comment and getComment(), '
702  . 'but does have fields for getCommentLegacy()',
703  $ex->getMessage()
704  );
705  }
706  }
707 
708  public static function provideStages() {
709  return [
710  'MIGRATION_OLD' => [ MIGRATION_OLD ],
711  'MIGRATION_WRITE_BOTH' => [ MIGRATION_WRITE_BOTH ],
712  'MIGRATION_WRITE_NEW' => [ MIGRATION_WRITE_NEW ],
713  'MIGRATION_NEW' => [ MIGRATION_NEW ],
714  ];
715  }
716 
723  public function testInsertWrong( $stage ) {
724  $store = $this->makeStore( $stage );
725  $store->insert( $this->db, 'rev_comment', 'foo' );
726  }
727 
734  public function testInsertWithTempTableWrong( $stage ) {
735  $store = $this->makeStore( $stage );
736  $store->insertWithTempTable( $this->db, 'ipb_reason', 'foo' );
737  }
738 
743  public function testInsertWithTempTableDeprecated( $stage ) {
744  $store = $this->makeStore( $stage );
745  $wrap = TestingAccessWrapper::newFromObject( $store );
746  $wrap->tempTables += [ 'ipb_reason' => [
747  'stage' => MIGRATION_NEW,
748  'deprecatedIn' => '1.30',
749  ] ];
750 
751  $this->hideDeprecated( 'CommentStore::insertWithTempTable for ipb_reason' );
752  list( $fields, $callback ) = $store->insertWithTempTable( $this->db, 'ipb_reason', 'foo' );
753  $this->assertTrue( is_callable( $callback ) );
754  }
755 
756  public function testInsertTruncation() {
757  $comment = str_repeat( '💣', 16400 );
758  $truncated1 = str_repeat( '💣', 63 ) . '...';
759  $truncated2 = str_repeat( '💣', CommentStore::COMMENT_CHARACTER_LIMIT - 3 ) . '...';
760 
761  $store = $this->makeStore( MIGRATION_WRITE_BOTH );
762  $fields = $store->insert( $this->db, 'ipb_reason', $comment );
763  $this->assertSame( $truncated1, $fields['ipb_reason'] );
764  $stored = $this->db->selectField(
765  'comment', 'comment_text', [ 'comment_id' => $fields['ipb_reason_id'] ], __METHOD__
766  );
767  $this->assertSame( $truncated2, $stored );
768  }
769 
774  public function testInsertTooMuchData() {
775  $store = $this->makeStore( MIGRATION_WRITE_BOTH );
776  $store->insert( $this->db, 'ipb_reason', 'foo', [
777  'long' => str_repeat( '💣', 16400 )
778  ] );
779  }
780 
781  public function testGetStore() {
782  $this->assertInstanceOf( CommentStore::class, CommentStore::getStore() );
783  }
784 
785  public function testNewKey() {
786  $this->hideDeprecated( 'CommentStore::newKey' );
787  $this->assertInstanceOf( CommentStore::class, CommentStore::newKey( 'dummy' ) );
788  }
789 
790 }
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED since 1.16! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:2042
CommentStoreTest\testGetJoin_withKeyConstruction
testGetJoin_withKeyConstruction( $stage, $key, $expect)
provideGetJoin
Definition: CommentStoreTest.php:145
MIGRATION_NEW
const MIGRATION_NEW
Definition: Defines.php:318
CommentStore
CommentStore handles storage of comments (edit summaries, log reasons, etc) in the database.
Definition: CommentStore.php:31
MIGRATION_WRITE_BOTH
const MIGRATION_WRITE_BOTH
Definition: Defines.php:316
CommentStoreTest\testGetFields
testGetFields( $stage, $key, $expect)
provideGetFields
Definition: CommentStoreTest.php:62
$res
$res
Definition: database.txt:21
CommentStore\newKey
static newKey( $key)
Static constructor for easier chaining.
Definition: CommentStore.php:111
CommentStoreTest\testInsertWithTempTableDeprecated
testInsertWithTempTableDeprecated( $stage)
provideStages
Definition: CommentStoreTest.php:743
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
MIGRATION_WRITE_NEW
const MIGRATION_WRITE_NEW
Definition: Defines.php:317
CommentStoreTest\assertComment
assertComment( $expect, $actual, $from)
Definition: CommentStoreTest.php:347
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2693
MediaWikiTestCase\hideDeprecated
hideDeprecated( $function)
Don't throw a warning if $function is deprecated and called later.
Definition: MediaWikiTestCase.php:1940
CommentStoreTest\testGetCommentErrors
testGetCommentErrors()
Definition: CommentStoreTest.php:655
CommentStoreTest\$tablesUsed
$tablesUsed
Definition: CommentStoreTest.php:14
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
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
CommentStoreTest\testGetStore
testGetStore()
Definition: CommentStoreTest.php:781
CommentStoreTest\makeStoreWithKey
makeStoreWithKey( $stage, $key)
Create a store for a particular stage and key (for testing deprecated behaviour)
Definition: CommentStoreTest.php:37
CommentStoreTest\provideGetJoin
static provideGetJoin()
Definition: CommentStoreTest.php:163
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
MIGRATION_OLD
const MIGRATION_OLD
Definition: Defines.php:315
CommentStoreTest\makeStore
makeStore( $stage)
Create a store for a particular stage.
Definition: CommentStoreTest.php:26
CommentStoreTest\testInsertTruncation
testInsertTruncation()
Definition: CommentStoreTest.php:756
CommentStoreTest\testNewKey
testNewKey()
Definition: CommentStoreTest.php:785
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:8
CommentStoreTest\testInsertWithTempTableWrong
testInsertWithTempTableWrong( $stage)
provideStages
Definition: CommentStoreTest.php:734
CommentStoreTest\testGetJoin
testGetJoin( $stage, $key, $expect)
provideGetJoin
Definition: CommentStoreTest.php:157
CommentStore\COMMENT_CHARACTER_LIMIT
const COMMENT_CHARACTER_LIMIT
Maximum length of a comment in UTF-8 characters.
Definition: CommentStore.php:37
text
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
Definition: All_system_messages.txt:1267
CommentStoreTest\provideInsertRoundTrip
static provideInsertRoundTrip()
Definition: CommentStoreTest.php:544
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
CommentStoreTest\testInsertRoundTrip_withKeyConstruction
testInsertRoundTrip_withKeyConstruction( $table, $key, $pk, $extraFields, $comment, $data, $expect)
provideInsertRoundTrip
Definition: CommentStoreTest.php:460
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
CommentStoreTest
Database CommentStore CommentStoreComment.
Definition: CommentStoreTest.php:12
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
CommentStoreTest\provideStages
static provideStages()
Definition: CommentStoreTest.php:708
RawMessage
Variant of the Message class.
Definition: RawMessage.php:34
CommentStore\getStore
static getStore()
Definition: CommentStore.php:125
CommentStoreTest\testGetFields_withKeyConstruction
testGetFields_withKeyConstruction( $stage, $key, $expect)
provideGetFields
Definition: CommentStoreTest.php:50
CommentStoreTest\provideGetFields
static provideGetFields()
Definition: CommentStoreTest.php:68
CommentStoreTest\testInsertTooMuchData
testInsertTooMuchData()
OverflowException Comment data is too long (65611 bytes, maximum is 65535)
Definition: CommentStoreTest.php:774
CommentStoreComment
CommentStoreComment represents a comment stored by CommentStore.
Definition: CommentStoreComment.php:29
CommentStoreTest\testInsertWrong
testInsertWrong( $stage)
provideStages
Definition: CommentStoreTest.php:723
MediaWikiTestCase\$db
Database $db
Primary database.
Definition: MediaWikiTestCase.php:60
CommentStoreTest\testInsertRoundTrip
testInsertRoundTrip( $table, $key, $pk, $extraFields, $comment, $data, $expect)
provideInsertRoundTrip
Definition: CommentStoreTest.php:368