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' => array( 'SpecialPage', 'Preferences' ),
125 'Contributions' => 'SpecialContributions',
126 'Listgrouprights' => 'SpecialListGroupRights',
127 'Listusers' => array( 'SpecialPage', 'Listusers' ),
128 'Userrights' => 'UserrightsPage',
130 # Recent changes and logs
131 'Newimages' => array( 'IncludableSpecialPage', 'Newimages' ),
132 'Log' => array( 'SpecialPage', 'Log' ),
133 'Watchlist' => array( 'SpecialPage', 'Watchlist' ),
134 'Newpages' => 'SpecialNewpages',
135 'Recentchanges' => 'SpecialRecentchanges',
136 'Recentchangeslinked' => 'SpecialRecentchangeslinked',
137 'Tags' => 'SpecialTags',
139 # Media reports and uploads
140 'Listfiles' => array( 'SpecialPage', 'Listfiles' ),
141 'Filepath' => array( 'SpecialPage', 'Filepath' ),
142 'MIMEsearch' => array( 'SpecialPage', 'MIMEsearch' ),
143 'FileDuplicateSearch' => array( 'SpecialPage', 'FileDuplicateSearch' ),
144 'Upload' => array( 'SpecialPage', 'Upload' ),
146 # Wiki data and tools
147 'Statistics' => 'SpecialStatistics',
148 'Allmessages' => array( 'SpecialPage', 'Allmessages' ),
149 'Version' => 'SpecialVersion',
150 'Lockdb' => array( 'SpecialPage', 'Lockdb', 'siteadmin' ),
151 'Unlockdb' => array( 'SpecialPage', 'Unlockdb', 'siteadmin' ),
153 # Redirecting special pages
154 'LinkSearch' => array( 'SpecialPage', 'LinkSearch' ),
155 'Randompage' => 'Randompage',
156 'Randomredirect' => 'SpecialRandomredirect',
159 'Mostlinkedcategories' => array( 'SpecialPage', 'Mostlinkedcategories' ),
160 'Mostimages' => array( 'SpecialPage', 'Mostimages' ),
161 'Mostlinked' => array( 'SpecialPage', 'Mostlinked' ),
162 'Mostlinkedtemplates' => array( 'SpecialPage', 'Mostlinkedtemplates' ),
163 'Mostcategories' => array( 'SpecialPage', 'Mostcategories' ),
164 'Mostrevisions' => array( 'SpecialPage', 'Mostrevisions' ),
167 'Export' => 'SpecialExport',
168 'Import' => 'SpecialImport',
169 'Undelete' => array( 'SpecialPage', 'Undelete', 'deletedhistory' ),
170 'Whatlinkshere' => 'SpecialWhatlinkshere',
171 'MergeHistory' => array( 'SpecialPage', 'MergeHistory', 'mergehistory' ),
174 'Booksources' => 'SpecialBookSources',
176 # Unlisted / redirects
177 'Blankpage' => array( 'UnlistedSpecialPage', 'Blankpage' ),
178 'Blockme' => array( 'UnlistedSpecialPage', 'Blockme' ),
179 'Emailuser' => array( 'UnlistedSpecialPage', 'Emailuser' ),
180 'Listadmins' => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
181 'Listbots' => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ),
182 'Movepage' => array( 'UnlistedSpecialPage', 'Movepage' ),
183 'Mycontributions' => array( 'SpecialMycontributions' ),
184 'Mypage' => array( 'SpecialMypage' ),
185 'Mytalk' => array( 'SpecialMytalk' ),
186 'Revisiondelete' => 'SpecialRevisionDelete',
187 'Specialpages' => array( 'UnlistedSpecialPage', 'Specialpages' ),
188 'Userlogout' => array( 'UnlistedSpecialPage', 'Userlogout' ),
191 static public $mAliases;
192 static public $mListInitialised = false;
197 * Initialise the special page list
198 * This must be called before accessing SpecialPage::$mList
200 static function initList() {
201 global $wgSpecialPages;
202 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
204 if ( self
::$mListInitialised ) {
207 wfProfileIn( __METHOD__
);
209 # Better to set this now, to avoid infinite recursion in carelessly written hooks
210 self
::$mListInitialised = true;
212 if( !$wgDisableCounters ) {
213 self
::$mList['Popularpages'] = array( 'SpecialPage', 'Popularpages' );
216 if( !$wgDisableInternalSearch ) {
217 self
::$mList['Search'] = array( 'SpecialPage', 'Search' );
220 if( $wgEmailAuthentication ) {
221 self
::$mList['Confirmemail'] = 'EmailConfirmation';
222 self
::$mList['Invalidateemail'] = 'EmailInvalidation';
225 # Add extension special pages
226 self
::$mList = array_merge( self
::$mList, $wgSpecialPages );
229 # This hook can be used to remove undesired built-in special pages
230 wfRunHooks( 'SpecialPage_initList', array( &self
::$mList ) );
231 wfProfileOut( __METHOD__
);
234 static function initAliasList() {
235 if ( !is_null( self
::$mAliases ) ) {
240 $aliases = $wgContLang->getSpecialPageAliases();
241 $missingPages = self
::$mList;
242 self
::$mAliases = array();
243 foreach ( $aliases as $realName => $aliasList ) {
244 foreach ( $aliasList as $alias ) {
245 self
::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
247 unset( $missingPages[$realName] );
249 foreach ( $missingPages as $name => $stuff ) {
250 self
::$mAliases[$wgContLang->caseFold( $name )] = $name;
255 * Given a special page alias, return the special page name.
256 * Returns false if there is no such alias.
258 static function resolveAlias( $alias ) {
261 if ( !self
::$mListInitialised ) self
::initList();
262 if ( is_null( self
::$mAliases ) ) self
::initAliasList();
263 $caseFoldedAlias = $wgContLang->caseFold( $alias );
264 if ( isset( self
::$mAliases[$caseFoldedAlias] ) ) {
265 return self
::$mAliases[$caseFoldedAlias];
272 * Given a special page name with a possible subpage, return an array
273 * where the first element is the special page name and the second is the
276 static function resolveAliasWithSubpage( $alias ) {
277 $bits = explode( '/', $alias, 2 );
278 $name = self
::resolveAlias( $bits[0] );
279 if( !isset( $bits[1] ) ) { // bug 2087
284 return array( $name, $par );
288 * Add a page to the list of valid special pages. This used to be the preferred
289 * method for adding special pages in extensions. It's now suggested that you add
290 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
292 * @param SpecialPage $page
295 static function addPage( &$page ) {
296 if ( !self
::$mListInitialised ) {
299 self
::$mList[$page->mName
] = $page;
303 * Add a page to a certain display group for Special:SpecialPages
305 * @param mixed $page (SpecialPage or string)
306 * @param string $group
309 static function setGroup( $page, $group ) {
310 global $wgSpecialPageGroups;
311 $name = is_object($page) ?
$page->mName
: $page;
312 $wgSpecialPageGroups[$name] = $group;
316 * Add a page to a certain display group for Special:SpecialPages
318 * @param SpecialPage $page
321 static function getGroup( &$page ) {
322 global $wgSpecialPageGroups;
323 static $specialPageGroupsCache = array();
324 if( isset($specialPageGroupsCache[$page->mName
]) ) {
325 return $specialPageGroupsCache[$page->mName
];
327 $group = wfMsg('specialpages-specialpagegroup-'.strtolower($page->mName
));
329 ||
wfEmptyMsg('specialpages-specialpagegroup-'.strtolower($page->mName
), $group ) ) {
330 $group = isset($wgSpecialPageGroups[$page->mName
])
331 ?
$wgSpecialPageGroups[$page->mName
]
334 if( $group == '-' ) $group = 'other';
335 $specialPageGroupsCache[$page->mName
] = $group;
340 * Remove a special page from the list
341 * Formerly used to disable expensive or dangerous special pages. The
342 * preferred method is now to add a SpecialPage_initList hook.
346 static function removePage( $name ) {
347 if ( !self
::$mListInitialised ) {
350 unset( self
::$mList[$name] );
354 * Check if a given name exist as a special page or as a special page alias
355 * @param $name string: name of a special page
356 * @return boolean: true if a special page exists with this name
358 static function exists( $name ) {
360 if ( !self
::$mListInitialised ) {
363 if( !self
::$mAliases ) {
364 self
::initAliasList();
367 # Remove special pages inline parameters:
368 $bits = explode( '/', $name );
369 $name = $wgContLang->caseFold($bits[0]);
372 array_key_exists( $name, self
::$mList )
373 or array_key_exists( $name, self
::$mAliases )
378 * Find the object with a given name and return it (or NULL)
380 * @param string $name
382 static function getPage( $name ) {
383 if ( !self
::$mListInitialised ) {
386 if ( array_key_exists( $name, self
::$mList ) ) {
387 $rec = self
::$mList[$name];
388 if ( is_string( $rec ) ) {
390 self
::$mList[$name] = new $className;
391 } elseif ( is_array( $rec ) ) {
392 $className = array_shift( $rec );
393 self
::$mList[$name] = wfCreateObject( $className, $rec );
395 return self
::$mList[$name];
402 * Get a special page with a given localised name, or NULL if there
403 * is no such special page.
405 static function getPageByAlias( $alias ) {
406 $realName = self
::resolveAlias( $alias );
408 return self
::getPage( $realName );
415 * Return categorised listable special pages which are available
416 * for the current user, and everyone.
419 static function getUsablePages() {
421 if ( !self
::$mListInitialised ) {
426 foreach ( self
::$mList as $name => $rec ) {
427 $page = self
::getPage( $name );
428 if ( $page->isListed()
430 !$page->isRestricted()
431 ||
$page->userCanExecute( $wgUser )
434 $pages[$name] = $page;
441 * Return categorised listable special pages for all users
444 static function getRegularPages() {
445 if ( !self
::$mListInitialised ) {
450 foreach ( self
::$mList as $name => $rec ) {
451 $page = self
::getPage( $name );
452 if ( $page->isListed() && !$page->isRestricted() ) {
453 $pages[$name] = $page;
460 * Return categorised listable special pages which are available
461 * for the current user, but not for everyone
464 static function getRestrictedPages() {
466 if( !self
::$mListInitialised ) {
471 foreach( self
::$mList as $name => $rec ) {
472 $page = self
::getPage( $name );
475 && $page->isRestricted()
476 && $page->userCanExecute( $wgUser )
478 $pages[$name] = $page;
485 * Execute a special page path.
486 * The path may contain parameters, e.g. Special:Name/Params
487 * Extracts the special page name and call the execute method, passing the parameters
489 * Returns a title object if the page is redirected, false if there was no such special
490 * page, and true if it was successful.
492 * @param $title a title object
493 * @param $including output is being captured for use in {{special:whatever}}
495 static function executePath( &$title, $including = false ) {
496 global $wgOut, $wgTitle, $wgRequest;
497 wfProfileIn( __METHOD__
);
499 # FIXME: redirects broken due to this call
500 $bits = explode( '/', $title->getDBkey(), 2 );
502 if( !isset( $bits[1] ) ) { // bug 2087
507 $page = SpecialPage
::getPageByAlias( $name );
511 $wgOut->setArticleRelated( false );
512 $wgOut->setRobotPolicy( 'noindex,nofollow' );
513 $wgOut->setStatusCode( 404 );
514 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
516 wfProfileOut( __METHOD__
);
522 $redirect = $page->getRedirect( $par );
524 $query = $page->getRedirectQuery();
525 $url = $redirect->getFullUrl( $query );
526 $wgOut->redirect( $url );
527 wfProfileOut( __METHOD__
);
532 # Redirect to canonical alias for GET commands
533 # Not for POST, we'd lose the post data, so it's best to just distribute
534 # the request. Such POST requests are possible for old extensions that
535 # generate self-links without being aware that their default name has
537 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
539 unset( $query['title'] );
540 $query = wfArrayToCGI( $query );
541 $title = $page->getTitle( $par );
542 $url = $title->getFullUrl( $query );
543 $wgOut->redirect( $url );
544 wfProfileOut( __METHOD__
);
548 if ( $including && !$page->includable() ) {
549 wfProfileOut( __METHOD__
);
551 } elseif ( !$including ) {
552 $wgTitle = $page->getTitle();
554 $page->including( $including );
556 // Execute special page
557 $profName = 'Special:' . $page->getName();
558 wfProfileIn( $profName );
559 $page->execute( $par );
560 wfProfileOut( $profName );
561 wfProfileOut( __METHOD__
);
566 * Just like executePath() except it returns the HTML instead of outputting it
567 * Returns false if there was no such special page, or a title object if it was
571 static function capturePath( &$title ) {
572 global $wgOut, $wgTitle;
574 $oldTitle = $wgTitle;
576 $wgOut = new OutputPage
;
578 $ret = SpecialPage
::executePath( $title, true );
579 if ( $ret === true ) {
580 $ret = $wgOut->getHTML();
582 $wgTitle = $oldTitle;
588 * Get the local name for a specified canonical name
591 * @param mixed $subpage Boolean false, or string
595 static function getLocalNameFor( $name, $subpage = false ) {
597 $aliases = $wgContLang->getSpecialPageAliases();
598 if ( isset( $aliases[$name][0] ) ) {
599 $name = $aliases[$name][0];
601 if ( $subpage !== false && !is_null( $subpage ) ) {
602 $name = "$name/$subpage";
604 return ucfirst( $name );
608 * Get a localised Title object for a specified special page name
610 static function getTitleFor( $name, $subpage = false ) {
611 $name = self
::getLocalNameFor( $name, $subpage );
613 return Title
::makeTitle( NS_SPECIAL
, $name );
615 throw new MWException( "Invalid special page name \"$name\"" );
620 * Get a localised Title object for a page name with a possibly unvalidated subpage
622 static function getSafeTitleFor( $name, $subpage = false ) {
623 $name = self
::getLocalNameFor( $name, $subpage );
625 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
632 * Get a title for a given alias
633 * @return Title or null if there is no such alias
635 static function getTitleForAlias( $alias ) {
636 $name = self
::resolveAlias( $alias );
638 return self
::getTitleFor( $name );
645 * Default constructor for special pages
646 * Derivative classes should call this from their constructor
647 * Note that if the user does not have the required level, an error message will
648 * be displayed by the default execute() method, without the global function ever
651 * If you override execute(), you can recover the default behaviour with userCanExecute()
652 * and displayRestrictionError()
654 * @param string $name Name of the special page, as seen in links and URLs
655 * @param string $restriction User right required, e.g. "block" or "delete"
656 * @param boolean $listed Whether the page is listed in Special:Specialpages
657 * @param string $function Function called by execute(). By default it is constructed from $name
658 * @param string $file File which is included by execute(). It is also constructed from $name by default
660 function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
661 $this->mName
= $name;
662 $this->mRestriction
= $restriction;
663 $this->mListed
= $listed;
664 $this->mIncludable
= $includable;
665 if ( $function == false ) {
666 $this->mFunction
= 'wfSpecial'.$name;
668 $this->mFunction
= $function;
670 if ( $file === 'default' ) {
671 $this->mFile
= dirname(__FILE__
) . "/specials/Special$name.php";
673 $this->mFile
= $file;
682 function getName() { return $this->mName
; }
683 function getRestriction() { return $this->mRestriction
; }
684 function getFile() { return $this->mFile
; }
685 function isListed() { return $this->mListed
; }
689 * Accessor and mutator
691 function name( $x = NULL ) { return wfSetVar( $this->mName
, $x ); }
692 function restrictions( $x = NULL) { return wfSetVar( $this->mRestrictions
, $x ); }
693 function listed( $x = NULL) { return wfSetVar( $this->mListed
, $x ); }
694 function func( $x = NULL) { return wfSetVar( $this->mFunction
, $x ); }
695 function file( $x = NULL) { return wfSetVar( $this->mFile
, $x ); }
696 function includable( $x = NULL ) { return wfSetVar( $this->mIncludable
, $x ); }
697 function including( $x = NULL ) { return wfSetVar( $this->mIncluding
, $x ); }
701 * Get the localised name of the special page
703 function getLocalName() {
704 if ( !isset( $this->mLocalName
) ) {
705 $this->mLocalName
= self
::getLocalNameFor( $this->mName
);
707 return $this->mLocalName
;
711 * Can be overridden by subclasses with more complicated permissions
714 * @return bool Should the page be displayed with the restricted-access
717 public function isRestricted() {
718 global $wgGroupPermissions;
719 // DWIM: If all anons can do something, then it is not restricted
720 return $this->mRestriction
!= '' && empty($wgGroupPermissions['*'][$this->mRestriction
]);
724 * Checks if the given user (identified by an object) can execute this
725 * special page (as defined by $mRestriction). Can be overridden by sub-
726 * classes with more complicated permissions schemes.
728 * @param User $user The user to check
729 * @return bool Does the user have permission to view the page?
731 public function userCanExecute( $user ) {
732 return $user->isAllowed( $this->mRestriction
);
736 * Output an error message telling the user what access level they have to have
738 function displayRestrictionError() {
740 $wgOut->permissionRequired( $this->mRestriction
);
744 * Sets headers - this should be called from the execute() method of all derived classes!
746 function setHeaders() {
748 $wgOut->setArticleRelated( false );
749 $wgOut->setRobotPolicy( "noindex,nofollow" );
750 $wgOut->setPageTitle( $this->getDescription() );
754 * Default execute method
755 * Checks user permissions, calls the function given in mFunction
757 * This may be overridden by subclasses.
759 function execute( $par ) {
764 if ( $this->userCanExecute( $wgUser ) ) {
765 $func = $this->mFunction
;
766 // only load file if the function does not exist
767 if(!is_callable($func) and $this->mFile
) {
768 require_once( $this->mFile
);
770 $this->outputHeader();
771 call_user_func( $func, $par, $this );
773 $this->displayRestrictionError();
778 * Outputs a summary message on top of special pages
779 * Per default the message key is the canonical name of the special page
780 * May be overriden, i.e. by extensions to stick with the naming conventions
781 * for message keys: 'extensionname-xxx'
783 * @param string message key of the summary
785 function outputHeader( $summaryMessageKey = '' ) {
786 global $wgOut, $wgContLang;
788 if( $summaryMessageKey == '' ) {
789 $msg = $wgContLang->lc( $this->name() ) . '-summary';
791 $msg = $summaryMessageKey;
793 $out = wfMsgNoTrans( $msg );
794 if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() ) {
795 $wgOut->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1</div>", $msg );
800 # Returns the name that goes in the <h1> in the special page itself, and also the name that
801 # will be listed in Special:Specialpages
803 # Derived classes can override this, but usually it is easier to keep the default behaviour.
804 # Messages can be added at run-time, see MessageCache.php
805 function getDescription() {
806 return wfMsg( strtolower( $this->mName
) );
810 * Get a self-referential title object
812 function getTitle( $subpage = false) {
813 return self
::getTitleFor( $this->mName
, $subpage );
817 * Set whether this page is listed in Special:Specialpages, at run-time
819 function setListed( $listed ) {
820 return wfSetVar( $this->mListed
, $listed );
824 * If the special page is a redirect, then get the Title object it redirects to.
827 function getRedirect( $subpage ) {
832 * Return part of the request string for a special redirect page
833 * This allows passing, e.g. action=history to Special:Mypage, etc.
837 function getRedirectQuery() {
840 foreach( $this->mAllowedRedirectParams
as $arg ) {
841 if( $val = $wgRequest->getVal( $arg, false ) )
842 $params[] = $arg . '=' . $val;
845 return count( $params ) ?
implode( '&', $params ) : false;
850 * Shortcut to construct a special page which is unlisted by default
851 * @ingroup SpecialPage
853 class UnlistedSpecialPage
extends SpecialPage
855 function UnlistedSpecialPage( $name, $restriction = '', $function = false, $file = 'default' ) {
856 SpecialPage
::SpecialPage( $name, $restriction, false, $function, $file );
861 * Shortcut to construct an includable special page
862 * @ingroup SpecialPage
864 class IncludableSpecialPage
extends SpecialPage
866 function IncludableSpecialPage( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
867 SpecialPage
::SpecialPage( $name, $restriction, $listed, $function, $file, true );
872 * Shortcut to construct a special page alias.
873 * @ingroup SpecialPage
875 class SpecialRedirectToSpecial
extends UnlistedSpecialPage
{
876 var $redirName, $redirSubpage;
878 function __construct( $name, $redirName, $redirSubpage = false, $redirectParams = array() ) {
879 parent
::__construct( $name );
880 $this->redirName
= $redirName;
881 $this->redirSubpage
= $redirSubpage;
882 $this->mAllowedRedirectParams
= $redirectParams;
885 function getRedirect( $subpage ) {
886 if ( $this->redirSubpage
=== false ) {
887 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
889 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
894 /** SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
895 * are used to get user independant links pointing to the user page, talk
896 * page and list of contributions.
897 * This can let us cache a single copy of any generated content for all
902 * Shortcut to construct a special page pointing to current user user's page.
903 * @ingroup SpecialPage
905 class SpecialMypage
extends UnlistedSpecialPage
{
906 function __construct() {
907 parent
::__construct( 'Mypage' );
908 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro', 'section' );
911 function getRedirect( $subpage ) {
913 if ( strval( $subpage ) !== '' ) {
914 return Title
::makeTitle( NS_USER
, $wgUser->getName() . '/' . $subpage );
916 return Title
::makeTitle( NS_USER
, $wgUser->getName() );
922 * Shortcut to construct a special page pointing to current user talk page.
923 * @ingroup SpecialPage
925 class SpecialMytalk
extends UnlistedSpecialPage
{
926 function __construct() {
927 parent
::__construct( 'Mytalk' );
928 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro', 'section' );
931 function getRedirect( $subpage ) {
933 if ( strval( $subpage ) !== '' ) {
934 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() . '/' . $subpage );
936 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() );
942 * Shortcut to construct a special page pointing to current user contributions.
943 * @ingroup SpecialPage
945 class SpecialMycontributions
extends UnlistedSpecialPage
{
946 function __construct() {
947 parent
::__construct( 'Mycontributions' );
950 function getRedirect( $subpage ) {
952 return SpecialPage
::getTitleFor( 'Contributions', $wgUser->getName() );