Fixed some doxygen warnings
[mediawiki.git] / includes / SpecialPage.php
blobc452b17eec6c476a00883a38fd64afcdcc56d239
1 <?php
2 /**
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 * @file
21 * @ingroup SpecialPage
22 * @defgroup SpecialPage SpecialPage
25 /**
26 * Parent special page class, also static functions for handling the special
27 * page list.
28 * @ingroup SpecialPage
30 class SpecialPage {
31 /**#@+
32 * @access private
34 /**
35 * The canonical name of this special page
36 * Also used for the default <h1> heading, @see getDescription()
38 var $mName;
39 /**
40 * The local name of this special page
42 var $mLocalName;
43 /**
44 * Minimum user level required to access this page, or "" for anyone.
45 * Also used to categorise the pages in Special:Specialpages
47 var $mRestriction;
48 /**
49 * Listed in Special:Specialpages?
51 var $mListed;
52 /**
53 * Function name called by the default execute()
55 var $mFunction;
56 /**
57 * File which needs to be included before the function above can be called
59 var $mFile;
60 /**
61 * Whether or not this special page is being included from an article
63 var $mIncluding;
64 /**
65 * Whether the special page can be included in an article
67 var $mIncludable;
68 /**
69 * Query parameters that can be passed through redirects
71 var $mAllowedRedirectParams = array();
72 /**
73 * Query parameteres added by redirects
75 var $mAddedRedirectParams = array();
76 /**
77 * List of special pages, followed by parameters.
78 * If the only parameter is a string, that is the page name.
79 * Otherwise, it is an array. The format is one of:
80 ** array( 'SpecialPage', name, right )
81 ** array( 'IncludableSpecialPage', name, right, listed? )
82 ** array( 'UnlistedSpecialPage', name, right )
83 ** array( 'SpecialRedirectToSpecial', name, page to redirect to, special page param, ... )
85 static public $mList = array(
86 # Maintenance Reports
87 'BrokenRedirects' => array( 'SpecialPage', 'BrokenRedirects' ),
88 'Deadendpages' => array( 'SpecialPage', 'Deadendpages' ),
89 'DoubleRedirects' => array( 'SpecialPage', 'DoubleRedirects' ),
90 'Longpages' => array( 'SpecialPage', 'Longpages' ),
91 'Ancientpages' => array( 'SpecialPage', 'Ancientpages' ),
92 'Lonelypages' => array( 'SpecialPage', 'Lonelypages' ),
93 'Fewestrevisions' => array( 'SpecialPage', 'Fewestrevisions' ),
94 'Withoutinterwiki' => array( 'SpecialPage', 'Withoutinterwiki' ),
95 'Protectedpages' => array( 'SpecialPage', 'Protectedpages' ),
96 'Protectedtitles' => array( 'SpecialPage', 'Protectedtitles' ),
97 'Shortpages' => array( 'SpecialPage', 'Shortpages' ),
98 'Uncategorizedcategories' => array( 'SpecialPage', 'Uncategorizedcategories' ),
99 'Uncategorizedimages' => array( 'SpecialPage', 'Uncategorizedimages' ),
100 'Uncategorizedpages' => array( 'SpecialPage', 'Uncategorizedpages' ),
101 'Uncategorizedtemplates' => array( 'SpecialPage', 'Uncategorizedtemplates' ),
102 'Unusedcategories' => array( 'SpecialPage', 'Unusedcategories' ),
103 'Unusedimages' => array( 'SpecialPage', 'Unusedimages' ),
104 'Unusedtemplates' => array( 'SpecialPage', 'Unusedtemplates' ),
105 'Unwatchedpages' => array( 'SpecialPage', 'Unwatchedpages', 'unwatchedpages' ),
106 'Wantedcategories' => array( 'SpecialPage', 'Wantedcategories' ),
107 'Wantedfiles' => array( 'SpecialPage', 'Wantedfiles' ),
108 'Wantedpages' => array( 'IncludableSpecialPage', 'Wantedpages' ),
109 'Wantedtemplates' => array( 'SpecialPage', 'Wantedtemplates' ),
111 # List of pages
112 'Allpages' => 'SpecialAllpages',
113 'Prefixindex' => 'SpecialPrefixindex',
114 'Categories' => array( 'SpecialPage', 'Categories' ),
115 'Disambiguations' => array( 'SpecialPage', 'Disambiguations' ),
116 'Listredirects' => array( 'SpecialPage', 'Listredirects' ),
118 # Login/create account
119 'Userlogin' => array( 'SpecialPage', 'Userlogin' ),
120 'CreateAccount' => array( 'SpecialRedirectToSpecial', 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ),
122 # Users and rights
123 'Blockip' => array( 'SpecialPage', 'Blockip', 'block' ),
124 'Ipblocklist' => array( 'SpecialPage', 'Ipblocklist' ),
125 'Unblock' => array( 'SpecialRedirectToSpecial', 'Unblock', 'Ipblocklist', false, array( 'uselang', 'ip', 'id' ), array( 'action' => 'unblock' ) ),
126 'Resetpass' => 'SpecialResetpass',
127 'DeletedContributions' => 'DeletedContributionsPage',
128 'Preferences' => 'SpecialPreferences',
129 'Contributions' => 'SpecialContributions',
130 'Listgrouprights' => 'SpecialListGroupRights',
131 'Listusers' => array( 'SpecialPage', 'Listusers' ),
132 'Activeusers' => 'SpecialActiveUsers',
133 'Userrights' => 'UserrightsPage',
135 # Recent changes and logs
136 'Newimages' => array( 'IncludableSpecialPage', 'Newimages' ),
137 'Log' => array( 'SpecialPage', 'Log' ),
138 'Watchlist' => array( 'SpecialPage', 'Watchlist' ),
139 'Newpages' => 'SpecialNewpages',
140 'Recentchanges' => 'SpecialRecentchanges',
141 'Recentchangeslinked' => 'SpecialRecentchangeslinked',
142 'Tags' => 'SpecialTags',
144 # Media reports and uploads
145 'Listfiles' => array( 'SpecialPage', 'Listfiles' ),
146 'Filepath' => array( 'SpecialPage', 'Filepath' ),
147 'MIMEsearch' => array( 'SpecialPage', 'MIMEsearch' ),
148 'FileDuplicateSearch' => array( 'SpecialPage', 'FileDuplicateSearch' ),
149 'Upload' => 'SpecialUpload',
151 # Wiki data and tools
152 'Statistics' => 'SpecialStatistics',
153 'Allmessages' => 'SpecialAllmessages',
154 'Version' => 'SpecialVersion',
155 'Lockdb' => array( 'SpecialPage', 'Lockdb', 'siteadmin' ),
156 'Unlockdb' => array( 'SpecialPage', 'Unlockdb', 'siteadmin' ),
158 # Redirecting special pages
159 'LinkSearch' => array( 'SpecialPage', 'LinkSearch' ),
160 'Randompage' => 'Randompage',
161 'Randomredirect' => 'SpecialRandomredirect',
163 # High use pages
164 'Mostlinkedcategories' => array( 'SpecialPage', 'Mostlinkedcategories' ),
165 'Mostimages' => array( 'SpecialPage', 'Mostimages' ),
166 'Mostlinked' => array( 'SpecialPage', 'Mostlinked' ),
167 'Mostlinkedtemplates' => array( 'SpecialPage', 'Mostlinkedtemplates' ),
168 'Mostcategories' => array( 'SpecialPage', 'Mostcategories' ),
169 'Mostrevisions' => array( 'SpecialPage', 'Mostrevisions' ),
171 # Page tools
172 'Export' => 'SpecialExport',
173 'Import' => 'SpecialImport',
174 'Undelete' => array( 'SpecialPage', 'Undelete', 'deletedhistory' ),
175 'Whatlinkshere' => 'SpecialWhatlinkshere',
176 'MergeHistory' => 'SpecialMergeHistory',
178 # Other
179 'Booksources' => 'SpecialBookSources',
181 # Unlisted / redirects
182 'Blankpage' => 'SpecialBlankpage',
183 'Blockme' => array( 'UnlistedSpecialPage', 'Blockme' ),
184 'Emailuser' => 'SpecialEmailUser',
185 'Listadmins' => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
186 'Listbots' => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ),
187 'Movepage' => array( 'UnlistedSpecialPage', 'Movepage' ),
188 'Mycontributions' => array( 'SpecialMycontributions' ),
189 'Mypage' => array( 'SpecialMypage' ),
190 'Mytalk' => array( 'SpecialMytalk' ),
191 'Revisiondelete' => 'SpecialRevisionDelete',
192 'RevisionMove' => 'SpecialRevisionMove',
193 'Specialpages' => array( 'UnlistedSpecialPage', 'Specialpages' ),
194 'Userlogout' => array( 'UnlistedSpecialPage', 'Userlogout' ),
197 static public $mAliases;
198 static public $mListInitialised = false;
200 /**#@-*/
203 * Initialise the special page list
204 * This must be called before accessing SpecialPage::$mList
206 static function initList() {
207 global $wgSpecialPages;
208 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
210 if ( self::$mListInitialised ) {
211 return;
213 wfProfileIn( __METHOD__ );
215 # Better to set this now, to avoid infinite recursion in carelessly written hooks
216 self::$mListInitialised = true;
218 if( !$wgDisableCounters ) {
219 self::$mList['Popularpages'] = array( 'SpecialPage', 'Popularpages' );
222 if( !$wgDisableInternalSearch ) {
223 self::$mList['Search'] = array( 'SpecialPage', 'Search' );
226 if( $wgEmailAuthentication ) {
227 self::$mList['Confirmemail'] = 'EmailConfirmation';
228 self::$mList['Invalidateemail'] = 'EmailInvalidation';
231 # Add extension special pages
232 self::$mList = array_merge( self::$mList, $wgSpecialPages );
234 # Run hooks
235 # This hook can be used to remove undesired built-in special pages
236 wfRunHooks( 'SpecialPage_initList', array( &self::$mList ) );
237 wfProfileOut( __METHOD__ );
240 static function initAliasList() {
241 if ( !is_null( self::$mAliases ) ) {
242 return;
245 global $wgContLang;
246 $aliases = $wgContLang->getSpecialPageAliases();
247 $missingPages = self::$mList;
248 self::$mAliases = array();
249 foreach ( $aliases as $realName => $aliasList ) {
250 foreach ( $aliasList as $alias ) {
251 self::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
253 unset( $missingPages[$realName] );
255 foreach ( $missingPages as $name => $stuff ) {
256 self::$mAliases[$wgContLang->caseFold( $name )] = $name;
261 * Given a special page alias, return the special page name.
262 * Returns false if there is no such alias.
264 * @param $alias String
265 * @return String or false
267 static function resolveAlias( $alias ) {
268 global $wgContLang;
270 if ( !self::$mListInitialised ) self::initList();
271 if ( is_null( self::$mAliases ) ) self::initAliasList();
272 $caseFoldedAlias = $wgContLang->caseFold( $alias );
273 if ( isset( self::$mAliases[$caseFoldedAlias] ) ) {
274 return self::$mAliases[$caseFoldedAlias];
275 } else {
276 return false;
281 * Given a special page name with a possible subpage, return an array
282 * where the first element is the special page name and the second is the
283 * subpage.
285 * @param $alias String
286 * @return Array
288 static function resolveAliasWithSubpage( $alias ) {
289 $bits = explode( '/', $alias, 2 );
290 $name = self::resolveAlias( $bits[0] );
291 if( !isset( $bits[1] ) ) { // bug 2087
292 $par = null;
293 } else {
294 $par = $bits[1];
296 return array( $name, $par );
300 * Add a page to the list of valid special pages. This used to be the preferred
301 * method for adding special pages in extensions. It's now suggested that you add
302 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
304 * @param $page SpecialPage
306 static function addPage( &$page ) {
307 if ( !self::$mListInitialised ) {
308 self::initList();
310 self::$mList[$page->mName] = $page;
314 * Add a page to a certain display group for Special:SpecialPages
316 * @param $page Mixed: SpecialPage or string
317 * @param $group String
319 static function setGroup( $page, $group ) {
320 global $wgSpecialPageGroups;
321 $name = is_object($page) ? $page->mName : $page;
322 $wgSpecialPageGroups[$name] = $group;
326 * Add a page to a certain display group for Special:SpecialPages
328 * @param $page SpecialPage
330 static function getGroup( &$page ) {
331 global $wgSpecialPageGroups;
332 static $specialPageGroupsCache = array();
333 if( isset($specialPageGroupsCache[$page->mName]) ) {
334 return $specialPageGroupsCache[$page->mName];
336 $group = wfMsg('specialpages-specialpagegroup-'.strtolower($page->mName));
337 if( $group == ''
338 || wfEmptyMsg('specialpages-specialpagegroup-'.strtolower($page->mName), $group ) ) {
339 $group = isset($wgSpecialPageGroups[$page->mName])
340 ? $wgSpecialPageGroups[$page->mName]
341 : '-';
343 if( $group == '-' ) $group = 'other';
344 $specialPageGroupsCache[$page->mName] = $group;
345 return $group;
349 * Remove a special page from the list
350 * Formerly used to disable expensive or dangerous special pages. The
351 * preferred method is now to add a SpecialPage_initList hook.
353 static function removePage( $name ) {
354 if ( !self::$mListInitialised ) {
355 self::initList();
357 unset( self::$mList[$name] );
361 * Check if a given name exist as a special page or as a special page alias
363 * @param $name String: name of a special page
364 * @return Boolean: true if a special page exists with this name
366 static function exists( $name ) {
367 global $wgContLang;
368 if ( !self::$mListInitialised ) {
369 self::initList();
371 if( !self::$mAliases ) {
372 self::initAliasList();
375 # Remove special pages inline parameters:
376 $bits = explode( '/', $name );
377 $name = $wgContLang->caseFold($bits[0]);
379 return
380 array_key_exists( $name, self::$mList )
381 or array_key_exists( $name, self::$mAliases )
386 * Find the object with a given name and return it (or NULL)
388 * @param $name String
389 * @return SpecialPage object or null if the page doesn't exist
391 static function getPage( $name ) {
392 if ( !self::$mListInitialised ) {
393 self::initList();
395 if ( array_key_exists( $name, self::$mList ) ) {
396 $rec = self::$mList[$name];
397 if ( is_string( $rec ) ) {
398 $className = $rec;
399 self::$mList[$name] = new $className;
400 } elseif ( is_array( $rec ) ) {
401 $className = array_shift( $rec );
402 self::$mList[$name] = wfCreateObject( $className, $rec );
404 return self::$mList[$name];
405 } else {
406 return null;
411 * Get a special page with a given localised name, or NULL if there
412 * is no such special page.
414 * @return SpecialPage object or null if the page doesn't exist
416 static function getPageByAlias( $alias ) {
417 $realName = self::resolveAlias( $alias );
418 if ( $realName ) {
419 return self::getPage( $realName );
420 } else {
421 return null;
426 * Return categorised listable special pages which are available
427 * for the current user, and everyone.
429 * @return Associative array mapping page's name to its SpecialPage object
431 static function getUsablePages() {
432 global $wgUser;
433 if ( !self::$mListInitialised ) {
434 self::initList();
436 $pages = array();
438 foreach ( self::$mList as $name => $rec ) {
439 $page = self::getPage( $name );
440 if ( $page->isListed()
441 && (
442 !$page->isRestricted()
443 || $page->userCanExecute( $wgUser )
446 $pages[$name] = $page;
449 return $pages;
453 * Return categorised listable special pages for all users
455 * @return Associative array mapping page's name to its SpecialPage object
457 static function getRegularPages() {
458 if ( !self::$mListInitialised ) {
459 self::initList();
461 $pages = array();
463 foreach ( self::$mList as $name => $rec ) {
464 $page = self::getPage( $name );
465 if ( $page->isListed() && !$page->isRestricted() ) {
466 $pages[$name] = $page;
469 return $pages;
473 * Return categorised listable special pages which are available
474 * for the current user, but not for everyone
476 * @return Associative array mapping page's name to its SpecialPage object
478 static function getRestrictedPages() {
479 global $wgUser;
480 if( !self::$mListInitialised ) {
481 self::initList();
483 $pages = array();
485 foreach( self::$mList as $name => $rec ) {
486 $page = self::getPage( $name );
488 $page->isListed()
489 && $page->isRestricted()
490 && $page->userCanExecute( $wgUser )
492 $pages[$name] = $page;
495 return $pages;
499 * Execute a special page path.
500 * The path may contain parameters, e.g. Special:Name/Params
501 * Extracts the special page name and call the execute method, passing the parameters
503 * Returns a title object if the page is redirected, false if there was no such special
504 * page, and true if it was successful.
506 * @param $title a title object
507 * @param $including output is being captured for use in {{special:whatever}}
509 static function executePath( &$title, $including = false ) {
510 global $wgOut, $wgTitle, $wgRequest;
511 wfProfileIn( __METHOD__ );
513 # FIXME: redirects broken due to this call
514 $bits = explode( '/', $title->getDBkey(), 2 );
515 $name = $bits[0];
516 if( !isset( $bits[1] ) ) { // bug 2087
517 $par = null;
518 } else {
519 $par = $bits[1];
521 $page = SpecialPage::getPageByAlias( $name );
522 # Nonexistent?
523 if ( !$page ) {
524 if ( !$including ) {
525 $wgOut->setArticleRelated( false );
526 $wgOut->setRobotPolicy( 'noindex,nofollow' );
527 $wgOut->setStatusCode( 404 );
528 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
530 wfProfileOut( __METHOD__ );
531 return false;
534 # Check for redirect
535 if ( !$including ) {
536 $redirect = $page->getRedirect( $par );
537 if ( $redirect ) {
538 $query = $page->getRedirectQuery();
539 $url = $redirect->getFullUrl( $query );
540 $wgOut->redirect( $url );
541 wfProfileOut( __METHOD__ );
542 return $redirect;
546 # Redirect to canonical alias for GET commands
547 # Not for POST, we'd lose the post data, so it's best to just distribute
548 # the request. Such POST requests are possible for old extensions that
549 # generate self-links without being aware that their default name has
550 # changed.
551 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
552 $query = $_GET;
553 unset( $query['title'] );
554 $query = wfArrayToCGI( $query );
555 $title = $page->getTitle( $par );
556 $url = $title->getFullUrl( $query );
557 $wgOut->redirect( $url );
558 wfProfileOut( __METHOD__ );
559 return $redirect;
562 if ( $including && !$page->includable() ) {
563 wfProfileOut( __METHOD__ );
564 return false;
565 } elseif ( !$including ) {
566 $wgTitle = $page->getTitle();
568 $page->including( $including );
570 // Execute special page
571 $profName = 'Special:' . $page->getName();
572 wfProfileIn( $profName );
573 $page->execute( $par );
574 wfProfileOut( $profName );
575 wfProfileOut( __METHOD__ );
576 return true;
580 * Just like executePath() except it returns the HTML instead of outputting it
581 * Returns false if there was no such special page, or a title object if it was
582 * a redirect.
584 * @return String: HTML fragment
586 static function capturePath( &$title ) {
587 global $wgOut, $wgTitle;
589 $oldTitle = $wgTitle;
590 $oldOut = $wgOut;
591 $wgOut = new OutputPage;
592 $wgOut->setTitle( $title );
594 $ret = SpecialPage::executePath( $title, true );
595 if ( $ret === true ) {
596 $ret = $wgOut->getHTML();
598 $wgTitle = $oldTitle;
599 $wgOut = $oldOut;
600 return $ret;
604 * Get the local name for a specified canonical name
606 * @param $name String
607 * @param $subpage Mixed: boolean false, or string
609 * @return String
611 static function getLocalNameFor( $name, $subpage = false ) {
612 global $wgContLang;
613 $aliases = $wgContLang->getSpecialPageAliases();
614 if ( isset( $aliases[$name][0] ) ) {
615 $name = $aliases[$name][0];
616 } else {
617 // Try harder in case someone misspelled the correct casing
618 $found = false;
619 foreach ( $aliases as $n => $values ) {
620 if ( strcasecmp( $name, $n ) === 0 ) {
621 wfWarn( "Found alias defined for $n when searching for special page aliases
622 for $name. Case mismatch?" );
623 $name = $values[0];
624 $found = true;
625 break;
628 if ( !$found ) wfWarn( "Did not find alias for special page '$name'.
629 Perhaps no page aliases are defined for it?" );
631 if ( $subpage !== false && !is_null( $subpage ) ) {
632 $name = "$name/$subpage";
634 return $wgContLang->ucfirst( $name );
638 * Get a localised Title object for a specified special page name
640 * @return Title object
642 static function getTitleFor( $name, $subpage = false ) {
643 $name = self::getLocalNameFor( $name, $subpage );
644 if ( $name ) {
645 return Title::makeTitle( NS_SPECIAL, $name );
646 } else {
647 throw new MWException( "Invalid special page name \"$name\"" );
652 * Get a localised Title object for a page name with a possibly unvalidated subpage
654 * @return Title object or null if the page doesn't exist
656 static function getSafeTitleFor( $name, $subpage = false ) {
657 $name = self::getLocalNameFor( $name, $subpage );
658 if ( $name ) {
659 return Title::makeTitleSafe( NS_SPECIAL, $name );
660 } else {
661 return null;
666 * Get a title for a given alias
668 * @return Title or null if there is no such alias
670 static function getTitleForAlias( $alias ) {
671 $name = self::resolveAlias( $alias );
672 if ( $name ) {
673 return self::getTitleFor( $name );
674 } else {
675 return null;
680 * Default constructor for special pages
681 * Derivative classes should call this from their constructor
682 * Note that if the user does not have the required level, an error message will
683 * be displayed by the default execute() method, without the global function ever
684 * being called.
686 * If you override execute(), you can recover the default behaviour with userCanExecute()
687 * and displayRestrictionError()
689 * @param $name String: name of the special page, as seen in links and URLs
690 * @param $restriction String: user right required, e.g. "block" or "delete"
691 * @param $listed Boolean: whether the page is listed in Special:Specialpages
692 * @param $function Callback: function called by execute(). By default it is constructed from $name
693 * @param $file String: file which is included by execute(). It is also constructed from $name by default
694 * @param $includable Boolean: whether the page can be included in normal pages
696 function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
697 $this->mName = $name;
698 $this->mRestriction = $restriction;
699 $this->mListed = $listed;
700 $this->mIncludable = $includable;
701 if ( !$function ) {
702 $this->mFunction = 'wfSpecial'.$name;
703 } else {
704 $this->mFunction = $function;
706 if ( $file === 'default' ) {
707 $this->mFile = dirname(__FILE__) . "/specials/Special$name.php";
708 } else {
709 $this->mFile = $file;
713 /**#@+
714 * Accessor
716 * @deprecated
718 function getName() { return $this->mName; }
719 function getRestriction() { return $this->mRestriction; }
720 function getFile() { return $this->mFile; }
721 function isListed() { return $this->mListed; }
722 /**#@-*/
724 /**#@+
725 * Accessor and mutator
727 function name( $x = null ) { return wfSetVar( $this->mName, $x ); }
728 function restrictions( $x = null) {
729 # Use the one below this
730 wfDeprecated( __METHOD__ );
731 return wfSetVar( $this->mRestriction, $x );
733 function restriction( $x = null) { return wfSetVar( $this->mRestriction, $x ); }
734 function listed( $x = null) { return wfSetVar( $this->mListed, $x ); }
735 function func( $x = null) { return wfSetVar( $this->mFunction, $x ); }
736 function file( $x = null) { return wfSetVar( $this->mFile, $x ); }
737 function includable( $x = null ) { return wfSetVar( $this->mIncludable, $x ); }
738 function including( $x = null ) { return wfSetVar( $this->mIncluding, $x ); }
739 /**#@-*/
742 * Get the localised name of the special page
744 function getLocalName() {
745 if ( !isset( $this->mLocalName ) ) {
746 $this->mLocalName = self::getLocalNameFor( $this->mName );
748 return $this->mLocalName;
752 * Can be overridden by subclasses with more complicated permissions
753 * schemes.
755 * @return Boolean: should the page be displayed with the restricted-access
756 * pages?
758 public function isRestricted() {
759 global $wgGroupPermissions;
760 // DWIM: If all anons can do something, then it is not restricted
761 return $this->mRestriction != '' && empty($wgGroupPermissions['*'][$this->mRestriction]);
765 * Checks if the given user (identified by an object) can execute this
766 * special page (as defined by $mRestriction). Can be overridden by sub-
767 * classes with more complicated permissions schemes.
769 * @param $user User: the user to check
770 * @return Boolean: does the user have permission to view the page?
772 public function userCanExecute( $user ) {
773 return $user->isAllowed( $this->mRestriction );
777 * Output an error message telling the user what access level they have to have
779 function displayRestrictionError() {
780 global $wgOut;
781 $wgOut->permissionRequired( $this->mRestriction );
785 * Sets headers - this should be called from the execute() method of all derived classes!
787 function setHeaders() {
788 global $wgOut;
789 $wgOut->setArticleRelated( false );
790 $wgOut->setRobotPolicy( "noindex,nofollow" );
791 $wgOut->setPageTitle( $this->getDescription() );
795 * Default execute method
796 * Checks user permissions, calls the function given in mFunction
798 * This may be overridden by subclasses.
800 function execute( $par ) {
801 global $wgUser;
803 $this->setHeaders();
805 if ( $this->userCanExecute( $wgUser ) ) {
806 $func = $this->mFunction;
807 // only load file if the function does not exist
808 if(!is_callable($func) and $this->mFile) {
809 require_once( $this->mFile );
811 $this->outputHeader();
812 call_user_func( $func, $par, $this );
813 } else {
814 $this->displayRestrictionError();
819 * Outputs a summary message on top of special pages
820 * Per default the message key is the canonical name of the special page
821 * May be overriden, i.e. by extensions to stick with the naming conventions
822 * for message keys: 'extensionname-xxx'
824 * @param $summaryMessageKey String: message key of the summary
826 function outputHeader( $summaryMessageKey = '' ) {
827 global $wgOut, $wgContLang;
829 if( $summaryMessageKey == '' ) {
830 $msg = $wgContLang->lc( $this->name() ) . '-summary';
831 } else {
832 $msg = $summaryMessageKey;
834 $out = wfMsgNoTrans( $msg );
835 if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() ) {
836 $wgOut->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
842 * Returns the name that goes in the \<h1\> in the special page itself, and
843 * also the name that will be listed in Special:Specialpages
845 * Derived classes can override this, but usually it is easier to keep the
846 * default behaviour. Messages can be added at run-time, see
847 * MessageCache.php.
849 * @return String
851 function getDescription() {
852 return wfMsg( strtolower( $this->mName ) );
856 * Get a self-referential title object
858 * @return Title object
860 function getTitle( $subpage = false ) {
861 return self::getTitleFor( $this->mName, $subpage );
865 * Set whether this page is listed in Special:Specialpages, at run-time
867 function setListed( $listed ) {
868 return wfSetVar( $this->mListed, $listed );
872 * If the special page is a redirect, then get the Title object it redirects to.
873 * False otherwise.
875 function getRedirect( $subpage ) {
876 return false;
880 * Return part of the request string for a special redirect page
881 * This allows passing, e.g. action=history to Special:Mypage, etc.
883 * @return String
885 function getRedirectQuery() {
886 global $wgRequest;
887 $params = array();
888 foreach( $this->mAllowedRedirectParams as $arg ) {
889 if( ( $val = $wgRequest->getVal( $arg, null ) ) !== null )
890 $params[] = $arg . '=' . $val;
893 foreach( $this->mAddedRedirectParams as $arg => $val ) {
894 $params[] = $arg . '=' . $val;
897 return count( $params ) ? implode( '&', $params ) : false;
902 * Shortcut to construct a special page which is unlisted by default
903 * @ingroup SpecialPage
905 class UnlistedSpecialPage extends SpecialPage
907 function UnlistedSpecialPage( $name, $restriction = '', $function = false, $file = 'default' ) {
908 SpecialPage::SpecialPage( $name, $restriction, false, $function, $file );
913 * Shortcut to construct an includable special page
914 * @ingroup SpecialPage
916 class IncludableSpecialPage extends SpecialPage
918 function IncludableSpecialPage( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
919 SpecialPage::SpecialPage( $name, $restriction, $listed, $function, $file, true );
924 * Shortcut to construct a special page alias.
925 * @ingroup SpecialPage
927 class SpecialRedirectToSpecial extends UnlistedSpecialPage {
928 var $redirName, $redirSubpage;
930 function __construct( $name, $redirName, $redirSubpage = false, $allowedRedirectParams = array(), $addedRedirectParams = array() ) {
931 parent::__construct( $name );
932 $this->redirName = $redirName;
933 $this->redirSubpage = $redirSubpage;
934 $this->mAllowedRedirectParams = $allowedRedirectParams;
935 $this->mAddedRedirectParams = $addedRedirectParams;
938 function getRedirect( $subpage ) {
939 if ( $this->redirSubpage === false ) {
940 return SpecialPage::getTitleFor( $this->redirName, $subpage );
941 } else {
942 return SpecialPage::getTitleFor( $this->redirName, $this->redirSubpage );
947 /** SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
948 * are used to get user independant links pointing to the user page, talk
949 * page and list of contributions.
950 * This can let us cache a single copy of any generated content for all
951 * users.
955 * Shortcut to construct a special page pointing to current user user's page.
956 * @ingroup SpecialPage
958 class SpecialMypage extends UnlistedSpecialPage {
959 function __construct() {
960 parent::__construct( 'Mypage' );
961 $this->mAllowedRedirectParams = array( 'action' , 'preload' , 'editintro', 'section' );
964 function getRedirect( $subpage ) {
965 global $wgUser;
966 if ( strval( $subpage ) !== '' ) {
967 return Title::makeTitle( NS_USER, $wgUser->getName() . '/' . $subpage );
968 } else {
969 return Title::makeTitle( NS_USER, $wgUser->getName() );
975 * Shortcut to construct a special page pointing to current user talk page.
976 * @ingroup SpecialPage
978 class SpecialMytalk extends UnlistedSpecialPage {
979 function __construct() {
980 parent::__construct( 'Mytalk' );
981 $this->mAllowedRedirectParams = array( 'action' , 'preload' , 'editintro', 'section' );
984 function getRedirect( $subpage ) {
985 global $wgUser;
986 if ( strval( $subpage ) !== '' ) {
987 return Title::makeTitle( NS_USER_TALK, $wgUser->getName() . '/' . $subpage );
988 } else {
989 return Title::makeTitle( NS_USER_TALK, $wgUser->getName() );
995 * Shortcut to construct a special page pointing to current user contributions.
996 * @ingroup SpecialPage
998 class SpecialMycontributions extends UnlistedSpecialPage {
999 function __construct() {
1000 parent::__construct( 'Mycontributions' );
1001 $this->mAllowedRedirectParams = array( 'limit', 'namespace', 'tagfilter',
1002 'offset', 'dir', 'year', 'month', 'feed' );
1005 function getRedirect( $subpage ) {
1006 global $wgUser;
1007 return SpecialPage::getTitleFor( 'Contributions', $wgUser->getName() );