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 );
263 return Title
::makeTitle( NS_SPECIAL
, $name, $fragment );
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 string|Bool $subpage 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 behavior with userCanExecute()
305 * and displayRestrictionError()
307 * @param string $name Name of the special page, as seen in links and URLs
308 * @param string $restriction User right required, e.g. "block" or "delete"
309 * @param bool $listed Whether the page is listed in Special:Specialpages
310 * @param Callback|Bool $function Function called by execute(). By default
311 * it is constructed from $name
312 * @param string $file File which is included by execute(). It is also
313 * constructed from $name by default
314 * @param bool $includable Whether the page can be included in normal pages
316 public function __construct(
317 $name = '', $restriction = '', $listed = true,
318 $function = false, $file = 'default', $includable = false
320 $this->init( $name, $restriction, $listed, $function, $file, $includable );
324 * Do the real work for the constructor, mainly so __call() can intercept
325 * calls to SpecialPage()
326 * @param string $name Name of the special page, as seen in links and URLs
327 * @param string $restriction User right required, e.g. "block" or "delete"
328 * @param bool $listed Whether the page is listed in Special:Specialpages
329 * @param Callback|Bool $function Function called by execute(). By default
330 * it is constructed from $name
331 * @param string $file File which is included by execute(). It is also
332 * constructed from $name by default
333 * @param bool $includable Whether the page can be included in normal pages
335 private function init( $name, $restriction, $listed, $function, $file, $includable ) {
336 $this->mName
= $name;
337 $this->mRestriction
= $restriction;
338 $this->mListed
= $listed;
339 $this->mIncludable
= $includable;
341 $this->mFunction
= 'wfSpecial' . $name;
343 $this->mFunction
= $function;
345 if ( $file === 'default' ) {
346 $this->mFile
= __DIR__
. "/specials/Special$name.php";
348 $this->mFile
= $file;
353 * Use PHP's magic __call handler to get calls to the old PHP4 constructor
354 * because PHP E_STRICT yells at you for having __construct() and SpecialPage()
356 * @param string $fName Name of called method
357 * @param array $a Arguments to the method
358 * @throws MWException
359 * @deprecated since 1.17, call parent::__construct()
361 public function __call( $fName, $a ) {
362 // Deprecated messages now, remove in 1.19 or 1.20?
363 wfDeprecated( __METHOD__
, '1.17' );
365 // Sometimes $fName is SpecialPage, sometimes it's specialpage. <3 PHP
366 if ( strtolower( $fName ) == 'specialpage' ) {
367 $name = isset( $a[0] ) ?
$a[0] : '';
368 $restriction = isset( $a[1] ) ?
$a[1] : '';
369 $listed = isset( $a[2] ) ?
$a[2] : true;
370 $function = isset( $a[3] ) ?
$a[3] : false;
371 $file = isset( $a[4] ) ?
$a[4] : 'default';
372 $includable = isset( $a[5] ) ?
$a[5] : false;
373 $this->init( $name, $restriction, $listed, $function, $file, $includable );
375 $className = get_class( $this );
376 throw new MWException( "Call to undefined method $className::$fName" );
381 * Get the name of this Special Page.
389 * Get the permission that a user must have to execute this page
392 function getRestriction() {
393 return $this->mRestriction
;
397 * Get the file which will be included by SpecialPage::execute() if your extension is
398 * still stuck in the past and hasn't overridden the execute() method. No modern code
399 * should want or need to know this.
401 * @deprecated since 1.18
404 wfDeprecated( __METHOD__
, '1.18' );
408 // @todo FIXME: Decide which syntax to use for this, and stick to it
410 * Whether this special page is listed in Special:SpecialPages
411 * @since r3583 (v1.3)
414 function isListed() {
415 return $this->mListed
;
418 * Set whether this page is listed in Special:Specialpages, at run-time
419 * @since r3583 (v1.3)
420 * @param $listed Bool
423 function setListed( $listed ) {
424 return wfSetVar( $this->mListed
, $listed );
427 * Get or set whether this special page is listed in Special:SpecialPages
428 * @since r11308 (v1.6)
432 function listed( $x = null ) {
433 return wfSetVar( $this->mListed
, $x );
437 * Whether it's allowed to transclude the special page via {{Special:Foo/params}}
440 public function isIncludable() {
441 return $this->mIncludable
;
445 * These mutators are very evil, as the relevant variables should not mutate. So
449 * @deprecated since 1.18
451 function name( $x = null ) {
452 wfDeprecated( __METHOD__
, '1.18' );
453 return wfSetVar( $this->mName
, $x );
457 * These mutators are very evil, as the relevant variables should not mutate. So
461 * @deprecated since 1.18
463 function restriction( $x = null ) {
464 wfDeprecated( __METHOD__
, '1.18' );
465 return wfSetVar( $this->mRestriction
, $x );
469 * These mutators are very evil, as the relevant variables should not mutate. So
473 * @deprecated since 1.18
475 function func( $x = null ) {
476 wfDeprecated( __METHOD__
, '1.18' );
477 return wfSetVar( $this->mFunction
, $x );
481 * These mutators are very evil, as the relevant variables should not mutate. So
485 * @deprecated since 1.18
487 function file( $x = null ) {
488 wfDeprecated( __METHOD__
, '1.18' );
489 return wfSetVar( $this->mFile
, $x );
493 * These mutators are very evil, as the relevant variables should not mutate. So
497 * @deprecated since 1.18
499 function includable( $x = null ) {
500 wfDeprecated( __METHOD__
, '1.18' );
501 return wfSetVar( $this->mIncludable
, $x );
505 * Whether the special page is being evaluated via transclusion
509 function including( $x = null ) {
510 return wfSetVar( $this->mIncluding
, $x );
514 * Get the localised name of the special page
516 function getLocalName() {
517 if ( !isset( $this->mLocalName
) ) {
518 $this->mLocalName
= SpecialPageFactory
::getLocalNameFor( $this->mName
);
520 return $this->mLocalName
;
524 * Is this page expensive (for some definition of expensive)?
525 * Expensive pages are disabled or cached in miser mode. Originally used
526 * (and still overridden) by QueryPage and subclasses, moved here so that
527 * Special:SpecialPages can safely call it for all special pages.
531 public function isExpensive() {
536 * Is this page cached?
537 * Expensive pages are cached or disabled in miser mode.
538 * Used by QueryPage and subclasses, moved here so that
539 * Special:SpecialPages can safely call it for all special pages.
544 public function isCached() {
549 * Can be overridden by subclasses with more complicated permissions
552 * @return Boolean: should the page be displayed with the restricted-access
555 public function isRestricted() {
556 // DWIM: If anons can do something, then it is not restricted
557 return $this->mRestriction
!= '' && !User
::groupHasPermission( '*', $this->mRestriction
);
561 * Checks if the given user (identified by an object) can execute this
562 * special page (as defined by $mRestriction). Can be overridden by sub-
563 * classes with more complicated permissions schemes.
565 * @param $user User: the user to check
566 * @return Boolean: does the user have permission to view the page?
568 public function userCanExecute( User
$user ) {
569 return $user->isAllowed( $this->mRestriction
);
573 * Output an error message telling the user what access level they have to have
575 function displayRestrictionError() {
576 throw new PermissionsError( $this->mRestriction
);
580 * Checks if userCanExecute, and if not throws a PermissionsError
584 public function checkPermissions() {
585 if ( !$this->userCanExecute( $this->getUser() ) ) {
586 $this->displayRestrictionError();
591 * If the wiki is currently in readonly mode, throws a ReadOnlyError
594 * @throws ReadOnlyError
596 public function checkReadOnly() {
597 if ( wfReadOnly() ) {
598 throw new ReadOnlyError
;
603 * Sets headers - this should be called from the execute() method of all derived classes!
605 function setHeaders() {
606 $out = $this->getOutput();
607 $out->setArticleRelated( false );
608 $out->setRobotPolicy( "noindex,nofollow" );
609 $out->setPageTitle( $this->getDescription() );
617 * @param $subPage string|null
619 final public function run( $subPage ) {
621 * Gets called before @see SpecialPage::execute.
625 * @param $special SpecialPage
626 * @param $subPage string|null
628 wfRunHooks( 'SpecialPageBeforeExecute', array( $this, $subPage ) );
630 $this->beforeExecute( $subPage );
631 $this->execute( $subPage );
632 $this->afterExecute( $subPage );
635 * Gets called after @see SpecialPage::execute.
639 * @param $special SpecialPage
640 * @param $subPage string|null
642 wfRunHooks( 'SpecialPageAfterExecute', array( $this, $subPage ) );
646 * Gets called before @see SpecialPage::execute.
650 * @param $subPage string|null
652 protected function beforeExecute( $subPage ) {
657 * Gets called after @see SpecialPage::execute.
661 * @param $subPage string|null
663 protected function afterExecute( $subPage ) {
668 * Default execute method
669 * Checks user permissions, calls the function given in mFunction
671 * This must be overridden by subclasses; it will be made abstract in a future version
673 * @param $subPage string|null
675 public function execute( $subPage ) {
677 $this->checkPermissions();
679 $func = $this->mFunction
;
680 // only load file if the function does not exist
681 if ( !is_callable( $func ) && $this->mFile
) {
682 require_once $this->mFile
;
684 $this->outputHeader();
685 call_user_func( $func, $subPage, $this );
689 * Outputs a summary message on top of special pages
690 * Per default the message key is the canonical name of the special page
691 * May be overridden, i.e. by extensions to stick with the naming conventions
692 * for message keys: 'extensionname-xxx'
694 * @param string $summaryMessageKey message key of the summary
696 function outputHeader( $summaryMessageKey = '' ) {
699 if ( $summaryMessageKey == '' ) {
700 $msg = $wgContLang->lc( $this->getName() ) . '-summary';
702 $msg = $summaryMessageKey;
704 if ( !$this->msg( $msg )->isDisabled() && !$this->including() ) {
705 $this->getOutput()->wrapWikiMsg(
706 "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
712 * Returns the name that goes in the \<h1\> in the special page itself, and
713 * also the name that will be listed in Special:Specialpages
715 * Derived classes can override this, but usually it is easier to keep the
716 * default behavior. Messages can be added at run-time, see
721 function getDescription() {
722 return $this->msg( strtolower( $this->mName
) )->text();
726 * Get a self-referential title object
728 * @param $subpage String|Bool
729 * @return Title object
731 function getTitle( $subpage = false ) {
732 return self
::getTitleFor( $this->mName
, $subpage );
736 * Sets the context this SpecialPage is executed in
738 * @param $context IContextSource
741 public function setContext( $context ) {
742 $this->mContext
= $context;
746 * Gets the context this SpecialPage is executed in
748 * @return IContextSource|RequestContext
751 public function getContext() {
752 if ( $this->mContext
instanceof IContextSource
) {
753 return $this->mContext
;
755 wfDebug( __METHOD__
. " called and \$mContext is null. " .
756 "Return RequestContext::getMain(); for sanity\n" );
757 return RequestContext
::getMain();
762 * Get the WebRequest being used for this instance
767 public function getRequest() {
768 return $this->getContext()->getRequest();
772 * Get the OutputPage being used for this instance
777 public function getOutput() {
778 return $this->getContext()->getOutput();
782 * Shortcut to get the User executing this instance
787 public function getUser() {
788 return $this->getContext()->getUser();
792 * Shortcut to get the skin being used for this instance
797 public function getSkin() {
798 return $this->getContext()->getSkin();
802 * Shortcut to get user's language
804 * @deprecated since 1.19 Use getLanguage instead
808 public function getLang() {
809 wfDeprecated( __METHOD__
, '1.19' );
810 return $this->getLanguage();
814 * Shortcut to get user's language
819 public function getLanguage() {
820 return $this->getContext()->getLanguage();
824 * Return the full title, including $par
829 public function getFullTitle() {
830 return $this->getContext()->getTitle();
834 * Wrapper around wfMessage that sets the current context.
839 public function msg( /* $args */ ) {
840 // Note: can't use func_get_args() directly as second or later item in
841 // a parameter list until PHP 5.3 or you get a fatal error.
842 // Works fine as the first parameter, which appears elsewhere in the
843 // code base. Sighhhh.
844 $args = func_get_args();
845 $message = call_user_func_array( array( $this->getContext(), 'msg' ), $args );
846 // RequestContext passes context to wfMessage, and the language is set from
847 // the context, but setting the language for Message class removes the
848 // interface message status, which breaks for example usernameless gender
849 // invocations. Restore the flag when not including special page in content.
850 if ( $this->including() ) {
851 $message->setInterfaceMessageFlag( false );
857 * Adds RSS/atom links
859 * @param $params array
861 protected function addFeedLinks( $params ) {
862 global $wgFeedClasses;
864 $feedTemplate = wfScript( 'api' );
866 foreach ( $wgFeedClasses as $format => $class ) {
867 $theseParams = $params +
array( 'feedformat' => $format );
868 $url = wfAppendQuery( $feedTemplate, $theseParams );
869 $this->getOutput()->addFeedLink( $format, $url );
874 * Get the group that the special page belongs in on Special:SpecialPage
875 * Use this method, instead of getGroupName to allow customization
876 * of the group name from the wiki side
878 * @return string Group of this special page
881 public function getFinalGroupName() {
882 global $wgSpecialPageGroups;
883 $name = $this->getName();
886 // Allow overbidding the group from the wiki side
887 $msg = $this->msg( 'specialpages-specialpagegroup-' . strtolower( $name ) )->inContentLanguage();
888 if ( !$msg->isBlank() ) {
889 $group = $msg->text();
891 // Than use the group from this object
892 $group = $this->getGroupName();
894 // Group '-' is used as default to have the chance to determine,
895 // if the special pages overrides this method,
896 // if not overridden, $wgSpecialPageGroups is checked for b/c
897 if ( $group === '-' && isset( $wgSpecialPageGroups[$name] ) ) {
898 $group = $wgSpecialPageGroups[$name];
902 // never give '-' back, change to 'other'
903 if ( $group === '-' ) {
911 * Under which header this special page is listed in Special:SpecialPages
912 * See messages 'specialpages-group-*' for valid names
913 * This method defaults to group 'other'
918 protected function getGroupName() {
919 // '-' used here to determine, if this group is overridden or has a hardcoded 'other'
920 // Needed for b/c in getFinalGroupName
926 * Special page which uses an HTMLForm to handle processing. This is mostly a
927 * clone of FormAction. More special pages should be built this way; maybe this could be
928 * a new structure for SpecialPages
930 abstract class FormSpecialPage
extends SpecialPage
{
932 * The sub-page of the special page.
935 protected $par = null;
938 * Get an HTMLForm descriptor array
941 abstract protected function getFormFields();
944 * Add pre-text to the form
945 * @return String HTML which will be sent to $form->addPreText()
947 protected function preText() {
952 * Add post-text to the form
953 * @return String HTML which will be sent to $form->addPostText()
955 protected function postText() {
960 * Play with the HTMLForm if you need to more substantially
961 * @param $form HTMLForm
963 protected function alterForm( HTMLForm
$form ) {
967 * Get message prefix for HTMLForm
972 protected function getMessagePrefix() {
973 return strtolower( $this->getName() );
977 * Get the HTMLForm to control behavior
978 * @return HTMLForm|null
980 protected function getForm() {
981 $this->fields
= $this->getFormFields();
983 $form = new HTMLForm( $this->fields
, $this->getContext(), $this->getMessagePrefix() );
984 $form->setSubmitCallback( array( $this, 'onSubmit' ) );
985 // If the form is a compact vertical form, then don't output this ugly
986 // fieldset surrounding it.
987 // XXX Special pages can setDisplayFormat to 'vform' in alterForm(), but that
988 // is called after this.
989 if ( !$form->isVForm() ) {
990 $form->setWrapperLegendMsg( $this->getMessagePrefix() . '-legend' );
993 $headerMsg = $this->msg( $this->getMessagePrefix() . '-text' );
994 if ( !$headerMsg->isDisabled() ) {
995 $form->addHeaderText( $headerMsg->parseAsBlock() );
998 // Retain query parameters (uselang etc)
999 $params = array_diff_key(
1000 $this->getRequest()->getQueryValues(), array( 'title' => null ) );
1001 $form->addHiddenField( 'redirectparams', wfArrayToCgi( $params ) );
1003 $form->addPreText( $this->preText() );
1004 $form->addPostText( $this->postText() );
1005 $this->alterForm( $form );
1007 // Give hooks a chance to alter the form, adding extra fields or text etc
1008 wfRunHooks( "Special{$this->getName()}BeforeFormDisplay", array( &$form ) );
1014 * Process the form on POST submission.
1015 * @param $data Array
1016 * @return Bool|Array true for success, false for didn't-try, array of errors on failure
1018 abstract public function onSubmit( array $data );
1021 * Do something exciting on successful processing of the form, most likely to show a
1022 * confirmation message
1023 * @since 1.22 Default is to do nothing
1025 public function onSuccess() {
1029 * Basic SpecialPage workflow: get a form, send it to the user; get some data back,
1031 * @param string $par Subpage string if one was specified
1033 public function execute( $par ) {
1034 $this->setParameter( $par );
1035 $this->setHeaders();
1037 // This will throw exceptions if there's a problem
1038 $this->checkExecutePermissions( $this->getUser() );
1040 $form = $this->getForm();
1041 if ( $form->show() ) {
1047 * Maybe do something interesting with the subpage parameter
1048 * @param string $par
1050 protected function setParameter( $par ) {
1055 * Called from execute() to check if the given user can perform this action.
1056 * Failures here must throw subclasses of ErrorPageError.
1058 * @throws UserBlockedError
1061 protected function checkExecutePermissions( User
$user ) {
1062 $this->checkPermissions();
1064 if ( $this->requiresUnblock() && $user->isBlocked() ) {
1065 $block = $user->getBlock();
1066 throw new UserBlockedError( $block );
1069 if ( $this->requiresWrite() ) {
1070 $this->checkReadOnly();
1077 * Whether this action requires the wiki not to be locked
1080 public function requiresWrite() {
1085 * Whether this action cannot be executed by a blocked user
1088 public function requiresUnblock() {
1094 * Shortcut to construct a special page which is unlisted by default
1095 * @ingroup SpecialPage
1097 class UnlistedSpecialPage
extends SpecialPage
{
1098 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
1099 parent
::__construct( $name, $restriction, false, $function, $file );
1102 public function isListed() {
1108 * Shortcut to construct an includable special page
1109 * @ingroup SpecialPage
1111 class IncludableSpecialPage
extends SpecialPage
{
1112 function __construct(
1113 $name, $restriction = '', $listed = true, $function = false, $file = 'default'
1115 parent
::__construct( $name, $restriction, $listed, $function, $file, true );
1118 public function isIncludable() {
1124 * Shortcut to construct a special page alias.
1125 * @ingroup SpecialPage
1127 abstract class RedirectSpecialPage
extends UnlistedSpecialPage
{
1129 // Query parameters that can be passed through redirects
1130 protected $mAllowedRedirectParams = array();
1132 // Query parameters added by redirects
1133 protected $mAddedRedirectParams = array();
1135 public function execute( $par ) {
1136 $redirect = $this->getRedirect( $par );
1137 $query = $this->getRedirectQuery();
1138 // Redirect to a page title with possible query parameters
1139 if ( $redirect instanceof Title
) {
1140 $url = $redirect->getFullURL( $query );
1141 $this->getOutput()->redirect( $url );
1143 } elseif ( $redirect === true ) {
1144 // Redirect to index.php with query parameters
1145 $url = wfAppendQuery( wfScript( 'index' ), $query );
1146 $this->getOutput()->redirect( $url );
1149 $class = get_class( $this );
1150 throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
1155 * If the special page is a redirect, then get the Title object it redirects to.
1158 * @param string $par Subpage string
1159 * @return Title|bool
1161 abstract public function getRedirect( $par );
1164 * Return part of the request string for a special redirect page
1165 * This allows passing, e.g. action=history to Special:Mypage, etc.
1169 public function getRedirectQuery() {
1172 foreach ( $this->mAllowedRedirectParams
as $arg ) {
1173 if ( $this->getRequest()->getVal( $arg, null ) !== null ) {
1174 $params[$arg] = $this->getRequest()->getVal( $arg );
1178 foreach ( $this->mAddedRedirectParams
as $arg => $val ) {
1179 $params[$arg] = $val;
1182 return count( $params )
1188 abstract class SpecialRedirectToSpecial
extends RedirectSpecialPage
{
1189 // @todo FIXME: Visibility must be declared
1190 var $redirName, $redirSubpage;
1192 function __construct(
1193 $name, $redirName, $redirSubpage = false,
1194 $allowedRedirectParams = array(), $addedRedirectParams = array()
1196 parent
::__construct( $name );
1197 $this->redirName
= $redirName;
1198 $this->redirSubpage
= $redirSubpage;
1199 $this->mAllowedRedirectParams
= $allowedRedirectParams;
1200 $this->mAddedRedirectParams
= $addedRedirectParams;
1203 public function getRedirect( $subpage ) {
1204 if ( $this->redirSubpage
=== false ) {
1205 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
1207 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
1213 * ListAdmins --> ListUsers/sysop
1215 class SpecialListAdmins
extends SpecialRedirectToSpecial
{
1216 function __construct() {
1217 parent
::__construct( 'Listadmins', 'Listusers', 'sysop' );
1222 * ListBots --> ListUsers/bot
1224 class SpecialListBots
extends SpecialRedirectToSpecial
{
1225 function __construct() {
1226 parent
::__construct( 'Listbots', 'Listusers', 'bot' );
1231 * CreateAccount --> UserLogin/signup
1232 * @todo FIXME: This (and the rest of the login frontend) needs to die a horrible painful death
1234 class SpecialCreateAccount
extends SpecialRedirectToSpecial
{
1235 function __construct() {
1236 parent
::__construct( 'CreateAccount', 'Userlogin', 'signup', array( 'returnto', 'returntoquery', 'uselang' ) );
1239 // No reason to hide this link on Special:Specialpages
1240 public function isListed() {
1244 protected function getGroupName() {
1249 * SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
1250 * are used to get user independent links pointing to the user page, talk
1251 * page and list of contributions.
1252 * This can let us cache a single copy of any generated content for all
1257 * Superclass for any RedirectSpecialPage which redirects the user
1258 * to a particular article (as opposed to user contributions, logs, etc.).
1260 * For security reasons these special pages are restricted to pass on
1261 * the following subset of GET parameters to the target page while
1262 * removing all others:
1264 * - useskin, uselang, printable: to alter the appearance of the resulting page
1266 * - redirect: allows viewing one's user page or talk page even if it is a
1269 * - rdfrom: allows redirecting to one's user page or talk page from an
1270 * external wiki with the "Redirect from..." notice.
1272 * - limit, offset: Useful for linking to history of one's own user page or
1273 * user talk page. For example, this would be a link to "the last edit to your
1274 * user talk page in the year 2010":
1275 * http://en.wikipedia.org/wiki/Special:MyPage?offset=20110000000000&limit=1&action=history
1277 * - feed: would allow linking to the current user's RSS feed for their user
1279 * http://en.wikipedia.org/w/index.php?title=Special:MyTalk&action=history&feed=rss
1281 * - preloadtitle: Can be used to provide a default section title for a
1282 * preloaded new comment on one's own talk page.
1284 * - summary : Can be used to provide a default edit summary for a preloaded
1285 * edit to one's own user page or talk page.
1287 * - preview: Allows showing/hiding preview on first edit regardless of user
1288 * preference, useful for preloaded edits where you know preview wouldn't be
1291 * - internaledit, externaledit, mode: Allows forcing the use of the
1292 * internal/external editor, e.g. to force the internal editor for
1293 * short/simple preloaded edits.
1295 * - redlink: Affects the message the user sees if their talk page/user talk
1296 * page does not currently exist. Avoids confusion for newbies with no user
1297 * pages over why they got a "permission error" following this link:
1298 * http://en.wikipedia.org/w/index.php?title=Special:MyPage&redlink=1
1300 * - debug: determines whether the debug parameter is passed to load.php,
1301 * which disables reformatting and allows scripts to be debugged. Useful
1302 * when debugging scripts that manipulate one's own user page or talk page.
1304 * @par Hook extension:
1305 * Extensions can add to the redirect parameters list by using the hook
1306 * RedirectSpecialArticleRedirectParams
1308 * This hook allows extensions which add GET parameters like FlaggedRevs to
1309 * retain those parameters when redirecting using special pages.
1311 * @par Hook extension example:
1313 * $wgHooks['RedirectSpecialArticleRedirectParams'][] =
1314 * 'MyExtensionHooks::onRedirectSpecialArticleRedirectParams';
1315 * public static function onRedirectSpecialArticleRedirectParams( &$redirectParams ) {
1316 * $redirectParams[] = 'stable';
1320 * @ingroup SpecialPage
1322 abstract class RedirectSpecialArticle
extends RedirectSpecialPage
{
1323 function __construct( $name ) {
1324 parent
::__construct( $name );
1325 $redirectParams = array(
1327 'redirect', 'rdfrom',
1328 # Options for preloaded edits
1329 'preload', 'editintro', 'preloadtitle', 'summary', 'nosummary',
1330 # Options for overriding user settings
1331 'preview', 'internaledit', 'externaledit', 'mode', 'minor', 'watchthis',
1332 # Options for history/diffs
1333 'section', 'oldid', 'diff', 'dir',
1334 'limit', 'offset', 'feed',
1337 # Options for action=raw; missing ctype can break JS or CSS in some browsers
1338 'ctype', 'maxage', 'smaxage',
1341 wfRunHooks( "RedirectSpecialArticleRedirectParams", array( &$redirectParams ) );
1342 $this->mAllowedRedirectParams
= $redirectParams;
1347 * Shortcut to construct a special page pointing to current user user's page.
1348 * @ingroup SpecialPage
1350 class SpecialMypage
extends RedirectSpecialArticle
{
1351 function __construct() {
1352 parent
::__construct( 'Mypage' );
1355 function getRedirect( $subpage ) {
1356 if ( strval( $subpage ) !== '' ) {
1357 return Title
::makeTitle( NS_USER
, $this->getUser()->getName() . '/' . $subpage );
1359 return Title
::makeTitle( NS_USER
, $this->getUser()->getName() );
1365 * Shortcut to construct a special page pointing to current user talk page.
1366 * @ingroup SpecialPage
1368 class SpecialMytalk
extends RedirectSpecialArticle
{
1369 function __construct() {
1370 parent
::__construct( 'Mytalk' );
1373 function getRedirect( $subpage ) {
1374 if ( strval( $subpage ) !== '' ) {
1375 return Title
::makeTitle( NS_USER_TALK
, $this->getUser()->getName() . '/' . $subpage );
1377 return Title
::makeTitle( NS_USER_TALK
, $this->getUser()->getName() );
1383 * Shortcut to construct a special page pointing to current user contributions.
1384 * @ingroup SpecialPage
1386 class SpecialMycontributions
extends RedirectSpecialPage
{
1387 function __construct() {
1388 parent
::__construct( 'Mycontributions' );
1389 $this->mAllowedRedirectParams
= array( 'limit', 'namespace', 'tagfilter',
1390 'offset', 'dir', 'year', 'month', 'feed' );
1393 function getRedirect( $subpage ) {
1394 return SpecialPage
::getTitleFor( 'Contributions', $this->getUser()->getName() );
1399 * Redirect to Special:Listfiles?user=$wgUser
1401 class SpecialMyuploads
extends RedirectSpecialPage
{
1402 function __construct() {
1403 parent
::__construct( 'Myuploads' );
1404 $this->mAllowedRedirectParams
= array( 'limit', 'ilshowall', 'ilsearch' );
1407 function getRedirect( $subpage ) {
1408 return SpecialPage
::getTitleFor( 'Listfiles', $this->getUser()->getName() );
1413 * Redirect Special:Listfiles?user=$wgUser&ilshowall=true
1415 class SpecialAllMyUploads
extends RedirectSpecialPage
{
1416 function __construct() {
1417 parent
::__construct( 'AllMyUploads' );
1418 $this->mAllowedRedirectParams
= array( 'limit', 'ilsearch' );
1421 function getRedirect( $subpage ) {
1422 $this->mAddedRedirectParams
['ilshowall'] = 1;
1423 return SpecialPage
::getTitleFor( 'Listfiles', $this->getUser()->getName() );
1429 * Redirect from Special:PermanentLink/### to index.php?oldid=###
1431 class SpecialPermanentLink
extends RedirectSpecialPage
{
1432 function __construct() {
1433 parent
::__construct( 'PermanentLink' );
1434 $this->mAllowedRedirectParams
= array();
1437 function getRedirect( $subpage ) {
1438 $subpage = intval( $subpage );
1439 if ( $subpage === 0 ) {
1440 # throw an error page when no subpage was given
1441 throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
1443 $this->mAddedRedirectParams
['oldid'] = $subpage;