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',
136 'DisableAccount' => 'SpecialDisableAccount',
138 # Recent changes and logs
139 'Newimages' => array( 'IncludableSpecialPage', 'Newimages' ),
140 'Log' => 'SpecialLog',
141 'Watchlist' => array( 'SpecialPage', 'Watchlist' ),
142 'Newpages' => 'SpecialNewpages',
143 'Recentchanges' => 'SpecialRecentchanges',
144 'Recentchangeslinked' => 'SpecialRecentchangeslinked',
145 'Tags' => 'SpecialTags',
147 # Media reports and uploads
148 'Listfiles' => array( 'SpecialPage', 'Listfiles' ),
149 'Filepath' => 'SpecialFilepath',
150 'MIMEsearch' => array( 'SpecialPage', 'MIMEsearch' ),
151 'FileDuplicateSearch' => array( 'SpecialPage', 'FileDuplicateSearch' ),
152 'Upload' => 'SpecialUpload',
153 'UploadStash' => 'SpecialUploadStash',
155 # Wiki data and tools
156 'Statistics' => 'SpecialStatistics',
157 'Allmessages' => 'SpecialAllmessages',
158 'Version' => 'SpecialVersion',
159 'Lockdb' => 'SpecialLockdb',
160 'Unlockdb' => 'SpecialUnlockdb',
162 # Redirecting special pages
163 'LinkSearch' => array( 'SpecialPage', 'LinkSearch' ),
164 'Randompage' => 'Randompage',
165 'Randomredirect' => 'SpecialRandomredirect',
168 'Mostlinkedcategories' => array( 'SpecialPage', 'Mostlinkedcategories' ),
169 'Mostimages' => array( 'SpecialPage', 'Mostimages' ),
170 'Mostlinked' => array( 'SpecialPage', 'Mostlinked' ),
171 'Mostlinkedtemplates' => array( 'SpecialPage', 'Mostlinkedtemplates' ),
172 'Mostcategories' => array( 'SpecialPage', 'Mostcategories' ),
173 'Mostrevisions' => array( 'SpecialPage', 'Mostrevisions' ),
176 'ComparePages' => 'SpecialComparePages',
177 'Export' => 'SpecialExport',
178 'Import' => 'SpecialImport',
179 'Undelete' => 'UndeleteForm',
180 'Whatlinkshere' => 'SpecialWhatlinkshere',
181 'MergeHistory' => 'SpecialMergeHistory',
184 'Booksources' => 'SpecialBookSources',
186 # Unlisted / redirects
187 'Blankpage' => 'SpecialBlankpage',
188 'Blockme' => 'SpecialBlockme',
189 'Emailuser' => 'SpecialEmailUser',
190 'Movepage' => 'MovePageForm',
191 'Mycontributions' => 'SpecialMycontributions',
192 'Mypage' => 'SpecialMypage',
193 'Mytalk' => 'SpecialMytalk',
194 'Myuploads' => 'SpecialMyuploads',
195 'Revisiondelete' => 'SpecialRevisionDelete',
196 'RevisionMove' => 'SpecialRevisionMove',
197 'Specialpages' => 'SpecialSpecialpages',
198 'Userlogout' => 'SpecialUserlogout',
201 static public $mAliases;
202 static public $mListInitialised = false;
207 * Initialise the special page list
208 * This must be called before accessing SpecialPage::$mList
210 static function initList() {
211 global $wgSpecialPages;
212 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
214 if ( self
::$mListInitialised ) {
217 wfProfileIn( __METHOD__
);
219 # Better to set this now, to avoid infinite recursion in carelessly written hooks
220 self
::$mListInitialised = true;
222 if( !$wgDisableCounters ) {
223 self
::$mList['Popularpages'] = array( 'SpecialPage', 'Popularpages' );
226 if( !$wgDisableInternalSearch ) {
227 self
::$mList['Search'] = array( 'SpecialPage', 'Search' );
230 if( $wgEmailAuthentication ) {
231 self
::$mList['Confirmemail'] = 'EmailConfirmation';
232 self
::$mList['Invalidateemail'] = 'EmailInvalidation';
235 # Add extension special pages
236 self
::$mList = array_merge( self
::$mList, $wgSpecialPages );
239 # This hook can be used to remove undesired built-in special pages
240 wfRunHooks( 'SpecialPage_initList', array( &self
::$mList ) );
241 wfProfileOut( __METHOD__
);
244 static function initAliasList() {
245 if ( !is_null( self
::$mAliases ) ) {
250 $aliases = $wgContLang->getSpecialPageAliases();
251 $missingPages = self
::$mList;
252 self
::$mAliases = array();
253 foreach ( $aliases as $realName => $aliasList ) {
254 foreach ( $aliasList as $alias ) {
255 self
::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
257 unset( $missingPages[$realName] );
259 foreach ( $missingPages as $name => $stuff ) {
260 self
::$mAliases[$wgContLang->caseFold( $name )] = $name;
265 * Given a special page alias, return the special page name.
266 * Returns false if there is no such alias.
268 * @param $alias String
269 * @return String or false
271 static function resolveAlias( $alias ) {
274 if ( !self
::$mListInitialised ) self
::initList();
275 if ( is_null( self
::$mAliases ) ) self
::initAliasList();
276 $caseFoldedAlias = $wgContLang->caseFold( $alias );
277 $caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
278 if ( isset( self
::$mAliases[$caseFoldedAlias] ) ) {
279 return self
::$mAliases[$caseFoldedAlias];
286 * Given a special page name with a possible subpage, return an array
287 * where the first element is the special page name and the second is the
290 * @param $alias String
293 static function resolveAliasWithSubpage( $alias ) {
294 $bits = explode( '/', $alias, 2 );
295 $name = self
::resolveAlias( $bits[0] );
296 if( !isset( $bits[1] ) ) { // bug 2087
301 return array( $name, $par );
305 * Add a page to the list of valid special pages. This used to be the preferred
306 * method for adding special pages in extensions. It's now suggested that you add
307 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
309 * @param $page SpecialPage
310 * Deprecated in 1.7, warnings in 1.17, might be removed in 1.20
312 static function addPage( &$page ) {
313 wfDeprecated( __METHOD__
);
314 if ( !self
::$mListInitialised ) {
317 self
::$mList[$page->mName
] = $page;
321 * Add a page to a certain display group for Special:SpecialPages
323 * @param $page Mixed: SpecialPage or string
324 * @param $group String
326 static function setGroup( $page, $group ) {
327 global $wgSpecialPageGroups;
328 $name = is_object($page) ?
$page->mName
: $page;
329 $wgSpecialPageGroups[$name] = $group;
333 * Add a page to a certain display group for Special:SpecialPages
335 * @param $page SpecialPage
337 static function getGroup( &$page ) {
338 global $wgSpecialPageGroups;
339 static $specialPageGroupsCache = array();
340 if( isset($specialPageGroupsCache[$page->mName
]) ) {
341 return $specialPageGroupsCache[$page->mName
];
343 $group = wfMsg('specialpages-specialpagegroup-'.strtolower($page->mName
));
345 ||
wfEmptyMsg('specialpages-specialpagegroup-'.strtolower($page->mName
), $group ) ) {
346 $group = isset($wgSpecialPageGroups[$page->mName
])
347 ?
$wgSpecialPageGroups[$page->mName
]
350 if( $group == '-' ) $group = 'other';
351 $specialPageGroupsCache[$page->mName
] = $group;
356 * Remove a special page from the list
357 * Formerly used to disable expensive or dangerous special pages. The
358 * preferred method is now to add a SpecialPage_initList hook.
360 static function removePage( $name ) {
361 if ( !self
::$mListInitialised ) {
364 unset( self
::$mList[$name] );
368 * Check if a given name exist as a special page or as a special page alias
370 * @param $name String: name of a special page
371 * @return Boolean: true if a special page exists with this name
373 static function exists( $name ) {
375 if ( !self
::$mListInitialised ) {
378 if( !self
::$mAliases ) {
379 self
::initAliasList();
382 # Remove special pages inline parameters:
383 $bits = explode( '/', $name );
384 $name = $wgContLang->caseFold($bits[0]);
387 array_key_exists( $name, self
::$mList )
388 or array_key_exists( $name, self
::$mAliases )
393 * Find the object with a given name and return it (or NULL)
395 * @param $name String
396 * @return SpecialPage object or null if the page doesn't exist
398 static function getPage( $name ) {
399 if ( !self
::$mListInitialised ) {
402 if ( array_key_exists( $name, self
::$mList ) ) {
403 $rec = self
::$mList[$name];
404 if ( is_string( $rec ) ) {
406 self
::$mList[$name] = new $className;
407 } elseif ( is_array( $rec ) ) {
408 $className = array_shift( $rec );
409 self
::$mList[$name] = wfCreateObject( $className, $rec );
411 return self
::$mList[$name];
418 * Get a special page with a given localised name, or NULL if there
419 * is no such special page.
421 * @return SpecialPage object or null if the page doesn't exist
423 static function getPageByAlias( $alias ) {
424 $realName = self
::resolveAlias( $alias );
426 return self
::getPage( $realName );
433 * Return categorised listable special pages which are available
434 * for the current user, and everyone.
436 * @return Associative array mapping page's name to its SpecialPage object
438 static function getUsablePages() {
440 if ( !self
::$mListInitialised ) {
445 foreach ( self
::$mList as $name => $rec ) {
446 $page = self
::getPage( $name );
447 if ( $page->isListed()
449 !$page->isRestricted()
450 ||
$page->userCanExecute( $wgUser )
453 $pages[$name] = $page;
460 * Return categorised listable special pages for all users
462 * @return Associative array mapping page's name to its SpecialPage object
464 static function getRegularPages() {
465 if ( !self
::$mListInitialised ) {
470 foreach ( self
::$mList as $name => $rec ) {
471 $page = self
::getPage( $name );
472 if ( $page->isListed() && !$page->isRestricted() ) {
473 $pages[$name] = $page;
480 * Return categorised listable special pages which are available
481 * for the current user, but not for everyone
483 * @return Associative array mapping page's name to its SpecialPage object
485 static function getRestrictedPages() {
487 if( !self
::$mListInitialised ) {
492 foreach( self
::$mList as $name => $rec ) {
493 $page = self
::getPage( $name );
496 && $page->isRestricted()
497 && $page->userCanExecute( $wgUser )
499 $pages[$name] = $page;
506 * Execute a special page path.
507 * The path may contain parameters, e.g. Special:Name/Params
508 * Extracts the special page name and call the execute method, passing the parameters
510 * Returns a title object if the page is redirected, false if there was no such special
511 * page, and true if it was successful.
513 * @param $title a title object
514 * @param $including output is being captured for use in {{special:whatever}}
516 static function executePath( &$title, $including = false ) {
517 global $wgOut, $wgTitle, $wgRequest;
518 wfProfileIn( __METHOD__
);
520 # FIXME: redirects broken due to this call
521 $bits = explode( '/', $title->getDBkey(), 2 );
523 if( !isset( $bits[1] ) ) { // bug 2087
528 $page = SpecialPage
::getPageByAlias( $name );
532 $wgOut->setArticleRelated( false );
533 $wgOut->setRobotPolicy( 'noindex,nofollow' );
534 $wgOut->setStatusCode( 404 );
535 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
537 wfProfileOut( __METHOD__
);
543 $redirect = $page->getRedirect( $par );
545 $query = $page->getRedirectQuery();
546 $url = $redirect->getFullUrl( $query );
547 $wgOut->redirect( $url );
548 wfProfileOut( __METHOD__
);
553 # Redirect to canonical alias for GET commands
554 # Not for POST, we'd lose the post data, so it's best to just distribute
555 # the request. Such POST requests are possible for old extensions that
556 # generate self-links without being aware that their default name has
558 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
560 unset( $query['title'] );
561 $query = wfArrayToCGI( $query );
562 $title = $page->getTitle( $par );
563 $url = $title->getFullUrl( $query );
564 $wgOut->redirect( $url );
565 wfProfileOut( __METHOD__
);
569 if ( $including && !$page->includable() ) {
570 wfProfileOut( __METHOD__
);
572 } elseif ( !$including ) {
573 $wgTitle = $page->getTitle();
575 $page->including( $including );
577 // Execute special page
578 $profName = 'Special:' . $page->name();
579 wfProfileIn( $profName );
580 $page->execute( $par );
581 wfProfileOut( $profName );
582 wfProfileOut( __METHOD__
);
587 * Just like executePath() except it returns the HTML instead of outputting it
588 * Returns false if there was no such special page, or a title object if it was
591 * @return String: HTML fragment
593 static function capturePath( &$title ) {
594 global $wgOut, $wgTitle;
596 $oldTitle = $wgTitle;
598 $wgOut = new OutputPage
;
599 $wgOut->setTitle( $title );
601 $ret = SpecialPage
::executePath( $title, true );
602 if ( $ret === true ) {
603 $ret = $wgOut->getHTML();
605 $wgTitle = $oldTitle;
611 * Get the local name for a specified canonical name
613 * @param $name String
614 * @param $subpage Mixed: boolean false, or string
618 static function getLocalNameFor( $name, $subpage = false ) {
620 $aliases = $wgContLang->getSpecialPageAliases();
621 if ( isset( $aliases[$name][0] ) ) {
622 $name = $aliases[$name][0];
624 // Try harder in case someone misspelled the correct casing
626 foreach ( $aliases as $n => $values ) {
627 if ( strcasecmp( $name, $n ) === 0 ) {
628 wfWarn( "Found alias defined for $n when searching for" .
629 "special page aliases for $name. Case mismatch?" );
636 wfWarn( "Did not find alias for special page '$name'. " .
637 "Perhaps no aliases are defined for it?" );
640 if ( $subpage !== false && !is_null( $subpage ) ) {
641 $name = "$name/$subpage";
643 return $wgContLang->ucfirst( $name );
647 * Get a localised Title object for a specified special page name
649 * @return Title object
651 static function getTitleFor( $name, $subpage = false ) {
652 $name = self
::getLocalNameFor( $name, $subpage );
654 return Title
::makeTitle( NS_SPECIAL
, $name );
656 throw new MWException( "Invalid special page name \"$name\"" );
661 * Get a localised Title object for a page name with a possibly unvalidated subpage
663 * @return Title object or null if the page doesn't exist
665 static function getSafeTitleFor( $name, $subpage = false ) {
666 $name = self
::getLocalNameFor( $name, $subpage );
668 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
675 * Get a title for a given alias
677 * @return Title or null if there is no such alias
679 static function getTitleForAlias( $alias ) {
680 $name = self
::resolveAlias( $alias );
682 return self
::getTitleFor( $name );
689 * Default constructor for special pages
690 * Derivative classes should call this from their constructor
691 * Note that if the user does not have the required level, an error message will
692 * be displayed by the default execute() method, without the global function ever
695 * If you override execute(), you can recover the default behaviour with userCanExecute()
696 * and displayRestrictionError()
698 * @param $name String: name of the special page, as seen in links and URLs
699 * @param $restriction String: user right required, e.g. "block" or "delete"
700 * @param $listed Boolean: whether the page is listed in Special:Specialpages
701 * @param $function Callback: function called by execute(). By default it is constructed from $name
702 * @param $file String: file which is included by execute(). It is also constructed from $name by default
703 * @param $includable Boolean: whether the page can be included in normal pages
705 function __construct( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
706 $this->mName
= $name;
707 $this->mRestriction
= $restriction;
708 $this->mListed
= $listed;
709 $this->mIncludable
= $includable;
711 $this->mFunction
= 'wfSpecial'.$name;
713 $this->mFunction
= $function;
715 if ( $file === 'default' ) {
716 $this->mFile
= dirname(__FILE__
) . "/specials/Special$name.php";
718 $this->mFile
= $file;
727 function getName() { return $this->mName
; }
728 function getRestriction() { return $this->mRestriction
; }
729 function getFile() { return $this->mFile
; }
730 function isListed() { return $this->mListed
; }
734 * Accessor and mutator
736 function name( $x = null ) { return wfSetVar( $this->mName
, $x ); }
737 function restrictions( $x = null) {
738 # Use the one below this
739 wfDeprecated( __METHOD__
);
740 return wfSetVar( $this->mRestriction
, $x );
742 function restriction( $x = null) { return wfSetVar( $this->mRestriction
, $x ); }
743 function listed( $x = null) { return wfSetVar( $this->mListed
, $x ); }
744 function func( $x = null) { return wfSetVar( $this->mFunction
, $x ); }
745 function file( $x = null) { return wfSetVar( $this->mFile
, $x ); }
746 function includable( $x = null ) { return wfSetVar( $this->mIncludable
, $x ); }
747 function including( $x = null ) { return wfSetVar( $this->mIncluding
, $x ); }
751 * Get the localised name of the special page
753 function getLocalName() {
754 if ( !isset( $this->mLocalName
) ) {
755 $this->mLocalName
= self
::getLocalNameFor( $this->mName
);
757 return $this->mLocalName
;
761 * Can be overridden by subclasses with more complicated permissions
764 * @return Boolean: should the page be displayed with the restricted-access
767 public function isRestricted() {
768 global $wgGroupPermissions;
769 // DWIM: If all anons can do something, then it is not restricted
770 return $this->mRestriction
!= '' && empty($wgGroupPermissions['*'][$this->mRestriction
]);
774 * Checks if the given user (identified by an object) can execute this
775 * special page (as defined by $mRestriction). Can be overridden by sub-
776 * classes with more complicated permissions schemes.
778 * @param $user User: the user to check
779 * @return Boolean: does the user have permission to view the page?
781 public function userCanExecute( $user ) {
782 return $user->isAllowed( $this->mRestriction
);
786 * Output an error message telling the user what access level they have to have
788 function displayRestrictionError() {
790 $wgOut->permissionRequired( $this->mRestriction
);
794 * Sets headers - this should be called from the execute() method of all derived classes!
796 function setHeaders() {
798 $wgOut->setArticleRelated( false );
799 $wgOut->setRobotPolicy( "noindex,nofollow" );
800 $wgOut->setPageTitle( $this->getDescription() );
804 * Default execute method
805 * Checks user permissions, calls the function given in mFunction
807 * This may be overridden by subclasses.
809 function execute( $par ) {
814 if ( $this->userCanExecute( $wgUser ) ) {
815 $func = $this->mFunction
;
816 // only load file if the function does not exist
817 if(!is_callable($func) and $this->mFile
) {
818 require_once( $this->mFile
);
820 $this->outputHeader();
821 call_user_func( $func, $par, $this );
823 $this->displayRestrictionError();
828 * Outputs a summary message on top of special pages
829 * Per default the message key is the canonical name of the special page
830 * May be overriden, i.e. by extensions to stick with the naming conventions
831 * for message keys: 'extensionname-xxx'
833 * @param $summaryMessageKey String: message key of the summary
835 function outputHeader( $summaryMessageKey = '' ) {
836 global $wgOut, $wgContLang;
838 if( $summaryMessageKey == '' ) {
839 $msg = $wgContLang->lc( $this->name() ) . '-summary';
841 $msg = $summaryMessageKey;
843 $out = wfMsgNoTrans( $msg );
844 if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() ) {
845 $wgOut->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
851 * Returns the name that goes in the \<h1\> in the special page itself, and
852 * also the name that will be listed in Special:Specialpages
854 * Derived classes can override this, but usually it is easier to keep the
855 * default behaviour. Messages can be added at run-time, see
860 function getDescription() {
861 return wfMsg( strtolower( $this->mName
) );
865 * Get a self-referential title object
867 * @return Title object
869 function getTitle( $subpage = false ) {
870 return self
::getTitleFor( $this->mName
, $subpage );
874 * Set whether this page is listed in Special:Specialpages, at run-time
876 function setListed( $listed ) {
877 return wfSetVar( $this->mListed
, $listed );
881 * If the special page is a redirect, then get the Title object it redirects to.
884 function getRedirect( $subpage ) {
889 * Return part of the request string for a special redirect page
890 * This allows passing, e.g. action=history to Special:Mypage, etc.
894 function getRedirectQuery() {
897 foreach( $this->mAllowedRedirectParams
as $arg ) {
898 if( ( $val = $wgRequest->getVal( $arg, null ) ) !== null )
899 $params[] = $arg . '=' . $val;
902 foreach( $this->mAddedRedirectParams
as $arg => $val ) {
903 $params[] = $arg . '=' . $val;
906 return count( $params ) ?
implode( '&', $params ) : false;
911 * Shortcut to construct a special page which is unlisted by default
912 * @ingroup SpecialPage
914 class UnlistedSpecialPage
extends SpecialPage
916 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
917 parent
::__construct( $name, $restriction, false, $function, $file );
922 * Shortcut to construct an includable special page
923 * @ingroup SpecialPage
925 class IncludableSpecialPage
extends SpecialPage
927 function __construct( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
928 parent
::__construct( $name, $restriction, $listed, $function, $file, true );
933 * Shortcut to construct a special page alias.
934 * @ingroup SpecialPage
936 class SpecialRedirectToSpecial
extends UnlistedSpecialPage
{
937 var $redirName, $redirSubpage;
939 function __construct( $name, $redirName, $redirSubpage = false, $allowedRedirectParams = array(), $addedRedirectParams = array() ) {
940 parent
::__construct( $name );
941 $this->redirName
= $redirName;
942 $this->redirSubpage
= $redirSubpage;
943 $this->mAllowedRedirectParams
= $allowedRedirectParams;
944 $this->mAddedRedirectParams
= $addedRedirectParams;
947 function getRedirect( $subpage ) {
948 if ( $this->redirSubpage
=== false ) {
949 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
951 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
956 /** SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
957 * are used to get user independant links pointing to the user page, talk
958 * page and list of contributions.
959 * This can let us cache a single copy of any generated content for all
964 * Shortcut to construct a special page pointing to current user user's page.
965 * @ingroup SpecialPage
967 class SpecialMypage
extends UnlistedSpecialPage
{
968 function __construct() {
969 parent
::__construct( 'Mypage' );
970 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro',
971 'section', 'oldid', 'diff', 'dir' );
974 function getRedirect( $subpage ) {
976 if ( strval( $subpage ) !== '' ) {
977 return Title
::makeTitle( NS_USER
, $wgUser->getName() . '/' . $subpage );
979 return Title
::makeTitle( NS_USER
, $wgUser->getName() );
985 * Shortcut to construct a special page pointing to current user talk page.
986 * @ingroup SpecialPage
988 class SpecialMytalk
extends UnlistedSpecialPage
{
989 function __construct() {
990 parent
::__construct( 'Mytalk' );
991 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro',
992 'section', 'oldid', 'diff', 'dir' );
995 function getRedirect( $subpage ) {
997 if ( strval( $subpage ) !== '' ) {
998 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() . '/' . $subpage );
1000 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() );
1006 * Shortcut to construct a special page pointing to current user contributions.
1007 * @ingroup SpecialPage
1009 class SpecialMycontributions
extends UnlistedSpecialPage
{
1010 function __construct() {
1011 parent
::__construct( 'Mycontributions' );
1012 $this->mAllowedRedirectParams
= array( 'limit', 'namespace', 'tagfilter',
1013 'offset', 'dir', 'year', 'month', 'feed' );
1016 function getRedirect( $subpage ) {
1018 return SpecialPage
::getTitleFor( 'Contributions', $wgUser->getName() );
1023 * Redirect to Special:Listfiles?user=$wgUser
1025 class SpecialMyuploads
extends UnlistedSpecialPage
{
1026 function __construct() {
1027 parent
::__construct( 'Myuploads' );
1028 $this->mAllowedRedirectParams
= array( 'limit' );
1031 function getRedirect( $subpage ) {
1033 return SpecialPage
::getTitleFor( 'Listfiles', $wgUser->getName() );