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.
20 * @addtogroup SpecialPage
24 * Parent special page class, also static functions for handling the special
26 * @addtogroup SpecialPage
34 * The canonical name of this special page
35 * Also used for the default <h1> heading, @see getDescription()
39 * The local name of this special page
43 * Minimum user level required to access this page, or "" for anyone.
44 * Also used to categorise the pages in Special:Specialpages
48 * Listed in Special:Specialpages?
52 * Function name called by the default execute()
56 * File which needs to be included before the function above can be called
60 * Whether or not this special page is being included from an article
64 * Whether the special page can be included in an article
68 * Query parameters that can be passed through redirects
70 var $mAllowedRedirectParams = array();
72 * List of special pages, followed by parameters.
73 * If the only parameter is a string, that is the page name.
74 * Otherwise, it is an array. The format is one of:
75 ** array( 'SpecialPage', name, right )
76 ** array( 'IncludableSpecialPage', name, right, listed? )
77 ** array( 'UnlistedSpecialPage', name, right )
78 ** array( 'SpecialRedirectToSpecial', name, page to redirect to, special page param, ... )
80 static public $mList = array(
81 'DoubleRedirects' => array( 'SpecialPage', 'DoubleRedirects' ),
82 'BrokenRedirects' => array( 'SpecialPage', 'BrokenRedirects' ),
83 'Disambiguations' => array( 'SpecialPage', 'Disambiguations' ),
85 'Userlogin' => array( 'SpecialPage', 'Userlogin' ),
86 'Userlogout' => array( 'UnlistedSpecialPage', 'Userlogout' ),
87 'CreateAccount' => array( 'SpecialRedirectToSpecial', 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ),
88 'Preferences' => array( 'SpecialPage', 'Preferences' ),
89 'Watchlist' => array( 'SpecialPage', 'Watchlist' ),
91 'Recentchanges' => array( 'IncludableSpecialPage', 'Recentchanges' ),
92 'Upload' => array( 'SpecialPage', 'Upload' ),
93 'Imagelist' => array( 'SpecialPage', 'Imagelist' ),
94 'Newimages' => array( 'IncludableSpecialPage', 'Newimages' ),
95 'Listusers' => array( 'SpecialPage', 'Listusers' ),
96 'Listgrouprights' => 'SpecialListGroupRights',
97 'Statistics' => array( 'SpecialPage', 'Statistics' ),
98 'Randompage' => 'Randompage',
99 'Lonelypages' => array( 'SpecialPage', 'Lonelypages' ),
100 'Uncategorizedpages' => array( 'SpecialPage', 'Uncategorizedpages' ),
101 'Uncategorizedcategories' => array( 'SpecialPage', 'Uncategorizedcategories' ),
102 'Uncategorizedimages' => array( 'SpecialPage', 'Uncategorizedimages' ),
103 'Uncategorizedtemplates' => array( 'SpecialPage', 'Uncategorizedtemplates' ),
104 'Unusedcategories' => array( 'SpecialPage', 'Unusedcategories' ),
105 'Unusedimages' => array( 'SpecialPage', 'Unusedimages' ),
106 'Wantedpages' => array( 'IncludableSpecialPage', 'Wantedpages' ),
107 'Wantedcategories' => array( 'SpecialPage', 'Wantedcategories' ),
108 'Mostlinked' => array( 'SpecialPage', 'Mostlinked' ),
109 'Mostlinkedcategories' => array( 'SpecialPage', 'Mostlinkedcategories' ),
110 'Mostlinkedtemplates' => array( 'SpecialPage', 'Mostlinkedtemplates' ),
111 'Mostcategories' => array( 'SpecialPage', 'Mostcategories' ),
112 'Mostimages' => array( 'SpecialPage', 'Mostimages' ),
113 'Mostrevisions' => array( 'SpecialPage', 'Mostrevisions' ),
114 'Fewestrevisions' => array( 'SpecialPage', 'Fewestrevisions' ),
115 'Shortpages' => array( 'SpecialPage', 'Shortpages' ),
116 'Longpages' => array( 'SpecialPage', 'Longpages' ),
117 'Newpages' => array( 'IncludableSpecialPage', 'Newpages' ),
118 'Ancientpages' => array( 'SpecialPage', 'Ancientpages' ),
119 'Deadendpages' => array( 'SpecialPage', 'Deadendpages' ),
120 'Protectedpages' => array( 'SpecialPage', 'Protectedpages' ),
121 'Protectedtitles' => array( 'SpecialPage', 'Protectedtitles' ),
122 'Allpages' => array( 'IncludableSpecialPage', 'Allpages' ),
123 'Prefixindex' => array( 'IncludableSpecialPage', 'Prefixindex' ) ,
124 'Ipblocklist' => array( 'SpecialPage', 'Ipblocklist' ),
125 'Specialpages' => array( 'UnlistedSpecialPage', 'Specialpages' ),
126 'Contributions' => array( 'SpecialPage', 'Contributions' ),
127 'Emailuser' => array( 'UnlistedSpecialPage', 'Emailuser' ),
128 'Whatlinkshere' => array( 'SpecialPage', 'Whatlinkshere' ),
129 'Recentchangeslinked' => array( 'SpecialPage', 'Recentchangeslinked' ),
130 'Movepage' => array( 'UnlistedSpecialPage', 'Movepage' ),
131 'Blockme' => array( 'UnlistedSpecialPage', 'Blockme' ),
132 'Resetpass' => array( 'UnlistedSpecialPage', 'Resetpass' ),
133 'Booksources' => 'SpecialBookSources',
134 'Categories' => array( 'SpecialPage', 'Categories' ),
135 'Export' => array( 'SpecialPage', 'Export' ),
136 'Version' => array( 'SpecialPage', 'Version' ),
137 'Allmessages' => array( 'SpecialPage', 'Allmessages' ),
138 'Log' => array( 'SpecialPage', 'Log' ),
139 'Blockip' => array( 'SpecialPage', 'Blockip', 'block' ),
140 'Undelete' => array( 'SpecialPage', 'Undelete', 'deletedhistory' ),
141 'Import' => array( 'SpecialPage', 'Import', 'import' ),
142 'Lockdb' => array( 'SpecialPage', 'Lockdb', 'siteadmin' ),
143 'Unlockdb' => array( 'SpecialPage', 'Unlockdb', 'siteadmin' ),
144 'Userrights' => 'UserrightsPage',
145 'MIMEsearch' => array( 'SpecialPage', 'MIMEsearch' ),
146 'FileDuplicateSearch' => array( 'SpecialPage', 'FileDuplicateSearch' ),
147 'Unwatchedpages' => array( 'SpecialPage', 'Unwatchedpages', 'unwatchedpages' ),
148 'Listredirects' => array( 'SpecialPage', 'Listredirects' ),
149 'Revisiondelete' => array( 'UnlistedSpecialPage', 'Revisiondelete', 'deleterevision' ),
150 'Unusedtemplates' => array( 'SpecialPage', 'Unusedtemplates' ),
151 'Randomredirect' => 'SpecialRandomredirect',
152 'Withoutinterwiki' => array( 'SpecialPage', 'Withoutinterwiki' ),
153 'Filepath' => array( 'SpecialPage', 'Filepath' ),
155 'Mypage' => array( 'SpecialMypage' ),
156 'Mytalk' => array( 'SpecialMytalk' ),
157 'Mycontributions' => array( 'SpecialMycontributions' ),
158 'Listadmins' => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
159 'MergeHistory' => array( 'SpecialPage', 'MergeHistory', 'mergehistory' ),
160 'Listbots' => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ),
163 static public $mAliases;
164 static public $mListInitialised = false;
166 * List of special pages, followed by what subtitle they should go under
167 * at Special:SpecialPages
169 static public $mGroupsList = array(
170 'DoubleRedirects' => 'maintenance',
171 'BrokenRedirects' => 'maintenance',
172 'Lonelypages' => 'maintenance',
173 'Uncategorizedpages' => 'maintenance',
174 'Uncategorizedcategories' => 'maintenance',
175 'Uncategorizedimages' => 'maintenance',
176 'Uncategorizedtemplates' => 'maintenance',
177 'Unusedcategories' => 'maintenance',
178 'Unusedimages' => 'maintenance',
179 'Protectedpages' => 'maintenance',
180 'Protectedtitles' => 'maintenance',
181 'Unusedtemplates' => 'maintenance',
182 'Withoutinterwiki' => 'maintenance',
183 'Longpages' => 'maintenance',
185 'Userlogin' => 'login',
186 'Userlogout' => 'login',
187 'CreateAccount' => 'login',
189 'Recentchanges' => 'changes',
190 'Recentchangeslinked' => 'changes',
191 'Watchlist' => 'changes',
192 'Newimages' => 'changes',
193 'Newpages' => 'changes',
197 'Imagelist' => 'media',
198 'MIMEsearch' => 'media',
199 'FileDuplicateSearch' => 'media',
200 'Filepath' => 'media',
202 'Listusers' => 'users',
203 'Listgrouprights' => 'users',
204 'Ipblocklist' => 'users',
205 'Contributions' => 'users',
206 'Emailuser' => 'users',
207 'Listadmins' => 'users',
208 'Listbots' => 'users',
210 'Wantedpages' => 'needy',
211 'Wantedcategories' => 'needy',
212 'Shortpages' => 'needy',
213 'Ancientpages' => 'needy',
214 'Deadendpages' => 'needy',
216 'Mostlinked' => 'highuse',
217 'Mostlinkedcategories' => 'highuse',
218 'Mostlinkedtemplates' => 'highuse',
219 'Mostcategories' => 'highuse',
220 'Mostimages' => 'highuse',
221 'Mostrevisions' => 'highuse',
223 'Userrights' => 'permissions',
224 'Blockip' => 'permissions',
226 'Statistics' => 'other',
227 'Fewestrevisions' => 'other',
228 'Randompage' => 'other',
229 'Disambiguations' => 'other',
230 'Specialpages' => 'other',
231 'Blockme' => 'other',
232 'Movepage' => 'other',
233 'MergeHistory' => 'other',
235 'Unlockdb' => 'other',
236 'Version' => 'other',
237 'Whatlinkshere' => 'other',
238 'Booksources' => 'other',
239 'Revisiondelete' => 'other',
241 'Categories' => 'other',
242 'Undelete' => 'other',
244 'Unwatchedpages' => 'other',
245 'Randomredirect' => 'other',
246 'Allpages' => 'other',
247 'Allmessages' => 'other',
248 'Prefixindex' => 'other',
249 'Listredirects' => 'other',
250 'Preferences' => 'other',
251 'Resetpass' => 'other',
254 'Mycontributions' => 'other',
260 * Initialise the special page list
261 * This must be called before accessing SpecialPage::$mList
263 static function initList() {
264 global $wgSpecialPages;
265 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
267 if ( self
::$mListInitialised ) {
270 wfProfileIn( __METHOD__
);
272 # Better to set this now, to avoid infinite recursion in carelessly written hooks
273 self
::$mListInitialised = true;
275 if( !$wgDisableCounters ) {
276 self
::$mList['Popularpages'] = array( 'SpecialPage', 'Popularpages' );
279 if( !$wgDisableInternalSearch ) {
280 self
::$mList['Search'] = array( 'SpecialPage', 'Search' );
283 if( $wgEmailAuthentication ) {
284 self
::$mList['Confirmemail'] = 'EmailConfirmation';
285 self
::$mList['Invalidateemail'] = 'EmailInvalidation';
288 # Add extension special pages
289 self
::$mList = array_merge( self
::$mList, $wgSpecialPages );
292 # This hook can be used to remove undesired built-in special pages
293 wfRunHooks( 'SpecialPage_initList', array( &self
::$mList ) );
294 wfProfileOut( __METHOD__
);
297 static function initAliasList() {
298 if ( !is_null( self
::$mAliases ) ) {
303 $aliases = $wgContLang->getSpecialPageAliases();
304 $missingPages = self
::$mList;
305 self
::$mAliases = array();
306 foreach ( $aliases as $realName => $aliasList ) {
307 foreach ( $aliasList as $alias ) {
308 self
::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
310 unset( $missingPages[$realName] );
312 foreach ( $missingPages as $name => $stuff ) {
313 self
::$mAliases[$wgContLang->caseFold( $name )] = $name;
318 * Given a special page alias, return the special page name.
319 * Returns false if there is no such alias.
321 static function resolveAlias( $alias ) {
324 if ( !self
::$mListInitialised ) self
::initList();
325 if ( is_null( self
::$mAliases ) ) self
::initAliasList();
326 $caseFoldedAlias = $wgContLang->caseFold( $alias );
327 if ( isset( self
::$mAliases[$caseFoldedAlias] ) ) {
328 return self
::$mAliases[$caseFoldedAlias];
335 * Given a special page name with a possible subpage, return an array
336 * where the first element is the special page name and the second is the
339 static function resolveAliasWithSubpage( $alias ) {
340 $bits = explode( '/', $alias, 2 );
341 $name = self
::resolveAlias( $bits[0] );
342 if( !isset( $bits[1] ) ) { // bug 2087
347 return array( $name, $par );
351 * Add a page to the list of valid special pages. This used to be the preferred
352 * method for adding special pages in extensions. It's now suggested that you add
353 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
355 * @param mixed $page Must either be an array specifying a class name and
356 * constructor parameters, or an object. The object,
357 * when constructed, must have an execute() method which
358 * sends HTML to $wgOut.
361 static function addPage( &$page ) {
362 if ( !self
::$mListInitialised ) {
365 self
::$mList[$page->mName
] = $page;
369 * Add a page to a certain display group for Special:SpecialPages
371 * @param mixed $page Must either be an array specifying a class name and
372 * constructor parameters, or an object.
373 * @param string $group
376 static function setGroup( &$page, $group ) {
377 if ( !self
::$mListInitialised ) {
380 self
::$mGroupsList[$page->mName
] = $group;
384 * Add a page to a certain display group for Special:SpecialPages
386 * @param mixed $page Must either be an array specifying a class name and
387 * constructor parameters, or an object.
390 static function getGroup( &$page ) {
391 if ( !self
::$mListInitialised ) {
394 $group = isset(self
::$mGroupsList[$page->mName
]) ?
395 self
::$mGroupsList[$page->mName
] : 'other';
400 * Remove a special page from the list
401 * Formerly used to disable expensive or dangerous special pages. The
402 * preferred method is now to add a SpecialPage_initList hook.
406 static function removePage( $name ) {
407 if ( !self
::$mListInitialised ) {
410 unset( self
::$mList[$name] );
414 * Check if a given name exist as a special page or as a special page alias
415 * @param $name string: name of a special page
416 * @return boolean: true if a special page exists with this name
418 static function exists( $name ) {
420 if ( !self
::$mListInitialised ) {
423 if( !self
::$mAliases ) {
424 self
::initAliasList();
427 # Remove special pages inline parameters:
428 $bits = explode( '/', $name );
429 $name = $wgContLang->caseFold($bits[0]);
432 array_key_exists( $name, self
::$mList )
433 or array_key_exists( $name, self
::$mAliases )
438 * Find the object with a given name and return it (or NULL)
440 * @param string $name
442 static function getPage( $name ) {
443 if ( !self
::$mListInitialised ) {
446 if ( array_key_exists( $name, self
::$mList ) ) {
447 $rec = self
::$mList[$name];
448 if ( is_string( $rec ) ) {
450 self
::$mList[$name] = new $className;
451 } elseif ( is_array( $rec ) ) {
452 $className = array_shift( $rec );
453 self
::$mList[$name] = wfCreateObject( $className, $rec );
455 return self
::$mList[$name];
462 * Get a special page with a given localised name, or NULL if there
463 * is no such special page.
465 static function getPageByAlias( $alias ) {
466 $realName = self
::resolveAlias( $alias );
468 return self
::getPage( $realName );
475 * Return categorised listable special pages for all users
478 static function getRegularPages() {
479 if ( !self
::$mListInitialised ) {
484 foreach ( self
::$mList as $name => $rec ) {
485 $page = self
::getPage( $name );
486 if ( $page->isListed() && !$page->isRestricted() ) {
487 $pages[$name] = $page;
494 * Return categorised listable special pages which are available
495 * for the current user, but not for everyone
498 static function getRestrictedPages() {
500 if ( !self
::$mListInitialised ) {
505 foreach ( self
::$mList as $name => $rec ) {
506 $page = self
::getPage( $name );
509 and $page->isRestricted()
510 and $page->userCanExecute( $wgUser )
512 $pages[$name] = $page;
519 * Execute a special page path.
520 * The path may contain parameters, e.g. Special:Name/Params
521 * Extracts the special page name and call the execute method, passing the parameters
523 * Returns a title object if the page is redirected, false if there was no such special
524 * page, and true if it was successful.
526 * @param $title a title object
527 * @param $including output is being captured for use in {{special:whatever}}
529 static function executePath( &$title, $including = false ) {
530 global $wgOut, $wgTitle, $wgRequest;
531 wfProfileIn( __METHOD__
);
533 # FIXME: redirects broken due to this call
534 $bits = explode( '/', $title->getDBkey(), 2 );
536 if( !isset( $bits[1] ) ) { // bug 2087
541 $page = SpecialPage
::getPageByAlias( $name );
545 $wgOut->setArticleRelated( false );
546 $wgOut->setRobotpolicy( 'noindex,nofollow' );
547 $wgOut->setStatusCode( 404 );
548 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
550 wfProfileOut( __METHOD__
);
556 $redirect = $page->getRedirect( $par );
558 $query = $page->getRedirectQuery();
559 $url = $redirect->getFullUrl( $query );
560 $wgOut->redirect( $url );
561 wfProfileOut( __METHOD__
);
566 # Redirect to canonical alias for GET commands
567 # Not for POST, we'd lose the post data, so it's best to just distribute
568 # the request. Such POST requests are possible for old extensions that
569 # generate self-links without being aware that their default name has
571 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
573 unset( $query['title'] );
574 $query = wfArrayToCGI( $query );
575 $title = $page->getTitle( $par );
576 $url = $title->getFullUrl( $query );
577 $wgOut->redirect( $url );
578 wfProfileOut( __METHOD__
);
582 if ( $including && !$page->includable() ) {
583 wfProfileOut( __METHOD__
);
585 } elseif ( !$including ) {
586 $wgTitle = $page->getTitle();
588 $page->including( $including );
590 // Execute special page
591 $profName = 'Special:' . $page->getName();
592 wfProfileIn( $profName );
593 $page->execute( $par );
594 wfProfileOut( $profName );
595 wfProfileOut( __METHOD__
);
600 * Just like executePath() except it returns the HTML instead of outputting it
601 * Returns false if there was no such special page, or a title object if it was
605 static function capturePath( &$title ) {
606 global $wgOut, $wgTitle;
608 $oldTitle = $wgTitle;
610 $wgOut = new OutputPage
;
612 $ret = SpecialPage
::executePath( $title, true );
613 if ( $ret === true ) {
614 $ret = $wgOut->getHTML();
616 $wgTitle = $oldTitle;
622 * Get the local name for a specified canonical name
625 * @param mixed $subpage Boolean false, or string
629 static function getLocalNameFor( $name, $subpage = false ) {
631 $aliases = $wgContLang->getSpecialPageAliases();
632 if ( isset( $aliases[$name][0] ) ) {
633 $name = $aliases[$name][0];
635 if ( $subpage !== false && !is_null( $subpage ) ) {
636 $name = "$name/$subpage";
642 * Get a localised Title object for a specified special page name
644 static function getTitleFor( $name, $subpage = false ) {
645 $name = self
::getLocalNameFor( $name, $subpage );
647 return Title
::makeTitle( NS_SPECIAL
, $name );
649 throw new MWException( "Invalid special page name \"$name\"" );
654 * Get a localised Title object for a page name with a possibly unvalidated subpage
656 static function getSafeTitleFor( $name, $subpage = false ) {
657 $name = self
::getLocalNameFor( $name, $subpage );
659 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
666 * Get a title for a given alias
667 * @return Title or null if there is no such alias
669 static function getTitleForAlias( $alias ) {
670 $name = self
::resolveAlias( $alias );
672 return self
::getTitleFor( $name );
679 * Default constructor for special pages
680 * Derivative classes should call this from their constructor
681 * Note that if the user does not have the required level, an error message will
682 * be displayed by the default execute() method, without the global function ever
685 * If you override execute(), you can recover the default behaviour with userCanExecute()
686 * and displayRestrictionError()
688 * @param string $name Name of the special page, as seen in links and URLs
689 * @param string $restriction User right required, e.g. "block" or "delete"
690 * @param boolean $listed Whether the page is listed in Special:Specialpages
691 * @param string $function Function called by execute(). By default it is constructed from $name
692 * @param string $file File which is included by execute(). It is also constructed from $name by default
694 function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
695 $this->mName
= $name;
696 $this->mRestriction
= $restriction;
697 $this->mListed
= $listed;
698 $this->mIncludable
= $includable;
699 if ( $function == false ) {
700 $this->mFunction
= 'wfSpecial'.$name;
702 $this->mFunction
= $function;
704 if ( $file === 'default' ) {
705 $this->mFile
= dirname(__FILE__
) . "/Special{$name}.php";
707 $this->mFile
= $file;
716 function getName() { return $this->mName
; }
717 function getRestriction() { return $this->mRestriction
; }
718 function getFile() { return $this->mFile
; }
719 function isListed() { return $this->mListed
; }
723 * Accessor and mutator
725 function name( $x = NULL ) { return wfSetVar( $this->mName
, $x ); }
726 function restrictions( $x = NULL) { return wfSetVar( $this->mRestrictions
, $x ); }
727 function listed( $x = NULL) { return wfSetVar( $this->mListed
, $x ); }
728 function func( $x = NULL) { return wfSetVar( $this->mFunction
, $x ); }
729 function file( $x = NULL) { return wfSetVar( $this->mFile
, $x ); }
730 function includable( $x = NULL ) { return wfSetVar( $this->mIncludable
, $x ); }
731 function including( $x = NULL ) { return wfSetVar( $this->mIncluding
, $x ); }
735 * Get the localised name of the special page
737 function getLocalName() {
738 if ( !isset( $this->mLocalName
) ) {
739 $this->mLocalName
= self
::getLocalNameFor( $this->mName
);
741 return $this->mLocalName
;
745 * Can be overridden by subclasses with more complicated permissions
748 * @return bool Should the page be displayed with the restricted-access
751 public function isRestricted() {
752 return $this->mRestriction
!= '';
756 * Checks if the given user (identified by an object) can execute this
757 * special page (as defined by $mRestriction). Can be overridden by sub-
758 * classes with more complicated permissions schemes.
760 * @param User $user The user to check
761 * @return bool Does the user have permission to view the page?
763 public function userCanExecute( $user ) {
764 return $user->isAllowed( $this->mRestriction
);
768 * Output an error message telling the user what access level they have to have
770 function displayRestrictionError() {
772 $wgOut->permissionRequired( $this->mRestriction
);
776 * Sets headers - this should be called from the execute() method of all derived classes!
778 function setHeaders() {
780 $wgOut->setArticleRelated( false );
781 $wgOut->setRobotPolicy( "noindex,nofollow" );
782 $wgOut->setPageTitle( $this->getDescription() );
786 * Default execute method
787 * Checks user permissions, calls the function given in mFunction
789 * This may be overridden by subclasses.
791 function execute( $par ) {
796 if ( $this->userCanExecute( $wgUser ) ) {
797 $func = $this->mFunction
;
798 // only load file if the function does not exist
799 if(!is_callable($func) and $this->mFile
) {
800 require_once( $this->mFile
);
802 # FIXME: these hooks are broken for extensions and anything else that subclasses SpecialPage.
803 if ( wfRunHooks( 'SpecialPageExecuteBeforeHeader', array( &$this, &$par, &$func ) ) )
804 $this->outputHeader();
805 if ( ! wfRunHooks( 'SpecialPageExecuteBeforePage', array( &$this, &$par, &$func ) ) )
807 call_user_func( $func, $par, $this );
808 if ( ! wfRunHooks( 'SpecialPageExecuteAfterPage', array( &$this, &$par, &$func ) ) )
811 $this->displayRestrictionError();
815 function outputHeader() {
816 global $wgOut, $wgContLang;
818 $msg = $wgContLang->lc( $this->name() ) . '-summary';
819 $out = wfMsgNoTrans( $msg );
820 if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() ) {
821 $wgOut->addWikiText( $out );
826 # Returns the name that goes in the <h1> in the special page itself, and also the name that
827 # will be listed in Special:Specialpages
829 # Derived classes can override this, but usually it is easier to keep the default behaviour.
830 # Messages can be added at run-time, see MessageCache.php
831 function getDescription() {
832 return wfMsg( strtolower( $this->mName
) );
836 * Get a self-referential title object
838 function getTitle( $subpage = false) {
839 return self
::getTitleFor( $this->mName
, $subpage );
843 * Set whether this page is listed in Special:Specialpages, at run-time
845 function setListed( $listed ) {
846 return wfSetVar( $this->mListed
, $listed );
850 * If the special page is a redirect, then get the Title object it redirects to.
853 function getRedirect( $subpage ) {
858 * Return part of the request string for a special redirect page
859 * This allows passing, e.g. action=history to Special:Mypage, etc.
863 function getRedirectQuery() {
866 foreach( $this->mAllowedRedirectParams
as $arg ) {
867 if( $val = $wgRequest->getVal( $arg, false ) )
868 $params[] = $arg . '=' . $val;
871 return count( $params ) ?
implode( '&', $params ) : false;
876 * Shortcut to construct a special page which is unlisted by default
877 * @addtogroup SpecialPage
879 class UnlistedSpecialPage
extends SpecialPage
881 function UnlistedSpecialPage( $name, $restriction = '', $function = false, $file = 'default' ) {
882 SpecialPage
::SpecialPage( $name, $restriction, false, $function, $file );
887 * Shortcut to construct an includable special page
888 * @addtogroup SpecialPage
890 class IncludableSpecialPage
extends SpecialPage
892 function IncludableSpecialPage( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
893 SpecialPage
::SpecialPage( $name, $restriction, $listed, $function, $file, true );
898 * Shortcut to construct a special page alias.
899 * @addtogroup SpecialPage
901 class SpecialRedirectToSpecial
extends UnlistedSpecialPage
{
902 var $redirName, $redirSubpage;
904 function __construct( $name, $redirName, $redirSubpage = false, $redirectParams = array() ) {
905 parent
::__construct( $name );
906 $this->redirName
= $redirName;
907 $this->redirSubpage
= $redirSubpage;
908 $this->mAllowedRedirectParams
= $redirectParams;
911 function getRedirect( $subpage ) {
912 if ( $this->redirSubpage
=== false ) {
913 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
915 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
920 /** SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
921 * are used to get user independant links pointing to the user page, talk
922 * page and list of contributions.
923 * This can let us cache a single copy of any generated content for all
928 * Shortcut to construct a special page pointing to current user user's page.
929 * @addtogroup SpecialPage
931 class SpecialMypage
extends UnlistedSpecialPage
{
932 function __construct() {
933 parent
::__construct( 'Mypage' );
934 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro', 'section' );
937 function getRedirect( $subpage ) {
939 if ( strval( $subpage ) !== '' ) {
940 return Title
::makeTitle( NS_USER
, $wgUser->getName() . '/' . $subpage );
942 return Title
::makeTitle( NS_USER
, $wgUser->getName() );
948 * Shortcut to construct a special page pointing to current user talk page.
949 * @addtogroup SpecialPage
951 class SpecialMytalk
extends UnlistedSpecialPage
{
952 function __construct() {
953 parent
::__construct( 'Mytalk' );
954 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro', 'section' );
957 function getRedirect( $subpage ) {
959 if ( strval( $subpage ) !== '' ) {
960 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() . '/' . $subpage );
962 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() );
968 * Shortcut to construct a special page pointing to current user contributions.
969 * @addtogroup SpecialPage
971 class SpecialMycontributions
extends UnlistedSpecialPage
{
972 function __construct() {
973 parent
::__construct( 'Mycontributions' );
976 function getRedirect( $subpage ) {
978 return SpecialPage
::getTitleFor( 'Contributions', $wgUser->getName() );