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;
210 global $wgEnableSelenium;
212 if ( self
::$mListInitialised ) {
215 wfProfileIn( __METHOD__
);
217 # Better to set this now, to avoid infinite recursion in carelessly written hooks
218 self
::$mListInitialised = true;
220 if( !$wgDisableCounters ) {
221 self
::$mList['Popularpages'] = array( 'SpecialPage', 'Popularpages' );
224 if( !$wgDisableInternalSearch ) {
225 self
::$mList['Search'] = array( 'SpecialPage', 'Search' );
228 if( $wgEmailAuthentication ) {
229 self
::$mList['Confirmemail'] = 'EmailConfirmation';
230 self
::$mList['Invalidateemail'] = 'EmailInvalidation';
233 if ( $wgEnableSelenium ) {
234 self
::$mList['Selenium'] = 'SpecialSelenium';
237 # Add extension special pages
238 self
::$mList = array_merge( self
::$mList, $wgSpecialPages );
241 # This hook can be used to remove undesired built-in special pages
242 wfRunHooks( 'SpecialPage_initList', array( &self
::$mList ) );
243 wfProfileOut( __METHOD__
);
246 static function initAliasList() {
247 if ( !is_null( self
::$mAliases ) ) {
252 $aliases = $wgContLang->getSpecialPageAliases();
253 $missingPages = self
::$mList;
254 self
::$mAliases = array();
255 foreach ( $aliases as $realName => $aliasList ) {
256 foreach ( $aliasList as $alias ) {
257 self
::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
259 unset( $missingPages[$realName] );
261 foreach ( $missingPages as $name => $stuff ) {
262 self
::$mAliases[$wgContLang->caseFold( $name )] = $name;
267 * Given a special page alias, return the special page name.
268 * Returns false if there is no such alias.
270 * @param $alias String
271 * @return String or false
273 static function resolveAlias( $alias ) {
276 if ( !self
::$mListInitialised ) self
::initList();
277 if ( is_null( self
::$mAliases ) ) self
::initAliasList();
278 $caseFoldedAlias = $wgContLang->caseFold( $alias );
279 if ( isset( self
::$mAliases[$caseFoldedAlias] ) ) {
280 return self
::$mAliases[$caseFoldedAlias];
287 * Given a special page name with a possible subpage, return an array
288 * where the first element is the special page name and the second is the
291 * @param $alias String
294 static function resolveAliasWithSubpage( $alias ) {
295 $bits = explode( '/', $alias, 2 );
296 $name = self
::resolveAlias( $bits[0] );
297 if( !isset( $bits[1] ) ) { // bug 2087
302 return array( $name, $par );
306 * Add a page to the list of valid special pages. This used to be the preferred
307 * method for adding special pages in extensions. It's now suggested that you add
308 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
310 * @param $page SpecialPage
311 * Deprecated in 1.7, warnings in 1.17, might be removed in 1.20
313 static function addPage( &$page ) {
314 wfDeprecated( __METHOD__
);
315 if ( !self
::$mListInitialised ) {
318 self
::$mList[$page->mName
] = $page;
322 * Add a page to a certain display group for Special:SpecialPages
324 * @param $page Mixed: SpecialPage or string
325 * @param $group String
327 static function setGroup( $page, $group ) {
328 global $wgSpecialPageGroups;
329 $name = is_object($page) ?
$page->mName
: $page;
330 $wgSpecialPageGroups[$name] = $group;
334 * Add a page to a certain display group for Special:SpecialPages
336 * @param $page SpecialPage
338 static function getGroup( &$page ) {
339 global $wgSpecialPageGroups;
340 static $specialPageGroupsCache = array();
341 if( isset($specialPageGroupsCache[$page->mName
]) ) {
342 return $specialPageGroupsCache[$page->mName
];
344 $group = wfMsg('specialpages-specialpagegroup-'.strtolower($page->mName
));
346 ||
wfEmptyMsg('specialpages-specialpagegroup-'.strtolower($page->mName
), $group ) ) {
347 $group = isset($wgSpecialPageGroups[$page->mName
])
348 ?
$wgSpecialPageGroups[$page->mName
]
351 if( $group == '-' ) $group = 'other';
352 $specialPageGroupsCache[$page->mName
] = $group;
357 * Remove a special page from the list
358 * Formerly used to disable expensive or dangerous special pages. The
359 * preferred method is now to add a SpecialPage_initList hook.
361 static function removePage( $name ) {
362 if ( !self
::$mListInitialised ) {
365 unset( self
::$mList[$name] );
369 * Check if a given name exist as a special page or as a special page alias
371 * @param $name String: name of a special page
372 * @return Boolean: true if a special page exists with this name
374 static function exists( $name ) {
376 if ( !self
::$mListInitialised ) {
379 if( !self
::$mAliases ) {
380 self
::initAliasList();
383 # Remove special pages inline parameters:
384 $bits = explode( '/', $name );
385 $name = $wgContLang->caseFold($bits[0]);
388 array_key_exists( $name, self
::$mList )
389 or array_key_exists( $name, self
::$mAliases )
394 * Find the object with a given name and return it (or NULL)
396 * @param $name String
397 * @return SpecialPage object or null if the page doesn't exist
399 static function getPage( $name ) {
400 if ( !self
::$mListInitialised ) {
403 if ( array_key_exists( $name, self
::$mList ) ) {
404 $rec = self
::$mList[$name];
405 if ( is_string( $rec ) ) {
407 self
::$mList[$name] = new $className;
408 } elseif ( is_array( $rec ) ) {
409 $className = array_shift( $rec );
410 self
::$mList[$name] = wfCreateObject( $className, $rec );
412 return self
::$mList[$name];
419 * Get a special page with a given localised name, or NULL if there
420 * is no such special page.
422 * @return SpecialPage object or null if the page doesn't exist
424 static function getPageByAlias( $alias ) {
425 $realName = self
::resolveAlias( $alias );
427 return self
::getPage( $realName );
434 * Return categorised listable special pages which are available
435 * for the current user, and everyone.
437 * @return Associative array mapping page's name to its SpecialPage object
439 static function getUsablePages() {
441 if ( !self
::$mListInitialised ) {
446 foreach ( self
::$mList as $name => $rec ) {
447 $page = self
::getPage( $name );
448 if ( $page->isListed()
450 !$page->isRestricted()
451 ||
$page->userCanExecute( $wgUser )
454 $pages[$name] = $page;
461 * Return categorised listable special pages for all users
463 * @return Associative array mapping page's name to its SpecialPage object
465 static function getRegularPages() {
466 if ( !self
::$mListInitialised ) {
471 foreach ( self
::$mList as $name => $rec ) {
472 $page = self
::getPage( $name );
473 if ( $page->isListed() && !$page->isRestricted() ) {
474 $pages[$name] = $page;
481 * Return categorised listable special pages which are available
482 * for the current user, but not for everyone
484 * @return Associative array mapping page's name to its SpecialPage object
486 static function getRestrictedPages() {
488 if( !self
::$mListInitialised ) {
493 foreach( self
::$mList as $name => $rec ) {
494 $page = self
::getPage( $name );
497 && $page->isRestricted()
498 && $page->userCanExecute( $wgUser )
500 $pages[$name] = $page;
507 * Execute a special page path.
508 * The path may contain parameters, e.g. Special:Name/Params
509 * Extracts the special page name and call the execute method, passing the parameters
511 * Returns a title object if the page is redirected, false if there was no such special
512 * page, and true if it was successful.
514 * @param $title a title object
515 * @param $including output is being captured for use in {{special:whatever}}
517 static function executePath( &$title, $including = false ) {
518 global $wgOut, $wgTitle, $wgRequest;
519 wfProfileIn( __METHOD__
);
521 # FIXME: redirects broken due to this call
522 $bits = explode( '/', $title->getDBkey(), 2 );
524 if( !isset( $bits[1] ) ) { // bug 2087
529 $page = SpecialPage
::getPageByAlias( $name );
533 $wgOut->setArticleRelated( false );
534 $wgOut->setRobotPolicy( 'noindex,nofollow' );
535 $wgOut->setStatusCode( 404 );
536 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
538 wfProfileOut( __METHOD__
);
544 $redirect = $page->getRedirect( $par );
546 $query = $page->getRedirectQuery();
547 $url = $redirect->getFullUrl( $query );
548 $wgOut->redirect( $url );
549 wfProfileOut( __METHOD__
);
554 # Redirect to canonical alias for GET commands
555 # Not for POST, we'd lose the post data, so it's best to just distribute
556 # the request. Such POST requests are possible for old extensions that
557 # generate self-links without being aware that their default name has
559 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
561 unset( $query['title'] );
562 $query = wfArrayToCGI( $query );
563 $title = $page->getTitle( $par );
564 $url = $title->getFullUrl( $query );
565 $wgOut->redirect( $url );
566 wfProfileOut( __METHOD__
);
570 if ( $including && !$page->includable() ) {
571 wfProfileOut( __METHOD__
);
573 } elseif ( !$including ) {
574 $wgTitle = $page->getTitle();
576 $page->including( $including );
578 // Execute special page
579 $profName = 'Special:' . $page->getName();
580 wfProfileIn( $profName );
581 $page->execute( $par );
582 wfProfileOut( $profName );
583 wfProfileOut( __METHOD__
);
588 * Just like executePath() except it returns the HTML instead of outputting it
589 * Returns false if there was no such special page, or a title object if it was
592 * @return String: HTML fragment
594 static function capturePath( &$title ) {
595 global $wgOut, $wgTitle;
597 $oldTitle = $wgTitle;
599 $wgOut = new OutputPage
;
600 $wgOut->setTitle( $title );
602 $ret = SpecialPage
::executePath( $title, true );
603 if ( $ret === true ) {
604 $ret = $wgOut->getHTML();
606 $wgTitle = $oldTitle;
612 * Get the local name for a specified canonical name
614 * @param $name String
615 * @param $subpage Mixed: boolean false, or string
619 static function getLocalNameFor( $name, $subpage = false ) {
621 $aliases = $wgContLang->getSpecialPageAliases();
622 if ( isset( $aliases[$name][0] ) ) {
623 $name = $aliases[$name][0];
625 // Try harder in case someone misspelled the correct casing
627 foreach ( $aliases as $n => $values ) {
628 if ( strcasecmp( $name, $n ) === 0 ) {
629 wfWarn( "Found alias defined for $n when searching for" .
630 "special page aliases for $name. Case mismatch?" );
637 wfWarn( "Did not find alias for special page '$name'." .
638 "Perhaps no aliases are defined for it?" );
641 if ( $subpage !== false && !is_null( $subpage ) ) {
642 $name = "$name/$subpage";
644 return $wgContLang->ucfirst( $name );
648 * Get a localised Title object for a specified special page name
650 * @return Title object
652 static function getTitleFor( $name, $subpage = false ) {
653 $name = self
::getLocalNameFor( $name, $subpage );
655 return Title
::makeTitle( NS_SPECIAL
, $name );
657 throw new MWException( "Invalid special page name \"$name\"" );
662 * Get a localised Title object for a page name with a possibly unvalidated subpage
664 * @return Title object or null if the page doesn't exist
666 static function getSafeTitleFor( $name, $subpage = false ) {
667 $name = self
::getLocalNameFor( $name, $subpage );
669 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
676 * Get a title for a given alias
678 * @return Title or null if there is no such alias
680 static function getTitleForAlias( $alias ) {
681 $name = self
::resolveAlias( $alias );
683 return self
::getTitleFor( $name );
690 * Default constructor for special pages
691 * Derivative classes should call this from their constructor
692 * Note that if the user does not have the required level, an error message will
693 * be displayed by the default execute() method, without the global function ever
696 * If you override execute(), you can recover the default behaviour with userCanExecute()
697 * and displayRestrictionError()
699 * @param $name String: name of the special page, as seen in links and URLs
700 * @param $restriction String: user right required, e.g. "block" or "delete"
701 * @param $listed Boolean: whether the page is listed in Special:Specialpages
702 * @param $function Callback: function called by execute(). By default it is constructed from $name
703 * @param $file String: file which is included by execute(). It is also constructed from $name by default
704 * @param $includable Boolean: whether the page can be included in normal pages
706 function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
707 $this->mName
= $name;
708 $this->mRestriction
= $restriction;
709 $this->mListed
= $listed;
710 $this->mIncludable
= $includable;
712 $this->mFunction
= 'wfSpecial'.$name;
714 $this->mFunction
= $function;
716 if ( $file === 'default' ) {
717 $this->mFile
= dirname(__FILE__
) . "/specials/Special$name.php";
719 $this->mFile
= $file;
728 function getName() { return $this->mName
; }
729 function getRestriction() { return $this->mRestriction
; }
730 function getFile() { return $this->mFile
; }
731 function isListed() { return $this->mListed
; }
735 * Accessor and mutator
737 function name( $x = null ) { return wfSetVar( $this->mName
, $x ); }
738 function restrictions( $x = null) {
739 # Use the one below this
740 wfDeprecated( __METHOD__
);
741 return wfSetVar( $this->mRestriction
, $x );
743 function restriction( $x = null) { return wfSetVar( $this->mRestriction
, $x ); }
744 function listed( $x = null) { return wfSetVar( $this->mListed
, $x ); }
745 function func( $x = null) { return wfSetVar( $this->mFunction
, $x ); }
746 function file( $x = null) { return wfSetVar( $this->mFile
, $x ); }
747 function includable( $x = null ) { return wfSetVar( $this->mIncludable
, $x ); }
748 function including( $x = null ) { return wfSetVar( $this->mIncluding
, $x ); }
752 * Get the localised name of the special page
754 function getLocalName() {
755 if ( !isset( $this->mLocalName
) ) {
756 $this->mLocalName
= self
::getLocalNameFor( $this->mName
);
758 return $this->mLocalName
;
762 * Can be overridden by subclasses with more complicated permissions
765 * @return Boolean: should the page be displayed with the restricted-access
768 public function isRestricted() {
769 global $wgGroupPermissions;
770 // DWIM: If all anons can do something, then it is not restricted
771 return $this->mRestriction
!= '' && empty($wgGroupPermissions['*'][$this->mRestriction
]);
775 * Checks if the given user (identified by an object) can execute this
776 * special page (as defined by $mRestriction). Can be overridden by sub-
777 * classes with more complicated permissions schemes.
779 * @param $user User: the user to check
780 * @return Boolean: does the user have permission to view the page?
782 public function userCanExecute( $user ) {
783 return $user->isAllowed( $this->mRestriction
);
787 * Output an error message telling the user what access level they have to have
789 function displayRestrictionError() {
791 $wgOut->permissionRequired( $this->mRestriction
);
795 * Sets headers - this should be called from the execute() method of all derived classes!
797 function setHeaders() {
799 $wgOut->setArticleRelated( false );
800 $wgOut->setRobotPolicy( "noindex,nofollow" );
801 $wgOut->setPageTitle( $this->getDescription() );
805 * Default execute method
806 * Checks user permissions, calls the function given in mFunction
808 * This may be overridden by subclasses.
810 function execute( $par ) {
815 if ( $this->userCanExecute( $wgUser ) ) {
816 $func = $this->mFunction
;
817 // only load file if the function does not exist
818 if(!is_callable($func) and $this->mFile
) {
819 require_once( $this->mFile
);
821 $this->outputHeader();
822 call_user_func( $func, $par, $this );
824 $this->displayRestrictionError();
829 * Outputs a summary message on top of special pages
830 * Per default the message key is the canonical name of the special page
831 * May be overriden, i.e. by extensions to stick with the naming conventions
832 * for message keys: 'extensionname-xxx'
834 * @param $summaryMessageKey String: message key of the summary
836 function outputHeader( $summaryMessageKey = '' ) {
837 global $wgOut, $wgContLang;
839 if( $summaryMessageKey == '' ) {
840 $msg = $wgContLang->lc( $this->name() ) . '-summary';
842 $msg = $summaryMessageKey;
844 $out = wfMsgNoTrans( $msg );
845 if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() ) {
846 $wgOut->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
852 * Returns the name that goes in the \<h1\> in the special page itself, and
853 * also the name that will be listed in Special:Specialpages
855 * Derived classes can override this, but usually it is easier to keep the
856 * default behaviour. Messages can be added at run-time, see
861 function getDescription() {
862 return wfMsg( strtolower( $this->mName
) );
866 * Get a self-referential title object
868 * @return Title object
870 function getTitle( $subpage = false ) {
871 return self
::getTitleFor( $this->mName
, $subpage );
875 * Set whether this page is listed in Special:Specialpages, at run-time
877 function setListed( $listed ) {
878 return wfSetVar( $this->mListed
, $listed );
882 * If the special page is a redirect, then get the Title object it redirects to.
885 function getRedirect( $subpage ) {
890 * Return part of the request string for a special redirect page
891 * This allows passing, e.g. action=history to Special:Mypage, etc.
895 function getRedirectQuery() {
898 foreach( $this->mAllowedRedirectParams
as $arg ) {
899 if( ( $val = $wgRequest->getVal( $arg, null ) ) !== null )
900 $params[] = $arg . '=' . $val;
903 foreach( $this->mAddedRedirectParams
as $arg => $val ) {
904 $params[] = $arg . '=' . $val;
907 return count( $params ) ?
implode( '&', $params ) : false;
912 * Shortcut to construct a special page which is unlisted by default
913 * @ingroup SpecialPage
915 class UnlistedSpecialPage
extends SpecialPage
917 function UnlistedSpecialPage( $name, $restriction = '', $function = false, $file = 'default' ) {
918 parent
::SpecialPage( $name, $restriction, false, $function, $file );
923 * Shortcut to construct an includable special page
924 * @ingroup SpecialPage
926 class IncludableSpecialPage
extends SpecialPage
928 function IncludableSpecialPage( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
929 parent
::SpecialPage( $name, $restriction, $listed, $function, $file, true );
934 * Shortcut to construct a special page alias.
935 * @ingroup SpecialPage
937 class SpecialRedirectToSpecial
extends UnlistedSpecialPage
{
938 var $redirName, $redirSubpage;
940 function __construct( $name, $redirName, $redirSubpage = false, $allowedRedirectParams = array(), $addedRedirectParams = array() ) {
941 parent
::__construct( $name );
942 $this->redirName
= $redirName;
943 $this->redirSubpage
= $redirSubpage;
944 $this->mAllowedRedirectParams
= $allowedRedirectParams;
945 $this->mAddedRedirectParams
= $addedRedirectParams;
948 function getRedirect( $subpage ) {
949 if ( $this->redirSubpage
=== false ) {
950 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
952 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
957 /** SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
958 * are used to get user independant links pointing to the user page, talk
959 * page and list of contributions.
960 * This can let us cache a single copy of any generated content for all
965 * Shortcut to construct a special page pointing to current user user's page.
966 * @ingroup SpecialPage
968 class SpecialMypage
extends UnlistedSpecialPage
{
969 function __construct() {
970 parent
::__construct( 'Mypage' );
971 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro', 'section' );
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', 'section' );
994 function getRedirect( $subpage ) {
996 if ( strval( $subpage ) !== '' ) {
997 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() . '/' . $subpage );
999 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() );
1005 * Shortcut to construct a special page pointing to current user contributions.
1006 * @ingroup SpecialPage
1008 class SpecialMycontributions
extends UnlistedSpecialPage
{
1009 function __construct() {
1010 parent
::__construct( 'Mycontributions' );
1011 $this->mAllowedRedirectParams
= array( 'limit', 'namespace', 'tagfilter',
1012 'offset', 'dir', 'year', 'month', 'feed' );
1015 function getRedirect( $subpage ) {
1017 return SpecialPage
::getTitleFor( 'Contributions', $wgUser->getName() );