Debian Codegraph @

includes/specialpage/SpecialPageFactory.php

raw symbols SCIP
1 <?php
2 /**
3 * Factory for handling the special page list and generating SpecialPage objects.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 * @defgroup SpecialPage SpecialPage
23 */
24
25 namespace MediaWiki\SpecialPage;
26
27 use MediaWiki\Config\ServiceOptions;
28 use MediaWiki\Context\IContextSource;
29 use MediaWiki\Context\RequestContext;
30 use MediaWiki\HookContainer\HookContainer;
31 use MediaWiki\HookContainer\HookRunner;
32 use MediaWiki\Language\Language;
33 use MediaWiki\Linker\LinkRenderer;
34 use MediaWiki\MainConfigNames;
35 use MediaWiki\Page\PageReference;
36 use MediaWiki\Profiler\ProfilingContext;
37 use MediaWiki\Specials\Redirects\SpecialAllMyUploads;
38 use MediaWiki\Specials\Redirects\SpecialListAdmins;
39 use MediaWiki\Specials\Redirects\SpecialListBots;
40 use MediaWiki\Specials\Redirects\SpecialMycontributions;
41 use MediaWiki\Specials\Redirects\SpecialMylog;
42 use MediaWiki\Specials\Redirects\SpecialMypage;
43 use MediaWiki\Specials\Redirects\SpecialMytalk;
44 use MediaWiki\Specials\Redirects\SpecialMyuploads;
45 use MediaWiki\Specials\Redirects\SpecialTalkPage;
46 use MediaWiki\Specials\SpecialActiveUsers;
47 use MediaWiki\Specials\SpecialAllMessages;
48 use MediaWiki\Specials\SpecialAllPages;
49 use MediaWiki\Specials\SpecialAncientPages;
50 use MediaWiki\Specials\SpecialApiHelp;
51 use MediaWiki\Specials\SpecialApiSandbox;
52 use MediaWiki\Specials\SpecialAuthenticationPopupSuccess;
53 use MediaWiki\Specials\SpecialAutoblockList;
54 use MediaWiki\Specials\SpecialBlankpage;
55 use MediaWiki\Specials\SpecialBlock;
56 use MediaWiki\Specials\SpecialBlockList;
57 use MediaWiki\Specials\SpecialBookSources;
58 use MediaWiki\Specials\SpecialBotPasswords;
59 use MediaWiki\Specials\SpecialBrokenRedirects;
60 use MediaWiki\Specials\SpecialCategories;
61 use MediaWiki\Specials\SpecialChangeContentModel;
62 use MediaWiki\Specials\SpecialChangeCredentials;
63 use MediaWiki\Specials\SpecialChangeEmail;
64 use MediaWiki\Specials\SpecialChangePassword;
65 use MediaWiki\Specials\SpecialComparePages;
66 use MediaWiki\Specials\SpecialConfirmEmail;
67 use MediaWiki\Specials\SpecialContribute;
68 use MediaWiki\Specials\SpecialContributions;
69 use MediaWiki\Specials\SpecialCreateAccount;
70 use MediaWiki\Specials\SpecialDeadendPages;
71 use MediaWiki\Specials\SpecialDeletedContributions;
72 use MediaWiki\Specials\SpecialDeletePage;
73 use MediaWiki\Specials\SpecialDiff;
74 use MediaWiki\Specials\SpecialDoubleRedirects;
75 use MediaWiki\Specials\SpecialEditPage;
76 use MediaWiki\Specials\SpecialEditRecovery;
77 use MediaWiki\Specials\SpecialEditTags;
78 use MediaWiki\Specials\SpecialEditWatchlist;
79 use MediaWiki\Specials\SpecialEmailInvalidate;
80 use MediaWiki\Specials\SpecialEmailUser;
81 use MediaWiki\Specials\SpecialExpandTemplates;
82 use MediaWiki\Specials\SpecialExport;
83 use MediaWiki\Specials\SpecialFewestRevisions;
84 use MediaWiki\Specials\SpecialFileDuplicateSearch;
85 use MediaWiki\Specials\SpecialFilepath;
86 use MediaWiki\Specials\SpecialGoToInterwiki;
87 use MediaWiki\Specials\SpecialImport;
88 use MediaWiki\Specials\SpecialJavaScriptTest;
89 use MediaWiki\Specials\SpecialLinkAccounts;
90 use MediaWiki\Specials\SpecialLinkSearch;
91 use MediaWiki\Specials\SpecialListDuplicatedFiles;
92 use MediaWiki\Specials\SpecialListFiles;
93 use MediaWiki\Specials\SpecialListGrants;
94 use MediaWiki\Specials\SpecialListGroupRights;
95 use MediaWiki\Specials\SpecialListRedirects;
96 use MediaWiki\Specials\SpecialListUsers;
97 use MediaWiki\Specials\SpecialLockdb;
98 use MediaWiki\Specials\SpecialLog;
99 use MediaWiki\Specials\SpecialLonelyPages;
100 use MediaWiki\Specials\SpecialLongPages;
101 use MediaWiki\Specials\SpecialMediaStatistics;
102 use MediaWiki\Specials\SpecialMergeHistory;
103 use MediaWiki\Specials\SpecialMIMESearch;
104 use MediaWiki\Specials\SpecialMostCategories;
105 use MediaWiki\Specials\SpecialMostImages;
106 use MediaWiki\Specials\SpecialMostInterwikis;
107 use MediaWiki\Specials\SpecialMostLinked;
108 use MediaWiki\Specials\SpecialMostLinkedCategories;
109 use MediaWiki\Specials\SpecialMostLinkedTemplates;
110 use MediaWiki\Specials\SpecialMostRevisions;
111 use MediaWiki\Specials\SpecialMovePage;
112 use MediaWiki\Specials\SpecialMute;
113 use MediaWiki\Specials\SpecialMyLanguage;
114 use MediaWiki\Specials\SpecialNamespaceInfo;
115 use MediaWiki\Specials\SpecialNewFiles;
116 use MediaWiki\Specials\SpecialNewPages;
117 use MediaWiki\Specials\SpecialNewSection;
118 use MediaWiki\Specials\SpecialPageData;
119 use MediaWiki\Specials\SpecialPageHistory;
120 use MediaWiki\Specials\SpecialPageInfo;
121 use MediaWiki\Specials\SpecialPageLanguage;
122 use MediaWiki\Specials\SpecialPagesWithProp;
123 use MediaWiki\Specials\SpecialPasswordPolicies;
124 use MediaWiki\Specials\SpecialPasswordReset;
125 use MediaWiki\Specials\SpecialPermanentLink;
126 use MediaWiki\Specials\SpecialPreferences;
127 use MediaWiki\Specials\SpecialPrefixIndex;
128 use MediaWiki\Specials\SpecialProtectedPages;
129 use MediaWiki\Specials\SpecialProtectedTitles;
130 use MediaWiki\Specials\SpecialProtectPage;
131 use MediaWiki\Specials\SpecialPurge;
132 use MediaWiki\Specials\SpecialRandomInCategory;
133 use MediaWiki\Specials\SpecialRandomPage;
134 use MediaWiki\Specials\SpecialRandomRedirect;
135 use MediaWiki\Specials\SpecialRandomRootPage;
136 use MediaWiki\Specials\SpecialRecentChanges;
137 use MediaWiki\Specials\SpecialRecentChangesLinked;
138 use MediaWiki\Specials\SpecialRedirect;
139 use MediaWiki\Specials\SpecialRemoveCredentials;
140 use MediaWiki\Specials\SpecialRenameUser;
141 use MediaWiki\Specials\SpecialResetTokens;
142 use MediaWiki\Specials\SpecialRevisionDelete;
143 use MediaWiki\Specials\SpecialRunJobs;
144 use MediaWiki\Specials\SpecialSearch;
145 use MediaWiki\Specials\SpecialShortPages;
146 use MediaWiki\Specials\SpecialSpecialPages;
147 use MediaWiki\Specials\SpecialStatistics;
148 use MediaWiki\Specials\SpecialTags;
149 use MediaWiki\Specials\SpecialTrackingCategories;
150 use MediaWiki\Specials\SpecialUnblock;
151 use MediaWiki\Specials\SpecialUncategorizedCategories;
152 use MediaWiki\Specials\SpecialUncategorizedImages;
153 use MediaWiki\Specials\SpecialUncategorizedPages;
154 use MediaWiki\Specials\SpecialUncategorizedTemplates;
155 use MediaWiki\Specials\SpecialUndelete;
156 use MediaWiki\Specials\SpecialUnlinkAccounts;
157 use MediaWiki\Specials\SpecialUnlockdb;
158 use MediaWiki\Specials\SpecialUnusedCategories;
159 use MediaWiki\Specials\SpecialUnusedImages;
160 use MediaWiki\Specials\SpecialUnusedTemplates;
161 use MediaWiki\Specials\SpecialUnwatchedPages;
162 use MediaWiki\Specials\SpecialUpload;
163 use MediaWiki\Specials\SpecialUploadStash;
164 use MediaWiki\Specials\SpecialUserLogin;
165 use MediaWiki\Specials\SpecialUserLogout;
166 use MediaWiki\Specials\SpecialUserRights;
167 use MediaWiki\Specials\SpecialVersion;
168 use MediaWiki\Specials\SpecialWantedCategories;
169 use MediaWiki\Specials\SpecialWantedFiles;
170 use MediaWiki\Specials\SpecialWantedPages;
171 use MediaWiki\Specials\SpecialWantedTemplates;
172 use MediaWiki\Specials\SpecialWatchlist;
173 use MediaWiki\Specials\SpecialWhatLinksHere;
174 use MediaWiki\Specials\SpecialWithoutInterwiki;
175 use MediaWiki\Title\Title;
176 use MediaWiki\Title\TitleFactory;
177 use MediaWiki\User\User;
178 use Profiler;
179 use Wikimedia\DebugInfo\DebugInfoTrait;
180 use Wikimedia\ObjectFactory\ObjectFactory;
181
182 /**
183 * Factory for handling the special page list and generating SpecialPage objects.
184 *
185 * To add a special page in an extension, add to $wgSpecialPages either
186 * an object instance or an array containing the name and constructor
187 * parameters. The latter is preferred for performance reasons.
188 *
189 * The object instantiated must be either an instance of SpecialPage or a
190 * sub-class thereof. It must have an execute() method, which sends the HTML
191 * for the special page to $wgOut. The parent class has an execute() method
192 * which distributes the call to the historical global functions. Additionally,
193 * execute() also checks if the user has the necessary access privileges
194 * and bails out if not.
195 *
196 * To add a core special page, use the similar static list in
197 * SpecialPageFactory::$list. To remove a core static special page at runtime, use
198 * a SpecialPage_initList hook.
199 *
200 * @ingroup SpecialPage
201 * @since 1.17
202 */
203 class SpecialPageFactory {
204 use DebugInfoTrait;
205
206 /**
207 * List of special page names to the subclass of SpecialPage which handles them.
208 */
209 private const CORE_LIST = [
210 // Maintenance Reports
211 'BrokenRedirects' => [
212 'class' => SpecialBrokenRedirects::class,
213 'services' => [
214 'ContentHandlerFactory',
215 'ConnectionProvider',
216 'LinkBatchFactory',
217 'RedirectLookup'
218 ]
219 ],
220 'Deadendpages' => [
221 'class' => SpecialDeadendPages::class,
222 'services' => [
223 'NamespaceInfo',
224 'ConnectionProvider',
225 'LinkBatchFactory',
226 'LanguageConverterFactory',
227 ]
228 ],
229 'DoubleRedirects' => [
230 'class' => SpecialDoubleRedirects::class,
231 'services' => [
232 'ContentHandlerFactory',
233 'LinkBatchFactory',
234 'ConnectionProvider',
235 ]
236 ],
237 'Longpages' => [
238 'class' => SpecialLongPages::class,
239 'services' => [
240 // Same as for Shortpages
241 'NamespaceInfo',
242 'ConnectionProvider',
243 'LinkBatchFactory',
244 ]
245 ],
246 'Ancientpages' => [
247 'class' => SpecialAncientPages::class,
248 'services' => [
249 'NamespaceInfo',
250 'ConnectionProvider',
251 'LinkBatchFactory',
252 'LanguageConverterFactory',
253 ]
254 ],
255 'Lonelypages' => [
256 'class' => SpecialLonelyPages::class,
257 'services' => [
258 'NamespaceInfo',
259 'ConnectionProvider',
260 'LinkBatchFactory',
261 'LanguageConverterFactory',
262 'LinksMigration',
263 ]
264 ],
265 'Fewestrevisions' => [
266 'class' => SpecialFewestRevisions::class,
267 'services' => [
268 // Same as for Mostrevisions
269 'NamespaceInfo',
270 'ConnectionProvider',
271 'LinkBatchFactory',
272 'LanguageConverterFactory',
273 ]
274 ],
275 'Withoutinterwiki' => [
276 'class' => SpecialWithoutInterwiki::class,
277 'services' => [
278 'NamespaceInfo',
279 'ConnectionProvider',
280 'LinkBatchFactory',
281 'LanguageConverterFactory',
282 ]
283 ],
284 'Protectedpages' => [
285 'class' => SpecialProtectedPages::class,
286 'services' => [
287 'LinkBatchFactory',
288 'ConnectionProvider',
289 'CommentStore',
290 'RowCommentFormatter',
291 'RestrictionStore',
292 ]
293 ],
294 'Protectedtitles' => [
295 'class' => SpecialProtectedTitles::class,
296 'services' => [
297 'LinkBatchFactory',
298 'ConnectionProvider',
299 ]
300 ],
301 'Shortpages' => [
302 'class' => SpecialShortPages::class,
303 'services' => [
304 // Same as for Longpages
305 'NamespaceInfo',
306 'ConnectionProvider',
307 'LinkBatchFactory',
308 ]
309 ],
310 'Uncategorizedcategories' => [
311 'class' => SpecialUncategorizedCategories::class,
312 'services' => [
313 // Same as for SpecialUncategorizedPages and SpecialUncategorizedTemplates
314 'NamespaceInfo',
315 'ConnectionProvider',
316 'LinkBatchFactory',
317 'LanguageConverterFactory',
318 ]
319 ],
320 'Uncategorizedimages' => [
321 'class' => SpecialUncategorizedImages::class,
322 'services' => [
323 'ConnectionProvider',
324 ]
325 ],
326 'Uncategorizedpages' => [
327 'class' => SpecialUncategorizedPages::class,
328 'services' => [
329 // Same as for SpecialUncategorizedCategories and SpecialUncategorizedTemplates
330 'NamespaceInfo',
331 'ConnectionProvider',
332 'LinkBatchFactory',
333 'LanguageConverterFactory',
334 ]
335 ],
336 'Uncategorizedtemplates' => [
337 'class' => SpecialUncategorizedTemplates::class,
338 'services' => [
339 // Same as for SpecialUncategorizedCategories and SpecialUncategorizedPages
340 'NamespaceInfo',
341 'ConnectionProvider',
342 'LinkBatchFactory',
343 'LanguageConverterFactory',
344 ]
345 ],
346 'Unusedcategories' => [
347 'class' => SpecialUnusedCategories::class,
348 'services' => [
349 'ConnectionProvider',
350 'LinkBatchFactory',
351 ]
352 ],
353 'Unusedimages' => [
354 'class' => SpecialUnusedImages::class,
355 'services' => [
356 'ConnectionProvider',
357 ]
358 ],
359 'Unusedtemplates' => [
360 'class' => SpecialUnusedTemplates::class,
361 'services' => [
362 'ConnectionProvider',
363 'LinksMigration',
364 ]
365 ],
366 'Unwatchedpages' => [
367 'class' => SpecialUnwatchedPages::class,
368 'services' => [
369 'LinkBatchFactory',
370 'ConnectionProvider',
371 'LanguageConverterFactory',
372 ]
373 ],
374 'Wantedcategories' => [
375 'class' => SpecialWantedCategories::class,
376 'services' => [
377 'ConnectionProvider',
378 'LinkBatchFactory',
379 'LanguageConverterFactory',
380 ]
381 ],
382 'Wantedfiles' => [
383 'class' => SpecialWantedFiles::class,
384 'services' => [
385 'RepoGroup',
386 'ConnectionProvider',
387 'LinkBatchFactory',
388 ]
389 ],
390 'Wantedpages' => [
391 'class' => SpecialWantedPages::class,
392 'services' => [
393 'ConnectionProvider',
394 'LinkBatchFactory',
395 'LinksMigration',
396 ]
397 ],
398 'Wantedtemplates' => [
399 'class' => SpecialWantedTemplates::class,
400 'services' => [
401 'ConnectionProvider',
402 'LinkBatchFactory',
403 'LinksMigration',
404 ]
405 ],
406
407 // List of pages
408 'Allpages' => [
409 'class' => SpecialAllPages::class,
410 'services' => [
411 'ConnectionProvider',
412 'SearchEngineFactory',
413 'PageStore',
414 ]
415 ],
416 'Prefixindex' => [
417 'class' => SpecialPrefixIndex::class,
418 'services' => [
419 'ConnectionProvider',
420 'LinkCache',
421 ]
422 ],
423 'Categories' => [
424 'class' => SpecialCategories::class,
425 'services' => [
426 'LinkBatchFactory',
427 'ConnectionProvider',
428 ]
429 ],
430 'Listredirects' => [
431 'class' => SpecialListRedirects::class,
432 'services' => [
433 'LinkBatchFactory',
434 'ConnectionProvider',
435 'WikiPageFactory',
436 'RedirectLookup'
437 ]
438 ],
439 'PagesWithProp' => [
440 'class' => SpecialPagesWithProp::class,
441 'services' => [
442 'ConnectionProvider',
443 ]
444 ],
445 'TrackingCategories' => [
446 'class' => SpecialTrackingCategories::class,
447 'services' => [
448 'LinkBatchFactory',
449 'TrackingCategories',
450 ]
451 ],
452
453 // Authentication
454 'Userlogin' => [
455 'class' => SpecialUserLogin::class,
456 'services' => [
457 'AuthManager',
458 ]
459 ],
460 'Userlogout' => [
461 'class' => SpecialUserLogout::class,
462 'services' => [
463 'TempUserConfig',
464 ],
465 ],
466 'CreateAccount' => [
467 'class' => SpecialCreateAccount::class,
468 'services' => [
469 'AuthManager',
470 'FormatterFactory',
471 ]
472 ],
473 'LinkAccounts' => [
474 'class' => SpecialLinkAccounts::class,
475 'services' => [
476 'AuthManager',
477 ]
478 ],
479 'UnlinkAccounts' => [
480 'class' => SpecialUnlinkAccounts::class,
481 'services' => [
482 'AuthManager',
483 ]
484 ],
485 'ChangeCredentials' => [
486 'class' => SpecialChangeCredentials::class,
487 'services' => [
488 'AuthManager',
489 ]
490 ],
491 'RemoveCredentials' => [
492 'class' => SpecialRemoveCredentials::class,
493 'services' => [
494 'AuthManager',
495 ]
496 ],
497 'AuthenticationPopupSuccess' => [
498 'class' => SpecialAuthenticationPopupSuccess::class,
499 'services' => [
500 'SkinFactory',
501 ]
502 ],
503
504 // Users and rights
505 'Activeusers' => [
506 'class' => SpecialActiveUsers::class,
507 'services' => [
508 'LinkBatchFactory',
509 'ConnectionProvider',
510 'UserGroupManager',
511 'UserIdentityLookup',
512 'HideUserUtils',
513 ]
514 ],
515 'Block' => [
516 'class' => SpecialBlock::class,
517 'services' => [
518 'BlockUtils',
519 'BlockPermissionCheckerFactory',
520 'BlockUserFactory',
521 'DatabaseBlockStore',
522 'UserNameUtils',
523 'UserNamePrefixSearch',
524 'BlockActionInfo',
525 'TitleFormatter',
526 'NamespaceInfo'
527 ]
528 ],
529 'Unblock' => [
530 'class' => SpecialUnblock::class,
531 'services' => [
532 'UnblockUserFactory',
533 'BlockUtils',
534 'DatabaseBlockStore',
535 'UserNameUtils',
536 'UserNamePrefixSearch',
537 'WatchlistManager',
538 ]
539 ],
540 'BlockList' => [
541 'class' => SpecialBlockList::class,
542 'services' => [
543 'LinkBatchFactory',
544 'DatabaseBlockStore',
545 'BlockRestrictionStore',
546 'ConnectionProvider',
547 'CommentStore',
548 'BlockUtils',
549 'HideUserUtils',
550 'BlockActionInfo',
551 'RowCommentFormatter',
552 ],
553 ],
554 'AutoblockList' => [
555 'class' => SpecialAutoblockList::class,
556 'services' => [
557 'LinkBatchFactory',
558 'BlockRestrictionStore',
559 'ConnectionProvider',
560 'CommentStore',
561 'BlockUtils',
562 'HideUserUtils',
563 'BlockActionInfo',
564 'RowCommentFormatter',
565 ],
566 ],
567 'ChangePassword' => [
568 'class' => SpecialChangePassword::class,
569 ],
570 'BotPasswords' => [
571 'class' => SpecialBotPasswords::class,
572 'services' => [
573 'PasswordFactory',
574 'AuthManager',
575 'CentralIdLookup',
576 'GrantsInfo',
577 'GrantsLocalization',
578 ]
579 ],
580 'PasswordReset' => [
581 'class' => SpecialPasswordReset::class,
582 'services' => [
583 'PasswordReset'
584 ]
585 ],
586 'DeletedContributions' => [
587 'class' => SpecialDeletedContributions::class,
588 'services' => [
589 'PermissionManager',
590 'ConnectionProvider',
591 'RevisionStore',
592 'NamespaceInfo',
593 'UserNameUtils',
594 'UserNamePrefixSearch',
595 'UserOptionsLookup',
596 'CommentFormatter',
597 'LinkBatchFactory',
598 'UserFactory',
599 'UserIdentityLookup',
600 'DatabaseBlockStore',
601 'TempUserConfig',
602 ]
603 ],
604 'Preferences' => [
605 'class' => SpecialPreferences::class,
606 'services' => [
607 'PreferencesFactory',
608 'UserOptionsManager',
609 ]
610 ],
611 'ResetTokens' => [
612 'class' => SpecialResetTokens::class,
613 ],
614 'Contributions' => [
615 'class' => SpecialContributions::class,
616 'services' => [
617 'LinkBatchFactory',
618 'PermissionManager',
619 'ConnectionProvider',
620 'RevisionStore',
621 'NamespaceInfo',
622 'UserNameUtils',
623 'UserNamePrefixSearch',
624 'UserOptionsLookup',
625 'CommentFormatter',
626 'UserFactory',
627 'UserIdentityLookup',
628 'DatabaseBlockStore',
629 'TempUserConfig',
630 ]
631 ],
632 'Listgrouprights' => [
633 'class' => SpecialListGroupRights::class,
634 'services' => [
635 'NamespaceInfo',
636 'UserGroupManager',
637 'LanguageConverterFactory',
638 'GroupPermissionsLookup',
639 ]
640 ],
641 'Listgrants' => [
642 'class' => SpecialListGrants::class,
643 'services' => [
644 'GrantsLocalization',
645 ]
646 ],
647 'Listusers' => [
648 'class' => SpecialListUsers::class,
649 'services' => [
650 'LinkBatchFactory',
651 'ConnectionProvider',
652 'UserGroupManager',
653 'UserIdentityLookup',
654 'HideUserUtils',
655 ]
656 ],
657 'Listadmins' => [
658 'class' => SpecialListAdmins::class,
659 ],
660 'Listbots' => [
661 'class' => SpecialListBots::class,
662 ],
663 'Userrights' => [
664 'class' => SpecialUserRights::class,
665 'services' => [
666 'UserGroupManagerFactory',
667 'UserNameUtils',
668 'UserNamePrefixSearch',
669 'UserFactory',
670 'ActorStoreFactory',
671 'WatchlistManager',
672 'TempUserConfig',
673 ]
674 ],
675 'EditWatchlist' => [
676 'class' => SpecialEditWatchlist::class,
677 'services' => [
678 'WatchedItemStore',
679 'TitleParser',
680 'GenderCache',
681 'LinkBatchFactory',
682 'NamespaceInfo',
683 'WikiPageFactory',
684 'WatchlistManager',
685 ]
686 ],
687 'PasswordPolicies' => [
688 'class' => SpecialPasswordPolicies::class,
689 'services' => [
690 'UserGroupManager',
691 ]
692 ],
693
694 // Recent changes and logs
695 'Newimages' => [
696 'class' => SpecialNewFiles::class,
697 'services' => [
698 'MimeAnalyzer',
699 'GroupPermissionsLookup',
700 'ConnectionProvider',
701 'LinkBatchFactory',
702 ]
703 ],
704 'Log' => [
705 'class' => SpecialLog::class,
706 'services' => [
707 'LinkBatchFactory',
708 'ConnectionProvider',
709 'ActorNormalization',
710 'UserIdentityLookup',
711 'UserNameUtils',
712 'LogFormatterFactory',
713 ]
714 ],
715 'Watchlist' => [
716 'class' => SpecialWatchlist::class,
717 'services' => [
718 'WatchedItemStore',
719 'WatchlistManager',
720 'UserOptionsLookup',
721 'ChangeTagsStore',
722 'UserIdentityUtils',
723 'TempUserConfig',
724 ]
725 ],
726 'Newpages' => [
727 'class' => SpecialNewPages::class,
728 'services' => [
729 'LinkBatchFactory',
730 'ContentHandlerFactory',
731 'GroupPermissionsLookup',
732 'RevisionLookup',
733 'NamespaceInfo',
734 'UserOptionsLookup',
735 'RowCommentFormatter',
736 'ChangeTagsStore',
737 'TempUserConfig',
738 ]
739 ],
740 'Recentchanges' => [
741 'class' => SpecialRecentChanges::class,
742 'services' => [
743 'WatchedItemStore',
744 'MessageCache',
745 'UserOptionsLookup',
746 'ChangeTagsStore',
747 'UserIdentityUtils',
748 'TempUserConfig',
749 ]
750 ],
751 'Recentchangeslinked' => [
752 'class' => SpecialRecentChangesLinked::class,
753 'services' => [
754 'WatchedItemStore',
755 'MessageCache',
756 'UserOptionsLookup',
757 'SearchEngineFactory',
758 'ChangeTagsStore',
759 'UserIdentityUtils',
760 'TempUserConfig',
761 ]
762 ],
763 'Tags' => [
764 'class' => SpecialTags::class,
765 'services' => [
766 'ChangeTagsStore',
767 ]
768 ],
769
770 // Media reports and uploads
771 'Listfiles' => [
772 'class' => SpecialListFiles::class,
773 'services' => [
774 'RepoGroup',
775 'ConnectionProvider',
776 'CommentStore',
777 'UserNameUtils',
778 'UserNamePrefixSearch',
779 'CommentFormatter',
780 'LinkBatchFactory',
781 ]
782 ],
783 'Filepath' => [
784 'class' => SpecialFilepath::class,
785 'services' => [
786 'SearchEngineFactory',
787 ]
788 ],
789 'MediaStatistics' => [
790 'class' => SpecialMediaStatistics::class,
791 'services' => [
792 'MimeAnalyzer',
793 'ConnectionProvider',
794 'LinkBatchFactory',
795 ]
796 ],
797 'MIMEsearch' => [
798 'class' => SpecialMIMESearch::class,
799 'services' => [
800 'ConnectionProvider',
801 'LinkBatchFactory',
802 'LanguageConverterFactory',
803 ]
804 ],
805 'FileDuplicateSearch' => [
806 'class' => SpecialFileDuplicateSearch::class,
807 'services' => [
808 'LinkBatchFactory',
809 'RepoGroup',
810 'SearchEngineFactory',
811 'LanguageConverterFactory',
812 ]
813 ],
814 'Upload' => [
815 'class' => SpecialUpload::class,
816 'services' => [
817 'RepoGroup',
818 'UserOptionsLookup',
819 'NamespaceInfo',
820 ]
821 ],
822 'UploadStash' => [
823 'class' => SpecialUploadStash::class,
824 'services' => [
825 'RepoGroup',
826 'HttpRequestFactory',
827 'UrlUtils',
828 'ConnectionProvider',
829 ]
830 ],
831 'ListDuplicatedFiles' => [
832 'class' => SpecialListDuplicatedFiles::class,
833 'services' => [
834 'ConnectionProvider',
835 'LinkBatchFactory',
836 ]
837 ],
838
839 // Data and tools
840 'ApiSandbox' => [
841 'class' => SpecialApiSandbox::class,
842 ],
843 'Statistics' => [
844 'class' => SpecialStatistics::class,
845 'services' => [
846 'UserGroupManager',
847 ]
848 ],
849 'Allmessages' => [
850 'class' => SpecialAllMessages::class,
851 'services' => [
852 'LanguageFactory',
853 'LanguageNameUtils',
854 'LocalisationCache',
855 'ConnectionProvider',
856 ]
857 ],
858 'Version' => [
859 'class' => SpecialVersion::class,
860 'services' => [
861 'ParserFactory',
862 'UrlUtils',
863 'ConnectionProvider',
864 ]
865 ],
866 'Lockdb' => [
867 'class' => SpecialLockdb::class,
868 ],
869 'Unlockdb' => [
870 'class' => SpecialUnlockdb::class,
871 ],
872 'NamespaceInfo' => [
873 'class' => SpecialNamespaceInfo::class,
874 'services' => [
875 'NamespaceInfo',
876 ],
877 ],
878
879 // Redirecting special pages
880 'LinkSearch' => [
881 'class' => SpecialLinkSearch::class,
882 'services' => [
883 'ConnectionProvider',
884 'LinkBatchFactory',
885 'UrlUtils',
886 ]
887 ],
888 'Randompage' => [
889 'class' => SpecialRandomPage::class,
890 'services' => [
891 'ConnectionProvider',
892 'NamespaceInfo',
893 ]
894 ],
895 'RandomInCategory' => [
896 'class' => SpecialRandomInCategory::class,
897 'services' => [
898 'ConnectionProvider',
899 ]
900 ],
901 'Randomredirect' => [
902 'class' => SpecialRandomRedirect::class,
903 'services' => [
904 'ConnectionProvider',
905 'NamespaceInfo',
906 ]
907 ],
908 'Randomrootpage' => [
909 'class' => SpecialRandomRootPage::class,
910 'services' => [
911 'ConnectionProvider',
912 'NamespaceInfo',
913 ]
914 ],
915 'GoToInterwiki' => [
916 'class' => SpecialGoToInterwiki::class,
917 ],
918
919 // High use pages
920 'Mostlinkedcategories' => [
921 'class' => SpecialMostLinkedCategories::class,
922 'services' => [
923 'ConnectionProvider',
924 'LinkBatchFactory',
925 'LanguageConverterFactory',
926 ]
927 ],
928 'Mostimages' => [
929 'class' => SpecialMostImages::class,
930 'services' => [
931 'ConnectionProvider',
932 'LanguageConverterFactory',
933 ]
934 ],
935 'Mostinterwikis' => [
936 'class' => SpecialMostInterwikis::class,
937 'services' => [
938 'NamespaceInfo',
939 'ConnectionProvider',
940 'LinkBatchFactory',
941 ]
942 ],
943 'Mostlinked' => [
944 'class' => SpecialMostLinked::class,
945 'services' => [
946 'ConnectionProvider',
947 'LinkBatchFactory',
948 'LinksMigration',
949 ]
950 ],
951 'Mostlinkedtemplates' => [
952 'class' => SpecialMostLinkedTemplates::class,
953 'services' => [
954 'ConnectionProvider',
955 'LinkBatchFactory',
956 'LinksMigration',
957 ]
958 ],
959 'Mostcategories' => [
960 'class' => SpecialMostCategories::class,
961 'services' => [
962 'NamespaceInfo',
963 'ConnectionProvider',
964 'LinkBatchFactory',
965 ]
966 ],
967 'Mostrevisions' => [
968 'class' => SpecialMostRevisions::class,
969 'services' => [
970 // Same as for Fewestrevisions
971 'NamespaceInfo',
972 'ConnectionProvider',
973 'LinkBatchFactory',
974 'LanguageConverterFactory',
975 ]
976 ],
977
978 // Page tools
979 'ComparePages' => [
980 'class' => SpecialComparePages::class,
981 'services' => [
982 'RevisionLookup',
983 'ContentHandlerFactory',
984 ]
985 ],
986 'Export' => [
987 'class' => SpecialExport::class,
988 'services' => [
989 'ConnectionProvider',
990 'WikiExporterFactory',
991 'TitleFormatter',
992 'LinksMigration',
993 ]
994 ],
995 'Import' => [
996 'class' => SpecialImport::class,
997 'services' => [
998 'WikiImporterFactory',
999 ]
1000 ],
1001 'Undelete' => [
1002 'class' => SpecialUndelete::class,
1003 'services' => [
1004 'PermissionManager',
1005 'RevisionStore',
1006 'RevisionRenderer',
1007 'ContentHandlerFactory',
1008 'ChangeTagDefStore',
1009 'LinkBatchFactory',
1010 'RepoGroup',
1011 'ConnectionProvider',
1012 'UserOptionsLookup',
1013 'WikiPageFactory',
1014 'SearchEngineFactory',
1015 'UndeletePageFactory',
1016 'ArchivedRevisionLookup',
1017 'CommentFormatter',
1018 'WatchlistManager',
1019 ],
1020 ],
1021 'Whatlinkshere' => [
1022 'class' => SpecialWhatLinksHere::class,
1023 'services' => [
1024 'ConnectionProvider',
1025 'LinkBatchFactory',
1026 'ContentHandlerFactory',
1027 'SearchEngineFactory',
1028 'NamespaceInfo',
1029 'TitleFactory',
1030 'LinksMigration',
1031 ]
1032 ],
1033 'MergeHistory' => [
1034 'class' => SpecialMergeHistory::class,
1035 'services' => [
1036 'MergeHistoryFactory',
1037 'LinkBatchFactory',
1038 'ConnectionProvider',
1039 'RevisionStore',
1040 'CommentFormatter',
1041 ]
1042 ],
1043 'ExpandTemplates' => [
1044 'class' => SpecialExpandTemplates::class,
1045 'services' => [
1046 'ParserFactory',
1047 'UserOptionsLookup',
1048 'Tidy',
1049 ],
1050 ],
1051 'ChangeContentModel' => [
1052 'class' => SpecialChangeContentModel::class,
1053 'services' => [
1054 'ContentHandlerFactory',
1055 'ContentModelChangeFactory',
1056 'SpamChecker',
1057 'RevisionLookup',
1058 'WikiPageFactory',
1059 'SearchEngineFactory',
1060 'CollationFactory',
1061 ],
1062 ],
1063
1064 // Other
1065 'Booksources' => [
1066 'class' => SpecialBookSources::class,
1067 'services' => [
1068 'RevisionLookup',
1069 'TitleFactory',
1070 ]
1071 ],
1072
1073 // Unlisted / redirects
1074 'ApiHelp' => [
1075 'class' => SpecialApiHelp::class,
1076 'services' => [
1077 'UrlUtils',
1078 ]
1079 ],
1080 'Blankpage' => [
1081 'class' => SpecialBlankpage::class,
1082 ],
1083 'DeletePage' => [
1084 'class' => SpecialDeletePage::class,
1085 'services' => [
1086 'SearchEngineFactory',
1087 ]
1088 ],
1089 'Diff' => [
1090 'class' => SpecialDiff::class,
1091 ],
1092 'EditPage' => [
1093 'class' => SpecialEditPage::class,
1094 'services' => [
1095 'SearchEngineFactory',
1096 ]
1097 ],
1098 'EditTags' => [
1099 'class' => SpecialEditTags::class,
1100 'services' => [
1101 'PermissionManager',
1102 'ChangeTagsStore',
1103 ],
1104 ],
1105 'Emailuser' => [
1106 'class' => SpecialEmailUser::class,
1107 'services' => [
1108 'UserNameUtils',
1109 'UserNamePrefixSearch',
1110 'UserOptionsLookup',
1111 'EmailUserFactory',
1112 'UserFactory',
1113 ]
1114 ],
1115 'Movepage' => [
1116 'class' => SpecialMovePage::class,
1117 'services' => [
1118 'MovePageFactory',
1119 'PermissionManager',
1120 'UserOptionsLookup',
1121 'ConnectionProvider',
1122 'ContentHandlerFactory',
1123 'NamespaceInfo',
1124 'LinkBatchFactory',
1125 'RepoGroup',
1126 'WikiPageFactory',
1127 'SearchEngineFactory',
1128 'WatchlistManager',
1129 'RestrictionStore',
1130 'TitleFactory',
1131 'DeletePageFactory',
1132 ]
1133 ],
1134 'Mycontributions' => [
1135 'class' => SpecialMycontributions::class,
1136 'services' => [
1137 'TempUserConfig',
1138 ],
1139 ],
1140 'MyLanguage' => [
1141 'class' => SpecialMyLanguage::class,
1142 'services' => [
1143 'LanguageNameUtils',
1144 'RedirectLookup'
1145 ]
1146 ],
1147 'Mylog' => [
1148 'class' => SpecialMylog::class,
1149 'services' => [
1150 'TempUserConfig',
1151 ],
1152 ],
1153 'Mypage' => [
1154 'class' => SpecialMypage::class,
1155 'services' => [
1156 'TempUserConfig',
1157 ],
1158 ],
1159 'Mytalk' => [
1160 'class' => SpecialMytalk::class,
1161 'services' => [
1162 'TempUserConfig',
1163 ],
1164 ],
1165 'PageHistory' => [
1166 'class' => SpecialPageHistory::class,
1167 'services' => [
1168 'SearchEngineFactory',
1169 ]
1170 ],
1171 'PageInfo' => [
1172 'class' => SpecialPageInfo::class,
1173 'services' => [
1174 'SearchEngineFactory',
1175 ]
1176 ],
1177 'ProtectPage' => [
1178 'class' => SpecialProtectPage::class,
1179 'services' => [
1180 'SearchEngineFactory',
1181 ]
1182 ],
1183 'Purge' => [
1184 'class' => SpecialPurge::class,
1185 'services' => [
1186 'SearchEngineFactory',
1187 ]
1188 ],
1189 'Myuploads' => [
1190 'class' => SpecialMyuploads::class,
1191 'services' => [
1192 'TempUserConfig',
1193 ],
1194 ],
1195 'AllMyUploads' => [
1196 'class' => SpecialAllMyUploads::class,
1197 ],
1198 'NewSection' => [
1199 'class' => SpecialNewSection::class,
1200 'services' => [
1201 'SearchEngineFactory',
1202 ]
1203 ],
1204 'PermanentLink' => [
1205 'class' => SpecialPermanentLink::class,
1206 ],
1207 'Redirect' => [
1208 'class' => SpecialRedirect::class,
1209 'services' => [
1210 'RepoGroup',
1211 'UserFactory',
1212 ]
1213 ],
1214 'Renameuser' => [
1215 'class' => SpecialRenameUser::class,
1216 'services' => [
1217 'ConnectionProvider',
1218 'MovePageFactory',
1219 'PermissionManager',
1220 'TitleFactory',
1221 'UserFactory',
1222 'UserNamePrefixSearch',
1223 'UserNameUtils',
1224 ]
1225 ],
1226 'Revisiondelete' => [
1227 'class' => SpecialRevisionDelete::class,
1228 'services' => [
1229 'PermissionManager',
1230 'RepoGroup',
1231 ],
1232 ],
1233 'RunJobs' => [
1234 'class' => SpecialRunJobs::class,
1235 'services' => [
1236 'JobRunner',
1237 'ReadOnlyMode',
1238 ]
1239 ],
1240 'Specialpages' => [
1241 'class' => SpecialSpecialPages::class,
1242 ],
1243 'PageData' => [
1244 'class' => SpecialPageData::class,
1245 ],
1246 'Contribute' => [
1247 'class' => SpecialContribute::class,
1248 ],
1249 'TalkPage' => [
1250 'class' => SpecialTalkPage::class,
1251 'services' => [
1252 'TitleParser',
1253 ],
1254 ],
1255 ];
1256
1257 /** @var array Special page name => class name */
1258 private $list;
1259
1260 /** @var array */
1261 private $aliases;
1262
1263 /** @var ServiceOptions */
1264 private $options;
1265
1266 /** @var Language */
1267 private $contLang;
1268
1269 /**
1270 * @var ObjectFactory
1271 * @noVarDump
1272 */
1273 private $objectFactory;
1274
1275 /**
1276 * @var HookContainer
1277 * @noVarDump
1278 */
1279 private $hookContainer;
1280
1281 /**
1282 * @var HookRunner
1283 * @noVarDump
1284 */
1285 private $hookRunner;
1286
1287 /**
1288 * @internal For use by ServiceWiring
1289 */
1290 public const CONSTRUCTOR_OPTIONS = [
1291 MainConfigNames::DisableInternalSearch,
1292 MainConfigNames::EmailAuthentication,
1293 MainConfigNames::EnableEmail,
1294 MainConfigNames::EnableJavaScriptTest,
1295 MainConfigNames::EnableSpecialMute,
1296 MainConfigNames::EnableEditRecovery,
1297 MainConfigNames::PageLanguageUseDB,
1298 MainConfigNames::SpecialPages,
1299 ];
1300
1301 /**
1302 * @var TitleFactory
1303 */
1304 private $titleFactory;
1305
1306 /**
1307 * @param ServiceOptions $options
1308 * @param Language $contLang
1309 * @param ObjectFactory $objectFactory
1310 * @param TitleFactory $titleFactory
1311 * @param HookContainer $hookContainer
1312 */
1313 public function __construct(
1314 ServiceOptions $options,
1315 Language $contLang,
1316 ObjectFactory $objectFactory,
1317 TitleFactory $titleFactory,
1318 HookContainer $hookContainer
1319 ) {
1320 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
1321 $this->options = $options;
1322 $this->contLang = $contLang;
1323 $this->objectFactory = $objectFactory;
1324 $this->titleFactory = $titleFactory;
1325 $this->hookContainer = $hookContainer;
1326 $this->hookRunner = new HookRunner( $hookContainer );
1327 }
1328
1329 /**
1330 * Returns a list of canonical special page names.
1331 * May be used to iterate over all registered special pages.
1332 *
1333 * @return string[]
1334 */
1335 public function getNames(): array {
1336 return array_keys( $this->getPageList() );
1337 }
1338
1339 /**
1340 * Get the special page list as an array
1341 *
1342 * @return array
1343 */
1344 private function getPageList(): array {
1345 if ( !is_array( $this->list ) ) {
1346 $this->list = self::CORE_LIST;
1347
1348 if ( !$this->options->get( MainConfigNames::DisableInternalSearch ) ) {
1349 $this->list['Search'] = [
1350 'class' => SpecialSearch::class,
1351 'services' => [
1352 'SearchEngineConfig',
1353 'SearchEngineFactory',
1354 'NamespaceInfo',
1355 'ContentHandlerFactory',
1356 'InterwikiLookup',
1357 'ReadOnlyMode',
1358 'UserOptionsManager',
1359 'LanguageConverterFactory',
1360 'RepoGroup',
1361 'SearchResultThumbnailProvider',
1362 'TitleMatcher',
1363 ]
1364 ];
1365 }
1366
1367 if ( $this->options->get( MainConfigNames::EmailAuthentication ) ) {
1368 $this->list['Confirmemail'] = [
1369 'class' => SpecialConfirmEmail::class,
1370 'services' => [
1371 'UserFactory',
1372 ]
1373 ];
1374 $this->list['Invalidateemail'] = [
1375 'class' => SpecialEmailInvalidate::class,
1376 'services' => [
1377 'UserFactory',
1378 ]
1379 ];
1380 }
1381
1382 if ( $this->options->get( MainConfigNames::EnableEmail ) ) {
1383 $this->list['ChangeEmail'] = [
1384 'class' => SpecialChangeEmail::class,
1385 'services' => [
1386 'AuthManager',
1387 ],
1388 ];
1389 }
1390
1391 if ( $this->options->get( MainConfigNames::EnableJavaScriptTest ) ) {
1392 $this->list['JavaScriptTest'] = [
1393 'class' => SpecialJavaScriptTest::class
1394 ];
1395 }
1396
1397 if ( $this->options->get( MainConfigNames::EnableSpecialMute ) ) {
1398 $this->list['Mute'] = [
1399 'class' => SpecialMute::class,
1400 'services' => [
1401 'CentralIdLookup',
1402 'UserOptionsManager',
1403 'UserIdentityLookup',
1404 'UserIdentityUtils',
1405 ]
1406 ];
1407 }
1408
1409 if ( $this->options->get( MainConfigNames::PageLanguageUseDB ) ) {
1410 $this->list['PageLanguage'] = [
1411 'class' => SpecialPageLanguage::class,
1412 'services' => [
1413 'ContentHandlerFactory',
1414 'LanguageNameUtils',
1415 'ConnectionProvider',
1416 'SearchEngineFactory',
1417 ]
1418 ];
1419 }
1420
1421 if ( $this->options->get( MainConfigNames::EnableEditRecovery ) ) {
1422 $this->list['EditRecovery'] = [
1423 'class' => SpecialEditRecovery::class,
1424 'services' => [
1425 'UserOptionsLookup',
1426 ],
1427 ];
1428 }
1429
1430 // Add extension special pages
1431 $this->list = array_merge( $this->list,
1432 $this->options->get( MainConfigNames::SpecialPages ) );
1433
1434 // This hook can be used to disable unwanted core special pages
1435 // or conditionally register special pages.
1436 $this->hookRunner->onSpecialPage_initList( $this->list );
1437 }
1438
1439 return $this->list;
1440 }
1441
1442 /**
1443 * Initialise and return the list of special page aliases. Returns an array where
1444 * the key is an alias, and the value is the canonical name of the special page.
1445 * All registered special pages are guaranteed to map to themselves.
1446 * @return array
1447 */
1448 private function getAliasList(): array {
1449 if ( $this->aliases === null ) {
1450 $aliases = $this->contLang->getSpecialPageAliases();
1451 $pageList = $this->getPageList();
1452
1453 $this->aliases = [];
1454 $keepAlias = [];
1455
1456 // Force every canonical name to be an alias for itself.
1457 foreach ( $pageList as $name => $stuff ) {
1458 $caseFoldedAlias = $this->contLang->caseFold( $name );
1459 $this->aliases[$caseFoldedAlias] = $name;
1460 $keepAlias[$caseFoldedAlias] = 'canonical';
1461 }
1462
1463 // Check for $aliases being an array since Language::getSpecialPageAliases can return null
1464 if ( is_array( $aliases ) ) {
1465 foreach ( $aliases as $realName => $aliasList ) {
1466 $first = true;
1467 foreach ( $aliasList as $alias ) {
1468 $caseFoldedAlias = $this->contLang->caseFold( $alias );
1469
1470 if ( isset( $this->aliases[$caseFoldedAlias] ) &&
1471 $realName === $this->aliases[$caseFoldedAlias]
1472 ) {
1473 $first = false;
1474 // Ignore same-realName conflicts
1475 continue;
1476 }
1477
1478 if ( !isset( $keepAlias[$caseFoldedAlias] ) ) {
1479 $this->aliases[$caseFoldedAlias] = $realName;
1480 if ( $first ) {
1481 $keepAlias[$caseFoldedAlias] = 'first';
1482 }
1483 } elseif ( $first ) {
1484 wfWarn( "First alias '$alias' for $realName conflicts with " .
1485 "{$keepAlias[$caseFoldedAlias]} alias for " .
1486 $this->aliases[$caseFoldedAlias]
1487 );
1488 }
1489 $first = false;
1490 }
1491 }
1492 }
1493 }
1494
1495 return $this->aliases;
1496 }
1497
1498 /**
1499 * Given a special page name with a possible subpage, return an array
1500 * where the first element is the special page name and the second is the
1501 * subpage.
1502 *
1503 * @param string $alias
1504 * @return array [ String, String|null ], or [ null, null ] if the page is invalid
1505 */
1506 public function resolveAlias( $alias ) {
1507 $bits = explode( '/', $alias, 2 );
1508
1509 $caseFoldedAlias = $this->contLang->caseFold( $bits[0] );
1510 $caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
1511 $aliases = $this->getAliasList();
1512 if ( !isset( $aliases[$caseFoldedAlias] ) ) {
1513 return [ null, null ];
1514 }
1515 $name = $aliases[$caseFoldedAlias];
1516 $par = $bits[1] ?? null; // T4087
1517
1518 return [ $name, $par ];
1519 }
1520
1521 /**
1522 * Check if a given name exist as a special page or as a special page alias
1523 *
1524 * @param string $name Name of a special page
1525 * @return bool True if a special page exists with this name
1526 */
1527 public function exists( $name ) {
1528 [ $title, ] = $this->resolveAlias( $name );
1529
1530 $specialPageList = $this->getPageList();
1531 return $title !== null && isset( $specialPageList[$title] );
1532 }
1533
1534 /**
1535 * Find the object with a given name and return it (or NULL)
1536 *
1537 * @param string $name Special page name, may be localised and/or an alias
1538 * @return SpecialPage|null SpecialPage object or null if the page doesn't exist
1539 */
1540 public function getPage( $name ) {
1541 [ $realName, ] = $this->resolveAlias( $name );
1542
1543 $specialPageList = $this->getPageList();
1544
1545 if ( $realName !== null && isset( $specialPageList[$realName] ) ) {
1546 $rec = $specialPageList[$realName];
1547
1548 if ( is_array( $rec ) || is_string( $rec ) || is_callable( $rec ) ) {
1549 $page = $this->objectFactory->createObject(
1550 $rec,
1551 [
1552 'allowClassName' => true,
1553 'allowCallable' => true
1554 ]
1555 );
1556 } else {
1557 $page = null;
1558 }
1559
1560 if ( $page instanceof SpecialPage ) {
1561 $page->setHookContainer( $this->hookContainer );
1562 $page->setContentLanguage( $this->contLang );
1563 $page->setSpecialPageFactory( $this );
1564 return $page;
1565 }
1566
1567 // It's not a classname, nor a callback, nor a legacy constructor array,
1568 // nor a special page object. Give up.
1569 wfLogWarning( "Cannot instantiate special page $realName: bad spec!" );
1570 }
1571
1572 return null;
1573 }
1574
1575 /**
1576 * Get listed special pages available to the current user.
1577 *
1578 * This includes both unrestricted pages, and restricted pages
1579 * that the current user has the required permissions for.
1580 *
1581 * @param User $user User object to check permissions provided
1582 * @return SpecialPage[]
1583 */
1584 public function getUsablePages( User $user ): array {
1585 $pages = [];
1586 foreach ( $this->getPageList() as $name => $rec ) {
1587 $page = $this->getPage( $name );
1588 if ( $page ) { // not null
1589 $page->setContext( RequestContext::getMain() );
1590 if ( $page->isListed()
1591 && ( !$page->isRestricted() || $page->userCanExecute( $user ) )
1592 ) {
1593 $pages[$name] = $page;
1594 }
1595 }
1596 }
1597
1598 return $pages;
1599 }
1600
1601 /**
1602 * Get listed special pages available to everyone by default.
1603 *
1604 * @return array<string,SpecialPage>
1605 */
1606 public function getRegularPages(): array {
1607 $pages = [];
1608 foreach ( $this->getPageList() as $name => $rec ) {
1609 $page = $this->getPage( $name );
1610 if ( $page && $page->isListed() && !$page->isRestricted() ) {
1611 $pages[$name] = $page;
1612 }
1613 }
1614
1615 return $pages;
1616 }
1617
1618 /**
1619 * Get listed special pages, including those that may require user rights.
1620 *
1621 * @since 1.42
1622 * @return array<string,SpecialPage>
1623 */
1624 public function getListedPages(): array {
1625 $pages = [];
1626 foreach ( $this->getPageList() as $name => $rec ) {
1627 $page = $this->getPage( $name );
1628 if ( $page && $page->isListed() ) {
1629 $pages[$name] = $page;
1630 }
1631 }
1632 return $pages;
1633 }
1634
1635 /**
1636 * Execute a special page path.
1637 * The path may contain parameters, e.g. Special:Name/Params
1638 * Extracts the special page name and call the execute method, passing the parameters
1639 *
1640 * Returns a title object if the page is redirected, false if there was no such special
1641 * page, and true if it was successful.
1642 *
1643 * @param PageReference|string $path
1644 * @param IContextSource $context
1645 * @param bool $including Bool output is being captured for use in {{special:whatever}}
1646 * @param LinkRenderer|null $linkRenderer (since 1.28)
1647 *
1648 * @return bool|Title
1649 */
1650 public function executePath( $path, IContextSource $context, $including = false,
1651 ?LinkRenderer $linkRenderer = null
1652 ) {
1653 if ( $path instanceof PageReference ) {
1654 $path = $path->getDBkey();
1655 }
1656
1657 $bits = explode( '/', $path, 2 );
1658 $name = $bits[0];
1659 $par = $bits[1] ?? null; // T4087
1660
1661 $page = $this->getPage( $name );
1662 if ( !$page ) {
1663 // Emulate SpecialPage::setHeaders()
1664 $context->getOutput()->setArticleRelated( false );
1665 $context->getOutput()->setRobotPolicy( 'noindex,nofollow' );
1666
1667 if ( $context->getConfig()->get( MainConfigNames::Send404Code ) ) {
1668 $context->getOutput()->setStatusCode( 404 );
1669 }
1670
1671 $context->getOutput()->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
1672
1673 return false;
1674 }
1675
1676 if ( !$including ) {
1677 ProfilingContext::singleton()->init( MW_ENTRY_POINT, $page->getName() );
1678 // Narrow DB query expectations for this HTTP request
1679 $trxLimits = $context->getConfig()->get( MainConfigNames::TrxProfilerLimits );
1680 $trxProfiler = Profiler::instance()->getTransactionProfiler();
1681 if ( $context->getRequest()->wasPosted() && !$page->doesWrites() ) {
1682 $trxProfiler->setExpectations( $trxLimits['POST-nonwrite'], __METHOD__ );
1683 }
1684 }
1685
1686 // Page exists, set the context
1687 $page->setContext( $context );
1688
1689 if ( !$including ) {
1690 // Redirect to canonical alias for GET commands
1691 // Not for POST, we'd lose the post data, so it's best to just distribute
1692 // the request. Such POST requests are possible for old extensions that
1693 // generate self-links without being aware that their default name has
1694 // changed.
1695 if ( $name != $page->getLocalName() && !$context->getRequest()->wasPosted() ) {
1696 $query = $context->getRequest()->getQueryValues();
1697 unset( $query['title'] );
1698 $title = $page->getPageTitle( $par ?? false );
1699 $url = $title->getFullURL( $query );
1700 $context->getOutput()->redirect( $url );
1701
1702 return $title;
1703 }
1704
1705 // @phan-suppress-next-line PhanUndeclaredMethod
1706 $context->setTitle( $page->getPageTitle( $par ?? false ) );
1707 } elseif ( !$page->isIncludable() ) {
1708 return false;
1709 }
1710
1711 $page->including( $including );
1712 if ( $linkRenderer ) {
1713 $page->setLinkRenderer( $linkRenderer );
1714 }
1715
1716 // Execute special page
1717 $page->run( $par );
1718
1719 return true;
1720 }
1721
1722 /**
1723 * Just like executePath() but will override global variables and execute
1724 * the page in "inclusion" mode. Returns true if the execution was
1725 * successful or false if there was no such special page, or a title object
1726 * if it was a redirect.
1727 *
1728 * Also saves the current $wgTitle, $wgOut, $wgRequest, $wgUser and $wgLang
1729 * variables so that the special page will get the context it'd expect on a
1730 * normal request, and then restores them to their previous values after.
1731 *
1732 * @param PageReference $page
1733 * @param IContextSource $context
1734 * @param LinkRenderer|null $linkRenderer (since 1.28)
1735 * @return bool|Title
1736 */
1737 public function capturePath(
1738 PageReference $page, IContextSource $context, ?LinkRenderer $linkRenderer = null
1739 ) {
1740 // phpcs:ignore MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgUser,MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgTitle
1741 global $wgTitle, $wgOut, $wgRequest, $wgUser, $wgLang;
1742 $main = RequestContext::getMain();
1743
1744 // Save current globals and main context
1745 $glob = [
1746 'title' => $wgTitle,
1747 'output' => $wgOut,
1748 'request' => $wgRequest,
1749 'user' => $wgUser,
1750 'language' => $wgLang,
1751 ];
1752 $ctx = [
1753 'title' => $main->getTitle(),
1754 'output' => $main->getOutput(),
1755 'request' => $main->getRequest(),
1756 'user' => $main->getUser(),
1757 'language' => $main->getLanguage(),
1758 ];
1759 if ( $main->canUseWikiPage() ) {
1760 $ctx['wikipage'] = $main->getWikiPage();
1761 }
1762
1763 // just needed for $wgTitle and RequestContext::setTitle
1764 $title = $this->titleFactory->castFromPageReference( $page );
1765
1766 // Override
1767 $wgTitle = $title;
1768 $wgOut = $context->getOutput();
1769 $wgRequest = $context->getRequest();
1770 $wgUser = $context->getUser();
1771 $wgLang = $context->getLanguage();
1772 // FIXME: Once reasonably certain that no SpecialPage subclasses
1773 // rely on direct RequestContext::getMain instead of their local
1774 // context getters, these can be removed (T323184)
1775 // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
1776 @$main->setTitle( $title );
1777 $main->setOutput( $context->getOutput() );
1778 $main->setRequest( $context->getRequest() );
1779 $main->setUser( $context->getUser() );
1780 $main->setLanguage( $context->getLanguage() );
1781
1782 try {
1783 // The useful part
1784 return $this->executePath( $page, $context, true, $linkRenderer );
1785 } finally {
1786 // Restore old globals and context
1787 $wgTitle = $glob['title'];
1788 $wgOut = $glob['output'];
1789 $wgRequest = $glob['request'];
1790 $wgUser = $glob['user'];
1791 $wgLang = $glob['language'];
1792 // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
1793 @$main->setTitle( $ctx['title'] );
1794 $main->setOutput( $ctx['output'] );
1795 $main->setRequest( $ctx['request'] );
1796 $main->setUser( $ctx['user'] );
1797 $main->setLanguage( $ctx['language'] );
1798 if ( isset( $ctx['wikipage'] ) ) {
1799 $main->setWikiPage( $ctx['wikipage'] );
1800 }
1801 }
1802 }
1803
1804 /**
1805 * Get the local name for a specified canonical name
1806 *
1807 * @param string $name
1808 * @param string|false|null $subpage
1809 * @return string
1810 */
1811 public function getLocalNameFor( $name, $subpage = false ) {
1812 $aliases = $this->contLang->getSpecialPageAliases();
1813 $aliasList = $this->getAliasList();
1814
1815 // Find the first alias that maps back to $name
1816 if ( isset( $aliases[$name] ) ) {
1817 $found = false;
1818 foreach ( $aliases[$name] as $alias ) {
1819 $caseFoldedAlias = $this->contLang->caseFold( $alias );
1820 $caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
1821 if ( isset( $aliasList[$caseFoldedAlias] ) &&
1822 $aliasList[$caseFoldedAlias] === $name
1823 ) {
1824 $name = $alias;
1825 $found = true;
1826 break;
1827 }
1828 }
1829 if ( !$found ) {
1830 wfWarn( "Did not find a usable alias for special page '$name'. " .
1831 "It seems all defined aliases conflict?" );
1832 }
1833 } else {
1834 // Check if someone misspelled the correct casing
1835 if ( is_array( $aliases ) ) {
1836 foreach ( $aliases as $n => $values ) {
1837 if ( strcasecmp( $name, $n ) === 0 ) {
1838 wfWarn( "Found alias defined for $n when searching for " .
1839 "special page aliases for $name. Case mismatch?" );
1840 return $this->getLocalNameFor( $n, $subpage );
1841 }
1842 }
1843 }
1844
1845 wfWarn( "Did not find alias for special page '$name'. " .
1846 "Perhaps no aliases are defined for it?" );
1847 }
1848
1849 if ( $subpage !== false && $subpage !== null ) {
1850 // Make sure it's in dbkey form
1851 $subpage = str_replace( ' ', '_', $subpage );
1852 $name = "$name/$subpage";
1853 }
1854
1855 return $this->contLang->ucfirst( $name );
1856 }
1857
1858 /**
1859 * Get a title for a given alias
1860 *
1861 * @param string $alias
1862 * @return Title|null Title or null if there is no such alias
1863 */
1864 public function getTitleForAlias( $alias ) {
1865 [ $name, $subpage ] = $this->resolveAlias( $alias );
1866 if ( $name != null ) {
1867 return SpecialPage::getTitleFor( $name, $subpage );
1868 }
1869
1870 return null;
1871 }
1872 }