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(
83 'DoubleRedirects' => array( 'SpecialPage', 'DoubleRedirects' ),
84 'BrokenRedirects' => array( 'SpecialPage', 'BrokenRedirects' ),
85 'Disambiguations' => array( 'SpecialPage', 'Disambiguations' ),
87 'Userlogin' => array( 'SpecialPage', 'Userlogin' ),
88 'Userlogout' => array( 'UnlistedSpecialPage', 'Userlogout' ),
89 'CreateAccount' => array( 'SpecialRedirectToSpecial', 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ),
90 'Preferences' => array( 'SpecialPage', 'Preferences' ),
91 'Watchlist' => array( 'SpecialPage', 'Watchlist' ),
93 'Recentchanges' => 'SpecialRecentchanges',
94 'Upload' => array( 'SpecialPage', 'Upload' ),
95 'Imagelist' => array( 'SpecialPage', 'Imagelist' ),
96 'Newimages' => array( 'IncludableSpecialPage', 'Newimages' ),
97 'Listusers' => array( 'SpecialPage', 'Listusers' ),
98 'Listgrouprights' => 'SpecialListGroupRights',
99 'DeletedContributions' => 'DeletedContributionsPage',
100 'Statistics' => array( 'SpecialPage', 'Statistics' ),
101 'Randompage' => 'Randompage',
102 'Lonelypages' => array( 'SpecialPage', 'Lonelypages' ),
103 'Uncategorizedpages' => array( 'SpecialPage', 'Uncategorizedpages' ),
104 'Uncategorizedcategories' => array( 'SpecialPage', 'Uncategorizedcategories' ),
105 'Uncategorizedimages' => array( 'SpecialPage', 'Uncategorizedimages' ),
106 'Uncategorizedtemplates' => array( 'SpecialPage', 'Uncategorizedtemplates' ),
107 'Unusedcategories' => array( 'SpecialPage', 'Unusedcategories' ),
108 'Unusedimages' => array( 'SpecialPage', 'Unusedimages' ),
109 'Wantedpages' => array( 'IncludableSpecialPage', 'Wantedpages' ),
110 'Wantedcategories' => array( 'SpecialPage', 'Wantedcategories' ),
111 'Wantedfiles' => array( 'SpecialPage', 'Wantedfiles' ),
112 'Mostlinked' => array( 'SpecialPage', 'Mostlinked' ),
113 'Mostlinkedcategories' => array( 'SpecialPage', 'Mostlinkedcategories' ),
114 'Mostlinkedtemplates' => array( 'SpecialPage', 'Mostlinkedtemplates' ),
115 'Mostcategories' => array( 'SpecialPage', 'Mostcategories' ),
116 'Mostimages' => array( 'SpecialPage', 'Mostimages' ),
117 'Mostrevisions' => array( 'SpecialPage', 'Mostrevisions' ),
118 'Fewestrevisions' => array( 'SpecialPage', 'Fewestrevisions' ),
119 'Shortpages' => array( 'SpecialPage', 'Shortpages' ),
120 'Longpages' => array( 'SpecialPage', 'Longpages' ),
121 'Newpages' => 'SpecialNewpages',
122 'Ancientpages' => array( 'SpecialPage', 'Ancientpages' ),
123 'Deadendpages' => array( 'SpecialPage', 'Deadendpages' ),
124 'Protectedpages' => array( 'SpecialPage', 'Protectedpages' ),
125 'Protectedtitles' => array( 'SpecialPage', 'Protectedtitles' ),
126 'Allpages' => 'SpecialAllpages',
127 'Prefixindex' => 'SpecialPrefixindex',
128 'Ipblocklist' => array( 'SpecialPage', 'Ipblocklist' ),
129 'Specialpages' => array( 'UnlistedSpecialPage', 'Specialpages' ),
130 'Contributions' => array( 'SpecialPage', 'Contributions' ),
131 'Emailuser' => array( 'UnlistedSpecialPage', 'Emailuser' ),
132 'Whatlinkshere' => array( 'SpecialPage', 'Whatlinkshere' ),
133 'LinkSearch' => array( 'SpecialPage', 'LinkSearch' ),
134 'Recentchangeslinked' => 'SpecialRecentchangeslinked',
135 'Movepage' => array( 'UnlistedSpecialPage', 'Movepage' ),
136 'Blockme' => array( 'UnlistedSpecialPage', 'Blockme' ),
137 'Resetpass' => array( 'UnlistedSpecialPage', 'Resetpass' ),
138 'Booksources' => 'SpecialBookSources',
139 'Categories' => array( 'SpecialPage', 'Categories' ),
140 'Export' => array( 'SpecialPage', 'Export' ),
141 'Version' => array( 'SpecialPage', 'Version' ),
142 'Blankpage' => array( 'UnlistedSpecialPage', 'Blankpage' ),
143 'Allmessages' => array( 'SpecialPage', 'Allmessages' ),
144 'Log' => array( 'SpecialPage', 'Log' ),
145 'Blockip' => array( 'SpecialPage', 'Blockip', 'block' ),
146 'Undelete' => array( 'SpecialPage', 'Undelete', 'deletedhistory' ),
147 'Import' => array( 'SpecialPage', 'Import', 'import' ),
148 'Lockdb' => array( 'SpecialPage', 'Lockdb', 'siteadmin' ),
149 'Unlockdb' => array( 'SpecialPage', 'Unlockdb', 'siteadmin' ),
150 'Userrights' => 'UserrightsPage',
151 'MIMEsearch' => array( 'SpecialPage', 'MIMEsearch' ),
152 'FileDuplicateSearch' => array( 'SpecialPage', 'FileDuplicateSearch' ),
153 'Unwatchedpages' => array( 'SpecialPage', 'Unwatchedpages', 'unwatchedpages' ),
154 'Listredirects' => array( 'SpecialPage', 'Listredirects' ),
155 'Revisiondelete' => array( 'UnlistedSpecialPage', 'Revisiondelete', 'deleterevision' ),
156 'Unusedtemplates' => array( 'SpecialPage', 'Unusedtemplates' ),
157 'Randomredirect' => 'SpecialRandomredirect',
158 'Withoutinterwiki' => array( 'SpecialPage', 'Withoutinterwiki' ),
159 'Filepath' => array( 'SpecialPage', 'Filepath' ),
161 'Mypage' => array( 'SpecialMypage' ),
162 'Mytalk' => array( 'SpecialMytalk' ),
163 'Mycontributions' => array( 'SpecialMycontributions' ),
164 'Listadmins' => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
165 'MergeHistory' => array( 'SpecialPage', 'MergeHistory', 'mergehistory' ),
166 'Listbots' => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ),
169 static public $mAliases;
170 static public $mListInitialised = false;
175 * Initialise the special page list
176 * This must be called before accessing SpecialPage::$mList
178 static function initList() {
179 global $wgSpecialPages;
180 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
182 if ( self
::$mListInitialised ) {
185 wfProfileIn( __METHOD__
);
187 # Better to set this now, to avoid infinite recursion in carelessly written hooks
188 self
::$mListInitialised = true;
190 if( !$wgDisableCounters ) {
191 self
::$mList['Popularpages'] = array( 'SpecialPage', 'Popularpages' );
194 if( !$wgDisableInternalSearch ) {
195 self
::$mList['Search'] = array( 'SpecialPage', 'Search' );
198 if( $wgEmailAuthentication ) {
199 self
::$mList['Confirmemail'] = 'EmailConfirmation';
200 self
::$mList['Invalidateemail'] = 'EmailInvalidation';
203 # Add extension special pages
204 self
::$mList = array_merge( self
::$mList, $wgSpecialPages );
207 # This hook can be used to remove undesired built-in special pages
208 wfRunHooks( 'SpecialPage_initList', array( &self
::$mList ) );
209 wfProfileOut( __METHOD__
);
212 static function initAliasList() {
213 if ( !is_null( self
::$mAliases ) ) {
218 $aliases = $wgContLang->getSpecialPageAliases();
219 $missingPages = self
::$mList;
220 self
::$mAliases = array();
221 foreach ( $aliases as $realName => $aliasList ) {
222 foreach ( $aliasList as $alias ) {
223 self
::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
225 unset( $missingPages[$realName] );
227 foreach ( $missingPages as $name => $stuff ) {
228 self
::$mAliases[$wgContLang->caseFold( $name )] = $name;
233 * Given a special page alias, return the special page name.
234 * Returns false if there is no such alias.
236 static function resolveAlias( $alias ) {
239 if ( !self
::$mListInitialised ) self
::initList();
240 if ( is_null( self
::$mAliases ) ) self
::initAliasList();
241 $caseFoldedAlias = $wgContLang->caseFold( $alias );
242 if ( isset( self
::$mAliases[$caseFoldedAlias] ) ) {
243 return self
::$mAliases[$caseFoldedAlias];
250 * Given a special page name with a possible subpage, return an array
251 * where the first element is the special page name and the second is the
254 static function resolveAliasWithSubpage( $alias ) {
255 $bits = explode( '/', $alias, 2 );
256 $name = self
::resolveAlias( $bits[0] );
257 if( !isset( $bits[1] ) ) { // bug 2087
262 return array( $name, $par );
266 * Add a page to the list of valid special pages. This used to be the preferred
267 * method for adding special pages in extensions. It's now suggested that you add
268 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
270 * @param SpecialPage $page
273 static function addPage( &$page ) {
274 if ( !self
::$mListInitialised ) {
277 self
::$mList[$page->mName
] = $page;
281 * Add a page to a certain display group for Special:SpecialPages
283 * @param mixed $page (SpecialPage or string)
284 * @param string $group
287 static function setGroup( $page, $group ) {
288 global $wgSpecialPageGroups;
289 $name = is_object($page) ?
$page->mName
: $page;
290 $wgSpecialPageGroups[$name] = $group;
294 * Add a page to a certain display group for Special:SpecialPages
296 * @param SpecialPage $page
299 static function getGroup( &$page ) {
300 global $wgSpecialPageGroups;
301 static $specialPageGroupsCache = array();
302 if( isset($specialPageGroupsCache[$page->mName
]) ) {
303 return $specialPageGroupsCache[$page->mName
];
305 $group = wfMsg('specialpages-specialpagegroup-'.strtolower($page->mName
));
307 ||
wfEmptyMsg('specialpages-specialpagegroup-'.strtolower($page->mName
), $group ) ) {
308 $group = isset($wgSpecialPageGroups[$page->mName
])
309 ?
$wgSpecialPageGroups[$page->mName
]
312 if( $group == '-' ) $group = 'other';
313 $specialPageGroupsCache[$page->mName
] = $group;
318 * Remove a special page from the list
319 * Formerly used to disable expensive or dangerous special pages. The
320 * preferred method is now to add a SpecialPage_initList hook.
324 static function removePage( $name ) {
325 if ( !self
::$mListInitialised ) {
328 unset( self
::$mList[$name] );
332 * Check if a given name exist as a special page or as a special page alias
333 * @param $name string: name of a special page
334 * @return boolean: true if a special page exists with this name
336 static function exists( $name ) {
338 if ( !self
::$mListInitialised ) {
341 if( !self
::$mAliases ) {
342 self
::initAliasList();
345 # Remove special pages inline parameters:
346 $bits = explode( '/', $name );
347 $name = $wgContLang->caseFold($bits[0]);
350 array_key_exists( $name, self
::$mList )
351 or array_key_exists( $name, self
::$mAliases )
356 * Find the object with a given name and return it (or NULL)
358 * @param string $name
360 static function getPage( $name ) {
361 if ( !self
::$mListInitialised ) {
364 if ( array_key_exists( $name, self
::$mList ) ) {
365 $rec = self
::$mList[$name];
366 if ( is_string( $rec ) ) {
368 self
::$mList[$name] = new $className;
369 } elseif ( is_array( $rec ) ) {
370 $className = array_shift( $rec );
371 self
::$mList[$name] = wfCreateObject( $className, $rec );
373 return self
::$mList[$name];
380 * Get a special page with a given localised name, or NULL if there
381 * is no such special page.
383 static function getPageByAlias( $alias ) {
384 $realName = self
::resolveAlias( $alias );
386 return self
::getPage( $realName );
393 * Return categorised listable special pages which are available
394 * for the current user, and everyone.
397 static function getUsablePages() {
399 if ( !self
::$mListInitialised ) {
404 foreach ( self
::$mList as $name => $rec ) {
405 $page = self
::getPage( $name );
406 if ( $page->isListed()
408 !$page->isRestricted()
409 ||
$page->userCanExecute( $wgUser )
412 $pages[$name] = $page;
419 * Return categorised listable special pages for all users
422 static function getRegularPages() {
423 if ( !self
::$mListInitialised ) {
428 foreach ( self
::$mList as $name => $rec ) {
429 $page = self
::getPage( $name );
430 if ( $page->isListed() && !$page->isRestricted() ) {
431 $pages[$name] = $page;
438 * Return categorised listable special pages which are available
439 * for the current user, but not for everyone
442 static function getRestrictedPages() {
444 if( !self
::$mListInitialised ) {
449 foreach( self
::$mList as $name => $rec ) {
450 $page = self
::getPage( $name );
453 && $page->isRestricted()
454 && $page->userCanExecute( $wgUser )
456 $pages[$name] = $page;
463 * Execute a special page path.
464 * The path may contain parameters, e.g. Special:Name/Params
465 * Extracts the special page name and call the execute method, passing the parameters
467 * Returns a title object if the page is redirected, false if there was no such special
468 * page, and true if it was successful.
470 * @param $title a title object
471 * @param $including output is being captured for use in {{special:whatever}}
473 static function executePath( &$title, $including = false ) {
474 global $wgOut, $wgTitle, $wgRequest;
475 wfProfileIn( __METHOD__
);
477 # FIXME: redirects broken due to this call
478 $bits = explode( '/', $title->getDBkey(), 2 );
480 if( !isset( $bits[1] ) ) { // bug 2087
485 $page = SpecialPage
::getPageByAlias( $name );
489 $wgOut->setArticleRelated( false );
490 $wgOut->setRobotPolicy( 'noindex,nofollow' );
491 $wgOut->setStatusCode( 404 );
492 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
494 wfProfileOut( __METHOD__
);
500 $redirect = $page->getRedirect( $par );
502 $query = $page->getRedirectQuery();
503 $url = $redirect->getFullUrl( $query );
504 $wgOut->redirect( $url );
505 wfProfileOut( __METHOD__
);
510 # Redirect to canonical alias for GET commands
511 # Not for POST, we'd lose the post data, so it's best to just distribute
512 # the request. Such POST requests are possible for old extensions that
513 # generate self-links without being aware that their default name has
515 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
517 unset( $query['title'] );
518 $query = wfArrayToCGI( $query );
519 $title = $page->getTitle( $par );
520 $url = $title->getFullUrl( $query );
521 $wgOut->redirect( $url );
522 wfProfileOut( __METHOD__
);
526 if ( $including && !$page->includable() ) {
527 wfProfileOut( __METHOD__
);
529 } elseif ( !$including ) {
530 $wgTitle = $page->getTitle();
532 $page->including( $including );
534 // Execute special page
535 $profName = 'Special:' . $page->getName();
536 wfProfileIn( $profName );
537 $page->execute( $par );
538 wfProfileOut( $profName );
539 wfProfileOut( __METHOD__
);
544 * Just like executePath() except it returns the HTML instead of outputting it
545 * Returns false if there was no such special page, or a title object if it was
549 static function capturePath( &$title ) {
550 global $wgOut, $wgTitle;
552 $oldTitle = $wgTitle;
554 $wgOut = new OutputPage
;
556 $ret = SpecialPage
::executePath( $title, true );
557 if ( $ret === true ) {
558 $ret = $wgOut->getHTML();
560 $wgTitle = $oldTitle;
566 * Get the local name for a specified canonical name
569 * @param mixed $subpage Boolean false, or string
573 static function getLocalNameFor( $name, $subpage = false ) {
575 $aliases = $wgContLang->getSpecialPageAliases();
576 if ( isset( $aliases[$name][0] ) ) {
577 $name = $aliases[$name][0];
579 if ( $subpage !== false && !is_null( $subpage ) ) {
580 $name = "$name/$subpage";
586 * Get a localised Title object for a specified special page name
588 static function getTitleFor( $name, $subpage = false ) {
589 $name = self
::getLocalNameFor( $name, $subpage );
591 return Title
::makeTitle( NS_SPECIAL
, $name );
593 throw new MWException( "Invalid special page name \"$name\"" );
598 * Get a localised Title object for a page name with a possibly unvalidated subpage
600 static function getSafeTitleFor( $name, $subpage = false ) {
601 $name = self
::getLocalNameFor( $name, $subpage );
603 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
610 * Get a title for a given alias
611 * @return Title or null if there is no such alias
613 static function getTitleForAlias( $alias ) {
614 $name = self
::resolveAlias( $alias );
616 return self
::getTitleFor( $name );
623 * Default constructor for special pages
624 * Derivative classes should call this from their constructor
625 * Note that if the user does not have the required level, an error message will
626 * be displayed by the default execute() method, without the global function ever
629 * If you override execute(), you can recover the default behaviour with userCanExecute()
630 * and displayRestrictionError()
632 * @param string $name Name of the special page, as seen in links and URLs
633 * @param string $restriction User right required, e.g. "block" or "delete"
634 * @param boolean $listed Whether the page is listed in Special:Specialpages
635 * @param string $function Function called by execute(). By default it is constructed from $name
636 * @param string $file File which is included by execute(). It is also constructed from $name by default
638 function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
639 $this->mName
= $name;
640 $this->mRestriction
= $restriction;
641 $this->mListed
= $listed;
642 $this->mIncludable
= $includable;
643 if ( $function == false ) {
644 $this->mFunction
= 'wfSpecial'.$name;
646 $this->mFunction
= $function;
648 if ( $file === 'default' ) {
649 $this->mFile
= dirname(__FILE__
) . "/specials/Special$name.php";
651 $this->mFile
= $file;
660 function getName() { return $this->mName
; }
661 function getRestriction() { return $this->mRestriction
; }
662 function getFile() { return $this->mFile
; }
663 function isListed() { return $this->mListed
; }
667 * Accessor and mutator
669 function name( $x = NULL ) { return wfSetVar( $this->mName
, $x ); }
670 function restrictions( $x = NULL) { return wfSetVar( $this->mRestrictions
, $x ); }
671 function listed( $x = NULL) { return wfSetVar( $this->mListed
, $x ); }
672 function func( $x = NULL) { return wfSetVar( $this->mFunction
, $x ); }
673 function file( $x = NULL) { return wfSetVar( $this->mFile
, $x ); }
674 function includable( $x = NULL ) { return wfSetVar( $this->mIncludable
, $x ); }
675 function including( $x = NULL ) { return wfSetVar( $this->mIncluding
, $x ); }
679 * Get the localised name of the special page
681 function getLocalName() {
682 if ( !isset( $this->mLocalName
) ) {
683 $this->mLocalName
= self
::getLocalNameFor( $this->mName
);
685 return $this->mLocalName
;
689 * Can be overridden by subclasses with more complicated permissions
692 * @return bool Should the page be displayed with the restricted-access
695 public function isRestricted() {
696 return $this->mRestriction
!= '';
700 * Checks if the given user (identified by an object) can execute this
701 * special page (as defined by $mRestriction). Can be overridden by sub-
702 * classes with more complicated permissions schemes.
704 * @param User $user The user to check
705 * @return bool Does the user have permission to view the page?
707 public function userCanExecute( $user ) {
708 return $user->isAllowed( $this->mRestriction
);
712 * Output an error message telling the user what access level they have to have
714 function displayRestrictionError() {
716 $wgOut->permissionRequired( $this->mRestriction
);
720 * Sets headers - this should be called from the execute() method of all derived classes!
722 function setHeaders() {
724 $wgOut->setArticleRelated( false );
725 $wgOut->setRobotPolicy( "noindex,nofollow" );
726 $wgOut->setPageTitle( $this->getDescription() );
730 * Default execute method
731 * Checks user permissions, calls the function given in mFunction
733 * This may be overridden by subclasses.
735 function execute( $par ) {
740 if ( $this->userCanExecute( $wgUser ) ) {
741 $func = $this->mFunction
;
742 // only load file if the function does not exist
743 if ( !is_callable( $func ) ) {
744 // Check whether a run method has been defined
745 if ( is_callable( array( $this, 'run' ) ) )
746 $func = array( $this, 'run' );
747 // Else load from file if it has been specified
748 elseif ( $this->mFile
)
749 require_once( $this->mFile
);
751 # FIXME: these hooks are broken for extensions and anything else that subclasses SpecialPage.
752 if ( wfRunHooks( 'SpecialPageExecuteBeforeHeader', array( &$this, &$par, &$func ) ) )
753 $this->outputHeader();
754 if ( ! wfRunHooks( 'SpecialPageExecuteBeforePage', array( &$this, &$par, &$func ) ) )
756 call_user_func( $func, $par, $this );
757 if ( ! wfRunHooks( 'SpecialPageExecuteAfterPage', array( &$this, &$par, &$func ) ) )
760 $this->displayRestrictionError();
765 function outputHeader() {
766 global $wgOut, $wgContLang;
768 $msg = $wgContLang->lc( $this->name() ) . '-summary';
769 $out = wfMsgNoTrans( $msg );
770 if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() ) {
771 $wgOut->addWikiMsg( $msg );
776 # Returns the name that goes in the <h1> in the special page itself, and also the name that
777 # will be listed in Special:Specialpages
779 # Derived classes can override this, but usually it is easier to keep the default behaviour.
780 # Messages can be added at run-time, see MessageCache.php
781 function getDescription() {
782 return wfMsg( strtolower( $this->mName
) );
786 * Get a self-referential title object
788 function getTitle( $subpage = false) {
789 return self
::getTitleFor( $this->mName
, $subpage );
793 * Set whether this page is listed in Special:Specialpages, at run-time
795 function setListed( $listed ) {
796 return wfSetVar( $this->mListed
, $listed );
800 * If the special page is a redirect, then get the Title object it redirects to.
803 function getRedirect( $subpage ) {
808 * Return part of the request string for a special redirect page
809 * This allows passing, e.g. action=history to Special:Mypage, etc.
813 function getRedirectQuery() {
816 foreach( $this->mAllowedRedirectParams
as $arg ) {
817 if( $val = $wgRequest->getVal( $arg, false ) )
818 $params[] = $arg . '=' . $val;
821 return count( $params ) ?
implode( '&', $params ) : false;
826 * Shortcut to construct a special page which is unlisted by default
827 * @ingroup SpecialPage
829 class UnlistedSpecialPage
extends SpecialPage
831 function UnlistedSpecialPage( $name, $restriction = '', $function = false, $file = 'default' ) {
832 SpecialPage
::SpecialPage( $name, $restriction, false, $function, $file );
837 * Shortcut to construct an includable special page
838 * @ingroup SpecialPage
840 class IncludableSpecialPage
extends SpecialPage
842 function IncludableSpecialPage( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
843 SpecialPage
::SpecialPage( $name, $restriction, $listed, $function, $file, true );
848 * Shortcut to construct a special page alias.
849 * @ingroup SpecialPage
851 class SpecialRedirectToSpecial
extends UnlistedSpecialPage
{
852 var $redirName, $redirSubpage;
854 function __construct( $name, $redirName, $redirSubpage = false, $redirectParams = array() ) {
855 parent
::__construct( $name );
856 $this->redirName
= $redirName;
857 $this->redirSubpage
= $redirSubpage;
858 $this->mAllowedRedirectParams
= $redirectParams;
861 function getRedirect( $subpage ) {
862 if ( $this->redirSubpage
=== false ) {
863 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
865 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
870 /** SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
871 * are used to get user independant links pointing to the user page, talk
872 * page and list of contributions.
873 * This can let us cache a single copy of any generated content for all
878 * Shortcut to construct a special page pointing to current user user's page.
879 * @ingroup SpecialPage
881 class SpecialMypage
extends UnlistedSpecialPage
{
882 function __construct() {
883 parent
::__construct( 'Mypage' );
884 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro', 'section' );
887 function getRedirect( $subpage ) {
889 if ( strval( $subpage ) !== '' ) {
890 return Title
::makeTitle( NS_USER
, $wgUser->getName() . '/' . $subpage );
892 return Title
::makeTitle( NS_USER
, $wgUser->getName() );
898 * Shortcut to construct a special page pointing to current user talk page.
899 * @ingroup SpecialPage
901 class SpecialMytalk
extends UnlistedSpecialPage
{
902 function __construct() {
903 parent
::__construct( 'Mytalk' );
904 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro', 'section' );
907 function getRedirect( $subpage ) {
909 if ( strval( $subpage ) !== '' ) {
910 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() . '/' . $subpage );
912 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() );
918 * Shortcut to construct a special page pointing to current user contributions.
919 * @ingroup SpecialPage
921 class SpecialMycontributions
extends UnlistedSpecialPage
{
922 function __construct() {
923 parent
::__construct( 'Mycontributions' );
926 function getRedirect( $subpage ) {
928 return SpecialPage
::getTitleFor( 'Contributions', $wgUser->getName() );