summaryrefslogtreecommitdiff
path: root/includes/specialpage/SpecialPageFactory.php
blob: e794a5dfdcaa29048f9061b092c965d0a7e357b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
<?php
/**
 * Factory for handling the special page list and generating SpecialPage objects.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * http://www.gnu.org/copyleft/gpl.html
 *
 * @file
 * @ingroup SpecialPage
 * @defgroup SpecialPage SpecialPage
 */

/**
 * Factory for handling the special page list and generating SpecialPage objects.
 *
 * To add a special page in an extension, add to $wgSpecialPages either
 * an object instance or an array containing the name and constructor
 * parameters. The latter is preferred for performance reasons.
 *
 * The object instantiated must be either an instance of SpecialPage or a
 * sub-class thereof. It must have an execute() method, which sends the HTML
 * for the special page to $wgOut. The parent class has an execute() method
 * which distributes the call to the historical global functions. Additionally,
 * execute() also checks if the user has the necessary access privileges
 * and bails out if not.
 *
 * To add a core special page, use the similar static list in
 * SpecialPageFactory::$list. To remove a core static special page at runtime, use
 * a SpecialPage_initList hook.
 *
 * @ingroup SpecialPage
 * @since 1.17
 */
class SpecialPageFactory {
	/**
	 * List of special page names to the subclass of SpecialPage which handles them.
	 */
	private static $coreList = array(
		// Maintenance Reports
		'BrokenRedirects' => 'BrokenRedirectsPage',
		'Deadendpages' => 'DeadendPagesPage',
		'DoubleRedirects' => 'DoubleRedirectsPage',
		'Longpages' => 'LongPagesPage',
		'Ancientpages' => 'AncientPagesPage',
		'Lonelypages' => 'LonelyPagesPage',
		'Fewestrevisions' => 'FewestrevisionsPage',
		'Withoutinterwiki' => 'WithoutInterwikiPage',
		'Protectedpages' => 'SpecialProtectedpages',
		'Protectedtitles' => 'SpecialProtectedtitles',
		'Shortpages' => 'ShortPagesPage',
		'Uncategorizedcategories' => 'UncategorizedCategoriesPage',
		'Uncategorizedimages' => 'UncategorizedImagesPage',
		'Uncategorizedpages' => 'UncategorizedPagesPage',
		'Uncategorizedtemplates' => 'UncategorizedTemplatesPage',
		'Unusedcategories' => 'UnusedCategoriesPage',
		'Unusedimages' => 'UnusedimagesPage',
		'Unusedtemplates' => 'UnusedtemplatesPage',
		'Unwatchedpages' => 'UnwatchedpagesPage',
		'Wantedcategories' => 'WantedCategoriesPage',
		'Wantedfiles' => 'WantedFilesPage',
		'Wantedpages' => 'WantedPagesPage',
		'Wantedtemplates' => 'WantedTemplatesPage',

		// List of pages
		'Allpages' => 'SpecialAllPages',
		'Prefixindex' => 'SpecialPrefixindex',
		'Categories' => 'SpecialCategories',
		'Listredirects' => 'ListredirectsPage',
		'PagesWithProp' => 'SpecialPagesWithProp',
		'TrackingCategories' => 'SpecialTrackingCategories',

		// Login/create account
		'Userlogin' => 'LoginForm',
		'CreateAccount' => 'SpecialCreateAccount',

		// Users and rights
		'Block' => 'SpecialBlock',
		'Unblock' => 'SpecialUnblock',
		'BlockList' => 'SpecialBlockList',
		'ChangePassword' => 'SpecialChangePassword',
		'PasswordReset' => 'SpecialPasswordReset',
		'DeletedContributions' => 'DeletedContributionsPage',
		'Preferences' => 'SpecialPreferences',
		'ResetTokens' => 'SpecialResetTokens',
		'Contributions' => 'SpecialContributions',
		'Listgrouprights' => 'SpecialListGroupRights',
		'Listusers' => 'SpecialListUsers',
		'Listadmins' => 'SpecialListAdmins',
		'Listbots' => 'SpecialListBots',
		'Userrights' => 'UserrightsPage',
		'EditWatchlist' => 'SpecialEditWatchlist',

		// Recent changes and logs
		'Newimages' => 'SpecialNewFiles',
		'Log' => 'SpecialLog',
		'Watchlist' => 'SpecialWatchlist',
		'Newpages' => 'SpecialNewpages',
		'Recentchanges' => 'SpecialRecentChanges',
		'Recentchangeslinked' => 'SpecialRecentChangesLinked',
		'Tags' => 'SpecialTags',

		// Media reports and uploads
		'Listfiles' => 'SpecialListFiles',
		'Filepath' => 'SpecialFilepath',
		'MediaStatistics' => 'MediaStatisticsPage',
		'MIMEsearch' => 'MIMEsearchPage',
		'FileDuplicateSearch' => 'FileDuplicateSearchPage',
		'Upload' => 'SpecialUpload',
		'UploadStash' => 'SpecialUploadStash',
		'ListDuplicatedFiles' => 'ListDuplicatedFilesPage',

		// Data and tools
		'Statistics' => 'SpecialStatistics',
		'Allmessages' => 'SpecialAllMessages',
		'Version' => 'SpecialVersion',
		'Lockdb' => 'SpecialLockdb',
		'Unlockdb' => 'SpecialUnlockdb',

		// Redirecting special pages
		'LinkSearch' => 'LinkSearchPage',
		'Randompage' => 'RandomPage',
		'RandomInCategory' => 'SpecialRandomInCategory',
		'Randomredirect' => 'SpecialRandomredirect',

		// High use pages
		'Mostlinkedcategories' => 'MostlinkedCategoriesPage',
		'Mostimages' => 'MostimagesPage',
		'Mostinterwikis' => 'MostinterwikisPage',
		'Mostlinked' => 'MostlinkedPage',
		'Mostlinkedtemplates' => 'MostlinkedTemplatesPage',
		'Mostcategories' => 'MostcategoriesPage',
		'Mostrevisions' => 'MostrevisionsPage',

		// Page tools
		'ComparePages' => 'SpecialComparePages',
		'Export' => 'SpecialExport',
		'Import' => 'SpecialImport',
		'Undelete' => 'SpecialUndelete',
		'Whatlinkshere' => 'SpecialWhatLinksHere',
		'MergeHistory' => 'SpecialMergeHistory',
		'ExpandTemplates' => 'SpecialExpandTemplates',

		// Other
		'Booksources' => 'SpecialBookSources',

		// Unlisted / redirects
		'ApiHelp' => 'SpecialApiHelp',
		'Blankpage' => 'SpecialBlankpage',
		'Diff' => 'SpecialDiff',
		'EditTags' => 'SpecialEditTags',
		'Emailuser' => 'SpecialEmailUser',
		'Movepage' => 'MovePageForm',
		'Mycontributions' => 'SpecialMycontributions',
		'MyLanguage' => 'SpecialMyLanguage',
		'Mypage' => 'SpecialMypage',
		'Mytalk' => 'SpecialMytalk',
		'Myuploads' => 'SpecialMyuploads',
		'AllMyUploads' => 'SpecialAllMyUploads',
		'PermanentLink' => 'SpecialPermanentLink',
		'Redirect' => 'SpecialRedirect',
		'Revisiondelete' => 'SpecialRevisionDelete',
		'RunJobs' => 'SpecialRunJobs',
		'Specialpages' => 'SpecialSpecialpages',
		'Userlogout' => 'SpecialUserlogout',
	);

