Localisation updates from http://translatewiki.net.
[mediawiki.git] / includes / SpecialPage.php
blobb529f863f39c3a661237aa7b1414b1251840e224
1 <?php
2 /**
3 * SpecialPage: handling special pages and lists thereof.
5 * To add a special page in an extension, add to $wgSpecialPages either
6 * an object instance or an array containing the name and constructor
7 * parameters. The latter is preferred for performance reasons.
9 * The object instantiated must be either an instance of SpecialPage or a
10 * sub-class thereof. It must have an execute() method, which sends the HTML
11 * for the special page to $wgOut. The parent class has an execute() method
12 * which distributes the call to the historical global functions. Additionally,
13 * execute() also checks if the user has the necessary access privileges
14 * and bails out if not.
16 * To add a core special page, use the similar static list in
17 * SpecialPage::$mList. To remove a core static special page at runtime, use
18 * a SpecialPage_initList hook.
20 * @file
21 * @ingroup SpecialPage
22 * @defgroup SpecialPage SpecialPage
25 /**
26 * Parent special page class, also static functions for handling the special
27 * page list.
28 * @ingroup SpecialPage
30 class SpecialPage {
32 // The canonical name of this special page
33 // Also used for the default <h1> heading, @see getDescription()
34 protected $mName;
36 // The local name of this special page
37 private $mLocalName;
39 // Minimum user level required to access this page, or "" for anyone.
40 // Also used to categorise the pages in Special:Specialpages
41 private $mRestriction;
43 // Listed in Special:Specialpages?
44 private $mListed;
46 // Function name called by the default execute()
47 private $mFunction;
49 // File which needs to be included before the function above can be called
50 private $mFile;
52 // Whether or not this special page is being included from an article
53 protected $mIncluding;
55 // Whether the special page can be included in an article
56 protected $mIncludable;
58 /**
59 * Current request context
60 * @var IContextSource
62 protected $mContext;
64 /**
65 * Initialise the special page list
66 * This must be called before accessing SpecialPage::$mList
67 * @deprecated since 1.18
69 static function initList() {
70 wfDeprecated( __METHOD__, '1.18' );
71 // Noop
74 /**
75 * @deprecated since 1.18
77 static function initAliasList() {
78 wfDeprecated( __METHOD__, '1.18' );
79 // Noop
82 /**
83 * Given a special page alias, return the special page name.
84 * Returns false if there is no such alias.
86 * @param $alias String
87 * @return String or false
88 * @deprecated since 1.18 call SpecialPageFactory method directly
90 static function resolveAlias( $alias ) {
91 wfDeprecated( __METHOD__, '1.18' );
92 list( $name, /*...*/ ) = SpecialPageFactory::resolveAlias( $alias );
93 return $name;
96 /**
97 * Given a special page name with a possible subpage, return an array
98 * where the first element is the special page name and the second is the
99 * subpage.
101 * @param $alias String
102 * @return Array
103 * @deprecated since 1.18 call SpecialPageFactory method directly
105 static function resolveAliasWithSubpage( $alias ) {
106 return SpecialPageFactory::resolveAlias( $alias );
110 * Add a page to the list of valid special pages. This used to be the preferred
111 * method for adding special pages in extensions. It's now suggested that you add
112 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
114 * @param $page SpecialPage
115 * @deprecated since 1.7, warnings in 1.17, might be removed in 1.20
117 static function addPage( &$page ) {
118 wfDeprecated( __METHOD__, '1.7' );
119 SpecialPageFactory::getList()->{$page->mName} = $page;
123 * Add a page to a certain display group for Special:SpecialPages
125 * @param $page Mixed: SpecialPage or string
126 * @param $group String
127 * @deprecated since 1.18 call SpecialPageFactory method directly
129 static function setGroup( $page, $group ) {
130 wfDeprecated( __METHOD__, '1.18' );
131 SpecialPageFactory::setGroup( $page, $group );
135 * Get the group that the special page belongs in on Special:SpecialPage
137 * @param $page SpecialPage
138 * @return string
139 * @deprecated since 1.18 call SpecialPageFactory method directly
141 static function getGroup( &$page ) {
142 wfDeprecated( __METHOD__, '1.18' );
143 return SpecialPageFactory::getGroup( $page );
147 * Remove a special page from the list
148 * Formerly used to disable expensive or dangerous special pages. The
149 * preferred method is now to add a SpecialPage_initList hook.
150 * @deprecated since 1.18
152 * @param $name String the page to remove
154 static function removePage( $name ) {
155 wfDeprecated( __METHOD__, '1.18' );
156 unset( SpecialPageFactory::getList()->$name );
160 * Check if a given name exist as a special page or as a special page alias
162 * @param $name String: name of a special page
163 * @return Boolean: true if a special page exists with this name
164 * @deprecated since 1.18 call SpecialPageFactory method directly
166 static function exists( $name ) {
167 wfDeprecated( __METHOD__, '1.18' );
168 return SpecialPageFactory::exists( $name );
172 * Find the object with a given name and return it (or NULL)
174 * @param $name String
175 * @return SpecialPage object or null if the page doesn't exist
176 * @deprecated since 1.18 call SpecialPageFactory method directly
178 static function getPage( $name ) {
179 wfDeprecated( __METHOD__, '1.18' );
180 return SpecialPageFactory::getPage( $name );
184 * Get a special page with a given localised name, or NULL if there
185 * is no such special page.
187 * @param $alias String
188 * @return SpecialPage object or null if the page doesn't exist
189 * @deprecated since 1.18 call SpecialPageFactory method directly
191 static function getPageByAlias( $alias ) {
192 wfDeprecated( __METHOD__, '1.18' );
193 return SpecialPageFactory::getPage( $alias );
197 * Return categorised listable special pages which are available
198 * for the current user, and everyone.
200 * @param $user User object to check permissions, $wgUser will be used
201 * if not provided
202 * @return array Associative array mapping page's name to its SpecialPage object
203 * @deprecated since 1.18 call SpecialPageFactory method directly
205 static function getUsablePages( User $user = null ) {
206 wfDeprecated( __METHOD__, '1.18' );
207 return SpecialPageFactory::getUsablePages( $user );
211 * Return categorised listable special pages for all users
213 * @return array Associative array mapping page's name to its SpecialPage object
214 * @deprecated since 1.18 call SpecialPageFactory method directly
216 static function getRegularPages() {
217 wfDeprecated( __METHOD__, '1.18' );
218 return SpecialPageFactory::getRegularPages();
222 * Return categorised listable special pages which are available
223 * for the current user, but not for everyone
225 * @return array Associative array mapping page's name to its SpecialPage object
226 * @deprecated since 1.18 call SpecialPageFactory method directly
228 static function getRestrictedPages() {
229 wfDeprecated( __METHOD__, '1.18' );
230 return SpecialPageFactory::getRestrictedPages();
234 * Execute a special page path.
235 * The path may contain parameters, e.g. Special:Name/Params
236 * Extracts the special page name and call the execute method, passing the parameters
238 * Returns a title object if the page is redirected, false if there was no such special
239 * page, and true if it was successful.
241 * @param $title Title object
242 * @param $context IContextSource
243 * @param $including Bool output is being captured for use in {{special:whatever}}
244 * @return Bool
245 * @deprecated since 1.18 call SpecialPageFactory method directly
247 public static function executePath( &$title, IContextSource &$context, $including = false ) {
248 wfDeprecated( __METHOD__, '1.18' );
249 return SpecialPageFactory::executePath( $title, $context, $including );
253 * Get the local name for a specified canonical name
255 * @param $name String
256 * @param $subpage Mixed: boolean false, or string
258 * @return String
259 * @deprecated since 1.18 call SpecialPageFactory method directly
261 static function getLocalNameFor( $name, $subpage = false ) {
262 wfDeprecated( __METHOD__, '1.18' );
263 return SpecialPageFactory::getLocalNameFor( $name, $subpage );
267 * Get a localised Title object for a specified special page name
269 * @param $name String
270 * @param $subpage String|Bool subpage string, or false to not use a subpage
271 * @return Title object
273 public static function getTitleFor( $name, $subpage = false ) {
274 $name = SpecialPageFactory::getLocalNameFor( $name, $subpage );
275 if ( $name ) {
276 return Title::makeTitle( NS_SPECIAL, $name );
277 } else {
278 throw new MWException( "Invalid special page name \"$name\"" );
283 * Get a localised Title object for a page name with a possibly unvalidated subpage
285 * @param $name String
286 * @param $subpage String|Bool subpage string, or false to not use a subpage
287 * @return Title object or null if the page doesn't exist
289 public static function getSafeTitleFor( $name, $subpage = false ) {
290 $name = SpecialPageFactory::getLocalNameFor( $name, $subpage );
291 if ( $name ) {
292 return Title::makeTitleSafe( NS_SPECIAL, $name );
293 } else {
294 return null;
299 * Get a title for a given alias
301 * @param $alias String
302 * @return Title or null if there is no such alias
303 * @deprecated since 1.18 call SpecialPageFactory method directly
305 static function getTitleForAlias( $alias ) {
306 wfDeprecated( __METHOD__, '1.18' );
307 return SpecialPageFactory::getTitleForAlias( $alias );
311 * Default constructor for special pages
312 * Derivative classes should call this from their constructor
313 * Note that if the user does not have the required level, an error message will
314 * be displayed by the default execute() method, without the global function ever
315 * being called.
317 * If you override execute(), you can recover the default behaviour with userCanExecute()
318 * and displayRestrictionError()
320 * @param $name String: name of the special page, as seen in links and URLs
321 * @param $restriction String: user right required, e.g. "block" or "delete"
322 * @param $listed Bool: whether the page is listed in Special:Specialpages
323 * @param $function Callback|Bool: function called by execute(). By default it is constructed from $name
324 * @param $file String: file which is included by execute(). It is also constructed from $name by default
325 * @param $includable Bool: whether the page can be included in normal pages
327 public function __construct(
328 $name = '', $restriction = '', $listed = true,
329 $function = false, $file = 'default', $includable = false
331 $this->init( $name, $restriction, $listed, $function, $file, $includable );
335 * Do the real work for the constructor, mainly so __call() can intercept
336 * calls to SpecialPage()
337 * @param $name String: name of the special page, as seen in links and URLs
338 * @param $restriction String: user right required, e.g. "block" or "delete"
339 * @param $listed Bool: whether the page is listed in Special:Specialpages
340 * @param $function Callback|Bool: function called by execute(). By default it is constructed from $name
341 * @param $file String: file which is included by execute(). It is also constructed from $name by default
342 * @param $includable Bool: whether the page can be included in normal pages
344 private function init( $name, $restriction, $listed, $function, $file, $includable ) {
345 $this->mName = $name;
346 $this->mRestriction = $restriction;
347 $this->mListed = $listed;
348 $this->mIncludable = $includable;
349 if ( !$function ) {
350 $this->mFunction = 'wfSpecial' . $name;
351 } else {
352 $this->mFunction = $function;
354 if ( $file === 'default' ) {
355 $this->mFile = dirname( __FILE__ ) . "/specials/Special$name.php";
356 } else {
357 $this->mFile = $file;
362 * Use PHP's magic __call handler to get calls to the old PHP4 constructor
363 * because PHP E_STRICT yells at you for having __construct() and SpecialPage()
365 * @param $fName String Name of called method
366 * @param $a Array Arguments to the method
367 * @deprecated since 1.17, call parent::__construct()
369 public function __call( $fName, $a ) {
370 // Deprecated messages now, remove in 1.19 or 1.20?
371 wfDeprecated( __METHOD__, '1.17' );
373 // Sometimes $fName is SpecialPage, sometimes it's specialpage. <3 PHP
374 if ( strtolower( $fName ) == 'specialpage' ) {
375 $name = isset( $a[0] ) ? $a[0] : '';
376 $restriction = isset( $a[1] ) ? $a[1] : '';
377 $listed = isset( $a[2] ) ? $a[2] : true;
378 $function = isset( $a[3] ) ? $a[3] : false;
379 $file = isset( $a[4] ) ? $a[4] : 'default';
380 $includable = isset( $a[5] ) ? $a[5] : false;
381 $this->init( $name, $restriction, $listed, $function, $file, $includable );
382 } else {
383 $className = get_class( $this );
384 throw new MWException( "Call to undefined method $className::$fName" );
389 * Get the name of this Special Page.
390 * @return String
392 function getName() {
393 return $this->mName;
397 * Get the permission that a user must have to execute this page
398 * @return String
400 function getRestriction() {
401 return $this->mRestriction;
405 * Get the file which will be included by SpecialPage::execute() if your extension is
406 * still stuck in the past and hasn't overridden the execute() method. No modern code
407 * should want or need to know this.
408 * @return String
409 * @deprecated since 1.18
411 function getFile() {
412 wfDeprecated( __METHOD__, '1.18' );
413 return $this->mFile;
416 // @todo FIXME: Decide which syntax to use for this, and stick to it
418 * Whether this special page is listed in Special:SpecialPages
419 * @since r3583 (v1.3)
420 * @return Bool
422 function isListed() {
423 return $this->mListed;
426 * Set whether this page is listed in Special:Specialpages, at run-time
427 * @since r3583 (v1.3)
428 * @param $listed Bool
429 * @return Bool
431 function setListed( $listed ) {
432 return wfSetVar( $this->mListed, $listed );
435 * Get or set whether this special page is listed in Special:SpecialPages
436 * @since r11308 (v1.6)
437 * @param $x Bool
438 * @return Bool
440 function listed( $x = null ) {
441 return wfSetVar( $this->mListed, $x );
445 * Whether it's allowed to transclude the special page via {{Special:Foo/params}}
446 * @return Bool
448 public function isIncludable() {
449 return $this->mIncludable;
453 * These mutators are very evil, as the relevant variables should not mutate. So
454 * don't use them.
455 * @param $x Mixed
456 * @return Mixed
457 * @deprecated since 1.18
459 function name( $x = null ) { wfDeprecated( __METHOD__, '1.18' ); return wfSetVar( $this->mName, $x ); }
462 * These mutators are very evil, as the relevant variables should not mutate. So
463 * don't use them.
464 * @param $x Mixed
465 * @return Mixed
466 * @deprecated since 1.18
468 function restriction( $x = null ) { wfDeprecated( __METHOD__, '1.18' ); return wfSetVar( $this->mRestriction, $x ); }
471 * These mutators are very evil, as the relevant variables should not mutate. So
472 * don't use them.
473 * @param $x Mixed
474 * @return Mixed
475 * @deprecated since 1.18
477 function func( $x = null ) { wfDeprecated( __METHOD__, '1.18' ); return wfSetVar( $this->mFunction, $x ); }
480 * These mutators are very evil, as the relevant variables should not mutate. So
481 * don't use them.
482 * @param $x Mixed
483 * @return Mixed
484 * @deprecated since 1.18
486 function file( $x = null ) { wfDeprecated( __METHOD__, '1.18' ); return wfSetVar( $this->mFile, $x ); }
489 * These mutators are very evil, as the relevant variables should not mutate. So
490 * don't use them.
491 * @param $x Mixed
492 * @return Mixed
493 * @deprecated since 1.18
495 function includable( $x = null ) { wfDeprecated( __METHOD__, '1.18' ); return wfSetVar( $this->mIncludable, $x ); }
498 * Whether the special page is being evaluated via transclusion
499 * @param $x Bool
500 * @return Bool
502 function including( $x = null ) {
503 return wfSetVar( $this->mIncluding, $x );
507 * Get the localised name of the special page
509 function getLocalName() {
510 if ( !isset( $this->mLocalName ) ) {
511 $this->mLocalName = SpecialPageFactory::getLocalNameFor( $this->mName );
513 return $this->mLocalName;
517 * Is this page expensive (for some definition of expensive)?
518 * Expensive pages are disabled or cached in miser mode. Originally used
519 * (and still overridden) by QueryPage and subclasses, moved here so that
520 * Special:SpecialPages can safely call it for all special pages.
522 * @return Boolean
524 public function isExpensive() {
525 return false;
529 * Can be overridden by subclasses with more complicated permissions
530 * schemes.
532 * @return Boolean: should the page be displayed with the restricted-access
533 * pages?
535 public function isRestricted() {
536 global $wgGroupPermissions;
537 // DWIM: If all anons can do something, then it is not restricted
538 return $this->mRestriction != '' && empty( $wgGroupPermissions['*'][$this->mRestriction] );
542 * Checks if the given user (identified by an object) can execute this
543 * special page (as defined by $mRestriction). Can be overridden by sub-
544 * classes with more complicated permissions schemes.
546 * @param $user User: the user to check
547 * @return Boolean: does the user have permission to view the page?
549 public function userCanExecute( User $user ) {
550 return $user->isAllowed( $this->mRestriction );
554 * Output an error message telling the user what access level they have to have
556 function displayRestrictionError() {
557 throw new PermissionsError( $this->mRestriction );
561 * Checks if userCanExecute, and if not throws a PermissionsError
563 * @since 1.19
565 public function checkPermissions() {
566 if ( !$this->userCanExecute( $this->getUser() ) ) {
567 $this->displayRestrictionError();
572 * If the wiki is currently in readonly mode, throws a ReadOnlyError
574 * @since 1.19
575 * @throws ReadOnlyError
577 public function checkReadOnly() {
578 if ( wfReadOnly() ) {
579 throw new ReadOnlyError;
584 * Sets headers - this should be called from the execute() method of all derived classes!
586 function setHeaders() {
587 $out = $this->getOutput();
588 $out->setArticleRelated( false );
589 $out->setRobotPolicy( "noindex,nofollow" );
590 $out->setPageTitle( $this->getDescription() );
594 * Default execute method
595 * Checks user permissions, calls the function given in mFunction
597 * This must be overridden by subclasses; it will be made abstract in a future version
599 * @param $par String subpage string, if one was specified
601 function execute( $par ) {
602 $this->setHeaders();
603 $this->checkPermissions();
605 $func = $this->mFunction;
606 // only load file if the function does not exist
607 if ( !is_callable( $func ) && $this->mFile ) {
608 require_once( $this->mFile );
610 $this->outputHeader();
611 call_user_func( $func, $par, $this );
615 * Outputs a summary message on top of special pages
616 * Per default the message key is the canonical name of the special page
617 * May be overriden, i.e. by extensions to stick with the naming conventions
618 * for message keys: 'extensionname-xxx'
620 * @param $summaryMessageKey String: message key of the summary
622 function outputHeader( $summaryMessageKey = '' ) {
623 global $wgContLang;
625 if ( $summaryMessageKey == '' ) {
626 $msg = $wgContLang->lc( $this->getName() ) . '-summary';
627 } else {
628 $msg = $summaryMessageKey;
630 if ( !$this->msg( $msg )->isBlank() && !$this->including() ) {
631 $this->getOutput()->wrapWikiMsg(
632 "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
638 * Returns the name that goes in the \<h1\> in the special page itself, and
639 * also the name that will be listed in Special:Specialpages
641 * Derived classes can override this, but usually it is easier to keep the
642 * default behaviour. Messages can be added at run-time, see
643 * MessageCache.php.
645 * @return String
647 function getDescription() {
648 return $this->msg( strtolower( $this->mName ) )->text();
652 * Get a self-referential title object
654 * @param $subpage String|Bool
655 * @return Title object
657 function getTitle( $subpage = false ) {
658 return self::getTitleFor( $this->mName, $subpage );
662 * Sets the context this SpecialPage is executed in
664 * @param $context IContextSource
665 * @since 1.18
667 public function setContext( $context ) {
668 $this->mContext = $context;
672 * Gets the context this SpecialPage is executed in
674 * @return IContextSource|RequestContext
675 * @since 1.18
677 public function getContext() {
678 if ( $this->mContext instanceof IContextSource ) {
679 return $this->mContext;
680 } else {
681 wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
682 return RequestContext::getMain();
687 * Get the WebRequest being used for this instance
689 * @return WebRequest
690 * @since 1.18
692 public function getRequest() {
693 return $this->getContext()->getRequest();
697 * Get the OutputPage being used for this instance
699 * @return OutputPage
700 * @since 1.18
702 public function getOutput() {
703 return $this->getContext()->getOutput();
707 * Shortcut to get the User executing this instance
709 * @return User
710 * @since 1.18
712 public function getUser() {
713 return $this->getContext()->getUser();
717 * Shortcut to get the skin being used for this instance
719 * @return Skin
720 * @since 1.18
722 public function getSkin() {
723 return $this->getContext()->getSkin();
727 * Shortcut to get user's language
729 * @deprecated 1.19 Use getLanguage instead
730 * @return Language
731 * @since 1.18
733 public function getLang() {
734 wfDeprecated( __METHOD__, '1.19' );
735 return $this->getLanguage();
739 * Shortcut to get user's language
741 * @return Language
742 * @since 1.19
744 public function getLanguage() {
745 return $this->getContext()->getLanguage();
749 * Return the full title, including $par
751 * @return Title
752 * @since 1.18
754 public function getFullTitle() {
755 return $this->getContext()->getTitle();
759 * Wrapper around wfMessage that sets the current context.
761 * @return Message
762 * @see wfMessage
764 public function msg( /* $args */ ) {
765 // Note: can't use func_get_args() directly as second or later item in
766 // a parameter list until PHP 5.3 or you get a fatal error.
767 // Works fine as the first parameter, which appears elsewhere in the
768 // code base. Sighhhh.
769 $args = func_get_args();
770 $message = call_user_func_array( array( $this->getContext(), 'msg' ), $args );
771 // RequestContext passes context to wfMessage, and the language is set from
772 // the context, but setting the language for Message class removes the
773 // interface message status, which breaks for example usernameless gender
774 // invokations. Restore the flag when not including special page in content.
775 if ( $this->including() ) {
776 $message->setInterfaceMessageFlag( false );
778 return $message;
782 * Adds RSS/atom links
784 * @param $params array
786 protected function addFeedLinks( $params ) {
787 global $wgFeedClasses;
789 $feedTemplate = wfScript( 'api' ) . '?';
791 foreach ( $wgFeedClasses as $format => $class ) {
792 $theseParams = $params + array( 'feedformat' => $format );
793 $url = $feedTemplate . wfArrayToCGI( $theseParams );
794 $this->getOutput()->addFeedLink( $format, $url );
800 * Special page which uses an HTMLForm to handle processing. This is mostly a
801 * clone of FormAction. More special pages should be built this way; maybe this could be
802 * a new structure for SpecialPages
804 abstract class FormSpecialPage extends SpecialPage {
807 * Get an HTMLForm descriptor array
808 * @return Array
810 protected abstract function getFormFields();
813 * Add pre- or post-text to the form
814 * @return String HTML which will be sent to $form->addPreText()
816 protected function preText() { return ''; }
817 protected function postText() { return ''; }
820 * Play with the HTMLForm if you need to more substantially
821 * @param $form HTMLForm
823 protected function alterForm( HTMLForm $form ) {}
826 * Get the HTMLForm to control behaviour
827 * @return HTMLForm|null
829 protected function getForm() {
830 $this->fields = $this->getFormFields();
832 $form = new HTMLForm( $this->fields, $this->getContext() );
833 $form->setSubmitCallback( array( $this, 'onSubmit' ) );
834 $form->setWrapperLegend( $this->msg( strtolower( $this->getName() ) . '-legend' ) );
835 $form->addHeaderText(
836 $this->msg( strtolower( $this->getName() ) . '-text' )->parseAsBlock() );
838 // Retain query parameters (uselang etc)
839 $params = array_diff_key(
840 $this->getRequest()->getQueryValues(), array( 'title' => null ) );
841 $form->addHiddenField( 'redirectparams', wfArrayToCGI( $params ) );
843 $form->addPreText( $this->preText() );
844 $form->addPostText( $this->postText() );
845 $this->alterForm( $form );
847 // Give hooks a chance to alter the form, adding extra fields or text etc
848 wfRunHooks( "Special{$this->getName()}BeforeFormDisplay", array( &$form ) );
850 return $form;
854 * Process the form on POST submission.
855 * @param $data Array
856 * @return Bool|Array true for success, false for didn't-try, array of errors on failure
858 public abstract function onSubmit( array $data );
861 * Do something exciting on successful processing of the form, most likely to show a
862 * confirmation message
864 public abstract function onSuccess();
867 * Basic SpecialPage workflow: get a form, send it to the user; get some data back,
869 * @param $par String Subpage string if one was specified
871 public function execute( $par ) {
872 $this->setParameter( $par );
873 $this->setHeaders();
875 // This will throw exceptions if there's a problem
876 $this->checkExecutePermissions( $this->getUser() );
878 $form = $this->getForm();
879 if ( $form->show() ) {
880 $this->onSuccess();
885 * Maybe do something interesting with the subpage parameter
886 * @param $par String
888 protected function setParameter( $par ) {}
891 * Called from execute() to check if the given user can perform this action.
892 * Failures here must throw subclasses of ErrorPageError.
893 * @param $user User
894 * @return Bool true
895 * @throws ErrorPageError
897 protected function checkExecutePermissions( User $user ) {
898 $this->checkPermissions();
900 if ( $this->requiresUnblock() && $user->isBlocked() ) {
901 $block = $user->getBlock();
902 throw new UserBlockedError( $block );
905 if ( $this->requiresWrite() ) {
906 $this->checkReadOnly();
909 return true;
913 * Whether this action requires the wiki not to be locked
914 * @return Bool
916 public function requiresWrite() {
917 return true;
921 * Whether this action cannot be executed by a blocked user
922 * @return Bool
924 public function requiresUnblock() {
925 return true;
930 * Shortcut to construct a special page which is unlisted by default
931 * @ingroup SpecialPage
933 class UnlistedSpecialPage extends SpecialPage {
934 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
935 parent::__construct( $name, $restriction, false, $function, $file );
938 public function isListed() {
939 return false;
944 * Shortcut to construct an includable special page
945 * @ingroup SpecialPage
947 class IncludableSpecialPage extends SpecialPage {
948 function __construct(
949 $name, $restriction = '', $listed = true, $function = false, $file = 'default'
951 parent::__construct( $name, $restriction, $listed, $function, $file, true );
954 public function isIncludable() {
955 return true;
960 * Shortcut to construct a special page alias.
961 * @ingroup SpecialPage
963 abstract class RedirectSpecialPage extends UnlistedSpecialPage {
965 // Query parameters that can be passed through redirects
966 protected $mAllowedRedirectParams = array();
968 // Query parameteres added by redirects
969 protected $mAddedRedirectParams = array();
971 public function execute( $par ) {
972 $redirect = $this->getRedirect( $par );
973 $query = $this->getRedirectQuery();
974 // Redirect to a page title with possible query parameters
975 if ( $redirect instanceof Title ) {
976 $url = $redirect->getFullUrl( $query );
977 $this->getOutput()->redirect( $url );
978 wfProfileOut( __METHOD__ );
979 return $redirect;
980 // Redirect to index.php with query parameters
981 } elseif ( $redirect === true ) {
982 global $wgScript;
983 $url = $wgScript . '?' . wfArrayToCGI( $query );
984 $this->getOutput()->redirect( $url );
985 wfProfileOut( __METHOD__ );
986 return $redirect;
987 } else {
988 $class = __CLASS__;
989 throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
994 * If the special page is a redirect, then get the Title object it redirects to.
995 * False otherwise.
997 * @param $par String Subpage string
998 * @return Title|bool
1000 abstract public function getRedirect( $par );
1003 * Return part of the request string for a special redirect page
1004 * This allows passing, e.g. action=history to Special:Mypage, etc.
1006 * @return String
1008 public function getRedirectQuery() {
1009 $params = array();
1011 foreach ( $this->mAllowedRedirectParams as $arg ) {
1012 if ( $this->getRequest()->getVal( $arg, null ) !== null ) {
1013 $params[$arg] = $this->getRequest()->getVal( $arg );
1017 foreach ( $this->mAddedRedirectParams as $arg => $val ) {
1018 $params[$arg] = $val;
1021 return count( $params )
1022 ? $params
1023 : false;
1027 abstract class SpecialRedirectToSpecial extends RedirectSpecialPage {
1028 var $redirName, $redirSubpage;
1030 function __construct(
1031 $name, $redirName, $redirSubpage = false,
1032 $allowedRedirectParams = array(), $addedRedirectParams = array()
1034 parent::__construct( $name );
1035 $this->redirName = $redirName;
1036 $this->redirSubpage = $redirSubpage;
1037 $this->mAllowedRedirectParams = $allowedRedirectParams;
1038 $this->mAddedRedirectParams = $addedRedirectParams;
1041 public function getRedirect( $subpage ) {
1042 if ( $this->redirSubpage === false ) {
1043 return SpecialPage::getTitleFor( $this->redirName, $subpage );
1044 } else {
1045 return SpecialPage::getTitleFor( $this->redirName, $this->redirSubpage );
1051 * ListAdmins --> ListUsers/sysop
1053 class SpecialListAdmins extends SpecialRedirectToSpecial {
1054 function __construct() {
1055 parent::__construct( 'Listadmins', 'Listusers', 'sysop' );
1060 * ListBots --> ListUsers/bot
1062 class SpecialListBots extends SpecialRedirectToSpecial {
1063 function __construct() {
1064 parent::__construct( 'Listbots', 'Listusers', 'bot' );
1069 * CreateAccount --> UserLogin/signup
1070 * @todo FIXME: This (and the rest of the login frontend) needs to die a horrible painful death
1072 class SpecialCreateAccount extends SpecialRedirectToSpecial {
1073 function __construct() {
1074 parent::__construct( 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) );
1078 * SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
1079 * are used to get user independant links pointing to the user page, talk
1080 * page and list of contributions.
1081 * This can let us cache a single copy of any generated content for all
1082 * users.
1086 * Shortcut to construct a special page pointing to current user user's page.
1087 * @ingroup SpecialPage
1089 class SpecialMypage extends RedirectSpecialPage {
1090 function __construct() {
1091 parent::__construct( 'Mypage' );
1092 $this->mAllowedRedirectParams = array( 'action', 'preload', 'preloadtitle', 'editintro',
1093 'section', 'oldid', 'diff', 'dir',
1094 // Options for action=raw; missing ctype can break JS or CSS in some browsers
1095 'ctype', 'maxage', 'smaxage' );
1098 function getRedirect( $subpage ) {
1099 if ( strval( $subpage ) !== '' ) {
1100 return Title::makeTitle( NS_USER, $this->getUser()->getName() . '/' . $subpage );
1101 } else {
1102 return Title::makeTitle( NS_USER, $this->getUser()->getName() );
1108 * Shortcut to construct a special page pointing to current user talk page.
1109 * @ingroup SpecialPage
1111 class SpecialMytalk extends RedirectSpecialPage {
1112 function __construct() {
1113 parent::__construct( 'Mytalk' );
1114 $this->mAllowedRedirectParams = array( 'action', 'preload', 'preloadtitle', 'editintro',
1115 'section', 'oldid', 'diff', 'dir' );
1118 function getRedirect( $subpage ) {
1119 if ( strval( $subpage ) !== '' ) {
1120 return Title::makeTitle( NS_USER_TALK, $this->getUser()->getName() . '/' . $subpage );
1121 } else {
1122 return Title::makeTitle( NS_USER_TALK, $this->getUser()->getName() );
1128 * Shortcut to construct a special page pointing to current user contributions.
1129 * @ingroup SpecialPage
1131 class SpecialMycontributions extends RedirectSpecialPage {
1132 function __construct() {
1133 parent::__construct( 'Mycontributions' );
1134 $this->mAllowedRedirectParams = array( 'limit', 'namespace', 'tagfilter',
1135 'offset', 'dir', 'year', 'month', 'feed' );
1138 function getRedirect( $subpage ) {
1139 return SpecialPage::getTitleFor( 'Contributions', $this->getUser()->getName() );
1144 * Redirect to Special:Listfiles?user=$wgUser
1146 class SpecialMyuploads extends RedirectSpecialPage {
1147 function __construct() {
1148 parent::__construct( 'Myuploads' );
1149 $this->mAllowedRedirectParams = array( 'limit' );
1152 function getRedirect( $subpage ) {
1153 return SpecialPage::getTitleFor( 'Listfiles', $this->getUser()->getName() );
1158 * Redirect from Special:PermanentLink/### to index.php?oldid=###
1160 class SpecialPermanentLink extends RedirectSpecialPage {
1161 function __construct() {
1162 parent::__construct( 'PermanentLink' );
1163 $this->mAllowedRedirectParams = array();
1166 function getRedirect( $subpage ) {
1167 $subpage = intval( $subpage );
1168 if ( $subpage === 0 ) {
1169 # throw an error page when no subpage was given
1170 throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
1172 $this->mAddedRedirectParams['oldid'] = $subpage;
1173 return true;