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 * @throws MWException
258 * @return Title object
260 public static function getTitleFor( $name, $subpage = false ) {
261 $name = SpecialPageFactory
::getLocalNameFor( $name, $subpage );
263 return Title
::makeTitle( NS_SPECIAL
, $name );
265 throw new MWException( "Invalid special page name \"$name\"" );
270 * Get a localised Title object for a page name with a possibly unvalidated subpage
272 * @param $name String
273 * @param $subpage String|Bool subpage string, or false to not use a subpage
274 * @return Title object or null if the page doesn't exist
276 public static function getSafeTitleFor( $name, $subpage = false ) {
277 $name = SpecialPageFactory
::getLocalNameFor( $name, $subpage );
279 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
286 * Get a title for a given alias
288 * @param $alias String
289 * @return Title or null if there is no such alias
290 * @deprecated since 1.18 call SpecialPageFactory method directly
292 static function getTitleForAlias( $alias ) {
293 wfDeprecated( __METHOD__
, '1.18' );
294 return SpecialPageFactory
::getTitleForAlias( $alias );
298 * Default constructor for special pages
299 * Derivative classes should call this from their constructor
300 * Note that if the user does not have the required level, an error message will
301 * be displayed by the default execute() method, without the global function ever
304 * If you override execute(), you can recover the default behaviour with userCanExecute()
305 * and displayRestrictionError()
307 * @param $name String: name of the special page, as seen in links and URLs
308 * @param $restriction String: user right required, e.g. "block" or "delete"
309 * @param $listed Bool: whether the page is listed in Special:Specialpages
310 * @param $function Callback|Bool: function called by execute(). By default it is constructed from $name
311 * @param $file String: file which is included by execute(). It is also constructed from $name by default
312 * @param $includable Bool: whether the page can be included in normal pages
314 public function __construct(
315 $name = '', $restriction = '', $listed = true,
316 $function = false, $file = 'default', $includable = false
318 $this->init( $name, $restriction, $listed, $function, $file, $includable );
322 * Do the real work for the constructor, mainly so __call() can intercept
323 * calls to SpecialPage()
324 * @param $name String: name of the special page, as seen in links and URLs
325 * @param $restriction String: user right required, e.g. "block" or "delete"
326 * @param $listed Bool: whether the page is listed in Special:Specialpages
327 * @param $function Callback|Bool: function called by execute(). By default it is constructed from $name
328 * @param $file String: file which is included by execute(). It is also constructed from $name by default
329 * @param $includable Bool: whether the page can be included in normal pages
331 private function init( $name, $restriction, $listed, $function, $file, $includable ) {
332 $this->mName
= $name;
333 $this->mRestriction
= $restriction;
334 $this->mListed
= $listed;
335 $this->mIncludable
= $includable;
337 $this->mFunction
= 'wfSpecial' . $name;
339 $this->mFunction
= $function;
341 if ( $file === 'default' ) {
342 $this->mFile
= __DIR__
. "/specials/Special$name.php";
344 $this->mFile
= $file;
349 * Use PHP's magic __call handler to get calls to the old PHP4 constructor
350 * because PHP E_STRICT yells at you for having __construct() and SpecialPage()
352 * @param $fName String Name of called method
353 * @param $a Array Arguments to the method
354 * @throws MWException
355 * @deprecated since 1.17, call parent::__construct()
357 public function __call( $fName, $a ) {
358 // Deprecated messages now, remove in 1.19 or 1.20?
359 wfDeprecated( __METHOD__
, '1.17' );
361 // Sometimes $fName is SpecialPage, sometimes it's specialpage. <3 PHP
362 if ( strtolower( $fName ) == 'specialpage' ) {
363 $name = isset( $a[0] ) ?
$a[0] : '';
364 $restriction = isset( $a[1] ) ?
$a[1] : '';
365 $listed = isset( $a[2] ) ?
$a[2] : true;
366 $function = isset( $a[3] ) ?
$a[3] : false;
367 $file = isset( $a[4] ) ?
$a[4] : 'default';
368 $includable = isset( $a[5] ) ?
$a[5] : false;
369 $this->init( $name, $restriction, $listed, $function, $file, $includable );
371 $className = get_class( $this );
372 throw new MWException( "Call to undefined method $className::$fName" );
377 * Get the name of this Special Page.
385 * Get the permission that a user must have to execute this page
388 function getRestriction() {
389 return $this->mRestriction
;
393 * Get the file which will be included by SpecialPage::execute() if your extension is
394 * still stuck in the past and hasn't overridden the execute() method. No modern code
395 * should want or need to know this.
397 * @deprecated since 1.18
400 wfDeprecated( __METHOD__
, '1.18' );
404 // @todo FIXME: Decide which syntax to use for this, and stick to it
406 * Whether this special page is listed in Special:SpecialPages
407 * @since r3583 (v1.3)
410 function isListed() {
411 return $this->mListed
;
414 * Set whether this page is listed in Special:Specialpages, at run-time
415 * @since r3583 (v1.3)
416 * @param $listed Bool
419 function setListed( $listed ) {
420 return wfSetVar( $this->mListed
, $listed );
423 * Get or set whether this special page is listed in Special:SpecialPages
424 * @since r11308 (v1.6)
428 function listed( $x = null ) {
429 return wfSetVar( $this->mListed
, $x );
433 * Whether it's allowed to transclude the special page via {{Special:Foo/params}}
436 public function isIncludable() {
437 return $this->mIncludable
;
441 * These mutators are very evil, as the relevant variables should not mutate. So
445 * @deprecated since 1.18
447 function name( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mName
, $x ); }
450 * These mutators are very evil, as the relevant variables should not mutate. So
454 * @deprecated since 1.18
456 function restriction( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mRestriction
, $x ); }
459 * These mutators are very evil, as the relevant variables should not mutate. So
463 * @deprecated since 1.18
465 function func( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mFunction
, $x ); }
468 * These mutators are very evil, as the relevant variables should not mutate. So
472 * @deprecated since 1.18
474 function file( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mFile
, $x ); }
477 * These mutators are very evil, as the relevant variables should not mutate. So
481 * @deprecated since 1.18
483 function includable( $x = null ) { wfDeprecated( __METHOD__
, '1.18' ); return wfSetVar( $this->mIncludable
, $x ); }
486 * Whether the special page is being evaluated via transclusion
490 function including( $x = null ) {
491 return wfSetVar( $this->mIncluding
, $x );
495 * Get the localised name of the special page
497 function getLocalName() {
498 if ( !isset( $this->mLocalName
) ) {
499 $this->mLocalName
= SpecialPageFactory
::getLocalNameFor( $this->mName
);
501 return $this->mLocalName
;
505 * Is this page expensive (for some definition of expensive)?
506 * Expensive pages are disabled or cached in miser mode. Originally used
507 * (and still overridden) by QueryPage and subclasses, moved here so that
508 * Special:SpecialPages can safely call it for all special pages.
512 public function isExpensive() {
517 * Can be overridden by subclasses with more complicated permissions
520 * @return Boolean: should the page be displayed with the restricted-access
523 public function isRestricted() {
524 // DWIM: If all anons can do something, then it is not restricted
525 return $this->mRestriction
!= '' && User
::groupHasPermission( '*', $this->mRestriction
);
529 * Checks if the given user (identified by an object) can execute this
530 * special page (as defined by $mRestriction). Can be overridden by sub-
531 * classes with more complicated permissions schemes.
533 * @param $user User: the user to check
534 * @return Boolean: does the user have permission to view the page?
536 public function userCanExecute( User
$user ) {
537 return $user->isAllowed( $this->mRestriction
);
541 * Output an error message telling the user what access level they have to have
543 function displayRestrictionError() {
544 throw new PermissionsError( $this->mRestriction
);
548 * Checks if userCanExecute, and if not throws a PermissionsError
552 public function checkPermissions() {
553 if ( !$this->userCanExecute( $this->getUser() ) ) {
554 $this->displayRestrictionError();
559 * If the wiki is currently in readonly mode, throws a ReadOnlyError
562 * @throws ReadOnlyError
564 public function checkReadOnly() {
565 if ( wfReadOnly() ) {
566 throw new ReadOnlyError
;
571 * Sets headers - this should be called from the execute() method of all derived classes!
573 function setHeaders() {
574 $out = $this->getOutput();
575 $out->setArticleRelated( false );
576 $out->setRobotPolicy( "noindex,nofollow" );
577 $out->setPageTitle( $this->getDescription() );
585 * @param $subPage string|null
587 public final function run( $subPage ) {
589 * Gets called before @see SpecialPage::execute.
593 * @param $special SpecialPage
594 * @param $subPage string|null
596 wfRunHooks( 'SpecialPageBeforeExecute', array( $this, $subPage ) );
598 $this->beforeExecute( $subPage );
599 $this->execute( $subPage );
600 $this->afterExecute( $subPage );
603 * Gets called after @see SpecialPage::execute.
607 * @param $special SpecialPage
608 * @param $subPage string|null
610 wfRunHooks( 'SpecialPageAfterExecute', array( $this, $subPage ) );
614 * Gets called before @see SpecialPage::execute.
618 * @param $subPage string|null
620 protected function beforeExecute( $subPage ) {
625 * Gets called after @see SpecialPage::execute.
629 * @param $subPage string|null
631 protected function afterExecute( $subPage ) {
636 * Default execute method
637 * Checks user permissions, calls the function given in mFunction
639 * This must be overridden by subclasses; it will be made abstract in a future version
641 * @param $subPage string|null
643 public function execute( $subPage ) {
645 $this->checkPermissions();
647 $func = $this->mFunction
;
648 // only load file if the function does not exist
649 if ( !is_callable( $func ) && $this->mFile
) {
650 require_once( $this->mFile
);
652 $this->outputHeader();
653 call_user_func( $func, $subPage, $this );
657 * Outputs a summary message on top of special pages
658 * Per default the message key is the canonical name of the special page
659 * May be overriden, i.e. by extensions to stick with the naming conventions
660 * for message keys: 'extensionname-xxx'
662 * @param $summaryMessageKey String: message key of the summary
664 function outputHeader( $summaryMessageKey = '' ) {
667 if ( $summaryMessageKey == '' ) {
668 $msg = $wgContLang->lc( $this->getName() ) . '-summary';
670 $msg = $summaryMessageKey;
672 if ( !$this->msg( $msg )->isDisabled() && !$this->including() ) {
673 $this->getOutput()->wrapWikiMsg(
674 "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
680 * Returns the name that goes in the \<h1\> in the special page itself, and
681 * also the name that will be listed in Special:Specialpages
683 * Derived classes can override this, but usually it is easier to keep the
684 * default behaviour. Messages can be added at run-time, see
689 function getDescription() {
690 return $this->msg( strtolower( $this->mName
) )->text();
694 * Get a self-referential title object
696 * @param $subpage String|Bool
697 * @return Title object
699 function getTitle( $subpage = false ) {
700 return self
::getTitleFor( $this->mName
, $subpage );
704 * Sets the context this SpecialPage is executed in
706 * @param $context IContextSource
709 public function setContext( $context ) {
710 $this->mContext
= $context;
714 * Gets the context this SpecialPage is executed in
716 * @return IContextSource|RequestContext
719 public function getContext() {
720 if ( $this->mContext
instanceof IContextSource
) {
721 return $this->mContext
;
723 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
724 return RequestContext
::getMain();
729 * Get the WebRequest being used for this instance
734 public function getRequest() {
735 return $this->getContext()->getRequest();
739 * Get the OutputPage being used for this instance
744 public function getOutput() {
745 return $this->getContext()->getOutput();
749 * Shortcut to get the User executing this instance
754 public function getUser() {
755 return $this->getContext()->getUser();
759 * Shortcut to get the skin being used for this instance
764 public function getSkin() {
765 return $this->getContext()->getSkin();
769 * Shortcut to get user's language
771 * @deprecated 1.19 Use getLanguage instead
775 public function getLang() {
776 wfDeprecated( __METHOD__
, '1.19' );
777 return $this->getLanguage();
781 * Shortcut to get user's language
786 public function getLanguage() {
787 return $this->getContext()->getLanguage();
791 * Return the full title, including $par
796 public function getFullTitle() {
797 return $this->getContext()->getTitle();
801 * Wrapper around wfMessage that sets the current context.
806 public function msg( /* $args */ ) {
807 // Note: can't use func_get_args() directly as second or later item in
808 // a parameter list until PHP 5.3 or you get a fatal error.
809 // Works fine as the first parameter, which appears elsewhere in the
810 // code base. Sighhhh.
811 $args = func_get_args();
812 $message = call_user_func_array( array( $this->getContext(), 'msg' ), $args );
813 // RequestContext passes context to wfMessage, and the language is set from
814 // the context, but setting the language for Message class removes the
815 // interface message status, which breaks for example usernameless gender
816 // invokations. Restore the flag when not including special page in content.
817 if ( $this->including() ) {
818 $message->setInterfaceMessageFlag( false );
824 * Adds RSS/atom links
826 * @param $params array
828 protected function addFeedLinks( $params ) {
829 global $wgFeedClasses;
831 $feedTemplate = wfScript( 'api' ) . '?';
833 foreach ( $wgFeedClasses as $format => $class ) {
834 $theseParams = $params +
array( 'feedformat' => $format );
835 $url = $feedTemplate . wfArrayToCGI( $theseParams );
836 $this->getOutput()->addFeedLink( $format, $url );
842 * Special page which uses an HTMLForm to handle processing. This is mostly a
843 * clone of FormAction. More special pages should be built this way; maybe this could be
844 * a new structure for SpecialPages
846 abstract class FormSpecialPage
extends SpecialPage
{
849 * Get an HTMLForm descriptor array
852 protected abstract function getFormFields();
855 * Add pre- or post-text to the form
856 * @return String HTML which will be sent to $form->addPreText()
858 protected function preText() { return ''; }
859 protected function postText() { return ''; }
862 * Play with the HTMLForm if you need to more substantially
863 * @param $form HTMLForm
865 protected function alterForm( HTMLForm
$form ) {}
868 * Get the HTMLForm to control behaviour
869 * @return HTMLForm|null
871 protected function getForm() {
872 $this->fields
= $this->getFormFields();
874 $form = new HTMLForm( $this->fields
, $this->getContext() );
875 $form->setSubmitCallback( array( $this, 'onSubmit' ) );
876 $form->setWrapperLegend( $this->msg( strtolower( $this->getName() ) . '-legend' ) );
877 $form->addHeaderText(
878 $this->msg( strtolower( $this->getName() ) . '-text' )->parseAsBlock() );
880 // Retain query parameters (uselang etc)
881 $params = array_diff_key(
882 $this->getRequest()->getQueryValues(), array( 'title' => null ) );
883 $form->addHiddenField( 'redirectparams', wfArrayToCGI( $params ) );
885 $form->addPreText( $this->preText() );
886 $form->addPostText( $this->postText() );
887 $this->alterForm( $form );
889 // Give hooks a chance to alter the form, adding extra fields or text etc
890 wfRunHooks( "Special{$this->getName()}BeforeFormDisplay", array( &$form ) );
896 * Process the form on POST submission.
898 * @return Bool|Array true for success, false for didn't-try, array of errors on failure
900 public abstract function onSubmit( array $data );
903 * Do something exciting on successful processing of the form, most likely to show a
904 * confirmation message
906 public abstract function onSuccess();
909 * Basic SpecialPage workflow: get a form, send it to the user; get some data back,
911 * @param $par String Subpage string if one was specified
913 public function execute( $par ) {
914 $this->setParameter( $par );
917 // This will throw exceptions if there's a problem
918 $this->checkExecutePermissions( $this->getUser() );
920 $form = $this->getForm();
921 if ( $form->show() ) {
927 * Maybe do something interesting with the subpage parameter
930 protected function setParameter( $par ) {}
933 * Called from execute() to check if the given user can perform this action.
934 * Failures here must throw subclasses of ErrorPageError.
936 * @throws UserBlockedError
939 protected function checkExecutePermissions( User
$user ) {
940 $this->checkPermissions();
942 if ( $this->requiresUnblock() && $user->isBlocked() ) {
943 $block = $user->getBlock();
944 throw new UserBlockedError( $block );
947 if ( $this->requiresWrite() ) {
948 $this->checkReadOnly();
955 * Whether this action requires the wiki not to be locked
958 public function requiresWrite() {
963 * Whether this action cannot be executed by a blocked user
966 public function requiresUnblock() {
972 * Shortcut to construct a special page which is unlisted by default
973 * @ingroup SpecialPage
975 class UnlistedSpecialPage
extends SpecialPage
{
976 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
977 parent
::__construct( $name, $restriction, false, $function, $file );
980 public function isListed() {
986 * Shortcut to construct an includable special page
987 * @ingroup SpecialPage
989 class IncludableSpecialPage
extends SpecialPage
{
990 function __construct(
991 $name, $restriction = '', $listed = true, $function = false, $file = 'default'
993 parent
::__construct( $name, $restriction, $listed, $function, $file, true );
996 public function isIncludable() {
1002 * Shortcut to construct a special page alias.
1003 * @ingroup SpecialPage
1005 abstract class RedirectSpecialPage
extends UnlistedSpecialPage
{
1007 // Query parameters that can be passed through redirects
1008 protected $mAllowedRedirectParams = array();
1010 // Query parameteres added by redirects
1011 protected $mAddedRedirectParams = array();
1013 public function execute( $par ) {
1014 $redirect = $this->getRedirect( $par );
1015 $query = $this->getRedirectQuery();
1016 // Redirect to a page title with possible query parameters
1017 if ( $redirect instanceof Title
) {
1018 $url = $redirect->getFullUrl( $query );
1019 $this->getOutput()->redirect( $url );
1020 wfProfileOut( __METHOD__
);
1022 // Redirect to index.php with query parameters
1023 } elseif ( $redirect === true ) {
1025 $url = $wgScript . '?' . wfArrayToCGI( $query );
1026 $this->getOutput()->redirect( $url );
1027 wfProfileOut( __METHOD__
);
1031 throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
1036 * If the special page is a redirect, then get the Title object it redirects to.
1039 * @param $par String Subpage string
1040 * @return Title|bool
1042 abstract public function getRedirect( $par );
1045 * Return part of the request string for a special redirect page
1046 * This allows passing, e.g. action=history to Special:Mypage, etc.
1050 public function getRedirectQuery() {
1053 foreach ( $this->mAllowedRedirectParams
as $arg ) {
1054 if ( $this->getRequest()->getVal( $arg, null ) !== null ) {
1055 $params[$arg] = $this->getRequest()->getVal( $arg );
1059 foreach ( $this->mAddedRedirectParams
as $arg => $val ) {
1060 $params[$arg] = $val;
1063 return count( $params )
1069 abstract class SpecialRedirectToSpecial
extends RedirectSpecialPage
{
1070 var $redirName, $redirSubpage;
1072 function __construct(
1073 $name, $redirName, $redirSubpage = false,
1074 $allowedRedirectParams = array(), $addedRedirectParams = array()
1076 parent
::__construct( $name );
1077 $this->redirName
= $redirName;
1078 $this->redirSubpage
= $redirSubpage;
1079 $this->mAllowedRedirectParams
= $allowedRedirectParams;
1080 $this->mAddedRedirectParams
= $addedRedirectParams;
1083 public function getRedirect( $subpage ) {
1084 if ( $this->redirSubpage
=== false ) {
1085 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
1087 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
1093 * ListAdmins --> ListUsers/sysop
1095 class SpecialListAdmins
extends SpecialRedirectToSpecial
{
1096 function __construct() {
1097 parent
::__construct( 'Listadmins', 'Listusers', 'sysop' );
1102 * ListBots --> ListUsers/bot
1104 class SpecialListBots
extends SpecialRedirectToSpecial
{
1105 function __construct() {
1106 parent
::__construct( 'Listbots', 'Listusers', 'bot' );
1111 * CreateAccount --> UserLogin/signup
1112 * @todo FIXME: This (and the rest of the login frontend) needs to die a horrible painful death
1114 class SpecialCreateAccount
extends SpecialRedirectToSpecial
{
1115 function __construct() {
1116 parent
::__construct( 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) );
1120 * SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
1121 * are used to get user independant links pointing to the user page, talk
1122 * page and list of contributions.
1123 * This can let us cache a single copy of any generated content for all
1128 * Superclass for any RedirectSpecialPage which redirects the user
1129 * to a particular article (as opposed to user contributions, logs, etc.).
1131 * For security reasons these special pages are restricted to pass on
1132 * the following subset of GET parameters to the target page while
1133 * removing all others:
1135 * - useskin, uselang, printable: to alter the appearance of the resulting page
1137 * - redirect: allows viewing one's user page or talk page even if it is a
1140 * - rdfrom: allows redirecting to one's user page or talk page from an
1141 * external wiki with the "Redirect from..." notice.
1143 * - limit, offset: Useful for linking to history of one's own user page or
1144 * user talk page. For example, this would be a link to "the last edit to your
1145 * user talk page in the year 2010":
1146 * http://en.wikipedia.org/w/index.php?title=Special:MyPage&offset=20110000000000&limit=1&action=history
1148 * - feed: would allow linking to the current user's RSS feed for their user
1150 * http://en.wikipedia.org/w/index.php?title=Special:MyTalk&action=history&feed=rss
1152 * - preloadtitle: Can be used to provide a default section title for a
1153 * preloaded new comment on one's own talk page.
1155 * - summary : Can be used to provide a default edit summary for a preloaded
1156 * edit to one's own user page or talk page.
1158 * - preview: Allows showing/hiding preview on first edit regardless of user
1159 * preference, useful for preloaded edits where you know preview wouldn't be
1162 * - internaledit, externaledit, mode: Allows forcing the use of the
1163 * internal/external editor, e.g. to force the internal editor for
1164 * short/simple preloaded edits.
1166 * - redlink: Affects the message the user sees if their talk page/user talk
1167 * page does not currently exist. Avoids confusion for newbies with no user
1168 * pages over why they got a "permission error" following this link:
1169 * http://en.wikipedia.org/w/index.php?title=Special:MyPage&redlink=1
1171 * - debug: determines whether the debug parameter is passed to load.php,
1172 * which disables reformatting and allows scripts to be debugged. Useful
1173 * when debugging scripts that manipulate one's own user page or talk page.
1175 * @par Hook extension:
1176 * Extensions can add to the redirect parameters list by using the hook
1177 * RedirectSpecialArticleRedirectParams
1179 * This hook allows extensions which add GET parameters like FlaggedRevs to
1180 * retain those parameters when redirecting using special pages.
1182 * @par Hook extension example:
1184 * $wgHooks['RedirectSpecialArticleRedirectParams'][] =
1185 * 'MyExtensionHooks::onRedirectSpecialArticleRedirectParams';
1186 * public static function onRedirectSpecialArticleRedirectParams( &$redirectParams ) {
1187 * $redirectParams[] = 'stable';
1191 * @ingroup SpecialPage
1193 abstract class RedirectSpecialArticle
extends RedirectSpecialPage
{
1194 function __construct( $name ) {
1195 parent
::__construct( $name );
1196 $redirectParams = array(
1198 'redirect', 'rdfrom',
1199 # Options for preloaded edits
1200 'preload', 'editintro', 'preloadtitle', 'summary',
1201 # Options for overriding user settings
1202 'preview', 'internaledit', 'externaledit', 'mode',
1203 # Options for history/diffs
1204 'section', 'oldid', 'diff', 'dir',
1205 'limit', 'offset', 'feed',
1208 # Options for action=raw; missing ctype can break JS or CSS in some browsers
1209 'ctype', 'maxage', 'smaxage',
1212 wfRunHooks( "RedirectSpecialArticleRedirectParams", array(&$redirectParams) );
1213 $this->mAllowedRedirectParams
= $redirectParams;
1218 * Shortcut to construct a special page pointing to current user user's page.
1219 * @ingroup SpecialPage
1221 class SpecialMypage
extends RedirectSpecialArticle
{
1222 function __construct() {
1223 parent
::__construct( 'Mypage' );
1226 function getRedirect( $subpage ) {
1227 if ( strval( $subpage ) !== '' ) {
1228 return Title
::makeTitle( NS_USER
, $this->getUser()->getName() . '/' . $subpage );
1230 return Title
::makeTitle( NS_USER
, $this->getUser()->getName() );
1236 * Shortcut to construct a special page pointing to current user talk page.
1237 * @ingroup SpecialPage
1239 class SpecialMytalk
extends RedirectSpecialArticle
{
1240 function __construct() {
1241 parent
::__construct( 'Mytalk' );
1244 function getRedirect( $subpage ) {
1245 if ( strval( $subpage ) !== '' ) {
1246 return Title
::makeTitle( NS_USER_TALK
, $this->getUser()->getName() . '/' . $subpage );
1248 return Title
::makeTitle( NS_USER_TALK
, $this->getUser()->getName() );
1254 * Shortcut to construct a special page pointing to current user contributions.
1255 * @ingroup SpecialPage
1257 class SpecialMycontributions
extends RedirectSpecialPage
{
1258 function __construct() {
1259 parent
::__construct( 'Mycontributions' );
1260 $this->mAllowedRedirectParams
= array( 'limit', 'namespace', 'tagfilter',
1261 'offset', 'dir', 'year', 'month', 'feed' );
1264 function getRedirect( $subpage ) {
1265 return SpecialPage
::getTitleFor( 'Contributions', $this->getUser()->getName() );
1270 * Redirect to Special:Listfiles?user=$wgUser
1272 class SpecialMyuploads
extends RedirectSpecialPage
{
1273 function __construct() {
1274 parent
::__construct( 'Myuploads' );
1275 $this->mAllowedRedirectParams
= array( 'limit' );
1278 function getRedirect( $subpage ) {
1279 return SpecialPage
::getTitleFor( 'Listfiles', $this->getUser()->getName() );
1284 * Redirect from Special:PermanentLink/### to index.php?oldid=###
1286 class SpecialPermanentLink
extends RedirectSpecialPage
{
1287 function __construct() {
1288 parent
::__construct( 'PermanentLink' );
1289 $this->mAllowedRedirectParams
= array();
1292 function getRedirect( $subpage ) {
1293 $subpage = intval( $subpage );
1294 if ( $subpage === 0 ) {
1295 # throw an error page when no subpage was given
1296 throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
1298 $this->mAddedRedirectParams
['oldid'] = $subpage;