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( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
201  $this->overrideMwServices();
202 
203  $user = $this->getTestUser()->getUser();
204  $user->getActorId( wfGetDB( DB_MASTER ) );
205  $this->assertConditions(
206  [ # expected
207  "NOT((rc_actor = '{$user->getActorId()}'))",
208  ],
209  [
210  'hidemyself' => 1,
211  ],
212  "rc conditions: hidemyself=1 (logged in)",
213  $user
214  );
215 
216  $user = User::newFromName( '10.11.12.13', false );
217  $id = $user->getActorId( wfGetDB( DB_MASTER ) );
218  $this->assertConditions(
219  [ # expected
220  "NOT((rc_actor = '{$user->getActorId()}'))",
221  ],
222  [
223  'hidemyself' => 1,
224  ],
225  "rc conditions: hidemyself=1 (anon)",
226  $user
227  );
228  }
229 
230  public function testRcHidemyselfFilter_old() {
231  $this->setMwGlobals(
232  'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
233  );
234  $this->overrideMwServices();
235 
236  $user = $this->getTestUser()->getUser();
237  $user->getActorId( wfGetDB( DB_MASTER ) );
238  $this->assertConditions(
239  [ # expected
240  "NOT((rc_user = '{$user->getId()}'))",
241  ],
242  [
243  'hidemyself' => 1,
244  ],
245  "rc conditions: hidemyself=1 (logged in)",
246  $user
247  );
248 
249  $user = User::newFromName( '10.11.12.13', false );
250  $id = $user->getActorId( wfGetDB( DB_MASTER ) );
251  $this->assertConditions(
252  [ # expected
253  "NOT((rc_user_text = '10.11.12.13'))",
254  ],
255  [
256  'hidemyself' => 1,
257  ],
258  "rc conditions: hidemyself=1 (anon)",
259  $user
260  );
261  }
262 
263  public function testRcHidebyothersFilter() {
264  $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
265  $this->overrideMwServices();
266 
267  $user = $this->getTestUser()->getUser();
268  $user->getActorId( wfGetDB( DB_MASTER ) );
269  $this->assertConditions(
270  [ # expected
271  "(rc_actor = '{$user->getActorId()}')",
272  ],
273  [
274  'hidebyothers' => 1,
275  ],
276  "rc conditions: hidebyothers=1 (logged in)",
277  $user
278  );
279 
280  $user = User::newFromName( '10.11.12.13', false );
281  $id = $user->getActorId( wfGetDB( DB_MASTER ) );
282  $this->assertConditions(
283  [ # expected
284  "(rc_actor = '{$user->getActorId()}')",
285  ],
286  [
287  'hidebyothers' => 1,
288  ],
289  "rc conditions: hidebyothers=1 (anon)",
290  $user
291  );
292  }
293 
294  public function testRcHidebyothersFilter_old() {
295  $this->setMwGlobals(
296  'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
297  );
298  $this->overrideMwServices();
299 
300  $user = $this->getTestUser()->getUser();
301  $user->getActorId( wfGetDB( DB_MASTER ) );
302  $this->assertConditions(
303  [ # expected
304  "(rc_user_text = '{$user->getName()}')",
305  ],
306  [
307  'hidebyothers' => 1,
308  ],
309  "rc conditions: hidebyothers=1 (logged in)",
310  $user
311  );
312 
313  $user = User::newFromName( '10.11.12.13', false );
314  $id = $user->getActorId( wfGetDB( DB_MASTER ) );
315  $this->assertConditions(
316  [ # expected
317  "(rc_user_text = '10.11.12.13')",
318  ],
319  [
320  'hidebyothers' => 1,
321  ],
322  "rc conditions: hidebyothers=1 (anon)",
323  $user
324  );
325  }
326 
327  public function testRcHidepageedits() {
328  $this->assertConditions(
329  [ # expected
330  "rc_type != '0'",
331  ],
332  [
333  'hidepageedits' => 1,
334  ],
335  "rc conditions: hidepageedits=1"
336  );
337  }
338 
339  public function testRcHidenewpages() {
340  $this->assertConditions(
341  [ # expected
342  "rc_type != '1'",
343  ],
344  [
345  'hidenewpages' => 1,
346  ],
347  "rc conditions: hidenewpages=1"
348  );
349  }
350 
351  public function testRcHidelog() {
352  $this->assertConditions(
353  [ # expected
354  "rc_type != '3'",
355  ],
356  [
357  'hidelog' => 1,
358  ],
359  "rc conditions: hidelog=1"
360  );
361  }
362 
363  public function testRcHidehumans() {
364  $this->assertConditions(
365  [ # expected
366  'rc_bot' => 1,
367  ],
368  [
369  'hidebots' => 0,
370  'hidehumans' => 1,
371  ],
372  "rc conditions: hidebots=0 hidehumans=1"
373  );
374  }
375 
377  $this->setMwGlobals( 'wgUseRCPatrol', false );
378  $user = $this->getTestUser()->getUser();
379  $this->assertConditions(
380  [ # expected
381  ],
382  [
383  'hidepatrolled' => 1,
384  ],
385  "rc conditions: hidepatrolled=1 (user not allowed)",
386  $user
387  );
388  }
389 
391  $this->setMwGlobals( 'wgUseRCPatrol', false );
392  $user = $this->getTestUser()->getUser();
393  $this->assertConditions(
394  [ # expected
395  ],
396  [
397  'hideunpatrolled' => 1,
398  ],
399  "rc conditions: hideunpatrolled=1 (user not allowed)",
400  $user
401  );
402  }
403 
404  public function testRcHidepatrolledFilter() {
405  $user = $this->getTestSysop()->getUser();
406  $this->assertConditions(
407  [ # expected
408  'rc_patrolled' => 0,
409  ],
410  [
411  'hidepatrolled' => 1,
412  ],
413  "rc conditions: hidepatrolled=1",
414  $user
415  );
416  }
417 
418  public function testRcHideunpatrolledFilter() {
419  $user = $this->getTestSysop()->getUser();
420  $this->assertConditions(
421  [ # expected
422  'rc_patrolled' => [ 1, 2 ],
423  ],
424  [
425  'hideunpatrolled' => 1,
426  ],
427  "rc conditions: hideunpatrolled=1",
428  $user
429  );
430  }
431 
432  public function testRcReviewStatusFilter() {
433  $user = $this->getTestSysop()->getUser();
434  $this->assertConditions(
435  [ #expected
436  'rc_patrolled' => 1,
437  ],
438  [
439  'reviewStatus' => 'manual'
440  ],
441  "rc conditions: reviewStatus=manual",
442  $user
443  );
444  $this->assertConditions(
445  [ #expected
446  'rc_patrolled' => [ 0, 2 ],
447  ],
448  [
449  'reviewStatus' => 'unpatrolled;auto'
450  ],
451  "rc conditions: reviewStatus=unpatrolled;auto",
452  $user
453  );
454  }
455 
456  public function testRcHideminorFilter() {
457  $this->assertConditions(
458  [ # expected
459  "rc_minor = 0",
460  ],
461  [
462  'hideminor' => 1,
463  ],
464  "rc conditions: hideminor=1"
465  );
466  }
467 
468  public function testRcHidemajorFilter() {
469  $this->assertConditions(
470  [ # expected
471  "rc_minor = 1",
472  ],
473  [
474  'hidemajor' => 1,
475  ],
476  "rc conditions: hidemajor=1"
477  );
478  }
479 
480  public function testHideCategorization() {
481  $this->assertConditions(
482  [
483  # expected
484  "rc_type != '6'"
485  ],
486  [
487  'hidecategorization' => 1
488  ],
489  "rc conditions: hidecategorization=1"
490  );
491  }
492 
493  public function testFilterUserExpLevelAll() {
494  $this->assertConditions(
495  [
496  # expected
497  ],
498  [
499  'userExpLevel' => 'registered;unregistered;newcomer;learner;experienced',
500  ],
501  "rc conditions: userExpLevel=registered;unregistered;newcomer;learner;experienced"
502  );
503  }
504 
506  $this->assertConditions(
507  [
508  # expected
509  ],
510  [
511  'userExpLevel' => 'registered;unregistered',
512  ],
513  "rc conditions: userExpLevel=registered;unregistered"
514  );
515  }
516 
518  $this->assertConditions(
519  [
520  # expected
521  ],
522  [
523  'userExpLevel' => 'registered;unregistered;learner',
524  ],
525  "rc conditions: userExpLevel=registered;unregistered;learner"
526  );
527  }
528 
530  $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
531  $this->overrideMwServices();
532 
533  $this->assertConditions(
534  [
535  # expected
536  'actor_rc_user.actor_user IS NOT NULL',
537  ],
538  [
539  'userExpLevel' => 'newcomer;learner;experienced',
540  ],
541  "rc conditions: userExpLevel=newcomer;learner;experienced"
542  );
543  }
544 
546  $this->setMwGlobals(
547  'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
548  );
549  $this->overrideMwServices();
550 
551  $this->assertConditions(
552  [
553  # expected
554  'rc_user != 0',
555  ],
556  [
557  'userExpLevel' => 'newcomer;learner;experienced',
558  ],
559  "rc conditions: userExpLevel=newcomer;learner;experienced"
560  );
561  }
562 
564  $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
565  $this->overrideMwServices();
566 
567  $this->assertConditions(
568  [
569  # expected
570  'actor_rc_user.actor_user IS NOT NULL',
571  ],
572  [
573  'userExpLevel' => 'registered',
574  ],
575  "rc conditions: userExpLevel=registered"
576  );
577  }
578 
580  $this->setMwGlobals(
581  'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
582  );
583  $this->overrideMwServices();
584 
585  $this->assertConditions(
586  [
587  # expected
588  'rc_user != 0',
589  ],
590  [
591  'userExpLevel' => 'registered',
592  ],
593  "rc conditions: userExpLevel=registered"
594  );
595  }
596 
598  $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
599  $this->overrideMwServices();
600 
601  $this->assertConditions(
602  [
603  # expected
604  'actor_rc_user.actor_user IS NULL',
605  ],
606  [
607  'userExpLevel' => 'unregistered',
608  ],
609  "rc conditions: userExpLevel=unregistered"
610  );
611  }
612 
614  $this->setMwGlobals(
615  'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
616  );
617  $this->overrideMwServices();
618 
619  $this->assertConditions(
620  [
621  # expected
622  'rc_user = 0',
623  ],
624  [
625  'userExpLevel' => 'unregistered',
626  ],
627  "rc conditions: userExpLevel=unregistered"
628  );
629  }
630 
632  $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
633  $this->overrideMwServices();
634 
635  $this->assertConditions(
636  [
637  # expected
638  'actor_rc_user.actor_user IS NOT NULL',
639  ],
640  [
641  'userExpLevel' => 'registered;learner',
642  ],
643  "rc conditions: userExpLevel=registered;learner"
644  );
645  }
646 
648  $this->setMwGlobals(
649  'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
650  );
651  $this->overrideMwServices();
652 
653  $this->assertConditions(
654  [
655  # expected
656  'rc_user != 0',
657  ],
658  [
659  'userExpLevel' => 'registered;learner',
660  ],
661  "rc conditions: userExpLevel=registered;learner"
662  );
663  }
664 
666  $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
667  $this->overrideMwServices();
668 
669  $conds = $this->buildQuery( [ 'userExpLevel' => 'unregistered;experienced' ] );
670 
671  $this->assertRegExp(
672  '/\(actor_rc_user\.actor_user IS NULL\) OR '
673  . '\(\(user_editcount >= 500\) AND \(user_registration <= \'[^\']+\'\)\)/',
674  reset( $conds ),
675  "rc conditions: userExpLevel=unregistered;experienced"
676  );
677  }
678 
680  $this->setMwGlobals(
681  'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
682  );
683  $this->overrideMwServices();
684 
685  $conds = $this->buildQuery( [ 'userExpLevel' => 'unregistered;experienced' ] );
686 
687  $this->assertRegExp(
688  '/\(rc_user = 0\) OR '
689  . '\(\(user_editcount >= 500\) AND \(user_registration <= \'[^\']+\'\)\)/',
690  reset( $conds ),
691  "rc conditions: userExpLevel=unregistered;experienced"
692  );
693  }
694 
695  public function testFilterUserExpLevel() {
696  $now = time();
697  $this->setMwGlobals( [
698  'wgLearnerEdits' => 10,
699  'wgLearnerMemberSince' => 4,
700  'wgExperiencedUserEdits' => 500,
701  'wgExperiencedUserMemberSince' => 30,
702  ] );
703 
704  $this->createUsers( [
705  'Newcomer1' => [ 'edits' => 2, 'days' => 2 ],
706  'Newcomer2' => [ 'edits' => 12, 'days' => 3 ],
707  'Newcomer3' => [ 'edits' => 8, 'days' => 5 ],
708  'Learner1' => [ 'edits' => 15, 'days' => 10 ],
709  'Learner2' => [ 'edits' => 450, 'days' => 20 ],
710  'Learner3' => [ 'edits' => 460, 'days' => 33 ],
711  'Learner4' => [ 'edits' => 525, 'days' => 28 ],
712  'Experienced1' => [ 'edits' => 538, 'days' => 33 ],
713  ], $now );
714 
715  // newcomers only
716  $this->assertArrayEquals(
717  [ 'Newcomer1', 'Newcomer2', 'Newcomer3' ],
718  $this->fetchUsers( [ 'newcomer' ], $now )
719  );
720 
721  // newcomers and learner
722  $this->assertArrayEquals(
723  [
724  'Newcomer1', 'Newcomer2', 'Newcomer3',
725  'Learner1', 'Learner2', 'Learner3', 'Learner4',
726  ],
727  $this->fetchUsers( [ 'newcomer', 'learner' ], $now )
728  );
729 
730  // newcomers and more learner
731  $this->assertArrayEquals(
732  [
733  'Newcomer1', 'Newcomer2', 'Newcomer3',
734  'Experienced1',
735  ],
736  $this->fetchUsers( [ 'newcomer', 'experienced' ], $now )
737  );
738 
739  // learner only
740  $this->assertArrayEquals(
741  [ 'Learner1', 'Learner2', 'Learner3', 'Learner4' ],
742  $this->fetchUsers( [ 'learner' ], $now )
743  );
744 
745  // more experienced only
746  $this->assertArrayEquals(
747  [ 'Experienced1' ],
748  $this->fetchUsers( [ 'experienced' ], $now )
749  );
750 
751  // learner and more experienced
752  $this->assertArrayEquals(
753  [
754  'Learner1', 'Learner2', 'Learner3', 'Learner4',
755  'Experienced1',
756  ],
757  $this->fetchUsers( [ 'learner', 'experienced' ], $now )
758  );
759  }
760 
761  private function createUsers( $specs, $now ) {
762  $dbw = wfGetDB( DB_MASTER );
763  foreach ( $specs as $name => $spec ) {
765  $name,
766  [
767  'editcount' => $spec['edits'],
768  'registration' => $dbw->timestamp( $this->daysAgo( $spec['days'], $now ) ),
769  'email' => 'ut',
770  ]
771  );
772  }
773  }
774 
775  private function fetchUsers( $filters, $now ) {
776  $tables = [];
777  $conds = [];
778  $fields = [];
779  $query_options = [];
780  $join_conds = [];
781 
782  sort( $filters );
783 
784  call_user_func_array(
785  [ $this->changesListSpecialPage, 'filterOnUserExperienceLevel' ],
786  [
787  get_class( $this->changesListSpecialPage ),
788  $this->changesListSpecialPage->getContext(),
789  $this->changesListSpecialPage->getDB(),
790  &$tables,
791  &$fields,
792  &$conds,
793  &$query_options,
794  &$join_conds,
795  $filters,
796  $now
797  ]
798  );
799 
800  // @todo: This is not at all safe or sane. It just blindly assumes
801  // nothing in $conds depends on any other tables.
802  $result = wfGetDB( DB_MASTER )->select(
803  'user',
804  'user_name',
805  array_filter( $conds ) + [ 'user_email' => 'ut' ]
806  );
807 
808  $usernames = [];
809  foreach ( $result as $row ) {
810  $usernames[] = $row->user_name;
811  }
812 
813  return $usernames;
814  }
815 
816  private function daysAgo( $days, $now ) {
817  $secondsPerDay = 86400;
818  return $now - $days * $secondsPerDay;
819  }
820 
821  public function testGetStructuredFilterJsData() {
822  $this->changesListSpecialPage->filterGroups = [];
823 
824  $definition = [
825  [
826  'name' => 'gub-group',
827  'title' => 'gub-group-title',
829  'filters' => [
830  [
831  'name' => 'hidefoo',
832  'label' => 'foo-label',
833  'description' => 'foo-description',
834  'default' => true,
835  'showHide' => 'showhidefoo',
836  'priority' => 2,
837  ],
838  [
839  'name' => 'hidebar',
840  'label' => 'bar-label',
841  'description' => 'bar-description',
842  'default' => false,
843  'priority' => 4,
844  ]
845  ],
846  ],
847 
848  [
849  'name' => 'des-group',
850  'title' => 'des-group-title',
852  'isFullCoverage' => true,
853  'filters' => [
854  [
855  'name' => 'grault',
856  'label' => 'grault-label',
857  'description' => 'grault-description',
858  ],
859  [
860  'name' => 'garply',
861  'label' => 'garply-label',
862  'description' => 'garply-description',
863  ],
864  ],
865  'queryCallable' => function () {
866  },
868  ],
869 
870  [
871  'name' => 'unstructured',
873  'filters' => [
874  [
875  'name' => 'hidethud',
876  'showHide' => 'showhidethud',
877  'default' => true,
878  ],
879 
880  [
881  'name' => 'hidemos',
882  'showHide' => 'showhidemos',
883  'default' => false,
884  ],
885  ],
886  ],
887 
888  ];
889 
890  $this->changesListSpecialPage->registerFiltersFromDefinitions( $definition );
891 
892  $this->assertArrayEquals(
893  [
894  // Filters that only display in the unstructured UI are
895  // are not included, and neither are groups that would
896  // be empty due to the above.
897  'groups' => [
898  [
899  'name' => 'gub-group',
900  'title' => 'gub-group-title',
902  'priority' => -1,
903  'filters' => [
904  [
905  'name' => 'hidebar',
906  'label' => 'bar-label',
907  'description' => 'bar-description',
908  'default' => false,
909  'priority' => 4,
910  'cssClass' => null,
911  'conflicts' => [],
912  'subset' => [],
913  'defaultHighlightColor' => null
914  ],
915  [
916  'name' => 'hidefoo',
917  'label' => 'foo-label',
918  'description' => 'foo-description',
919  'default' => true,
920  'priority' => 2,
921  'cssClass' => null,
922  'conflicts' => [],
923  'subset' => [],
924  'defaultHighlightColor' => null
925  ],
926  ],
927  'fullCoverage' => true,
928  'conflicts' => [],
929  ],
930 
931  [
932  'name' => 'des-group',
933  'title' => 'des-group-title',
935  'priority' => -2,
936  'fullCoverage' => true,
937  'filters' => [
938  [
939  'name' => 'grault',
940  'label' => 'grault-label',
941  'description' => 'grault-description',
942  'cssClass' => null,
943  'priority' => -2,
944  'conflicts' => [],
945  'subset' => [],
946  'defaultHighlightColor' => null
947  ],
948  [
949  'name' => 'garply',
950  'label' => 'garply-label',
951  'description' => 'garply-description',
952  'cssClass' => null,
953  'priority' => -3,
954  'conflicts' => [],
955  'subset' => [],
956  'defaultHighlightColor' => null
957  ],
958  ],
959  'conflicts' => [],
960  'separator' => ';',
962  ],
963  ],
964  'messageKeys' => [
965  'gub-group-title',
966  'bar-label',
967  'bar-description',
968  'foo-label',
969  'foo-description',
970  'des-group-title',
971  'grault-label',
972  'grault-description',
973  'garply-label',
974  'garply-description',
975  ],
976  ],
977  $this->changesListSpecialPage->getStructuredFilterJsData(), false, true
980  );
981  }
982 
983  public function provideParseParameters() {
984  return [
985  [ 'hidebots', [ 'hidebots' => true ] ],
986 
987  [ 'bots', [ 'hidebots' => false ] ],
988 
989  [ 'hideminor', [ 'hideminor' => true ] ],
990 
991  [ 'minor', [ 'hideminor' => false ] ],
992 
993  [ 'hidemajor', [ 'hidemajor' => true ] ],
994 
995  [ 'hideliu', [ 'hideliu' => true ] ],
996 
997  [ 'hidepatrolled', [ 'hidepatrolled' => true ] ],
998 
999  [ 'hideunpatrolled', [ 'hideunpatrolled' => true ] ],
1000 
1001  [ 'hideanons', [ 'hideanons' => true ] ],
1002 
1003  [ 'hidemyself', [ 'hidemyself' => true ] ],
1004 
1005  [ 'hidebyothers', [ 'hidebyothers' => true ] ],
1006 
1007  [ 'hidehumans', [ 'hidehumans' => true ] ],
1008 
1009  [ 'hidepageedits', [ 'hidepageedits' => true ] ],
1010 
1011  [ 'pagedits', [ 'hidepageedits' => false ] ],
1012 
1013  [ 'hidenewpages', [ 'hidenewpages' => true ] ],
1014 
1015  [ 'hidecategorization', [ 'hidecategorization' => true ] ],
1016 
1017  [ 'hidelog', [ 'hidelog' => true ] ],
1018 
1019  [
1020  'userExpLevel=learner;experienced',
1021  [
1022  'userExpLevel' => 'learner;experienced'
1023  ],
1024  ],
1025 
1026  // A few random combos
1027  [
1028  'bots,hideliu,hidemyself',
1029  [
1030  'hidebots' => false,
1031  'hideliu' => true,
1032  'hidemyself' => true,
1033  ],
1034  ],
1035 
1036  [
1037  'minor,hideanons,categorization',
1038  [
1039  'hideminor' => false,
1040  'hideanons' => true,
1041  'hidecategorization' => false,
1042  ]
1043  ],
1044 
1045  [
1046  'hidehumans,bots,hidecategorization',
1047  [
1048  'hidehumans' => true,
1049  'hidebots' => false,
1050  'hidecategorization' => true,
1051  ],
1052  ],
1053 
1054  [
1055  'hidemyself,userExpLevel=newcomer;learner,hideminor',
1056  [
1057  'hidemyself' => true,
1058  'hideminor' => true,
1059  'userExpLevel' => 'newcomer;learner',
1060  ],
1061  ],
1062  ];
1063  }
1064 
1065  public function provideGetFilterConflicts() {
1066  return [
1067  [
1068  "parameters" => [],
1069  "expectedConflicts" => false,
1070  ],
1071  [
1072  "parameters" => [
1073  "hideliu" => true,
1074  "userExpLevel" => "newcomer",
1075  ],
1076  "expectedConflicts" => false,
1077  ],
1078  [
1079  "parameters" => [
1080  "hideanons" => true,
1081  "userExpLevel" => "learner",
1082  ],
1083  "expectedConflicts" => false,
1084  ],
1085  [
1086  "parameters" => [
1087  "hidemajor" => true,
1088  "hidenewpages" => true,
1089  "hidepageedits" => true,
1090  "hidecategorization" => false,
1091  "hidelog" => true,
1092  "hideWikidata" => true,
1093  ],
1094  "expectedConflicts" => true,
1095  ],
1096  [
1097  "parameters" => [
1098  "hidemajor" => true,
1099  "hidenewpages" => false,
1100  "hidepageedits" => true,
1101  "hidecategorization" => false,
1102  "hidelog" => false,
1103  "hideWikidata" => true,
1104  ],
1105  "expectedConflicts" => true,
1106  ],
1107  [
1108  "parameters" => [
1109  "hidemajor" => true,
1110  "hidenewpages" => false,
1111  "hidepageedits" => false,
1112  "hidecategorization" => true,
1113  "hidelog" => true,
1114  "hideWikidata" => true,
1115  ],
1116  "expectedConflicts" => false,
1117  ],
1118  [
1119  "parameters" => [
1120  "hideminor" => true,
1121  "hidenewpages" => true,
1122  "hidepageedits" => true,
1123  "hidecategorization" => false,
1124  "hidelog" => true,
1125  "hideWikidata" => true,
1126  ],
1127  "expectedConflicts" => false,
1128  ],
1129  ];
1130  }
1131 
1135  public function testGetFilterConflicts( $parameters, $expectedConflicts ) {
1136  $context = new RequestContext;
1137  $context->setRequest( new FauxRequest( $parameters ) );
1138  $this->changesListSpecialPage->setContext( $context );
1139 
1140  $this->assertEquals(
1141  $expectedConflicts,
1142  $this->changesListSpecialPage->areFiltersInConflict()
1143  );
1144  }
1145 
1146  public function validateOptionsProvider() {
1147  return [
1148  [
1149  [ 'hideanons' => 1, 'hideliu' => 1, 'hidebots' => 1 ],
1150  true,
1151  [ 'userExpLevel' => 'unregistered', 'hidebots' => 1, ],
1152  true,
1153  ],
1154  [
1155  [ 'hideanons' => 1, 'hideliu' => 1, 'hidebots' => 0 ],
1156  true,
1157  [ 'hidebots' => 0, 'hidehumans' => 1 ],
1158  true,
1159  ],
1160  [
1161  [ 'hideanons' => 1 ],
1162  true,
1163  [ 'userExpLevel' => 'registered' ],
1164  true,
1165  ],
1166  [
1167  [ 'hideliu' => 1 ],
1168  true,
1169  [ 'userExpLevel' => 'unregistered' ],
1170  true,
1171  ],
1172  [
1173  [ 'hideanons' => 1, 'hidebots' => 1 ],
1174  true,
1175  [ 'userExpLevel' => 'registered', 'hidebots' => 1 ],
1176  true,
1177  ],
1178  [
1179  [ 'hideliu' => 1, 'hidebots' => 0 ],
1180  true,
1181  [ 'userExpLevel' => 'unregistered', 'hidebots' => 0 ],
1182  true,
1183  ],
1184  [
1185  [ 'hidemyself' => 1, 'hidebyothers' => 1 ],
1186  true,
1187  [],
1188  true,
1189  ],
1190  [
1191  [ 'hidebots' => 1, 'hidehumans' => 1 ],
1192  true,
1193  [],
1194  true,
1195  ],
1196  [
1197  [ 'hidepatrolled' => 1, 'hideunpatrolled' => 1 ],
1198  true,
1199  [],
1200  true,
1201  ],
1202  [
1203  [ 'hideminor' => 1, 'hidemajor' => 1 ],
1204  true,
1205  [],
1206  true,
1207  ],
1208  [
1209  // changeType
1210  [ 'hidepageedits' => 1, 'hidenewpages' => 1, 'hidecategorization' => 1, 'hidelog' => 1, ],
1211  true,
1212  [],
1213  true,
1214  ],
1215  ];
1216  }
1217 }
Test class for ChangesListSpecialPage class.
const NS_MAIN
Definition: Defines.php:60
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:49
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:39
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:284
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)
const SCHEMA_COMPAT_NEW
Definition: Defines.php:287
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:281
static createNew( $name, $params=[])
Add a user to the database, return the user object.
Definition: User.php:4174
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:594
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