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