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
30 // The canonical name of this special page
31 // Also used for the default <h1> heading, @see getDescription()
34 // The local name of this special page
37 // Minimum user level required to access this page, or "" for anyone.
38 // Also used to categorise the pages in Special:Specialpages
39 private $mRestriction;
41 // Listed in Special:Specialpages?
44 // Function name called by the default execute()
47 // File which needs to be included before the function above can be called
50 // Whether or not this special page is being included from an article
51 protected $mIncluding;
53 // Whether the special page can be included in an article
54 protected $mIncludable;
57 * Current request context
63 * Initialise the special page list
64 * This must be called before accessing SpecialPage::$mList
65 * @deprecated since 1.18
67 static function initList() {
68 wfDeprecated( __METHOD__
, '1.18' );
73 * @deprecated since 1.18
75 static function initAliasList() {
76 wfDeprecated( __METHOD__
, '1.18' );
81 * Given a special page alias, return the special page name.
82 * Returns false if there is no such alias.
84 * @param $alias String
85 * @return String or false
86 * @deprecated since 1.18 call SpecialPageFactory method directly
88 static function resolveAlias( $alias ) {
89 wfDeprecated( __METHOD__
, '1.18' );
90 list( $name, /*...*/ ) = SpecialPageFactory
::resolveAlias( $alias );
95 * Given a special page name with a possible subpage, return an array
96 * where the first element is the special page name and the second is the
99 * @param $alias String
101 * @deprecated since 1.18 call SpecialPageFactory method directly
103 static function resolveAliasWithSubpage( $alias ) {
104 return SpecialPageFactory
::resolveAlias( $alias );
108 * Add a page to a certain display group for Special:SpecialPages
110 * @param $page Mixed: SpecialPage or string
111 * @param $group String
112 * @deprecated since 1.18 call SpecialPageFactory method directly
114 static function setGroup( $page, $group ) {
115 wfDeprecated( __METHOD__
, '1.18' );
116 SpecialPageFactory
::setGroup( $page, $group );
120 * Get the group that the special page belongs in on Special:SpecialPage
122 * @param $page SpecialPage
124 * @deprecated since 1.18 call SpecialPageFactory method directly
126 static function getGroup( &$page ) {
127 wfDeprecated( __METHOD__
, '1.18' );
128 return SpecialPageFactory
::getGroup( $page );
132 * Remove a special page from the list
133 * Formerly used to disable expensive or dangerous special pages. The
134 * preferred method is now to add a SpecialPage_initList hook.
135 * @deprecated since 1.18
137 * @param string $name the page to remove
139 static function removePage( $name ) {
140 wfDeprecated( __METHOD__
, '1.18' );
141 unset( SpecialPageFactory
::getList()->$name );
145 * Check if a given name exist as a special page or as a special page alias
147 * @param string $name name of a special page
148 * @return Boolean: true if a special page exists with this name
149 * @deprecated since 1.18 call SpecialPageFactory method directly
151 static function exists( $name ) {
152 wfDeprecated( __METHOD__
, '1.18' );
153 return SpecialPageFactory
::exists( $name );
157 * Find the object with a given name and return it (or NULL)
159 * @param $name String
160 * @return SpecialPage object or null if the page doesn't exist
161 * @deprecated since 1.18 call SpecialPageFactory method directly
163 static function getPage( $name ) {
164 wfDeprecated( __METHOD__
, '1.18' );
165 return SpecialPageFactory
::getPage( $name );
169 * Get a special page with a given localised name, or NULL if there
170 * is no such special page.
172 * @param $alias String
173 * @return SpecialPage object or null if the page doesn't exist
174 * @deprecated since 1.18 call SpecialPageFactory method directly
176 static function getPageByAlias( $alias ) {
177 wfDeprecated( __METHOD__
, '1.18' );
178 return SpecialPageFactory
::getPage( $alias );
182 * Return categorised listable special pages which are available
183 * for the current user, and everyone.
185 * @param $user User object to check permissions, $wgUser will be used
187 * @return array Associative array mapping page's name to its SpecialPage object
188 * @deprecated since 1.18 call SpecialPageFactory method directly
190 static function getUsablePages( User
$user = null ) {
191 wfDeprecated( __METHOD__
, '1.18' );
192 return SpecialPageFactory
::getUsablePages( $user );
196 * Return categorised listable special pages for all users
198 * @return array Associative array mapping page's name to its SpecialPage object
199 * @deprecated since 1.18 call SpecialPageFactory method directly
201 static function getRegularPages() {
202 wfDeprecated( __METHOD__
, '1.18' );
203 return SpecialPageFactory
::getRegularPages();
207 * Return categorised listable special pages which are available
208 * for the current user, but not for everyone
210 * @return array Associative array mapping page's name to its SpecialPage object
211 * @deprecated since 1.18 call SpecialPageFactory method directly
213 static function getRestrictedPages() {
214 wfDeprecated( __METHOD__
, '1.18' );
215 return SpecialPageFactory
::getRestrictedPages();
219 * Execute a special page path.
220 * The path may contain parameters, e.g. Special:Name/Params
221 * Extracts the special page name and call the execute method, passing the parameters
223 * Returns a title object if the page is redirected, false if there was no such special
224 * page, and true if it was successful.
226 * @param $title Title object
227 * @param $context IContextSource
228 * @param $including Bool output is being captured for use in {{special:whatever}}
230 * @deprecated since 1.18 call SpecialPageFactory method directly
232 public static function executePath( &$title, IContextSource
&$context, $including = false ) {
233 wfDeprecated( __METHOD__
, '1.18' );
234 return SpecialPageFactory
::executePath( $title, $context, $including );
238 * Get the local name for a specified canonical name
240 * @param $name String
241 * @param $subpage Mixed: boolean false, or string
244 * @deprecated since 1.18 call SpecialPageFactory method directly
246 static function getLocalNameFor( $name, $subpage = false ) {
247 wfDeprecated( __METHOD__
, '1.18' );
248 return SpecialPageFactory
::getLocalNameFor( $name, $subpage );
252 * Get a localised Title object for a specified special page name
254 * @param $name String
255 * @param string|Bool $subpage subpage string, or false to not use a subpage
256 * @param string $fragment the link fragment (after the "#")
257 * @throws MWException
258 * @return Title object
260 public static function getTitleFor( $name, $subpage = false, $fragment = '' ) {
261 $name = SpecialPageFactory
::getLocalNameFor( $name, $subpage );
262 return Title
::makeTitle( NS_SPECIAL
, $name, $fragment );
266 * Get a localised Title object for a page name with a possibly unvalidated subpage
268 * @param $name String
269 * @param string|Bool $subpage subpage string, or false to not use a subpage
270 * @return Title object or null if the page doesn't exist
272 public static function getSafeTitleFor( $name, $subpage = false ) {
273 $name = SpecialPageFactory
::getLocalNameFor( $name, $subpage );
275 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
282 * Get a title for a given alias
284 * @param $alias String
285 * @return Title or null if there is no such alias
286 * @deprecated since 1.18 call SpecialPageFactory method directly
288 static function getTitleForAlias( $alias ) {
289 wfDeprecated( __METHOD__
, '1.18' );
290 return SpecialPageFactory
::getTitleForAlias( $alias );
294 * Default constructor for special pages
295 * Derivative classes should call this from their constructor
296 * Note that if the user does not have the required level, an error message will
297 * be displayed by the default execute() method, without the global function ever
300 * If you override execute(), you can recover the default behavior with userCanExecute()
301 * and displayRestrictionError()
303 * @param string $name Name of the special page, as seen in links and URLs
304 * @param string $restriction User right required, e.g. "block" or "delete"
305 * @param bool $listed Whether the page is listed in Special:Specialpages
306 * @param Callback|Bool $function Function called by execute(). By default
307 * it is constructed from $name
308 * @param string $file File which is included by execute(). It is also
309 * constructed from $name by default
310 * @param bool $includable Whether the page can be included in normal pages
312 public function __construct(
313 $name = '', $restriction = '', $listed = true,
314 $function = false, $file = 'default', $includable = false
316 $this->init( $name, $restriction, $listed, $function, $file, $includable );
320 * Do the real work for the constructor, mainly so __call() can intercept
321 * calls to SpecialPage()
322 * @param string $name Name of the special page, as seen in links and URLs
323 * @param string $restriction User right required, e.g. "block" or "delete"
324 * @param bool $listed Whether the page is listed in Special:Specialpages
325 * @param Callback|Bool $function Function called by execute(). By default
326 * it is constructed from $name
327 * @param string $file File which is included by execute(). It is also
328 * constructed from $name by default
329 * @param bool $includable 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 string $fName Name of called method
353 * @param array $a 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 ) {
448 wfDeprecated( __METHOD__
, '1.18' );
449 return wfSetVar( $this->mName
, $x );
453 * These mutators are very evil, as the relevant variables should not mutate. So
457 * @deprecated since 1.18
459 function restriction( $x = null ) {
460 wfDeprecated( __METHOD__
, '1.18' );
461 return wfSetVar( $this->mRestriction
, $x );
465 * These mutators are very evil, as the relevant variables should not mutate. So
469 * @deprecated since 1.18
471 function func( $x = null ) {
472 wfDeprecated( __METHOD__
, '1.18' );
473 return wfSetVar( $this->mFunction
, $x );
477 * These mutators are very evil, as the relevant variables should not mutate. So
481 * @deprecated since 1.18
483 function file( $x = null ) {
484 wfDeprecated( __METHOD__
, '1.18' );
485 return wfSetVar( $this->mFile
, $x );
489 * These mutators are very evil, as the relevant variables should not mutate. So
493 * @deprecated since 1.18
495 function includable( $x = null ) {
496 wfDeprecated( __METHOD__
, '1.18' );
497 return wfSetVar( $this->mIncludable
, $x );
501 * Whether the special page is being evaluated via transclusion
505 function including( $x = null ) {
506 return wfSetVar( $this->mIncluding
, $x );
510 * Get the localised name of the special page
512 function getLocalName() {
513 if ( !isset( $this->mLocalName
) ) {
514 $this->mLocalName
= SpecialPageFactory
::getLocalNameFor( $this->mName
);
516 return $this->mLocalName
;
520 * Is this page expensive (for some definition of expensive)?
521 * Expensive pages are disabled or cached in miser mode. Originally used
522 * (and still overridden) by QueryPage and subclasses, moved here so that
523 * Special:SpecialPages can safely call it for all special pages.
527 public function isExpensive() {
532 * Is this page cached?
533 * Expensive pages are cached or disabled in miser mode.
534 * Used by QueryPage and subclasses, moved here so that
535 * Special:SpecialPages can safely call it for all special pages.
540 public function isCached() {
545 * Can be overridden by subclasses with more complicated permissions
548 * @return Boolean: should the page be displayed with the restricted-access
551 public function isRestricted() {
552 // DWIM: If anons can do something, then it is not restricted
553 return $this->mRestriction
!= '' && !User
::groupHasPermission( '*', $this->mRestriction
);
557 * Checks if the given user (identified by an object) can execute this
558 * special page (as defined by $mRestriction). Can be overridden by sub-
559 * classes with more complicated permissions schemes.
561 * @param $user User: the user to check
562 * @return Boolean: does the user have permission to view the page?
564 public function userCanExecute( User
$user ) {
565 return $user->isAllowed( $this->mRestriction
);
569 * Output an error message telling the user what access level they have to have
571 function displayRestrictionError() {
572 throw new PermissionsError( $this->mRestriction
);
576 * Checks if userCanExecute, and if not throws a PermissionsError
580 public function checkPermissions() {
581 if ( !$this->userCanExecute( $this->getUser() ) ) {
582 $this->displayRestrictionError();
587 * If the wiki is currently in readonly mode, throws a ReadOnlyError
590 * @throws ReadOnlyError
592 public function checkReadOnly() {
593 if ( wfReadOnly() ) {
594 throw new ReadOnlyError
;
599 * Sets headers - this should be called from the execute() method of all derived classes!
601 function setHeaders() {
602 $out = $this->getOutput();
603 $out->setArticleRelated( false );
604 $out->setRobotPolicy( "noindex,nofollow" );
605 $out->setPageTitle( $this->getDescription() );
613 * @param $subPage string|null
615 final public function run( $subPage ) {
617 * Gets called before @see SpecialPage::execute.
621 * @param $special SpecialPage
622 * @param $subPage string|null
624 wfRunHooks( 'SpecialPageBeforeExecute', array( $this, $subPage ) );
626 $this->beforeExecute( $subPage );
627 $this->execute( $subPage );
628 $this->afterExecute( $subPage );
631 * Gets called after @see SpecialPage::execute.
635 * @param $special SpecialPage
636 * @param $subPage string|null
638 wfRunHooks( 'SpecialPageAfterExecute', array( $this, $subPage ) );
642 * Gets called before @see SpecialPage::execute.
646 * @param $subPage string|null
648 protected function beforeExecute( $subPage ) {
653 * Gets called after @see SpecialPage::execute.
657 * @param $subPage string|null
659 protected function afterExecute( $subPage ) {
664 * Default execute method
665 * Checks user permissions, calls the function given in mFunction
667 * This must be overridden by subclasses; it will be made abstract in a future version
669 * @param $subPage string|null
671 public function execute( $subPage ) {
673 $this->checkPermissions();
675 $func = $this->mFunction
;
676 // only load file if the function does not exist
677 if ( !is_callable( $func ) && $this->mFile
) {
678 require_once $this->mFile
;
680 $this->outputHeader();
681 call_user_func( $func, $subPage, $this );
685 * Outputs a summary message on top of special pages
686 * Per default the message key is the canonical name of the special page
687 * May be overridden, i.e. by extensions to stick with the naming conventions
688 * for message keys: 'extensionname-xxx'
690 * @param string $summaryMessageKey message key of the summary
692 function outputHeader( $summaryMessageKey = '' ) {
695 if ( $summaryMessageKey == '' ) {
696 $msg = $wgContLang->lc( $this->getName() ) . '-summary';
698 $msg = $summaryMessageKey;
700 if ( !$this->msg( $msg )->isDisabled() && !$this->including() ) {
701 $this->getOutput()->wrapWikiMsg(
702 "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
708 * Returns the name that goes in the \<h1\> in the special page itself, and
709 * also the name that will be listed in Special:Specialpages
711 * Derived classes can override this, but usually it is easier to keep the
712 * default behavior. Messages can be added at run-time, see
717 function getDescription() {
718 return $this->msg( strtolower( $this->mName
) )->text();
722 * Get a self-referential title object
724 * @param $subpage String|Bool
725 * @return Title object
727 function getTitle( $subpage = false ) {
728 return self
::getTitleFor( $this->mName
, $subpage );
732 * Sets the context this SpecialPage is executed in
734 * @param $context IContextSource
737 public function setContext( $context ) {
738 $this->mContext
= $context;
742 * Gets the context this SpecialPage is executed in
744 * @return IContextSource|RequestContext
747 public function getContext() {
748 if ( $this->mContext
instanceof IContextSource
) {
749 return $this->mContext
;
751 wfDebug( __METHOD__
. " called and \$mContext is null. " .
752 "Return RequestContext::getMain(); for sanity\n" );
753 return RequestContext
::getMain();
758 * Get the WebRequest being used for this instance
763 public function getRequest() {
764 return $this->getContext()->getRequest();
768 * Get the OutputPage being used for this instance
773 public function getOutput() {
774 return $this->getContext()->getOutput();
778 * Shortcut to get the User executing this instance
783 public function getUser() {
784 return $this->getContext()->getUser();
788 * Shortcut to get the skin being used for this instance
793 public function getSkin() {
794 return $this->getContext()->getSkin();
798 * Shortcut to get user's language
800 * @deprecated since 1.19 Use getLanguage instead
804 public function getLang() {
805 wfDeprecated( __METHOD__
, '1.19' );
806 return $this->getLanguage();
810 * Shortcut to get user's language
815 public function getLanguage() {
816 return $this->getContext()->getLanguage();
820 * Return the full title, including $par
825 public function getFullTitle() {
826 return $this->getContext()->getTitle();
830 * Wrapper around wfMessage that sets the current context.
835 public function msg( /* $args */ ) {
836 $message = call_user_func_array(
837 array( $this->getContext(), 'msg' ),
840 // RequestContext passes context to wfMessage, and the language is set from
841 // the context, but setting the language for Message class removes the
842 // interface message status, which breaks for example usernameless gender
843 // invocations. Restore the flag when not including special page in content.
844 if ( $this->including() ) {
845 $message->setInterfaceMessageFlag( false );
851 * Adds RSS/atom links
853 * @param $params array
855 protected function addFeedLinks( $params ) {
856 global $wgFeedClasses;
858 $feedTemplate = wfScript( 'api' );
860 foreach ( $wgFeedClasses as $format => $class ) {
861 $theseParams = $params +
array( 'feedformat' => $format );
862 $url = wfAppendQuery( $feedTemplate, $theseParams );
863 $this->getOutput()->addFeedLink( $format, $url );
868 * Get the group that the special page belongs in on Special:SpecialPage
869 * Use this method, instead of getGroupName to allow customization
870 * of the group name from the wiki side
872 * @return string Group of this special page
875 public function getFinalGroupName() {
876 global $wgSpecialPageGroups;
877 $name = $this->getName();
879 // Allow overbidding the group from the wiki side
880 $msg = $this->msg( 'specialpages-specialpagegroup-' . strtolower( $name ) )->inContentLanguage();
881 if ( !$msg->isBlank() ) {
882 $group = $msg->text();
884 // Than use the group from this object
885 $group = $this->getGroupName();
887 // Group '-' is used as default to have the chance to determine,
888 // if the special pages overrides this method,
889 // if not overridden, $wgSpecialPageGroups is checked for b/c
890 if ( $group === '-' && isset( $wgSpecialPageGroups[$name] ) ) {
891 $group = $wgSpecialPageGroups[$name];
895 // never give '-' back, change to 'other'
896 if ( $group === '-' ) {
904 * Under which header this special page is listed in Special:SpecialPages
905 * See messages 'specialpages-group-*' for valid names
906 * This method defaults to group 'other'
911 protected function getGroupName() {
912 // '-' used here to determine, if this group is overridden or has a hardcoded 'other'
913 // Needed for b/c in getFinalGroupName
919 * Special page which uses an HTMLForm to handle processing. This is mostly a
920 * clone of FormAction. More special pages should be built this way; maybe this could be
921 * a new structure for SpecialPages
923 abstract class FormSpecialPage
extends SpecialPage
{
925 * The sub-page of the special page.
928 protected $par = null;
931 * Get an HTMLForm descriptor array
934 abstract protected function getFormFields();
937 * Add pre-text to the form
938 * @return String HTML which will be sent to $form->addPreText()
940 protected function preText() {
945 * Add post-text to the form
946 * @return String HTML which will be sent to $form->addPostText()
948 protected function postText() {
953 * Play with the HTMLForm if you need to more substantially
954 * @param $form HTMLForm
956 protected function alterForm( HTMLForm
$form ) {
960 * Get message prefix for HTMLForm
965 protected function getMessagePrefix() {
966 return strtolower( $this->getName() );
970 * Get the HTMLForm to control behavior
971 * @return HTMLForm|null
973 protected function getForm() {
974 $this->fields
= $this->getFormFields();
976 $form = new HTMLForm( $this->fields
, $this->getContext(), $this->getMessagePrefix() );
977 $form->setSubmitCallback( array( $this, 'onSubmit' ) );
978 // If the form is a compact vertical form, then don't output this ugly
979 // fieldset surrounding it.
980 // XXX Special pages can setDisplayFormat to 'vform' in alterForm(), but that
981 // is called after this.
982 if ( !$form->isVForm() ) {
983 $form->setWrapperLegendMsg( $this->getMessagePrefix() . '-legend' );
986 $headerMsg = $this->msg( $this->getMessagePrefix() . '-text' );
987 if ( !$headerMsg->isDisabled() ) {
988 $form->addHeaderText( $headerMsg->parseAsBlock() );
991 // Retain query parameters (uselang etc)
992 $params = array_diff_key(
993 $this->getRequest()->getQueryValues(), array( 'title' => null ) );
994 $form->addHiddenField( 'redirectparams', wfArrayToCgi( $params ) );
996 $form->addPreText( $this->preText() );
997 $form->addPostText( $this->postText() );
998 $this->alterForm( $form );
1000 // Give hooks a chance to alter the form, adding extra fields or text etc
1001 wfRunHooks( "Special{$this->getName()}BeforeFormDisplay", array( &$form ) );
1007 * Process the form on POST submission.
1008 * @param $data Array
1009 * @return Bool|Array true for success, false for didn't-try, array of errors on failure
1011 abstract public function onSubmit( array $data );
1014 * Do something exciting on successful processing of the form, most likely to show a
1015 * confirmation message
1016 * @since 1.22 Default is to do nothing
1018 public function onSuccess() {
1022 * Basic SpecialPage workflow: get a form, send it to the user; get some data back,
1024 * @param string $par Subpage string if one was specified
1026 public function execute( $par ) {
1027 $this->setParameter( $par );
1028 $this->setHeaders();
1030 // This will throw exceptions if there's a problem
1031 $this->checkExecutePermissions( $this->getUser() );
1033 $form = $this->getForm();
1034 if ( $form->show() ) {
1040 * Maybe do something interesting with the subpage parameter
1041 * @param string $par
1043 protected function setParameter( $par ) {
1048 * Called from execute() to check if the given user can perform this action.
1049 * Failures here must throw subclasses of ErrorPageError.
1051 * @throws UserBlockedError
1054 protected function checkExecutePermissions( User
$user ) {
1055 $this->checkPermissions();
1057 if ( $this->requiresUnblock() && $user->isBlocked() ) {
1058 $block = $user->getBlock();
1059 throw new UserBlockedError( $block );
1062 if ( $this->requiresWrite() ) {
1063 $this->checkReadOnly();
1070 * Whether this action requires the wiki not to be locked
1073 public function requiresWrite() {
1078 * Whether this action cannot be executed by a blocked user
1081 public function requiresUnblock() {
1087 * Shortcut to construct a special page which is unlisted by default
1088 * @ingroup SpecialPage
1090 class UnlistedSpecialPage
extends SpecialPage
{
1091 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
1092 parent
::__construct( $name, $restriction, false, $function, $file );
1095 public function isListed() {
1101 * Shortcut to construct an includable special page
1102 * @ingroup SpecialPage
1104 class IncludableSpecialPage
extends SpecialPage
{
1105 function __construct(
1106 $name, $restriction = '', $listed = true, $function = false, $file = 'default'
1108 parent
::__construct( $name, $restriction, $listed, $function, $file, true );
1111 public function isIncludable() {
1117 * Shortcut to construct a special page alias.
1118 * @ingroup SpecialPage
1120 abstract class RedirectSpecialPage
extends UnlistedSpecialPage
{
1122 // Query parameters that can be passed through redirects
1123 protected $mAllowedRedirectParams = array();
1125 // Query parameters added by redirects
1126 protected $mAddedRedirectParams = array();
1128 public function execute( $par ) {
1129 $redirect = $this->getRedirect( $par );
1130 $query = $this->getRedirectQuery();
1131 // Redirect to a page title with possible query parameters
1132 if ( $redirect instanceof Title
) {
1133 $url = $redirect->getFullURL( $query );
1134 $this->getOutput()->redirect( $url );
1136 } elseif ( $redirect === true ) {
1137 // Redirect to index.php with query parameters
1138 $url = wfAppendQuery( wfScript( 'index' ), $query );
1139 $this->getOutput()->redirect( $url );
1142 $class = get_class( $this );
1143 throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
1148 * If the special page is a redirect, then get the Title object it redirects to.
1151 * @param string $par Subpage string
1152 * @return Title|bool
1154 abstract public function getRedirect( $par );
1157 * Return part of the request string for a special redirect page
1158 * This allows passing, e.g. action=history to Special:Mypage, etc.
1162 public function getRedirectQuery() {
1165 foreach ( $this->mAllowedRedirectParams
as $arg ) {
1166 if ( $this->getRequest()->getVal( $arg, null ) !== null ) {
1167 $params[$arg] = $this->getRequest()->getVal( $arg );
1171 foreach ( $this->mAddedRedirectParams
as $arg => $val ) {
1172 $params[$arg] = $val;
1175 return count( $params )
1181 abstract class SpecialRedirectToSpecial
extends RedirectSpecialPage
{
1182 // @todo FIXME: Visibility must be declared
1183 var $redirName, $redirSubpage;
1185 function __construct(
1186 $name, $redirName, $redirSubpage = false,
1187 $allowedRedirectParams = array(), $addedRedirectParams = array()
1189 parent
::__construct( $name );
1190 $this->redirName
= $redirName;
1191 $this->redirSubpage
= $redirSubpage;
1192 $this->mAllowedRedirectParams
= $allowedRedirectParams;
1193 $this->mAddedRedirectParams
= $addedRedirectParams;
1196 public function getRedirect( $subpage ) {
1197 if ( $this->redirSubpage
=== false ) {
1198 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
1200 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
1206 * ListAdmins --> ListUsers/sysop
1208 class SpecialListAdmins
extends SpecialRedirectToSpecial
{
1209 function __construct() {
1210 parent
::__construct( 'Listadmins', 'Listusers', 'sysop' );
1215 * ListBots --> ListUsers/bot
1217 class SpecialListBots
extends SpecialRedirectToSpecial
{
1218 function __construct() {
1219 parent
::__construct( 'Listbots', 'Listusers', 'bot' );
1224 * CreateAccount --> UserLogin/signup
1225 * @todo FIXME: This (and the rest of the login frontend) needs to die a horrible painful death
1227 class SpecialCreateAccount
extends SpecialRedirectToSpecial
{
1228 function __construct() {
1229 parent
::__construct( 'CreateAccount', 'Userlogin', 'signup', array( 'returnto', 'returntoquery', 'uselang' ) );
1232 // No reason to hide this link on Special:Specialpages
1233 public function isListed() {
1237 protected function getGroupName() {
1242 * SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
1243 * are used to get user independent links pointing to the user page, talk
1244 * page and list of contributions.
1245 * This can let us cache a single copy of any generated content for all
1250 * Superclass for any RedirectSpecialPage which redirects the user
1251 * to a particular article (as opposed to user contributions, logs, etc.).
1253 * For security reasons these special pages are restricted to pass on
1254 * the following subset of GET parameters to the target page while
1255 * removing all others:
1257 * - useskin, uselang, printable: to alter the appearance of the resulting page
1259 * - redirect: allows viewing one's user page or talk page even if it is a
1262 * - rdfrom: allows redirecting to one's user page or talk page from an
1263 * external wiki with the "Redirect from..." notice.
1265 * - limit, offset: Useful for linking to history of one's own user page or
1266 * user talk page. For example, this would be a link to "the last edit to your
1267 * user talk page in the year 2010":
1268 * http://en.wikipedia.org/wiki/Special:MyPage?offset=20110000000000&limit=1&action=history
1270 * - feed: would allow linking to the current user's RSS feed for their user
1272 * http://en.wikipedia.org/w/index.php?title=Special:MyTalk&action=history&feed=rss
1274 * - preloadtitle: Can be used to provide a default section title for a
1275 * preloaded new comment on one's own talk page.
1277 * - summary : Can be used to provide a default edit summary for a preloaded
1278 * edit to one's own user page or talk page.
1280 * - preview: Allows showing/hiding preview on first edit regardless of user
1281 * preference, useful for preloaded edits where you know preview wouldn't be
1284 * - internaledit, externaledit, mode: Allows forcing the use of the
1285 * internal/external editor, e.g. to force the internal editor for
1286 * short/simple preloaded edits.
1288 * - redlink: Affects the message the user sees if their talk page/user talk
1289 * page does not currently exist. Avoids confusion for newbies with no user
1290 * pages over why they got a "permission error" following this link:
1291 * http://en.wikipedia.org/w/index.php?title=Special:MyPage&redlink=1
1293 * - debug: determines whether the debug parameter is passed to load.php,
1294 * which disables reformatting and allows scripts to be debugged. Useful
1295 * when debugging scripts that manipulate one's own user page or talk page.
1297 * @par Hook extension:
1298 * Extensions can add to the redirect parameters list by using the hook
1299 * RedirectSpecialArticleRedirectParams
1301 * This hook allows extensions which add GET parameters like FlaggedRevs to
1302 * retain those parameters when redirecting using special pages.
1304 * @par Hook extension example:
1306 * $wgHooks['RedirectSpecialArticleRedirectParams'][] =
1307 * 'MyExtensionHooks::onRedirectSpecialArticleRedirectParams';
1308 * public static function onRedirectSpecialArticleRedirectParams( &$redirectParams ) {
1309 * $redirectParams[] = 'stable';
1313 * @ingroup SpecialPage
1315 abstract class RedirectSpecialArticle
extends RedirectSpecialPage
{
1316 function __construct( $name ) {
1317 parent
::__construct( $name );
1318 $redirectParams = array(
1320 'redirect', 'rdfrom',
1321 # Options for preloaded edits
1322 'preload', 'editintro', 'preloadtitle', 'summary', 'nosummary',
1323 # Options for overriding user settings
1324 'preview', 'internaledit', 'externaledit', 'mode', 'minor', 'watchthis',
1325 # Options for history/diffs
1326 'section', 'oldid', 'diff', 'dir',
1327 'limit', 'offset', 'feed',
1330 # Options for action=raw; missing ctype can break JS or CSS in some browsers
1331 'ctype', 'maxage', 'smaxage',
1334 wfRunHooks( "RedirectSpecialArticleRedirectParams", array( &$redirectParams ) );
1335 $this->mAllowedRedirectParams
= $redirectParams;
1340 * Shortcut to construct a special page pointing to current user user's page.
1341 * @ingroup SpecialPage
1343 class SpecialMypage
extends RedirectSpecialArticle
{
1344 function __construct() {
1345 parent
::__construct( 'Mypage' );
1348 function getRedirect( $subpage ) {
1349 if ( strval( $subpage ) !== '' ) {
1350 return Title
::makeTitle( NS_USER
, $this->getUser()->getName() . '/' . $subpage );
1352 return Title
::makeTitle( NS_USER
, $this->getUser()->getName() );
1358 * Shortcut to construct a special page pointing to current user talk page.
1359 * @ingroup SpecialPage
1361 class SpecialMytalk
extends RedirectSpecialArticle
{
1362 function __construct() {
1363 parent
::__construct( 'Mytalk' );
1366 function getRedirect( $subpage ) {
1367 if ( strval( $subpage ) !== '' ) {
1368 return Title
::makeTitle( NS_USER_TALK
, $this->getUser()->getName() . '/' . $subpage );
1370 return Title
::makeTitle( NS_USER_TALK
, $this->getUser()->getName() );
1376 * Shortcut to construct a special page pointing to current user contributions.
1377 * @ingroup SpecialPage
1379 class SpecialMycontributions
extends RedirectSpecialPage
{
1380 function __construct() {
1381 parent
::__construct( 'Mycontributions' );
1382 $this->mAllowedRedirectParams
= array( 'limit', 'namespace', 'tagfilter',
1383 'offset', 'dir', 'year', 'month', 'feed' );
1386 function getRedirect( $subpage ) {
1387 return SpecialPage
::getTitleFor( 'Contributions', $this->getUser()->getName() );
1392 * Redirect to Special:Listfiles?user=$wgUser
1394 class SpecialMyuploads
extends RedirectSpecialPage
{
1395 function __construct() {
1396 parent
::__construct( 'Myuploads' );
1397 $this->mAllowedRedirectParams
= array( 'limit', 'ilshowall', 'ilsearch' );
1400 function getRedirect( $subpage ) {
1401 return SpecialPage
::getTitleFor( 'Listfiles', $this->getUser()->getName() );
1406 * Redirect Special:Listfiles?user=$wgUser&ilshowall=true
1408 class SpecialAllMyUploads
extends RedirectSpecialPage
{
1409 function __construct() {
1410 parent
::__construct( 'AllMyUploads' );
1411 $this->mAllowedRedirectParams
= array( 'limit', 'ilsearch' );
1414 function getRedirect( $subpage ) {
1415 $this->mAddedRedirectParams
['ilshowall'] = 1;
1416 return SpecialPage
::getTitleFor( 'Listfiles', $this->getUser()->getName() );
1422 * Redirect from Special:PermanentLink/### to index.php?oldid=###
1424 class SpecialPermanentLink
extends RedirectSpecialPage
{
1425 function __construct() {
1426 parent
::__construct( 'PermanentLink' );
1427 $this->mAllowedRedirectParams
= array();
1430 function getRedirect( $subpage ) {
1431 $subpage = intval( $subpage );
1432 if ( $subpage === 0 ) {
1433 # throw an error page when no subpage was given
1434 throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
1436 $this->mAddedRedirectParams
['oldid'] = $subpage;