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