Follow-up r86255: don't special-case redirecting special pages in executePath(),...
[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 // The canonical name of this special page
33 // Also used for the default <h1> heading, @see getDescription()
34 /*private*/ var $mName;
35
36 // The local name of this special page
37 private $mLocalName;
38
39 // Minimum user level required to access this page, or "" for anyone.
40 // Also used to categorise the pages in Special:Specialpages
41 private $mRestriction;
42
43 // Listed in Special:Specialpages?
44 private $mListed;
45
46 // Function name called by the default execute()
47 private $mFunction;
48
49 // File which needs to be included before the function above can be called
50 private $mFile;
51
52 // Whether or not this special page is being included from an article
53 protected $mIncluding;
54
55 // Whether the special page can be included in an article
56 protected $mIncludable;
57
58 /**
59 * Current request context
60 * @var RequestContext
61 */
62 protected $mContext;
63
64 /**
65 * Initialise the special page list
66 * This must be called before accessing SpecialPage::$mList
67 * @deprecated since 1.18
68 */
69 static function initList() {
70 // Noop
71 }
72
73 /**
74 * @deprecated since 1.18
75 */
76 static function initAliasList() {
77 // Noop
78 }
79
80 /**
81 * Given a special page alias, return the special page name.
82 * Returns false if there is no such alias.
83 *
84 * @param $alias String
85 * @return String or false
86 * @deprecated since 1.18 call SpecialPageFactory method directly
87 */
88 static function resolveAlias( $alias ) {
89 list( $name, /*...*/ ) = SpecialPageFactory::resolveAlias( $alias );
90 return $name;
91 }
92
93 /**
94 * Given a special page name with a possible subpage, return an array
95 * where the first element is the special page name and the second is the
96 * subpage.
97 *
98 * @param $alias String
99 * @return Array
100 * @deprecated since 1.18 call SpecialPageFactory method directly
101 */
102 static function resolveAliasWithSubpage( $alias ) {
103 return SpecialPageFactory::resolveAlias( $alias );
104 }
105
106 /**
107 * Add a page to the list of valid special pages. This used to be the preferred
108 * method for adding special pages in extensions. It's now suggested that you add
109 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
110 *
111 * @param $page SpecialPage
112 * @deprecated in 1.7, warnings in 1.17, might be removed in 1.20
113 */
114 static function addPage( &$page ) {
115 wfDeprecated( __METHOD__ );
116 SpecialPageFactory::getList()->{$page->mName} = $page;
117 }
118
119 /**
120 * Add a page to a certain display group for Special:SpecialPages
121 *
122 * @param $page Mixed: SpecialPage or string
123 * @param $group String
124 * @deprecated since 1.18 call SpecialPageFactory method directly
125 */
126 static function setGroup( $page, $group ) {
127 return SpecialPageFactory::setGroup( $page, $group );
128 }
129
130 /**
131 * Add a page to a certain display group for Special:SpecialPages
132 *
133 * @param $page SpecialPage
134 * @deprecated since 1.18 call SpecialPageFactory method directly
135 */
136 static function getGroup( &$page ) {
137 return SpecialPageFactory::getGroup( $page );
138 }
139
140 /**
141 * Remove a special page from the list
142 * Formerly used to disable expensive or dangerous special pages. The
143 * preferred method is now to add a SpecialPage_initList hook.
144 * @deprecated since 1.18
145 */
146 static function removePage( $name ) {
147 unset( SpecialPageFactory::getList()->$name );
148 }
149
150 /**
151 * Check if a given name exist as a special page or as a special page alias
152 *
153 * @param $name String: name of a special page
154 * @return Boolean: true if a special page exists with this name
155 * @deprecated since 1.18 call SpecialPageFactory method directly
156 */
157 static function exists( $name ) {
158 return SpecialPageFactory::exists( $name );
159 }
160
161 /**
162 * Find the object with a given name and return it (or NULL)
163 *
164 * @param $name String
165 * @return SpecialPage object or null if the page doesn't exist
166 * @deprecated since 1.18 call SpecialPageFactory method directly
167 */
168 static function getPage( $name ) {
169 return SpecialPageFactory::getPage( $name );
170 }
171
172 /**
173 * Get a special page with a given localised name, or NULL if there
174 * is no such special page.
175 *
176 * @return SpecialPage object or null if the page doesn't exist
177 * @deprecated since 1.18 call SpecialPageFactory method directly
178 */
179 static function getPageByAlias( $alias ) {
180 return SpecialPageFactory::getPage( $alias );
181 }
182
183 /**
184 * Return categorised listable special pages which are available
185 * for the current user, and everyone.
186 *
187 * @return Associative array mapping page's name to its SpecialPage object
188 * @deprecated since 1.18 call SpecialPageFactory method directly
189 */
190 static function getUsablePages() {
191 return SpecialPageFactory::getUsablePages();
192 }
193
194 /**
195 * Return categorised listable special pages for all users
196 *
197 * @return Associative array mapping page's name to its SpecialPage object
198 * @deprecated since 1.18 call SpecialPageFactory method directly
199 */
200 static function getRegularPages() {
201 return SpecialPageFactory::getRegularPages();
202 }
203
204 /**
205 * Return categorised listable special pages which are available
206 * for the current user, but not for everyone
207 *
208 * @return Associative array mapping page's name to its SpecialPage object
209 * @deprecated since 1.18 call SpecialPageFactory method directly
210 */
211 static function getRestrictedPages() {
212 return SpecialPageFactory::getRestrictedPages();
213 }
214
215 /**
216 * Execute a special page path.
217 * The path may contain parameters, e.g. Special:Name/Params
218 * Extracts the special page name and call the execute method, passing the parameters
219 *
220 * Returns a title object if the page is redirected, false if there was no such special
221 * page, and true if it was successful.
222 *
223 * @param $title Title object
224 * @param $context RequestContext
225 * @param $including Bool output is being captured for use in {{special:whatever}}
226 * @deprecated since 1.18 call SpecialPageFactory method directly
227 */
228 public static function executePath( &$title, RequestContext &$context, $including = false ) {
229 return SpecialPageFactory::executePath( $title, $context, $including );
230 }
231
232 /**
233 * Just like executePath() except it returns the HTML instead of outputting it
234 * Returns false if there was no such special page, or a title object if it was
235 * a redirect.
236 *
237 * @return String: HTML fragment
238 * @deprecated since 1.18 call SpecialPageFactory method directly
239 */
240 static function capturePath( &$title ) {
241 return SpecialPageFactory::capturePath( $title );
242 }
243
244 /**
245 * Get the local name for a specified canonical name
246 *
247 * @param $name String
248 * @param $subpage Mixed: boolean false, or string
249 *
250 * @return String
251 * @deprecated since 1.18 call SpecialPageFactory method directly
252 */
253 static function getLocalNameFor( $name, $subpage = false ) {
254 return SpecialPageFactory::getLocalNameFor( $name, $subpage );
255 }
256
257 /**
258 * Get a localised Title object for a specified special page name
259 *
260 * @return Title object
261 */
262 public static function getTitleFor( $name, $subpage = false ) {
263 $name = SpecialPageFactory::getLocalNameFor( $name, $subpage );
264 if ( $name ) {
265 return Title::makeTitle( NS_SPECIAL, $name );
266 } else {
267 throw new MWException( "Invalid special page name \"$name\"" );
268 }
269 }
270
271 /**
272 * Get a localised Title object for a page name with a possibly unvalidated subpage
273 *
274 * @return Title object or null if the page doesn't exist
275 */
276 public static function getSafeTitleFor( $name, $subpage = false ) {
277 $name = SpecialPageFactory::getLocalNameFor( $name, $subpage );
278 if ( $name ) {
279 return Title::makeTitleSafe( NS_SPECIAL, $name );
280 } else {
281 return null;
282 }
283 }
284
285 /**
286 * Get a title for a given alias
287 *
288 * @return Title or null if there is no such alias
289 * @deprecated since 1.18 call SpecialPageFactory method directly
290 */
291 static function getTitleForAlias( $alias ) {
292 return SpecialPageFactory::getTitleForAlias( $alias );
293 }
294
295 /**
296 * Default constructor for special pages
297 * Derivative classes should call this from their constructor
298 * Note that if the user does not have the required level, an error message will
299 * be displayed by the default execute() method, without the global function ever
300 * being called.
301 *
302 * If you override execute(), you can recover the default behaviour with userCanExecute()
303 * and displayRestrictionError()
304 *
305 * @param $name String: name of the special page, as seen in links and URLs
306 * @param $restriction String: user right required, e.g. "block" or "delete"
307 * @param $listed Boolean: whether the page is listed in Special:Specialpages
308 * @param $function Callback: function called by execute(). By default it is constructed from $name
309 * @param $file String: file which is included by execute(). It is also constructed from $name by default
310 * @param $includable Boolean: whether the page can be included in normal pages
311 */
312 public function __construct( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
313 $this->init( $name, $restriction, $listed, $function, $file, $includable );
314 }
315
316 /**
317 * Do the real work for the constructor, mainly so __call() can intercept
318 * calls to SpecialPage()
319 * @see __construct() for param docs
320 */
321 private function init( $name, $restriction, $listed, $function, $file, $includable ) {
322 $this->mName = $name;
323 $this->mRestriction = $restriction;
324 $this->mListed = $listed;
325 $this->mIncludable = $includable;
326 if ( !$function ) {
327 $this->mFunction = 'wfSpecial'.$name;
328 } else {
329 $this->mFunction = $function;
330 }
331 if ( $file === 'default' ) {
332 $this->mFile = dirname(__FILE__) . "/specials/Special$name.php";
333 } else {
334 $this->mFile = $file;
335 }
336 }
337
338 /**
339 * Use PHP's magic __call handler to get calls to the old PHP4 constructor
340 * because PHP E_STRICT yells at you for having __construct() and SpecialPage()
341 *
342 * @param $fName String Name of called method
343 * @param $a Array Arguments to the method
344 * @deprecated since 1.17, call parent::__construct()
345 */
346 public function __call( $fName, $a ) {
347 // Sometimes $fName is SpecialPage, sometimes it's specialpage. <3 PHP
348 if( strtolower( $fName ) == 'specialpage' ) {
349 // Deprecated messages now, remove in 1.19 or 1.20?
350 wfDeprecated( __METHOD__ );
351
352 $name = isset( $a[0] ) ? $a[0] : '';
353 $restriction = isset( $a[1] ) ? $a[1] : '';
354 $listed = isset( $a[2] ) ? $a[2] : true;
355 $function = isset( $a[3] ) ? $a[3] : false;
356 $file = isset( $a[4] ) ? $a[4] : 'default';
357 $includable = isset( $a[5] ) ? $a[5] : false;
358 $this->init( $name, $restriction, $listed, $function, $file, $includable );
359 } else {
360 $className = get_class( $this );
361 throw new MWException( "Call to undefined method $className::$fName" );
362 }
363 }
364
365 /**
366 * Get the name of this Special Page.
367 * @return String
368 */
369 function getName() {
370 return $this->mName;
371 }
372
373 /**
374 * Get the permission that a user must have to execute this page
375 * @return String
376 */
377 function getRestriction() {
378 return $this->mRestriction;
379 }
380
381 /**
382 * Get the file which will be included by SpecialPage::execute() if your extension is
383 * still stuck in the past and hasn't overridden the execute() method. No modern code
384 * should want or need to know this.
385 * @return String
386 * @deprecated since 1.18
387 */
388 function getFile() {
389 return $this->mFile;
390 }
391
392 // FIXME: decide which syntax to use for this, and stick to it
393 /**
394 * Whether this special page is listed in Special:SpecialPages
395 * @since r3583 (v1.3)
396 * @return Bool
397 */
398 function isListed() {
399 return $this->mListed;
400 }
401 /**
402 * Set whether this page is listed in Special:Specialpages, at run-time
403 * @since r3583 (v1.3)
404 * @return Bool
405 */
406 function setListed( $listed ) {
407 return wfSetVar( $this->mListed, $listed );
408 }
409 /**
410 * Get or set whether this special page is listed in Special:SpecialPages
411 * @since r11308 (v1.6)
412 * @return Bool
413 */
414 function listed( $x = null) {
415 return wfSetVar( $this->mListed, $x );
416 }
417
418 /**
419 * Whether it's allowed to transclude the special page via {{Special:Foo/params}}
420 * @return Bool
421 */
422 public function isIncludable(){
423 return $this->mIncludable;
424 }
425
426 /**
427 * These mutators are very evil, as the relevant variables should not mutate. So
428 * don't use them.
429 * @deprecated since 1.18
430 */
431 function name( $x = null ) { return wfSetVar( $this->mName, $x ); }
432 function restriction( $x = null) { return wfSetVar( $this->mRestriction, $x ); }
433 function func( $x = null) { return wfSetVar( $this->mFunction, $x ); }
434 function file( $x = null) { return wfSetVar( $this->mFile, $x ); }
435 function includable( $x = null ) { return wfSetVar( $this->mIncludable, $x ); }
436
437 /**
438 * Whether the special page is being evaluated via transclusion
439 * @return Bool
440 */
441 function including( $x = null ) {
442 return wfSetVar( $this->mIncluding, $x );
443 }
444
445 /**
446 * Get the localised name of the special page
447 */
448 function getLocalName() {
449 if ( !isset( $this->mLocalName ) ) {
450 $this->mLocalName = SpecialPageFactory::getLocalNameFor( $this->mName );
451 }
452 return $this->mLocalName;
453 }
454
455 /**
456 * Is this page expensive (for some definition of expensive)?
457 * Expensive pages are disabled or cached in miser mode. Originally used
458 * (and still overridden) by QueryPage and subclasses, moved here so that
459 * Special:SpecialPages can safely call it for all special pages.
460 *
461 * @return Boolean
462 */
463 public function isExpensive() {
464 return false;
465 }
466
467 /**
468 * Can be overridden by subclasses with more complicated permissions
469 * schemes.
470 *
471 * @return Boolean: should the page be displayed with the restricted-access
472 * pages?
473 */
474 public function isRestricted() {
475 global $wgGroupPermissions;
476 // DWIM: If all anons can do something, then it is not restricted
477 return $this->mRestriction != '' && empty($wgGroupPermissions['*'][$this->mRestriction]);
478 }
479
480 /**
481 * Checks if the given user (identified by an object) can execute this
482 * special page (as defined by $mRestriction). Can be overridden by sub-
483 * classes with more complicated permissions schemes.
484 *
485 * @param $user User: the user to check
486 * @return Boolean: does the user have permission to view the page?
487 */
488 public function userCanExecute( User $user ) {
489 return $user->isAllowed( $this->mRestriction );
490 }
491
492 /**
493 * Output an error message telling the user what access level they have to have
494 */
495 function displayRestrictionError() {
496 throw new PermissionsError( $this->mRestriction );
497 }
498
499 /**
500 * Sets headers - this should be called from the execute() method of all derived classes!
501 */
502 function setHeaders() {
503 $out = $this->getOutput();
504 $out->setArticleRelated( false );
505 $out->setRobotPolicy( "noindex,nofollow" );
506 $out->setPageTitle( $this->getDescription() );
507 }
508
509 /**
510 * Default execute method
511 * Checks user permissions, calls the function given in mFunction
512 *
513 * This must be overridden by subclasses; it will be made abstract in a future version
514 */
515 function execute( $par ) {
516 $this->setHeaders();
517
518 if ( $this->userCanExecute( $this->getUser() ) ) {
519 $func = $this->mFunction;
520 // only load file if the function does not exist
521 if(!is_callable($func) and $this->mFile) {
522 require_once( $this->mFile );
523 }
524 $this->outputHeader();
525 call_user_func( $func, $par, $this );
526 } else {
527 $this->displayRestrictionError();
528 }
529 }
530
531 /**
532 * Outputs a summary message on top of special pages
533 * Per default the message key is the canonical name of the special page
534 * May be overriden, i.e. by extensions to stick with the naming conventions
535 * for message keys: 'extensionname-xxx'
536 *
537 * @param $summaryMessageKey String: message key of the summary
538 */
539 function outputHeader( $summaryMessageKey = '' ) {
540 global $wgContLang;
541
542 if( $summaryMessageKey == '' ) {
543 $msg = $wgContLang->lc( $this->getName() ) . '-summary';
544 } else {
545 $msg = $summaryMessageKey;
546 }
547 if ( !wfMessage( $msg )->isBlank() and ! $this->including() ) {
548 $this->getOutput()->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
549 }
550
551 }
552
553 /**
554 * Returns the name that goes in the \<h1\> in the special page itself, and
555 * also the name that will be listed in Special:Specialpages
556 *
557 * Derived classes can override this, but usually it is easier to keep the
558 * default behaviour. Messages can be added at run-time, see
559 * MessageCache.php.
560 *
561 * @return String
562 */
563 function getDescription() {
564 return wfMsg( strtolower( $this->mName ) );
565 }
566
567 /**
568 * Get a self-referential title object
569 *
570 * @return Title object
571 */
572 function getTitle( $subpage = false ) {
573 return self::getTitleFor( $this->mName, $subpage );
574 }
575
576 /**
577 * Sets the context this SpecialPage is executed in
578 *
579 * @param $context RequestContext
580 * @since 1.18
581 */
582 public function setContext( $context ) {
583 $this->mContext = $context;
584 }
585
586 /**
587 * Gets the context this SpecialPage is executed in
588 *
589 * @return RequestContext
590 * @since 1.18
591 */
592 public function getContext() {
593 if ( $this->mContext instanceof RequestContext ) {
594 return $this->mContext;
595 } else {
596 wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
597 return RequestContext::getMain();
598 }
599 }
600
601 /**
602 * Get the WebRequest being used for this instance
603 *
604 * @return WebRequest
605 * @since 1.18
606 */
607 public function getRequest() {
608 return $this->getContext()->getRequest();
609 }
610
611 /**
612 * Get the OutputPage being used for this instance
613 *
614 * @return OutputPage
615 * @since 1.18
616 */
617 public function getOutput() {
618 return $this->getContext()->getOutput();
619 }
620
621 /**
622 * Shortcut to get the skin being used for this instance
623 *
624 * @return User
625 * @since 1.18
626 */
627 public function getUser() {
628 return $this->getContext()->getUser();
629 }
630
631 /**
632 * Shortcut to get the skin being used for this instance
633 *
634 * @return Skin
635 * @since 1.18
636 */
637 public function getSkin() {
638 return $this->getContext()->getSkin();
639 }
640
641 /**
642 * Return the full title, including $par
643 *
644 * @return Title
645 * @since 1.18
646 */
647 public function getFullTitle() {
648 return $this->getContext()->getTitle();
649 }
650
651 /**
652 * Wrapper around wfMessage that sets the current context. Currently this
653 * is only the title.
654 *
655 * @see wfMessage
656 */
657 public function msg( /* $args */ ) {
658 return call_user_func_array( 'wfMessage', func_get_args() )->title( $this->getFullTitle() );
659 }
660 }
661
662 /**
663 * Shortcut to construct a special page which is unlisted by default
664 * @ingroup SpecialPage
665 */
666 class UnlistedSpecialPage extends SpecialPage
667 {
668 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
669 parent::__construct( $name, $restriction, false, $function, $file );
670 }
671
672 public function isListed(){
673 return false;
674 }
675 }
676
677 /**
678 * Shortcut to construct an includable special page
679 * @ingroup SpecialPage
680 */
681 class IncludableSpecialPage extends SpecialPage
682 {
683 function __construct( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
684 parent::__construct( $name, $restriction, $listed, $function, $file, true );
685 }
686
687 public function isIncludable(){
688 return true;
689 }
690 }
691
692 /**
693 * Shortcut to construct a special page alias.
694 * @ingroup SpecialPage
695 */
696 abstract class RedirectSpecialPage extends UnlistedSpecialPage {
697
698 // Query parameters that can be passed through redirects
699 protected $mAllowedRedirectParams = array();
700
701 // Query parameteres added by redirects
702 protected $mAddedRedirectParams = array();
703
704 public function execute( $par ){
705 $redirect = $this->getRedirect( $par );
706 $query = $this->getRedirectQuery();
707 if ( $redirect instanceof Title ) {
708 $url = $redirect->getFullUrl( $query );
709 $this->getContext()->output->redirect( $url );
710 wfProfileOut( __METHOD__ );
711 return $redirect;
712 } elseif ( $redirect === true ) {
713 global $wgScript;
714 $url = $wgScript . '?' . wfArrayToCGI( $query );
715 $this->getContext()->output->redirect( $url );
716 wfProfileOut( __METHOD__ );
717 return $redirect;
718 } else {
719 $class = __CLASS__;
720 throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
721 }
722 }
723
724 /**
725 * If the special page is a redirect, then get the Title object it redirects to.
726 * False otherwise.
727 *
728 * @return Title|false
729 */
730 abstract public function getRedirect( $par );
731
732 /**
733 * Return part of the request string for a special redirect page
734 * This allows passing, e.g. action=history to Special:Mypage, etc.
735 *
736 * @return String
737 */
738 public function getRedirectQuery() {
739 $params = array();
740
741 foreach( $this->mAllowedRedirectParams as $arg ) {
742 if( $this->getContext()->request->getVal( $arg, null ) !== null ){
743 $params[$arg] = $this->getContext()->request->getVal( $arg );
744 }
745 }
746
747 foreach( $this->mAddedRedirectParams as $arg => $val ) {
748 $params[$arg] = $val;
749 }
750
751 return count( $params )
752 ? $params
753 : false;
754 }
755 }
756
757 abstract class SpecialRedirectToSpecial extends RedirectSpecialPage {
758
759 var $redirName, $redirSubpage;
760
761 function __construct( $name, $redirName, $redirSubpage = false, $allowedRedirectParams = array(), $addedRedirectParams = array() ) {
762 parent::__construct( $name );
763 $this->redirName = $redirName;
764 $this->redirSubpage = $redirSubpage;
765 $this->mAllowedRedirectParams = $allowedRedirectParams;
766 $this->mAddedRedirectParams = $addedRedirectParams;
767 }
768
769 public function getRedirect( $subpage ) {
770 if ( $this->redirSubpage === false ) {
771 return SpecialPage::getTitleFor( $this->redirName, $subpage );
772 } else {
773 return SpecialPage::getTitleFor( $this->redirName, $this->redirSubpage );
774 }
775 }
776 }
777
778 /**
779 * ListAdmins --> ListUsers/admin
780 */
781 class SpecialListAdmins extends SpecialRedirectToSpecial {
782 function __construct(){
783 parent::__construct( 'ListAdmins', 'ListUsers', 'sysop' );
784 }
785 }
786
787 /**
788 * ListBots --> ListUsers/admin
789 */
790 class SpecialListBots extends SpecialRedirectToSpecial {
791 function __construct(){
792 parent::__construct( 'ListAdmins', 'ListUsers', 'bot' );
793 }
794 }
795
796 /**
797 * CreateAccount --> UserLogin/signup
798 * FIXME: this (and the rest of the login frontend) needs to die a horrible painful death
799 */
800 class SpecialCreateAccount extends SpecialRedirectToSpecial {
801 function __construct(){
802 parent::__construct( 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) );
803 }
804 }
805 /**
806 * SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
807 * are used to get user independant links pointing to the user page, talk
808 * page and list of contributions.
809 * This can let us cache a single copy of any generated content for all
810 * users.
811 */
812
813 /**
814 * Shortcut to construct a special page pointing to current user user's page.
815 * @ingroup SpecialPage
816 */
817 class SpecialMypage extends RedirectSpecialPage {
818 function __construct() {
819 parent::__construct( 'Mypage' );
820 $this->mAllowedRedirectParams = array( 'action' , 'preload' , 'editintro',
821 'section', 'oldid', 'diff', 'dir' );
822 }
823
824 function getRedirect( $subpage ) {
825 global $wgUser;
826 if ( strval( $subpage ) !== '' ) {
827 return Title::makeTitle( NS_USER, $wgUser->getName() . '/' . $subpage );
828 } else {
829 return Title::makeTitle( NS_USER, $wgUser->getName() );
830 }
831 }
832 }
833
834 /**
835 * Shortcut to construct a special page pointing to current user talk page.
836 * @ingroup SpecialPage
837 */
838 class SpecialMytalk extends RedirectSpecialPage {
839 function __construct() {
840 parent::__construct( 'Mytalk' );
841 $this->mAllowedRedirectParams = array( 'action' , 'preload' , 'editintro',
842 'section', 'oldid', 'diff', 'dir' );
843 }
844
845 function getRedirect( $subpage ) {
846 global $wgUser;
847 if ( strval( $subpage ) !== '' ) {
848 return Title::makeTitle( NS_USER_TALK, $wgUser->getName() . '/' . $subpage );
849 } else {
850 return Title::makeTitle( NS_USER_TALK, $wgUser->getName() );
851 }
852 }
853 }
854
855 /**
856 * Shortcut to construct a special page pointing to current user contributions.
857 * @ingroup SpecialPage
858 */
859 class SpecialMycontributions extends RedirectSpecialPage {
860 function __construct() {
861 parent::__construct( 'Mycontributions' );
862 $this->mAllowedRedirectParams = array( 'limit', 'namespace', 'tagfilter',
863 'offset', 'dir', 'year', 'month', 'feed' );
864 }
865
866 function getRedirect( $subpage ) {
867 global $wgUser;
868 return SpecialPage::getTitleFor( 'Contributions', $wgUser->getName() );
869 }
870 }
871
872 /**
873 * Redirect to Special:Listfiles?user=$wgUser
874 */
875 class SpecialMyuploads extends RedirectSpecialPage {
876 function __construct() {
877 parent::__construct( 'Myuploads' );
878 $this->mAllowedRedirectParams = array( 'limit' );
879 }
880
881 function getRedirect( $subpage ) {
882 global $wgUser;
883 return SpecialPage::getTitleFor( 'Listfiles', $wgUser->getName() );
884 }
885 }
886
887 /**
888 * Redirect from Special:PermanentLink/### to index.php?oldid=###
889 */
890 class SpecialPermanentLink extends RedirectSpecialPage {
891 function __construct() {
892 parent::__construct( 'PermanentLink' );
893 $this->mAllowedRedirectParams = array();
894 }
895
896 function getRedirect( $subpage ) {
897 $subpage = intval( $subpage );
898 $this->mAddedRedirectParams['oldid'] = $subpage;
899 return true;
900 }
901 }