MediaWiki  master
ChangesListSpecialPageTest.php
Go to the documentation of this file.
1 <?php
2 
4 
18  protected function getPage() {
19  $mock = $this->getMockBuilder( ChangesListSpecialPage::class )
20  ->setConstructorArgs(
21  [
22  'ChangesListSpecialPage',
23  ''
24  ]
25  )
26  ->setMethods( [ 'getPageTitle' ] )
27  ->getMockForAbstractClass();
28 
29  $mock->method( 'getPageTitle' )->willReturn(
30  Title::makeTitle( NS_SPECIAL, 'ChangesListSpecialPage' )
31  );
32 
33  $mock = TestingAccessWrapper::newFromObject(
34  $mock
35  );
36 
37  return $mock;
38  }
39 
40  private function buildQuery(
41  $requestOptions = null,
42  $user = null
43  ) {
45  $context->setRequest( new FauxRequest( $requestOptions ) );
46  if ( $user ) {
47  $context->setUser( $user );
48  }
49 
50  $this->changesListSpecialPage->setContext( $context );
51  $this->changesListSpecialPage->filterGroups = [];
52  $formOptions = $this->changesListSpecialPage->setup( null );
53 
54  # ¬†Filter out rc_timestamp conditions which depends on the test runtime
55  # This condition is not needed as of march 2, 2011 -- hashar
56  # @todo FIXME: Find a way to generate the correct rc_timestamp
57 
58  $tables = [];
59  $fields = [];
60  $queryConditions = [];
61  $query_options = [];
62  $join_conds = [];
63 
64  call_user_func_array(
65  [ $this->changesListSpecialPage, 'buildQuery' ],
66  [
67  &$tables,
68  &$fields,
69  &$queryConditions,
70  &$query_options,
71  &$join_conds,
72  $formOptions
73  ]
74  );
75 
76  $queryConditions = array_filter(
77  $queryConditions,
78  'ChangesListSpecialPageTest::filterOutRcTimestampCondition'
79  );
80 
81  return $queryConditions;
82  }
83 
85  private function assertConditions(
86  $expected,
87  $requestOptions = null,
88  $message = '',
89  $user = null
90  ) {
91  $queryConditions = $this->buildQuery( $requestOptions, $user );
92 
93  $this->assertEquals(
94  self::normalizeCondition( $expected ),
95  self::normalizeCondition( $queryConditions ),
96  $message
97  );
98  }
99 
100  private static function normalizeCondition( $conds ) {
101  $dbr = wfGetDB( DB_REPLICA );
102  $normalized = array_map(
103  function ( $k, $v ) use ( $dbr ) {
104  if ( is_array( $v ) ) {
105  sort( $v );
106  }
107  // (Ab)use makeList() to format only this entry
108  return $dbr->makeList( [ $k => $v ], Database::LIST_AND );
109  },
110  array_keys( $conds ),
111  $conds
112  );
113  sort( $normalized );
114  return $normalized;
115  }
116 
118  private static function filterOutRcTimestampCondition( $var ) {
119  return ( is_array( $var ) || strpos( $var, 'rc_timestamp ' ) === false );
120  }
121 
122  public function testRcNsFilter() {
123  $this->assertConditions(
124  [ # expected
125  "rc_namespace = '0'",
126  ],
127  [
128  'namespace' => NS_MAIN,
129  ],
130  "rc conditions with one namespace"
131  );
132  }
133 
134  public function testRcNsFilterInversion() {
135  $this->assertConditions(
136  [ # expected
137  "rc_namespace != '0'",
138  ],
139  [
140  'namespace' => NS_MAIN,
141  'invert' => 1,
142  ],
143  "rc conditions with namespace inverted"
144  );
145  }
146 
147  public function testRcNsFilterMultiple() {
148  $this->assertConditions(
149  [ # expected
150  "rc_namespace IN ('1','2','3')",
151  ],
152  [
153  'namespace' => '1;2;3',
154  ],
155  "rc conditions with multiple namespaces"
156  );
157  }
158 
160  $this->assertConditions(
161  [ # expected
162  "rc_namespace IN ('0','1','4','5','6','7')",
163  ],
164  [
165  'namespace' => '1;4;7',
166  'associated' => 1,
167  ],
168  "rc conditions with multiple namespaces and associated"
169  );
170  }
171 
173  $this->assertConditions(
174  [ # expected
175  "rc_namespace NOT IN ('2','3','8','9')",
176  ],
177  [
178  'namespace' => '2;3;9',
179  'associated' => 1,
180  'invert' => 1
181  ],
182  "rc conditions with multiple namespaces, associated and inverted"
183  );
184  }
185 
186  public function testRcNsFilterMultipleInvert() {
187  $this->assertConditions(
188  [ # expected
189  "rc_namespace NOT IN ('1','2','3')",
190  ],
191  [
192  'namespace' => '1;2;3',
193  'invert' => 1,
194  ],
195  "rc conditions with multiple namespaces inverted"
196  );
197  }
198 
199  public function testRcHidemyselfFilter() {
200  $this->setMwGlobals(
201  'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
202  );
203  $this->overrideMwServices();
204 
205  $user = $this->getTestUser()->getUser();
206  $user->getActorId( wfGetDB( DB_MASTER ) );
207  $this->assertConditions(
208  [ # expected
209  "NOT((rc_user = '{$user->getId()}'))",
210  ],
211  [
212  'hidemyself' => 1,
213  ],
214  "rc conditions: hidemyself=1 (logged in)",
215  $user
216  );
217 
218  $user = User::newFromName( '10.11.12.13', false );
219  $id = $user->getActorId( wfGetDB( DB_MASTER ) );
220  $this->assertConditions(
221  [ # expected
222  "NOT((rc_user_text = '10.11.12.13'))",
223  ],
224  [
225  'hidemyself' => 1,
226  ],
227  "rc conditions: hidemyself=1 (anon)",
228  $user
229  );
230  }
231 
232  public function testRcHidebyothersFilter() {
233  $this->setMwGlobals(
234  'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
235  );
236  $this->overrideMwServices();
237 
238  $user = $this->getTestUser()->getUser();
239  $user->getActorId( wfGetDB( DB_MASTER ) );
240  $this->assertConditions(
241  [ # expected
242  "(rc_user_text = '{$user->getName()}')",
243  ],
244  [
245  'hidebyothers' => 1,
246  ],
247  "rc conditions: hidebyothers=1 (logged in)",
248  $user
249  );
250 
251  $user = User::newFromName( '10.11.12.13', false );
252  $id = $user->getActorId( wfGetDB( DB_MASTER ) );
253  $this->assertConditions(
254  [ # expected
255  "(rc_user_text = '10.11.12.13')",
256  ],
257  [
258  'hidebyothers' => 1,
259  ],
260  "rc conditions: hidebyothers=1 (anon)",
261  $user
262  );
263  }
264 
265  public function testRcHidepageedits() {
266  $this->assertConditions(
267  [ # expected
268  "rc_type != '0'",
269  ],
270  [
271  'hidepageedits' => 1,
272  ],
273  "rc conditions: hidepageedits=1"
274  );
275  }
276 
277  public function testRcHidenewpages() {
278  $this->assertConditions(
279  [ # expected
280  "rc_type != '1'",
281  ],
282  [
283  'hidenewpages' => 1,
284  ],
285  "rc conditions: hidenewpages=1"
286  );
287  }
288 
289  public function testRcHidelog() {
290  $this->assertConditions(
291  [ # expected
292  "rc_type != '3'",
293  ],
294  [
295  'hidelog' => 1,
296  ],
297  "rc conditions: hidelog=1"
298  );
299  }
300 
301  public function testRcHidehumans() {
302  $this->assertConditions(
303  [ # expected
304  'rc_bot' => 1,
305  ],
306  [
307  'hidebots' => 0,
308  'hidehumans' => 1,
309  ],
310  "rc conditions: hidebots=0 hidehumans=1"
311  );
312  }
313 
315  $this->setMwGlobals( 'wgUseRCPatrol', false );
316  $user = $this->getTestUser()->getUser();
317  $this->assertConditions(
318  [ # expected
319  ],
320  [
321  'hidepatrolled' => 1,
322  ],
323  "rc conditions: hidepatrolled=1 (user not allowed)",
324  $user
325  );
326  }
327 
329  $this->setMwGlobals( 'wgUseRCPatrol', false );
330  $user = $this->getTestUser()->getUser();
331  $this->assertConditions(
332  [ # expected
333  ],
334  [
335  'hideunpatrolled' => 1,
336  ],
337  "rc conditions: hideunpatrolled=1 (user not allowed)",
338  $user
339  );
340  }
341  public function testRcHidepatrolledFilter() {
342  $user = $this->getTestSysop()->getUser();
343  $this->assertConditions(
344  [ # expected
345  'rc_patrolled' => 0,
346  ],
347  [
348  'hidepatrolled' => 1,
349  ],
350  "rc conditions: hidepatrolled=1",
351  $user
352  );
353  }
354 
355  public function testRcHideunpatrolledFilter() {
356  $user = $this->getTestSysop()->getUser();
357  $this->assertConditions(
358  [ # expected
359  'rc_patrolled' => [ 1, 2 ],
360  ],
361  [
362  'hideunpatrolled' => 1,
363  ],
364  "rc conditions: hideunpatrolled=1",
365  $user
366  );
367  }
368 
369  public function testRcReviewStatusFilter() {
370  $user = $this->getTestSysop()->getUser();
371  $this->assertConditions(
372  [ #expected
373  'rc_patrolled' => 1,
374  ],
375  [
376  'reviewStatus' => 'manual'
377  ],
378  "rc conditions: reviewStatus=manual",
379  $user
380  );
381  $this->assertConditions(
382  [ #expected
383  'rc_patrolled' => [ 0, 2 ],
384  ],
385  [
386  'reviewStatus' => 'unpatrolled;auto'
387  ],
388  "rc conditions: reviewStatus=unpatrolled;auto",
389  $user
390  );
391  }
392 
393  public function testRcHideminorFilter() {
394  $this->assertConditions(
395  [ # expected
396  "rc_minor = 0",
397  ],
398  [
399  'hideminor' => 1,
400  ],
401  "rc conditions: hideminor=1"
402  );
403  }
404 
405  public function testRcHidemajorFilter() {
406  $this->assertConditions(
407  [ # expected
408  "rc_minor = 1",
409  ],
410  [
411  'hidemajor' => 1,
412  ],
413  "rc conditions: hidemajor=1"
414  );
415  }
416 
417  public function testHideCategorization() {
418  $this->assertConditions(
419  [
420  # expected
421  "rc_type != '6'"
422  ],
423  [
424  'hidecategorization' => 1
425  ],
426  "rc conditions: hidecategorization=1"
427  );
428  }
429 
430  public function testFilterUserExpLevelAll() {
431  $this->assertConditions(
432  [
433  # expected
434  ],
435  [
436  'userExpLevel' => 'registered;unregistered;newcomer;learner;experienced',
437  ],
438  "rc conditions: userExpLevel=registered;unregistered;newcomer;learner;experienced"
439  );
440  }
441 
443  $this->assertConditions(
444  [
445  # expected
446  ],
447  [
448  'userExpLevel' => 'registered;unregistered',
449  ],
450  "rc conditions: userExpLevel=registered;unregistered"
451  );
452  }
453 
455  $this->assertConditions(
456  [
457  # expected
458  ],
459  [
460  'userExpLevel' => 'registered;unregistered;learner',
461  ],
462  "rc conditions: userExpLevel=registered;unregistered;learner"
463  );
464  }
465 
467  $this->setMwGlobals(
468  'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
469  );
470  $this->overrideMwServices();
471 
472  $this->assertConditions(
473  [
474  # expected
475  'rc_user != 0',
476  ],
477  [
478  'userExpLevel' => 'newcomer;learner;experienced',
479  ],
480  "rc conditions: userExpLevel=newcomer;learner;experienced"
481  );
482  }
483 
485  $this->setMwGlobals(
486  'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
487  );
488  $this->overrideMwServices();
489 
490  $this->assertConditions(
491  [
492  # expected
493  'rc_user != 0',
494  ],
495  [
496  'userExpLevel' => 'registered',
497  ],
498  "rc conditions: userExpLevel=registered"
499  );
500  }
501 
503  $this->setMwGlobals(
504  'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
505  );
506  $this->overrideMwServices();
507 
508  $this->assertConditions(
509  [
510  # expected
511  'rc_user = 0',
512  ],
513  [
514  'userExpLevel' => 'unregistered',
515  ],
516  "rc conditions: userExpLevel=unregistered"
517  );
518  }
519 
521  $this->setMwGlobals(
522  'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
523  );
524  $this->overrideMwServices();
525 
526  $this->assertConditions(
527  [
528  # expected
529  'rc_user != 0',
530  ],
531  [
532  'userExpLevel' => 'registered;learner',
533  ],
534  "rc conditions: userExpLevel=registered;learner"
535  );
536  }
537 
539  $this->setMwGlobals(
540  'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
541  );
542  $this->overrideMwServices();
543 
544  $conds = $this->buildQuery( [ 'userExpLevel' => 'unregistered;experienced' ] );
545 
546  $this->assertRegExp(
547  '/\(rc_user = 0\) OR '
548  . '\(\(user_editcount >= 500\) AND \(user_registration <= \'[^\']+\'\)\)/',
549  reset( $conds ),
550  "rc conditions: userExpLevel=unregistered;experienced"
551  );
552  }
553 
554  public function testFilterUserExpLevel() {
555  $now = time();
556  $this->setMwGlobals( [
557  'wgLearnerEdits' => 10,
558  'wgLearnerMemberSince' => 4,
559  'wgExperiencedUserEdits' => 500,
560  'wgExperiencedUserMemberSince' => 30,
561  ] );
562 
563  $this->createUsers( [
564  'Newcomer1' => [ 'edits' => 2, 'days' => 2 ],
565  'Newcomer2' => [ 'edits' => 12, 'days' => 3 ],
566  'Newcomer3' => [ 'edits' => 8, 'days' => 5 ],
567  'Learner1' => [ 'edits' => 15, 'days' => 10 ],
568  'Learner2' => [ 'edits' => 450, 'days' => 20 ],
569  'Learner3' => [ 'edits' => 460, 'days' => 33 ],
570  'Learner4' => [ 'edits' => 525, 'days' => 28 ],
571  'Experienced1' => [ 'edits' => 538, 'days' => 33 ],
572  ], $now );
573 
574  // newcomers only
575  $this->assertArrayEquals(
576  [ 'Newcomer1', 'Newcomer2', 'Newcomer3' ],
577  $this->fetchUsers( [ 'newcomer' ], $now )
578  );
579 
580  // newcomers and learner
581  $this->assertArrayEquals(
582  [
583  'Newcomer1', 'Newcomer2', 'Newcomer3',
584  'Learner1', 'Learner2', 'Learner3', 'Learner4',
585  ],
586  $this->fetchUsers( [ 'newcomer', 'learner' ], $now )
587  );
588 
589  // newcomers and more learner
590  $this->assertArrayEquals(
591  [
592  'Newcomer1', 'Newcomer2', 'Newcomer3',
593  'Experienced1',
594  ],
595  $this->fetchUsers( [ 'newcomer', 'experienced' ], $now )
596  );
597 
598  // learner only
599  $this->assertArrayEquals(
600  [ 'Learner1', 'Learner2', 'Learner3', 'Learner4' ],
601  $this->fetchUsers( [ 'learner' ], $now )
602  );
603 
604  // more experienced only
605  $this->assertArrayEquals(
606  [ 'Experienced1' ],
607  $this->fetchUsers( [ 'experienced' ], $now )
608  );
609 
610  // learner and more experienced
611  $this->assertArrayEquals(
612  [
613  'Learner1', 'Learner2', 'Learner3', 'Learner4',
614  'Experienced1',
615  ],
616  $this->fetchUsers( [ 'learner', 'experienced' ], $now )
617  );
618  }
619 
620  private function createUsers( $specs, $now ) {
621  $dbw = wfGetDB( DB_MASTER );
622  foreach ( $specs as $name => $spec ) {
624  $name,
625  [
626  'editcount' => $spec['edits'],
627  'registration' => $dbw->timestamp( $this->daysAgo( $spec['days'], $now ) ),
628  'email' => 'ut',
629  ]
630  );
631  }
632  }
633 
634  private function fetchUsers( $filters, $now ) {
635  $tables = [];
636  $conds = [];
637  $fields = [];
638  $query_options = [];
639  $join_conds = [];
640 
641  sort( $filters );
642 
643  call_user_func_array(
644  [ $this->changesListSpecialPage, 'filterOnUserExperienceLevel' ],
645  [
646  get_class( $this->changesListSpecialPage ),
647  $this->changesListSpecialPage->getContext(),
648  $this->changesListSpecialPage->getDB(),
649  &$tables,
650  &$fields,
651  &$conds,
652  &$query_options,
653  &$join_conds,
654  $filters,
655  $now
656  ]
657  );
658 
659  // @todo: This is not at all safe or sane. It just blindly assumes
660  // nothing in $conds depends on any other tables.
661  $result = wfGetDB( DB_MASTER )->select(
662  'user',
663  'user_name',
664  array_filter( $conds ) + [ 'user_email' => 'ut' ]
665  );
666 
667  $usernames = [];
668  foreach ( $result as $row ) {
669  $usernames[] = $row->user_name;
670  }
671 
672  return $usernames;
673  }
674 
675  private function daysAgo( $days, $now ) {
676  $secondsPerDay = 86400;
677  return $now - $days * $secondsPerDay;
678  }
679 
680  public function testGetStructuredFilterJsData() {
681  $this->changesListSpecialPage->filterGroups = [];
682 
683  $definition = [
684  [
685  'name' => 'gub-group',
686  'title' => 'gub-group-title',
688  'filters' => [
689  [
690  'name' => 'hidefoo',
691  'label' => 'foo-label',
692  'description' => 'foo-description',
693  'default' => true,
694  'showHide' => 'showhidefoo',
695  'priority' => 2,
696  ],
697  [
698  'name' => 'hidebar',
699  'label' => 'bar-label',
700  'description' => 'bar-description',
701  'default' => false,
702  'priority' => 4,
703  ]
704  ],
705  ],
706 
707  [
708  'name' => 'des-group',
709  'title' => 'des-group-title',
711  'isFullCoverage' => true,
712  'filters' => [
713  [
714  'name' => 'grault',
715  'label' => 'grault-label',
716  'description' => 'grault-description',
717  ],
718  [
719  'name' => 'garply',
720  'label' => 'garply-label',
721  'description' => 'garply-description',
722  ],
723  ],
724  'queryCallable' => function () {
725  },
727  ],
728 
729  [
730  'name' => 'unstructured',
732  'filters' => [
733  [
734  'name' => 'hidethud',
735  'showHide' => 'showhidethud',
736  'default' => true,
737  ],
738 
739  [
740  'name' => 'hidemos',
741  'showHide' => 'showhidemos',
742  'default' => false,
743  ],
744  ],
745  ],
746 
747  ];
748 
749  $this->changesListSpecialPage->registerFiltersFromDefinitions( $definition );
750 
751  $this->assertArrayEquals(
752  [
753  // Filters that only display in the unstructured UI are
754  // are not included, and neither are groups that would
755  // be empty due to the above.
756  'groups' => [
757  [
758  'name' => 'gub-group',
759  'title' => 'gub-group-title',
761  'priority' => -1,
762  'filters' => [
763  [
764  'name' => 'hidebar',
765  'label' => 'bar-label',
766  'description' => 'bar-description',
767  'default' => false,
768  'priority' => 4,
769  'cssClass' => null,
770  'conflicts' => [],
771  'subset' => [],
772  'defaultHighlightColor' => null
773  ],
774  [
775  'name' => 'hidefoo',
776  'label' => 'foo-label',
777  'description' => 'foo-description',
778  'default' => true,
779  'priority' => 2,
780  'cssClass' => null,
781  'conflicts' => [],
782  'subset' => [],
783  'defaultHighlightColor' => null
784  ],
785  ],
786  'fullCoverage' => true,
787  'conflicts' => [],
788  ],
789 
790  [
791  'name' => 'des-group',
792  'title' => 'des-group-title',
794  'priority' => -2,
795  'fullCoverage' => true,
796  'filters' => [
797  [
798  'name' => 'grault',
799  'label' => 'grault-label',
800  'description' => 'grault-description',
801  'cssClass' => null,
802  'priority' => -2,
803  'conflicts' => [],
804  'subset' => [],
805  'defaultHighlightColor' => null
806  ],
807  [
808  'name' => 'garply',
809  'label' => 'garply-label',
810  'description' => 'garply-description',
811  'cssClass' => null,
812  'priority' => -3,
813  'conflicts' => [],
814  'subset' => [],
815  'defaultHighlightColor' => null
816  ],
817  ],
818  'conflicts' => [],
819  'separator' => ';',
821  ],
822  ],
823  'messageKeys' => [
824  'gub-group-title',
825  'bar-label',
826  'bar-description',
827  'foo-label',
828  'foo-description',
829  'des-group-title',
830  'grault-label',
831  'grault-description',
832  'garply-label',
833  'garply-description',
834  ],
835  ],
836  $this->changesListSpecialPage->getStructuredFilterJsData(), false, true
839  );
840  }
841 
842  public function provideParseParameters() {
843  return [
844  [ 'hidebots', [ 'hidebots' => true ] ],
845 
846  [ 'bots', [ 'hidebots' => false ] ],
847 
848  [ 'hideminor', [ 'hideminor' => true ] ],
849 
850  [ 'minor', [ 'hideminor' => false ] ],
851 
852  [ 'hidemajor', [ 'hidemajor' => true ] ],
853 
854  [ 'hideliu', [ 'hideliu' => true ] ],
855 
856  [ 'hidepatrolled', [ 'hidepatrolled' => true ] ],
857 
858  [ 'hideunpatrolled', [ 'hideunpatrolled' => true ] ],
859 
860  [ 'hideanons', [ 'hideanons' => true ] ],
861 
862  [ 'hidemyself', [ 'hidemyself' => true ] ],
863 
864  [ 'hidebyothers', [ 'hidebyothers' => true ] ],
865 
866  [ 'hidehumans', [ 'hidehumans' => true ] ],
867 
868  [ 'hidepageedits', [ 'hidepageedits' => true ] ],
869 
870  [ 'pagedits', [ 'hidepageedits' => false ] ],
871 
872  [ 'hidenewpages', [ 'hidenewpages' => true ] ],
873 
874  [ 'hidecategorization', [ 'hidecategorization' => true ] ],
875 
876  [ 'hidelog', [ 'hidelog' => true ] ],
877 
878  [
879  'userExpLevel=learner;experienced',
880  [
881  'userExpLevel' => 'learner;experienced'
882  ],
883  ],
884 
885  // A few random combos
886  [
887  'bots,hideliu,hidemyself',
888  [
889  'hidebots' => false,
890  'hideliu' => true,
891  'hidemyself' => true,
892  ],
893  ],
894 
895  [
896  'minor,hideanons,categorization',
897  [
898  'hideminor' => false,
899  'hideanons' => true,
900  'hidecategorization' => false,
901  ]
902  ],
903 
904  [
905  'hidehumans,bots,hidecategorization',
906  [
907  'hidehumans' => true,
908  'hidebots' => false,
909  'hidecategorization' => true,
910  ],
911  ],
912 
913  [
914  'hidemyself,userExpLevel=newcomer;learner,hideminor',
915  [
916  'hidemyself' => true,
917  'hideminor' => true,
918  'userExpLevel' => 'newcomer;learner',
919  ],
920  ],
921  ];
922  }
923 
924  public function provideGetFilterConflicts() {
925  return [
926  [
927  "parameters" => [],
928  "expectedConflicts" => false,
929  ],
930  [
931  "parameters" => [
932  "hideliu" => true,
933  "userExpLevel" => "newcomer",
934  ],
935  "expectedConflicts" => false,
936  ],
937  [
938  "parameters" => [
939  "hideanons" => true,
940  "userExpLevel" => "learner",
941  ],
942  "expectedConflicts" => false,
943  ],
944  [
945  "parameters" => [
946  "hidemajor" => true,
947  "hidenewpages" => true,
948  "hidepageedits" => true,
949  "hidecategorization" => false,
950  "hidelog" => true,
951  "hideWikidata" => true,
952  ],
953  "expectedConflicts" => true,
954  ],
955  [
956  "parameters" => [
957  "hidemajor" => true,
958  "hidenewpages" => false,
959  "hidepageedits" => true,
960  "hidecategorization" => false,
961  "hidelog" => false,
962  "hideWikidata" => true,
963  ],
964  "expectedConflicts" => true,
965  ],
966  [
967  "parameters" => [
968  "hidemajor" => true,
969  "hidenewpages" => false,
970  "hidepageedits" => false,
971  "hidecategorization" => true,
972  "hidelog" => true,
973  "hideWikidata" => true,
974  ],
975  "expectedConflicts" => false,
976  ],
977  [
978  "parameters" => [
979  "hideminor" => true,
980  "hidenewpages" => true,
981  "hidepageedits" => true,
982  "hidecategorization" => false,
983  "hidelog" => true,
984  "hideWikidata" => true,
985  ],
986  "expectedConflicts" => false,
987  ],
988  ];
989  }
990 
994  public function testGetFilterConflicts( $parameters, $expectedConflicts ) {
995  $context = new RequestContext;
996  $context->setRequest( new FauxRequest( $parameters ) );
997  $this->changesListSpecialPage->setContext( $context );
998 
999  $this->assertEquals(
1000  $expectedConflicts,
1001  $this->changesListSpecialPage->areFiltersInConflict()
1002  );
1003  }
1004 
1005  public function validateOptionsProvider() {
1006  return [
1007  [
1008  [ 'hideanons' => 1, 'hideliu' => 1, 'hidebots' => 1 ],
1009  true,
1010  [ 'userExpLevel' => 'unregistered', 'hidebots' => 1, ],
1011  true,
1012  ],
1013  [
1014  [ 'hideanons' => 1, 'hideliu' => 1, 'hidebots' => 0 ],
1015  true,
1016  [ 'hidebots' => 0, 'hidehumans' => 1 ],
1017  true,
1018  ],
1019  [
1020  [ 'hideanons' => 1 ],
1021  true,
1022  [ 'userExpLevel' => 'registered' ],
1023  true,
1024  ],
1025  [
1026  [ 'hideliu' => 1 ],
1027  true,
1028  [ 'userExpLevel' => 'unregistered' ],
1029  true,
1030  ],
1031  [
1032  [ 'hideanons' => 1, 'hidebots' => 1 ],
1033  true,
1034  [ 'userExpLevel' => 'registered', 'hidebots' => 1 ],
1035  true,
1036  ],
1037  [
1038  [ 'hideliu' => 1, 'hidebots' => 0 ],
1039  true,
1040  [ 'userExpLevel' => 'unregistered', 'hidebots' => 0 ],
1041  true,
1042  ],
1043  [
1044  [ 'hidemyself' => 1, 'hidebyothers' => 1 ],
1045  true,
1046  [],
1047  true,
1048  ],
1049  [
1050  [ 'hidebots' => 1, 'hidehumans' => 1 ],
1051  true,
1052  [],
1053  true,
1054  ],
1055  [
1056  [ 'hidepatrolled' => 1, 'hideunpatrolled' => 1 ],
1057  true,
1058  [],
1059  true,
1060  ],
1061  [
1062  [ 'hideminor' => 1, 'hidemajor' => 1 ],
1063  true,
1064  [],
1065  true,
1066  ],
1067  [
1068  // changeType
1069  [ 'hidepageedits' => 1, 'hidenewpages' => 1, 'hidecategorization' => 1, 'hidelog' => 1, ],
1070  true,
1071  [],
1072  true,
1073  ],
1074  ];
1075  }
1076 }
Test class for ChangesListSpecialPage class.
const NS_MAIN
Definition: Defines.php:64
const TYPE
Type marker, used by JavaScript.
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static filterOutRcTimestampCondition( $var)
return false if condition begins with &#39;rc_timestamp &#39;
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
const NS_SPECIAL
Definition: Defines.php:53
const DB_MASTER
Definition: defines.php:26
this hook is for auditing only RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition: hooks.txt:979
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. '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. '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 '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:1980
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:1982
static getTestSysop()
Convenience method for getting an immutable admin test user.
const LIST_AND
Definition: Defines.php:43
Abstract base class for shared logic when testing ChangesListSpecialPage and subclasses.
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:780
overrideMwServices(Config $configOverrides=null, array $services=[])
Stashes the global instance of MediaWikiServices, and installs a new one, allowing test cases to over...
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown...
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
testGetFilterConflicts( $parameters, $expectedConflicts)
provideGetFilterConflicts
const SCHEMA_COMPAT_WRITE_BOTH
Definition: Defines.php:288
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:589
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 NONE
Signifies that no options in the group are selected, meaning the group has no effect.
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
buildQuery( $requestOptions=null, $user=null)
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2633
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
assertConditions( $expected, $requestOptions=null, $message='', $user=null)
helper to test SpecialRecentchanges::buildQuery()
const DB_REPLICA
Definition: defines.php:25
const SCHEMA_COMPAT_READ_OLD
Definition: Defines.php:285
static createNew( $name, $params=[])
Add a user to the database, return the user object.
Definition: User.php:4291
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:587
const TYPE
Type marker, used by JavaScript.
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1473