	private static $list;
	private static $aliases;

	/**
	 * Reset the internal list of special pages. Useful when changing $wgSpecialPages after
	 * the internal list has already been initialized, e.g. during testing.
	 */
	public static function resetList() {
		self::$list = null;
		self::$aliases = null;
	}

	/**
	 * Returns a list of canonical special page names.
	 * May be used to iterate over all registered special pages.
	 *
	 * @return string[]
	 */
	public static function getNames() {
		return array_keys( self::getPageList() );
	}

	/**
	 * Get the special page list as an array
	 *
	 * @deprecated since 1.24, use getNames() instead.
	 * @return array
	 */
	public static function getList() {
		wfDeprecated( __FUNCTION__, '1.24' );
		return self::getPageList();
	}

	/**
	 * Get the special page list as an array
	 *
	 * @return array
	 */
	private static function getPageList() {
		global $wgSpecialPages;
		global $wgDisableInternalSearch, $wgEmailAuthentication;
		global $wgEnableEmail, $wgEnableJavaScriptTest;
		global $wgPageLanguageUseDB, $wgContentHandlerUseDB;

		if ( !is_array( self::$list ) ) {

			self::$list = self::$coreList;

			if ( !$wgDisableInternalSearch ) {
				self::$list['Search'] = 'SpecialSearch';
			}

			if ( $wgEmailAuthentication ) {
				self::$list['Confirmemail'] = 'EmailConfirmation';
				self::$list['Invalidateemail'] = 'EmailInvalidation';
			}

			if ( $wgEnableEmail ) {
				self::$list['ChangeEmail'] = 'SpecialChangeEmail';
			}

			if ( $wgEnableJavaScriptTest ) {
				self::$list['JavaScriptTest'] = 'SpecialJavaScriptTest';
			}

			if ( $wgPageLanguageUseDB ) {
				self::$list['PageLanguage'] = 'SpecialPageLanguage';
			}
			if ( $wgContentHandlerUseDB ) {
				self::$list['ChangeContentModel'] = 'SpecialChangeContentModel';
			}

			self::$list['Activeusers'] = 'SpecialActiveUsers';

			// Add extension special pages
			self::$list = array_merge( self::$list, $wgSpecialPages );

			// This hook can be used to disable unwanted core special pages
			// or conditionally register special pages.
			Hooks::run( 'SpecialPage_initList', array( &self::$list ) );

		}

		return self::$list;
	}

