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
36 * The canonical name of this special page
37 * Also used for the default <h1> heading, @see getDescription()
41 * The local name of this special page
45 * Minimum user level required to access this page, or "" for anyone.
46 * Also used to categorise the pages in Special:Specialpages
50 * Listed in Special:Specialpages?
54 * Function name called by the default execute()
58 * File which needs to be included before the function above can be called
62 * Whether or not this special page is being included from an article
66 * Whether the special page can be included in an article
70 * Query parameters that can be passed through redirects
72 var $mAllowedRedirectParams = array();
74 * List of special pages, followed by parameters.
75 * If the only parameter is a string, that is the page name.
76 * Otherwise, it is an array. The format is one of:
77 ** array( 'SpecialPage', name, right )
78 ** array( 'IncludableSpecialPage', name, right, listed? )
79 ** array( 'UnlistedSpecialPage', name, right )
80 ** array( 'SpecialRedirectToSpecial', name, page to redirect to, special page param, ... )
82 static public $mList = array(
84 'BrokenRedirects' => array( 'SpecialPage', 'BrokenRedirects' ),
85 'Deadendpages' => array( 'SpecialPage', 'Deadendpages' ),
86 'DoubleRedirects' => array( 'SpecialPage', 'DoubleRedirects' ),
87 'Longpages' => array( 'SpecialPage', 'Longpages' ),
88 'Ancientpages' => array( 'SpecialPage', 'Ancientpages' ),
89 'Lonelypages' => array( 'SpecialPage', 'Lonelypages' ),
90 'Fewestrevisions' => array( 'SpecialPage', 'Fewestrevisions' ),
91 'Withoutinterwiki' => array( 'SpecialPage', 'Withoutinterwiki' ),
92 'Protectedpages' => array( 'SpecialPage', 'Protectedpages' ),
93 'Protectedtitles' => array( 'SpecialPage', 'Protectedtitles' ),
94 'Shortpages' => array( 'SpecialPage', 'Shortpages' ),
95 'Uncategorizedcategories' => array( 'SpecialPage', 'Uncategorizedcategories' ),
96 'Uncategorizedimages' => array( 'SpecialPage', 'Uncategorizedimages' ),
97 'Uncategorizedpages' => array( 'SpecialPage', 'Uncategorizedpages' ),
98 'Uncategorizedtemplates' => array( 'SpecialPage', 'Uncategorizedtemplates' ),
99 'Unusedcategories' => array( 'SpecialPage', 'Unusedcategories' ),
100 'Unusedimages' => array( 'SpecialPage', 'Unusedimages' ),
101 'Unusedtemplates' => array( 'SpecialPage', 'Unusedtemplates' ),
102 'Unwatchedpages' => array( 'SpecialPage', 'Unwatchedpages', 'unwatchedpages' ),
103 'Wantedcategories' => array( 'SpecialPage', 'Wantedcategories' ),
104 'Wantedfiles' => array( 'SpecialPage', 'Wantedfiles' ),
105 'Wantedpages' => array( 'IncludableSpecialPage', 'Wantedpages' ),
106 'Wantedtemplates' => array( 'SpecialPage', 'Wantedtemplates' ),
109 'Allpages' => 'SpecialAllpages',
110 'Prefixindex' => 'SpecialPrefixindex',
111 'Categories' => array( 'SpecialPage', 'Categories' ),
112 'Disambiguations' => array( 'SpecialPage', 'Disambiguations' ),
113 'Listredirects' => array( 'SpecialPage', 'Listredirects' ),
115 # Login/create account
116 'Userlogin' => array( 'SpecialPage', 'Userlogin' ),
117 'CreateAccount' => array( 'SpecialRedirectToSpecial', 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ),
120 'Blockip' => array( 'SpecialPage', 'Blockip', 'block' ),
121 'Ipblocklist' => array( 'SpecialPage', 'Ipblocklist' ),
122 'Resetpass' => 'SpecialResetpass',
123 'DeletedContributions' => 'DeletedContributionsPage',
124 'Preferences' => 'SpecialPreferences',
125 'Contributions' => 'SpecialContributions',
126 'Listgrouprights' => 'SpecialListGroupRights',
127 'Listusers' => array( 'SpecialPage', 'Listusers' ),
128 'Activeusers' => array( 'SpecialPage', 'Activeusers' ),
129 'Userrights' => 'UserrightsPage',
131 # Recent changes and logs
132 'Newimages' => array( 'IncludableSpecialPage', 'Newimages' ),
133 'Log' => array( 'SpecialPage', 'Log' ),
134 'Watchlist' => array( 'SpecialPage', 'Watchlist' ),
135 'Newpages' => 'SpecialNewpages',
136 'Recentchanges' => 'SpecialRecentchanges',
137 'Recentchangeslinked' => 'SpecialRecentchangeslinked',
138 'Tags' => 'SpecialTags',
140 # Media reports and uploads
141 'Listfiles' => array( 'SpecialPage', 'Listfiles' ),
142 'Filepath' => array( 'SpecialPage', 'Filepath' ),
143 'MIMEsearch' => array( 'SpecialPage', 'MIMEsearch' ),
144 'FileDuplicateSearch' => array( 'SpecialPage', 'FileDuplicateSearch' ),
145 'Upload' => array( 'SpecialPage', 'Upload' ),
147 # Wiki data and tools
148 'Statistics' => 'SpecialStatistics',
149 'Allmessages' => array( 'SpecialPage', 'Allmessages' ),
150 'Version' => 'SpecialVersion',
151 'Lockdb' => array( 'SpecialPage', 'Lockdb', 'siteadmin' ),
152 'Unlockdb' => array( 'SpecialPage', 'Unlockdb', 'siteadmin' ),
154 # Redirecting special pages
155 'LinkSearch' => array( 'SpecialPage', 'LinkSearch' ),
156 'Randompage' => 'Randompage',
157 'Randomredirect' => 'SpecialRandomredirect',
160 'Mostlinkedcategories' => array( 'SpecialPage', 'Mostlinkedcategories' ),
161 'Mostimages' => array( 'SpecialPage', 'Mostimages' ),
162 'Mostlinked' => array( 'SpecialPage', 'Mostlinked' ),
163 'Mostlinkedtemplates' => array( 'SpecialPage', 'Mostlinkedtemplates' ),
164 'Mostcategories' => array( 'SpecialPage', 'Mostcategories' ),
165 'Mostrevisions' => array( 'SpecialPage', 'Mostrevisions' ),
168 'Export' => 'SpecialExport',
169 'Import' => 'SpecialImport',
170 'Undelete' => array( 'SpecialPage', 'Undelete', 'deletedhistory' ),
171 'Whatlinkshere' => 'SpecialWhatlinkshere',
172 'MergeHistory' => array( 'SpecialPage', 'MergeHistory', 'mergehistory' ),
175 'Booksources' => 'SpecialBookSources',
177 # Unlisted / redirects
178 'Blankpage' => 'SpecialBlankpage',
179 'Blockme' => array( 'UnlistedSpecialPage', 'Blockme' ),
180 'Emailuser' => array( 'UnlistedSpecialPage', 'Emailuser' ),
181 'Listadmins' => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
182 'Listbots' => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ),
183 'Movepage' => array( 'UnlistedSpecialPage', 'Movepage' ),
184 'Mycontributions' => array( 'SpecialMycontributions' ),
185 'Mypage' => array( 'SpecialMypage' ),
186 'Mytalk' => array( 'SpecialMytalk' ),
187 'Revisiondelete' => 'SpecialRevisionDelete',
188 'Specialpages' => array( 'UnlistedSpecialPage', 'Specialpages' ),
189 'Userlogout' => array( 'UnlistedSpecialPage', 'Userlogout' ),
192 static public $mAliases;
193 static public $mListInitialised = false;
198 * Initialise the special page list
199 * This must be called before accessing SpecialPage::$mList
201 static function initList() {
202 global $wgSpecialPages;
203 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
205 if ( self
::$mListInitialised ) {
208 wfProfileIn( __METHOD__
);
210 # Better to set this now, to avoid infinite recursion in carelessly written hooks
211 self
::$mListInitialised = true;
213 if( !$wgDisableCounters ) {
214 self
::$mList['Popularpages'] = array( 'SpecialPage', 'Popularpages' );
217 if( !$wgDisableInternalSearch ) {
218 self
::$mList['Search'] = array( 'SpecialPage', 'Search' );
221 if( $wgEmailAuthentication ) {
222 self
::$mList['Confirmemail'] = 'EmailConfirmation';
223 self
::$mList['Invalidateemail'] = 'EmailInvalidation';
226 # Add extension special pages
227 self
::$mList = array_merge( self
::$mList, $wgSpecialPages );
230 # This hook can be used to remove undesired built-in special pages
231 wfRunHooks( 'SpecialPage_initList', array( &self
::$mList ) );
232 wfProfileOut( __METHOD__
);
235 static function initAliasList() {
236 if ( !is_null( self
::$mAliases ) ) {
241 $aliases = $wgContLang->getSpecialPageAliases();
242 $missingPages = self
::$mList;
243 self
::$mAliases = array();
244 foreach ( $aliases as $realName => $aliasList ) {
245 foreach ( $aliasList as $alias ) {
246 self
::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
248 unset( $missingPages[$realName] );
250 foreach ( $missingPages as $name => $stuff ) {
251 self
::$mAliases[$wgContLang->caseFold( $name )] = $name;
256 * Given a special page alias, return the special page name.
257 * Returns false if there is no such alias.
259 static function resolveAlias( $alias ) {
262 if ( !self
::$mListInitialised ) self
::initList();
263 if ( is_null( self
::$mAliases ) ) self
::initAliasList();
264 $caseFoldedAlias = $wgContLang->caseFold( $alias );
265 if ( isset( self
::$mAliases[$caseFoldedAlias] ) ) {
266 return self
::$mAliases[$caseFoldedAlias];
273 * Given a special page name with a possible subpage, return an array
274 * where the first element is the special page name and the second is the
277 static function resolveAliasWithSubpage( $alias ) {
278 $bits = explode( '/', $alias, 2 );
279 $name = self
::resolveAlias( $bits[0] );
280 if( !isset( $bits[1] ) ) { // bug 2087
285 return array( $name, $par );
289 * Add a page to the list of valid special pages. This used to be the preferred
290 * method for adding special pages in extensions. It's now suggested that you add
291 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
293 * @param SpecialPage $page
296 static function addPage( &$page ) {
297 if ( !self
::$mListInitialised ) {
300 self
::$mList[$page->mName
] = $page;
304 * Add a page to a certain display group for Special:SpecialPages
306 * @param mixed $page (SpecialPage or string)
307 * @param string $group
310 static function setGroup( $page, $group ) {
311 global $wgSpecialPageGroups;
312 $name = is_object($page) ?
$page->mName
: $page;
313 $wgSpecialPageGroups[$name] = $group;
317 * Add a page to a certain display group for Special:SpecialPages
319 * @param SpecialPage $page
322 static function getGroup( &$page ) {
323 global $wgSpecialPageGroups;
324 static $specialPageGroupsCache = array();
325 if( isset($specialPageGroupsCache[$page->mName
]) ) {
326 return $specialPageGroupsCache[$page->mName
];
328 $group = wfMsg('specialpages-specialpagegroup-'.strtolower($page->mName
));
330 ||
wfEmptyMsg('specialpages-specialpagegroup-'.strtolower($page->mName
), $group ) ) {
331 $group = isset($wgSpecialPageGroups[$page->mName
])
332 ?
$wgSpecialPageGroups[$page->mName
]
335 if( $group == '-' ) $group = 'other';
336 $specialPageGroupsCache[$page->mName
] = $group;
341 * Remove a special page from the list
342 * Formerly used to disable expensive or dangerous special pages. The
343 * preferred method is now to add a SpecialPage_initList hook.
347 static function removePage( $name ) {
348 if ( !self
::$mListInitialised ) {
351 unset( self
::$mList[$name] );
355 * Check if a given name exist as a special page or as a special page alias
356 * @param $name string: name of a special page
357 * @return boolean: true if a special page exists with this name
359 static function exists( $name ) {
361 if ( !self
::$mListInitialised ) {
364 if( !self
::$mAliases ) {
365 self
::initAliasList();
368 # Remove special pages inline parameters:
369 $bits = explode( '/', $name );
370 $name = $wgContLang->caseFold($bits[0]);
373 array_key_exists( $name, self
::$mList )
374 or array_key_exists( $name, self
::$mAliases )
379 * Find the object with a given name and return it (or NULL)
381 * @param string $name
383 static function getPage( $name ) {
384 if ( !self
::$mListInitialised ) {
387 if ( array_key_exists( $name, self
::$mList ) ) {
388 $rec = self
::$mList[$name];
389 if ( is_string( $rec ) ) {
391 self
::$mList[$name] = new $className;
392 } elseif ( is_array( $rec ) ) {
393 $className = array_shift( $rec );
394 self
::$mList[$name] = wfCreateObject( $className, $rec );
396 return self
::$mList[$name];
403 * Get a special page with a given localised name, or NULL if there
404 * is no such special page.
406 static function getPageByAlias( $alias ) {
407 $realName = self
::resolveAlias( $alias );
409 return self
::getPage( $realName );
416 * Return categorised listable special pages which are available
417 * for the current user, and everyone.
420 static function getUsablePages() {
422 if ( !self
::$mListInitialised ) {
427 foreach ( self
::$mList as $name => $rec ) {
428 $page = self
::getPage( $name );
429 if ( $page->isListed()
431 !$page->isRestricted()
432 ||
$page->userCanExecute( $wgUser )
435 $pages[$name] = $page;
442 * Return categorised listable special pages for all users
445 static function getRegularPages() {
446 if ( !self
::$mListInitialised ) {
451 foreach ( self
::$mList as $name => $rec ) {
452 $page = self
::getPage( $name );
453 if ( $page->isListed() && !$page->isRestricted() ) {
454 $pages[$name] = $page;
461 * Return categorised listable special pages which are available
462 * for the current user, but not for everyone
465 static function getRestrictedPages() {
467 if( !self
::$mListInitialised ) {
472 foreach( self
::$mList as $name => $rec ) {
473 $page = self
::getPage( $name );
476 && $page->isRestricted()
477 && $page->userCanExecute( $wgUser )
479 $pages[$name] = $page;
486 * Execute a special page path.
487 * The path may contain parameters, e.g. Special:Name/Params
488 * Extracts the special page name and call the execute method, passing the parameters
490 * Returns a title object if the page is redirected, false if there was no such special
491 * page, and true if it was successful.
493 * @param $title a title object
494 * @param $including output is being captured for use in {{special:whatever}}
496 static function executePath( &$title, $including = false ) {
497 global $wgOut, $wgTitle, $wgRequest;
498 wfProfileIn( __METHOD__
);
500 # FIXME: redirects broken due to this call
501 $bits = explode( '/', $title->getDBkey(), 2 );
503 if( !isset( $bits[1] ) ) { // bug 2087
508 $page = SpecialPage
::getPageByAlias( $name );
512 $wgOut->setArticleRelated( false );
513 $wgOut->setRobotPolicy( 'noindex,nofollow' );
514 $wgOut->setStatusCode( 404 );
515 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
517 wfProfileOut( __METHOD__
);
523 $redirect = $page->getRedirect( $par );
525 $query = $page->getRedirectQuery();
526 $url = $redirect->getFullUrl( $query );
527 $wgOut->redirect( $url );
528 wfProfileOut( __METHOD__
);
533 # Redirect to canonical alias for GET commands
534 # Not for POST, we'd lose the post data, so it's best to just distribute
535 # the request. Such POST requests are possible for old extensions that
536 # generate self-links without being aware that their default name has
538 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
540 unset( $query['title'] );
541 $query = wfArrayToCGI( $query );
542 $title = $page->getTitle( $par );
543 $url = $title->getFullUrl( $query );
544 $wgOut->redirect( $url );
545 wfProfileOut( __METHOD__
);
549 if ( $including && !$page->includable() ) {
550 wfProfileOut( __METHOD__
);
552 } elseif ( !$including ) {
553 $wgTitle = $page->getTitle();
555 $page->including( $including );
557 // Execute special page
558 $profName = 'Special:' . $page->getName();
559 wfProfileIn( $profName );
560 $page->execute( $par );
561 wfProfileOut( $profName );
562 wfProfileOut( __METHOD__
);
567 * Just like executePath() except it returns the HTML instead of outputting it
568 * Returns false if there was no such special page, or a title object if it was
572 static function capturePath( &$title ) {
573 global $wgOut, $wgTitle;
575 $oldTitle = $wgTitle;
577 $wgOut = new OutputPage
;
579 $ret = SpecialPage
::executePath( $title, true );
580 if ( $ret === true ) {
581 $ret = $wgOut->getHTML();
583 $wgTitle = $oldTitle;
589 * Get the local name for a specified canonical name
592 * @param mixed $subpage Boolean false, or string
596 static function getLocalNameFor( $name, $subpage = false ) {
598 $aliases = $wgContLang->getSpecialPageAliases();
599 if ( isset( $aliases[$name][0] ) ) {
600 $name = $aliases[$name][0];
602 // Try harder in case someone misspelled the correct casing
604 foreach ( $aliases as $n => $values ) {
605 if ( strcasecmp( $name, $n ) === 0 ) {
606 wfWarn( "Found $n for $name with casefix" );
612 if ( !$found ) wfWarn( "Did not find name for special page $name" );
614 if ( $subpage !== false && !is_null( $subpage ) ) {
615 $name = "$name/$subpage";
617 return ucfirst( $name );
621 * Get a localised Title object for a specified special page name
623 static function getTitleFor( $name, $subpage = false ) {
624 $name = self
::getLocalNameFor( $name, $subpage );
626 return Title
::makeTitle( NS_SPECIAL
, $name );
628 throw new MWException( "Invalid special page name \"$name\"" );
633 * Get a localised Title object for a page name with a possibly unvalidated subpage
635 static function getSafeTitleFor( $name, $subpage = false ) {
636 $name = self
::getLocalNameFor( $name, $subpage );
638 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
645 * Get a title for a given alias
646 * @return Title or null if there is no such alias
648 static function getTitleForAlias( $alias ) {
649 $name = self
::resolveAlias( $alias );
651 return self
::getTitleFor( $name );
658 * Default constructor for special pages
659 * Derivative classes should call this from their constructor
660 * Note that if the user does not have the required level, an error message will
661 * be displayed by the default execute() method, without the global function ever
664 * If you override execute(), you can recover the default behaviour with userCanExecute()
665 * and displayRestrictionError()
667 * @param string $name Name of the special page, as seen in links and URLs
668 * @param string $restriction User right required, e.g. "block" or "delete"
669 * @param boolean $listed Whether the page is listed in Special:Specialpages
670 * @param string $function Function called by execute(). By default it is constructed from $name
671 * @param string $file File which is included by execute(). It is also constructed from $name by default
673 function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
674 $this->mName
= $name;
675 $this->mRestriction
= $restriction;
676 $this->mListed
= $listed;
677 $this->mIncludable
= $includable;
678 if ( $function == false ) {
679 $this->mFunction
= 'wfSpecial'.$name;
681 $this->mFunction
= $function;
683 if ( $file === 'default' ) {
684 $this->mFile
= dirname(__FILE__
) . "/specials/Special$name.php";
686 $this->mFile
= $file;
695 function getName() { return $this->mName
; }
696 function getRestriction() { return $this->mRestriction
; }
697 function getFile() { return $this->mFile
; }
698 function isListed() { return $this->mListed
; }
702 * Accessor and mutator
704 function name( $x = NULL ) { return wfSetVar( $this->mName
, $x ); }
705 function restrictions( $x = NULL) { return wfSetVar( $this->mRestrictions
, $x ); }
706 function listed( $x = NULL) { return wfSetVar( $this->mListed
, $x ); }
707 function func( $x = NULL) { return wfSetVar( $this->mFunction
, $x ); }
708 function file( $x = NULL) { return wfSetVar( $this->mFile
, $x ); }
709 function includable( $x = NULL ) { return wfSetVar( $this->mIncludable
, $x ); }
710 function including( $x = NULL ) { return wfSetVar( $this->mIncluding
, $x ); }
714 * Get the localised name of the special page
716 function getLocalName() {
717 if ( !isset( $this->mLocalName
) ) {
718 $this->mLocalName
= self
::getLocalNameFor( $this->mName
);
720 return $this->mLocalName
;
724 * Can be overridden by subclasses with more complicated permissions
727 * @return bool Should the page be displayed with the restricted-access
730 public function isRestricted() {
731 global $wgGroupPermissions;
732 // DWIM: If all anons can do something, then it is not restricted
733 return $this->mRestriction
!= '' && empty($wgGroupPermissions['*'][$this->mRestriction
]);
737 * Checks if the given user (identified by an object) can execute this
738 * special page (as defined by $mRestriction). Can be overridden by sub-
739 * classes with more complicated permissions schemes.
741 * @param User $user The user to check
742 * @return bool Does the user have permission to view the page?
744 public function userCanExecute( $user ) {
745 return $user->isAllowed( $this->mRestriction
);
749 * Output an error message telling the user what access level they have to have
751 function displayRestrictionError() {
753 $wgOut->permissionRequired( $this->mRestriction
);
757 * Sets headers - this should be called from the execute() method of all derived classes!
759 function setHeaders() {
761 $wgOut->setArticleRelated( false );
762 $wgOut->setRobotPolicy( "noindex,nofollow" );
763 $wgOut->setPageTitle( $this->getDescription() );
767 * Default execute method
768 * Checks user permissions, calls the function given in mFunction
770 * This may be overridden by subclasses.
772 function execute( $par ) {
777 if ( $this->userCanExecute( $wgUser ) ) {
778 $func = $this->mFunction
;
779 // only load file if the function does not exist
780 if(!is_callable($func) and $this->mFile
) {
781 require_once( $this->mFile
);
783 $this->outputHeader();
784 call_user_func( $func, $par, $this );
786 $this->displayRestrictionError();
791 * Outputs a summary message on top of special pages
792 * Per default the message key is the canonical name of the special page
793 * May be overriden, i.e. by extensions to stick with the naming conventions
794 * for message keys: 'extensionname-xxx'
796 * @param string message key of the summary
798 function outputHeader( $summaryMessageKey = '' ) {
799 global $wgOut, $wgContLang;
801 if( $summaryMessageKey == '' ) {
802 $msg = $wgContLang->lc( $this->name() ) . '-summary';
804 $msg = $summaryMessageKey;
806 $out = wfMsgNoTrans( $msg );
807 if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() ) {
808 $wgOut->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1</div>", $msg );
813 # Returns the name that goes in the <h1> in the special page itself, and also the name that
814 # will be listed in Special:Specialpages
816 # Derived classes can override this, but usually it is easier to keep the default behaviour.
817 # Messages can be added at run-time, see MessageCache.php
818 function getDescription() {
819 return wfMsg( strtolower( $this->mName
) );
823 * Get a self-referential title object
825 function getTitle( $subpage = false) {
826 return self
::getTitleFor( $this->mName
, $subpage );
830 * Set whether this page is listed in Special:Specialpages, at run-time
832 function setListed( $listed ) {
833 return wfSetVar( $this->mListed
, $listed );
837 * If the special page is a redirect, then get the Title object it redirects to.
840 function getRedirect( $subpage ) {
845 * Return part of the request string for a special redirect page
846 * This allows passing, e.g. action=history to Special:Mypage, etc.
850 function getRedirectQuery() {
853 foreach( $this->mAllowedRedirectParams
as $arg ) {
854 if( $val = $wgRequest->getVal( $arg, false ) )
855 $params[] = $arg . '=' . $val;
858 return count( $params ) ?
implode( '&', $params ) : false;
863 * Shortcut to construct a special page which is unlisted by default
864 * @ingroup SpecialPage
866 class UnlistedSpecialPage
extends SpecialPage
868 function UnlistedSpecialPage( $name, $restriction = '', $function = false, $file = 'default' ) {
869 SpecialPage
::SpecialPage( $name, $restriction, false, $function, $file );
874 * Shortcut to construct an includable special page
875 * @ingroup SpecialPage
877 class IncludableSpecialPage
extends SpecialPage
879 function IncludableSpecialPage( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
880 SpecialPage
::SpecialPage( $name, $restriction, $listed, $function, $file, true );
885 * Shortcut to construct a special page alias.
886 * @ingroup SpecialPage
888 class SpecialRedirectToSpecial
extends UnlistedSpecialPage
{
889 var $redirName, $redirSubpage;
891 function __construct( $name, $redirName, $redirSubpage = false, $redirectParams = array() ) {
892 parent
::__construct( $name );
893 $this->redirName
= $redirName;
894 $this->redirSubpage
= $redirSubpage;
895 $this->mAllowedRedirectParams
= $redirectParams;
898 function getRedirect( $subpage ) {
899 if ( $this->redirSubpage
=== false ) {
900 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
902 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
907 /** SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
908 * are used to get user independant links pointing to the user page, talk
909 * page and list of contributions.
910 * This can let us cache a single copy of any generated content for all
915 * Shortcut to construct a special page pointing to current user user's page.
916 * @ingroup SpecialPage
918 class SpecialMypage
extends UnlistedSpecialPage
{
919 function __construct() {
920 parent
::__construct( 'Mypage' );
921 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro', 'section' );
924 function getRedirect( $subpage ) {
926 if ( strval( $subpage ) !== '' ) {
927 return Title
::makeTitle( NS_USER
, $wgUser->getName() . '/' . $subpage );
929 return Title
::makeTitle( NS_USER
, $wgUser->getName() );
935 * Shortcut to construct a special page pointing to current user talk page.
936 * @ingroup SpecialPage
938 class SpecialMytalk
extends UnlistedSpecialPage
{
939 function __construct() {
940 parent
::__construct( 'Mytalk' );
941 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro', 'section' );
944 function getRedirect( $subpage ) {
946 if ( strval( $subpage ) !== '' ) {
947 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() . '/' . $subpage );
949 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() );
955 * Shortcut to construct a special page pointing to current user contributions.
956 * @ingroup SpecialPage
958 class SpecialMycontributions
extends UnlistedSpecialPage
{
959 function __construct() {
960 parent
::__construct( 'Mycontributions' );
963 function getRedirect( $subpage ) {
965 return SpecialPage
::getTitleFor( 'Contributions', $wgUser->getName() );