3 * Parent class for all special pages.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * Parent special page class, also static functions for handling the special
27 * @ingroup SpecialPage
31 // The canonical name of this special page
32 // Also used for the default <h1> heading, @see getDescription()
35 // The local name of this special page
38 // Minimum user level required to access this page, or "" for anyone.
39 // Also used to categorise the pages in Special:Specialpages
40 private $mRestriction;
42 // Listed in Special:Specialpages?
45 // Function name called by the default execute()
48 // File which needs to be included before the function above can be called
51 // Whether or not this special page is being included from an article
52 protected $mIncluding;
54 // Whether the special page can be included in an article
55 protected $mIncludable;
58 * Current request context
64 * Initialise the special page list
65 * This must be called before accessing SpecialPage::$mList
66 * @deprecated since 1.18
68 static function initList() {
69 wfDeprecated( __METHOD__
, '1.18' );
74 * @deprecated since 1.18
76 static function initAliasList() {
77 wfDeprecated( __METHOD__
, '1.18' );
82 * Given a special page alias, return the special page name.
83 * Returns false if there is no such alias.
85 * @param $alias String
86 * @return String or false
87 * @deprecated since 1.18 call SpecialPageFactory method directly
89 static function resolveAlias( $alias ) {
90 wfDeprecated( __METHOD__
, '1.18' );
91 list( $name, /*...*/ ) = SpecialPageFactory
::resolveAlias( $alias );
96 * Given a special page name with a possible subpage, return an array
97 * where the first element is the special page name and the second is the
100 * @param $alias String
102 * @deprecated since 1.18 call SpecialPageFactory method directly
104 static function resolveAliasWithSubpage( $alias ) {
105 return SpecialPageFactory
::resolveAlias( $alias );
109 * Add a page to the list of valid special pages. This used to be the preferred
110 * method for adding special pages in extensions. It's now suggested that you add
111 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
113 * @param $page SpecialPage
114 * @deprecated since 1.7, warnings in 1.17, might be removed in 1.20
116 static function addPage( &$page ) {
117 wfDeprecated( __METHOD__
, '1.7' );
118 SpecialPageFactory
::getList()->{$page->mName
} = $page;
122 * Add a page to a certain display group for Special:SpecialPages
124 * @param $page Mixed: SpecialPage or string
125 * @param $group String
126 * @deprecated since 1.18 call SpecialPageFactory method directly
128 static function setGroup( $page, $group ) {
129 wfDeprecated( __METHOD__
, '1.18' );
130 SpecialPageFactory
::setGroup( $page, $group );
134 * Get the group that the special page belongs in on Special:SpecialPage
136 * @param $page SpecialPage
138 * @deprecated since 1.18 call SpecialPageFactory method directly
140 static function getGroup( &$page ) {
141 wfDeprecated( __METHOD__
, '1.18' );
142 return SpecialPageFactory
::getGroup( $page );
146 * Remove a special page from the list
147 * Formerly used to disable expensive or dangerous special pages. The
148 * preferred method is now to add a SpecialPage_initList hook.
149 * @deprecated since 1.18
151 * @param $name String the page to remove
153 static function removePage( $name ) {
154 wfDeprecated( __METHOD__
, '1.18' );
155 unset( SpecialPageFactory
::getList()->$name );
159 * Check if a given name exist as a special page or as a special page alias
161 * @param $name String: name of a special page
162 * @return Boolean: true if a special page exists with this name
163 * @deprecated since 1.18 call SpecialPageFactory method directly
165 static function exists( $name ) {
166 wfDeprecated( __METHOD__
, '1.18' );
167 return SpecialPageFactory
::exists( $name );
171 * Find the object with a given name and return it (or NULL)
173 * @param $name String
174 * @return SpecialPage object or null if the page doesn't exist
175 * @deprecated since 1.18 call SpecialPageFactory method directly
177 static function getPage( $name ) {
178 wfDeprecated( __METHOD__
, '1.18' );
179 return SpecialPageFactory
::getPage( $name );
183 * Get a special page with a given localised name, or NULL if there
184 * is no such special page.
186 * @param $alias String
187 * @return SpecialPage object or null if the page doesn't exist
188 * @deprecated since 1.18 call SpecialPageFactory method directly
190 static function getPageByAlias( $alias ) {
191 wfDeprecated( __METHOD__
, '1.18' );
192 return SpecialPageFactory
::getPage( $alias );
196 * Return categorised listable special pages which are available
197 * for the current user, and everyone.
199 * @param $user User object to check permissions, $wgUser will be used
201 * @return array Associative array mapping page's name to its SpecialPage object
202 * @deprecated since 1.18 call SpecialPageFactory method directly
204 static function getUsablePages( User
$user = null ) {
205 wfDeprecated( __METHOD__
, '1.18' );
206 return SpecialPageFactory
::getUsablePages( $user );
210 * Return categorised listable special pages for all users
212 * @return array Associative array mapping page's name to its SpecialPage object
213 * @deprecated since 1.18 call SpecialPageFactory method directly
215 static function getRegularPages() {
216 wfDeprecated( __METHOD__
, '1.18' );
217 return SpecialPageFactory
::getRegularPages();
221 * Return categorised listable special pages which are available
222 * for the current user, but not for everyone
224 * @return array Associative array mapping page's name to its SpecialPage object
225 * @deprecated since 1.18 call SpecialPageFactory method directly
227 static function getRestrictedPages() {
228 wfDeprecated( __METHOD__
, '1.18' );
229 return SpecialPageFactory
::getRestrictedPages();
233 * Execute a special page path.
234 * The path may contain parameters, e.g. Special:Name/Params
235 * Extracts the special page name and call the execute method, passing the parameters
237 * Returns a title object if the page is redirected, false if there was no such special
238 * page, and true if it was successful.
240 * @param $title Title object
241 * @param $context IContextSource
242 * @param $including Bool output is being captured for use in {{special:whatever}}
244 * @deprecated since 1.18 call SpecialPageFactory method directly
246 public static function executePath( &$title, IContextSource
&$context, $including = false ) {
247 wfDeprecated( __METHOD__
, '1.18' );
248 return SpecialPageFactory
::executePath( $title, $context, $including );
252 * Get the local name for a specified canonical name
254 * @param $name String
255 * @param $subpage Mixed: boolean false, or string
258 * @deprecated since 1.18 call SpecialPageFactory method directly
260 static function getLocalNameFor( $name, $subpage = false ) {
261 wfDeprecated( __METHOD__
, '1.18' );
262 return SpecialPageFactory
::getLocalNameFor( $name, $subpage );
266 * Get a localised Title object for a specified special page name
268 * @param $name String
269 * @param $subpage String|Bool subpage string, or false to not use a subpage
270 * @return Title object
272 public static function getTitleFor( $name, $subpage = false ) {
273 $name = SpecialPageFactory
::getLocalNameFor( $name, $subpage );
275 return Title
::makeTitle( NS_SPECIAL
, $name );
277 throw new MWException( "Invalid special page name \"$name\"" );
282 * Get a localised Title object for a page name with a possibly unvalidated subpage
284 * @param $name String
285 * @param $subpage String|Bool subpage string, or false to not use a subpage
286 * @return Title object or null if the page doesn't exist
288 public static function getSafeTitleFor( $name, $subpage = false ) {
289 $name = SpecialPageFactory
::getLocalNameFor( $name, $subpage );
291 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
298 * Get a title for a given alias
300 * @param $alias String
301 * @return Title or null if there is no such alias
302 * @deprecated since 1.18 call SpecialPageFactory method directly
304 static function getTitleForAlias( $alias ) {
305 wfDeprecated( __METHOD__
, '1.18' );
306 return SpecialPageFactory
::getTitleForAlias( $alias );
310 * Default constructor for special pages
311 * Derivative classes should call this from their constructor
312 * Note that if the user does not have the required level, an error message will
313 * be displayed by the default execute() method, without the global function ever
316 * If you override execute(), you can recover the default behaviour with userCanExecute()
317 * and displayRestrictionError()
319 * @param $name String: name of the special page, as seen in links and URLs
320 * @param $restriction String: user right required, e.g. "block" or "delete"
321 * @param $listed Bool: whether the page is listed in Special:Specialpages
322 * @param $function Callback|Bool: function called by execute(). By default it is constructed from $name
323 * @param $file String: file which is included by execute(). It is also constructed from $name by default
324 * @param $includable Bool: whether the page can be included in normal pages
326 public function __construct(
327 $name = '', $restriction = '', $listed = true,
328 $function = false, $file = 'default', $includable = false
330 $this->init( $name, $restriction, $listed, $function, $file, $includable );
334 * Do the real work for the constructor, mainly so __call() can intercept
335 * calls to SpecialPage()
336 * @param $name String: name of the special page, as seen in links and URLs
337 * @param $restriction String: user right required, e.g. "block" or "delete"
338 * @param $listed Bool: whether the page is listed in Special:Specialpages
339 * @param $function Callback|Bool: function called by execute(). By default it is constructed from $name
340 * @param $file String: file which is included by execute(). It is also constructed from $name by default
341 * @param $includable Bool: whether the page can be included in normal pages
343 private function init( $name, $restriction, $listed, $function, $file, $includable ) {
344 $this->mName
= $name;
345 $this->mRestriction
= $restriction;
346 $this->mListed
= $listed;
347 $this->mIncludable
= $includable;
349 $this->mFunction
= 'wfSpecial' . $name;
351 $this->mFunction
= $function;
353 if ( $file === 'default' ) {
354 $this->mFile
= dirname( __FILE__
) . "/specials/Special$name.php";
356 $this->mFile
= $file;
361 * Use PHP's magic __call handler to get calls to the old PHP4 constructor
362 * because PHP E_STRICT yells at you for having __construct() and SpecialPage()
364 * @param $fName String Name of called method
365 * @param $a Array Arguments to the method
366 * @deprecated since 1.17, call parent::__construct()
368 public function __call( $fName, $a ) {
369 // Deprecated messages now, remove in 1.19 or 1.20?
370 wfDeprecated( __METHOD__
, '1.17' );
372 // Sometimes $fName is SpecialPage, sometimes it's specialpage. <3 PHP
373 if ( strtolower( $fName ) == 'specialpage' ) {
374 $name = isset( $a[0] ) ?
$a[0] : '';
375 $restriction = isset( $a[1] ) ?
$a[1] : '';
376 $listed = isset( $a[2] ) ?
$a[2] : true;
377 $function = isset( $a[3] ) ?
$a[3] : false;
378 $file = isset( $a[4] ) ?
$a[4] : 'default';
379 $includable = isset( $a[5] ) ?
$a[5] : false;
380 $this->init( $name, $restriction, $listed, $function, $file, $includable );
382 $className = get_class( $this );
383 throw new MWException( "Call to undefined method $className::$fName" );
388 * Get the name of this Special Page.
396 * Get the permission that a user must have to execute this page
399 function getRestriction() {
400 return $this->mRestriction
;
404 * Get the file which will be included by SpecialPage::execute() if your extension is
405 * still stuck in the past and hasn't overridden the execute() method. No modern code
406 * should want or need to know this.
408 * @deprecated since 1.18
411 wfDeprecated( __METHOD__
, '1.18' );
415 // @todo FIXME: Decide which syntax to use for this, and stick to it
417 * Whether this special page is listed in Special:SpecialPages
418 * @since r3583 (v1.3)
421 function isListed() {
422 return $this->mListed
;
425 * Set whether this page is listed in Special:Specialpages, at run-time
426 * @since r3583 (v1.3)
427 * @param $listed Bool
430 function setListed( $listed ) {
431 return wfSetVar( $this->mListed
, $listed );
434 * Get or set whether this special page is listed in Special:SpecialPages
435 * @since r11308 (v1.6)
439 function listed( $x = null ) {
440 return wfSetVar( $this->mListed
, $x );
444 * Whether it's allowed to transclude the special page via {{Special:Foo/params}}
447 public function isIncludable() {
448 return $this->mIncludable
;
452 * These mutators are very evil, as the relevant variables should not mutate. So
456 * @deprecated since 1.18
458 function name( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mName
, $x ); }
461 * These mutators are very evil, as the relevant variables should not mutate. So
465 * @deprecated since 1.18
467 function restriction( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mRestriction
, $x ); }
470 * These mutators are very evil, as the relevant variables should not mutate. So
474 * @deprecated since 1.18
476 function func( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mFunction
, $x ); }
479 * These mutators are very evil, as the relevant variables should not mutate. So
483 * @deprecated since 1.18
485 function file( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mFile
, $x ); }
488 * These mutators are very evil, as the relevant variables should not mutate. So
492 * @deprecated since 1.18
494 function includable( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mIncludable
, $x ); }
497 * Whether the special page is being evaluated via transclusion
501 function including( $x = null ) {
502 return wfSetVar( $this->mIncluding
, $x );
506 * Get the localised name of the special page
508 function getLocalName() {
509 if ( !isset( $this->mLocalName
) ) {
510 $this->mLocalName
= SpecialPageFactory
::getLocalNameFor( $this->mName
);
512 return $this->mLocalName
;
516 * Is this page expensive (for some definition of expensive)?
517 * Expensive pages are disabled or cached in miser mode. Originally used
518 * (and still overridden) by QueryPage and subclasses, moved here so that
519 * Special:SpecialPages can safely call it for all special pages.
523 public function isExpensive() {
528 * Can be overridden by subclasses with more complicated permissions
531 * @return Boolean: should the page be displayed with the restricted-access
534 public function isRestricted() {
535 global $wgGroupPermissions;
536 // DWIM: If all anons can do something, then it is not restricted
537 return $this->mRestriction
!= '' && empty( $wgGroupPermissions['*'][$this->mRestriction
] );
541 * Checks if the given user (identified by an object) can execute this
542 * special page (as defined by $mRestriction). Can be overridden by sub-
543 * classes with more complicated permissions schemes.
545 * @param $user User: the user to check
546 * @return Boolean: does the user have permission to view the page?
548 public function userCanExecute( User
$user ) {
549 return $user->isAllowed( $this->mRestriction
);
553 * Output an error message telling the user what access level they have to have
555 function displayRestrictionError() {
556 throw new PermissionsError( $this->mRestriction
);
560 * Checks if userCanExecute, and if not throws a PermissionsError
564 public function checkPermissions() {
565 if ( !$this->userCanExecute( $this->getUser() ) ) {
566 $this->displayRestrictionError();
571 * If the wiki is currently in readonly mode, throws a ReadOnlyError
574 * @throws ReadOnlyError
576 public function checkReadOnly() {
577 if ( wfReadOnly() ) {
578 throw new ReadOnlyError
;
583 * Sets headers - this should be called from the execute() method of all derived classes!
585 function setHeaders() {
586 $out = $this->getOutput();
587 $out->setArticleRelated( false );
588 $out->setRobotPolicy( "noindex,nofollow" );
589 $out->setPageTitle( $this->getDescription() );
597 * @param $subPage string|null
599 public final function run( $subPage ) {
600 $this->beforeExecute( $subPage );
601 $this->execute( $subPage );
602 $this->afterExecute( $subPage );
606 * Gets called before @see SpecialPage::execute.
610 * @param $subPage string|null
612 protected function beforeExecute( $subPage ) {
617 * Gets called after @see SpecialPage::execute.
621 * @param $subPage string|null
623 protected function afterExecute( $subPage ) {
628 * Default execute method
629 * Checks user permissions, calls the function given in mFunction
631 * This must be overridden by subclasses; it will be made abstract in a future version
633 * @param $subPage string|null
635 public function execute( $subPage ) {
637 $this->checkPermissions();
639 $func = $this->mFunction
;
640 // only load file if the function does not exist
641 if ( !is_callable( $func ) && $this->mFile
) {
642 require_once( $this->mFile
);
644 $this->outputHeader();
645 call_user_func( $func, $subPage, $this );
649 * Outputs a summary message on top of special pages
650 * Per default the message key is the canonical name of the special page
651 * May be overriden, i.e. by extensions to stick with the naming conventions
652 * for message keys: 'extensionname-xxx'
654 * @param $summaryMessageKey String: message key of the summary
656 function outputHeader( $summaryMessageKey = '' ) {
659 if ( $summaryMessageKey == '' ) {
660 $msg = $wgContLang->lc( $this->getName() ) . '-summary';
662 $msg = $summaryMessageKey;
664 if ( !$this->msg( $msg )->isDisabled() && !$this->including() ) {
665 $this->getOutput()->wrapWikiMsg(
666 "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
672 * Returns the name that goes in the \<h1\> in the special page itself, and
673 * also the name that will be listed in Special:Specialpages
675 * Derived classes can override this, but usually it is easier to keep the
676 * default behaviour. Messages can be added at run-time, see
681 function getDescription() {
682 return $this->msg( strtolower( $this->mName
) )->text();
686 * Get a self-referential title object
688 * @param $subpage String|Bool
689 * @return Title object
691 function getTitle( $subpage = false ) {
692 return self
::getTitleFor( $this->mName
, $subpage );
696 * Sets the context this SpecialPage is executed in
698 * @param $context IContextSource
701 public function setContext( $context ) {
702 $this->mContext
= $context;
706 * Gets the context this SpecialPage is executed in
708 * @return IContextSource|RequestContext
711 public function getContext() {
712 if ( $this->mContext
instanceof IContextSource
) {
713 return $this->mContext
;
715 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
716 return RequestContext
::getMain();
721 * Get the WebRequest being used for this instance
726 public function getRequest() {
727 return $this->getContext()->getRequest();
731 * Get the OutputPage being used for this instance
736 public function getOutput() {
737 return $this->getContext()->getOutput();
741 * Shortcut to get the User executing this instance
746 public function getUser() {
747 return $this->getContext()->getUser();
751 * Shortcut to get the skin being used for this instance
756 public function getSkin() {
757 return $this->getContext()->getSkin();
761 * Shortcut to get user's language
763 * @deprecated 1.19 Use getLanguage instead
767 public function getLang() {
768 wfDeprecated( __METHOD__
, '1.19' );
769 return $this->getLanguage();
773 * Shortcut to get user's language
778 public function getLanguage() {
779 return $this->getContext()->getLanguage();
783 * Return the full title, including $par
788 public function getFullTitle() {
789 return $this->getContext()->getTitle();
793 * Wrapper around wfMessage that sets the current context.
798 public function msg( /* $args */ ) {
799 // Note: can't use func_get_args() directly as second or later item in
800 // a parameter list until PHP 5.3 or you get a fatal error.
801 // Works fine as the first parameter, which appears elsewhere in the
802 // code base. Sighhhh.
803 $args = func_get_args();
804 $message = call_user_func_array( array( $this->getContext(), 'msg' ), $args );
805 // RequestContext passes context to wfMessage, and the language is set from
806 // the context, but setting the language for Message class removes the
807 // interface message status, which breaks for example usernameless gender
808 // invokations. Restore the flag when not including special page in content.
809 if ( $this->including() ) {
810 $message->setInterfaceMessageFlag( false );
816 * Adds RSS/atom links
818 * @param $params array
820 protected function addFeedLinks( $params ) {
821 global $wgFeedClasses;
823 $feedTemplate = wfScript( 'api' ) . '?';
825 foreach ( $wgFeedClasses as $format => $class ) {
826 $theseParams = $params +
array( 'feedformat' => $format );
827 $url = $feedTemplate . wfArrayToCGI( $theseParams );
828 $this->getOutput()->addFeedLink( $format, $url );
834 * Special page which uses an HTMLForm to handle processing. This is mostly a
835 * clone of FormAction. More special pages should be built this way; maybe this could be
836 * a new structure for SpecialPages
838 abstract class FormSpecialPage
extends SpecialPage
{
841 * Get an HTMLForm descriptor array
844 protected abstract function getFormFields();
847 * Add pre- or post-text to the form
848 * @return String HTML which will be sent to $form->addPreText()
850 protected function preText() { return ''; }
851 protected function postText() { return ''; }
854 * Play with the HTMLForm if you need to more substantially
855 * @param $form HTMLForm
857 protected function alterForm( HTMLForm
$form ) {}
860 * Get the HTMLForm to control behaviour
861 * @return HTMLForm|null
863 protected function getForm() {
864 $this->fields
= $this->getFormFields();
866 $form = new HTMLForm( $this->fields
, $this->getContext() );
867 $form->setSubmitCallback( array( $this, 'onSubmit' ) );
868 $form->setWrapperLegend( $this->msg( strtolower( $this->getName() ) . '-legend' ) );
869 $form->addHeaderText(
870 $this->msg( strtolower( $this->getName() ) . '-text' )->parseAsBlock() );
872 // Retain query parameters (uselang etc)
873 $params = array_diff_key(
874 $this->getRequest()->getQueryValues(), array( 'title' => null ) );
875 $form->addHiddenField( 'redirectparams', wfArrayToCGI( $params ) );
877 $form->addPreText( $this->preText() );
878 $form->addPostText( $this->postText() );
879 $this->alterForm( $form );
881 // Give hooks a chance to alter the form, adding extra fields or text etc
882 wfRunHooks( "Special{$this->getName()}BeforeFormDisplay", array( &$form ) );
888 * Process the form on POST submission.
890 * @return Bool|Array true for success, false for didn't-try, array of errors on failure
892 public abstract function onSubmit( array $data );
895 * Do something exciting on successful processing of the form, most likely to show a
896 * confirmation message
898 public abstract function onSuccess();
901 * Basic SpecialPage workflow: get a form, send it to the user; get some data back,
903 * @param $par String Subpage string if one was specified
905 public function execute( $par ) {
906 $this->setParameter( $par );
909 // This will throw exceptions if there's a problem
910 $this->checkExecutePermissions( $this->getUser() );
912 $form = $this->getForm();
913 if ( $form->show() ) {
919 * Maybe do something interesting with the subpage parameter
922 protected function setParameter( $par ) {}
925 * Called from execute() to check if the given user can perform this action.
926 * Failures here must throw subclasses of ErrorPageError.
929 * @throws ErrorPageError
931 protected function checkExecutePermissions( User
$user ) {
932 $this->checkPermissions();
934 if ( $this->requiresUnblock() && $user->isBlocked() ) {
935 $block = $user->getBlock();
936 throw new UserBlockedError( $block );
939 if ( $this->requiresWrite() ) {
940 $this->checkReadOnly();
947 * Whether this action requires the wiki not to be locked
950 public function requiresWrite() {
955 * Whether this action cannot be executed by a blocked user
958 public function requiresUnblock() {
964 * Shortcut to construct a special page which is unlisted by default
965 * @ingroup SpecialPage
967 class UnlistedSpecialPage
extends SpecialPage
{
968 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
969 parent
::__construct( $name, $restriction, false, $function, $file );
972 public function isListed() {
978 * Shortcut to construct an includable special page
979 * @ingroup SpecialPage
981 class IncludableSpecialPage
extends SpecialPage
{
982 function __construct(
983 $name, $restriction = '', $listed = true, $function = false, $file = 'default'
985 parent
::__construct( $name, $restriction, $listed, $function, $file, true );
988 public function isIncludable() {
994 * Shortcut to construct a special page alias.
995 * @ingroup SpecialPage
997 abstract class RedirectSpecialPage
extends UnlistedSpecialPage
{
999 // Query parameters that can be passed through redirects
1000 protected $mAllowedRedirectParams = array();
1002 // Query parameteres added by redirects
1003 protected $mAddedRedirectParams = array();
1005 public function execute( $par ) {
1006 $redirect = $this->getRedirect( $par );
1007 $query = $this->getRedirectQuery();
1008 // Redirect to a page title with possible query parameters
1009 if ( $redirect instanceof Title
) {
1010 $url = $redirect->getFullUrl( $query );
1011 $this->getOutput()->redirect( $url );
1012 wfProfileOut( __METHOD__
);
1014 // Redirect to index.php with query parameters
1015 } elseif ( $redirect === true ) {
1017 $url = $wgScript . '?' . wfArrayToCGI( $query );
1018 $this->getOutput()->redirect( $url );
1019 wfProfileOut( __METHOD__
);
1023 throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
1028 * If the special page is a redirect, then get the Title object it redirects to.
1031 * @param $par String Subpage string
1032 * @return Title|bool
1034 abstract public function getRedirect( $par );
1037 * Return part of the request string for a special redirect page
1038 * This allows passing, e.g. action=history to Special:Mypage, etc.
1042 public function getRedirectQuery() {
1045 foreach ( $this->mAllowedRedirectParams
as $arg ) {
1046 if ( $this->getRequest()->getVal( $arg, null ) !== null ) {
1047 $params[$arg] = $this->getRequest()->getVal( $arg );
1051 foreach ( $this->mAddedRedirectParams
as $arg => $val ) {
1052 $params[$arg] = $val;
1055 return count( $params )
1061 abstract class SpecialRedirectToSpecial
extends RedirectSpecialPage
{
1062 var $redirName, $redirSubpage;
1064 function __construct(
1065 $name, $redirName, $redirSubpage = false,
1066 $allowedRedirectParams = array(), $addedRedirectParams = array()
1068 parent
::__construct( $name );
1069 $this->redirName
= $redirName;
1070 $this->redirSubpage
= $redirSubpage;
1071 $this->mAllowedRedirectParams
= $allowedRedirectParams;
1072 $this->mAddedRedirectParams
= $addedRedirectParams;
1075 public function getRedirect( $subpage ) {
1076 if ( $this->redirSubpage
=== false ) {
1077 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
1079 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
1085 * ListAdmins --> ListUsers/sysop
1087 class SpecialListAdmins
extends SpecialRedirectToSpecial
{
1088 function __construct() {
1089 parent
::__construct( 'Listadmins', 'Listusers', 'sysop' );
1094 * ListBots --> ListUsers/bot
1096 class SpecialListBots
extends SpecialRedirectToSpecial
{
1097 function __construct() {
1098 parent
::__construct( 'Listbots', 'Listusers', 'bot' );
1103 * CreateAccount --> UserLogin/signup
1104 * @todo FIXME: This (and the rest of the login frontend) needs to die a horrible painful death
1106 class SpecialCreateAccount
extends SpecialRedirectToSpecial
{
1107 function __construct() {
1108 parent
::__construct( 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) );
1112 * SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
1113 * are used to get user independant links pointing to the user page, talk
1114 * page and list of contributions.
1115 * This can let us cache a single copy of any generated content for all
1120 * Shortcut to construct a special page pointing to current user user's page.
1121 * @ingroup SpecialPage
1123 class SpecialMypage
extends RedirectSpecialPage
{
1124 function __construct() {
1125 parent
::__construct( 'Mypage' );
1126 $this->mAllowedRedirectParams
= array( 'action', 'preload', 'preloadtitle', 'editintro',
1127 'section', 'oldid', 'diff', 'dir',
1128 // Options for action=raw; missing ctype can break JS or CSS in some browsers
1129 'ctype', 'maxage', 'smaxage' );
1132 function getRedirect( $subpage ) {
1133 if ( strval( $subpage ) !== '' ) {
1134 return Title
::makeTitle( NS_USER
, $this->getUser()->getName() . '/' . $subpage );
1136 return Title
::makeTitle( NS_USER
, $this->getUser()->getName() );
1142 * Shortcut to construct a special page pointing to current user talk page.
1143 * @ingroup SpecialPage
1145 class SpecialMytalk
extends RedirectSpecialPage
{
1146 function __construct() {
1147 parent
::__construct( 'Mytalk' );
1148 $this->mAllowedRedirectParams
= array( 'action', 'preload', 'preloadtitle', 'editintro',
1149 'section', 'oldid', 'diff', 'dir' );
1152 function getRedirect( $subpage ) {
1153 if ( strval( $subpage ) !== '' ) {
1154 return Title
::makeTitle( NS_USER_TALK
, $this->getUser()->getName() . '/' . $subpage );
1156 return Title
::makeTitle( NS_USER_TALK
, $this->getUser()->getName() );
1162 * Shortcut to construct a special page pointing to current user contributions.
1163 * @ingroup SpecialPage
1165 class SpecialMycontributions
extends RedirectSpecialPage
{
1166 function __construct() {
1167 parent
::__construct( 'Mycontributions' );
1168 $this->mAllowedRedirectParams
= array( 'limit', 'namespace', 'tagfilter',
1169 'offset', 'dir', 'year', 'month', 'feed' );
1172 function getRedirect( $subpage ) {
1173 return SpecialPage
::getTitleFor( 'Contributions', $this->getUser()->getName() );
1178 * Redirect to Special:Listfiles?user=$wgUser
1180 class SpecialMyuploads
extends RedirectSpecialPage
{
1181 function __construct() {
1182 parent
::__construct( 'Myuploads' );
1183 $this->mAllowedRedirectParams
= array( 'limit' );
1186 function getRedirect( $subpage ) {
1187 return SpecialPage
::getTitleFor( 'Listfiles', $this->getUser()->getName() );
1192 * Redirect from Special:PermanentLink/### to index.php?oldid=###
1194 class SpecialPermanentLink
extends RedirectSpecialPage
{
1195 function __construct() {
1196 parent
::__construct( 'PermanentLink' );
1197 $this->mAllowedRedirectParams
= array();
1200 function getRedirect( $subpage ) {
1201 $subpage = intval( $subpage );
1202 if ( $subpage === 0 ) {
1203 # throw an error page when no subpage was given
1204 throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
1206 $this->mAddedRedirectParams
['oldid'] = $subpage;