MediaWiki  1.32.0
ChangesListSpecialPageTest.php
Go to the documentation of this file.
1 <?php
2 
3 use Wikimedia\TestingAccessWrapper;
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 ) || false === strpos( $var, 'rc_timestamp ' ) );
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  'Learner and more experienced'
618  );
619  }
620 
621  private function createUsers( $specs, $now ) {
622  $dbw = wfGetDB( DB_MASTER );
623  foreach ( $specs as $name => $spec ) {
625  $name,
626  [
627  'editcount' => $spec['edits'],
628  'registration' => $dbw->timestamp( $this->daysAgo( $spec['days'], $now ) ),
629  'email' => 'ut',
630  ]
631  );
632  }
633  }
634 
635  private function fetchUsers( $filters, $now ) {
636  $tables = [];
637  $conds = [];
638  $fields = [];
639  $query_options = [];
640  $join_conds = [];
641 
642  sort( $filters );
643 
644  call_user_func_array(
645  [ $this->changesListSpecialPage, 'filterOnUserExperienceLevel' ],
646  [
647  get_class( $this->changesListSpecialPage ),
648  $this->changesListSpecialPage->getContext(),
649  $this->changesListSpecialPage->getDB(),
650  &$tables,
651  &$fields,
652  &$conds,
653  &$query_options,
654  &$join_conds,
655  $filters,
656  $now
657  ]
658  );
659 
660  // @todo: This is not at all safe or sane. It just blindly assumes
661  // nothing in $conds depends on any other tables.
662  $result = wfGetDB( DB_MASTER )->select(
663  'user',
664  'user_name',
665  array_filter( $conds ) + [ 'user_email' => 'ut' ]
666  );
667 
668  $usernames = [];
669  foreach ( $result as $row ) {
670  $usernames[] = $row->user_name;
671  }
672 
673  return $usernames;
674  }
675 
676  private function daysAgo( $days, $now ) {
677  $secondsPerDay = 86400;
678  return $now - $days * $secondsPerDay;
679  }
680 
681  public function testGetStructuredFilterJsData() {
682  $this->changesListSpecialPage->filterGroups = [];
683 
684  $definition = [
685  [
686  'name' => 'gub-group',
687  'title' => 'gub-group-title',
689  'filters' => [
690  [
691  'name' => 'hidefoo',
692  'label' => 'foo-label',
693  'description' => 'foo-description',
694  'default' => true,
695  'showHide' => 'showhidefoo',
696  'priority' => 2,
697  ],
698  [
699  'name' => 'hidebar',
700  'label' => 'bar-label',
701  'description' => 'bar-description',
702  'default' => false,
703  'priority' => 4,
704  ]
705  ],
706  ],
707 
708  [
709  'name' => 'des-group',
710  'title' => 'des-group-title',
712  'isFullCoverage' => true,
713  'filters' => [
714  [
715  'name' => 'grault',
716  'label' => 'grault-label',
717  'description' => 'grault-description',
718  ],
719  [
720  'name' => 'garply',
721  'label' => 'garply-label',
722  'description' => 'garply-description',
723  ],
724  ],
725  'queryCallable' => function () {
726  },
728  ],
729 
730  [
731  'name' => 'unstructured',
733  'filters' => [
734  [
735  'name' => 'hidethud',
736  'showHide' => 'showhidethud',
737  'default' => true,
738  ],
739 
740  [
741  'name' => 'hidemos',
742  'showHide' => 'showhidemos',
743  'default' => false,
744  ],
745  ],
746  ],
747 
748  ];
749 
750  $this->changesListSpecialPage->registerFiltersFromDefinitions( $definition );
751 
752  $this->assertArrayEquals(
753  [
754  // Filters that only display in the unstructured UI are
755  // are not included, and neither are groups that would
756  // be empty due to the above.
757  'groups' => [
758  [
759  'name' => 'gub-group',
760  'title' => 'gub-group-title',
762  'priority' => -1,
763  'filters' => [
764  [
765  'name' => 'hidebar',
766  'label' => 'bar-label',
767  'description' => 'bar-description',
768  'default' => false,
769  'priority' => 4,
770  'cssClass' => null,
771  'conflicts' => [],
772  'subset' => [],
773  'defaultHighlightColor' => null
774  ],
775  [
776  'name' => 'hidefoo',
777  'label' => 'foo-label',
778  'description' => 'foo-description',
779  'default' => true,
780  'priority' => 2,
781  'cssClass' => null,
782  'conflicts' => [],
783  'subset' => [],
784  'defaultHighlightColor' => null
785  ],
786  ],
787  'fullCoverage' => true,
788  'conflicts' => [],
789  ],
790 
791  [
792  'name' => 'des-group',
793  'title' => 'des-group-title',
795  'priority' => -2,
796  'fullCoverage' => true,
797  'filters' => [
798  [
799  'name' => 'grault',
800  'label' => 'grault-label',
801  'description' => 'grault-description',
802  'cssClass' => null,
803  'priority' => -2,
804  'conflicts' => [],
805  'subset' => [],
806  'defaultHighlightColor' => null
807  ],
808  [
809  'name' => 'garply',
810  'label' => 'garply-label',
811  'description' => 'garply-description',
812  'cssClass' => null,
813  'priority' => -3,
814  'conflicts' => [],
815  'subset' => [],
816  'defaultHighlightColor' => null
817  ],
818  ],
819  'conflicts' => [],
820  'separator' => ';',
822  ],
823  ],
824  'messageKeys' => [
825  'gub-group-title',
826  'bar-label',
827  'bar-description',
828  'foo-label',
829  'foo-description',
830  'des-group-title',
831  'grault-label',
832  'grault-description',
833  'garply-label',
834  'garply-description',
835  ],
836  ],
837  $this->changesListSpecialPage->getStructuredFilterJsData(), false, true
840  );
841  }
842 
843  public function provideParseParameters() {
844  return [
845  [ 'hidebots', [ 'hidebots' => true ] ],
846 
847  [ 'bots', [ 'hidebots' => false ] ],
848 
849  [ 'hideminor', [ 'hideminor' => true ] ],
850 
851  [ 'minor', [ 'hideminor' => false ] ],
852 
853  [ 'hidemajor', [ 'hidemajor' => true ] ],
854 
855  [ 'hideliu', [ 'hideliu' => true ] ],
856 
857  [ 'hidepatrolled', [ 'hidepatrolled' => true ] ],
858 
859  [ 'hideunpatrolled', [ 'hideunpatrolled' => true ] ],
860 
861  [ 'hideanons', [ 'hideanons' => true ] ],
862 
863  [ 'hidemyself', [ 'hidemyself' => true ] ],
864 
865  [ 'hidebyothers', [ 'hidebyothers' => true ] ],
866 
867  [ 'hidehumans', [ 'hidehumans' => true ] ],
868 
869  [ 'hidepageedits', [ 'hidepageedits' => true ] ],
870 
871  [ 'pagedits', [ 'hidepageedits' => false ] ],
872 
873  [ 'hidenewpages', [ 'hidenewpages' => true ] ],
874 
875  [ 'hidecategorization', [ 'hidecategorization' => true ] ],
876 
877  [ 'hidelog', [ 'hidelog' => true ] ],
878 
879  [
880  'userExpLevel=learner;experienced',
881  [
882  'userExpLevel' => 'learner;experienced'
883  ],
884  ],
885 
886  // A few random combos
887  [
888  'bots,hideliu,hidemyself',
889  [
890  'hidebots' => false,
891  'hideliu' => true,
892  'hidemyself' => true,
893  ],
894  ],
895 
896  [
897  'minor,hideanons,categorization',
898  [
899  'hideminor' => false,
900  'hideanons' => true,
901  'hidecategorization' => false,
902  ]
903  ],
904 
905  [
906  'hidehumans,bots,hidecategorization',
907  [
908  'hidehumans' => true,
909  'hidebots' => false,
910  'hidecategorization' => true,
911  ],
912  ],
913 
914  [
915  'hidemyself,userExpLevel=newcomer;learner,hideminor',
916  [
917  'hidemyself' => true,
918  'hideminor' => true,
919  'userExpLevel' => 'newcomer;learner',
920  ],
921  ],
922  ];
923  }
924 
925  public function provideGetFilterConflicts() {
926  return [
927  [
928  "parameters" => [],
929  "expectedConflicts" => false,
930  ],
931  [
932  "parameters" => [
933  "hideliu" => true,
934  "userExpLevel" => "newcomer",
935  ],
936  "expectedConflicts" => false,
937  ],
938  [
939  "parameters" => [
940  "hideanons" => true,
941  "userExpLevel" => "learner",
942  ],
943  "expectedConflicts" => false,
944  ],
945  [
946  "parameters" => [
947  "hidemajor" => true,
948  "hidenewpages" => true,
949  "hidepageedits" => true,
950  "hidecategorization" => false,
951  "hidelog" => true,
952  "hideWikidata" => true,
953  ],
954  "expectedConflicts" => true,
955  ],
956  [
957  "parameters" => [
958  "hidemajor" => true,
959  "hidenewpages" => false,
960  "hidepageedits" => true,
961  "hidecategorization" => false,
962  "hidelog" => false,
963  "hideWikidata" => true,
964  ],
965  "expectedConflicts" => true,
966  ],
967  [
968  "parameters" => [
969  "hidemajor" => true,
970  "hidenewpages" => false,
971  "hidepageedits" => false,
972  "hidecategorization" => true,
973  "hidelog" => true,
974  "hideWikidata" => true,
975  ],
976  "expectedConflicts" => false,
977  ],
978  [
979  "parameters" => [
980  "hideminor" => true,
981  "hidenewpages" => true,
982  "hidepageedits" => true,
983  "hidecategorization" => false,
984  "hidelog" => true,
985  "hideWikidata" => true,
986  ],
987  "expectedConflicts" => false,
988  ],
989  ];
990  }
991 
995  public function testGetFilterConflicts( $parameters, $expectedConflicts ) {
996  $context = new RequestContext;
997  $context->setRequest( new FauxRequest( $parameters ) );
998  $this->changesListSpecialPage->setContext( $context );
999 
1000  $this->assertEquals(
1001  $expectedConflicts,
1002  $this->changesListSpecialPage->areFiltersInConflict()
1003  );
1004  }
1005 
1006  public function validateOptionsProvider() {
1007  return [
1008  [
1009  [ 'hideanons' => 1, 'hideliu' => 1, 'hidebots' => 1 ],
1010  true,
1011  [ 'userExpLevel' => 'unregistered', 'hidebots' => 1, ],
1012  true,
1013  ],
1014  [
1015  [ 'hideanons' => 1, 'hideliu' => 1, 'hidebots' => 0 ],
1016  true,
1017  [ 'hidebots' => 0, 'hidehumans' => 1 ],
1018  true,
1019  ],
1020  [
1021  [ 'hideanons' => 1 ],
1022  true,
1023  [ 'userExpLevel' => 'registered' ],
1024  true,
1025  ],
1026  [
1027  [ 'hideliu' => 1 ],
1028  true,
1029  [ 'userExpLevel' => 'unregistered' ],
1030  true,
1031  ],
1032  [
1033  [ 'hideanons' => 1, 'hidebots' => 1 ],
1034  true,
1035  [ 'userExpLevel' => 'registered', 'hidebots' => 1 ],
1036  true,
1037  ],
1038  [
1039  [ 'hideliu' => 1, 'hidebots' => 0 ],
1040  true,
1041  [ 'userExpLevel' => 'unregistered', 'hidebots' => 0 ],
1042  true,
1043  ],
1044  [
1045  [ 'hidemyself' => 1, 'hidebyothers' => 1 ],
1046  true,
1047  [],
1048  true,
1049  ],
1050  [
1051  [ 'hidebots' => 1, 'hidehumans' => 1 ],
1052  true,
1053  [],
1054  true,
1055  ],
1056  [
1057  [ 'hidepatrolled' => 1, 'hideunpatrolled' => 1 ],
1058  true,
1059  [],
1060  true,
1061  ],
1062  [
1063  [ 'hideminor' => 1, 'hidemajor' => 1 ],
1064  true,
1065  [],
1066  true,
1067  ],
1068  [
1069  // changeType
1070  [ 'hidepageedits' => 1, 'hidenewpages' => 1, 'hidecategorization' => 1, 'hidelog' => 1, ],
1071  true,
1072  [],
1073  true,
1074  ],
1075  ];
1076  }
1077 }
ChangesListSpecialPageTest\testRcNsFilterMultipleAssociatedInvert
testRcNsFilterMultipleAssociatedInvert()
Definition: ChangesListSpecialPageTest.php:172
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:244
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
MediaWikiTestCase\assertArrayEquals
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Definition: MediaWikiTestCase.php:2036
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
ChangesListSpecialPageTest\daysAgo
daysAgo( $days, $now)
Definition: ChangesListSpecialPageTest.php:676
ChangesListSpecialPageTest\testFilterUserExpLevelAllExperienceLevels
testFilterUserExpLevelAllExperienceLevels()
Definition: ChangesListSpecialPageTest.php:466
ChangesListSpecialPageTest\testFilterUserExpLevelRegisteredUnregisteredLearner
testFilterUserExpLevelRegisteredUnregisteredLearner()
Definition: ChangesListSpecialPageTest.php:454
$context
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:2675
MediaWikiTestCase\getTestUser
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
Definition: MediaWikiTestCase.php:179
ChangesListSpecialPageTest\testRcHidemyselfFilter
testRcHidemyselfFilter()
Definition: ChangesListSpecialPageTest.php:199
ChangesListSpecialPageTest\testRcHideunpatrolledFilter
testRcHideunpatrolledFilter()
Definition: ChangesListSpecialPageTest.php:355
ChangesListSpecialPageTest\assertConditions
assertConditions( $expected, $requestOptions=null, $message='', $user=null)
helper to test SpecialRecentchanges::buildQuery()
Definition: ChangesListSpecialPageTest.php:85
ChangesListSpecialPageTest\testFilterUserExpLevelRegistrered
testFilterUserExpLevelRegistrered()
Definition: ChangesListSpecialPageTest.php:484
ChangesListSpecialPageTest\testFilterUserExpLevelUnregistrered
testFilterUserExpLevelUnregistrered()
Definition: ChangesListSpecialPageTest.php:502
ChangesListSpecialPageTest\getPage
getPage()
Definition: ChangesListSpecialPageTest.php:18
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED since 1.16! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:2034
ChangesListSpecialPageTest\testRcNsFilterMultipleAssociated
testRcNsFilterMultipleAssociated()
Definition: ChangesListSpecialPageTest.php:159
$tables
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:1018
ChangesListSpecialPageTest\testRcHidelog
testRcHidelog()
Definition: ChangesListSpecialPageTest.php:289
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:592
ChangesListSpecialPageTest\testFilterUserExpLevel
testFilterUserExpLevel()
Definition: ChangesListSpecialPageTest.php:554
ChangesListSpecialPageTest\testRcHidemajorFilter
testRcHidemajorFilter()
Definition: ChangesListSpecialPageTest.php:405
ChangesListSpecialPageTest\testRcHidepageedits
testRcHidepageedits()
Definition: ChangesListSpecialPageTest.php:265
ChangesListSpecialPageTest\testRcNsFilterInversion
testRcNsFilterInversion()
Definition: ChangesListSpecialPageTest.php:134
ChangesListSpecialPageTest\testFilterUserExpLevelRegistreredOrLearner
testFilterUserExpLevelRegistreredOrLearner()
Definition: ChangesListSpecialPageTest.php:520
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
LIST_AND
const LIST_AND
Definition: Defines.php:43
User\createNew
static createNew( $name, $params=[])
Add a user to the database, return the user object.
Definition: User.php:4302
$dbr
$dbr
Definition: testCompression.php:50
MediaWikiTestCase\overrideMwServices
overrideMwServices(Config $configOverrides=null, array $services=[])
Stashes the global instance of MediaWikiServices, and installs a new one, allowing test cases to over...
Definition: MediaWikiTestCase.php:934
ChangesListSpecialPageTest\testRcNsFilterMultiple
testRcNsFilterMultiple()
Definition: ChangesListSpecialPageTest.php:147
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:53
ChangesListSpecialPageTest
Test class for ChangesListSpecialPage class.
Definition: ChangesListSpecialPageTest.php:17
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2693
ChangesListSpecialPageTest\testRcNsFilter
testRcNsFilter()
Definition: ChangesListSpecialPageTest.php:122
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:706
ChangesListSpecialPageTest\testFilterUserExpLevelUnregistreredOrExperienced
testFilterUserExpLevelUnregistreredOrExperienced()
Definition: ChangesListSpecialPageTest.php:538
ChangesListSpecialPageTest\testGetFilterConflicts
testGetFilterConflicts( $parameters, $expectedConflicts)
provideGetFilterConflicts
Definition: ChangesListSpecialPageTest.php:995
ChangesListSpecialPageTest\testRcHidebyothersFilter
testRcHidebyothersFilter()
Definition: ChangesListSpecialPageTest.php:232
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
ChangesListSpecialPageTest\testFilterUserExpLevelAll
testFilterUserExpLevelAll()
Definition: ChangesListSpecialPageTest.php:430
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:545
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:32
ChangesListSpecialPageTest\testRcHideunpatrolledDisabledFilter
testRcHideunpatrolledDisabledFilter()
Definition: ChangesListSpecialPageTest.php:328
DB_MASTER
const DB_MASTER
Definition: defines.php:26
ChangesListSpecialPageTest\provideGetFilterConflicts
provideGetFilterConflicts()
Definition: ChangesListSpecialPageTest.php:925
ChangesListSpecialPageTest\fetchUsers
fetchUsers( $filters, $now)
Definition: ChangesListSpecialPageTest.php:635
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
ChangesListSpecialPageTest\createUsers
createUsers( $specs, $now)
Definition: ChangesListSpecialPageTest.php:621
ChangesListSpecialPageTest\normalizeCondition
static normalizeCondition( $conds)
Definition: ChangesListSpecialPageTest.php:100
ChangesListSpecialPageTest\testRcHidepatrolledFilter
testRcHidepatrolledFilter()
Definition: ChangesListSpecialPageTest.php:341
ChangesListSpecialPageTest\testRcHidenewpages
testRcHidenewpages()
Definition: ChangesListSpecialPageTest.php:277
MediaWikiTestCase\getTestSysop
static getTestSysop()
Convenience method for getting an immutable admin test user.
Definition: MediaWikiTestCase.php:203
ChangesListStringOptionsFilterGroup\NONE
const NONE
Signifies that no options in the group are selected, meaning the group has no effect.
Definition: ChangesListStringOptionsFilterGroup.php:59
ChangesListSpecialPageTest\buildQuery
buildQuery( $requestOptions=null, $user=null)
Definition: ChangesListSpecialPageTest.php:40
ChangesListSpecialPageTest\provideParseParameters
provideParseParameters()
Definition: ChangesListSpecialPageTest.php:843
ChangesListSpecialPageTest\testRcHidehumans
testRcHidehumans()
Definition: ChangesListSpecialPageTest.php:301
ChangesListSpecialPageTest\testRcHideminorFilter
testRcHideminorFilter()
Definition: ChangesListSpecialPageTest.php:393
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
SCHEMA_COMPAT_WRITE_BOTH
const SCHEMA_COMPAT_WRITE_BOTH
Definition: Defines.php:288
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:2036
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
ChangesListSpecialPageTest\testRcNsFilterMultipleInvert
testRcNsFilterMultipleInvert()
Definition: ChangesListSpecialPageTest.php:186
ChangesListBooleanFilterGroup\TYPE
const TYPE
Type marker, used by JavaScript.
Definition: ChangesListBooleanFilterGroup.php:16
ChangesListSpecialPageTest\testHideCategorization
testHideCategorization()
Definition: ChangesListSpecialPageTest.php:417
ChangesListSpecialPageTest\validateOptionsProvider
validateOptionsProvider()
Definition: ChangesListSpecialPageTest.php:1006
ChangesListSpecialPageTest\filterOutRcTimestampCondition
static filterOutRcTimestampCondition( $var)
return false if condition begins with 'rc_timestamp '
Definition: ChangesListSpecialPageTest.php:118
ChangesListStringOptionsFilterGroup\TYPE
const TYPE
Type marker, used by JavaScript.
Definition: ChangesListStringOptionsFilterGroup.php:41
ChangesListSpecialPageTest\testFilterUserExpLevelRegisteredUnregistered
testFilterUserExpLevelRegisteredUnregistered()
Definition: ChangesListSpecialPageTest.php:442
SCHEMA_COMPAT_READ_OLD
const SCHEMA_COMPAT_READ_OLD
Definition: Defines.php:285
ChangesListSpecialPageTest\testRcReviewStatusFilter
testRcReviewStatusFilter()
Definition: ChangesListSpecialPageTest.php:369
AbstractChangesListSpecialPageTestCase
Abstract base class for shared logic when testing ChangesListSpecialPage and subclasses.
Definition: AbstractChangesListSpecialPageTestCase.php:9
ChangesListSpecialPageTest\testGetStructuredFilterJsData
testGetStructuredFilterJsData()
Definition: ChangesListSpecialPageTest.php:681
ChangesListSpecialPageTest\testRcHidepatrolledDisabledFilter
testRcHidepatrolledDisabledFilter()
Definition: ChangesListSpecialPageTest.php:314