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