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 a certain display group for Special:SpecialPages
111 * @param $page Mixed: SpecialPage or string
112 * @param $group String
113 * @deprecated since 1.18 call SpecialPageFactory method directly
115 static function setGroup( $page, $group ) {
116 wfDeprecated( __METHOD__
, '1.18' );
117 SpecialPageFactory
::setGroup( $page, $group );
121 * Get the group that the special page belongs in on Special:SpecialPage
123 * @param $page SpecialPage
125 * @deprecated since 1.18 call SpecialPageFactory method directly
127 static function getGroup( &$page ) {
128 wfDeprecated( __METHOD__
, '1.18' );
129 return SpecialPageFactory
::getGroup( $page );
133 * Remove a special page from the list
134 * Formerly used to disable expensive or dangerous special pages. The
135 * preferred method is now to add a SpecialPage_initList hook.
136 * @deprecated since 1.18
138 * @param $name String the page to remove
140 static function removePage( $name ) {
141 wfDeprecated( __METHOD__
, '1.18' );
142 unset( SpecialPageFactory
::getList()->$name );
146 * Check if a given name exist as a special page or as a special page alias
148 * @param $name String: name of a special page
149 * @return Boolean: true if a special page exists with this name
150 * @deprecated since 1.18 call SpecialPageFactory method directly
152 static function exists( $name ) {
153 wfDeprecated( __METHOD__
, '1.18' );
154 return SpecialPageFactory
::exists( $name );
158 * Find the object with a given name and return it (or NULL)
160 * @param $name String
161 * @return SpecialPage object or null if the page doesn't exist
162 * @deprecated since 1.18 call SpecialPageFactory method directly
164 static function getPage( $name ) {
165 wfDeprecated( __METHOD__
, '1.18' );
166 return SpecialPageFactory
::getPage( $name );
170 * Get a special page with a given localised name, or NULL if there
171 * is no such special page.
173 * @param $alias 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 getPageByAlias( $alias ) {
178 wfDeprecated( __METHOD__
, '1.18' );
179 return SpecialPageFactory
::getPage( $alias );
183 * Return categorised listable special pages which are available
184 * for the current user, and everyone.
186 * @param $user User object to check permissions, $wgUser will be used
188 * @return array Associative array mapping page's name to its SpecialPage object
189 * @deprecated since 1.18 call SpecialPageFactory method directly
191 static function getUsablePages( User
$user = null ) {
192 wfDeprecated( __METHOD__
, '1.18' );
193 return SpecialPageFactory
::getUsablePages( $user );
197 * Return categorised listable special pages for all users
199 * @return array Associative array mapping page's name to its SpecialPage object
200 * @deprecated since 1.18 call SpecialPageFactory method directly
202 static function getRegularPages() {
203 wfDeprecated( __METHOD__
, '1.18' );
204 return SpecialPageFactory
::getRegularPages();
208 * Return categorised listable special pages which are available
209 * for the current user, but not for everyone
211 * @return array Associative array mapping page's name to its SpecialPage object
212 * @deprecated since 1.18 call SpecialPageFactory method directly
214 static function getRestrictedPages() {
215 wfDeprecated( __METHOD__
, '1.18' );
216 return SpecialPageFactory
::getRestrictedPages();
220 * Execute a special page path.
221 * The path may contain parameters, e.g. Special:Name/Params
222 * Extracts the special page name and call the execute method, passing the parameters
224 * Returns a title object if the page is redirected, false if there was no such special
225 * page, and true if it was successful.
227 * @param $title Title object
228 * @param $context IContextSource
229 * @param $including Bool output is being captured for use in {{special:whatever}}
231 * @deprecated since 1.18 call SpecialPageFactory method directly
233 public static function executePath( &$title, IContextSource
&$context, $including = false ) {
234 wfDeprecated( __METHOD__
, '1.18' );
235 return SpecialPageFactory
::executePath( $title, $context, $including );
239 * Get the local name for a specified canonical name
241 * @param $name String
242 * @param $subpage Mixed: boolean false, or string
245 * @deprecated since 1.18 call SpecialPageFactory method directly
247 static function getLocalNameFor( $name, $subpage = false ) {
248 wfDeprecated( __METHOD__
, '1.18' );
249 return SpecialPageFactory
::getLocalNameFor( $name, $subpage );
253 * Get a localised Title object for a specified special page name
255 * @param $name String
256 * @param $subpage String|Bool subpage string, or false to not use a subpage
257 * @return Title object
259 public static function getTitleFor( $name, $subpage = false ) {
260 $name = SpecialPageFactory
::getLocalNameFor( $name, $subpage );
262 return Title
::makeTitle( NS_SPECIAL
, $name );
264 throw new MWException( "Invalid special page name \"$name\"" );
269 * Get a localised Title object for a page name with a possibly unvalidated subpage
271 * @param $name String
272 * @param $subpage String|Bool subpage string, or false to not use a subpage
273 * @return Title object or null if the page doesn't exist
275 public static function getSafeTitleFor( $name, $subpage = false ) {
276 $name = SpecialPageFactory
::getLocalNameFor( $name, $subpage );
278 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
285 * Get a title for a given alias
287 * @param $alias String
288 * @return Title or null if there is no such alias
289 * @deprecated since 1.18 call SpecialPageFactory method directly
291 static function getTitleForAlias( $alias ) {
292 wfDeprecated( __METHOD__
, '1.18' );
293 return SpecialPageFactory
::getTitleForAlias( $alias );
297 * Default constructor for special pages
298 * Derivative classes should call this from their constructor
299 * Note that if the user does not have the required level, an error message will
300 * be displayed by the default execute() method, without the global function ever
303 * If you override execute(), you can recover the default behaviour with userCanExecute()
304 * and displayRestrictionError()
306 * @param $name String: name of the special page, as seen in links and URLs
307 * @param $restriction String: user right required, e.g. "block" or "delete"
308 * @param $listed Bool: whether the page is listed in Special:Specialpages
309 * @param $function Callback|Bool: function called by execute(). By default it is constructed from $name
310 * @param $file String: file which is included by execute(). It is also constructed from $name by default
311 * @param $includable Bool: whether the page can be included in normal pages
313 public function __construct(
314 $name = '', $restriction = '', $listed = true,
315 $function = false, $file = 'default', $includable = false
317 $this->init( $name, $restriction, $listed, $function, $file, $includable );
321 * Do the real work for the constructor, mainly so __call() can intercept
322 * calls to SpecialPage()
323 * @param $name String: name of the special page, as seen in links and URLs
324 * @param $restriction String: user right required, e.g. "block" or "delete"
325 * @param $listed Bool: whether the page is listed in Special:Specialpages
326 * @param $function Callback|Bool: function called by execute(). By default it is constructed from $name
327 * @param $file String: file which is included by execute(). It is also constructed from $name by default
328 * @param $includable Bool: whether the page can be included in normal pages
330 private function init( $name, $restriction, $listed, $function, $file, $includable ) {
331 $this->mName
= $name;
332 $this->mRestriction
= $restriction;
333 $this->mListed
= $listed;
334 $this->mIncludable
= $includable;
336 $this->mFunction
= 'wfSpecial' . $name;
338 $this->mFunction
= $function;
340 if ( $file === 'default' ) {
341 $this->mFile
= __DIR__
. "/specials/Special$name.php";
343 $this->mFile
= $file;
348 * Use PHP's magic __call handler to get calls to the old PHP4 constructor
349 * because PHP E_STRICT yells at you for having __construct() and SpecialPage()
351 * @param $fName String Name of called method
352 * @param $a Array Arguments to the method
353 * @deprecated since 1.17, call parent::__construct()
355 public function __call( $fName, $a ) {
356 // Deprecated messages now, remove in 1.19 or 1.20?
357 wfDeprecated( __METHOD__
, '1.17' );
359 // Sometimes $fName is SpecialPage, sometimes it's specialpage. <3 PHP
360 if ( strtolower( $fName ) == 'specialpage' ) {
361 $name = isset( $a[0] ) ?
$a[0] : '';
362 $restriction = isset( $a[1] ) ?
$a[1] : '';
363 $listed = isset( $a[2] ) ?
$a[2] : true;
364 $function = isset( $a[3] ) ?
$a[3] : false;
365 $file = isset( $a[4] ) ?
$a[4] : 'default';
366 $includable = isset( $a[5] ) ?
$a[5] : false;
367 $this->init( $name, $restriction, $listed, $function, $file, $includable );
369 $className = get_class( $this );
370 throw new MWException( "Call to undefined method $className::$fName" );
375 * Get the name of this Special Page.
383 * Get the permission that a user must have to execute this page
386 function getRestriction() {
387 return $this->mRestriction
;
391 * Get the file which will be included by SpecialPage::execute() if your extension is
392 * still stuck in the past and hasn't overridden the execute() method. No modern code
393 * should want or need to know this.
395 * @deprecated since 1.18
398 wfDeprecated( __METHOD__
, '1.18' );
402 // @todo FIXME: Decide which syntax to use for this, and stick to it
404 * Whether this special page is listed in Special:SpecialPages
405 * @since r3583 (v1.3)
408 function isListed() {
409 return $this->mListed
;
412 * Set whether this page is listed in Special:Specialpages, at run-time
413 * @since r3583 (v1.3)
414 * @param $listed Bool
417 function setListed( $listed ) {
418 return wfSetVar( $this->mListed
, $listed );
421 * Get or set whether this special page is listed in Special:SpecialPages
422 * @since r11308 (v1.6)
426 function listed( $x = null ) {
427 return wfSetVar( $this->mListed
, $x );
431 * Whether it's allowed to transclude the special page via {{Special:Foo/params}}
434 public function isIncludable() {
435 return $this->mIncludable
;
439 * These mutators are very evil, as the relevant variables should not mutate. So
443 * @deprecated since 1.18
445 function name( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mName
, $x ); }
448 * These mutators are very evil, as the relevant variables should not mutate. So
452 * @deprecated since 1.18
454 function restriction( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mRestriction
, $x ); }
457 * These mutators are very evil, as the relevant variables should not mutate. So
461 * @deprecated since 1.18
463 function func( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mFunction
, $x ); }
466 * These mutators are very evil, as the relevant variables should not mutate. So
470 * @deprecated since 1.18
472 function file( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mFile
, $x ); }
475 * These mutators are very evil, as the relevant variables should not mutate. So
479 * @deprecated since 1.18
481 function includable( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mIncludable
, $x ); }
484 * Whether the special page is being evaluated via transclusion
488 function including( $x = null ) {
489 return wfSetVar( $this->mIncluding
, $x );
493 * Get the localised name of the special page
495 function getLocalName() {
496 if ( !isset( $this->mLocalName
) ) {
497 $this->mLocalName
= SpecialPageFactory
::getLocalNameFor( $this->mName
);
499 return $this->mLocalName
;
503 * Is this page expensive (for some definition of expensive)?
504 * Expensive pages are disabled or cached in miser mode. Originally used
505 * (and still overridden) by QueryPage and subclasses, moved here so that
506 * Special:SpecialPages can safely call it for all special pages.
510 public function isExpensive() {
515 * Can be overridden by subclasses with more complicated permissions
518 * @return Boolean: should the page be displayed with the restricted-access
521 public function isRestricted() {
522 global $wgGroupPermissions;
523 // DWIM: If all anons can do something, then it is not restricted
524 return $this->mRestriction
!= '' && empty( $wgGroupPermissions['*'][$this->mRestriction
] );
528 * Checks if the given user (identified by an object) can execute this
529 * special page (as defined by $mRestriction). Can be overridden by sub-
530 * classes with more complicated permissions schemes.
532 * @param $user User: the user to check
533 * @return Boolean: does the user have permission to view the page?
535 public function userCanExecute( User
$user ) {
536 return $user->isAllowed( $this->mRestriction
);
540 * Output an error message telling the user what access level they have to have
542 function displayRestrictionError() {
543 throw new PermissionsError( $this->mRestriction
);
547 * Checks if userCanExecute, and if not throws a PermissionsError
551 public function checkPermissions() {
552 if ( !$this->userCanExecute( $this->getUser() ) ) {
553 $this->displayRestrictionError();
558 * If the wiki is currently in readonly mode, throws a ReadOnlyError
561 * @throws ReadOnlyError
563 public function checkReadOnly() {
564 if ( wfReadOnly() ) {
565 throw new ReadOnlyError
;
570 * Sets headers - this should be called from the execute() method of all derived classes!
572 function setHeaders() {
573 $out = $this->getOutput();
574 $out->setArticleRelated( false );
575 $out->setRobotPolicy( "noindex,nofollow" );
576 $out->setPageTitle( $this->getDescription() );
584 * @param $subPage string|null
586 public final function run( $subPage ) {
588 * Gets called before @see SpecialPage::execute.
592 * @param $special SpecialPage
593 * @param $subPage string|null
595 wfRunHooks( 'SpecialPageBeforeExecute', array( $this, $subPage ) );
597 $this->beforeExecute( $subPage );
598 $this->execute( $subPage );
599 $this->afterExecute( $subPage );
602 * Gets called after @see SpecialPage::execute.
606 * @param $special SpecialPage
607 * @param $subPage string|null
609 wfRunHooks( 'SpecialPageAfterExecute', array( $this, $subPage ) );
613 * Gets called before @see SpecialPage::execute.
617 * @param $subPage string|null
619 protected function beforeExecute( $subPage ) {
624 * Gets called after @see SpecialPage::execute.
628 * @param $subPage string|null
630 protected function afterExecute( $subPage ) {
635 * Default execute method
636 * Checks user permissions, calls the function given in mFunction
638 * This must be overridden by subclasses; it will be made abstract in a future version
640 * @param $subPage string|null
642 public function execute( $subPage ) {
644 $this->checkPermissions();
646 $func = $this->mFunction
;
647 // only load file if the function does not exist
648 if ( !is_callable( $func ) && $this->mFile
) {
649 require_once( $this->mFile
);
651 $this->outputHeader();
652 call_user_func( $func, $subPage, $this );
656 * Outputs a summary message on top of special pages
657 * Per default the message key is the canonical name of the special page
658 * May be overriden, i.e. by extensions to stick with the naming conventions
659 * for message keys: 'extensionname-xxx'
661 * @param $summaryMessageKey String: message key of the summary
663 function outputHeader( $summaryMessageKey = '' ) {
666 if ( $summaryMessageKey == '' ) {
667 $msg = $wgContLang->lc( $this->getName() ) . '-summary';
669 $msg = $summaryMessageKey;
671 if ( !$this->msg( $msg )->isDisabled() && !$this->including() ) {
672 $this->getOutput()->wrapWikiMsg(
673 "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
679 * Returns the name that goes in the \<h1\> in the special page itself, and
680 * also the name that will be listed in Special:Specialpages
682 * Derived classes can override this, but usually it is easier to keep the
683 * default behaviour. Messages can be added at run-time, see
688 function getDescription() {
689 return $this->msg( strtolower( $this->mName
) )->text();
693 * Get a self-referential title object
695 * @param $subpage String|Bool
696 * @return Title object
698 function getTitle( $subpage = false ) {
699 return self
::getTitleFor( $this->mName
, $subpage );
703 * Sets the context this SpecialPage is executed in
705 * @param $context IContextSource
708 public function setContext( $context ) {
709 $this->mContext
= $context;
713 * Gets the context this SpecialPage is executed in
715 * @return IContextSource|RequestContext
718 public function getContext() {
719 if ( $this->mContext
instanceof IContextSource
) {
720 return $this->mContext
;
722 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
723 return RequestContext
::getMain();
728 * Get the WebRequest being used for this instance
733 public function getRequest() {
734 return $this->getContext()->getRequest();
738 * Get the OutputPage being used for this instance
743 public function getOutput() {
744 return $this->getContext()->getOutput();
748 * Shortcut to get the User executing this instance
753 public function getUser() {
754 return $this->getContext()->getUser();
758 * Shortcut to get the skin being used for this instance
763 public function getSkin() {
764 return $this->getContext()->getSkin();
768 * Shortcut to get user's language
770 * @deprecated 1.19 Use getLanguage instead
774 public function getLang() {
775 wfDeprecated( __METHOD__
, '1.19' );
776 return $this->getLanguage();
780 * Shortcut to get user's language
785 public function getLanguage() {
786 return $this->getContext()->getLanguage();
790 * Return the full title, including $par
795 public function getFullTitle() {
796 return $this->getContext()->getTitle();
800 * Wrapper around wfMessage that sets the current context.
805 public function msg( /* $args */ ) {
806 // Note: can't use func_get_args() directly as second or later item in
807 // a parameter list until PHP 5.3 or you get a fatal error.
808 // Works fine as the first parameter, which appears elsewhere in the
809 // code base. Sighhhh.
810 $args = func_get_args();
811 $message = call_user_func_array( array( $this->getContext(), 'msg' ), $args );
812 // RequestContext passes context to wfMessage, and the language is set from
813 // the context, but setting the language for Message class removes the
814 // interface message status, which breaks for example usernameless gender
815 // invokations. Restore the flag when not including special page in content.
816 if ( $this->including() ) {
817 $message->setInterfaceMessageFlag( false );
823 * Adds RSS/atom links
825 * @param $params array
827 protected function addFeedLinks( $params ) {
828 global $wgFeedClasses;
830 $feedTemplate = wfScript( 'api' ) . '?';
832 foreach ( $wgFeedClasses as $format => $class ) {
833 $theseParams = $params +
array( 'feedformat' => $format );
834 $url = $feedTemplate . wfArrayToCGI( $theseParams );
835 $this->getOutput()->addFeedLink( $format, $url );
841 * Special page which uses an HTMLForm to handle processing. This is mostly a
842 * clone of FormAction. More special pages should be built this way; maybe this could be
843 * a new structure for SpecialPages
845 abstract class FormSpecialPage
extends SpecialPage
{
848 * Get an HTMLForm descriptor array
851 protected abstract function getFormFields();
854 * Add pre- or post-text to the form
855 * @return String HTML which will be sent to $form->addPreText()
857 protected function preText() { return ''; }
858 protected function postText() { return ''; }
861 * Play with the HTMLForm if you need to more substantially
862 * @param $form HTMLForm
864 protected function alterForm( HTMLForm
$form ) {}
867 * Get the HTMLForm to control behaviour
868 * @return HTMLForm|null
870 protected function getForm() {
871 $this->fields
= $this->getFormFields();
873 $form = new HTMLForm( $this->fields
, $this->getContext() );
874 $form->setSubmitCallback( array( $this, 'onSubmit' ) );
875 $form->setWrapperLegend( $this->msg( strtolower( $this->getName() ) . '-legend' ) );
876 $form->addHeaderText(
877 $this->msg( strtolower( $this->getName() ) . '-text' )->parseAsBlock() );
879 // Retain query parameters (uselang etc)
880 $params = array_diff_key(
881 $this->getRequest()->getQueryValues(), array( 'title' => null ) );
882 $form->addHiddenField( 'redirectparams', wfArrayToCGI( $params ) );
884 $form->addPreText( $this->preText() );
885 $form->addPostText( $this->postText() );
886 $this->alterForm( $form );
888 // Give hooks a chance to alter the form, adding extra fields or text etc
889 wfRunHooks( "Special{$this->getName()}BeforeFormDisplay", array( &$form ) );
895 * Process the form on POST submission.
897 * @return Bool|Array true for success, false for didn't-try, array of errors on failure
899 public abstract function onSubmit( array $data );
902 * Do something exciting on successful processing of the form, most likely to show a
903 * confirmation message
905 public abstract function onSuccess();
908 * Basic SpecialPage workflow: get a form, send it to the user; get some data back,
910 * @param $par String Subpage string if one was specified
912 public function execute( $par ) {
913 $this->setParameter( $par );
916 // This will throw exceptions if there's a problem
917 $this->checkExecutePermissions( $this->getUser() );
919 $form = $this->getForm();
920 if ( $form->show() ) {
926 * Maybe do something interesting with the subpage parameter
929 protected function setParameter( $par ) {}
932 * Called from execute() to check if the given user can perform this action.
933 * Failures here must throw subclasses of ErrorPageError.
936 * @throws ErrorPageError
938 protected function checkExecutePermissions( User
$user ) {
939 $this->checkPermissions();
941 if ( $this->requiresUnblock() && $user->isBlocked() ) {
942 $block = $user->getBlock();
943 throw new UserBlockedError( $block );
946 if ( $this->requiresWrite() ) {
947 $this->checkReadOnly();
954 * Whether this action requires the wiki not to be locked
957 public function requiresWrite() {
962 * Whether this action cannot be executed by a blocked user
965 public function requiresUnblock() {
971 * Shortcut to construct a special page which is unlisted by default
972 * @ingroup SpecialPage
974 class UnlistedSpecialPage
extends SpecialPage
{
975 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
976 parent
::__construct( $name, $restriction, false, $function, $file );
979 public function isListed() {
985 * Shortcut to construct an includable special page
986 * @ingroup SpecialPage
988 class IncludableSpecialPage
extends SpecialPage
{
989 function __construct(
990 $name, $restriction = '', $listed = true, $function = false, $file = 'default'
992 parent
::__construct( $name, $restriction, $listed, $function, $file, true );
995 public function isIncludable() {
1001 * Shortcut to construct a special page alias.
1002 * @ingroup SpecialPage
1004 abstract class RedirectSpecialPage
extends UnlistedSpecialPage
{
1006 // Query parameters that can be passed through redirects
1007 protected $mAllowedRedirectParams = array();
1009 // Query parameteres added by redirects
1010 protected $mAddedRedirectParams = array();
1012 public function execute( $par ) {
1013 $redirect = $this->getRedirect( $par );
1014 $query = $this->getRedirectQuery();
1015 // Redirect to a page title with possible query parameters
1016 if ( $redirect instanceof Title
) {
1017 $url = $redirect->getFullUrl( $query );
1018 $this->getOutput()->redirect( $url );
1019 wfProfileOut( __METHOD__
);
1021 // Redirect to index.php with query parameters
1022 } elseif ( $redirect === true ) {
1024 $url = $wgScript . '?' . wfArrayToCGI( $query );
1025 $this->getOutput()->redirect( $url );
1026 wfProfileOut( __METHOD__
);
1030 throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
1035 * If the special page is a redirect, then get the Title object it redirects to.
1038 * @param $par String Subpage string
1039 * @return Title|bool
1041 abstract public function getRedirect( $par );
1044 * Return part of the request string for a special redirect page
1045 * This allows passing, e.g. action=history to Special:Mypage, etc.
1049 public function getRedirectQuery() {
1052 foreach ( $this->mAllowedRedirectParams
as $arg ) {
1053 if ( $this->getRequest()->getVal( $arg, null ) !== null ) {
1054 $params[$arg] = $this->getRequest()->getVal( $arg );
1058 foreach ( $this->mAddedRedirectParams
as $arg => $val ) {
1059 $params[$arg] = $val;
1062 return count( $params )
1068 abstract class SpecialRedirectToSpecial
extends RedirectSpecialPage
{
1069 var $redirName, $redirSubpage;
1071 function __construct(
1072 $name, $redirName, $redirSubpage = false,
1073 $allowedRedirectParams = array(), $addedRedirectParams = array()
1075 parent
::__construct( $name );
1076 $this->redirName
= $redirName;
1077 $this->redirSubpage
= $redirSubpage;
1078 $this->mAllowedRedirectParams
= $allowedRedirectParams;
1079 $this->mAddedRedirectParams
= $addedRedirectParams;
1082 public function getRedirect( $subpage ) {
1083 if ( $this->redirSubpage
=== false ) {
1084 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
1086 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
1092 * ListAdmins --> ListUsers/sysop
1094 class SpecialListAdmins
extends SpecialRedirectToSpecial
{
1095 function __construct() {
1096 parent
::__construct( 'Listadmins', 'Listusers', 'sysop' );
1101 * ListBots --> ListUsers/bot
1103 class SpecialListBots
extends SpecialRedirectToSpecial
{
1104 function __construct() {
1105 parent
::__construct( 'Listbots', 'Listusers', 'bot' );
1110 * CreateAccount --> UserLogin/signup
1111 * @todo FIXME: This (and the rest of the login frontend) needs to die a horrible painful death
1113 class SpecialCreateAccount
extends SpecialRedirectToSpecial
{
1114 function __construct() {
1115 parent
::__construct( 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) );
1119 * SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
1120 * are used to get user independant links pointing to the user page, talk
1121 * page and list of contributions.
1122 * This can let us cache a single copy of any generated content for all
1127 * Superclass for any RedirectSpecialPage which redirects the user
1128 * to a particular article (as opposed to user contributions, logs, etc.).
1130 * For security reasons these special pages are restricted to pass on
1131 * the following subset of GET parameters to the target page while
1132 * removing all others:
1134 * - useskin, uselang, printable: to alter the appearance of the resulting page
1136 * - redirect: allows viewing one's user page or talk page even if it is a
1139 * - rdfrom: allows redirecting to one's user page or talk page from an
1140 * external wiki with the "Redirect from..." notice.
1142 * - limit, offset: Useful for linking to history of one's own user page or
1143 * user talk page. For example, this would be a link to "the last edit to your
1144 * user talk page in the year 2010":
1145 * http://en.wikipedia.org/w/index.php?title=Special:MyPage&offset=20110000000000&limit=1&action=history
1147 * - feed: would allow linking to the current user's RSS feed for their user
1149 * http://en.wikipedia.org/w/index.php?title=Special:MyTalk&action=history&feed=rss
1151 * - preloadtitle: Can be used to provide a default section title for a
1152 * preloaded new comment on one's own talk page.
1154 * - summary : Can be used to provide a default edit summary for a preloaded
1155 * edit to one's own user page or talk page.
1157 * - preview: Allows showing/hiding preview on first edit regardless of user
1158 * preference, useful for preloaded edits where you know preview wouldn't be
1161 * - internaledit, externaledit, mode: Allows forcing the use of the
1162 * internal/external editor, e.g. to force the internal editor for
1163 * short/simple preloaded edits.
1165 * - redlink: Affects the message the user sees if their talk page/user talk
1166 * page does not currently exist. Avoids confusion for newbies with no user
1167 * pages over why they got a "permission error" following this link:
1168 * http://en.wikipedia.org/w/index.php?title=Special:MyPage&redlink=1
1170 * - debug: determines whether the debug parameter is passed to load.php,
1171 * which disables reformatting and allows scripts to be debugged. Useful
1172 * when debugging scripts that manipulate one's own user page or talk page.
1174 * @par Hook extension:
1175 * Extensions can add to the redirect parameters list by using the hook
1176 * RedirectSpecialArticleRedirectParams
1178 * This hook allows extensions which add GET parameters like FlaggedRevs to
1179 * retain those parameters when redirecting using special pages.
1181 * @par Hook extension example:
1183 * $wgHooks['RedirectSpecialArticleRedirectParams'][] =
1184 * 'MyExtensionHooks::onRedirectSpecialArticleRedirectParams';
1185 * public static function onRedirectSpecialArticleRedirectParams( &$redirectParams ) {
1186 * $redirectParams[] = 'stable';
1190 * @ingroup SpecialPage
1192 abstract class RedirectSpecialArticle
extends RedirectSpecialPage
{
1193 function __construct( $name ) {
1194 parent
::__construct( $name );
1195 $redirectParams = array(
1197 'redirect', 'rdfrom',
1198 # Options for preloaded edits
1199 'preload', 'editintro', 'preloadtitle', 'summary',
1200 # Options for overriding user settings
1201 'preview', 'internaledit', 'externaledit', 'mode',
1202 # Options for history/diffs
1203 'section', 'oldid', 'diff', 'dir',
1204 'limit', 'offset', 'feed',
1207 # Options for action=raw; missing ctype can break JS or CSS in some browsers
1208 'ctype', 'maxage', 'smaxage',
1211 wfRunHooks( "RedirectSpecialArticleRedirectParams", array(&$redirectParams) );
1212 $this->mAllowedRedirectParams
= $redirectParams;
1217 * Shortcut to construct a special page pointing to current user user's page.
1218 * @ingroup SpecialPage
1220 class SpecialMypage
extends RedirectSpecialArticle
{
1221 function __construct() {
1222 parent
::__construct( 'Mypage' );
1225 function getRedirect( $subpage ) {
1226 if ( strval( $subpage ) !== '' ) {
1227 return Title
::makeTitle( NS_USER
, $this->getUser()->getName() . '/' . $subpage );
1229 return Title
::makeTitle( NS_USER
, $this->getUser()->getName() );
1235 * Shortcut to construct a special page pointing to current user talk page.
1236 * @ingroup SpecialPage
1238 class SpecialMytalk
extends RedirectSpecialArticle
{
1239 function __construct() {
1240 parent
::__construct( 'Mytalk' );
1243 function getRedirect( $subpage ) {
1244 if ( strval( $subpage ) !== '' ) {
1245 return Title
::makeTitle( NS_USER_TALK
, $this->getUser()->getName() . '/' . $subpage );
1247 return Title
::makeTitle( NS_USER_TALK
, $this->getUser()->getName() );
1253 * Shortcut to construct a special page pointing to current user contributions.
1254 * @ingroup SpecialPage
1256 class SpecialMycontributions
extends RedirectSpecialPage
{
1257 function __construct() {
1258 parent
::__construct( 'Mycontributions' );
1259 $this->mAllowedRedirectParams
= array( 'limit', 'namespace', 'tagfilter',
1260 'offset', 'dir', 'year', 'month', 'feed' );
1263 function getRedirect( $subpage ) {
1264 return SpecialPage
::getTitleFor( 'Contributions', $this->getUser()->getName() );
1269 * Redirect to Special:Listfiles?user=$wgUser
1271 class SpecialMyuploads
extends RedirectSpecialPage
{
1272 function __construct() {
1273 parent
::__construct( 'Myuploads' );
1274 $this->mAllowedRedirectParams
= array( 'limit' );
1277 function getRedirect( $subpage ) {
1278 return SpecialPage
::getTitleFor( 'Listfiles', $this->getUser()->getName() );
1283 * Redirect from Special:PermanentLink/### to index.php?oldid=###
1285 class SpecialPermanentLink
extends RedirectSpecialPage
{
1286 function __construct() {
1287 parent
::__construct( 'PermanentLink' );
1288 $this->mAllowedRedirectParams
= array();
1291 function getRedirect( $subpage ) {
1292 $subpage = intval( $subpage );
1293 if ( $subpage === 0 ) {
1294 # throw an error page when no subpage was given
1295 throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
1297 $this->mAddedRedirectParams
['oldid'] = $subpage;