Merge "Introduce Special:RedirectExternal"
[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
38 /**
39 * Factory for handling the special page list and generating SpecialPage objects.
40 *
41 * To add a special page in an extension, add to $wgSpecialPages either
42 * an object instance or an array containing the name and constructor
43 * parameters. The latter is preferred for performance reasons.
44 *
45 * The object instantiated must be either an instance of SpecialPage or a
46 * sub-class thereof. It must have an execute() method, which sends the HTML
47 * for the special page to $wgOut. The parent class has an execute() method
48 * which distributes the call to the historical global functions. Additionally,
49 * execute() also checks if the user has the necessary access privileges
50 * and bails out if not.
51 *
52 * To add a core special page, use the similar static list in
53 * SpecialPageFactory::$list. To remove a core static special page at runtime, use
54 * a SpecialPage_initList hook.
55 *
56 * @note There are two classes called SpecialPageFactory. You should use this first one, in
57 * namespace MediaWiki\Special, which is a service. \SpecialPageFactory is a deprecated collection
58 * of static methods that forwards to the global service.
59 *
60 * @ingroup SpecialPage
61 * @since 1.17
62 */
63 class SpecialPageFactory {
64 /**
65 * List of special page names to the subclass of SpecialPage which handles them.
66 * @todo Make this a const when we drop HHVM support (T192166). It can still be private in PHP
67 * 7.1.
68 */
69 private static $coreList = [
70 // Maintenance Reports
71 'BrokenRedirects' => \BrokenRedirectsPage::class,
72 'Deadendpages' => \DeadendPagesPage::class,
73 'DoubleRedirects' => \DoubleRedirectsPage::class,
74 'Longpages' => \LongPagesPage::class,
75 'Ancientpages' => \AncientPagesPage::class,
76 'Lonelypages' => \LonelyPagesPage::class,
77 'Fewestrevisions' => \FewestrevisionsPage::class,
78 'Withoutinterwiki' => \WithoutInterwikiPage::class,
79 'Protectedpages' => \SpecialProtectedpages::class,
80 'Protectedtitles' => \SpecialProtectedtitles::class,
81 'Shortpages' => \ShortPagesPage::class,
82 'Uncategorizedcategories' => \UncategorizedCategoriesPage::class,
83 'Uncategorizedimages' => \UncategorizedImagesPage::class,
84 'Uncategorizedpages' => \UncategorizedPagesPage::class,
85 'Uncategorizedtemplates' => \UncategorizedTemplatesPage::class,
86 'Unusedcategories' => \UnusedCategoriesPage::class,
87 'Unusedimages' => \UnusedimagesPage::class,
88 'Unusedtemplates' => \UnusedtemplatesPage::class,
89 'Unwatchedpages' => \UnwatchedpagesPage::class,
90 'Wantedcategories' => \WantedCategoriesPage::class,
91 'Wantedfiles' => \WantedFilesPage::class,
92 'Wantedpages' => \WantedPagesPage::class,
93 'Wantedtemplates' => \WantedTemplatesPage::class,
94
95 // List of pages
96 'Allpages' => \SpecialAllPages::class,
97 'Prefixindex' => \SpecialPrefixindex::class,
98 'Categories' => \SpecialCategories::class,
99 'Listredirects' => \ListredirectsPage::class,
100 'PagesWithProp' => \SpecialPagesWithProp::class,
101 'TrackingCategories' => \SpecialTrackingCategories::class,
102
103 // Authentication
104 'Userlogin' => \SpecialUserLogin::class,
105 'Userlogout' => \SpecialUserLogout::class,
106 'CreateAccount' => \SpecialCreateAccount::class,
107 'LinkAccounts' => \SpecialLinkAccounts::class,
108 'UnlinkAccounts' => \SpecialUnlinkAccounts::class,
109 'ChangeCredentials' => \SpecialChangeCredentials::class,
110 'RemoveCredentials' => \SpecialRemoveCredentials::class,
111
112 // Users and rights
113 'Activeusers' => \SpecialActiveUsers::class,
114 'Block' => \SpecialBlock::class,
115 'Unblock' => \SpecialUnblock::class,
116 'BlockList' => \SpecialBlockList::class,
117 'AutoblockList' => \SpecialAutoblockList::class,
118 'ChangePassword' => \SpecialChangePassword::class,
119 'BotPasswords' => \SpecialBotPasswords::class,
120 'PasswordReset' => \SpecialPasswordReset::class,
121 'DeletedContributions' => \DeletedContributionsPage::class,
122 'Preferences' => \SpecialPreferences::class,
123 'ResetTokens' => \SpecialResetTokens::class,
124 'Contributions' => \SpecialContributions::class,
125 'Listgrouprights' => \SpecialListGroupRights::class,
126 'Listgrants' => \SpecialListGrants::class,
127 'Listusers' => \SpecialListUsers::class,
128 'Listadmins' => \SpecialListAdmins::class,
129 'Listbots' => \SpecialListBots::class,
130 'Userrights' => \UserrightsPage::class,
131 'EditWatchlist' => \SpecialEditWatchlist::class,
132 'PasswordPolicies' => \SpecialPasswordPolicies::class,
133
134 // Recent changes and logs
135 'Newimages' => \SpecialNewFiles::class,
136 'Log' => \SpecialLog::class,
137 'Watchlist' => \SpecialWatchlist::class,
138 'Newpages' => \SpecialNewpages::class,
139 'Recentchanges' => \SpecialRecentChanges::class,
140 'Recentchangeslinked' => \SpecialRecentChangesLinked::class,
141 'Tags' => \SpecialTags::class,
142
143 // Media reports and uploads
144 'Listfiles' => \SpecialListFiles::class,
145 'Filepath' => \SpecialFilepath::class,
146 'MediaStatistics' => \MediaStatisticsPage::class,
147 'MIMEsearch' => \MIMEsearchPage::class,
148 'FileDuplicateSearch' => \FileDuplicateSearchPage::class,
149 'Upload' => \SpecialUpload::class,
150 'UploadStash' => \SpecialUploadStash::class,
151 'ListDuplicatedFiles' => \ListDuplicatedFilesPage::class,
152
153 // Data and tools
154 'ApiSandbox' => \SpecialApiSandbox::class,
155 'Statistics' => \SpecialStatistics::class,
156 'Allmessages' => \SpecialAllMessages::class,
157 'Version' => \SpecialVersion::class,
158 'Lockdb' => \SpecialLockdb::class,
159 'Unlockdb' => \SpecialUnlockdb::class,
160
161 // Redirecting special pages
162 'LinkSearch' => \LinkSearchPage::class,
163 'Randompage' => \RandomPage::class,
164 'RandomInCategory' => \SpecialRandomInCategory::class,
165 'Randomredirect' => \SpecialRandomredirect::class,
166 'Randomrootpage' => \SpecialRandomrootpage::class,
167 'GoToInterwiki' => \SpecialGoToInterwiki::class,
168
169 // High use pages
170 'Mostlinkedcategories' => \MostlinkedCategoriesPage::class,
171 'Mostimages' => \MostimagesPage::class,
172 'Mostinterwikis' => \MostinterwikisPage::class,
173 'Mostlinked' => \MostlinkedPage::class,
174 'Mostlinkedtemplates' => \MostlinkedTemplatesPage::class,
175 'Mostcategories' => \MostcategoriesPage::class,
176 'Mostrevisions' => \MostrevisionsPage::class,
177
178 // Page tools
179 'ComparePages' => \SpecialComparePages::class,
180 'Export' => \SpecialExport::class,
181 'Import' => \SpecialImport::class,
182 'Undelete' => \SpecialUndelete::class,
183 'Whatlinkshere' => \SpecialWhatLinksHere::class,
184 'MergeHistory' => \SpecialMergeHistory::class,
185 'ExpandTemplates' => \SpecialExpandTemplates::class,
186
187 // Other
188 'Booksources' => \SpecialBookSources::class,
189
190 // Unlisted / redirects
191 'ApiHelp' => \SpecialApiHelp::class,
192 'Blankpage' => \SpecialBlankpage::class,
193 'Diff' => \SpecialDiff::class,
194 'EditTags' => \SpecialEditTags::class,
195 'Emailuser' => \SpecialEmailUser::class,
196 'Movepage' => \MovePageForm::class,
197 'Mycontributions' => \SpecialMycontributions::class,
198 'MyLanguage' => \SpecialMyLanguage::class,
199 'Mypage' => \SpecialMypage::class,
200 'Mytalk' => \SpecialMytalk::class,
201 'Myuploads' => \SpecialMyuploads::class,
202 'AllMyUploads' => \SpecialAllMyUploads::class,
203 'PermanentLink' => \SpecialPermanentLink::class,
204 'Redirect' => \SpecialRedirect::class,
205 'RedirectExternal' => \SpecialRedirectExternal::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 ( $rec instanceof SpecialPage ) {
405 $page = $rec; // XXX: we should deep clone here
406 } else {
407 $page = null;
408 }
409
410 if ( $page instanceof SpecialPage ) {
411 return $page;
412 }
413
414 // It's not a classname, nor a callback, nor a legacy constructor array,
415 // nor a special page object. Give up.
416 wfLogWarning( "Cannot instantiate special page $realName: bad spec!" );
417 }
418
419 return null;
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
427 * provided
428 * @return array ( string => Specialpage )
429 */
430 public function getUsablePages( User $user ) : array {
431 $pages = [];
432 foreach ( $this->getPageList() as $name => $rec ) {
433 $page = $this->getPage( $name );
434 if ( $page ) { // not null
435 $page->setContext( RequestContext::getMain() );
436 if ( $page->isListed()
437 && ( !$page->isRestricted() || $page->userCanExecute( $user ) )
438 ) {
439 $pages[$name] = $page;
440 }
441 }
442 }
443
444 return $pages;
445 }
446
447 /**
448 * Return categorised listable special pages for all users
449 *
450 * @return array ( string => Specialpage )
451 */
452 public function getRegularPages() : array {
453 $pages = [];
454 foreach ( $this->getPageList() as $name => $rec ) {
455 $page = $this->getPage( $name );
456 if ( $page && $page->isListed() && !$page->isRestricted() ) {
457 $pages[$name] = $page;
458 }
459 }
460
461 return $pages;
462 }
463
464 /**
465 * Return categorised listable special pages which are available
466 * for the current user, but not for everyone
467 *
468 * @param User $user User object to use
469 * @return array ( string => Specialpage )
470 */
471 public function getRestrictedPages( User $user ) : array {
472 $pages = [];
473 foreach ( $this->getPageList() as $name => $rec ) {
474 $page = $this->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 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 = $this->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 }
557
558 $context->setTitle( $page->getPageTitle( $par ) );
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 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 = $this->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 function getLocalNameFor( $name, $subpage = false ) {
649 $aliases = $this->contLang->getSpecialPageAliases();
650 $aliasList = $this->getAliasList();
651
652 // Find the first alias that maps back to $name
653 if ( isset( $aliases[$name] ) ) {
654 $found = false;
655 foreach ( $aliases[$name] as $alias ) {
656 $caseFoldedAlias = $this->contLang->caseFold( $alias );
657 $caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
658 if ( isset( $aliasList[$caseFoldedAlias] ) &&
659 $aliasList[$caseFoldedAlias] === $name
660 ) {
661 $name = $alias;
662 $found = true;
663 break;
664 }
665 }
666 if ( !$found ) {
667 wfWarn( "Did not find a usable alias for special page '$name'. " .
668 "It seems all defined aliases conflict?" );
669 }
670 } else {
671 // Check if someone misspelled the correct casing
672 if ( is_array( $aliases ) ) {
673 foreach ( $aliases as $n => $values ) {
674 if ( strcasecmp( $name, $n ) === 0 ) {
675 wfWarn( "Found alias defined for $n when searching for " .
676 "special page aliases for $name. Case mismatch?" );
677 return $this->getLocalNameFor( $n, $subpage );
678 }
679 }
680 }
681
682 wfWarn( "Did not find alias for special page '$name'. " .
683 "Perhaps no aliases are defined for it?" );
684 }
685
686 if ( $subpage !== false && !is_null( $subpage ) ) {
687 // Make sure it's in dbkey form
688 $subpage = str_replace( ' ', '_', $subpage );
689 $name = "$name/$subpage";
690 }
691
692 return $this->contLang->ucfirst( $name );
693 }
694
695 /**
696 * Get a title for a given alias
697 *
698 * @param string $alias
699 * @return Title|null Title or null if there is no such alias
700 */
701 public function getTitleForAlias( $alias ) {
702 list( $name, $subpage ) = $this->resolveAlias( $alias );
703 if ( $name != null ) {
704 return SpecialPage::getTitleFor( $name, $subpage );
705 }
706
707 return null;
708 }
709 }