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' ),
160 'Dismissnotice' => array( 'UnlistedSpecialPage', 'Dismissnotice' ),
162 'Mypage' => array( 'SpecialMypage' ),
163 'Mytalk' => array( 'SpecialMytalk' ),
164 'Mycontributions' => array( 'SpecialMycontributions' ),
165 'Listadmins' => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
166 'MergeHistory' => array( 'SpecialPage', 'MergeHistory', 'mergehistory' ),
167 'Listbots' => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ),
168 'Nuke' => 'SpecialNuke',
171 static public $mAliases;
172 static public $mListInitialised = false;
177 * Initialise the special page list
178 * This must be called before accessing SpecialPage::$mList
180 static function initList() {
181 global $wgSpecialPages;
182 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
184 if ( self
::$mListInitialised ) {
187 wfProfileIn( __METHOD__
);
189 # Better to set this now, to avoid infinite recursion in carelessly written hooks
190 self
::$mListInitialised = true;
192 if( !$wgDisableCounters ) {
193 self
::$mList['Popularpages'] = array( 'SpecialPage', 'Popularpages' );
196 if( !$wgDisableInternalSearch ) {
197 self
::$mList['Search'] = array( 'SpecialPage', 'Search' );
200 if( $wgEmailAuthentication ) {
201 self
::$mList['Confirmemail'] = 'EmailConfirmation';
202 self
::$mList['Invalidateemail'] = 'EmailInvalidation';
205 # Add extension special pages
206 self
::$mList = array_merge( self
::$mList, $wgSpecialPages );
209 # This hook can be used to remove undesired built-in special pages
210 wfRunHooks( 'SpecialPage_initList', array( &self
::$mList ) );
211 wfProfileOut( __METHOD__
);
214 static function initAliasList() {
215 if ( !is_null( self
::$mAliases ) ) {
220 $aliases = $wgContLang->getSpecialPageAliases();
221 $missingPages = self
::$mList;
222 self
::$mAliases = array();
223 foreach ( $aliases as $realName => $aliasList ) {
224 foreach ( $aliasList as $alias ) {
225 self
::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
227 unset( $missingPages[$realName] );
229 foreach ( $missingPages as $name => $stuff ) {
230 self
::$mAliases[$wgContLang->caseFold( $name )] = $name;
235 * Given a special page alias, return the special page name.
236 * Returns false if there is no such alias.
238 static function resolveAlias( $alias ) {
241 if ( !self
::$mListInitialised ) self
::initList();
242 if ( is_null( self
::$mAliases ) ) self
::initAliasList();
243 $caseFoldedAlias = $wgContLang->caseFold( $alias );
244 if ( isset( self
::$mAliases[$caseFoldedAlias] ) ) {
245 return self
::$mAliases[$caseFoldedAlias];
252 * Given a special page name with a possible subpage, return an array
253 * where the first element is the special page name and the second is the
256 static function resolveAliasWithSubpage( $alias ) {
257 $bits = explode( '/', $alias, 2 );
258 $name = self
::resolveAlias( $bits[0] );
259 if( !isset( $bits[1] ) ) { // bug 2087
264 return array( $name, $par );
268 * Add a page to the list of valid special pages. This used to be the preferred
269 * method for adding special pages in extensions. It's now suggested that you add
270 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
272 * @param SpecialPage $page
275 static function addPage( &$page ) {
276 if ( !self
::$mListInitialised ) {
279 self
::$mList[$page->mName
] = $page;
283 * Add a page to a certain display group for Special:SpecialPages
285 * @param mixed $page (SpecialPage or string)
286 * @param string $group
289 static function setGroup( $page, $group ) {
290 global $wgSpecialPageGroups;
291 $name = is_object($page) ?
$page->mName
: $page;
292 $wgSpecialPageGroups[$name] = $group;
296 * Add a page to a certain display group for Special:SpecialPages
298 * @param SpecialPage $page
301 static function getGroup( &$page ) {
302 global $wgSpecialPageGroups;
303 static $specialPageGroupsCache = array();
304 if( isset($specialPageGroupsCache[$page->mName
]) ) {
305 return $specialPageGroupsCache[$page->mName
];
307 $group = wfMsg('specialpages-specialpagegroup-'.strtolower($page->mName
));
309 ||
wfEmptyMsg('specialpages-specialpagegroup-'.strtolower($page->mName
), $group ) ) {
310 $group = isset($wgSpecialPageGroups[$page->mName
])
311 ?
$wgSpecialPageGroups[$page->mName
]
314 if( $group == '-' ) $group = 'other';
315 $specialPageGroupsCache[$page->mName
] = $group;
320 * Remove a special page from the list
321 * Formerly used to disable expensive or dangerous special pages. The
322 * preferred method is now to add a SpecialPage_initList hook.
326 static function removePage( $name ) {
327 if ( !self
::$mListInitialised ) {
330 unset( self
::$mList[$name] );
334 * Check if a given name exist as a special page or as a special page alias
335 * @param $name string: name of a special page
336 * @return boolean: true if a special page exists with this name
338 static function exists( $name ) {
340 if ( !self
::$mListInitialised ) {
343 if( !self
::$mAliases ) {
344 self
::initAliasList();
347 # Remove special pages inline parameters:
348 $bits = explode( '/', $name );
349 $name = $wgContLang->caseFold($bits[0]);
352 array_key_exists( $name, self
::$mList )
353 or array_key_exists( $name, self
::$mAliases )
358 * Find the object with a given name and return it (or NULL)
360 * @param string $name
362 static function getPage( $name ) {
363 if ( !self
::$mListInitialised ) {
366 if ( array_key_exists( $name, self
::$mList ) ) {
367 $rec = self
::$mList[$name];
368 if ( is_string( $rec ) ) {
370 self
::$mList[$name] = new $className;
371 } elseif ( is_array( $rec ) ) {
372 $className = array_shift( $rec );
373 self
::$mList[$name] = wfCreateObject( $className, $rec );
375 return self
::$mList[$name];
382 * Get a special page with a given localised name, or NULL if there
383 * is no such special page.
385 static function getPageByAlias( $alias ) {
386 $realName = self
::resolveAlias( $alias );
388 return self
::getPage( $realName );
395 * Return categorised listable special pages which are available
396 * for the current user, and everyone.
399 static function getUsablePages() {
401 if ( !self
::$mListInitialised ) {
406 foreach ( self
::$mList as $name => $rec ) {
407 $page = self
::getPage( $name );
408 if ( $page->isListed()
410 !$page->isRestricted()
411 ||
$page->userCanExecute( $wgUser )
414 $pages[$name] = $page;
421 * Return categorised listable special pages for all users
424 static function getRegularPages() {
425 if ( !self
::$mListInitialised ) {
430 foreach ( self
::$mList as $name => $rec ) {
431 $page = self
::getPage( $name );
432 if ( $page->isListed() && !$page->isRestricted() ) {
433 $pages[$name] = $page;
440 * Return categorised listable special pages which are available
441 * for the current user, but not for everyone
444 static function getRestrictedPages() {
446 if( !self
::$mListInitialised ) {
451 foreach( self
::$mList as $name => $rec ) {
452 $page = self
::getPage( $name );
455 && $page->isRestricted()
456 && $page->userCanExecute( $wgUser )
458 $pages[$name] = $page;
465 * Execute a special page path.
466 * The path may contain parameters, e.g. Special:Name/Params
467 * Extracts the special page name and call the execute method, passing the parameters
469 * Returns a title object if the page is redirected, false if there was no such special
470 * page, and true if it was successful.
472 * @param $title a title object
473 * @param $including output is being captured for use in {{special:whatever}}
475 static function executePath( &$title, $including = false ) {
476 global $wgOut, $wgTitle, $wgRequest;
477 wfProfileIn( __METHOD__
);
479 # FIXME: redirects broken due to this call
480 $bits = explode( '/', $title->getDBkey(), 2 );
482 if( !isset( $bits[1] ) ) { // bug 2087
487 $page = SpecialPage
::getPageByAlias( $name );
491 $wgOut->setArticleRelated( false );
492 $wgOut->setRobotPolicy( 'noindex,nofollow' );
493 $wgOut->setStatusCode( 404 );
494 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
496 wfProfileOut( __METHOD__
);
502 $redirect = $page->getRedirect( $par );
504 $query = $page->getRedirectQuery();
505 $url = $redirect->getFullUrl( $query );
506 $wgOut->redirect( $url );
507 wfProfileOut( __METHOD__
);
512 # Redirect to canonical alias for GET commands
513 # Not for POST, we'd lose the post data, so it's best to just distribute
514 # the request. Such POST requests are possible for old extensions that
515 # generate self-links without being aware that their default name has
517 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
519 unset( $query['title'] );
520 $query = wfArrayToCGI( $query );
521 $title = $page->getTitle( $par );
522 $url = $title->getFullUrl( $query );
523 $wgOut->redirect( $url );
524 wfProfileOut( __METHOD__
);
528 if ( $including && !$page->includable() ) {
529 wfProfileOut( __METHOD__
);
531 } elseif ( !$including ) {
532 $wgTitle = $page->getTitle();
534 $page->including( $including );
536 // Execute special page
537 $profName = 'Special:' . $page->getName();
538 wfProfileIn( $profName );
539 $page->execute( $par );
540 wfProfileOut( $profName );
541 wfProfileOut( __METHOD__
);
546 * Just like executePath() except it returns the HTML instead of outputting it
547 * Returns false if there was no such special page, or a title object if it was
551 static function capturePath( &$title ) {
552 global $wgOut, $wgTitle;
554 $oldTitle = $wgTitle;
556 $wgOut = new OutputPage
;
558 $ret = SpecialPage
::executePath( $title, true );
559 if ( $ret === true ) {
560 $ret = $wgOut->getHTML();
562 $wgTitle = $oldTitle;
568 * Get the local name for a specified canonical name
571 * @param mixed $subpage Boolean false, or string
575 static function getLocalNameFor( $name, $subpage = false ) {
577 $aliases = $wgContLang->getSpecialPageAliases();
578 if ( isset( $aliases[$name][0] ) ) {
579 $name = $aliases[$name][0];
581 if ( $subpage !== false && !is_null( $subpage ) ) {
582 $name = "$name/$subpage";
588 * Get a localised Title object for a specified special page name
590 static function getTitleFor( $name, $subpage = false ) {
591 $name = self
::getLocalNameFor( $name, $subpage );
593 return Title
::makeTitle( NS_SPECIAL
, $name );
595 throw new MWException( "Invalid special page name \"$name\"" );
600 * Get a localised Title object for a page name with a possibly unvalidated subpage
602 static function getSafeTitleFor( $name, $subpage = false ) {
603 $name = self
::getLocalNameFor( $name, $subpage );
605 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
612 * Get a title for a given alias
613 * @return Title or null if there is no such alias
615 static function getTitleForAlias( $alias ) {
616 $name = self
::resolveAlias( $alias );
618 return self
::getTitleFor( $name );
625 * Default constructor for special pages
626 * Derivative classes should call this from their constructor
627 * Note that if the user does not have the required level, an error message will
628 * be displayed by the default execute() method, without the global function ever
631 * If you override execute(), you can recover the default behaviour with userCanExecute()
632 * and displayRestrictionError()
634 * @param string $name Name of the special page, as seen in links and URLs
635 * @param string $restriction User right required, e.g. "block" or "delete"
636 * @param boolean $listed Whether the page is listed in Special:Specialpages
637 * @param string $function Function called by execute(). By default it is constructed from $name
638 * @param string $file File which is included by execute(). It is also constructed from $name by default
640 function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
641 $this->mName
= $name;
642 $this->mRestriction
= $restriction;
643 $this->mListed
= $listed;
644 $this->mIncludable
= $includable;
645 if ( $function == false ) {
646 $this->mFunction
= 'wfSpecial'.$name;
648 $this->mFunction
= $function;
650 if ( $file === 'default' ) {
651 $this->mFile
= dirname(__FILE__
) . "/specials/Special$name.php";
653 $this->mFile
= $file;
662 function getName() { return $this->mName
; }
663 function getRestriction() { return $this->mRestriction
; }
664 function getFile() { return $this->mFile
; }
665 function isListed() { return $this->mListed
; }
669 * Accessor and mutator
671 function name( $x = NULL ) { return wfSetVar( $this->mName
, $x ); }
672 function restrictions( $x = NULL) { return wfSetVar( $this->mRestrictions
, $x ); }
673 function listed( $x = NULL) { return wfSetVar( $this->mListed
, $x ); }
674 function func( $x = NULL) { return wfSetVar( $this->mFunction
, $x ); }
675 function file( $x = NULL) { return wfSetVar( $this->mFile
, $x ); }
676 function includable( $x = NULL ) { return wfSetVar( $this->mIncludable
, $x ); }
677 function including( $x = NULL ) { return wfSetVar( $this->mIncluding
, $x ); }
681 * Get the localised name of the special page
683 function getLocalName() {
684 if ( !isset( $this->mLocalName
) ) {
685 $this->mLocalName
= self
::getLocalNameFor( $this->mName
);
687 return $this->mLocalName
;
691 * Can be overridden by subclasses with more complicated permissions
694 * @return bool Should the page be displayed with the restricted-access
697 public function isRestricted() {
698 return $this->mRestriction
!= '';
702 * Checks if the given user (identified by an object) can execute this
703 * special page (as defined by $mRestriction). Can be overridden by sub-
704 * classes with more complicated permissions schemes.
706 * @param User $user The user to check
707 * @return bool Does the user have permission to view the page?
709 public function userCanExecute( $user ) {
710 return $user->isAllowed( $this->mRestriction
);
714 * Output an error message telling the user what access level they have to have
716 function displayRestrictionError() {
718 $wgOut->permissionRequired( $this->mRestriction
);
722 * Sets headers - this should be called from the execute() method of all derived classes!
724 function setHeaders() {
726 $wgOut->setArticleRelated( false );
727 $wgOut->setRobotPolicy( "noindex,nofollow" );
728 $wgOut->setPageTitle( $this->getDescription() );
732 * Default execute method
733 * Checks user permissions, calls the function given in mFunction
735 * This may be overridden by subclasses.
737 function execute( $par ) {
742 if ( $this->userCanExecute( $wgUser ) ) {
743 $func = $this->mFunction
;
744 // only load file if the function does not exist
745 if(!is_callable($func) and $this->mFile
) {
746 require_once( $this->mFile
);
748 # FIXME: these hooks are broken for extensions and anything else that subclasses SpecialPage.
749 if ( wfRunHooks( 'SpecialPageExecuteBeforeHeader', array( &$this, &$par, &$func ) ) )
750 $this->outputHeader();
751 if ( ! wfRunHooks( 'SpecialPageExecuteBeforePage', array( &$this, &$par, &$func ) ) )
753 call_user_func( $func, $par, $this );
754 if ( ! wfRunHooks( 'SpecialPageExecuteAfterPage', array( &$this, &$par, &$func ) ) )
757 $this->displayRestrictionError();
761 function outputHeader() {
762 global $wgOut, $wgContLang;
764 $msg = $wgContLang->lc( $this->name() ) . '-summary';
765 $out = wfMsgNoTrans( $msg );
766 if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() ) {
767 $wgOut->addWikiMsg( $msg );
772 # Returns the name that goes in the <h1> in the special page itself, and also the name that
773 # will be listed in Special:Specialpages
775 # Derived classes can override this, but usually it is easier to keep the default behaviour.
776 # Messages can be added at run-time, see MessageCache.php
777 function getDescription() {
778 return wfMsg( strtolower( $this->mName
) );
782 * Get a self-referential title object
784 function getTitle( $subpage = false) {
785 return self
::getTitleFor( $this->mName
, $subpage );
789 * Set whether this page is listed in Special:Specialpages, at run-time
791 function setListed( $listed ) {
792 return wfSetVar( $this->mListed
, $listed );
796 * If the special page is a redirect, then get the Title object it redirects to.
799 function getRedirect( $subpage ) {
804 * Return part of the request string for a special redirect page
805 * This allows passing, e.g. action=history to Special:Mypage, etc.
809 function getRedirectQuery() {
812 foreach( $this->mAllowedRedirectParams
as $arg ) {
813 if( $val = $wgRequest->getVal( $arg, false ) )
814 $params[] = $arg . '=' . $val;
817 return count( $params ) ?
implode( '&', $params ) : false;
822 * Shortcut to construct a special page which is unlisted by default
823 * @ingroup SpecialPage
825 class UnlistedSpecialPage
extends SpecialPage
827 function UnlistedSpecialPage( $name, $restriction = '', $function = false, $file = 'default' ) {
828 SpecialPage
::SpecialPage( $name, $restriction, false, $function, $file );
833 * Shortcut to construct an includable special page
834 * @ingroup SpecialPage
836 class IncludableSpecialPage
extends SpecialPage
838 function IncludableSpecialPage( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
839 SpecialPage
::SpecialPage( $name, $restriction, $listed, $function, $file, true );
844 * Shortcut to construct a special page alias.
845 * @ingroup SpecialPage
847 class SpecialRedirectToSpecial
extends UnlistedSpecialPage
{
848 var $redirName, $redirSubpage;
850 function __construct( $name, $redirName, $redirSubpage = false, $redirectParams = array() ) {
851 parent
::__construct( $name );
852 $this->redirName
= $redirName;
853 $this->redirSubpage
= $redirSubpage;
854 $this->mAllowedRedirectParams
= $redirectParams;
857 function getRedirect( $subpage ) {
858 if ( $this->redirSubpage
=== false ) {
859 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
861 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
866 /** SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
867 * are used to get user independant links pointing to the user page, talk
868 * page and list of contributions.
869 * This can let us cache a single copy of any generated content for all
874 * Shortcut to construct a special page pointing to current user user's page.
875 * @ingroup SpecialPage
877 class SpecialMypage
extends UnlistedSpecialPage
{
878 function __construct() {
879 parent
::__construct( 'Mypage' );
880 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro', 'section' );
883 function getRedirect( $subpage ) {
885 if ( strval( $subpage ) !== '' ) {
886 return Title
::makeTitle( NS_USER
, $wgUser->getName() . '/' . $subpage );
888 return Title
::makeTitle( NS_USER
, $wgUser->getName() );
894 * Shortcut to construct a special page pointing to current user talk page.
895 * @ingroup SpecialPage
897 class SpecialMytalk
extends UnlistedSpecialPage
{
898 function __construct() {
899 parent
::__construct( 'Mytalk' );
900 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro', 'section' );
903 function getRedirect( $subpage ) {
905 if ( strval( $subpage ) !== '' ) {
906 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() . '/' . $subpage );
908 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() );
914 * Shortcut to construct a special page pointing to current user contributions.
915 * @ingroup SpecialPage
917 class SpecialMycontributions
extends UnlistedSpecialPage
{
918 function __construct() {
919 parent
::__construct( 'Mycontributions' );
922 function getRedirect( $subpage ) {
924 return SpecialPage
::getTitleFor( 'Contributions', $wgUser->getName() );