Refactor the factory/i18n/list/etc static methods from SpecialPage into their own...
[lhc/web/wiklou.git] / includes / SpecialPage.php
1 <?php
2 /**
3 * SpecialPage: handling special pages and lists thereof.
4 *
5 * To add a special page in an extension, add to $wgSpecialPages either
6 * an object instance or an array containing the name and constructor
7 * parameters. The latter is preferred for performance reasons.
8 *
9 * The object instantiated must be either an instance of SpecialPage or a
10 * sub-class thereof. It must have an execute() method, which sends the HTML
11 * for the special page to $wgOut. The parent class has an execute() method
12 * which distributes the call to the historical global functions. Additionally,
13 * execute() also checks if the user has the necessary access privileges
14 * and bails out if not.
15 *
16 * To add a core special page, use the similar static list in
17 * SpecialPage::$mList. To remove a core static special page at runtime, use
18 * a SpecialPage_initList hook.
19 *
20 * @file
21 * @ingroup SpecialPage
22 * @defgroup SpecialPage SpecialPage
23 */
24
25 /**
26 * Parent special page class, also static functions for handling the special
27 * page list.
28 * @ingroup SpecialPage
29 */
30 class SpecialPage {
31 /**#@+
32 * @access private
33 */
34 /**
35 * The canonical name of this special page
36 * Also used for the default <h1> heading, @see getDescription()
37 */
38 var $mName;
39 /**
40 * The local name of this special page
41 */
42 var $mLocalName;
43 /**
44 * Minimum user level required to access this page, or "" for anyone.
45 * Also used to categorise the pages in Special:Specialpages
46 */
47 var $mRestriction;
48 /**
49 * Listed in Special:Specialpages?
50 */
51 var $mListed;
52 /**
53 * Function name called by the default execute()
54 */
55 var $mFunction;
56 /**
57 * File which needs to be included before the function above can be called
58 */
59 var $mFile;
60 /**
61 * Whether or not this special page is being included from an article
62 */
63 var $mIncluding;
64 /**
65 * Whether the special page can be included in an article
66 */
67 var $mIncludable;
68 /**
69 * Query parameters that can be passed through redirects
70 */
71 var $mAllowedRedirectParams = array();
72 /**
73 * Query parameteres added by redirects
74 */
75 var $mAddedRedirectParams = array();
76 /**
77 * Current request context
78 * @var RequestContext
79 */
80 protected $mContext;
81
82 /**
83 * List of special page names to the subclass of SpecialPage which handles them.
84 */
85 static public $mList = array(
86 # Maintenance Reports
87 'BrokenRedirects' => 'BrokenRedirectsPage',
88 'Deadendpages' => 'DeadendpagesPage',
89 'DoubleRedirects' => 'DoubleRedirectsPage',
90 'Longpages' => 'LongpagesPage',
91 'Ancientpages' => 'AncientpagesPage',
92 'Lonelypages' => 'LonelypagesPage',
93 'Fewestrevisions' => 'FewestrevisionsPage',
94 'Withoutinterwiki' => 'WithoutinterwikiPage',
95 'Protectedpages' => 'SpecialProtectedpages',
96 'Protectedtitles' => 'SpecialProtectedtitles',
97 'Shortpages' => 'ShortpagesPage',
98 'Uncategorizedcategories' => 'UncategorizedcategoriesPage',
99 'Uncategorizedimages' => 'UncategorizedimagesPage',
100 'Uncategorizedpages' => 'UncategorizedpagesPage',
101 'Uncategorizedtemplates' => 'UncategorizedtemplatesPage',
102 'Unusedcategories' => 'UnusedcategoriesPage',
103 'Unusedimages' => 'UnusedimagesPage',
104 'Unusedtemplates' => 'UnusedtemplatesPage',
105 'Unwatchedpages' => 'UnwatchedpagesPage',
106 'Wantedcategories' => 'WantedcategoriesPage',
107 'Wantedfiles' => 'WantedfilesPage',
108 'Wantedpages' => 'WantedpagesPage',
109 'Wantedtemplates' => 'WantedtemplatesPage',
110
111 # List of pages
112 'Allpages' => 'SpecialAllpages',
113 'Prefixindex' => 'SpecialPrefixindex',
114 'Categories' => 'SpecialCategories',
115 'Disambiguations' => 'DisambiguationsPage',
116 'Listredirects' => 'ListredirectsPage',
117
118 # Login/create account
119 'Userlogin' => 'LoginForm',
120 'CreateAccount' => 'SpecialCreateAccount',
121
122 # Users and rights
123 'Block' => 'SpecialBlock',
124 'Unblock' => 'SpecialUnblock',
125 'BlockList' => 'SpecialBlockList',
126 'Resetpass' => 'SpecialResetpass',
127 'DeletedContributions' => 'DeletedContributionsPage',
128 'Preferences' => 'SpecialPreferences',
129 'Contributions' => 'SpecialContributions',
130 'Listgrouprights' => 'SpecialListGroupRights',
131 'Listusers' => 'SpecialListUsers' ,
132 'Listadmins' => 'SpecialListAdmins',
133 'Listbots' => 'SpecialListBots',
134 'Activeusers' => 'SpecialActiveUsers',
135 'Userrights' => 'UserrightsPage',
136 'EditWatchlist' => 'SpecialEditWatchlist',
137
138 # Recent changes and logs
139 'Newimages' => 'SpecialNewFiles',
140 'Log' => 'SpecialLog',
141 'Watchlist' => 'SpecialWatchlist',
142 'Newpages' => 'SpecialNewpages',
143 'Recentchanges' => 'SpecialRecentchanges',
144 'Recentchangeslinked' => 'SpecialRecentchangeslinked',
145 'Tags' => 'SpecialTags',
146
147 # Media reports and uploads
148 'Listfiles' => 'SpecialListFiles',
149 'Filepath' => 'SpecialFilepath',
150 'MIMEsearch' => 'MIMEsearchPage',
151 'FileDuplicateSearch' => 'FileDuplicateSearchPage',
152 'Upload' => 'SpecialUpload',
153 'UploadStash' => 'SpecialUploadStash',
154
155 # Wiki data and tools
156 'Statistics' => 'SpecialStatistics',
157 'Allmessages' => 'SpecialAllmessages',
158 'Version' => 'SpecialVersion',
159 'Lockdb' => 'SpecialLockdb',
160 'Unlockdb' => 'SpecialUnlockdb',
161
162 # Redirecting special pages
163 'LinkSearch' => 'LinkSearchPage',
164 'Randompage' => 'Randompage',
165 'Randomredirect' => 'SpecialRandomredirect',
166
167 # High use pages
168 'Mostlinkedcategories' => 'MostlinkedCategoriesPage',
169 'Mostimages' => 'MostimagesPage',
170 'Mostlinked' => 'MostlinkedPage',
171 'Mostlinkedtemplates' => 'MostlinkedTemplatesPage',
172 'Mostcategories' => 'MostcategoriesPage',
173 'Mostrevisions' => 'MostrevisionsPage',
174
175 # Page tools
176 'ComparePages' => 'SpecialComparePages',
177 'Export' => 'SpecialExport',
178 'Import' => 'SpecialImport',
179 'Undelete' => 'SpecialUndelete',
180 'Whatlinkshere' => 'SpecialWhatlinkshere',
181 'MergeHistory' => 'SpecialMergeHistory',
182
183 # Other
184 'Booksources' => 'SpecialBookSources',
185
186 # Unlisted / redirects
187 'Blankpage' => 'SpecialBlankpage',
188 'Blockme' => 'SpecialBlockme',
189 'Emailuser' => 'SpecialEmailUser',
190 'Movepage' => 'MovePageForm',
191 'Mycontributions' => 'SpecialMycontributions',
192 'Mypage' => 'SpecialMypage',
193 'Mytalk' => 'SpecialMytalk',
194 'Myuploads' => 'SpecialMyuploads',
195 'PermanentLink' => 'SpecialPermanentLink',
196 'Revisiondelete' => 'SpecialRevisionDelete',
197 'Specialpages' => 'SpecialSpecialpages',
198 'Userlogout' => 'SpecialUserlogout',
199 );
200
201 static public $mAliases;
202 static public $mListInitialised = false;
203
204 /**
205 * Initialise the special page list
206 * This must be called before accessing SpecialPage::$mList
207 * @deprecated since 1.18
208 */
209 static function initList() {
210 // Noop
211 }
212
213 /**
214 * @deprecated since 1.18
215 */
216 static function initAliasList() {
217 // Noop
218 }
219
220 /**
221 * Given a special page alias, return the special page name.
222 * Returns false if there is no such alias.
223 *
224 * @param $alias String
225 * @return String or false
226 * @deprecated since 1.18 call SpecialPageFactory method directly
227 */
228 static function resolveAlias( $alias ) {
229 list( $name, /*...*/ ) = SpecialPageFactory::resolveAlias( $alias );
230 return $name;
231 }
232
233 /**
234 * Given a special page name with a possible subpage, return an array
235 * where the first element is the special page name and the second is the
236 * subpage.
237 *
238 * @param $alias String
239 * @return Array
240 * @deprecated since 1.18 call SpecialPageFactory method directly
241 */
242 static function resolveAliasWithSubpage( $alias ) {
243 return SpecialPageFactory::resolveAlias( $alias );
244 }
245
246 /**
247 * Add a page to the list of valid special pages. This used to be the preferred
248 * method for adding special pages in extensions. It's now suggested that you add
249 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
250 *
251 * @param $page SpecialPage
252 * @deprecated in 1.7, warnings in 1.17, might be removed in 1.20
253 */
254 static function addPage( &$page ) {
255 wfDeprecated( __METHOD__ );
256 SpecialPageFactory::getList()->{$page->mName} = $page;
257 }
258
259 /**
260 * Add a page to a certain display group for Special:SpecialPages
261 *
262 * @param $page Mixed: SpecialPage or string
263 * @param $group String
264 * @deprecated since 1.18 call SpecialPageFactory method directly
265 */
266 static function setGroup( $page, $group ) {
267 return SpecialPageFactory::setGroup( $page, $group );
268 }
269
270 /**
271 * Add a page to a certain display group for Special:SpecialPages
272 *
273 * @param $page SpecialPage
274 * @deprecated since 1.18 call SpecialPageFactory method directly
275 */
276 static function getGroup( &$page ) {
277 return SpecialPageFactory::getGroup( $page );
278 }
279
280 /**
281 * Remove a special page from the list
282 * Formerly used to disable expensive or dangerous special pages. The
283 * preferred method is now to add a SpecialPage_initList hook.
284 * @deprecated since 1.18
285 */
286 static function removePage( $name ) {
287 unset( SpecialPageFactory::getList()->$name );
288 }
289
290 /**
291 * Check if a given name exist as a special page or as a special page alias
292 *
293 * @param $name String: name of a special page
294 * @return Boolean: true if a special page exists with this name
295 * @deprecated since 1.18 call SpecialPageFactory method directly
296 */
297 static function exists( $name ) {
298 return SpecialPageFactory::exists( $name );
299 }
300
301 /**
302 * Find the object with a given name and return it (or NULL)
303 *
304 * @param $name String
305 * @return SpecialPage object or null if the page doesn't exist
306 * @deprecated since 1.18 call SpecialPageFactory method directly
307 */
308 static function getPage( $name ) {
309 return SpecialPageFactory::getPage( $name );
310 }
311
312 /**
313 * Get a special page with a given localised name, or NULL if there
314 * is no such special page.
315 *
316 * @return SpecialPage object or null if the page doesn't exist
317 * @deprecated since 1.18 call SpecialPageFactory method directly
318 */
319 static function getPageByAlias( $alias ) {
320 return SpecialPageFactory::getPage( $alias );
321 }
322
323 /**
324 * Return categorised listable special pages which are available
325 * for the current user, and everyone.
326 *
327 * @return Associative array mapping page's name to its SpecialPage object
328 * @deprecated since 1.18 call SpecialPageFactory method directly
329 */
330 static function getUsablePages() {
331 return SpecialPageFactory::getUsablePages();
332 }
333
334 /**
335 * Return categorised listable special pages for all users
336 *
337 * @return Associative array mapping page's name to its SpecialPage object
338 * @deprecated since 1.18 call SpecialPageFactory method directly
339 */
340 static function getRegularPages() {
341 return SpecialPageFactory::getRegularPages();
342 }
343
344 /**
345 * Return categorised listable special pages which are available
346 * for the current user, but not for everyone
347 *
348 * @return Associative array mapping page's name to its SpecialPage object
349 * @deprecated since 1.18 call SpecialPageFactory method directly
350 */
351 static function getRestrictedPages() {
352 return SpecialPageFactory::getRestrictedPages();
353 }
354
355 /**
356 * Execute a special page path.
357 * The path may contain parameters, e.g. Special:Name/Params
358 * Extracts the special page name and call the execute method, passing the parameters
359 *
360 * Returns a title object if the page is redirected, false if there was no such special
361 * page, and true if it was successful.
362 *
363 * @param $title Title object
364 * @param $context RequestContext
365 * @param $including Bool output is being captured for use in {{special:whatever}}
366 * @deprecated since 1.18 call SpecialPageFactory method directly
367 */
368 public static function executePath( &$title, RequestContext &$context, $including = false ) {
369 return SpecialPageFactory::executePath( $title, $context, $including );
370 }
371
372 /**
373 * Just like executePath() except it returns the HTML instead of outputting it
374 * Returns false if there was no such special page, or a title object if it was
375 * a redirect.
376 *
377 * @return String: HTML fragment
378 * @deprecated since 1.18 call SpecialPageFactory method directly
379 */
380 static function capturePath( &$title ) {
381 return SpecialPageFactory::capturePath( $title );
382 }
383
384 /**
385 * Get the local name for a specified canonical name
386 *
387 * @param $name String
388 * @param $subpage Mixed: boolean false, or string
389 *
390 * @return String
391 * @deprecated since 1.18 call SpecialPageFactory method directly
392 */
393 static function getLocalNameFor( $name, $subpage = false ) {
394 return SpecialPageFactory::getLocalNameFor( $name, $subpage );
395 }
396
397 /**
398 * Get a localised Title object for a specified special page name
399 *
400 * @return Title object
401 */
402 public static function getTitleFor( $name, $subpage = false ) {
403 $name = SpecialPageFactory::getLocalNameFor( $name, $subpage );
404 if ( $name ) {
405 return Title::makeTitle( NS_SPECIAL, $name );
406 } else {
407 throw new MWException( "Invalid special page name \"$name\"" );
408 }
409 }
410
411 /**
412 * Get a localised Title object for a page name with a possibly unvalidated subpage
413 *
414 * @return Title object or null if the page doesn't exist
415 */
416 public static function getSafeTitleFor( $name, $subpage = false ) {
417 $name = SpecialPageFactory::getLocalNameFor( $name, $subpage );
418 if ( $name ) {
419 return Title::makeTitleSafe( NS_SPECIAL, $name );
420 } else {
421 return null;
422 }
423 }
424
425 /**
426 * Get a title for a given alias
427 *
428 * @return Title or null if there is no such alias
429 * @deprecated since 1.18 call SpecialPageFactory method directly
430 */
431 static function getTitleForAlias( $alias ) {
432 return SpecialPageFactory::getTitleForAlias( $alias );
433 }
434
435 /**
436 * Default constructor for special pages
437 * Derivative classes should call this from their constructor
438 * Note that if the user does not have the required level, an error message will
439 * be displayed by the default execute() method, without the global function ever
440 * being called.
441 *
442 * If you override execute(), you can recover the default behaviour with userCanExecute()
443 * and displayRestrictionError()
444 *
445 * @param $name String: name of the special page, as seen in links and URLs
446 * @param $restriction String: user right required, e.g. "block" or "delete"
447 * @param $listed Boolean: whether the page is listed in Special:Specialpages
448 * @param $function Callback: function called by execute(). By default it is constructed from $name
449 * @param $file String: file which is included by execute(). It is also constructed from $name by default
450 * @param $includable Boolean: whether the page can be included in normal pages
451 */
452 public function __construct( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
453 $this->init( $name, $restriction, $listed, $function, $file, $includable );
454 }
455
456 /**
457 * Do the real work for the constructor, mainly so __call() can intercept
458 * calls to SpecialPage()
459 * @see __construct() for param docs
460 */
461 private function init( $name, $restriction, $listed, $function, $file, $includable ) {
462 $this->mName = $name;
463 $this->mRestriction = $restriction;
464 $this->mListed = $listed;
465 $this->mIncludable = $includable;
466 if ( !$function ) {
467 $this->mFunction = 'wfSpecial'.$name;
468 } else {
469 $this->mFunction = $function;
470 }
471 if ( $file === 'default' ) {
472 $this->mFile = dirname(__FILE__) . "/specials/Special$name.php";
473 } else {
474 $this->mFile = $file;
475 }
476 }
477
478 /**
479 * Use PHP's magic __call handler to get calls to the old PHP4 constructor
480 * because PHP E_STRICT yells at you for having __construct() and SpecialPage()
481 *
482 * @param $fName String Name of called method
483 * @param $a Array Arguments to the method
484 * @deprecated since 1.17, call parent::__construct()
485 */
486 public function __call( $fName, $a ) {
487 // Sometimes $fName is SpecialPage, sometimes it's specialpage. <3 PHP
488 if( strtolower( $fName ) == 'specialpage' ) {
489 // Deprecated messages now, remove in 1.19 or 1.20?
490 wfDeprecated( __METHOD__ );
491
492 $name = isset( $a[0] ) ? $a[0] : '';
493 $restriction = isset( $a[1] ) ? $a[1] : '';
494 $listed = isset( $a[2] ) ? $a[2] : true;
495 $function = isset( $a[3] ) ? $a[3] : false;
496 $file = isset( $a[4] ) ? $a[4] : 'default';
497 $includable = isset( $a[5] ) ? $a[5] : false;
498 $this->init( $name, $restriction, $listed, $function, $file, $includable );
499 } else {
500 $className = get_class( $this );
501 throw new MWException( "Call to undefined method $className::$fName" );
502 }
503 }
504
505 /**#@+
506 * Accessor
507 *
508 * @deprecated
509 */
510 function getName() { return $this->mName; }
511 function getRestriction() { return $this->mRestriction; }
512 function getFile() { return $this->mFile; }
513 function isListed() { return $this->mListed; }
514 /**#@-*/
515
516 /**#@+
517 * Accessor and mutator
518 */
519 function name( $x = null ) { return wfSetVar( $this->mName, $x ); }
520 function restrictions( $x = null) {
521 # Use the one below this
522 wfDeprecated( __METHOD__ );
523 return wfSetVar( $this->mRestriction, $x );
524 }
525 function restriction( $x = null) { return wfSetVar( $this->mRestriction, $x ); }
526 function listed( $x = null) { return wfSetVar( $this->mListed, $x ); }
527 function func( $x = null) { return wfSetVar( $this->mFunction, $x ); }
528 function file( $x = null) { return wfSetVar( $this->mFile, $x ); }
529 function includable( $x = null ) { return wfSetVar( $this->mIncludable, $x ); }
530 function including( $x = null ) { return wfSetVar( $this->mIncluding, $x ); }
531 /**#@-*/
532
533 /**
534 * Get the localised name of the special page
535 */
536 function getLocalName() {
537 if ( !isset( $this->mLocalName ) ) {
538 $this->mLocalName = SpecialPageFactory::getLocalNameFor( $this->mName );
539 }
540 return $this->mLocalName;
541 }
542
543 /**
544 * Is this page expensive (for some definition of expensive)?
545 * Expensive pages are disabled or cached in miser mode. Originally used
546 * (and still overridden) by QueryPage and subclasses, moved here so that
547 * Special:SpecialPages can safely call it for all special pages.
548 *
549 * @return Boolean
550 */
551 public function isExpensive() {
552 return false;
553 }
554
555 /**
556 * Can be overridden by subclasses with more complicated permissions
557 * schemes.
558 *
559 * @return Boolean: should the page be displayed with the restricted-access
560 * pages?
561 */
562 public function isRestricted() {
563 global $wgGroupPermissions;
564 // DWIM: If all anons can do something, then it is not restricted
565 return $this->mRestriction != '' && empty($wgGroupPermissions['*'][$this->mRestriction]);
566 }
567
568 /**
569 * Checks if the given user (identified by an object) can execute this
570 * special page (as defined by $mRestriction). Can be overridden by sub-
571 * classes with more complicated permissions schemes.
572 *
573 * @param $user User: the user to check
574 * @return Boolean: does the user have permission to view the page?
575 */
576 public function userCanExecute( $user ) {
577 return $user->isAllowed( $this->mRestriction );
578 }
579
580 /**
581 * Output an error message telling the user what access level they have to have
582 */
583 function displayRestrictionError() {
584 throw new PermissionsError( $this->mRestriction );
585 }
586
587 /**
588 * Sets headers - this should be called from the execute() method of all derived classes!
589 */
590 function setHeaders() {
591 $out = $this->getOutput();
592 $out->setArticleRelated( false );
593 $out->setRobotPolicy( "noindex,nofollow" );
594 $out->setPageTitle( $this->getDescription() );
595 }
596
597 /**
598 * Default execute method
599 * Checks user permissions, calls the function given in mFunction
600 *
601 * This may be overridden by subclasses.
602 */
603 function execute( $par ) {
604 $this->setHeaders();
605
606 if ( $this->userCanExecute( $this->getUser() ) ) {
607 $func = $this->mFunction;
608 // only load file if the function does not exist
609 if(!is_callable($func) and $this->mFile) {
610 require_once( $this->mFile );
611 }
612 $this->outputHeader();
613 call_user_func( $func, $par, $this );
614 } else {
615 $this->displayRestrictionError();
616 }
617 }
618
619 /**
620 * Outputs a summary message on top of special pages
621 * Per default the message key is the canonical name of the special page
622 * May be overriden, i.e. by extensions to stick with the naming conventions
623 * for message keys: 'extensionname-xxx'
624 *
625 * @param $summaryMessageKey String: message key of the summary
626 */
627 function outputHeader( $summaryMessageKey = '' ) {
628 global $wgContLang;
629
630 if( $summaryMessageKey == '' ) {
631 $msg = $wgContLang->lc( $this->name() ) . '-summary';
632 } else {
633 $msg = $summaryMessageKey;
634 }
635 if ( !wfMessage( $msg )->isBlank() and ! $this->including() ) {
636 $this->getOutput()->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
637 }
638
639 }
640
641 /**
642 * Returns the name that goes in the \<h1\> in the special page itself, and
643 * also the name that will be listed in Special:Specialpages
644 *
645 * Derived classes can override this, but usually it is easier to keep the
646 * default behaviour. Messages can be added at run-time, see
647 * MessageCache.php.
648 *
649 * @return String
650 */
651 function getDescription() {
652 return wfMsg( strtolower( $this->mName ) );
653 }
654
655 /**
656 * Get a self-referential title object
657 *
658 * @return Title object
659 */
660 function getTitle( $subpage = false ) {
661 return self::getTitleFor( $this->mName, $subpage );
662 }
663
664 /**
665 * Set whether this page is listed in Special:Specialpages, at run-time
666 *
667 * @return Bool
668 */
669 function setListed( $listed ) {
670 return wfSetVar( $this->mListed, $listed );
671 }
672
673 /**
674 * If the special page is a redirect, then get the Title object it redirects to.
675 * False otherwise.
676 *
677 * @return Title|false
678 */
679 function getRedirect( $subpage ) {
680 return false;
681 }
682
683 /**
684 * Return part of the request string for a special redirect page
685 * This allows passing, e.g. action=history to Special:Mypage, etc.
686 *
687 * @return String
688 */
689 function getRedirectQuery() {
690 $params = array();
691
692 foreach( $this->mAllowedRedirectParams as $arg ) {
693 if( $this->getContext()->request->getVal( $arg, null ) !== null ){
694 $params[$arg] = $this->getContext()->request->getVal( $arg );
695 }
696 }
697
698 foreach( $this->mAddedRedirectParams as $arg => $val ) {
699 $params[$arg] = $val;
700 }
701
702 return count( $params )
703 ? $params
704 : false;
705 }
706
707 /**
708 * Sets the context this SpecialPage is executed in
709 *
710 * @param $context RequestContext
711 * @since 1.18
712 */
713 public function setContext( $context ) {
714 $this->mContext = $context;
715 }
716
717 /**
718 * Gets the context this SpecialPage is executed in
719 *
720 * @return RequestContext
721 * @since 1.18
722 */
723 public function getContext() {
724 if ( $this->mContext instanceof RequestContext ) {
725 return $this->mContext;
726 } else {
727 wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
728 return RequestContext::getMain();
729 }
730 }
731
732 /**
733 * Get the WebRequest being used for this instance
734 *
735 * @return WebRequest
736 * @since 1.18
737 */
738 public function getRequest() {
739 return $this->getContext()->getRequest();
740 }
741
742 /**
743 * Get the OutputPage being used for this instance
744 *
745 * @return OutputPage
746 * @since 1.18
747 */
748 public function getOutput() {
749 return $this->getContext()->getOutput();
750 }
751
752 /**
753 * Shortcut to get the skin being used for this instance
754 *
755 * @return User
756 * @since 1.18
757 */
758 public function getUser() {
759 return $this->getContext()->getUser();
760 }
761
762 /**
763 * Shortcut to get the skin being used for this instance
764 *
765 * @return Skin
766 * @since 1.18
767 */
768 public function getSkin() {
769 return $this->getContext()->getSkin();
770 }
771
772 /**
773 * Return the full title, including $par
774 *
775 * @return Title
776 * @since 1.18
777 */
778 public function getFullTitle() {
779 return $this->getContext()->getTitle();
780 }
781
782 /**
783 * Wrapper around wfMessage that sets the current context. Currently this
784 * is only the title.
785 *
786 * @see wfMessage
787 */
788 public function msg( /* $args */ ) {
789 return call_user_func_array( 'wfMessage', func_get_args() )->title( $this->getFullTitle() );
790 }
791 }
792
793 /**
794 * Shortcut to construct a special page which is unlisted by default
795 * @ingroup SpecialPage
796 */
797 class UnlistedSpecialPage extends SpecialPage
798 {
799 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
800 parent::__construct( $name, $restriction, false, $function, $file );
801 }
802 }
803
804 /**
805 * Shortcut to construct an includable special page
806 * @ingroup SpecialPage
807 */
808 class IncludableSpecialPage extends SpecialPage
809 {
810 function __construct( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
811 parent::__construct( $name, $restriction, $listed, $function, $file, true );
812 }
813 }
814
815 /**
816 * Shortcut to construct a special page alias.
817 * @ingroup SpecialPage
818 */
819 abstract class SpecialRedirectToSpecial extends UnlistedSpecialPage {
820 var $redirName, $redirSubpage;
821
822 function __construct( $name, $redirName, $redirSubpage = false, $allowedRedirectParams = array(), $addedRedirectParams = array() ) {
823 parent::__construct( $name );
824 $this->redirName = $redirName;
825 $this->redirSubpage = $redirSubpage;
826 $this->mAllowedRedirectParams = $allowedRedirectParams;
827 $this->mAddedRedirectParams = $addedRedirectParams;
828 }
829
830 function getRedirect( $subpage ) {
831 if ( $this->redirSubpage === false ) {
832 return SpecialPageFactory::getTitleFor( $this->redirName, $subpage );
833 } else {
834 return SpecialPageFactory::getTitleFor( $this->redirName, $this->redirSubpage );
835 }
836 }
837 }
838
839 /**
840 * ListAdmins --> ListUsers/admin
841 */
842 class SpecialListAdmins extends SpecialRedirectToSpecial {
843 function __construct(){
844 parent::__construct( 'ListAdmins', 'ListUsers', 'sysop' );
845 }
846 }
847
848 /**
849 * ListBots --> ListUsers/admin
850 */
851 class SpecialListBots extends SpecialRedirectToSpecial {
852 function __construct(){
853 parent::__construct( 'ListAdmins', 'ListUsers', 'bot' );
854 }
855 }
856
857 /**
858 * CreateAccount --> UserLogin/signup
859 * FIXME: this (and the rest of the login frontend) needs to die a horrible painful death
860 */
861 class SpecialCreateAccount extends SpecialRedirectToSpecial {
862 function __construct(){
863 parent::__construct( 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) );
864 }
865 }
866 /**
867 * SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
868 * are used to get user independant links pointing to the user page, talk
869 * page and list of contributions.
870 * This can let us cache a single copy of any generated content for all
871 * users.
872 */
873
874 /**
875 * Shortcut to construct a special page pointing to current user user's page.
876 * @ingroup SpecialPage
877 */
878 class SpecialMypage extends UnlistedSpecialPage {
879 function __construct() {
880 parent::__construct( 'Mypage' );
881 $this->mAllowedRedirectParams = array( 'action' , 'preload' , 'editintro',
882 'section', 'oldid', 'diff', 'dir' );
883 }
884
885 function getRedirect( $subpage ) {
886 global $wgUser;
887 if ( strval( $subpage ) !== '' ) {
888 return Title::makeTitle( NS_USER, $wgUser->getName() . '/' . $subpage );
889 } else {
890 return Title::makeTitle( NS_USER, $wgUser->getName() );
891 }
892 }
893 }
894
895 /**
896 * Shortcut to construct a special page pointing to current user talk page.
897 * @ingroup SpecialPage
898 */
899 class SpecialMytalk extends UnlistedSpecialPage {
900 function __construct() {
901 parent::__construct( 'Mytalk' );
902 $this->mAllowedRedirectParams = array( 'action' , 'preload' , 'editintro',
903 'section', 'oldid', 'diff', 'dir' );
904 }
905
906 function getRedirect( $subpage ) {
907 global $wgUser;
908 if ( strval( $subpage ) !== '' ) {
909 return Title::makeTitle( NS_USER_TALK, $wgUser->getName() . '/' . $subpage );
910 } else {
911 return Title::makeTitle( NS_USER_TALK, $wgUser->getName() );
912 }
913 }
914 }
915
916 /**
917 * Shortcut to construct a special page pointing to current user contributions.
918 * @ingroup SpecialPage
919 */
920 class SpecialMycontributions extends UnlistedSpecialPage {
921 function __construct() {
922 parent::__construct( 'Mycontributions' );
923 $this->mAllowedRedirectParams = array( 'limit', 'namespace', 'tagfilter',
924 'offset', 'dir', 'year', 'month', 'feed' );
925 }
926
927 function getRedirect( $subpage ) {
928 global $wgUser;
929 return SpecialPageFactory::getTitleFor( 'Contributions', $wgUser->getName() );
930 }
931 }
932
933 /**
934 * Redirect to Special:Listfiles?user=$wgUser
935 */
936 class SpecialMyuploads extends UnlistedSpecialPage {
937 function __construct() {
938 parent::__construct( 'Myuploads' );
939 $this->mAllowedRedirectParams = array( 'limit' );
940 }
941
942 function getRedirect( $subpage ) {
943 global $wgUser;
944 return SpecialPageFactory::getTitleFor( 'Listfiles', $wgUser->getName() );
945 }
946 }
947
948 /**
949 * Redirect from Special:PermanentLink/### to index.php?oldid=###
950 */
951 class SpecialPermanentLink extends UnlistedSpecialPage {
952 function __construct() {
953 parent::__construct( 'PermanentLink' );
954 $this->mAllowedRedirectParams = array();
955 }
956
957 function getRedirect( $subpage ) {
958 $subpage = intval( $subpage );
959 $this->mAddedRedirectParams['oldid'] = $subpage;
960 return true;
961 }
962 }