Merge "Convert file delete to use OOUI"
[lhc/web/wiklou.git] / includes / specialpage / SpecialPageFactory.php
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 use MediaWiki\Linker\LinkRenderer;
25 use Wikimedia\ObjectFactory;
26
27 /**
28 * Factory for handling the special page list and generating SpecialPage objects.
29 *
30 * To add a special page in an extension, add to $wgSpecialPages either
31 * an object instance or an array containing the name and constructor
32 * parameters. The latter is preferred for performance reasons.
33 *
34 * The object instantiated must be either an instance of SpecialPage or a
35 * sub-class thereof. It must have an execute() method, which sends the HTML
36 * for the special page to $wgOut. The parent class has an execute() method
37 * which distributes the call to the historical global functions. Additionally,
38 * execute() also checks if the user has the necessary access privileges
39 * and bails out if not.
40 *
41 * To add a core special page, use the similar static list in
42 * SpecialPageFactory::$list. To remove a core static special page at runtime, use
43 * a SpecialPage_initList hook.
44 *
45 * @ingroup SpecialPage
46 * @since 1.17
47 */
48 class SpecialPageFactory {
49 /**
50 * List of special page names to the subclass of SpecialPage which handles them.
51 */
52 private static $coreList = [
53 // Maintenance Reports
54 'BrokenRedirects' => BrokenRedirectsPage::class,
55 'Deadendpages' => DeadendPagesPage::class,
56 'DoubleRedirects' => DoubleRedirectsPage::class,
57 'Longpages' => LongPagesPage::class,
58 'Ancientpages' => AncientPagesPage::class,
59 'Lonelypages' => LonelyPagesPage::class,
60 'Fewestrevisions' => FewestrevisionsPage::class,
61 'Withoutinterwiki' => WithoutInterwikiPage::class,
62 'Protectedpages' => SpecialProtectedpages::class,
63 'Protectedtitles' => SpecialProtectedtitles::class,
64 'Shortpages' => ShortPagesPage::class,
65 'Uncategorizedcategories' => UncategorizedCategoriesPage::class,
66 'Uncategorizedimages' => UncategorizedImagesPage::class,
67 'Uncategorizedpages' => UncategorizedPagesPage::class,
68 'Uncategorizedtemplates' => UncategorizedTemplatesPage::class,
69 'Unusedcategories' => UnusedCategoriesPage::class,
70 'Unusedimages' => UnusedimagesPage::class,
71 'Unusedtemplates' => UnusedtemplatesPage::class,
72 'Unwatchedpages' => UnwatchedpagesPage::class,
73 'Wantedcategories' => WantedCategoriesPage::class,
74 'Wantedfiles' => WantedFilesPage::class,
75 'Wantedpages' => WantedPagesPage::class,
76 'Wantedtemplates' => WantedTemplatesPage::class,
77
78 // List of pages
79 'Allpages' => SpecialAllPages::class,
80 'Prefixindex' => SpecialPrefixindex::class,
81 'Categories' => SpecialCategories::class,
82 'Listredirects' => ListredirectsPage::class,
83 'PagesWithProp' => SpecialPagesWithProp::class,
84 'TrackingCategories' => SpecialTrackingCategories::class,
85
86 // Authentication
87 'Userlogin' => SpecialUserLogin::class,
88 'Userlogout' => SpecialUserLogout::class,
89 'CreateAccount' => SpecialCreateAccount::class,
90 'LinkAccounts' => SpecialLinkAccounts::class,
91 'UnlinkAccounts' => SpecialUnlinkAccounts::class,
92 'ChangeCredentials' => SpecialChangeCredentials::class,
93 'RemoveCredentials' => SpecialRemoveCredentials::class,
94
95 // Users and rights
96 'Activeusers' => SpecialActiveUsers::class,
97 'Block' => SpecialBlock::class,
98 'Unblock' => SpecialUnblock::class,
99 'BlockList' => SpecialBlockList::class,
100 'AutoblockList' => SpecialAutoblockList::class,
101 'ChangePassword' => SpecialChangePassword::class,
102 'BotPasswords' => SpecialBotPasswords::class,
103 'PasswordReset' => SpecialPasswordReset::class,
104 'DeletedContributions' => DeletedContributionsPage::class,
105 'Preferences' => SpecialPreferences::class,
106 'ResetTokens' => SpecialResetTokens::class,
107 'Contributions' => SpecialContributions::class,
108 'Listgrouprights' => SpecialListGroupRights::class,
109 'Listgrants' => SpecialListGrants::class,
110 'Listusers' => SpecialListUsers::class,
111 'Listadmins' => SpecialListAdmins::class,
112 'Listbots' => SpecialListBots::class,
113 'Userrights' => UserrightsPage::class,
114 'EditWatchlist' => SpecialEditWatchlist::class,
115 'PasswordPolicies' => SpecialPasswordPolicies::class,
116
117 // Recent changes and logs
118 'Newimages' => SpecialNewFiles::class,
119 'Log' => SpecialLog::class,
120 'Watchlist' => SpecialWatchlist::class,
121 'Newpages' => SpecialNewpages::class,
122 'Recentchanges' => SpecialRecentChanges::class,
123 'Recentchangeslinked' => SpecialRecentChangesLinked::class,
124 'Tags' => SpecialTags::class,
125
126 // Media reports and uploads
127 'Listfiles' => SpecialListFiles::class,
128 'Filepath' => SpecialFilepath::class,
129 'MediaStatistics' => MediaStatisticsPage::class,
130 'MIMEsearch' => MIMEsearchPage::class,
131 'FileDuplicateSearch' => FileDuplicateSearchPage::class,
132 'Upload' => SpecialUpload::class,
133 'UploadStash' => SpecialUploadStash::class,
134 'ListDuplicatedFiles' => ListDuplicatedFilesPage::class,
135
136 // Data and tools
137 'ApiSandbox' => SpecialApiSandbox::class,
138 'Statistics' => SpecialStatistics::class,
139 'Allmessages' => SpecialAllMessages::class,
140 'Version' => SpecialVersion::class,
141 'Lockdb' => SpecialLockdb::class,
142 'Unlockdb' => SpecialUnlockdb::class,
143
144 // Redirecting special pages
145 'LinkSearch' => LinkSearchPage::class,
146 'Randompage' => RandomPage::class,
147 'RandomInCategory' => SpecialRandomInCategory::class,
148 'Randomredirect' => SpecialRandomredirect::class,
149 'Randomrootpage' => SpecialRandomrootpage::class,
150 'GoToInterwiki' => SpecialGoToInterwiki::class,
151
152 // High use pages
153 'Mostlinkedcategories' => MostlinkedCategoriesPage::class,
154 'Mostimages' => MostimagesPage::class,
155 'Mostinterwikis' => MostinterwikisPage::class,
156 'Mostlinked' => MostlinkedPage::class,
157 'Mostlinkedtemplates' => MostlinkedTemplatesPage::class,
158 'Mostcategories' => MostcategoriesPage::class,
159 'Mostrevisions' => MostrevisionsPage::class,
160
161 // Page tools
162 'ComparePages' => SpecialComparePages::class,
163 'Export' => SpecialExport::class,
164 'Import' => SpecialImport::class,
165 'Undelete' => SpecialUndelete::class,
166 'Whatlinkshere' => SpecialWhatLinksHere::class,
167 'MergeHistory' => SpecialMergeHistory::class,
168 'ExpandTemplates' => SpecialExpandTemplates::class,
169
170 // Other
171 'Booksources' => SpecialBookSources::class,
172
173 // Unlisted / redirects
174 'ApiHelp' => SpecialApiHelp::class,
175 'Blankpage' => SpecialBlankpage::class,
176 'Diff' => SpecialDiff::class,
177 'EditTags' => SpecialEditTags::class,
178 'Emailuser' => SpecialEmailUser::class,
179 'Movepage' => MovePageForm::class,
180 'Mycontributions' => SpecialMycontributions::class,
181 'MyLanguage' => SpecialMyLanguage::class,
182 'Mypage' => SpecialMypage::class,
183 'Mytalk' => SpecialMytalk::class,
184 'Myuploads' => SpecialMyuploads::class,
185 'AllMyUploads' => SpecialAllMyUploads::class,
186 'PermanentLink' => SpecialPermanentLink::class,
187 'Redirect' => SpecialRedirect::class,
188 'Revisiondelete' => SpecialRevisionDelete::class,
189 'RunJobs' => SpecialRunJobs::class,
190 'Specialpages' => SpecialSpecialpages::class,
191 'PageData' => SpecialPageData::class,
192 ];
193
194 private static $list;
195 private static $aliases;
196
197 /**
198 * Reset the internal list of special pages. Useful when changing $wgSpecialPages after
199 * the internal list has already been initialized, e.g. during testing.
200 */
201 public static function resetList() {
202 self::$list = null;
203 self::$aliases = null;
204 }
205
206 /**
207 * Returns a list of canonical special page names.
208 * May be used to iterate over all registered special pages.
209 *
210 * @return string[]
211 */
212 public static function getNames() {
213 return array_keys( self::getPageList() );
214 }
215
216 /**
217 * Get the special page list as an array
218 *
219 * @return array
220 */
221 private static function getPageList() {
222 global $wgSpecialPages;
223 global $wgDisableInternalSearch, $wgEmailAuthentication;
224 global $wgEnableEmail, $wgEnableJavaScriptTest;
225 global $wgPageLanguageUseDB, $wgContentHandlerUseDB;
226
227 if ( !is_array( self::$list ) ) {
228 self::$list = self::$coreList;
229
230 if ( !$wgDisableInternalSearch ) {
231 self::$list['Search'] = SpecialSearch::class;
232 }
233
234 if ( $wgEmailAuthentication ) {
235 self::$list['Confirmemail'] = EmailConfirmation::class;
236 self::$list['Invalidateemail'] = EmailInvalidation::class;
237 }
238
239 if ( $wgEnableEmail ) {
240 self::$list['ChangeEmail'] = SpecialChangeEmail::class;
241 }
242
243 if ( $wgEnableJavaScriptTest ) {
244 self::$list['JavaScriptTest'] = SpecialJavaScriptTest::class;
245 }
246
247 if ( $wgPageLanguageUseDB ) {
248 self::$list['PageLanguage'] = SpecialPageLanguage::class;
249 }
250 if ( $wgContentHandlerUseDB ) {
251 self::$list['ChangeContentModel'] = SpecialChangeContentModel::class;
252 }
253
254 // Add extension special pages
255 self::$list = array_merge( self::$list, $wgSpecialPages );
256
257 // This hook can be used to disable unwanted core special pages
258 // or conditionally register special pages.
259 Hooks::run( 'SpecialPage_initList', [ &self::$list ] );
260
261 }
262
263 return self::$list;
264 }
265
266 /**
267 * Initialise and return the list of special page aliases. Returns an array where
268 * the key is an alias, and the value is the canonical name of the special page.
269 * All registered special pages are guaranteed to map to themselves.
270 * @return array
271 */
272 private static function getAliasList() {
273 if ( is_null( self::$aliases ) ) {
274 global $wgContLang;
275 $aliases = $wgContLang->getSpecialPageAliases();
276 $pageList = self::getPageList();
277
278 self::$aliases = [];
279 $keepAlias = [];
280
281 // Force every canonical name to be an alias for itself.
282 foreach ( $pageList as $name => $stuff ) {
283 $caseFoldedAlias = $wgContLang->caseFold( $name );
284 self::$aliases[$caseFoldedAlias] = $name;
285 $keepAlias[$caseFoldedAlias] = 'canonical';
286 }
287
288 // Check for $aliases being an array since Language::getSpecialPageAliases can return null
289 if ( is_array( $aliases ) ) {
290 foreach ( $aliases as $realName => $aliasList ) {
291 $aliasList = array_values( $aliasList );
292 foreach ( $aliasList as $i => $alias ) {
293 $caseFoldedAlias = $wgContLang->caseFold( $alias );
294
295 if ( isset( self::$aliases[$caseFoldedAlias] ) &&
296 $realName === self::$aliases[$caseFoldedAlias]
297 ) {
298 // Ignore same-realName conflicts
299 continue;
300 }
301
302 if ( !isset( $keepAlias[$caseFoldedAlias] ) ) {
303 self::$aliases[$caseFoldedAlias] = $realName;
304 if ( !$i ) {
305 $keepAlias[$caseFoldedAlias] = 'first';
306 }
307 } elseif ( !$i ) {
308 wfWarn( "First alias '$alias' for $realName conflicts with " .
309 "{$keepAlias[$caseFoldedAlias]} alias for " .
310 self::$aliases[$caseFoldedAlias]
311 );
312 }
313 }
314 }
315 }
316 }
317
318 return self::$aliases;
319 }
320
321 /**
322 * Given a special page name with a possible subpage, return an array
323 * where the first element is the special page name and the second is the
324 * subpage.
325 *
326 * @param string $alias
327 * @return array Array( String, String|null ), or array( null, null ) if the page is invalid
328 */
329 public static function resolveAlias( $alias ) {
330 global $wgContLang;
331 $bits = explode( '/', $alias, 2 );
332
333 $caseFoldedAlias = $wgContLang->caseFold( $bits[0] );
334 $caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
335 $aliases = self::getAliasList();
336 if ( isset( $aliases[$caseFoldedAlias] ) ) {
337 $name = $aliases[$caseFoldedAlias];
338 } else {
339 return [ null, null ];
340 }
341
342 if ( !isset( $bits[1] ) ) { // T4087
343 $par = null;
344 } else {
345 $par = $bits[1];
346 }
347
348 return [ $name, $par ];
349 }
350
351 /**
352 * Check if a given name exist as a special page or as a special page alias
353 *
354 * @param string $name Name of a special page
355 * @return bool True if a special page exists with this name
356 */
357 public static function exists( $name ) {
358 list( $title, /*...*/ ) = self::resolveAlias( $name );
359
360 $specialPageList = self::getPageList();
361 return isset( $specialPageList[$title] );
362 }
363
364 /**
365 * Find the object with a given name and return it (or NULL)
366 *
367 * @param string $name Special page name, may be localised and/or an alias
368 * @return SpecialPage|null SpecialPage object or null if the page doesn't exist
369 */
370 public static function getPage( $name ) {
371 list( $realName, /*...*/ ) = self::resolveAlias( $name );
372
373 $specialPageList = self::getPageList();
374
375 if ( isset( $specialPageList[$realName] ) ) {
376 $rec = $specialPageList[$realName];
377
378 if ( is_callable( $rec ) ) {
379 // Use callback to instantiate the special page
380 $page = call_user_func( $rec );
381 } elseif ( is_string( $rec ) ) {
382 $className = $rec;
383 $page = new $className;
384 } elseif ( is_array( $rec ) ) {
385 $className = array_shift( $rec );
386 // @deprecated, officially since 1.18, unofficially since forever
387 wfDeprecated( "Array syntax for \$wgSpecialPages is deprecated ($className), " .
388 "define a subclass of SpecialPage instead.", '1.18' );
389 $page = ObjectFactory::getObjectFromSpec( [
390 'class' => $className,
391 'args' => $rec,
392 'closure_expansion' => false,
393 ] );
394 } elseif ( $rec instanceof SpecialPage ) {
395 $page = $rec; // XXX: we should deep clone here
396 } else {
397 $page = null;
398 }
399
400 if ( $page instanceof SpecialPage ) {
401 return $page;
402 } else {
403 // It's not a classname, nor a callback, nor a legacy constructor array,
404 // nor a special page object. Give up.
405 wfLogWarning( "Cannot instantiate special page $realName: bad spec!" );
406 return null;
407 }
408
409 } else {
410 return null;
411 }
412 }
413
414 /**
415 * Return categorised listable special pages which are available
416 * for the current user, and everyone.
417 *
418 * @param User|null $user User object to check permissions, $wgUser will be used
419 * if not provided
420 * @return array ( string => Specialpage )
421 */
422 public static function getUsablePages( User $user = null ) {
423 $pages = [];
424 if ( $user === null ) {
425 global $wgUser;
426 $user = $wgUser;
427 }
428 foreach ( self::getPageList() as $name => $rec ) {
429 $page = self::getPage( $name );
430 if ( $page ) { // not null
431 $page->setContext( RequestContext::getMain() );
432 if ( $page->isListed()
433 && ( !$page->isRestricted() || $page->userCanExecute( $user ) )
434 ) {
435 $pages[$name] = $page;
436 }
437 }
438 }
439
440 return $pages;
441 }
442
443 /**
444 * Return categorised listable special pages for all users
445 *
446 * @return array ( string => Specialpage )
447 */
448 public static function getRegularPages() {
449 $pages = [];
450 foreach ( self::getPageList() as $name => $rec ) {
451 $page = self::getPage( $name );
452 if ( $page && $page->isListed() && !$page->isRestricted() ) {
453 $pages[$name] = $page;
454 }
455 }
456
457 return $pages;
458 }
459
460 /**
461 * Return categorised listable special pages which are available
462 * for the current user, but not for everyone
463 *
464 * @param User|null $user User object to use or null for $wgUser
465 * @return array ( string => Specialpage )
466 */
467 public static function getRestrictedPages( User $user = null ) {
468 $pages = [];
469 if ( $user === null ) {
470 global $wgUser;
471 $user = $wgUser;
472 }
473 foreach ( self::getPageList() as $name => $rec ) {
474 $page = self::getPage( $name );
475 if ( $page
476 && $page->isListed()
477 && $page->isRestricted()
478 && $page->userCanExecute( $user )
479 ) {
480 $pages[$name] = $page;
481 }
482 }
483
484 return $pages;
485 }
486
487 /**
488 * Execute a special page path.
489 * The path may contain parameters, e.g. Special:Name/Params
490 * Extracts the special page name and call the execute method, passing the parameters
491 *
492 * Returns a title object if the page is redirected, false if there was no such special
493 * page, and true if it was successful.
494 *
495 * @param Title &$title
496 * @param IContextSource &$context
497 * @param bool $including Bool output is being captured for use in {{special:whatever}}
498 * @param LinkRenderer|null $linkRenderer (since 1.28)
499 *
500 * @return bool|Title
501 */
502 public static function executePath( Title &$title, IContextSource &$context, $including = false,
503 LinkRenderer $linkRenderer = null
504 ) {
505 // @todo FIXME: Redirects broken due to this call
506 $bits = explode( '/', $title->getDBkey(), 2 );
507 $name = $bits[0];
508 if ( !isset( $bits[1] ) ) { // T4087
509 $par = null;
510 } else {
511 $par = $bits[1];
512 }
513
514 $page = self::getPage( $name );
515 if ( !$page ) {
516 $context->getOutput()->setArticleRelated( false );
517 $context->getOutput()->setRobotPolicy( 'noindex,nofollow' );
518
519 global $wgSend404Code;
520 if ( $wgSend404Code ) {
521 $context->getOutput()->setStatusCode( 404 );
522 }
523
524 $context->getOutput()->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
525
526 return false;
527 }
528
529 if ( !$including ) {
530 // Narrow DB query expectations for this HTTP request
531 $trxLimits = $context->getConfig()->get( 'TrxProfilerLimits' );
532 $trxProfiler = Profiler::instance()->getTransactionProfiler();
533 if ( $context->getRequest()->wasPosted() && !$page->doesWrites() ) {
534 $trxProfiler->setExpectations( $trxLimits['POST-nonwrite'], __METHOD__ );
535 $context->getRequest()->markAsSafeRequest();
536 }
537 }
538
539 // Page exists, set the context
540 $page->setContext( $context );
541
542 if ( !$including ) {
543 // Redirect to canonical alias for GET commands
544 // Not for POST, we'd lose the post data, so it's best to just distribute
545 // the request. Such POST requests are possible for old extensions that
546 // generate self-links without being aware that their default name has
547 // changed.
548 if ( $name != $page->getLocalName() && !$context->getRequest()->wasPosted() ) {
549 $query = $context->getRequest()->getQueryValues();
550 unset( $query['title'] );
551 $title = $page->getPageTitle( $par );
552 $url = $title->getFullURL( $query );
553 $context->getOutput()->redirect( $url );
554
555 return $title;
556 } else {
557 $context->setTitle( $page->getPageTitle( $par ) );
558 }
559 } elseif ( !$page->isIncludable() ) {
560 return false;
561 }
562
563 $page->including( $including );
564 if ( $linkRenderer ) {
565 $page->setLinkRenderer( $linkRenderer );
566 }
567
568 // Execute special page
569 $page->run( $par );
570
571 return true;
572 }
573
574 /**
575 * Just like executePath() but will override global variables and execute
576 * the page in "inclusion" mode. Returns true if the execution was
577 * successful or false if there was no such special page, or a title object
578 * if it was a redirect.
579 *
580 * Also saves the current $wgTitle, $wgOut, $wgRequest, $wgUser and $wgLang
581 * variables so that the special page will get the context it'd expect on a
582 * normal request, and then restores them to their previous values after.
583 *
584 * @param Title $title
585 * @param IContextSource $context
586 * @param LinkRenderer|null $linkRenderer (since 1.28)
587 * @return string HTML fragment
588 */
589 public static function capturePath(
590 Title $title, IContextSource $context, LinkRenderer $linkRenderer = null
591 ) {
592 global $wgTitle, $wgOut, $wgRequest, $wgUser, $wgLang;
593 $main = RequestContext::getMain();
594
595 // Save current globals and main context
596 $glob = [
597 'title' => $wgTitle,
598 'output' => $wgOut,
599 'request' => $wgRequest,
600 'user' => $wgUser,
601 'language' => $wgLang,
602 ];
603 $ctx = [
604 'title' => $main->getTitle(),
605 'output' => $main->getOutput(),
606 'request' => $main->getRequest(),
607 'user' => $main->getUser(),
608 'language' => $main->getLanguage(),
609 ];
610
611 // Override
612 $wgTitle = $title;
613 $wgOut = $context->getOutput();
614 $wgRequest = $context->getRequest();
615 $wgUser = $context->getUser();
616 $wgLang = $context->getLanguage();
617 $main->setTitle( $title );
618 $main->setOutput( $context->getOutput() );
619 $main->setRequest( $context->getRequest() );
620 $main->setUser( $context->getUser() );
621 $main->setLanguage( $context->getLanguage() );
622
623 // The useful part
624 $ret = self::executePath( $title, $context, true, $linkRenderer );
625
626 // Restore old globals and context
627 $wgTitle = $glob['title'];
628 $wgOut = $glob['output'];
629 $wgRequest = $glob['request'];
630 $wgUser = $glob['user'];
631 $wgLang = $glob['language'];
632 $main->setTitle( $ctx['title'] );
633 $main->setOutput( $ctx['output'] );
634 $main->setRequest( $ctx['request'] );
635 $main->setUser( $ctx['user'] );
636 $main->setLanguage( $ctx['language'] );
637
638 return $ret;
639 }
640
641 /**
642 * Get the local name for a specified canonical name
643 *
644 * @param string $name
645 * @param string|bool $subpage
646 * @return string
647 */
648 public static function getLocalNameFor( $name, $subpage = false ) {
649 global $wgContLang;
650 $aliases = $wgContLang->getSpecialPageAliases();
651 $aliasList = self::getAliasList();
652
653 // Find the first alias that maps back to $name
654 if ( isset( $aliases[$name] ) ) {
655 $found = false;
656 foreach ( $aliases[$name] as $alias ) {
657 $caseFoldedAlias = $wgContLang->caseFold( $alias );
658 $caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
659 if ( isset( $aliasList[$caseFoldedAlias] ) &&
660 $aliasList[$caseFoldedAlias] === $name
661 ) {
662 $name = $alias;
663 $found = true;
664 break;
665 }
666 }
667 if ( !$found ) {
668 wfWarn( "Did not find a usable alias for special page '$name'. " .
669 "It seems all defined aliases conflict?" );
670 }
671 } else {
672 // Check if someone misspelled the correct casing
673 if ( is_array( $aliases ) ) {
674 foreach ( $aliases as $n => $values ) {
675 if ( strcasecmp( $name, $n ) === 0 ) {
676 wfWarn( "Found alias defined for $n when searching for " .
677 "special page aliases for $name. Case mismatch?" );
678 return self::getLocalNameFor( $n, $subpage );
679 }
680 }
681 }
682
683 wfWarn( "Did not find alias for special page '$name'. " .
684 "Perhaps no aliases are defined for it?" );
685 }
686
687 if ( $subpage !== false && !is_null( $subpage ) ) {
688 // Make sure it's in dbkey form
689 $subpage = str_replace( ' ', '_', $subpage );
690 $name = "$name/$subpage";
691 }
692
693 return $wgContLang->ucfirst( $name );
694 }
695
696 /**
697 * Get a title for a given alias
698 *
699 * @param string $alias
700 * @return Title|null Title or null if there is no such alias
701 */
702 public static function getTitleForAlias( $alias ) {
703 list( $name, $subpage ) = self::resolveAlias( $alias );
704 if ( $name != null ) {
705 return SpecialPage::getTitleFor( $name, $subpage );
706 } else {
707 return null;
708 }
709 }
710 }