3 * SpecialPage: handling special pages and lists thereof.
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.
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.
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.
21 * @ingroup SpecialPage
22 * @defgroup SpecialPage SpecialPage
26 * Parent special page class, also static functions for handling the special
28 * @ingroup SpecialPage
32 // The canonical name of this special page
33 // Also used for the default <h1> heading, @see getDescription()
36 // The local name of this special page
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;
43 // Listed in Special:Specialpages?
46 // Function name called by the default execute()
49 // File which needs to be included before the function above can be called
52 // Whether or not this special page is being included from an article
53 protected $mIncluding;
55 // Whether the special page can be included in an article
56 protected $mIncludable;
59 * Current request context
65 * Initialise the special page list
66 * This must be called before accessing SpecialPage::$mList
67 * @deprecated since 1.18
69 static function initList() {
70 wfDeprecated( __METHOD__
, '1.18' );
75 * @deprecated since 1.18
77 static function initAliasList() {
78 wfDeprecated( __METHOD__
, '1.18' );
83 * Given a special page alias, return the special page name.
84 * Returns false if there is no such alias.
86 * @param $alias String
87 * @return String or false
88 * @deprecated since 1.18 call SpecialPageFactory method directly
90 static function resolveAlias( $alias ) {
91 wfDeprecated( __METHOD__
, '1.18' );
92 list( $name, /*...*/ ) = SpecialPageFactory
::resolveAlias( $alias );
97 * Given a special page name with a possible subpage, return an array
98 * where the first element is the special page name and the second is the
101 * @param $alias String
103 * @deprecated since 1.18 call SpecialPageFactory method directly
105 static function resolveAliasWithSubpage( $alias ) {
106 return SpecialPageFactory
::resolveAlias( $alias );
110 * Add a page to the list of valid special pages. This used to be the preferred
111 * method for adding special pages in extensions. It's now suggested that you add
112 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
114 * @param $page SpecialPage
115 * @deprecated since 1.7, warnings in 1.17, might be removed in 1.20
117 static function addPage( &$page ) {
118 wfDeprecated( __METHOD__
, '1.7' );
119 SpecialPageFactory
::getList()->{$page->mName
} = $page;
123 * Add a page to a certain display group for Special:SpecialPages
125 * @param $page Mixed: SpecialPage or string
126 * @param $group String
128 * @deprecated since 1.18 call SpecialPageFactory method directly
130 static function setGroup( $page, $group ) {
131 wfDeprecated( __METHOD__
, '1.18' );
132 return SpecialPageFactory
::setGroup( $page, $group );
136 * Get the group that the special page belongs in on Special:SpecialPage
138 * @param $page SpecialPage
140 * @deprecated since 1.18 call SpecialPageFactory method directly
142 static function getGroup( &$page ) {
143 wfDeprecated( __METHOD__
, '1.18' );
144 return SpecialPageFactory
::getGroup( $page );
148 * Remove a special page from the list
149 * Formerly used to disable expensive or dangerous special pages. The
150 * preferred method is now to add a SpecialPage_initList hook.
151 * @deprecated since 1.18
153 * @param $name String the page to remove
155 static function removePage( $name ) {
156 wfDeprecated( __METHOD__
, '1.18' );
157 unset( SpecialPageFactory
::getList()->$name );
161 * Check if a given name exist as a special page or as a special page alias
163 * @param $name String: name of a special page
164 * @return Boolean: true if a special page exists with this name
165 * @deprecated since 1.18 call SpecialPageFactory method directly
167 static function exists( $name ) {
168 wfDeprecated( __METHOD__
, '1.18' );
169 return SpecialPageFactory
::exists( $name );
173 * Find the object with a given name and return it (or NULL)
175 * @param $name String
176 * @return SpecialPage object or null if the page doesn't exist
177 * @deprecated since 1.18 call SpecialPageFactory method directly
179 static function getPage( $name ) {
180 wfDeprecated( __METHOD__
, '1.18' );
181 return SpecialPageFactory
::getPage( $name );
185 * Get a special page with a given localised name, or NULL if there
186 * is no such special page.
188 * @param $alias String
189 * @return SpecialPage object or null if the page doesn't exist
190 * @deprecated since 1.18 call SpecialPageFactory method directly
192 static function getPageByAlias( $alias ) {
193 wfDeprecated( __METHOD__
, '1.18' );
194 return SpecialPageFactory
::getPage( $alias );
198 * Return categorised listable special pages which are available
199 * for the current user, and everyone.
201 * @param $user User object to check permissions, $wgUser will be used
203 * @return Associative array mapping page's name to its SpecialPage object
204 * @deprecated since 1.18 call SpecialPageFactory method directly
206 static function getUsablePages( User
$user = null ) {
207 wfDeprecated( __METHOD__
, '1.18' );
208 return SpecialPageFactory
::getUsablePages( $user );
212 * Return categorised listable special pages for all users
214 * @return Associative array mapping page's name to its SpecialPage object
215 * @deprecated since 1.18 call SpecialPageFactory method directly
217 static function getRegularPages() {
218 wfDeprecated( __METHOD__
, '1.18' );
219 return SpecialPageFactory
::getRegularPages();
223 * Return categorised listable special pages which are available
224 * for the current user, but not for everyone
226 * @return Associative array mapping page's name to its SpecialPage object
227 * @deprecated since 1.18 call SpecialPageFactory method directly
229 static function getRestrictedPages() {
230 wfDeprecated( __METHOD__
, '1.18' );
231 return SpecialPageFactory
::getRestrictedPages();
235 * Execute a special page path.
236 * The path may contain parameters, e.g. Special:Name/Params
237 * Extracts the special page name and call the execute method, passing the parameters
239 * Returns a title object if the page is redirected, false if there was no such special
240 * page, and true if it was successful.
242 * @param $title Title object
243 * @param $context IContextSource
244 * @param $including Bool output is being captured for use in {{special:whatever}}
246 * @deprecated since 1.18 call SpecialPageFactory method directly
248 public static function executePath( &$title, IContextSource
&$context, $including = false ) {
249 wfDeprecated( __METHOD__
, '1.18' );
250 return SpecialPageFactory
::executePath( $title, $context, $including );
254 * Get the local name for a specified canonical name
256 * @param $name String
257 * @param $subpage Mixed: boolean false, or string
260 * @deprecated since 1.18 call SpecialPageFactory method directly
262 static function getLocalNameFor( $name, $subpage = false ) {
263 wfDeprecated( __METHOD__
, '1.18' );
264 return SpecialPageFactory
::getLocalNameFor( $name, $subpage );
268 * Get a localised Title object for a specified special page name
270 * @param $name String
271 * @param $subpage String|Bool subpage string, or false to not use a subpage
272 * @return Title object
274 public static function getTitleFor( $name, $subpage = false ) {
275 $name = SpecialPageFactory
::getLocalNameFor( $name, $subpage );
277 return Title
::makeTitle( NS_SPECIAL
, $name );
279 throw new MWException( "Invalid special page name \"$name\"" );
284 * Get a localised Title object for a page name with a possibly unvalidated subpage
286 * @param $name String
287 * @param $subpage String|Bool subpage string, or false to not use a subpage
288 * @return Title object or null if the page doesn't exist
290 public static function getSafeTitleFor( $name, $subpage = false ) {
291 $name = SpecialPageFactory
::getLocalNameFor( $name, $subpage );
293 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
300 * Get a title for a given alias
302 * @param $alias String
303 * @return Title or null if there is no such alias
304 * @deprecated since 1.18 call SpecialPageFactory method directly
306 static function getTitleForAlias( $alias ) {
307 wfDeprecated( __METHOD__
, '1.18' );
308 return SpecialPageFactory
::getTitleForAlias( $alias );
312 * Default constructor for special pages
313 * Derivative classes should call this from their constructor
314 * Note that if the user does not have the required level, an error message will
315 * be displayed by the default execute() method, without the global function ever
318 * If you override execute(), you can recover the default behaviour with userCanExecute()
319 * and displayRestrictionError()
321 * @param $name String: name of the special page, as seen in links and URLs
322 * @param $restriction String: user right required, e.g. "block" or "delete"
323 * @param $listed Bool: whether the page is listed in Special:Specialpages
324 * @param $function Callback|Bool: function called by execute(). By default it is constructed from $name
325 * @param $file String: file which is included by execute(). It is also constructed from $name by default
326 * @param $includable Bool: whether the page can be included in normal pages
328 public function __construct(
329 $name = '', $restriction = '', $listed = true,
330 $function = false, $file = 'default', $includable = false
332 $this->init( $name, $restriction, $listed, $function, $file, $includable );
336 * Do the real work for the constructor, mainly so __call() can intercept
337 * calls to SpecialPage()
338 * @param $name String: name of the special page, as seen in links and URLs
339 * @param $restriction String: user right required, e.g. "block" or "delete"
340 * @param $listed Bool: whether the page is listed in Special:Specialpages
341 * @param $function Callback|Bool: function called by execute(). By default it is constructed from $name
342 * @param $file String: file which is included by execute(). It is also constructed from $name by default
343 * @param $includable Bool: whether the page can be included in normal pages
345 private function init( $name, $restriction, $listed, $function, $file, $includable ) {
346 $this->mName
= $name;
347 $this->mRestriction
= $restriction;
348 $this->mListed
= $listed;
349 $this->mIncludable
= $includable;
351 $this->mFunction
= 'wfSpecial'.$name;
353 $this->mFunction
= $function;
355 if ( $file === 'default' ) {
356 $this->mFile
= dirname(__FILE__
) . "/specials/Special$name.php";
358 $this->mFile
= $file;
363 * Use PHP's magic __call handler to get calls to the old PHP4 constructor
364 * because PHP E_STRICT yells at you for having __construct() and SpecialPage()
366 * @param $fName String Name of called method
367 * @param $a Array Arguments to the method
368 * @deprecated since 1.17, call parent::__construct()
370 public function __call( $fName, $a ) {
371 // Deprecated messages now, remove in 1.19 or 1.20?
372 wfDeprecated( __METHOD__
, '1.17' );
374 // Sometimes $fName is SpecialPage, sometimes it's specialpage. <3 PHP
375 if( strtolower( $fName ) == 'specialpage' ) {
376 $name = isset( $a[0] ) ?
$a[0] : '';
377 $restriction = isset( $a[1] ) ?
$a[1] : '';
378 $listed = isset( $a[2] ) ?
$a[2] : true;
379 $function = isset( $a[3] ) ?
$a[3] : false;
380 $file = isset( $a[4] ) ?
$a[4] : 'default';
381 $includable = isset( $a[5] ) ?
$a[5] : false;
382 $this->init( $name, $restriction, $listed, $function, $file, $includable );
384 $className = get_class( $this );
385 throw new MWException( "Call to undefined method $className::$fName" );
390 * Get the name of this Special Page.
398 * Get the permission that a user must have to execute this page
401 function getRestriction() {
402 return $this->mRestriction
;
406 * Get the file which will be included by SpecialPage::execute() if your extension is
407 * still stuck in the past and hasn't overridden the execute() method. No modern code
408 * should want or need to know this.
410 * @deprecated since 1.18
413 wfDeprecated( __METHOD__
, '1.18' );
417 // @todo FIXME: Decide which syntax to use for this, and stick to it
419 * Whether this special page is listed in Special:SpecialPages
420 * @since r3583 (v1.3)
423 function isListed() {
424 return $this->mListed
;
427 * Set whether this page is listed in Special:Specialpages, at run-time
428 * @since r3583 (v1.3)
429 * @param $listed Bool
432 function setListed( $listed ) {
433 return wfSetVar( $this->mListed
, $listed );
436 * Get or set whether this special page is listed in Special:SpecialPages
437 * @since r11308 (v1.6)
441 function listed( $x = null) {
442 return wfSetVar( $this->mListed
, $x );
446 * Whether it's allowed to transclude the special page via {{Special:Foo/params}}
449 public function isIncludable(){
450 return $this->mIncludable
;
454 * These mutators are very evil, as the relevant variables should not mutate. So
458 * @deprecated since 1.18
460 function name( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mName
, $x ); }
461 function restriction( $x = null) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mRestriction
, $x ); }
462 function func( $x = null) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mFunction
, $x ); }
463 function file( $x = null) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mFile
, $x ); }
464 function includable( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mIncludable
, $x ); }
467 * Whether the special page is being evaluated via transclusion
471 function including( $x = null ) {
472 return wfSetVar( $this->mIncluding
, $x );
476 * Get the localised name of the special page
478 function getLocalName() {
479 if ( !isset( $this->mLocalName
) ) {
480 $this->mLocalName
= SpecialPageFactory
::getLocalNameFor( $this->mName
);
482 return $this->mLocalName
;
486 * Is this page expensive (for some definition of expensive)?
487 * Expensive pages are disabled or cached in miser mode. Originally used
488 * (and still overridden) by QueryPage and subclasses, moved here so that
489 * Special:SpecialPages can safely call it for all special pages.
493 public function isExpensive() {
498 * Can be overridden by subclasses with more complicated permissions
501 * @return Boolean: should the page be displayed with the restricted-access
504 public function isRestricted() {
505 global $wgGroupPermissions;
506 // DWIM: If all anons can do something, then it is not restricted
507 return $this->mRestriction
!= '' && empty($wgGroupPermissions['*'][$this->mRestriction
]);
511 * Checks if the given user (identified by an object) can execute this
512 * special page (as defined by $mRestriction). Can be overridden by sub-
513 * classes with more complicated permissions schemes.
515 * @param $user User: the user to check
516 * @return Boolean: does the user have permission to view the page?
518 public function userCanExecute( User
$user ) {
519 return $user->isAllowed( $this->mRestriction
);
523 * Output an error message telling the user what access level they have to have
525 function displayRestrictionError() {
526 throw new PermissionsError( $this->mRestriction
);
530 * Checks if userCanExecute, and if not throws a PermissionsError
534 public function checkPermissions() {
535 if ( !$this->userCanExecute( $this->getUser() ) ) {
536 $this->displayRestrictionError();
541 * If the wiki is currently in readonly mode, throws a ReadOnlyError
544 * @throws ReadOnlyError
546 public function checkReadOnly() {
547 if ( wfReadOnly() ) {
548 throw new ReadOnlyError
;
553 * Sets headers - this should be called from the execute() method of all derived classes!
555 function setHeaders() {
556 $out = $this->getOutput();
557 $out->setArticleRelated( false );
558 $out->setRobotPolicy( "noindex,nofollow" );
559 $out->setPageTitle( $this->getDescription() );
563 * Default execute method
564 * Checks user permissions, calls the function given in mFunction
566 * This must be overridden by subclasses; it will be made abstract in a future version
568 * @param $par String subpage string, if one was specified
570 function execute( $par ) {
572 $this->checkPermissions();
574 $func = $this->mFunction
;
575 // only load file if the function does not exist
576 if( !is_callable($func) && $this->mFile
) {
577 require_once( $this->mFile
);
579 $this->outputHeader();
580 call_user_func( $func, $par, $this );
584 * Outputs a summary message on top of special pages
585 * Per default the message key is the canonical name of the special page
586 * May be overriden, i.e. by extensions to stick with the naming conventions
587 * for message keys: 'extensionname-xxx'
589 * @param $summaryMessageKey String: message key of the summary
591 function outputHeader( $summaryMessageKey = '' ) {
594 if( $summaryMessageKey == '' ) {
595 $msg = $wgContLang->lc( $this->getName() ) . '-summary';
597 $msg = $summaryMessageKey;
599 if ( !$this->msg( $msg )->isBlank() && !$this->including() ) {
600 $this->getOutput()->wrapWikiMsg(
601 "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
607 * Returns the name that goes in the \<h1\> in the special page itself, and
608 * also the name that will be listed in Special:Specialpages
610 * Derived classes can override this, but usually it is easier to keep the
611 * default behaviour. Messages can be added at run-time, see
616 function getDescription() {
617 return $this->msg( strtolower( $this->mName
) )->text();
621 * Get a self-referential title object
623 * @param $subpage String|Bool
624 * @return Title object
626 function getTitle( $subpage = false ) {
627 return self
::getTitleFor( $this->mName
, $subpage );
631 * Sets the context this SpecialPage is executed in
633 * @param $context IContextSource
636 public function setContext( $context ) {
637 $this->mContext
= $context;
641 * Gets the context this SpecialPage is executed in
643 * @return IContextSource
646 public function getContext() {
647 if ( $this->mContext
instanceof IContextSource
) {
648 return $this->mContext
;
650 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
651 return RequestContext
::getMain();
656 * Get the WebRequest being used for this instance
661 public function getRequest() {
662 return $this->getContext()->getRequest();
666 * Get the OutputPage being used for this instance
671 public function getOutput() {
672 return $this->getContext()->getOutput();
676 * Shortcut to get the User executing this instance
681 public function getUser() {
682 return $this->getContext()->getUser();
686 * Shortcut to get the skin being used for this instance
691 public function getSkin() {
692 return $this->getContext()->getSkin();
696 * Shortcut to get user's language
698 * @deprecated 1.19 Use getLanguage instead
702 public function getLang() {
703 wfDeprecated( __METHOD__
, '1.19' );
704 return $this->getLanguage();
708 * Shortcut to get user's language
713 public function getLanguage() {
714 return $this->getContext()->getLanguage();
718 * Return the full title, including $par
723 public function getFullTitle() {
724 return $this->getContext()->getTitle();
728 * Wrapper around wfMessage that sets the current context.
733 public function msg( /* $args */ ) {
734 // Note: can't use func_get_args() directly as second or later item in
735 // a parameter list until PHP 5.3 or you get a fatal error.
736 // Works fine as the first parameter, which appears elsewhere in the
737 // code base. Sighhhh.
738 $args = func_get_args();
739 return call_user_func_array( array( $this->getContext(), 'msg' ), $args );
743 * Adds RSS/atom links
745 * @param $params array
747 protected function addFeedLinks( $params ) {
748 global $wgFeedClasses;
750 $feedTemplate = wfScript( 'api' ) . '?';
752 foreach( $wgFeedClasses as $format => $class ) {
753 $theseParams = $params +
array( 'feedformat' => $format );
754 $url = $feedTemplate . wfArrayToCGI( $theseParams );
755 $this->getOutput()->addFeedLink( $format, $url );
761 * Special page which uses an HTMLForm to handle processing. This is mostly a
762 * clone of FormAction. More special pages should be built this way; maybe this could be
763 * a new structure for SpecialPages
765 abstract class FormSpecialPage
extends SpecialPage
{
768 * Get an HTMLForm descriptor array
771 protected abstract function getFormFields();
774 * Add pre- or post-text to the form
775 * @return String HTML which will be sent to $form->addPreText()
777 protected function preText() { return ''; }
778 protected function postText() { return ''; }
781 * Play with the HTMLForm if you need to more substantially
782 * @param $form HTMLForm
784 protected function alterForm( HTMLForm
$form ) {}
787 * Get the HTMLForm to control behaviour
788 * @return HTMLForm|null
790 protected function getForm() {
791 $this->fields
= $this->getFormFields();
793 $form = new HTMLForm( $this->fields
, $this->getContext() );
794 $form->setSubmitCallback( array( $this, 'onSubmit' ) );
795 $form->setWrapperLegend( $this->msg( strtolower( $this->getName() ) . '-legend' ) );
796 $form->addHeaderText(
797 $this->msg( strtolower( $this->getName() ) . '-text' )->parseAsBlock() );
799 // Retain query parameters (uselang etc)
800 $params = array_diff_key(
801 $this->getRequest()->getQueryValues(), array( 'title' => null ) );
802 $form->addHiddenField( 'redirectparams', wfArrayToCGI( $params ) );
804 $form->addPreText( $this->preText() );
805 $form->addPostText( $this->postText() );
806 $this->alterForm( $form );
808 // Give hooks a chance to alter the form, adding extra fields or text etc
809 wfRunHooks( "Special{$this->getName()}BeforeFormDisplay", array( &$form ) );
815 * Process the form on POST submission.
817 * @return Bool|Array true for success, false for didn't-try, array of errors on failure
819 public abstract function onSubmit( array $data );
822 * Do something exciting on successful processing of the form, most likely to show a
823 * confirmation message
825 public abstract function onSuccess();
828 * Basic SpecialPage workflow: get a form, send it to the user; get some data back,
830 * @param $par String Subpage string if one was specified
832 public function execute( $par ) {
833 $this->setParameter( $par );
836 // This will throw exceptions if there's a problem
837 $this->checkExecutePermissions( $this->getUser() );
839 $form = $this->getForm();
840 if ( $form->show() ) {
846 * Maybe do something interesting with the subpage parameter
849 protected function setParameter( $par ){}
852 * Called from execute() to check if the given user can perform this action.
853 * Failures here must throw subclasses of ErrorPageError.
856 * @throws ErrorPageError
858 protected function checkExecutePermissions( User
$user ) {
859 $this->checkPermissions();
861 if ( $this->requiresUnblock() && $user->isBlocked() ) {
862 $block = $user->mBlock
;
863 throw new UserBlockedError( $block );
866 if ( $this->requiresWrite() ) {
867 $this->checkReadOnly();
874 * Whether this action requires the wiki not to be locked
877 public function requiresWrite() {
882 * Whether this action cannot be executed by a blocked user
885 public function requiresUnblock() {
891 * Shortcut to construct a special page which is unlisted by default
892 * @ingroup SpecialPage
894 class UnlistedSpecialPage
extends SpecialPage
{
895 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
896 parent
::__construct( $name, $restriction, false, $function, $file );
899 public function isListed(){
905 * Shortcut to construct an includable special page
906 * @ingroup SpecialPage
908 class IncludableSpecialPage
extends SpecialPage
{
909 function __construct(
910 $name, $restriction = '', $listed = true, $function = false, $file = 'default'
912 parent
::__construct( $name, $restriction, $listed, $function, $file, true );
915 public function isIncludable(){
921 * Shortcut to construct a special page alias.
922 * @ingroup SpecialPage
924 abstract class RedirectSpecialPage
extends UnlistedSpecialPage
{
926 // Query parameters that can be passed through redirects
927 protected $mAllowedRedirectParams = array();
929 // Query parameteres added by redirects
930 protected $mAddedRedirectParams = array();
932 public function execute( $par ){
933 $redirect = $this->getRedirect( $par );
934 $query = $this->getRedirectQuery();
935 // Redirect to a page title with possible query parameters
936 if ( $redirect instanceof Title
) {
937 $url = $redirect->getFullUrl( $query );
938 $this->getOutput()->redirect( $url );
939 wfProfileOut( __METHOD__
);
941 // Redirect to index.php with query parameters
942 } elseif ( $redirect === true ) {
944 $url = $wgScript . '?' . wfArrayToCGI( $query );
945 $this->getOutput()->redirect( $url );
946 wfProfileOut( __METHOD__
);
950 throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
955 * If the special page is a redirect, then get the Title object it redirects to.
958 * @param $par String Subpage string
959 * @return Title|false
961 abstract public function getRedirect( $par );
964 * Return part of the request string for a special redirect page
965 * This allows passing, e.g. action=history to Special:Mypage, etc.
969 public function getRedirectQuery() {
972 foreach( $this->mAllowedRedirectParams
as $arg ) {
973 if( $this->getRequest()->getVal( $arg, null ) !== null ){
974 $params[$arg] = $this->getRequest()->getVal( $arg );
978 foreach( $this->mAddedRedirectParams
as $arg => $val ) {
979 $params[$arg] = $val;
982 return count( $params )
988 abstract class SpecialRedirectToSpecial
extends RedirectSpecialPage
{
989 var $redirName, $redirSubpage;
991 function __construct(
992 $name, $redirName, $redirSubpage = false,
993 $allowedRedirectParams = array(), $addedRedirectParams = array()
995 parent
::__construct( $name );
996 $this->redirName
= $redirName;
997 $this->redirSubpage
= $redirSubpage;
998 $this->mAllowedRedirectParams
= $allowedRedirectParams;
999 $this->mAddedRedirectParams
= $addedRedirectParams;
1002 public function getRedirect( $subpage ) {
1003 if ( $this->redirSubpage
=== false ) {
1004 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
1006 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
1012 * ListAdmins --> ListUsers/sysop
1014 class SpecialListAdmins
extends SpecialRedirectToSpecial
{
1015 function __construct(){
1016 parent
::__construct( 'Listadmins', 'Listusers', 'sysop' );
1021 * ListBots --> ListUsers/bot
1023 class SpecialListBots
extends SpecialRedirectToSpecial
{
1024 function __construct(){
1025 parent
::__construct( 'Listbots', 'Listusers', 'bot' );
1030 * CreateAccount --> UserLogin/signup
1031 * @todo FIXME: This (and the rest of the login frontend) needs to die a horrible painful death
1033 class SpecialCreateAccount
extends SpecialRedirectToSpecial
{
1034 function __construct(){
1035 parent
::__construct( 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) );
1039 * SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
1040 * are used to get user independant links pointing to the user page, talk
1041 * page and list of contributions.
1042 * This can let us cache a single copy of any generated content for all
1047 * Shortcut to construct a special page pointing to current user user's page.
1048 * @ingroup SpecialPage
1050 class SpecialMypage
extends RedirectSpecialPage
{
1051 function __construct() {
1052 parent
::__construct( 'Mypage' );
1053 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro',
1054 'section', 'oldid', 'diff', 'dir',
1055 // Options for action=raw; missing ctype can break JS or CSS in some browsers
1056 'ctype', 'maxage', 'smaxage' );
1059 function getRedirect( $subpage ) {
1060 if ( strval( $subpage ) !== '' ) {
1061 return Title
::makeTitle( NS_USER
, $this->getUser()->getName() . '/' . $subpage );
1063 return Title
::makeTitle( NS_USER
, $this->getUser()->getName() );
1069 * Shortcut to construct a special page pointing to current user talk page.
1070 * @ingroup SpecialPage
1072 class SpecialMytalk
extends RedirectSpecialPage
{
1073 function __construct() {
1074 parent
::__construct( 'Mytalk' );
1075 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro',
1076 'section', 'oldid', 'diff', 'dir' );
1079 function getRedirect( $subpage ) {
1080 if ( strval( $subpage ) !== '' ) {
1081 return Title
::makeTitle( NS_USER_TALK
, $this->getUser()->getName() . '/' . $subpage );
1083 return Title
::makeTitle( NS_USER_TALK
, $this->getUser()->getName() );
1089 * Shortcut to construct a special page pointing to current user contributions.
1090 * @ingroup SpecialPage
1092 class SpecialMycontributions
extends RedirectSpecialPage
{
1093 function __construct() {
1094 parent
::__construct( 'Mycontributions' );
1095 $this->mAllowedRedirectParams
= array( 'limit', 'namespace', 'tagfilter',
1096 'offset', 'dir', 'year', 'month', 'feed' );
1099 function getRedirect( $subpage ) {
1100 return SpecialPage
::getTitleFor( 'Contributions', $this->getUser()->getName() );
1105 * Redirect to Special:Listfiles?user=$wgUser
1107 class SpecialMyuploads
extends RedirectSpecialPage
{
1108 function __construct() {
1109 parent
::__construct( 'Myuploads' );
1110 $this->mAllowedRedirectParams
= array( 'limit' );
1113 function getRedirect( $subpage ) {
1114 return SpecialPage
::getTitleFor( 'Listfiles', $this->getUser()->getName() );
1119 * Redirect from Special:PermanentLink/### to index.php?oldid=###
1121 class SpecialPermanentLink
extends RedirectSpecialPage
{
1122 function __construct() {
1123 parent
::__construct( 'PermanentLink' );
1124 $this->mAllowedRedirectParams
= array();
1127 function getRedirect( $subpage ) {
1128 $subpage = intval( $subpage );
1129 if( $subpage === 0 ) {
1130 # throw an error page when no subpage was given
1131 throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
1133 $this->mAddedRedirectParams
['oldid'] = $subpage;