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',
152 'UploadStash' => 'SpecialUploadStash',
154 # Wiki data and tools
155 'Statistics' => 'SpecialStatistics',
156 'Allmessages' => 'SpecialAllmessages',
157 'Version' => 'SpecialVersion',
158 'Lockdb' => 'SpecialLockdb',
159 'Unlockdb' => 'SpecialUnlockdb',
161 # Redirecting special pages
162 'LinkSearch' => array( 'SpecialPage', 'LinkSearch' ),
163 'Randompage' => 'Randompage',
164 'Randomredirect' => 'SpecialRandomredirect',
167 'Mostlinkedcategories' => array( 'SpecialPage', 'Mostlinkedcategories' ),
168 'Mostimages' => array( 'SpecialPage', 'Mostimages' ),
169 'Mostlinked' => array( 'SpecialPage', 'Mostlinked' ),
170 'Mostlinkedtemplates' => array( 'SpecialPage', 'Mostlinkedtemplates' ),
171 'Mostcategories' => array( 'SpecialPage', 'Mostcategories' ),
172 'Mostrevisions' => array( 'SpecialPage', 'Mostrevisions' ),
175 'ComparePages' => 'SpecialComparePages',
176 'Export' => 'SpecialExport',
177 'Import' => 'SpecialImport',
178 'Undelete' => 'UndeleteForm',
179 'Whatlinkshere' => 'SpecialWhatlinkshere',
180 'MergeHistory' => 'SpecialMergeHistory',
183 'Booksources' => 'SpecialBookSources',
185 # Unlisted / redirects
186 'Blankpage' => 'SpecialBlankpage',
187 'Blockme' => 'SpecialBlockme',
188 'Emailuser' => 'SpecialEmailUser',
189 'Movepage' => 'MovePageForm',
190 'Mycontributions' => 'SpecialMycontributions',
191 'Mypage' => 'SpecialMypage',
192 'Mytalk' => 'SpecialMytalk',
193 'Revisiondelete' => 'SpecialRevisionDelete',
194 'RevisionMove' => 'SpecialRevisionMove',
195 'Specialpages' => 'SpecialSpecialpages',
196 'Userlogout' => 'SpecialUserlogout',
199 static public $mAliases;
200 static public $mListInitialised = false;
205 * Initialise the special page list
206 * This must be called before accessing SpecialPage::$mList
208 static function initList() {
209 global $wgSpecialPages;
210 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
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 # Add extension special pages
234 self
::$mList = array_merge( self
::$mList, $wgSpecialPages );
237 # This hook can be used to remove undesired built-in special pages
238 wfRunHooks( 'SpecialPage_initList', array( &self
::$mList ) );
239 wfProfileOut( __METHOD__
);
242 static function initAliasList() {
243 if ( !is_null( self
::$mAliases ) ) {
248 $aliases = $wgContLang->getSpecialPageAliases();
249 $missingPages = self
::$mList;
250 self
::$mAliases = array();
251 foreach ( $aliases as $realName => $aliasList ) {
252 foreach ( $aliasList as $alias ) {
253 self
::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
255 unset( $missingPages[$realName] );
257 foreach ( $missingPages as $name => $stuff ) {
258 self
::$mAliases[$wgContLang->caseFold( $name )] = $name;
263 * Given a special page alias, return the special page name.
264 * Returns false if there is no such alias.
266 * @param $alias String
267 * @return String or false
269 static function resolveAlias( $alias ) {
272 if ( !self
::$mListInitialised ) self
::initList();
273 if ( is_null( self
::$mAliases ) ) self
::initAliasList();
274 $caseFoldedAlias = $wgContLang->caseFold( $alias );
275 if ( isset( self
::$mAliases[$caseFoldedAlias] ) ) {
276 return self
::$mAliases[$caseFoldedAlias];
283 * Given a special page name with a possible subpage, return an array
284 * where the first element is the special page name and the second is the
287 * @param $alias String
290 static function resolveAliasWithSubpage( $alias ) {
291 $bits = explode( '/', $alias, 2 );
292 $name = self
::resolveAlias( $bits[0] );
293 if( !isset( $bits[1] ) ) { // bug 2087
298 return array( $name, $par );
302 * Add a page to the list of valid special pages. This used to be the preferred
303 * method for adding special pages in extensions. It's now suggested that you add
304 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
306 * @param $page SpecialPage
307 * Deprecated in 1.7, warnings in 1.17, might be removed in 1.20
309 static function addPage( &$page ) {
310 wfDeprecated( __METHOD__
);
311 if ( !self
::$mListInitialised ) {
314 self
::$mList[$page->mName
] = $page;
318 * Add a page to a certain display group for Special:SpecialPages
320 * @param $page Mixed: SpecialPage or string
321 * @param $group String
323 static function setGroup( $page, $group ) {
324 global $wgSpecialPageGroups;
325 $name = is_object($page) ?
$page->mName
: $page;
326 $wgSpecialPageGroups[$name] = $group;
330 * Add a page to a certain display group for Special:SpecialPages
332 * @param $page SpecialPage
334 static function getGroup( &$page ) {
335 global $wgSpecialPageGroups;
336 static $specialPageGroupsCache = array();
337 if( isset($specialPageGroupsCache[$page->mName
]) ) {
338 return $specialPageGroupsCache[$page->mName
];
340 $group = wfMsg('specialpages-specialpagegroup-'.strtolower($page->mName
));
342 ||
wfEmptyMsg('specialpages-specialpagegroup-'.strtolower($page->mName
), $group ) ) {
343 $group = isset($wgSpecialPageGroups[$page->mName
])
344 ?
$wgSpecialPageGroups[$page->mName
]
347 if( $group == '-' ) $group = 'other';
348 $specialPageGroupsCache[$page->mName
] = $group;
353 * Remove a special page from the list
354 * Formerly used to disable expensive or dangerous special pages. The
355 * preferred method is now to add a SpecialPage_initList hook.
357 static function removePage( $name ) {
358 if ( !self
::$mListInitialised ) {
361 unset( self
::$mList[$name] );
365 * Check if a given name exist as a special page or as a special page alias
367 * @param $name String: name of a special page
368 * @return Boolean: true if a special page exists with this name
370 static function exists( $name ) {
372 if ( !self
::$mListInitialised ) {
375 if( !self
::$mAliases ) {
376 self
::initAliasList();
379 # Remove special pages inline parameters:
380 $bits = explode( '/', $name );
381 $name = $wgContLang->caseFold($bits[0]);
384 array_key_exists( $name, self
::$mList )
385 or array_key_exists( $name, self
::$mAliases )
390 * Find the object with a given name and return it (or NULL)
392 * @param $name String
393 * @return SpecialPage object or null if the page doesn't exist
395 static function getPage( $name ) {
396 if ( !self
::$mListInitialised ) {
399 if ( array_key_exists( $name, self
::$mList ) ) {
400 $rec = self
::$mList[$name];
401 if ( is_string( $rec ) ) {
403 self
::$mList[$name] = new $className;
404 } elseif ( is_array( $rec ) ) {
405 $className = array_shift( $rec );
406 self
::$mList[$name] = wfCreateObject( $className, $rec );
408 return self
::$mList[$name];
415 * Get a special page with a given localised name, or NULL if there
416 * is no such special page.
418 * @return SpecialPage object or null if the page doesn't exist
420 static function getPageByAlias( $alias ) {
421 $realName = self
::resolveAlias( $alias );
423 return self
::getPage( $realName );
430 * Return categorised listable special pages which are available
431 * for the current user, and everyone.
433 * @return Associative array mapping page's name to its SpecialPage object
435 static function getUsablePages() {
437 if ( !self
::$mListInitialised ) {
442 foreach ( self
::$mList as $name => $rec ) {
443 $page = self
::getPage( $name );
444 if ( $page->isListed()
446 !$page->isRestricted()
447 ||
$page->userCanExecute( $wgUser )
450 $pages[$name] = $page;
457 * Return categorised listable special pages for all users
459 * @return Associative array mapping page's name to its SpecialPage object
461 static function getRegularPages() {
462 if ( !self
::$mListInitialised ) {
467 foreach ( self
::$mList as $name => $rec ) {
468 $page = self
::getPage( $name );
469 if ( $page->isListed() && !$page->isRestricted() ) {
470 $pages[$name] = $page;
477 * Return categorised listable special pages which are available
478 * for the current user, but not for everyone
480 * @return Associative array mapping page's name to its SpecialPage object
482 static function getRestrictedPages() {
484 if( !self
::$mListInitialised ) {
489 foreach( self
::$mList as $name => $rec ) {
490 $page = self
::getPage( $name );
493 && $page->isRestricted()
494 && $page->userCanExecute( $wgUser )
496 $pages[$name] = $page;
503 * Execute a special page path.
504 * The path may contain parameters, e.g. Special:Name/Params
505 * Extracts the special page name and call the execute method, passing the parameters
507 * Returns a title object if the page is redirected, false if there was no such special
508 * page, and true if it was successful.
510 * @param $title a title object
511 * @param $including output is being captured for use in {{special:whatever}}
513 static function executePath( &$title, $including = false ) {
514 global $wgOut, $wgTitle, $wgRequest;
515 wfProfileIn( __METHOD__
);
517 # FIXME: redirects broken due to this call
518 $bits = explode( '/', $title->getDBkey(), 2 );
520 if( !isset( $bits[1] ) ) { // bug 2087
525 $page = SpecialPage
::getPageByAlias( $name );
529 $wgOut->setArticleRelated( false );
530 $wgOut->setRobotPolicy( 'noindex,nofollow' );
531 $wgOut->setStatusCode( 404 );
532 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
534 wfProfileOut( __METHOD__
);
540 $redirect = $page->getRedirect( $par );
542 $query = $page->getRedirectQuery();
543 $url = $redirect->getFullUrl( $query );
544 $wgOut->redirect( $url );
545 wfProfileOut( __METHOD__
);
550 # Redirect to canonical alias for GET commands
551 # Not for POST, we'd lose the post data, so it's best to just distribute
552 # the request. Such POST requests are possible for old extensions that
553 # generate self-links without being aware that their default name has
555 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
557 unset( $query['title'] );
558 $query = wfArrayToCGI( $query );
559 $title = $page->getTitle( $par );
560 $url = $title->getFullUrl( $query );
561 $wgOut->redirect( $url );
562 wfProfileOut( __METHOD__
);
566 if ( $including && !$page->includable() ) {
567 wfProfileOut( __METHOD__
);
569 } elseif ( !$including ) {
570 $wgTitle = $page->getTitle();
572 $page->including( $including );
574 // Execute special page
575 $profName = 'Special:' . $page->getName();
576 wfProfileIn( $profName );
577 $page->execute( $par );
578 wfProfileOut( $profName );
579 wfProfileOut( __METHOD__
);
584 * Just like executePath() except it returns the HTML instead of outputting it
585 * Returns false if there was no such special page, or a title object if it was
588 * @return String: HTML fragment
590 static function capturePath( &$title ) {
591 global $wgOut, $wgTitle;
593 $oldTitle = $wgTitle;
595 $wgOut = new OutputPage
;
596 $wgOut->setTitle( $title );
598 $ret = SpecialPage
::executePath( $title, true );
599 if ( $ret === true ) {
600 $ret = $wgOut->getHTML();
602 $wgTitle = $oldTitle;
608 * Get the local name for a specified canonical name
610 * @param $name String
611 * @param $subpage Mixed: boolean false, or string
615 static function getLocalNameFor( $name, $subpage = false ) {
617 $aliases = $wgContLang->getSpecialPageAliases();
618 if ( isset( $aliases[$name][0] ) ) {
619 $name = $aliases[$name][0];
621 // Try harder in case someone misspelled the correct casing
623 foreach ( $aliases as $n => $values ) {
624 if ( strcasecmp( $name, $n ) === 0 ) {
625 wfWarn( "Found alias defined for $n when searching for" .
626 "special page aliases for $name. Case mismatch?" );
633 wfWarn( "Did not find alias for special page '$name'. " .
634 "Perhaps no aliases are defined for it?" );
637 if ( $subpage !== false && !is_null( $subpage ) ) {
638 $name = "$name/$subpage";
640 return $wgContLang->ucfirst( $name );
644 * Get a localised Title object for a specified special page name
646 * @return Title object
648 static function getTitleFor( $name, $subpage = false ) {
649 $name = self
::getLocalNameFor( $name, $subpage );
651 return Title
::makeTitle( NS_SPECIAL
, $name );
653 throw new MWException( "Invalid special page name \"$name\"" );
658 * Get a localised Title object for a page name with a possibly unvalidated subpage
660 * @return Title object or null if the page doesn't exist
662 static function getSafeTitleFor( $name, $subpage = false ) {
663 $name = self
::getLocalNameFor( $name, $subpage );
665 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
672 * Get a title for a given alias
674 * @return Title or null if there is no such alias
676 static function getTitleForAlias( $alias ) {
677 $name = self
::resolveAlias( $alias );
679 return self
::getTitleFor( $name );
686 * Default constructor for special pages
687 * Derivative classes should call this from their constructor
688 * Note that if the user does not have the required level, an error message will
689 * be displayed by the default execute() method, without the global function ever
692 * If you override execute(), you can recover the default behaviour with userCanExecute()
693 * and displayRestrictionError()
695 * @param $name String: name of the special page, as seen in links and URLs
696 * @param $restriction String: user right required, e.g. "block" or "delete"
697 * @param $listed Boolean: whether the page is listed in Special:Specialpages
698 * @param $function Callback: function called by execute(). By default it is constructed from $name
699 * @param $file String: file which is included by execute(). It is also constructed from $name by default
700 * @param $includable Boolean: whether the page can be included in normal pages
702 function __construct( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
703 $this->mName
= $name;
704 $this->mRestriction
= $restriction;
705 $this->mListed
= $listed;
706 $this->mIncludable
= $includable;
708 $this->mFunction
= 'wfSpecial'.$name;
710 $this->mFunction
= $function;
712 if ( $file === 'default' ) {
713 $this->mFile
= dirname(__FILE__
) . "/specials/Special$name.php";
715 $this->mFile
= $file;
724 function getName() { return $this->mName
; }
725 function getRestriction() { return $this->mRestriction
; }
726 function getFile() { return $this->mFile
; }
727 function isListed() { return $this->mListed
; }
731 * Accessor and mutator
733 function name( $x = null ) { return wfSetVar( $this->mName
, $x ); }
734 function restrictions( $x = null) {
735 # Use the one below this
736 wfDeprecated( __METHOD__
);
737 return wfSetVar( $this->mRestriction
, $x );
739 function restriction( $x = null) { return wfSetVar( $this->mRestriction
, $x ); }
740 function listed( $x = null) { return wfSetVar( $this->mListed
, $x ); }
741 function func( $x = null) { return wfSetVar( $this->mFunction
, $x ); }
742 function file( $x = null) { return wfSetVar( $this->mFile
, $x ); }
743 function includable( $x = null ) { return wfSetVar( $this->mIncludable
, $x ); }
744 function including( $x = null ) { return wfSetVar( $this->mIncluding
, $x ); }
748 * Get the localised name of the special page
750 function getLocalName() {
751 if ( !isset( $this->mLocalName
) ) {
752 $this->mLocalName
= self
::getLocalNameFor( $this->mName
);
754 return $this->mLocalName
;
758 * Can be overridden by subclasses with more complicated permissions
761 * @return Boolean: should the page be displayed with the restricted-access
764 public function isRestricted() {
765 global $wgGroupPermissions;
766 // DWIM: If all anons can do something, then it is not restricted
767 return $this->mRestriction
!= '' && empty($wgGroupPermissions['*'][$this->mRestriction
]);
771 * Checks if the given user (identified by an object) can execute this
772 * special page (as defined by $mRestriction). Can be overridden by sub-
773 * classes with more complicated permissions schemes.
775 * @param $user User: the user to check
776 * @return Boolean: does the user have permission to view the page?
778 public function userCanExecute( $user ) {
779 return $user->isAllowed( $this->mRestriction
);
783 * Output an error message telling the user what access level they have to have
785 function displayRestrictionError() {
787 $wgOut->permissionRequired( $this->mRestriction
);
791 * Sets headers - this should be called from the execute() method of all derived classes!
793 function setHeaders() {
795 $wgOut->setArticleRelated( false );
796 $wgOut->setRobotPolicy( "noindex,nofollow" );
797 $wgOut->setPageTitle( $this->getDescription() );
801 * Default execute method
802 * Checks user permissions, calls the function given in mFunction
804 * This may be overridden by subclasses.
806 function execute( $par ) {
811 if ( $this->userCanExecute( $wgUser ) ) {
812 $func = $this->mFunction
;
813 // only load file if the function does not exist
814 if(!is_callable($func) and $this->mFile
) {
815 require_once( $this->mFile
);
817 $this->outputHeader();
818 call_user_func( $func, $par, $this );
820 $this->displayRestrictionError();
825 * Outputs a summary message on top of special pages
826 * Per default the message key is the canonical name of the special page
827 * May be overriden, i.e. by extensions to stick with the naming conventions
828 * for message keys: 'extensionname-xxx'
830 * @param $summaryMessageKey String: message key of the summary
832 function outputHeader( $summaryMessageKey = '' ) {
833 global $wgOut, $wgContLang;
835 if( $summaryMessageKey == '' ) {
836 $msg = $wgContLang->lc( $this->name() ) . '-summary';
838 $msg = $summaryMessageKey;
840 $out = wfMsgNoTrans( $msg );
841 if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() ) {
842 $wgOut->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
848 * Returns the name that goes in the \<h1\> in the special page itself, and
849 * also the name that will be listed in Special:Specialpages
851 * Derived classes can override this, but usually it is easier to keep the
852 * default behaviour. Messages can be added at run-time, see
857 function getDescription() {
858 return wfMsg( strtolower( $this->mName
) );
862 * Get a self-referential title object
864 * @return Title object
866 function getTitle( $subpage = false ) {
867 return self
::getTitleFor( $this->mName
, $subpage );
871 * Set whether this page is listed in Special:Specialpages, at run-time
873 function setListed( $listed ) {
874 return wfSetVar( $this->mListed
, $listed );
878 * If the special page is a redirect, then get the Title object it redirects to.
881 function getRedirect( $subpage ) {
886 * Return part of the request string for a special redirect page
887 * This allows passing, e.g. action=history to Special:Mypage, etc.
891 function getRedirectQuery() {
894 foreach( $this->mAllowedRedirectParams
as $arg ) {
895 if( ( $val = $wgRequest->getVal( $arg, null ) ) !== null )
896 $params[] = $arg . '=' . $val;
899 foreach( $this->mAddedRedirectParams
as $arg => $val ) {
900 $params[] = $arg . '=' . $val;
903 return count( $params ) ?
implode( '&', $params ) : false;
908 * Shortcut to construct a special page which is unlisted by default
909 * @ingroup SpecialPage
911 class UnlistedSpecialPage
extends SpecialPage
913 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
914 parent
::__construct( $name, $restriction, false, $function, $file );
919 * Shortcut to construct an includable special page
920 * @ingroup SpecialPage
922 class IncludableSpecialPage
extends SpecialPage
924 function __construct( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
925 parent
::__construct( $name, $restriction, $listed, $function, $file, true );
930 * Shortcut to construct a special page alias.
931 * @ingroup SpecialPage
933 class SpecialRedirectToSpecial
extends UnlistedSpecialPage
{
934 var $redirName, $redirSubpage;
936 function __construct( $name, $redirName, $redirSubpage = false, $allowedRedirectParams = array(), $addedRedirectParams = array() ) {
937 parent
::__construct( $name );
938 $this->redirName
= $redirName;
939 $this->redirSubpage
= $redirSubpage;
940 $this->mAllowedRedirectParams
= $allowedRedirectParams;
941 $this->mAddedRedirectParams
= $addedRedirectParams;
944 function getRedirect( $subpage ) {
945 if ( $this->redirSubpage
=== false ) {
946 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
948 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
953 /** SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
954 * are used to get user independant links pointing to the user page, talk
955 * page and list of contributions.
956 * This can let us cache a single copy of any generated content for all
961 * Shortcut to construct a special page pointing to current user user's page.
962 * @ingroup SpecialPage
964 class SpecialMypage
extends UnlistedSpecialPage
{
965 function __construct() {
966 parent
::__construct( 'Mypage' );
967 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro', 'section' );
970 function getRedirect( $subpage ) {
972 if ( strval( $subpage ) !== '' ) {
973 return Title
::makeTitle( NS_USER
, $wgUser->getName() . '/' . $subpage );
975 return Title
::makeTitle( NS_USER
, $wgUser->getName() );
981 * Shortcut to construct a special page pointing to current user talk page.
982 * @ingroup SpecialPage
984 class SpecialMytalk
extends UnlistedSpecialPage
{
985 function __construct() {
986 parent
::__construct( 'Mytalk' );
987 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro', 'section' );
990 function getRedirect( $subpage ) {
992 if ( strval( $subpage ) !== '' ) {
993 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() . '/' . $subpage );
995 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() );
1001 * Shortcut to construct a special page pointing to current user contributions.
1002 * @ingroup SpecialPage
1004 class SpecialMycontributions
extends UnlistedSpecialPage
{
1005 function __construct() {
1006 parent
::__construct( 'Mycontributions' );
1007 $this->mAllowedRedirectParams
= array( 'limit', 'namespace', 'tagfilter',
1008 'offset', 'dir', 'year', 'month', 'feed' );
1011 function getRedirect( $subpage ) {
1013 return SpecialPage
::getTitleFor( 'Contributions', $wgUser->getName() );