MediaWiki  1.33.0
ChangeTagsTest.php
Go to the documentation of this file.
1 <?php
2 
4 
10 
11  public function setUp() {
12  parent::setUp();
13 
14  $this->tablesUsed[] = 'change_tag';
15  $this->tablesUsed[] = 'change_tag_def';
16 
17  // Truncate these to avoid the supposed-to-be-unused IDs in tests here turning
18  // out to be used, leading ChangeTags::updateTags() to pick up bogus rc_id,
19  // log_id, or rev_id values and run into unique constraint violations.
20  $this->tablesUsed[] = 'recentchanges';
21  $this->tablesUsed[] = 'logging';
22  $this->tablesUsed[] = 'revision';
23  $this->tablesUsed[] = 'archive';
24  }
25 
26  // TODO only modifyDisplayQuery and getSoftwareTags are tested, nothing else is
27 
29  public function testModifyDisplayQuery( $origQuery, $filter_tag, $useTags, $modifiedQuery ) {
30  $this->setMwGlobals( 'wgUseTagFilter', $useTags );
31  $rcId = 123;
32  ChangeTags::updateTags( [ 'foo', 'bar' ], [], $rcId );
33  // HACK resolve deferred group concats (see comment in provideModifyDisplayQuery)
34  if ( isset( $modifiedQuery['fields']['ts_tags'] ) ) {
35  $modifiedQuery['fields']['ts_tags'] = call_user_func_array(
36  [ wfGetDB( DB_REPLICA ), 'buildGroupConcatField' ],
37  $modifiedQuery['fields']['ts_tags']
38  );
39  }
40  if ( isset( $modifiedQuery['exception'] ) ) {
41  $this->setExpectedException( $modifiedQuery['exception'] );
42  }
44  $origQuery['tables'],
45  $origQuery['fields'],
46  $origQuery['conds'],
47  $origQuery['join_conds'],
48  $origQuery['options'],
49  $filter_tag
50  );
51  if ( !isset( $modifiedQuery['exception'] ) ) {
52  $this->assertArrayEquals(
53  $modifiedQuery,
54  $origQuery,
55  /* ordered = */ false,
56  /* named = */ true
57  );
58  }
59  }
60 
61  public function provideModifyDisplayQuery() {
62  // HACK if we call $dbr->buildGroupConcatField() now, it will return the wrong table names
63  // We have to have the test runner call it instead
64  $baseConcats = [ ',', [ 'change_tag', 'change_tag_def' ], 'ctd_name' ];
65  $joinConds = [ 'change_tag_def' => [ 'JOIN', 'ct_tag_id=ctd_id' ] ];
66  $groupConcats = [
67  'recentchanges' => array_merge( $baseConcats, [ 'ct_rc_id=rc_id', $joinConds ] ),
68  'logging' => array_merge( $baseConcats, [ 'ct_log_id=log_id', $joinConds ] ),
69  'revision' => array_merge( $baseConcats, [ 'ct_rev_id=rev_id', $joinConds ] ),
70  'archive' => array_merge( $baseConcats, [ 'ct_rev_id=ar_rev_id', $joinConds ] ),
71  ];
72 
73  return [
74  'simple recentchanges query' => [
75  [
76  'tables' => [ 'recentchanges' ],
77  'fields' => [ 'rc_id', 'rc_timestamp' ],
78  'conds' => [ "rc_timestamp > '20170714183203'" ],
79  'join_conds' => [],
80  'options' => [ 'ORDER BY' => 'rc_timestamp DESC' ],
81  ],
82  '', // no tag filter
83  true, // tag filtering enabled
84  [
85  'tables' => [ 'recentchanges' ],
86  'fields' => [ 'rc_id', 'rc_timestamp', 'ts_tags' => $groupConcats['recentchanges'] ],
87  'conds' => [ "rc_timestamp > '20170714183203'" ],
88  'join_conds' => [],
89  'options' => [ 'ORDER BY' => 'rc_timestamp DESC' ],
90  ]
91  ],
92  'simple query with strings' => [
93  [
94  'tables' => 'recentchanges',
95  'fields' => 'rc_id',
96  'conds' => "rc_timestamp > '20170714183203'",
97  'join_conds' => [],
98  'options' => 'ORDER BY rc_timestamp DESC',
99  ],
100  '', // no tag filter
101  true, // tag filtering enabled
102  [
103  'tables' => [ 'recentchanges' ],
104  'fields' => [ 'rc_id', 'ts_tags' => $groupConcats['recentchanges'] ],
105  'conds' => [ "rc_timestamp > '20170714183203'" ],
106  'join_conds' => [],
107  'options' => [ 'ORDER BY rc_timestamp DESC' ],
108  ]
109  ],
110  'recentchanges query with single tag filter' => [
111  [
112  'tables' => [ 'recentchanges' ],
113  'fields' => [ 'rc_id', 'rc_timestamp' ],
114  'conds' => [ "rc_timestamp > '20170714183203'" ],
115  'join_conds' => [],
116  'options' => [ 'ORDER BY' => 'rc_timestamp DESC' ],
117  ],
118  'foo',
119  true, // tag filtering enabled
120  [
121  'tables' => [ 'recentchanges', 'change_tag' ],
122  'fields' => [ 'rc_id', 'rc_timestamp', 'ts_tags' => $groupConcats['recentchanges'] ],
123  'conds' => [ "rc_timestamp > '20170714183203'", 'ct_tag_id' => [ 1 ] ],
124  'join_conds' => [ 'change_tag' => [ 'JOIN', 'ct_rc_id=rc_id' ] ],
125  'options' => [ 'ORDER BY' => 'rc_timestamp DESC' ],
126  ]
127  ],
128  'logging query with single tag filter and strings' => [
129  [
130  'tables' => 'logging',
131  'fields' => 'log_id',
132  'conds' => "log_timestamp > '20170714183203'",
133  'join_conds' => [],
134  'options' => 'ORDER BY log_timestamp DESC',
135  ],
136  'foo',
137  true, // tag filtering enabled
138  [
139  'tables' => [ 'logging', 'change_tag' ],
140  'fields' => [ 'log_id', 'ts_tags' => $groupConcats['logging'] ],
141  'conds' => [ "log_timestamp > '20170714183203'", 'ct_tag_id' => [ 1 ] ],
142  'join_conds' => [ 'change_tag' => [ 'JOIN', 'ct_log_id=log_id' ] ],
143  'options' => [ 'ORDER BY log_timestamp DESC' ],
144  ]
145  ],
146  'revision query with single tag filter' => [
147  [
148  'tables' => [ 'revision' ],
149  'fields' => [ 'rev_id', 'rev_timestamp' ],
150  'conds' => [ "rev_timestamp > '20170714183203'" ],
151  'join_conds' => [],
152  'options' => [ 'ORDER BY' => 'rev_timestamp DESC' ],
153  ],
154  'foo',
155  true, // tag filtering enabled
156  [
157  'tables' => [ 'revision', 'change_tag' ],
158  'fields' => [ 'rev_id', 'rev_timestamp', 'ts_tags' => $groupConcats['revision'] ],
159  'conds' => [ "rev_timestamp > '20170714183203'", 'ct_tag_id' => [ 1 ] ],
160  'join_conds' => [ 'change_tag' => [ 'JOIN', 'ct_rev_id=rev_id' ] ],
161  'options' => [ 'ORDER BY' => 'rev_timestamp DESC' ],
162  ]
163  ],
164  'archive query with single tag filter' => [
165  [
166  'tables' => [ 'archive' ],
167  'fields' => [ 'ar_id', 'ar_timestamp' ],
168  'conds' => [ "ar_timestamp > '20170714183203'" ],
169  'join_conds' => [],
170  'options' => [ 'ORDER BY' => 'ar_timestamp DESC' ],
171  ],
172  'foo',
173  true, // tag filtering enabled
174  [
175  'tables' => [ 'archive', 'change_tag' ],
176  'fields' => [ 'ar_id', 'ar_timestamp', 'ts_tags' => $groupConcats['archive'] ],
177  'conds' => [ "ar_timestamp > '20170714183203'", 'ct_tag_id' => [ 1 ] ],
178  'join_conds' => [ 'change_tag' => [ 'JOIN', 'ct_rev_id=ar_rev_id' ] ],
179  'options' => [ 'ORDER BY' => 'ar_timestamp DESC' ],
180  ]
181  ],
182  'unsupported table name throws exception (even without tag filter)' => [
183  [
184  'tables' => [ 'foobar' ],
185  'fields' => [ 'fb_id', 'fb_timestamp' ],
186  'conds' => [ "fb_timestamp > '20170714183203'" ],
187  'join_conds' => [],
188  'options' => [ 'ORDER BY' => 'fb_timestamp DESC' ],
189  ],
190  '',
191  true, // tag filtering enabled
192  [ 'exception' => MWException::class ]
193  ],
194  'tag filter ignored when tag filtering is disabled' => [
195  [
196  'tables' => [ 'archive' ],
197  'fields' => [ 'ar_id', 'ar_timestamp' ],
198  'conds' => [ "ar_timestamp > '20170714183203'" ],
199  'join_conds' => [],
200  'options' => [ 'ORDER BY' => 'ar_timestamp DESC' ],
201  ],
202  'foo',
203  false, // tag filtering disabled
204  [
205  'tables' => [ 'archive' ],
206  'fields' => [ 'ar_id', 'ar_timestamp', 'ts_tags' => $groupConcats['archive'] ],
207  'conds' => [ "ar_timestamp > '20170714183203'" ],
208  'join_conds' => [],
209  'options' => [ 'ORDER BY' => 'ar_timestamp DESC' ],
210  ]
211  ],
212  'recentchanges query with multiple tag filter' => [
213  [
214  'tables' => [ 'recentchanges' ],
215  'fields' => [ 'rc_id', 'rc_timestamp' ],
216  'conds' => [ "rc_timestamp > '20170714183203'" ],
217  'join_conds' => [],
218  'options' => [ 'ORDER BY' => 'rc_timestamp DESC' ],
219  ],
220  [ 'foo', 'bar' ],
221  true, // tag filtering enabled
222  [
223  'tables' => [ 'recentchanges', 'change_tag' ],
224  'fields' => [ 'rc_id', 'rc_timestamp', 'ts_tags' => $groupConcats['recentchanges'] ],
225  'conds' => [ "rc_timestamp > '20170714183203'", 'ct_tag_id' => [ 1, 2 ] ],
226  'join_conds' => [ 'change_tag' => [ 'JOIN', 'ct_rc_id=rc_id' ] ],
227  'options' => [ 'ORDER BY' => 'rc_timestamp DESC', 'DISTINCT' ],
228  ]
229  ],
230  'recentchanges query with multiple tag filter that already has DISTINCT' => [
231  [
232  'tables' => [ 'recentchanges' ],
233  'fields' => [ 'rc_id', 'rc_timestamp' ],
234  'conds' => [ "rc_timestamp > '20170714183203'" ],
235  'join_conds' => [],
236  'options' => [ 'DISTINCT', 'ORDER BY' => 'rc_timestamp DESC' ],
237  ],
238  [ 'foo', 'bar' ],
239  true, // tag filtering enabled
240  [
241  'tables' => [ 'recentchanges', 'change_tag' ],
242  'fields' => [ 'rc_id', 'rc_timestamp', 'ts_tags' => $groupConcats['recentchanges'] ],
243  'conds' => [ "rc_timestamp > '20170714183203'", 'ct_tag_id' => [ 1, 2 ] ],
244  'join_conds' => [ 'change_tag' => [ 'JOIN', 'ct_rc_id=rc_id' ] ],
245  'options' => [ 'DISTINCT', 'ORDER BY' => 'rc_timestamp DESC' ],
246  ]
247  ],
248  'recentchanges query with multiple tag filter with strings' => [
249  [
250  'tables' => 'recentchanges',
251  'fields' => 'rc_id',
252  'conds' => "rc_timestamp > '20170714183203'",
253  'join_conds' => [],
254  'options' => 'ORDER BY rc_timestamp DESC',
255  ],
256  [ 'foo', 'bar' ],
257  true, // tag filtering enabled
258  [
259  'tables' => [ 'recentchanges', 'change_tag' ],
260  'fields' => [ 'rc_id', 'ts_tags' => $groupConcats['recentchanges'] ],
261  'conds' => [ "rc_timestamp > '20170714183203'", 'ct_tag_id' => [ 1, 2 ] ],
262  'join_conds' => [ 'change_tag' => [ 'JOIN', 'ct_rc_id=rc_id' ] ],
263  'options' => [ 'ORDER BY rc_timestamp DESC', 'DISTINCT' ],
264  ]
265  ],
266  ];
267  }
268 
269  public static function dataGetSoftwareTags() {
270  return [
271  [
272  [
273  'mw-contentModelChange' => true,
274  'mw-redirect' => true,
275  'mw-rollback' => true,
276  'mw-blank' => true,
277  'mw-replace' => true
278  ],
279  [
280  'mw-rollback',
281  'mw-replace',
282  'mw-blank'
283  ]
284  ],
285 
286  [
287  [
288  'mw-contentmodelchanged' => true,
289  'mw-replace' => true,
290  'mw-new-redirects' => true,
291  'mw-changed-redirect-target' => true,
292  'mw-rolback' => true,
293  'mw-blanking' => false
294  ],
295  [
296  'mw-replace',
297  'mw-changed-redirect-target'
298  ]
299  ],
300 
301  [
302  [
303  null,
304  false,
305  'Lorem ipsum',
306  'mw-translation'
307  ],
308  []
309  ],
310 
311  [
312  [],
313  []
314  ]
315  ];
316  }
317 
322  public function testGetSoftwareTags( $softwareTags, $expected ) {
323  $this->setMwGlobals( 'wgSoftwareTags', $softwareTags );
324 
325  $actual = ChangeTags::getSoftwareTags();
326  // Order of tags in arrays is not important
327  sort( $expected );
328  sort( $actual );
329  $this->assertEquals( $expected, $actual );
330  }
331 
332  public function testUpdateTags() {
333  // FIXME: fails under postgres
334  $this->markTestSkippedIfDbType( 'postgres' );
335 
336  $dbw = wfGetDB( DB_MASTER );
337  $dbw->delete( 'change_tag', '*' );
338  $dbw->delete( 'change_tag_def', '*' );
339 
340  $rcId = 123;
341  $revId = 341;
342  ChangeTags::updateTags( [ 'tag1', 'tag2' ], [], $rcId, $revId );
343 
344  $dbr = wfGetDB( DB_REPLICA );
345 
346  $expected = [
347  (object)[
348  'ctd_name' => 'tag1',
349  'ctd_id' => 1,
350  'ctd_count' => 1
351  ],
352  (object)[
353  'ctd_name' => 'tag2',
354  'ctd_id' => 2,
355  'ctd_count' => 1
356  ],
357  ];
358  $res = $dbr->select( 'change_tag_def', [ 'ctd_name', 'ctd_id', 'ctd_count' ], '' );
359  $this->assertEquals( $expected, iterator_to_array( $res, false ) );
360 
361  $expected2 = [
362  (object)[
363  'ct_tag_id' => 1,
364  'ct_rc_id' => 123,
365  'ct_rev_id' => 341
366  ],
367  (object)[
368  'ct_tag_id' => 2,
369  'ct_rc_id' => 123,
370  'ct_rev_id' => 341
371  ],
372  ];
373  $res2 = $dbr->select( 'change_tag', [ 'ct_tag_id', 'ct_rc_id', 'ct_rev_id' ], '' );
374  $this->assertEquals( $expected2, iterator_to_array( $res2, false ) );
375 
376  $rcId = 124;
377  $revId = 342;
378  ChangeTags::updateTags( [ 'tag1' ], [], $rcId, $revId );
379  ChangeTags::updateTags( [ 'tag3' ], [], $rcId, $revId );
380 
381  $dbr = wfGetDB( DB_REPLICA );
382 
383  $expected = [
384  (object)[
385  'ctd_name' => 'tag1',
386  'ctd_id' => 1,
387  'ctd_count' => 2
388  ],
389  (object)[
390  'ctd_name' => 'tag2',
391  'ctd_id' => 2,
392  'ctd_count' => 1
393  ],
394  (object)[
395  'ctd_name' => 'tag3',
396  'ctd_id' => 3,
397  'ctd_count' => 1
398  ],
399  ];
400  $res = $dbr->select( 'change_tag_def', [ 'ctd_name', 'ctd_id', 'ctd_count' ], '' );
401  $this->assertEquals( $expected, iterator_to_array( $res, false ) );
402 
403  $expected2 = [
404  (object)[
405  'ct_tag_id' => 1,
406  'ct_rc_id' => 123,
407  'ct_rev_id' => 341
408  ],
409  (object)[
410  'ct_tag_id' => 1,
411  'ct_rc_id' => 124,
412  'ct_rev_id' => 342
413  ],
414  (object)[
415  'ct_tag_id' => 2,
416  'ct_rc_id' => 123,
417  'ct_rev_id' => 341
418  ],
419  (object)[
420  'ct_tag_id' => 3,
421  'ct_rc_id' => 124,
422  'ct_rev_id' => 342
423  ],
424  ];
425  $res2 = $dbr->select( 'change_tag', [ 'ct_tag_id', 'ct_rc_id', 'ct_rev_id' ], '' );
426  $this->assertEquals( $expected2, iterator_to_array( $res2, false ) );
427  }
428 
429  public function testUpdateTagsSkipDuplicates() {
430  // FIXME: fails under postgres
431  $this->markTestSkippedIfDbType( 'postgres' );
432 
433  $dbw = wfGetDB( DB_MASTER );
434  $dbw->delete( 'change_tag', '*' );
435  $dbw->delete( 'change_tag_def', '*' );
436 
437  $rcId = 123;
438  ChangeTags::updateTags( [ 'tag1', 'tag2' ], [], $rcId );
439  ChangeTags::updateTags( [ 'tag2', 'tag3' ], [], $rcId );
440 
441  $dbr = wfGetDB( DB_REPLICA );
442 
443  $expected = [
444  (object)[
445  'ctd_name' => 'tag1',
446  'ctd_id' => 1,
447  'ctd_count' => 1
448  ],
449  (object)[
450  'ctd_name' => 'tag2',
451  'ctd_id' => 2,
452  'ctd_count' => 1
453  ],
454  (object)[
455  'ctd_name' => 'tag3',
456  'ctd_id' => 3,
457  'ctd_count' => 1
458  ],
459  ];
460  $res = $dbr->select( 'change_tag_def', [ 'ctd_name', 'ctd_id', 'ctd_count' ], '' );
461  $this->assertEquals( $expected, iterator_to_array( $res, false ) );
462 
463  $expected2 = [
464  (object)[
465  'ct_tag_id' => 1,
466  'ct_rc_id' => 123
467  ],
468  (object)[
469  'ct_tag_id' => 2,
470  'ct_rc_id' => 123
471  ],
472  (object)[
473  'ct_tag_id' => 3,
474  'ct_rc_id' => 123
475  ],
476  ];
477  $res2 = $dbr->select( 'change_tag', [ 'ct_tag_id', 'ct_rc_id' ], '' );
478  $this->assertEquals( $expected2, iterator_to_array( $res2, false ) );
479  }
480 
482  // FIXME: fails under postgres
483  $this->markTestSkippedIfDbType( 'postgres' );
484 
485  $dbw = wfGetDB( DB_MASTER );
486  $dbw->delete( 'change_tag', '*' );
487  $dbw->delete( 'change_tag_def', '*' );
488 
489  $rcId = 123;
490  ChangeTags::updateTags( [ 'tag1', 'tag2' ], [], $rcId );
491  $res = ChangeTags::updateTags( [ 'tag2', 'tag1' ], [], $rcId );
492  $this->assertEquals( [ [], [], [ 'tag1', 'tag2' ] ], $res );
493 
494  $dbr = wfGetDB( DB_REPLICA );
495 
496  $expected = [
497  (object)[
498  'ctd_name' => 'tag1',
499  'ctd_id' => 1,
500  'ctd_count' => 1
501  ],
502  (object)[
503  'ctd_name' => 'tag2',
504  'ctd_id' => 2,
505  'ctd_count' => 1
506  ],
507  ];
508  $res = $dbr->select( 'change_tag_def', [ 'ctd_name', 'ctd_id', 'ctd_count' ], '' );
509  $this->assertEquals( $expected, iterator_to_array( $res, false ) );
510 
511  $expected2 = [
512  (object)[
513  'ct_tag_id' => 1,
514  'ct_rc_id' => 123
515  ],
516  (object)[
517  'ct_tag_id' => 2,
518  'ct_rc_id' => 123
519  ],
520  ];
521  $res2 = $dbr->select( 'change_tag', [ 'ct_tag_id', 'ct_rc_id' ], '' );
522  $this->assertEquals( $expected2, iterator_to_array( $res2, false ) );
523  }
524 
525  public function testDeleteTags() {
526  $dbw = wfGetDB( DB_MASTER );
527  $dbw->delete( 'change_tag', '*' );
528  $dbw->delete( 'change_tag_def', '*' );
529  MediaWikiServices::getInstance()->resetServiceForTesting( 'NameTableStoreFactory' );
530 
531  $rcId = 123;
532  ChangeTags::updateTags( [ 'tag1', 'tag2' ], [], $rcId );
533 
534  ChangeTags::updateTags( [], [ 'tag2' ], $rcId );
535 
536  $dbr = wfGetDB( DB_REPLICA );
537 
538  $expected = [
539  (object)[
540  'ctd_name' => 'tag1',
541  'ctd_id' => 1,
542  'ctd_count' => 1
543  ],
544  ];
545  $res = $dbr->select( 'change_tag_def', [ 'ctd_name', 'ctd_id', 'ctd_count' ], '' );
546  $this->assertEquals( $expected, iterator_to_array( $res, false ) );
547 
548  $expected2 = [
549  (object)[
550  'ct_tag_id' => 1,
551  'ct_rc_id' => 123
552  ]
553  ];
554  $res2 = $dbr->select( 'change_tag', [ 'ct_tag_id', 'ct_rc_id' ], '' );
555  $this->assertEquals( $expected2, iterator_to_array( $res2, false ) );
556  }
557 
558  public function testTagUsageStatistics() {
559  $dbw = wfGetDB( DB_MASTER );
560  $dbw->delete( 'change_tag', '*' );
561  $dbw->delete( 'change_tag_def', '*' );
562  MediaWikiServices::getInstance()->resetServiceForTesting( 'NameTableStoreFactory' );
563 
564  $rcId = 123;
565  ChangeTags::updateTags( [ 'tag1', 'tag2' ], [], $rcId );
566 
567  $rcId = 124;
568  ChangeTags::updateTags( [ 'tag1' ], [], $rcId );
569 
570  $this->assertEquals( [ 'tag1' => 2, 'tag2' => 1 ], ChangeTags::tagUsageStatistics() );
571  }
572 
573  public function testListExplicitlyDefinedTags() {
574  $dbw = wfGetDB( DB_MASTER );
575  $dbw->delete( 'change_tag', '*' );
576  $dbw->delete( 'change_tag_def', '*' );
577 
578  $rcId = 123;
579  ChangeTags::updateTags( [ 'tag1', 'tag2' ], [], $rcId );
580  ChangeTags::defineTag( 'tag2' );
581 
582  $this->assertEquals( [ 'tag2' ], ChangeTags::listExplicitlyDefinedTags() );
583  $dbr = wfGetDB( DB_REPLICA );
584 
585  $expected = [
586  (object)[
587  'ctd_name' => 'tag1',
588  'ctd_user_defined' => 0
589  ],
590  (object)[
591  'ctd_name' => 'tag2',
592  'ctd_user_defined' => 1
593  ],
594  ];
595  $res = $dbr->select(
596  'change_tag_def',
597  [ 'ctd_name', 'ctd_user_defined' ],
598  '',
599  __METHOD__,
600  [ 'ORDER BY' => 'ctd_name' ]
601  );
602  $this->assertEquals( $expected, iterator_to_array( $res, false ) );
603  }
604 }
MediaWikiTestCase\assertArrayEquals
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Definition: MediaWikiTestCase.php:2070
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
ChangeTagsTest
ChangeTags Database.
Definition: ChangeTagsTest.php:9
ChangeTagsTest\testDeleteTags
testDeleteTags()
Definition: ChangeTagsTest.php:525
ChangeTagsTest\testUpdateTagsSkipDuplicates
testUpdateTagsSkipDuplicates()
Definition: ChangeTagsTest.php:429
ChangeTagsTest\testUpdateTagsDoNothingOnRepeatedCall
testUpdateTagsDoNothingOnRepeatedCall()
Definition: ChangeTagsTest.php:481
ChangeTagsTest\provideModifyDisplayQuery
provideModifyDisplayQuery()
Definition: ChangeTagsTest.php:61
$res
$res
Definition: database.txt:21
ChangeTagsTest\testTagUsageStatistics
testTagUsageStatistics()
Definition: ChangeTagsTest.php:558
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
ChangeTagsTest\testListExplicitlyDefinedTags
testListExplicitlyDefinedTags()
Definition: ChangeTagsTest.php:573
$dbr
$dbr
Definition: testCompression.php:50
ChangeTags\modifyDisplayQuery
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:728
ChangeTagsTest\setUp
setUp()
Definition: ChangeTagsTest.php:11
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2636
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:709
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
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
ChangeTags\getSoftwareTags
static getSoftwareTags( $all=false)
Loads defined core tags, checks for invalid types (if not array), and filters for supported and enabl...
Definition: ChangeTags.php:57
ChangeTagsTest\testGetSoftwareTags
testGetSoftwareTags( $softwareTags, $expected)
dataGetSoftwareTags ChangeTags::getSoftwareTags
Definition: ChangeTagsTest.php:322
ChangeTags\defineTag
static defineTag( $tag)
Set ctd_user_defined = 1 in change_tag_def without checking that the tag name is valid.
Definition: ChangeTags.php:877
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
ChangeTagsTest\dataGetSoftwareTags
static dataGetSoftwareTags()
Definition: ChangeTagsTest.php:269
DB_MASTER
const DB_MASTER
Definition: defines.php:26
ChangeTagsTest\testUpdateTags
testUpdateTags()
Definition: ChangeTagsTest.php:332
ChangeTags\listExplicitlyDefinedTags
static listExplicitlyDefinedTags()
Lists tags explicitly defined in the change_tag_def table of the database.
Definition: ChangeTags.php:1386
ChangeTags\updateTags
static updateTags( $tagsToAdd, $tagsToRemove, &$rc_id=null, &$rev_id=null, &$log_id=null, $params=null, RecentChange $rc=null, User $user=null)
Add and remove tags to/from a change given its rc_id, rev_id and/or log_id, without verifying that th...
Definition: ChangeTags.php:263
ChangeTagsTest\testModifyDisplayQuery
testModifyDisplayQuery( $origQuery, $filter_tag, $useTags, $modifiedQuery)
provideModifyDisplayQuery
Definition: ChangeTagsTest.php:29
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1985
ChangeTags\tagUsageStatistics
static tagUsageStatistics()
Returns a map of any tags used on the wiki to number of edits tagged with them, ordered descending by...
Definition: ChangeTags.php:1478
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
object
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Definition: globals.txt:25
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
MediaWikiTestCase\markTestSkippedIfDbType
markTestSkippedIfDbType( $type)
Skip the test if using the specified database type.
Definition: MediaWikiTestCase.php:2303