	/**
	 * Initialise and return the list of special page aliases. Returns an array where
	 * the key is an alias, and the value is the canonical name of the special page.
	 * All registered special pages are guaranteed to map to themselves.
	 * @return array
	 */
	private static function getAliasList() {
		if ( is_null( self::$aliases ) ) {
			global $wgContLang;
			$aliases = $wgContLang->getSpecialPageAliases();
			$pageList = self::getPageList();

			self::$aliases = array();
			$keepAlias = array();

			// Force every canonical name to be an alias for itself.
			foreach ( $pageList as $name => $stuff ) {
				$caseFoldedAlias = $wgContLang->caseFold( $name );
				self::$aliases[$caseFoldedAlias] = $name;
				$keepAlias[$caseFoldedAlias] = 'canonical';
			}

			// Check for $aliases being an array since Language::getSpecialPageAliases can return null
			if ( is_array( $aliases ) ) {
				foreach ( $aliases as $realName => $aliasList ) {
					$aliasList = array_values( $aliasList );
					foreach ( $aliasList as $i => $alias ) {
						$caseFoldedAlias = $wgContLang->caseFold( $alias );

						if ( isset( self::$aliases[$caseFoldedAlias] ) &&
							$realName === self::$aliases[$caseFoldedAlias]
						) {
							// Ignore same-realName conflicts
							continue;
						}

						if ( !isset( $keepAlias[$caseFoldedAlias] ) ) {
							self::$aliases[$caseFoldedAlias] = $realName;
							if ( !$i ) {
								$keepAlias[$caseFoldedAlias] = 'first';
							}
						} elseif ( !$i ) {
							wfWarn( "First alias '$alias' for $realName conflicts with " .
								"{$keepAlias[$caseFoldedAlias]} alias for " .
								self::$aliases[$caseFoldedAlias]
							);
						}
					}
				}
			}
		}

		return self::$aliases;
	}

	/**
	 * Given a special page name with a possible subpage, return an array
	 * where the first element is the special page name and the second is the
	 * subpage.
	 *
	 * @param string $alias
	 * @return array Array( String, String|null ), or array( null, null ) if the page is invalid
	 */
	public static function resolveAlias( $alias ) {
		global $wgContLang;
		$bits = explode( '/', $alias, 2 );

		$caseFoldedAlias = $wgContLang->caseFold( $bits[0] );
		$caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
		$aliases = self::getAliasList();
		if ( isset( $aliases[$caseFoldedAlias] ) ) {
			$name = $aliases[$caseFoldedAlias];
		} else {
			return array( null, null );
		}

		if ( !isset( $bits[1] ) ) { // bug 2087
			$par = null;
		} else {
			$par = $bits[1];
		}

		return array( $name, $par );
	}

	/**
	 * Check if a given name exist as a special page or as a special page alias
	 *
	 * @param string $name Name of a special page
	 * @return bool True if a special page exists with this name
	 */
	public static function exists( $name ) {
		list( $title, /*...*/ ) = self::resolveAlias( $name );

		$specialPageList = self::getPageList();
		return isset( $specialPageList[$title] );
	}

