MediaWiki  master
RevisionQueryInfoTest.php
Go to the documentation of this file.
1 <?php
2 
4 
9 
18 
19  protected function getRevisionQueryFields( $returnTextIdField = true ) {
20  $fields = [
21  'rev_id',
22  'rev_page',
23  'rev_timestamp',
24  'rev_minor_edit',
25  'rev_deleted',
26  'rev_len',
27  'rev_parent_id',
28  'rev_sha1',
29  ];
30  if ( $returnTextIdField ) {
31  $fields[] = 'rev_text_id';
32  }
33  return $fields;
34  }
35 
36  protected function getArchiveQueryFields( $returnTextFields = true ) {
37  $fields = [
38  'ar_id',
39  'ar_page_id',
40  'ar_namespace',
41  'ar_title',
42  'ar_rev_id',
43  'ar_timestamp',
44  'ar_minor_edit',
45  'ar_deleted',
46  'ar_len',
47  'ar_parent_id',
48  'ar_sha1',
49  ];
50  if ( $returnTextFields ) {
51  $fields[] = 'ar_text_id';
52  }
53  return $fields;
54  }
55 
56  protected function getNewCommentQueryFields( $prefix ) {
57  return [
58  "{$prefix}_comment_text" => "comment_{$prefix}_comment.comment_text",
59  "{$prefix}_comment_data" => "comment_{$prefix}_comment.comment_data",
60  "{$prefix}_comment_cid" => "comment_{$prefix}_comment.comment_id",
61  ];
62  }
63 
64  protected function getOldActorQueryFields( $prefix ) {
65  return [
66  "{$prefix}_user" => "{$prefix}_user",
67  "{$prefix}_user_text" => "{$prefix}_user_text",
68  "{$prefix}_actor" => 'NULL',
69  ];
70  }
71 
72  protected function getNewActorQueryFields( $prefix, $tmp = false ) {
73  return [
74  "{$prefix}_user" => "actor_{$prefix}_user.actor_user",
75  "{$prefix}_user_text" => "actor_{$prefix}_user.actor_name",
76  "{$prefix}_actor" => $tmp ?: "{$prefix}_actor",
77  ];
78  }
79 
80  protected function getNewActorJoins( $prefix ) {
81  return [
82  "temp_{$prefix}_user" => [
83  "JOIN",
84  "temp_{$prefix}_user.revactor_{$prefix} = {$prefix}_id",
85  ],
86  "actor_{$prefix}_user" => [
87  "JOIN",
88  "actor_{$prefix}_user.actor_id = temp_{$prefix}_user.revactor_actor",
89  ],
90  ];
91  }
92 
93  protected function getTextQueryFields() {
94  return [
95  'old_text',
96  'old_flags',
97  ];
98  }
99 
100  protected function getPageQueryFields() {
101  return [
102  'page_namespace',
103  'page_title',
104  'page_id',
105  'page_latest',
106  'page_is_redirect',
107  'page_len',
108  ];
109  }
110 
111  protected function getUserQueryFields() {
112  return [
113  'user_name',
114  ];
115  }
116 
117  protected function getContentHandlerQueryFields( $prefix ) {
118  return [
119  "{$prefix}_content_format",
120  "{$prefix}_content_model",
121  ];
122  }
123 
124  public function provideArchiveQueryInfo() {
125  yield 'MCR, comment, actor' => [
126  [
127  'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW,
128  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW,
129  ],
130  [
131  'tables' => [
132  'archive',
133  'actor_ar_user' => 'actor',
134  'comment_ar_comment' => 'comment',
135  ],
136  'fields' => array_merge(
137  $this->getArchiveQueryFields( false ),
138  $this->getNewActorQueryFields( 'ar' ),
139  $this->getNewCommentQueryFields( 'ar' )
140  ),
141  'joins' => [
142  'comment_ar_comment'
143  => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
144  'actor_ar_user' => [ 'JOIN', 'actor_ar_user.actor_id = ar_actor' ],
145  ],
146  ]
147  ];
148  yield 'read-new MCR, comment, actor' => [
149  [
150  'wgContentHandlerUseDB' => true,
151  'wgMultiContentRevisionSchemaMigrationStage'
153  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW,
154  ],
155  [
156  'tables' => [
157  'archive',
158  'actor_ar_user' => 'actor',
159  'comment_ar_comment' => 'comment',
160  ],
161  'fields' => array_merge(
162  $this->getArchiveQueryFields( false ),
163  $this->getNewActorQueryFields( 'ar' ),
164  $this->getNewCommentQueryFields( 'ar' )
165  ),
166  'joins' => [
167  'comment_ar_comment'
168  => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
169  'actor_ar_user' => [ 'JOIN', 'actor_ar_user.actor_id = ar_actor' ],
170  ],
171  ]
172  ];
173  yield 'MCR write-both/read-old' => [
174  [
175  'wgContentHandlerUseDB' => true,
176  'wgMultiContentRevisionSchemaMigrationStage'
178  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD,
179  ],
180  [
181  'tables' => [
182  'archive',
183  'comment_ar_comment' => 'comment',
184  ],
185  'fields' => array_merge(
186  $this->getArchiveQueryFields( true ),
187  $this->getContentHandlerQueryFields( 'ar' ),
188  $this->getOldActorQueryFields( 'ar' ),
189  $this->getNewCommentQueryFields( 'ar' )
190  ),
191  'joins' => [
192  'comment_ar_comment'
193  => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
194  ],
195  ]
196  ];
197  yield 'pre-MCR, no model' => [
198  [
199  'wgContentHandlerUseDB' => false,
200  'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
201  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
202  ],
203  [
204  'tables' => [
205  'archive',
206  'comment_ar_comment' => 'comment',
207  ],
208  'fields' => array_merge(
209  $this->getArchiveQueryFields( true ),
210  $this->getOldActorQueryFields( 'ar' ),
211  $this->getNewCommentQueryFields( 'ar' )
212  ),
213  'joins' => [
214  'comment_ar_comment'
215  => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
216  ],
217  ]
218  ];
219  }
220 
221  public function provideQueryInfo() {
222  // TODO: more option variations
223  yield 'MCR, page, user, comment, actor' => [
224  [
225  'wgContentHandlerUseDB' => true,
226  'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW,
227  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW,
228  ],
229  [ 'page', 'user' ],
230  [
231  'tables' => [
232  'revision',
233  'page',
234  'user',
235  'temp_rev_user' => 'revision_actor_temp',
236  'temp_rev_comment' => 'revision_comment_temp',
237  'actor_rev_user' => 'actor',
238  'comment_rev_comment' => 'comment',
239  ],
240  'fields' => array_merge(
241  $this->getRevisionQueryFields( false ),
242  $this->getPageQueryFields(),
243  $this->getUserQueryFields(),
244  $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
245  $this->getNewCommentQueryFields( 'rev' )
246  ),
247  'joins' => [
248  'page' => [ 'JOIN', [ 'page_id = rev_page' ] ],
249  'user' => [
250  'LEFT JOIN',
251  [ 'actor_rev_user.actor_user != 0', 'user_id = actor_rev_user.actor_user' ],
252  ],
253  'comment_rev_comment' => [
254  'JOIN',
255  'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
256  ],
257  'actor_rev_user' => [
258  'JOIN',
259  'actor_rev_user.actor_id = temp_rev_user.revactor_actor',
260  ],
261  'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
262  'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
263  ],
264  ]
265  ];
266  yield 'MCR read-new, page, user, comment, actor' => [
267  [
268  'wgContentHandlerUseDB' => true,
269  'wgMultiContentRevisionSchemaMigrationStage'
271  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW,
272  ],
273  [ 'page', 'user' ],
274  [
275  'tables' => [
276  'revision',
277  'page',
278  'user',
279  'temp_rev_user' => 'revision_actor_temp',
280  'temp_rev_comment' => 'revision_comment_temp',
281  'actor_rev_user' => 'actor',
282  'comment_rev_comment' => 'comment',
283  ],
284  'fields' => array_merge(
285  $this->getRevisionQueryFields( false ),
286  $this->getPageQueryFields(),
287  $this->getUserQueryFields(),
288  $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
289  $this->getNewCommentQueryFields( 'rev' )
290  ),
291  'joins' => array_merge(
292  [
293  'page' => [ 'JOIN', [ 'page_id = rev_page' ] ],
294  'user' => [
295  'LEFT JOIN',
296  [
297  'actor_rev_user.actor_user != 0',
298  'user_id = actor_rev_user.actor_user',
299  ]
300  ],
301  'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
302  'comment_rev_comment'
303  => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
304  ],
305  $this->getNewActorJoins( 'rev' )
306  ),
307  ]
308  ];
309  yield 'MCR read-new' => [
310  [
311  'wgContentHandlerUseDB' => true,
312  'wgMultiContentRevisionSchemaMigrationStage'
314  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW,
315  ],
316  [ 'page', 'user' ],
317  [
318  'tables' => [
319  'revision',
320  'page',
321  'user',
322  'temp_rev_user' => 'revision_actor_temp',
323  'temp_rev_comment' => 'revision_comment_temp',
324  'actor_rev_user' => 'actor',
325  'comment_rev_comment' => 'comment',
326  ],
327  'fields' => array_merge(
328  $this->getRevisionQueryFields( false ),
329  $this->getPageQueryFields(),
330  $this->getUserQueryFields(),
331  $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
332  $this->getNewCommentQueryFields( 'rev' )
333  ),
334  'joins' => array_merge(
335  [
336  'page' => [ 'JOIN', [ 'page_id = rev_page' ] ],
337  'user' => [
338  'LEFT JOIN',
339  [
340  'actor_rev_user.actor_user != 0',
341  'user_id = actor_rev_user.actor_user'
342  ]
343  ],
344  'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
345  'comment_rev_comment'
346  => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
347  ],
348  $this->getNewActorJoins( 'rev' )
349  ),
350  ]
351  ];
352  yield 'MCR write-both/read-old' => [
353  [
354  'wgContentHandlerUseDB' => true,
355  'wgMultiContentRevisionSchemaMigrationStage'
357  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD,
358  ],
359  [],
360  [
361  'tables' => [
362  'revision',
363  'temp_rev_comment' => 'revision_comment_temp',
364  'comment_rev_comment' => 'comment',
365  ],
366  'fields' => array_merge(
367  $this->getRevisionQueryFields( true ),
368  $this->getContentHandlerQueryFields( 'rev' ),
369  $this->getOldActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
370  $this->getNewCommentQueryFields( 'rev' )
371  ),
372  'joins' => [
373  'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
374  'comment_rev_comment'
375  => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
376  ],
377  ]
378  ];
379  yield 'MCR write-both/read-old, page, user' => [
380  [
381  'wgContentHandlerUseDB' => true,
382  'wgMultiContentRevisionSchemaMigrationStage'
384  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD,
385  ],
386  [ 'page', 'user' ],
387  [
388  'tables' => [
389  'revision',
390  'page',
391  'user',
392  'temp_rev_comment' => 'revision_comment_temp',
393  'comment_rev_comment' => 'comment',
394  ],
395  'fields' => array_merge(
396  $this->getRevisionQueryFields( true ),
397  $this->getContentHandlerQueryFields( 'rev' ),
398  $this->getUserQueryFields(),
399  $this->getPageQueryFields(),
400  $this->getOldActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
401  $this->getNewCommentQueryFields( 'rev' )
402  ),
403  'joins' => array_merge(
404  [
405  'page' => [ 'JOIN', [ 'page_id = rev_page' ] ],
406  'user' => [
407  'LEFT JOIN',
408  [
409  'rev_user != 0',
410  'user_id = rev_user'
411  ]
412  ],
413  'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
414  'comment_rev_comment'
415  => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
416  ]
417  ),
418  ]
419  ];
420  yield 'pre-MCR' => [
421  [
422  'wgContentHandlerUseDB' => true,
423  'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
424  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
425  ],
426  [],
427  [
428  'tables' => [
429  'revision',
430  'temp_rev_comment' => 'revision_comment_temp',
431  'comment_rev_comment' => 'comment',
432  ],
433  'fields' => array_merge(
434  $this->getRevisionQueryFields( true ),
435  $this->getContentHandlerQueryFields( 'rev' ),
436  $this->getOldActorQueryFields( 'rev' ),
437  $this->getNewCommentQueryFields( 'rev' )
438  ),
439  'joins' => [
440  'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
441  'comment_rev_comment'
442  => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
443  ],
444  ]
445  ];
446  yield 'pre-MCR, page, user' => [
447  [
448  'wgContentHandlerUseDB' => true,
449  'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
450  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
451  ],
452  [ 'page', 'user' ],
453  [
454  'tables' => [
455  'revision', 'page', 'user',
456  'temp_rev_comment' => 'revision_comment_temp',
457  'comment_rev_comment' => 'comment',
458  ],
459  'fields' => array_merge(
460  $this->getRevisionQueryFields( true ),
461  $this->getContentHandlerQueryFields( 'rev' ),
462  $this->getPageQueryFields(),
463  $this->getUserQueryFields(),
464  $this->getOldActorQueryFields( 'rev' ),
465  $this->getNewCommentQueryFields( 'rev' )
466  ),
467  'joins' => [
468  'page' => [ 'JOIN', [ 'page_id = rev_page' ] ],
469  'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
470  'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
471  'comment_rev_comment'
472  => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
473  ],
474  ]
475  ];
476  yield 'pre-MCR, no model' => [
477  [
478  'wgContentHandlerUseDB' => false,
479  'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
480  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
481  ],
482  [],
483  [
484  'tables' => [
485  'revision',
486  'temp_rev_comment' => 'revision_comment_temp',
487  'comment_rev_comment' => 'comment',
488  ],
489  'fields' => array_merge(
490  $this->getRevisionQueryFields( true ),
491  $this->getOldActorQueryFields( 'rev' ),
492  $this->getNewCommentQueryFields( 'rev' )
493  ),
494  'joins' => [
495  'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
496  'comment_rev_comment'
497  => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
498  ],
499  ],
500  ];
501  yield 'pre-MCR, no model, page' => [
502  [
503  'wgContentHandlerUseDB' => false,
504  'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
505  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
506  ],
507  [ 'page' ],
508  [
509  'tables' => [
510  'revision', 'page',
511  'temp_rev_comment' => 'revision_comment_temp',
512  'comment_rev_comment' => 'comment',
513  ],
514  'fields' => array_merge(
515  $this->getRevisionQueryFields( true ),
516  $this->getPageQueryFields(),
517  $this->getOldActorQueryFields( 'rev' ),
518  $this->getNewCommentQueryFields( 'rev' )
519  ),
520  'joins' => [
521  'page' => [ 'JOIN', [ 'page_id = rev_page' ], ],
522  'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
523  'comment_rev_comment'
524  => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
525  ],
526  ],
527  ];
528  yield 'pre-MCR, no model, user' => [
529  [
530  'wgContentHandlerUseDB' => false,
531  'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
532  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
533  ],
534  [ 'user' ],
535  [
536  'tables' => [
537  'revision', 'user',
538  'temp_rev_comment' => 'revision_comment_temp',
539  'comment_rev_comment' => 'comment',
540  ],
541  'fields' => array_merge(
542  $this->getRevisionQueryFields( true ),
543  $this->getUserQueryFields(),
544  $this->getOldActorQueryFields( 'rev' ),
545  $this->getNewCommentQueryFields( 'rev' )
546  ),
547  'joins' => [
548  'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
549  'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
550  'comment_rev_comment'
551  => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
552  ],
553  ],
554  ];
555  yield 'pre-MCR, no model, text' => [
556  [
557  'wgContentHandlerUseDB' => false,
558  'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
559  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
560  ],
561  [ 'text' ],
562  [
563  'tables' => [
564  'revision', 'text',
565  'temp_rev_comment' => 'revision_comment_temp',
566  'comment_rev_comment' => 'comment',
567  ],
568  'fields' => array_merge(
569  $this->getRevisionQueryFields( true ),
570  $this->getTextQueryFields(),
571  $this->getOldActorQueryFields( 'rev' ),
572  $this->getNewCommentQueryFields( 'rev' )
573  ),
574  'joins' => [
575  'text' => [ 'JOIN', [ 'rev_text_id=old_id' ] ],
576  'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
577  'comment_rev_comment'
578  => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
579  ],
580  ],
581  ];
582  yield 'pre-MCR, no model, text, page, user' => [
583  [
584  'wgContentHandlerUseDB' => false,
585  'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
586  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
587  ],
588  [ 'text', 'page', 'user' ],
589  [
590  'tables' => [
591  'revision', 'page', 'user', 'text',
592  'temp_rev_comment' => 'revision_comment_temp',
593  'comment_rev_comment' => 'comment',
594  ],
595  'fields' => array_merge(
596  $this->getRevisionQueryFields( true ),
597  $this->getPageQueryFields(),
598  $this->getUserQueryFields(),
599  $this->getTextQueryFields(),
600  $this->getOldActorQueryFields( 'rev' ),
601  $this->getNewCommentQueryFields( 'rev' )
602  ),
603  'joins' => [
604  'page' => [
605  'JOIN',
606  [ 'page_id = rev_page' ],
607  ],
608  'user' => [
609  'LEFT JOIN',
610  [
611  'rev_user != 0',
612  'user_id = rev_user',
613  ],
614  ],
615  'text' => [
616  'JOIN',
617  [ 'rev_text_id=old_id' ],
618  ],
619  'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
620  'comment_rev_comment'
621  => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
622  ],
623  ],
624  ];
625  }
626 
627  public function provideSlotsQueryInfo() {
628  yield 'MCR, no options' => [
629  [
630  'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW,
631  ],
632  [],
633  [
634  'tables' => [
635  'slots'
636  ],
637  'fields' => [
638  'slot_revision_id',
639  'slot_content_id',
640  'slot_origin',
641  'slot_role_id',
642  ],
643  'joins' => [],
644  ]
645  ];
646  yield 'MCR, role option' => [
647  [
648  'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW,
649  ],
650  [ 'role' ],
651  [
652  'tables' => [
653  'slots',
654  'slot_roles',
655  ],
656  'fields' => [
657  'slot_revision_id',
658  'slot_content_id',
659  'slot_origin',
660  'slot_role_id',
661  'role_name',
662  ],
663  'joins' => [
664  'slot_roles' => [ 'LEFT JOIN', [ 'slot_role_id = role_id' ] ],
665  ],
666  ]
667  ];
668  yield 'MCR read-new, content option' => [
669  [
670  'wgMultiContentRevisionSchemaMigrationStage'
672  ],
673  [ 'content' ],
674  [
675  'tables' => [
676  'slots',
677  'content',
678  ],
679  'fields' => [
680  'slot_revision_id',
681  'slot_content_id',
682  'slot_origin',
683  'slot_role_id',
684  'content_size',
685  'content_sha1',
686  'content_address',
687  'content_model',
688  ],
689  'joins' => [
690  'content' => [ 'JOIN', [ 'slot_content_id = content_id' ] ],
691  ],
692  ]
693  ];
694  yield 'MCR read-new, content and model options' => [
695  [
696  'wgMultiContentRevisionSchemaMigrationStage'
698  ],
699  [ 'content', 'model' ],
700  [
701  'tables' => [
702  'slots',
703  'content',
704  'content_models',
705  ],
706  'fields' => [
707  'slot_revision_id',
708  'slot_content_id',
709  'slot_origin',
710  'slot_role_id',
711  'content_size',
712  'content_sha1',
713  'content_address',
714  'content_model',
715  'model_name',
716  ],
717  'joins' => [
718  'content' => [ 'JOIN', [ 'slot_content_id = content_id' ] ],
719  'content_models' => [ 'LEFT JOIN', [ 'content_model = model_id' ] ],
720  ],
721  ]
722  ];
723 
724  $db = wfGetDB( DB_REPLICA );
725 
726  yield 'MCR write-both/read-old' => [
727  [
728  'wgMultiContentRevisionSchemaMigrationStage'
730  ],
731  [],
732  [
733  'tables' => [
734  'revision',
735  ],
736  'fields' => array_merge(
737  [
738  'slot_revision_id' => 'rev_id',
739  'slot_content_id' => 'NULL',
740  'slot_origin' => 'rev_id',
741  'role_name' => $db->addQuotes( SlotRecord::MAIN ),
742  ]
743  ),
744  'joins' => [],
745  ]
746  ];
747  yield 'MCR write-both/read-old, content' => [
748  [
749  'wgMultiContentRevisionSchemaMigrationStage'
751  ],
752  [ 'content' ],
753  [
754  'tables' => [
755  'revision',
756  ],
757  'fields' => array_merge(
758  [
759  'slot_revision_id' => 'rev_id',
760  'slot_content_id' => 'NULL',
761  'slot_origin' => 'rev_id',
762  'role_name' => $db->addQuotes( SlotRecord::MAIN ),
763  'content_size' => 'rev_len',
764  'content_sha1' => 'rev_sha1',
765  'content_address' => $db->buildConcat( [
766  $db->addQuotes( 'tt:' ), 'rev_text_id' ] ),
767  'rev_text_id' => 'rev_text_id',
768  'model_name' => 'rev_content_model',
769  ]
770  ),
771  'joins' => [],
772  ]
773  ];
774  yield 'MCR write-both/read-old, content, model, role' => [
775  [
776  'wgMultiContentRevisionSchemaMigrationStage'
778  ],
779  [ 'content', 'model', 'role' ],
780  [
781  'tables' => [
782  'revision',
783  ],
784  'fields' => array_merge(
785  [
786  'slot_revision_id' => 'rev_id',
787  'slot_content_id' => 'NULL',
788  'slot_origin' => 'rev_id',
789  'role_name' => $db->addQuotes( SlotRecord::MAIN ),
790  'content_size' => 'rev_len',
791  'content_sha1' => 'rev_sha1',
792  'content_address' => $db->buildConcat( [
793  $db->addQuotes( 'tt:' ), 'rev_text_id' ] ),
794  'rev_text_id' => 'rev_text_id',
795  'model_name' => 'rev_content_model',
796  ]
797  ),
798  'joins' => [],
799  ]
800  ];
801  yield 'pre-MCR' => [
802  [
803  'wgMultiContentRevisionSchemaMigrationStage'
805  ],
806  [],
807  [
808  'tables' => [
809  'revision',
810  ],
811  'fields' => array_merge(
812  [
813  'slot_revision_id' => 'rev_id',
814  'slot_content_id' => 'NULL',
815  'slot_origin' => 'rev_id',
816  'role_name' => $db->addQuotes( SlotRecord::MAIN ),
817  ]
818  ),
819  'joins' => [],
820  ]
821  ];
822  yield 'pre-MCR, content' => [
823  [
824  'wgMultiContentRevisionSchemaMigrationStage'
826  ],
827  [ 'content' ],
828  [
829  'tables' => [
830  'revision',
831  ],
832  'fields' => array_merge(
833  [
834  'slot_revision_id' => 'rev_id',
835  'slot_content_id' => 'NULL',
836  'slot_origin' => 'rev_id',
837  'role_name' => $db->addQuotes( SlotRecord::MAIN ),
838  'content_size' => 'rev_len',
839  'content_sha1' => 'rev_sha1',
840  'content_address' =>
841  $db->buildConcat( [ $db->addQuotes( 'tt:' ), 'rev_text_id' ] ),
842  'rev_text_id' => 'rev_text_id',
843  'model_name' => 'rev_content_model',
844  ]
845  ),
846  'joins' => [],
847  ]
848  ];
849  }
850 
851  public function provideSelectFields() {
852  yield 'with model, comment, and actor' => [
853  [
854  'wgContentHandlerUseDB' => true,
855  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD,
856  ],
857  'fields' => array_merge(
858  [
859  'rev_id',
860  'rev_page',
861  'rev_text_id',
862  'rev_timestamp',
863  'rev_user_text',
864  'rev_user',
865  'rev_actor' => 'NULL',
866  'rev_minor_edit',
867  'rev_deleted',
868  'rev_len',
869  'rev_parent_id',
870  'rev_sha1',
871  ],
872  $this->getContentHandlerQueryFields( 'rev' ),
873  [
874  'rev_comment_pk' => 'rev_id',
875  ]
876  ),
877  ];
878  yield 'no mode, no comment, no actor' => [
879  [
880  'wgContentHandlerUseDB' => false,
881  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
882  ],
883  'fields' => array_merge(
884  [
885  'rev_id',
886  'rev_page',
887  'rev_text_id',
888  'rev_timestamp',
889  'rev_user_text',
890  'rev_user',
891  'rev_actor' => 'NULL',
892  'rev_minor_edit',
893  'rev_deleted',
894  'rev_len',
895  'rev_parent_id',
896  'rev_sha1',
897  'rev_comment_pk' => 'rev_id',
898  ]
899  ),
900  ];
901  }
902 
903  public function provideSelectArchiveFields() {
904  yield 'with model, comment, and actor' => [
905  [
906  'wgContentHandlerUseDB' => true,
907  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD,
908  ],
909  'fields' => array_merge(
910  [
911  'ar_id',
912  'ar_page_id',
913  'ar_rev_id',
914  'ar_text_id',
915  'ar_timestamp',
916  'ar_user_text',
917  'ar_user',
918  'ar_actor' => 'NULL',
919  'ar_minor_edit',
920  'ar_deleted',
921  'ar_len',
922  'ar_parent_id',
923  'ar_sha1',
924  ],
925  $this->getContentHandlerQueryFields( 'ar' ),
926  [
927  'ar_comment_id' => 'ar_comment_id',
928  ]
929  ),
930  ];
931  yield 'no mode, no comment, no actor' => [
932  [
933  'wgContentHandlerUseDB' => false,
934  'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD,
935  ],
936  'fields' => array_merge(
937  [
938  'ar_id',
939  'ar_page_id',
940  'ar_rev_id',
941  'ar_text_id',
942  'ar_timestamp',
943  'ar_user_text',
944  'ar_user',
945  'ar_actor' => 'NULL',
946  'ar_minor_edit',
947  'ar_deleted',
948  'ar_len',
949  'ar_parent_id',
950  'ar_sha1',
951  'ar_comment_id' => 'ar_comment_id',
952  ]
953  ),
954  ];
955  }
956 
961  public function testRevisionSelectFields( $migrationStageSettings, $expected ) {
962  $this->setMwGlobals( $migrationStageSettings );
963  $this->overrideMwServices();
964 
965  $this->hideDeprecated( 'Revision::selectFields' );
967  }
968 
973  public function testRevisionSelectArchiveFields( $migrationStageSettings, $expected ) {
974  $this->setMwGlobals( $migrationStageSettings );
975  $this->overrideMwServices();
976 
977  $this->hideDeprecated( 'Revision::selectArchiveFields' );
979  }
980 
984  public function testRevisionUserJoinCond() {
985  $this->hideDeprecated( 'Revision::userJoinCond' );
986  $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_OLD );
987  $this->overrideMwServices();
988  $this->assertEquals(
989  [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
991  );
992  }
993 
997  public function testRevisionPageJoinCond() {
998  $this->hideDeprecated( 'Revision::pageJoinCond' );
999  $this->assertEquals(
1000  [ 'JOIN', [ 'page_id = rev_page' ] ],
1002  );
1003  }
1004 
1008  public function testRevisionSelectTextFields() {
1009  $this->hideDeprecated( 'Revision::selectTextFields' );
1010  $this->assertEquals(
1011  $this->getTextQueryFields(),
1013  );
1014  }
1015 
1019  public function testRevisionSelectPageFields() {
1020  $this->hideDeprecated( 'Revision::selectPageFields' );
1021  $this->assertEquals(
1022  $this->getPageQueryFields(),
1024  );
1025  }
1026 
1030  public function testRevisionSelectUserFields() {
1031  $this->hideDeprecated( 'Revision::selectUserFields' );
1032  $this->assertEquals(
1033  $this->getUserQueryFields(),
1035  );
1036  }
1037 
1042  public function testRevisionGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
1043  $this->setMwGlobals( $migrationStageSettings );
1044  $this->overrideMwServices();
1045 
1046  $queryInfo = Revision::getArchiveQueryInfo();
1047  $this->assertQueryInfoEquals( $expected, $queryInfo );
1048  }
1049 
1054  public function testRevisionGetQueryInfo( $migrationStageSettings, $options, $expected ) {
1055  $this->setMwGlobals( $migrationStageSettings );
1056  $this->overrideMwServices();
1057 
1058  $queryInfo = Revision::getQueryInfo( $options );
1059  $this->assertQueryInfoEquals( $expected, $queryInfo );
1060  }
1061 
1066  public function testRevisionStoreGetQueryInfo( $migrationStageSettings, $options, $expected ) {
1067  $this->setMwGlobals( $migrationStageSettings );
1068  $this->overrideMwServices();
1069 
1070  $store = MediaWikiServices::getInstance()->getRevisionStore();
1071 
1072  $queryInfo = $store->getQueryInfo( $options );
1073  $this->assertQueryInfoEquals( $expected, $queryInfo );
1074  }
1075 
1081  $migrationStageSettings,
1082  $options,
1083  $expected
1084  ) {
1085  $this->setMwGlobals( $migrationStageSettings );
1086  $this->overrideMwServices();
1087 
1088  $store = MediaWikiServices::getInstance()->getRevisionStore();
1089 
1090  $queryInfo = $store->getSlotsQueryInfo( $options );
1091  $this->assertQueryInfoEquals( $expected, $queryInfo );
1092  }
1093 
1098  public function testRevisionStoreGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
1099  $this->setMwGlobals( $migrationStageSettings );
1100  $this->overrideMwServices();
1101 
1102  $store = MediaWikiServices::getInstance()->getRevisionStore();
1103 
1104  $queryInfo = $store->getArchiveQueryInfo();
1105  $this->assertQueryInfoEquals( $expected, $queryInfo );
1106  }
1107 
1108  private function assertQueryInfoEquals( $expected, $queryInfo ) {
1110  $expected['tables'],
1111  $queryInfo['tables'],
1112  'tables'
1113  );
1115  $expected['fields'],
1116  $queryInfo['fields'],
1117  'fields'
1118  );
1120  $expected['joins'],
1121  $queryInfo['joins'],
1122  'joins'
1123  );
1124  }
1125 
1137  array $expected,
1138  array $actual,
1139  $message = null
1140  ) {
1141  $this->objectAssociativeSort( $expected );
1142  $this->objectAssociativeSort( $actual );
1143 
1144  // Separate the int key values from the string key values so that assertion failures are
1145  // easier to understand.
1146  $expectedIntKeyValues = [];
1147  $actualIntKeyValues = [];
1148 
1149  // Remove all int keys and re add them at the end after sorting by value
1150  // This will result in all int keys being in the same order with same ints at the end of
1151  // the array
1152  foreach ( $expected as $key => $value ) {
1153  if ( is_int( $key ) ) {
1154  unset( $expected[$key] );
1155  $expectedIntKeyValues[] = $value;
1156  }
1157  }
1158  foreach ( $actual as $key => $value ) {
1159  if ( is_int( $key ) ) {
1160  unset( $actual[$key] );
1161  $actualIntKeyValues[] = $value;
1162  }
1163  }
1164 
1165  $this->objectAssociativeSort( $expected );
1166  $this->objectAssociativeSort( $actual );
1167 
1168  $this->objectAssociativeSort( $expectedIntKeyValues );
1169  $this->objectAssociativeSort( $actualIntKeyValues );
1170 
1171  $this->assertEquals( $expected, $actual, $message );
1172  $this->assertEquals( $expectedIntKeyValues, $actualIntKeyValues, $message );
1173  }
1174 
1175 }
testRevisionSelectArchiveFields( $migrationStageSettings, $expected)
provideSelectArchiveFields Revision::selectArchiveFields
testRevisionStoreGetQueryInfo( $migrationStageSettings, $options, $expected)
provideQueryInfo \MediaWiki\Revision\RevisionStore::getQueryInfo
testRevisionGetQueryInfo( $migrationStageSettings, $options, $expected)
Revision::getQueryInfo provideQueryInfo.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
testRevisionSelectPageFields()
Revision::selectPageFields.
testRevisionSelectUserFields()
Revision::selectUserFields.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
$value
const SCHEMA_COMPAT_READ_NEW
Definition: Defines.php:267
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
static selectArchiveFields()
Return the list of revision fields that should be selected to create a new revision from an archive r...
Definition: Revision.php:402
static getInstance()
Returns the global default instance of the top level service locator.
testRevisionSelectTextFields()
Revision::selectTextFields.
assertArrayEqualsIgnoringIntKeyOrder(array $expected, array $actual, $message=null)
Assert that the two arrays passed are equal, ignoring the order of the values that integer keys...
testRevisionStoreGetSlotsQueryInfo( $migrationStageSettings, $options, $expected)
provideSlotsQueryInfo \MediaWiki\Revision\RevisionStore::getSlotsQueryInfo
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 & $options
Definition: hooks.txt:1972
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
Definition: Revision.php:342
static selectTextFields()
Return the list of text fields that should be selected to read the revision text. ...
Definition: Revision.php:462
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
static getArchiveQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new archived revision objec...
Definition: Revision.php:525
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object...
Definition: Revision.php:511
testRevisionStoreGetArchiveQueryInfo( $migrationStageSettings, $expected)
provideArchiveQueryInfo \MediaWiki\Revision\RevisionStore::getArchiveQueryInfo
testRevisionSelectFields( $migrationStageSettings, $expected)
provideSelectFields Revision::selectFields
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
const SCHEMA_COMPAT_WRITE_BOTH
Definition: Defines.php:268
testRevisionGetArchiveQueryInfo( $migrationStageSettings, $expected)
Revision::getArchiveQueryInfo provideArchiveQueryInfo.
static pageJoinCond()
Return the value of a select() page conds array for the page table.
Definition: Revision.php:331
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
const SCHEMA_COMPAT_NEW
Definition: Defines.php:271
Tests RevisionStore against the post-migration MCR DB schema.
static selectPageFields()
Return the list of page fields that should be selected from page table.
Definition: Revision.php:475
const DB_REPLICA
Definition: defines.php:25
const SCHEMA_COMPAT_READ_OLD
Definition: Defines.php:265
static userJoinCond()
Return the value of a select() JOIN conds array for the user table.
Definition: Revision.php:307
const SCHEMA_COMPAT_OLD
Definition: Defines.php:270
static selectUserFields()
Return the list of user fields that should be selected from user table.
Definition: Revision.php:492