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