	/**
	 * Find the object with a given name and return it (or NULL)
	 *
	 * @param string $name Special page name, may be localised and/or an alias
	 * @return SpecialPage|null SpecialPage object or null if the page doesn't exist
	 */
	public static function getPage( $name ) {
		list( $realName, /*...*/ ) = self::resolveAlias( $name );

		$specialPageList = self::getPageList();

		if ( isset( $specialPageList[$realName] ) ) {
			$rec = $specialPageList[$realName];

			if ( is_callable( $rec ) ) {
				// Use callback to instantiate the special page
				$page = call_user_func( $rec );
			} elseif ( is_string( $rec ) ) {
				$className = $rec;
				$page = new $className;
			} elseif ( is_array( $rec ) ) {
				$className = array_shift( $rec );
				// @deprecated, officially since 1.18, unofficially since forever
				wfDeprecated( "Array syntax for \$wgSpecialPages is deprecated ($className), " .
					"define a subclass of SpecialPage instead.", '1.18' );
				$page = ObjectFactory::getObjectFromSpec( array(
					'class' => $className,
					'args' => $rec,
					'closure_expansion' => false,
				) );
			} elseif ( $rec instanceof SpecialPage ) {
				$page = $rec; //XXX: we should deep clone here
			} else {
				$page = null;
			}

			if ( $page instanceof SpecialPage ) {
				return $page;
			} else {
				// It's not a classname, nor a callback, nor a legacy constructor array,
				// nor a special page object. Give up.
				wfLogWarning( "Cannot instantiate special page $realName: bad spec!" );
				return null;
			}

		} else {
			return null;
		}
	}

	/**
	 * Return categorised listable special pages which are available
	 * for the current user, and everyone.
	 *
	 * @param User $user User object to check permissions, $wgUser will be used
	 *        if not provided
	 * @return array ( string => Specialpage )
	 */
	public static function getUsablePages( User $user = null ) {
		$pages = array();
		if ( $user === null ) {
			global $wgUser;
			$user = $wgUser;
		}
		foreach ( self::getPageList() as $name => $rec ) {
			$page = self::getPage( $name );
			if ( $page ) { // not null
				$page->setContext( RequestContext::getMain() );
				if ( $page->isListed()
					&& ( !$page->isRestricted() || $page->userCanExecute( $user ) )
				) {
					$pages[$name] = $page;
				}
			}
		}

		return $pages;
	}

	/**
	 * Return categorised listable special pages for all users
	 *
	 * @return array ( string => Specialpage )
	 */
	public static function getRegularPages() {
		$pages = array();
		foreach ( self::getPageList() as $name => $rec ) {
			$page = self::getPage( $name );
			if ( $page->isListed() && !$page->isRestricted() ) {
				$pages[$name] = $page;
			}
		}

		return $pages;
	}

	/**
	 * Return categorised listable special pages which are available
	 * for the current user, but not for everyone
	 *
	 * @param User|null $user User object to use or null for $wgUser
	 * @return array ( string => Specialpage )
	 */
	public static function getRestrictedPages( User $user = null ) {
		$pages = array();
		if ( $user === null ) {
			global $wgUser;
			$user = $wgUser;
		}
		foreach ( self::getPageList() as $name => $rec ) {
			$page = self::getPage( $name );
			if (
				$page->isListed()
				&& $page->isRestricted()
				&& $page->userCanExecute( $user )
			) {
				$pages[$name] = $page;
			}
		}

		return $pages;
	}

	/**
	 * Execute a special page path.
	 * The path may contain parameters, e.g. Special:Name/Params
	 * Extracts the special page name and call the execute method, passing the parameters
	 *
	 * Returns a title object if the page is redirected, false if there was no such special
	 * page, and true if it was successful.
	 *
	 * @param Title $title
	 * @param IContextSource $context
	 * @param bool $including Bool output is being captured for use in {{special:whatever}}
	 *
	 * @return bool
	 */
	public static function executePath( Title &$title, IContextSource &$context, $including = false ) {

		// @todo FIXME: Redirects broken due to this call
		$bits = explode( '/', $title->getDBkey(), 2 );
		$name = $bits[0];
		if ( !isset( $bits[1] ) ) { // bug 2087
			$par = null;
		} else {
			$par = $bits[1];
		}
		$page = self::getPage( $name );
		// Nonexistent?
		if ( !$page ) {
			$context->getOutput()->setArticleRelated( false );
			$context->getOutput()->setRobotPolicy( 'noindex,nofollow' );

			global $wgSend404Code;
			if ( $wgSend404Code ) {
				$context->getOutput()->setStatusCode( 404 );
			}

			$context->getOutput()->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );

			return false;
		}

