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.
21 * @ingroup SpecialPage
22 * @defgroup SpecialPage SpecialPage
26 * Parent special page class, also static functions for handling the special
28 * @ingroup SpecialPage
35 * The canonical name of this special page
36 * Also used for the default <h1> heading, @see getDescription()
40 * The local name of this special page
44 * Minimum user level required to access this page, or "" for anyone.
45 * Also used to categorise the pages in Special:Specialpages
49 * Listed in Special:Specialpages?
53 * Function name called by the default execute()
57 * File which needs to be included before the function above can be called
61 * Whether or not this special page is being included from an article
65 * Whether the special page can be included in an article
69 * Query parameters that can be passed through redirects
71 var $mAllowedRedirectParams = array();
73 * Query parameteres added by redirects
75 var $mAddedRedirectParams = array();
77 * List of special pages, followed by parameters.
78 * If the only parameter is a string, that is the page name.
79 * Otherwise, it is an array. The format is one of:
80 ** array( 'SpecialPage', name, right )
81 ** array( 'IncludableSpecialPage', name, right, listed? )
82 ** array( 'UnlistedSpecialPage', name, right )
83 ** array( 'SpecialRedirectToSpecial', name, page to redirect to, special page param, ... )
85 static public $mList = array(
87 'BrokenRedirects' => array( 'SpecialPage', 'BrokenRedirects' ),
88 'Deadendpages' => array( 'SpecialPage', 'Deadendpages' ),
89 'DoubleRedirects' => array( 'SpecialPage', 'DoubleRedirects' ),
90 'Longpages' => array( 'SpecialPage', 'Longpages' ),
91 'Ancientpages' => array( 'SpecialPage', 'Ancientpages' ),
92 'Lonelypages' => array( 'SpecialPage', 'Lonelypages' ),
93 'Fewestrevisions' => array( 'SpecialPage', 'Fewestrevisions' ),
94 'Withoutinterwiki' => array( 'SpecialPage', 'Withoutinterwiki' ),
95 'Protectedpages' => 'SpecialProtectedpages',
96 'Protectedtitles' => 'SpecialProtectedtitles',
97 'Shortpages' => array( 'SpecialPage', 'Shortpages' ),
98 'Uncategorizedcategories' => array( 'SpecialPage', 'Uncategorizedcategories' ),
99 'Uncategorizedimages' => array( 'SpecialPage', 'Uncategorizedimages' ),
100 'Uncategorizedpages' => array( 'SpecialPage', 'Uncategorizedpages' ),
101 'Uncategorizedtemplates' => array( 'SpecialPage', 'Uncategorizedtemplates' ),
102 'Unusedcategories' => array( 'SpecialPage', 'Unusedcategories' ),
103 'Unusedimages' => array( 'SpecialPage', 'Unusedimages' ),
104 'Unusedtemplates' => array( 'SpecialPage', 'Unusedtemplates' ),
105 'Unwatchedpages' => array( 'SpecialPage', 'Unwatchedpages', 'unwatchedpages' ),
106 'Wantedcategories' => array( 'SpecialPage', 'Wantedcategories' ),
107 'Wantedfiles' => array( 'SpecialPage', 'Wantedfiles' ),
108 'Wantedpages' => array( 'IncludableSpecialPage', 'Wantedpages' ),
109 'Wantedtemplates' => array( 'SpecialPage', 'Wantedtemplates' ),
112 'Allpages' => 'SpecialAllpages',
113 'Prefixindex' => 'SpecialPrefixindex',
114 'Categories' => 'SpecialCategories',
115 'Disambiguations' => array( 'SpecialPage', 'Disambiguations' ),
116 'Listredirects' => array( 'SpecialPage', 'Listredirects' ),
118 # Login/create account
119 'Userlogin' => array( 'SpecialPage', 'Userlogin' ),
120 'CreateAccount' => array( 'SpecialRedirectToSpecial', 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ),
123 'Blockip' => 'IPBlockForm',
124 'Ipblocklist' => 'IPUnblockForm',
125 'Unblock' => array( 'SpecialRedirectToSpecial', 'Unblock', 'Ipblocklist', false, array( 'uselang', 'ip', 'id' ), array( 'action' => 'unblock' ) ),
126 'Resetpass' => 'SpecialResetpass',
127 'DeletedContributions' => 'DeletedContributionsPage',
128 'Preferences' => 'SpecialPreferences',
129 'Contributions' => 'SpecialContributions',
130 'Listgrouprights' => 'SpecialListGroupRights',
131 'Listusers' => array( 'SpecialPage', 'Listusers' ),
132 'Listadmins' => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
133 'Listbots' => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ),
134 'Activeusers' => 'SpecialActiveUsers',
135 'Userrights' => 'UserrightsPage',
137 # Recent changes and logs
138 'Newimages' => array( 'IncludableSpecialPage', 'Newimages' ),
139 'Log' => 'SpecialLog',
140 'Watchlist' => array( 'SpecialPage', 'Watchlist' ),
141 'Newpages' => 'SpecialNewpages',
142 'Recentchanges' => 'SpecialRecentchanges',
143 'Recentchangeslinked' => 'SpecialRecentchangeslinked',
144 'Tags' => 'SpecialTags',
146 # Media reports and uploads
147 'Listfiles' => array( 'SpecialPage', 'Listfiles' ),
148 'Filepath' => 'SpecialFilepath',
149 'MIMEsearch' => array( 'SpecialPage', 'MIMEsearch' ),
150 'FileDuplicateSearch' => array( 'SpecialPage', 'FileDuplicateSearch' ),
151 'Upload' => 'SpecialUpload',
153 # Wiki data and tools
154 'Statistics' => 'SpecialStatistics',
155 'Allmessages' => 'SpecialAllmessages',
156 'Version' => 'SpecialVersion',
157 'Lockdb' => 'SpecialLockdb',
158 'Unlockdb' => 'SpecialUnlockdb',
160 # Redirecting special pages
161 'LinkSearch' => array( 'SpecialPage', 'LinkSearch' ),
162 'Randompage' => 'Randompage',
163 'Randomredirect' => 'SpecialRandomredirect',
166 'Mostlinkedcategories' => array( 'SpecialPage', 'Mostlinkedcategories' ),
167 'Mostimages' => array( 'SpecialPage', 'Mostimages' ),
168 'Mostlinked' => array( 'SpecialPage', 'Mostlinked' ),
169 'Mostlinkedtemplates' => array( 'SpecialPage', 'Mostlinkedtemplates' ),
170 'Mostcategories' => array( 'SpecialPage', 'Mostcategories' ),
171 'Mostrevisions' => array( 'SpecialPage', 'Mostrevisions' ),
174 'ComparePages' => 'SpecialComparePages',
175 'Export' => 'SpecialExport',
176 'Import' => 'SpecialImport',
177 'Undelete' => 'UndeleteForm',
178 'Whatlinkshere' => 'SpecialWhatlinkshere',
179 'MergeHistory' => 'SpecialMergeHistory',
182 'Booksources' => 'SpecialBookSources',
184 # Unlisted / redirects
185 'Blankpage' => 'SpecialBlankpage',
186 'Blockme' => 'SpecialBlockme',
187 'Emailuser' => 'SpecialEmailUser',
188 'Movepage' => 'MovePageForm',
189 'Mycontributions' => 'SpecialMycontributions',
190 'Mypage' => 'SpecialMypage',
191 'Mytalk' => 'SpecialMytalk',
192 'Revisiondelete' => 'SpecialRevisionDelete',
193 'RevisionMove' => 'SpecialRevisionMove',
194 'Specialpages' => 'SpecialSpecialpages',
195 'Userlogout' => 'SpecialUserlogout',
198 static public $mAliases;
199 static public $mListInitialised = false;
204 * Initialise the special page list
205 * This must be called before accessing SpecialPage::$mList
207 static function initList() {
208 global $wgSpecialPages;
209 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
211 if ( self
::$mListInitialised ) {
214 wfProfileIn( __METHOD__
);
216 # Better to set this now, to avoid infinite recursion in carelessly written hooks
217 self
::$mListInitialised = true;
219 if( !$wgDisableCounters ) {
220 self
::$mList['Popularpages'] = array( 'SpecialPage', 'Popularpages' );
223 if( !$wgDisableInternalSearch ) {
224 self
::$mList['Search'] = array( 'SpecialPage', 'Search' );
227 if( $wgEmailAuthentication ) {
228 self
::$mList['Confirmemail'] = 'EmailConfirmation';
229 self
::$mList['Invalidateemail'] = 'EmailInvalidation';
232 # Add extension special pages
233 self
::$mList = array_merge( self
::$mList, $wgSpecialPages );
236 # This hook can be used to remove undesired built-in special pages
237 wfRunHooks( 'SpecialPage_initList', array( &self
::$mList ) );
238 wfProfileOut( __METHOD__
);
241 static function initAliasList() {
242 if ( !is_null( self
::$mAliases ) ) {
247 $aliases = $wgContLang->getSpecialPageAliases();
248 $missingPages = self
::$mList;
249 self
::$mAliases = array();
250 foreach ( $aliases as $realName => $aliasList ) {
251 foreach ( $aliasList as $alias ) {
252 self
::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
254 unset( $missingPages[$realName] );
256 foreach ( $missingPages as $name => $stuff ) {
257 self
::$mAliases[$wgContLang->caseFold( $name )] = $name;
262 * Given a special page alias, return the special page name.
263 * Returns false if there is no such alias.
265 * @param $alias String
266 * @return String or false
268 static function resolveAlias( $alias ) {
271 if ( !self
::$mListInitialised ) self
::initList();
272 if ( is_null( self
::$mAliases ) ) self
::initAliasList();
273 $caseFoldedAlias = $wgContLang->caseFold( $alias );
274 if ( isset( self
::$mAliases[$caseFoldedAlias] ) ) {
275 return self
::$mAliases[$caseFoldedAlias];
282 * Given a special page name with a possible subpage, return an array
283 * where the first element is the special page name and the second is the
286 * @param $alias String
289 static function resolveAliasWithSubpage( $alias ) {
290 $bits = explode( '/', $alias, 2 );
291 $name = self
::resolveAlias( $bits[0] );
292 if( !isset( $bits[1] ) ) { // bug 2087
297 return array( $name, $par );
301 * Add a page to the list of valid special pages. This used to be the preferred
302 * method for adding special pages in extensions. It's now suggested that you add
303 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
305 * @param $page SpecialPage
306 * Deprecated in 1.7, warnings in 1.17, might be removed in 1.20
308 static function addPage( &$page ) {
309 wfDeprecated( __METHOD__
);
310 if ( !self
::$mListInitialised ) {
313 self
::$mList[$page->mName
] = $page;
317 * Add a page to a certain display group for Special:SpecialPages
319 * @param $page Mixed: SpecialPage or string
320 * @param $group String
322 static function setGroup( $page, $group ) {
323 global $wgSpecialPageGroups;
324 $name = is_object($page) ?
$page->mName
: $page;
325 $wgSpecialPageGroups[$name] = $group;
329 * Add a page to a certain display group for Special:SpecialPages
331 * @param $page SpecialPage
333 static function getGroup( &$page ) {
334 global $wgSpecialPageGroups;
335 static $specialPageGroupsCache = array();
336 if( isset($specialPageGroupsCache[$page->mName
]) ) {
337 return $specialPageGroupsCache[$page->mName
];
339 $group = wfMsg('specialpages-specialpagegroup-'.strtolower($page->mName
));
341 ||
wfEmptyMsg('specialpages-specialpagegroup-'.strtolower($page->mName
), $group ) ) {
342 $group = isset($wgSpecialPageGroups[$page->mName
])
343 ?
$wgSpecialPageGroups[$page->mName
]
346 if( $group == '-' ) $group = 'other';
347 $specialPageGroupsCache[$page->mName
] = $group;
352 * Remove a special page from the list
353 * Formerly used to disable expensive or dangerous special pages. The
354 * preferred method is now to add a SpecialPage_initList hook.
356 static function removePage( $name ) {
357 if ( !self
::$mListInitialised ) {
360 unset( self
::$mList[$name] );
364 * Check if a given name exist as a special page or as a special page alias
366 * @param $name String: name of a special page
367 * @return Boolean: true if a special page exists with this name
369 static function exists( $name ) {
371 if ( !self
::$mListInitialised ) {
374 if( !self
::$mAliases ) {
375 self
::initAliasList();
378 # Remove special pages inline parameters:
379 $bits = explode( '/', $name );
380 $name = $wgContLang->caseFold($bits[0]);
383 array_key_exists( $name, self
::$mList )
384 or array_key_exists( $name, self
::$mAliases )
389 * Find the object with a given name and return it (or NULL)
391 * @param $name String
392 * @return SpecialPage object or null if the page doesn't exist
394 static function getPage( $name ) {
395 if ( !self
::$mListInitialised ) {
398 if ( array_key_exists( $name, self
::$mList ) ) {
399 $rec = self
::$mList[$name];
400 if ( is_string( $rec ) ) {
402 self
::$mList[$name] = new $className;
403 } elseif ( is_array( $rec ) ) {
404 $className = array_shift( $rec );
405 self
::$mList[$name] = wfCreateObject( $className, $rec );
407 return self
::$mList[$name];
414 * Get a special page with a given localised name, or NULL if there
415 * is no such special page.
417 * @return SpecialPage object or null if the page doesn't exist
419 static function getPageByAlias( $alias ) {
420 $realName = self
::resolveAlias( $alias );
422 return self
::getPage( $realName );
429 * Return categorised listable special pages which are available
430 * for the current user, and everyone.
432 * @return Associative array mapping page's name to its SpecialPage object
434 static function getUsablePages() {
436 if ( !self
::$mListInitialised ) {
441 foreach ( self
::$mList as $name => $rec ) {
442 $page = self
::getPage( $name );
443 if ( $page->isListed()
445 !$page->isRestricted()
446 ||
$page->userCanExecute( $wgUser )
449 $pages[$name] = $page;
456 * Return categorised listable special pages for all users
458 * @return Associative array mapping page's name to its SpecialPage object
460 static function getRegularPages() {
461 if ( !self
::$mListInitialised ) {
466 foreach ( self
::$mList as $name => $rec ) {
467 $page = self
::getPage( $name );
468 if ( $page->isListed() && !$page->isRestricted() ) {
469 $pages[$name] = $page;
476 * Return categorised listable special pages which are available
477 * for the current user, but not for everyone
479 * @return Associative array mapping page's name to its SpecialPage object
481 static function getRestrictedPages() {
483 if( !self
::$mListInitialised ) {
488 foreach( self
::$mList as $name => $rec ) {
489 $page = self
::getPage( $name );
492 && $page->isRestricted()
493 && $page->userCanExecute( $wgUser )
495 $pages[$name] = $page;
502 * Execute a special page path.
503 * The path may contain parameters, e.g. Special:Name/Params
504 * Extracts the special page name and call the execute method, passing the parameters
506 * Returns a title object if the page is redirected, false if there was no such special
507 * page, and true if it was successful.
509 * @param $title a title object
510 * @param $including output is being captured for use in {{special:whatever}}
512 static function executePath( &$title, $including = false ) {
513 global $wgOut, $wgTitle, $wgRequest;
514 wfProfileIn( __METHOD__
);
516 # FIXME: redirects broken due to this call
517 $bits = explode( '/', $title->getDBkey(), 2 );
519 if( !isset( $bits[1] ) ) { // bug 2087
524 $page = SpecialPage
::getPageByAlias( $name );
528 $wgOut->setArticleRelated( false );
529 $wgOut->setRobotPolicy( 'noindex,nofollow' );
530 $wgOut->setStatusCode( 404 );
531 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
533 wfProfileOut( __METHOD__
);
539 $redirect = $page->getRedirect( $par );
541 $query = $page->getRedirectQuery();
542 $url = $redirect->getFullUrl( $query );
543 $wgOut->redirect( $url );
544 wfProfileOut( __METHOD__
);
549 # Redirect to canonical alias for GET commands
550 # Not for POST, we'd lose the post data, so it's best to just distribute
551 # the request. Such POST requests are possible for old extensions that
552 # generate self-links without being aware that their default name has
554 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
556 unset( $query['title'] );
557 $query = wfArrayToCGI( $query );
558 $title = $page->getTitle( $par );
559 $url = $title->getFullUrl( $query );
560 $wgOut->redirect( $url );
561 wfProfileOut( __METHOD__
);
565 if ( $including && !$page->includable() ) {
566 wfProfileOut( __METHOD__
);
568 } elseif ( !$including ) {
569 $wgTitle = $page->getTitle();
571 $page->including( $including );
573 // Execute special page
574 $profName = 'Special:' . $page->getName();
575 wfProfileIn( $profName );
576 $page->execute( $par );
577 wfProfileOut( $profName );
578 wfProfileOut( __METHOD__
);
583 * Just like executePath() except it returns the HTML instead of outputting it
584 * Returns false if there was no such special page, or a title object if it was
587 * @return String: HTML fragment
589 static function capturePath( &$title ) {
590 global $wgOut, $wgTitle;
592 $oldTitle = $wgTitle;
594 $wgOut = new OutputPage
;
595 $wgOut->setTitle( $title );
597 $ret = SpecialPage
::executePath( $title, true );
598 if ( $ret === true ) {
599 $ret = $wgOut->getHTML();
601 $wgTitle = $oldTitle;
607 * Get the local name for a specified canonical name
609 * @param $name String
610 * @param $subpage Mixed: boolean false, or string
614 static function getLocalNameFor( $name, $subpage = false ) {
616 $aliases = $wgContLang->getSpecialPageAliases();
617 if ( isset( $aliases[$name][0] ) ) {
618 $name = $aliases[$name][0];
620 // Try harder in case someone misspelled the correct casing
622 foreach ( $aliases as $n => $values ) {
623 if ( strcasecmp( $name, $n ) === 0 ) {
624 wfWarn( "Found alias defined for $n when searching for" .
625 "special page aliases for $name. Case mismatch?" );
632 wfWarn( "Did not find alias for special page '$name'. " .
633 "Perhaps no aliases are defined for it?" );
636 if ( $subpage !== false && !is_null( $subpage ) ) {
637 $name = "$name/$subpage";
639 return $wgContLang->ucfirst( $name );
643 * Get a localised Title object for a specified special page name
645 * @return Title object
647 static function getTitleFor( $name, $subpage = false ) {
648 $name = self
::getLocalNameFor( $name, $subpage );
650 return Title
::makeTitle( NS_SPECIAL
, $name );
652 throw new MWException( "Invalid special page name \"$name\"" );
657 * Get a localised Title object for a page name with a possibly unvalidated subpage
659 * @return Title object or null if the page doesn't exist
661 static function getSafeTitleFor( $name, $subpage = false ) {
662 $name = self
::getLocalNameFor( $name, $subpage );
664 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
671 * Get a title for a given alias
673 * @return Title or null if there is no such alias
675 static function getTitleForAlias( $alias ) {
676 $name = self
::resolveAlias( $alias );
678 return self
::getTitleFor( $name );
685 * Default constructor for special pages
686 * Derivative classes should call this from their constructor
687 * Note that if the user does not have the required level, an error message will
688 * be displayed by the default execute() method, without the global function ever
691 * If you override execute(), you can recover the default behaviour with userCanExecute()
692 * and displayRestrictionError()
694 * @param $name String: name of the special page, as seen in links and URLs
695 * @param $restriction String: user right required, e.g. "block" or "delete"
696 * @param $listed Boolean: whether the page is listed in Special:Specialpages
697 * @param $function Callback: function called by execute(). By default it is constructed from $name
698 * @param $file String: file which is included by execute(). It is also constructed from $name by default
699 * @param $includable Boolean: whether the page can be included in normal pages
701 function __construct( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
702 $this->mName
= $name;
703 $this->mRestriction
= $restriction;
704 $this->mListed
= $listed;
705 $this->mIncludable
= $includable;
707 $this->mFunction
= 'wfSpecial'.$name;
709 $this->mFunction
= $function;
711 if ( $file === 'default' ) {
712 $this->mFile
= dirname(__FILE__
) . "/specials/Special$name.php";
714 $this->mFile
= $file;
723 function getName() { return $this->mName
; }
724 function getRestriction() { return $this->mRestriction
; }
725 function getFile() { return $this->mFile
; }
726 function isListed() { return $this->mListed
; }
730 * Accessor and mutator
732 function name( $x = null ) { return wfSetVar( $this->mName
, $x ); }
733 function restrictions( $x = null) {
734 # Use the one below this
735 wfDeprecated( __METHOD__
);
736 return wfSetVar( $this->mRestriction
, $x );
738 function restriction( $x = null) { return wfSetVar( $this->mRestriction
, $x ); }
739 function listed( $x = null) { return wfSetVar( $this->mListed
, $x ); }
740 function func( $x = null) { return wfSetVar( $this->mFunction
, $x ); }
741 function file( $x = null) { return wfSetVar( $this->mFile
, $x ); }
742 function includable( $x = null ) { return wfSetVar( $this->mIncludable
, $x ); }
743 function including( $x = null ) { return wfSetVar( $this->mIncluding
, $x ); }
747 * Get the localised name of the special page
749 function getLocalName() {
750 if ( !isset( $this->mLocalName
) ) {
751 $this->mLocalName
= self
::getLocalNameFor( $this->mName
);
753 return $this->mLocalName
;
757 * Can be overridden by subclasses with more complicated permissions
760 * @return Boolean: should the page be displayed with the restricted-access
763 public function isRestricted() {
764 global $wgGroupPermissions;
765 // DWIM: If all anons can do something, then it is not restricted
766 return $this->mRestriction
!= '' && empty($wgGroupPermissions['*'][$this->mRestriction
]);
770 * Checks if the given user (identified by an object) can execute this
771 * special page (as defined by $mRestriction). Can be overridden by sub-
772 * classes with more complicated permissions schemes.
774 * @param $user User: the user to check
775 * @return Boolean: does the user have permission to view the page?
777 public function userCanExecute( $user ) {
778 return $user->isAllowed( $this->mRestriction
);
782 * Output an error message telling the user what access level they have to have
784 function displayRestrictionError() {
786 $wgOut->permissionRequired( $this->mRestriction
);
790 * Sets headers - this should be called from the execute() method of all derived classes!
792 function setHeaders() {
794 $wgOut->setArticleRelated( false );
795 $wgOut->setRobotPolicy( "noindex,nofollow" );
796 $wgOut->setPageTitle( $this->getDescription() );
800 * Default execute method
801 * Checks user permissions, calls the function given in mFunction
803 * This may be overridden by subclasses.
805 function execute( $par ) {
810 if ( $this->userCanExecute( $wgUser ) ) {
811 $func = $this->mFunction
;
812 // only load file if the function does not exist
813 if(!is_callable($func) and $this->mFile
) {
814 require_once( $this->mFile
);
816 $this->outputHeader();
817 call_user_func( $func, $par, $this );
819 $this->displayRestrictionError();
824 * Outputs a summary message on top of special pages
825 * Per default the message key is the canonical name of the special page
826 * May be overriden, i.e. by extensions to stick with the naming conventions
827 * for message keys: 'extensionname-xxx'
829 * @param $summaryMessageKey String: message key of the summary
831 function outputHeader( $summaryMessageKey = '' ) {
832 global $wgOut, $wgContLang;
834 if( $summaryMessageKey == '' ) {
835 $msg = $wgContLang->lc( $this->name() ) . '-summary';
837 $msg = $summaryMessageKey;
839 $out = wfMsgNoTrans( $msg );
840 if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() ) {
841 $wgOut->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
847 * Returns the name that goes in the \<h1\> in the special page itself, and
848 * also the name that will be listed in Special:Specialpages
850 * Derived classes can override this, but usually it is easier to keep the
851 * default behaviour. Messages can be added at run-time, see
856 function getDescription() {
857 return wfMsg( strtolower( $this->mName
) );
861 * Get a self-referential title object
863 * @return Title object
865 function getTitle( $subpage = false ) {
866 return self
::getTitleFor( $this->mName
, $subpage );
870 * Set whether this page is listed in Special:Specialpages, at run-time
872 function setListed( $listed ) {
873 return wfSetVar( $this->mListed
, $listed );
877 * If the special page is a redirect, then get the Title object it redirects to.
880 function getRedirect( $subpage ) {
885 * Return part of the request string for a special redirect page
886 * This allows passing, e.g. action=history to Special:Mypage, etc.
890 function getRedirectQuery() {
893 foreach( $this->mAllowedRedirectParams
as $arg ) {
894 if( ( $val = $wgRequest->getVal( $arg, null ) ) !== null )
895 $params[] = $arg . '=' . $val;
898 foreach( $this->mAddedRedirectParams
as $arg => $val ) {
899 $params[] = $arg . '=' . $val;
902 return count( $params ) ?
implode( '&', $params ) : false;
907 * Shortcut to construct a special page which is unlisted by default
908 * @ingroup SpecialPage
910 class UnlistedSpecialPage
extends SpecialPage
912 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
913 parent
::__construct( $name, $restriction, false, $function, $file );
918 * Shortcut to construct an includable special page
919 * @ingroup SpecialPage
921 class IncludableSpecialPage
extends SpecialPage
923 function __construct( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
924 parent
::__construct( $name, $restriction, $listed, $function, $file, true );
929 * Shortcut to construct a special page alias.
930 * @ingroup SpecialPage
932 class SpecialRedirectToSpecial
extends UnlistedSpecialPage
{
933 var $redirName, $redirSubpage;
935 function __construct( $name, $redirName, $redirSubpage = false, $allowedRedirectParams = array(), $addedRedirectParams = array() ) {
936 parent
::__construct( $name );
937 $this->redirName
= $redirName;
938 $this->redirSubpage
= $redirSubpage;
939 $this->mAllowedRedirectParams
= $allowedRedirectParams;
940 $this->mAddedRedirectParams
= $addedRedirectParams;
943 function getRedirect( $subpage ) {
944 if ( $this->redirSubpage
=== false ) {
945 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
947 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
952 /** SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
953 * are used to get user independant links pointing to the user page, talk
954 * page and list of contributions.
955 * This can let us cache a single copy of any generated content for all
960 * Shortcut to construct a special page pointing to current user user's page.
961 * @ingroup SpecialPage
963 class SpecialMypage
extends UnlistedSpecialPage
{
964 function __construct() {
965 parent
::__construct( 'Mypage' );
966 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro', 'section' );
969 function getRedirect( $subpage ) {
971 if ( strval( $subpage ) !== '' ) {
972 return Title
::makeTitle( NS_USER
, $wgUser->getName() . '/' . $subpage );
974 return Title
::makeTitle( NS_USER
, $wgUser->getName() );
980 * Shortcut to construct a special page pointing to current user talk page.
981 * @ingroup SpecialPage
983 class SpecialMytalk
extends UnlistedSpecialPage
{
984 function __construct() {
985 parent
::__construct( 'Mytalk' );
986 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro', 'section' );
989 function getRedirect( $subpage ) {
991 if ( strval( $subpage ) !== '' ) {
992 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() . '/' . $subpage );
994 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() );
1000 * Shortcut to construct a special page pointing to current user contributions.
1001 * @ingroup SpecialPage
1003 class SpecialMycontributions
extends UnlistedSpecialPage
{
1004 function __construct() {
1005 parent
::__construct( 'Mycontributions' );
1006 $this->mAllowedRedirectParams
= array( 'limit', 'namespace', 'tagfilter',
1007 'offset', 'dir', 'year', 'month', 'feed' );
1010 function getRedirect( $subpage ) {
1012 return SpecialPage
::getTitleFor( 'Contributions', $wgUser->getName() );