		// Page exists, set the context
		$page->setContext( $context );

		if ( !$including ) {
			// Redirect to canonical alias for GET commands
			// Not for POST, we'd lose the post data, so it's best to just distribute
			// the request. Such POST requests are possible for old extensions that
			// generate self-links without being aware that their default name has
			// changed.
			if ( $name != $page->getLocalName() && !$context->getRequest()->wasPosted() ) {
				$query = $context->getRequest()->getQueryValues();
				unset( $query['title'] );
				$title = $page->getPageTitle( $par );
				$url = $title->getFullURL( $query );
				$context->getOutput()->redirect( $url );

				return $title;
			} else {
				$context->setTitle( $page->getPageTitle( $par ) );
			}
		} elseif ( !$page->isIncludable() ) {
			return false;
		}

		$page->including( $including );

		// Execute special page
		$page->run( $par );

		return true;
	}

	/**
	 * Just like executePath() but will override global variables and execute
	 * the page in "inclusion" mode. Returns true if the execution was
	 * successful or false if there was no such special page, or a title object
	 * if it was a redirect.
	 *
	 * Also saves the current $wgTitle, $wgOut, $wgRequest, $wgUser and $wgLang
	 * variables so that the special page will get the context it'd expect on a
	 * normal request, and then restores them to their previous values after.
	 *
	 * @param Title $title
	 * @param IContextSource $context
	 * @return string HTML fragment
	 */
	public static function capturePath( Title $title, IContextSource $context ) {
		global $wgOut, $wgTitle, $wgRequest, $wgUser, $wgLang;

		// Save current globals
		$oldTitle = $wgTitle;
		$oldOut = $wgOut;
		$oldRequest = $wgRequest;
		$oldUser = $wgUser;
		$oldLang = $wgLang;

		// Set the globals to the current context
		$wgTitle = $title;
		$wgOut = $context->getOutput();
		$wgRequest = $context->getRequest();
		$wgUser = $context->getUser();
		$wgLang = $context->getLanguage();

		// The useful part
		$ret = self::executePath( $title, $context, true );

		// And restore the old globals
		$wgTitle = $oldTitle;
		$wgOut = $oldOut;
		$wgRequest = $oldRequest;
		$wgUser = $oldUser;
		$wgLang = $oldLang;

		return $ret;
	}

	/**
	 * Get the local name for a specified canonical name
	 *
	 * @param string $name
	 * @param string|bool $subpage
	 * @return string
	 */
	public static function getLocalNameFor( $name, $subpage = false ) {
		global $wgContLang;
		$aliases = $wgContLang->getSpecialPageAliases();
		$aliasList = self::getAliasList();

		// Find the first alias that maps back to $name
		if ( isset( $aliases[$name] ) ) {
			$found = false;
			foreach ( $aliases[$name] as $alias ) {
				$caseFoldedAlias = $wgContLang->caseFold( $alias );
				$caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
				if ( isset( $aliasList[$caseFoldedAlias] ) &&
					$aliasList[$caseFoldedAlias] === $name
				) {
					$name = $alias;
					$found = true;
					break;
				}
			}
			if ( !$found ) {
				wfWarn( "Did not find a usable alias for special page '$name'. " .
					"It seems all defined aliases conflict?" );
			}
		} else {
			// Check if someone misspelled the correct casing
			if ( is_array( $aliases ) ) {
				foreach ( $aliases as $n => $values ) {
					if ( strcasecmp( $name, $n ) === 0 ) {
						wfWarn( "Found alias defined for $n when searching for " .
							"special page aliases for $name. Case mismatch?" );
						return self::getLocalNameFor( $n, $subpage );
					}
				}
			}

			wfWarn( "Did not find alias for special page '$name'. " .
				"Perhaps no aliases are defined for it?" );
		}

		if ( $subpage !== false && !is_null( $subpage ) ) {
			$name = "$name/$subpage";
		}

		return $wgContLang->ucfirst( $name );
	}

	/**
	 * Get a title for a given alias
	 *
	 * @param string $alias
	 * @return Title|null Title or null if there is no such alias
	 */
	public static function getTitleForAlias( $alias ) {
		list( $name, $subpage ) = self::resolveAlias( $alias );
		if ( $name != null ) {
			return SpecialPage::getTitleFor( $name, $subpage );
		} else {
			return null;
		}
	}
}