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
35 * The canonical name of this special page
36 * Also used for the default <h1> heading, @see getDescription()
40 * The local name of this special page
44 * Minimum user level required to access this page, or "" for anyone.
45 * Also used to categorise the pages in Special:Specialpages
49 * Listed in Special:Specialpages?
53 * Function name called by the default execute()
57 * File which needs to be included before the function above can be called
61 * Whether or not this special page is being included from an article
65 * Whether the special page can be included in an article
69 * Query parameters that can be passed through redirects
71 var $mAllowedRedirectParams = array();
73 * Query parameteres added by redirects
75 var $mAddedRedirectParams = array();
77 * Current request context
83 * List of special pages, followed by parameters.
84 * If the only parameter is a string, that is the page name.
85 * Otherwise, it is an array. The format is one of:
86 ** array( 'SpecialPage', name, right )
87 ** array( 'IncludableSpecialPage', name, right, listed? )
88 ** array( 'UnlistedSpecialPage', name, right )
89 ** array( 'SpecialRedirectToSpecial', name, page to redirect to, special page param, ... )
91 static public $mList = array(
93 'BrokenRedirects' => 'BrokenRedirectsPage',
94 'Deadendpages' => 'DeadendpagesPage',
95 'DoubleRedirects' => 'DoubleRedirectsPage',
96 'Longpages' => 'LongpagesPage',
97 'Ancientpages' => 'AncientpagesPage',
98 'Lonelypages' => 'LonelypagesPage',
99 'Fewestrevisions' => 'FewestrevisionsPage',
100 'Withoutinterwiki' => 'WithoutinterwikiPage',
101 'Protectedpages' => 'SpecialProtectedpages',
102 'Protectedtitles' => 'SpecialProtectedtitles',
103 'Shortpages' => 'ShortpagesPage',
104 'Uncategorizedcategories' => 'UncategorizedcategoriesPage',
105 'Uncategorizedimages' => 'UncategorizedimagesPage',
106 'Uncategorizedpages' => 'UncategorizedpagesPage',
107 'Uncategorizedtemplates' => 'UncategorizedtemplatesPage',
108 'Unusedcategories' => 'UnusedcategoriesPage',
109 'Unusedimages' => 'UnusedimagesPage',
110 'Unusedtemplates' => 'UnusedtemplatesPage',
111 'Unwatchedpages' => 'UnwatchedpagesPage',
112 'Wantedcategories' => 'WantedcategoriesPage',
113 'Wantedfiles' => 'WantedfilesPage',
114 'Wantedpages' => 'WantedpagesPage',
115 'Wantedtemplates' => 'WantedtemplatesPage',
118 'Allpages' => 'SpecialAllpages',
119 'Prefixindex' => 'SpecialPrefixindex',
120 'Categories' => 'SpecialCategories',
121 'Disambiguations' => 'DisambiguationsPage',
122 'Listredirects' => 'ListredirectsPage',
124 # Login/create account
125 'Userlogin' => 'LoginForm',
126 'CreateAccount' => array( 'SpecialRedirectToSpecial', 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ),
129 'Block' => 'SpecialBlock',
130 'Unblock' => 'SpecialUnblock',
131 'BlockList' => 'SpecialBlockList',
132 'Resetpass' => 'SpecialResetpass',
133 'DeletedContributions' => 'DeletedContributionsPage',
134 'Preferences' => 'SpecialPreferences',
135 'Contributions' => 'SpecialContributions',
136 'Listgrouprights' => 'SpecialListGroupRights',
137 'Listusers' => 'SpecialListusers',
138 'Listadmins' => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
139 'Listbots' => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ),
140 'Activeusers' => 'SpecialActiveUsers',
141 'Userrights' => 'UserrightsPage',
142 'DisableAccount' => 'SpecialDisableAccount',
143 'EditWatchlist' => 'SpecialEditWatchlist',
145 # Recent changes and logs
146 'Newimages' => 'SpecialNewFiles',
147 'Log' => 'SpecialLog',
148 'Watchlist' => 'SpecialWatchlist',
149 'Newpages' => 'SpecialNewpages',
150 'Recentchanges' => 'SpecialRecentchanges',
151 'Recentchangeslinked' => 'SpecialRecentchangeslinked',
152 'Tags' => 'SpecialTags',
154 # Media reports and uploads
155 'Listfiles' => 'SpecialListFiles',
156 'Filepath' => 'SpecialFilepath',
157 'MIMEsearch' => 'MIMEsearchPage',
158 'FileDuplicateSearch' => 'FileDuplicateSearchPage',
159 'Upload' => 'SpecialUpload',
160 'UploadStash' => 'SpecialUploadStash',
162 # Wiki data and tools
163 'Statistics' => 'SpecialStatistics',
164 'Allmessages' => 'SpecialAllmessages',
165 'Version' => 'SpecialVersion',
166 'Lockdb' => 'SpecialLockdb',
167 'Unlockdb' => 'SpecialUnlockdb',
169 # Redirecting special pages
170 'LinkSearch' => 'LinkSearchPage',
171 'Randompage' => 'Randompage',
172 'Randomredirect' => 'SpecialRandomredirect',
175 'Mostlinkedcategories' => 'MostlinkedCategoriesPage',
176 'Mostimages' => 'MostimagesPage',
177 'Mostlinked' => 'MostlinkedPage',
178 'Mostlinkedtemplates' => 'MostlinkedTemplatesPage',
179 'Mostcategories' => 'MostcategoriesPage',
180 'Mostrevisions' => 'MostrevisionsPage',
183 'ComparePages' => 'SpecialComparePages',
184 'Export' => 'SpecialExport',
185 'Import' => 'SpecialImport',
186 'Undelete' => 'SpecialUndelete',
187 'Whatlinkshere' => 'SpecialWhatlinkshere',
188 'MergeHistory' => 'SpecialMergeHistory',
191 'Booksources' => 'SpecialBookSources',
193 # Unlisted / redirects
194 'Blankpage' => 'SpecialBlankpage',
195 'Blockme' => 'SpecialBlockme',
196 'Emailuser' => 'SpecialEmailUser',
197 'Movepage' => 'MovePageForm',
198 'Mycontributions' => 'SpecialMycontributions',
199 'Mypage' => 'SpecialMypage',
200 'Mytalk' => 'SpecialMytalk',
201 'Myuploads' => 'SpecialMyuploads',
202 'PermanentLink' => 'SpecialPermanentLink',
203 'Revisiondelete' => 'SpecialRevisionDelete',
204 'RevisionMove' => 'SpecialRevisionMove',
205 'Specialpages' => 'SpecialSpecialpages',
206 'Userlogout' => 'SpecialUserlogout',
209 static public $mAliases;
210 static public $mListInitialised = false;
215 * Initialise the special page list
216 * This must be called before accessing SpecialPage::$mList
218 static function initList() {
219 global $wgSpecialPages;
220 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
222 if ( self
::$mListInitialised ) {
225 wfProfileIn( __METHOD__
);
227 # Better to set this now, to avoid infinite recursion in carelessly written hooks
228 self
::$mListInitialised = true;
230 if( !$wgDisableCounters ) {
231 self
::$mList['Popularpages'] = 'PopularpagesPage';
234 if( !$wgDisableInternalSearch ) {
235 self
::$mList['Search'] = 'SpecialSearch';
238 if( $wgEmailAuthentication ) {
239 self
::$mList['Confirmemail'] = 'EmailConfirmation';
240 self
::$mList['Invalidateemail'] = 'EmailInvalidation';
243 # Add extension special pages
244 self
::$mList = array_merge( self
::$mList, $wgSpecialPages );
247 # This hook can be used to remove undesired built-in special pages
248 wfRunHooks( 'SpecialPage_initList', array( &self
::$mList ) );
249 wfProfileOut( __METHOD__
);
252 static function initAliasList() {
253 if ( !is_null( self
::$mAliases ) ) {
258 $aliases = $wgContLang->getSpecialPageAliases();
259 $missingPages = self
::$mList;
260 self
::$mAliases = array();
261 foreach ( $aliases as $realName => $aliasList ) {
262 foreach ( $aliasList as $alias ) {
263 self
::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
265 unset( $missingPages[$realName] );
267 foreach ( $missingPages as $name => $stuff ) {
268 self
::$mAliases[$wgContLang->caseFold( $name )] = $name;
273 * Given a special page alias, return the special page name.
274 * Returns false if there is no such alias.
276 * @param $alias String
277 * @return String or false
279 static function resolveAlias( $alias ) {
282 if ( !self
::$mListInitialised ) self
::initList();
283 if ( is_null( self
::$mAliases ) ) self
::initAliasList();
284 $caseFoldedAlias = $wgContLang->caseFold( $alias );
285 $caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
286 if ( isset( self
::$mAliases[$caseFoldedAlias] ) ) {
287 return self
::$mAliases[$caseFoldedAlias];
294 * Given a special page name with a possible subpage, return an array
295 * where the first element is the special page name and the second is the
298 * @param $alias String
301 static function resolveAliasWithSubpage( $alias ) {
302 $bits = explode( '/', $alias, 2 );
303 $name = self
::resolveAlias( $bits[0] );
304 if( !isset( $bits[1] ) ) { // bug 2087
309 return array( $name, $par );
313 * Add a page to the list of valid special pages. This used to be the preferred
314 * method for adding special pages in extensions. It's now suggested that you add
315 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
317 * @param $page SpecialPage
318 * Deprecated in 1.7, warnings in 1.17, might be removed in 1.20
320 static function addPage( &$page ) {
321 wfDeprecated( __METHOD__
);
322 if ( !self
::$mListInitialised ) {
325 self
::$mList[$page->mName
] = $page;
329 * Add a page to a certain display group for Special:SpecialPages
331 * @param $page Mixed: SpecialPage or string
332 * @param $group String
334 static function setGroup( $page, $group ) {
335 global $wgSpecialPageGroups;
336 $name = is_object($page) ?
$page->mName
: $page;
337 $wgSpecialPageGroups[$name] = $group;
341 * Add a page to a certain display group for Special:SpecialPages
343 * @param $page SpecialPage
345 static function getGroup( &$page ) {
346 global $wgSpecialPageGroups;
347 static $specialPageGroupsCache = array();
348 if( isset($specialPageGroupsCache[$page->mName
]) ) {
349 return $specialPageGroupsCache[$page->mName
];
351 $msg = wfMessage('specialpages-specialpagegroup-'.strtolower($page->mName
));
352 if ( !$msg->isBlank() ) {
353 $group = $msg->text();
355 $group = isset($wgSpecialPageGroups[$page->mName
])
356 ?
$wgSpecialPageGroups[$page->mName
]
359 if( $group == '-' ) $group = 'other';
360 $specialPageGroupsCache[$page->mName
] = $group;
365 * Remove a special page from the list
366 * Formerly used to disable expensive or dangerous special pages. The
367 * preferred method is now to add a SpecialPage_initList hook.
369 static function removePage( $name ) {
370 if ( !self
::$mListInitialised ) {
373 unset( self
::$mList[$name] );
377 * Check if a given name exist as a special page or as a special page alias
379 * @param $name String: name of a special page
380 * @return Boolean: true if a special page exists with this name
382 static function exists( $name ) {
384 if ( !self
::$mListInitialised ) {
387 if( !self
::$mAliases ) {
388 self
::initAliasList();
391 # Remove special pages inline parameters:
392 $bits = explode( '/', $name );
393 $name = $wgContLang->caseFold($bits[0]);
396 array_key_exists( $name, self
::$mList )
397 or array_key_exists( $name, self
::$mAliases )
402 * Find the object with a given name and return it (or NULL)
404 * @param $name String
405 * @return SpecialPage object or null if the page doesn't exist
407 static function getPage( $name ) {
408 if ( !self
::$mListInitialised ) {
411 if ( array_key_exists( $name, self
::$mList ) ) {
412 $rec = self
::$mList[$name];
413 if ( is_string( $rec ) ) {
415 self
::$mList[$name] = new $className;
416 } elseif ( is_array( $rec ) ) {
417 $className = array_shift( $rec );
418 self
::$mList[$name] = MWFunction
::newObj( $className, $rec );
420 return self
::$mList[$name];
427 * Get a special page with a given localised name, or NULL if there
428 * is no such special page.
430 * @return SpecialPage object or null if the page doesn't exist
432 static function getPageByAlias( $alias ) {
433 $realName = self
::resolveAlias( $alias );
435 return self
::getPage( $realName );
442 * Return categorised listable special pages which are available
443 * for the current user, and everyone.
445 * @return Associative array mapping page's name to its SpecialPage object
447 static function getUsablePages() {
449 if ( !self
::$mListInitialised ) {
454 foreach ( self
::$mList as $name => $rec ) {
455 $page = self
::getPage( $name );
456 if ( $page->isListed()
458 !$page->isRestricted()
459 ||
$page->userCanExecute( $wgUser )
462 $pages[$name] = $page;
469 * Return categorised listable special pages for all users
471 * @return Associative array mapping page's name to its SpecialPage object
473 static function getRegularPages() {
474 if ( !self
::$mListInitialised ) {
479 foreach ( self
::$mList as $name => $rec ) {
480 $page = self
::getPage( $name );
481 if ( $page->isListed() && !$page->isRestricted() ) {
482 $pages[$name] = $page;
489 * Return categorised listable special pages which are available
490 * for the current user, but not for everyone
492 * @return Associative array mapping page's name to its SpecialPage object
494 static function getRestrictedPages() {
496 if( !self
::$mListInitialised ) {
501 foreach( self
::$mList as $name => $rec ) {
502 $page = self
::getPage( $name );
505 && $page->isRestricted()
506 && $page->userCanExecute( $wgUser )
508 $pages[$name] = $page;
515 * Execute a special page path.
516 * The path may contain parameters, e.g. Special:Name/Params
517 * Extracts the special page name and call the execute method, passing the parameters
519 * Returns a title object if the page is redirected, false if there was no such special
520 * page, and true if it was successful.
522 * @param $title a title object
523 * @param $including output is being captured for use in {{special:whatever}}
525 static function executePath( &$title, $including = false ) {
526 global $wgOut, $wgTitle, $wgRequest;
527 wfProfileIn( __METHOD__
);
529 # FIXME: redirects broken due to this call
530 $bits = explode( '/', $title->getDBkey(), 2 );
532 if( !isset( $bits[1] ) ) { // bug 2087
537 $page = SpecialPage
::getPageByAlias( $name );
540 $wgOut->setArticleRelated( false );
541 $wgOut->setRobotPolicy( 'noindex,nofollow' );
542 $wgOut->setStatusCode( 404 );
543 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
544 wfProfileOut( __METHOD__
);
548 # Page exists, set the context
549 $page->setContext( $wgOut->getContext() );
553 $redirect = $page->getRedirect( $par );
554 $query = $page->getRedirectQuery();
555 if ( $redirect instanceof Title
) {
556 $url = $redirect->getFullUrl( $query );
557 $wgOut->redirect( $url );
558 wfProfileOut( __METHOD__
);
560 } elseif( $redirect === true ) {
562 $url = $wgScript . '?' . wfArrayToCGI( $query );
563 $wgOut->redirect( $url );
564 wfProfileOut( __METHOD__
);
569 # Redirect to canonical alias for GET commands
570 # Not for POST, we'd lose the post data, so it's best to just distribute
571 # the request. Such POST requests are possible for old extensions that
572 # generate self-links without being aware that their default name has
574 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
576 unset( $query['title'] );
577 $query = wfArrayToCGI( $query );
578 $title = $page->getTitle( $par );
579 $url = $title->getFullUrl( $query );
580 $wgOut->redirect( $url );
581 wfProfileOut( __METHOD__
);
585 if ( $including && !$page->includable() ) {
586 wfProfileOut( __METHOD__
);
588 } elseif ( !$including ) {
589 $wgTitle = $page->getTitle();
591 $page->including( $including );
593 // Execute special page
594 $profName = 'Special:' . $page->name();
595 wfProfileIn( $profName );
596 $page->execute( $par );
597 wfProfileOut( $profName );
598 wfProfileOut( __METHOD__
);
603 * Just like executePath() except it returns the HTML instead of outputting it
604 * Returns false if there was no such special page, or a title object if it was
607 * @return String: HTML fragment
609 static function capturePath( &$title ) {
610 global $wgOut, $wgTitle, $wgUser;
612 // preload the skin - Sometimes the SpecialPage loads it at a bad point in time making a includable special page override the skin title
613 // This hack is ok for now. The plan is for
614 // - Skin to stop storing it's own title
615 // - includable special pages to stop using $wgTitle and $wgOut
616 // - and OutputPage to store it's own skin object instead of askin $wgUser
617 // Once just about any of those are implemented preloading will not be necessarily
620 $oldTitle = $wgTitle;
623 $context = new RequestContext
;
624 $context->setTitle( $title );
625 $wgOut = $context->getOutput();
627 $ret = SpecialPage
::executePath( $title, true );
628 if ( $ret === true ) {
629 $ret = $wgOut->getHTML();
631 $wgTitle = $oldTitle;
637 * Get the local name for a specified canonical name
639 * @param $name String
640 * @param $subpage Mixed: boolean false, or string
644 static function getLocalNameFor( $name, $subpage = false ) {
646 $aliases = $wgContLang->getSpecialPageAliases();
647 if ( isset( $aliases[$name][0] ) ) {
648 $name = $aliases[$name][0];
650 // Try harder in case someone misspelled the correct casing
652 foreach ( $aliases as $n => $values ) {
653 if ( strcasecmp( $name, $n ) === 0 ) {
654 wfWarn( "Found alias defined for $n when searching for " .
655 "special page aliases for $name. Case mismatch?" );
662 wfWarn( "Did not find alias for special page '$name'. " .
663 "Perhaps no aliases are defined for it?" );
666 if ( $subpage !== false && !is_null( $subpage ) ) {
667 $name = "$name/$subpage";
669 return $wgContLang->ucfirst( $name );
673 * Get a localised Title object for a specified special page name
675 * @return Title object
677 static function getTitleFor( $name, $subpage = false ) {
678 $name = self
::getLocalNameFor( $name, $subpage );
680 return Title
::makeTitle( NS_SPECIAL
, $name );
682 throw new MWException( "Invalid special page name \"$name\"" );
687 * Get a localised Title object for a page name with a possibly unvalidated subpage
689 * @return Title object or null if the page doesn't exist
691 static function getSafeTitleFor( $name, $subpage = false ) {
692 $name = self
::getLocalNameFor( $name, $subpage );
694 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
701 * Get a title for a given alias
703 * @return Title or null if there is no such alias
705 static function getTitleForAlias( $alias ) {
706 $name = self
::resolveAlias( $alias );
708 return self
::getTitleFor( $name );
715 * Default constructor for special pages
716 * Derivative classes should call this from their constructor
717 * Note that if the user does not have the required level, an error message will
718 * be displayed by the default execute() method, without the global function ever
721 * If you override execute(), you can recover the default behaviour with userCanExecute()
722 * and displayRestrictionError()
724 * @param $name String: name of the special page, as seen in links and URLs
725 * @param $restriction String: user right required, e.g. "block" or "delete"
726 * @param $listed Boolean: whether the page is listed in Special:Specialpages
727 * @param $function Callback: function called by execute(). By default it is constructed from $name
728 * @param $file String: file which is included by execute(). It is also constructed from $name by default
729 * @param $includable Boolean: whether the page can be included in normal pages
731 public function __construct( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
732 $this->init( $name, $restriction, $listed, $function, $file, $includable );
736 * Do the real work for the constructor, mainly so __call() can intercept
737 * calls to SpecialPage()
738 * @see __construct() for param docs
740 private function init( $name, $restriction, $listed, $function, $file, $includable ) {
741 $this->mName
= $name;
742 $this->mRestriction
= $restriction;
743 $this->mListed
= $listed;
744 $this->mIncludable
= $includable;
746 $this->mFunction
= 'wfSpecial'.$name;
748 $this->mFunction
= $function;
750 if ( $file === 'default' ) {
751 $this->mFile
= dirname(__FILE__
) . "/specials/Special$name.php";
753 $this->mFile
= $file;
758 * Use PHP's magic __call handler to get calls to the old PHP4 constructor
759 * because PHP E_STRICT yells at you for having __construct() and SpecialPage()
761 * @param $fName String Name of called method
762 * @param $a Array Arguments to the method
763 * @deprecated Call isn't deprecated, but SpecialPage::SpecialPage() is
765 public function __call( $fName, $a ) {
766 // Sometimes $fName is SpecialPage, sometimes it's specialpage. <3 PHP
767 if( strtolower( $fName ) == 'specialpage' ) {
768 // Debug messages now, warnings in 1.19 or 1.20?
769 wfDebug( "Deprecated SpecialPage::SpecialPage() called, use __construct();\n" );
770 $name = isset( $a[0] ) ?
$a[0] : '';
771 $restriction = isset( $a[1] ) ?
$a[1] : '';
772 $listed = isset( $a[2] ) ?
$a[2] : true;
773 $function = isset( $a[3] ) ?
$a[3] : false;
774 $file = isset( $a[4] ) ?
$a[4] : 'default';
775 $includable = isset( $a[5] ) ?
$a[5] : false;
776 $this->init( $name, $restriction, $listed, $function, $file, $includable );
778 $className = get_class( $this );
779 throw new MWException( "Call to undefined method $className::$fName" );
788 function getName() { return $this->mName
; }
789 function getRestriction() { return $this->mRestriction
; }
790 function getFile() { return $this->mFile
; }
791 function isListed() { return $this->mListed
; }
795 * Accessor and mutator
797 function name( $x = null ) { return wfSetVar( $this->mName
, $x ); }
798 function restrictions( $x = null) {
799 # Use the one below this
800 wfDeprecated( __METHOD__
);
801 return wfSetVar( $this->mRestriction
, $x );
803 function restriction( $x = null) { return wfSetVar( $this->mRestriction
, $x ); }
804 function listed( $x = null) { return wfSetVar( $this->mListed
, $x ); }
805 function func( $x = null) { return wfSetVar( $this->mFunction
, $x ); }
806 function file( $x = null) { return wfSetVar( $this->mFile
, $x ); }
807 function includable( $x = null ) { return wfSetVar( $this->mIncludable
, $x ); }
808 function including( $x = null ) { return wfSetVar( $this->mIncluding
, $x ); }
812 * Get the localised name of the special page
814 function getLocalName() {
815 if ( !isset( $this->mLocalName
) ) {
816 $this->mLocalName
= self
::getLocalNameFor( $this->mName
);
818 return $this->mLocalName
;
822 * Is this page expensive (for some definition of expensive)?
823 * Expensive pages are disabled or cached in miser mode. Originally used
824 * (and still overridden) by QueryPage and subclasses, moved here so that
825 * Special:SpecialPages can safely call it for all special pages.
829 public function isExpensive() {
834 * Can be overridden by subclasses with more complicated permissions
837 * @return Boolean: should the page be displayed with the restricted-access
840 public function isRestricted() {
841 global $wgGroupPermissions;
842 // DWIM: If all anons can do something, then it is not restricted
843 return $this->mRestriction
!= '' && empty($wgGroupPermissions['*'][$this->mRestriction
]);
847 * Checks if the given user (identified by an object) can execute this
848 * special page (as defined by $mRestriction). Can be overridden by sub-
849 * classes with more complicated permissions schemes.
851 * @param $user User: the user to check
852 * @return Boolean: does the user have permission to view the page?
854 public function userCanExecute( $user ) {
855 return $user->isAllowed( $this->mRestriction
);
859 * Output an error message telling the user what access level they have to have
861 function displayRestrictionError() {
862 $this->getOutput()->permissionRequired( $this->mRestriction
);
866 * Sets headers - this should be called from the execute() method of all derived classes!
868 function setHeaders() {
869 $out = $this->getOutput();
870 $out->setArticleRelated( false );
871 $out->setRobotPolicy( "noindex,nofollow" );
872 $out->setPageTitle( $this->getDescription() );
876 * Default execute method
877 * Checks user permissions, calls the function given in mFunction
879 * This may be overridden by subclasses.
881 function execute( $par ) {
884 if ( $this->userCanExecute( $this->getUser() ) ) {
885 $func = $this->mFunction
;
886 // only load file if the function does not exist
887 if(!is_callable($func) and $this->mFile
) {
888 require_once( $this->mFile
);
890 $this->outputHeader();
891 call_user_func( $func, $par, $this );
893 $this->displayRestrictionError();
898 * Outputs a summary message on top of special pages
899 * Per default the message key is the canonical name of the special page
900 * May be overriden, i.e. by extensions to stick with the naming conventions
901 * for message keys: 'extensionname-xxx'
903 * @param $summaryMessageKey String: message key of the summary
905 function outputHeader( $summaryMessageKey = '' ) {
908 if( $summaryMessageKey == '' ) {
909 $msg = $wgContLang->lc( $this->name() ) . '-summary';
911 $msg = $summaryMessageKey;
913 if ( !wfMessage( $msg )->isBlank() and ! $this->including() ) {
914 $this->getOutput()->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
920 * Returns the name that goes in the \<h1\> in the special page itself, and
921 * also the name that will be listed in Special:Specialpages
923 * Derived classes can override this, but usually it is easier to keep the
924 * default behaviour. Messages can be added at run-time, see
929 function getDescription() {
930 return wfMsg( strtolower( $this->mName
) );
934 * Get a self-referential title object
936 * @return Title object
938 function getTitle( $subpage = false ) {
939 return self
::getTitleFor( $this->mName
, $subpage );
943 * Set whether this page is listed in Special:Specialpages, at run-time
945 function setListed( $listed ) {
946 return wfSetVar( $this->mListed
, $listed );
950 * If the special page is a redirect, then get the Title object it redirects to.
953 function getRedirect( $subpage ) {
958 * Return part of the request string for a special redirect page
959 * This allows passing, e.g. action=history to Special:Mypage, etc.
963 function getRedirectQuery() {
967 foreach( $this->mAllowedRedirectParams
as $arg ) {
968 if( $wgRequest->getVal( $arg, null ) !== null ){
969 $params[$arg] = $wgRequest->getVal( $arg );
973 foreach( $this->mAddedRedirectParams
as $arg => $val ) {
974 $params[$arg] = $val;
977 return count( $params )
983 * Sets the context this SpecialPage is executed in
985 * @param $context RequestContext
988 protected function setContext( $context ) {
989 $this->mContext
= $context;
993 * Gets the context this SpecialPage is executed in
995 * @return RequestContext
998 public function getContext() {
999 if ( $this->mContext
instanceof RequestContext
) {
1000 return $this->mContext
;
1002 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1003 return RequestContext
::getMain();
1008 * Get the WebRequest being used for this instance
1010 * @return WebRequest
1013 public function getRequest() {
1014 return $this->getContext()->getRequest();
1018 * Get the OutputPage being used for this instance
1020 * @return OutputPage
1023 public function getOutput() {
1024 return $this->getContext()->getOutput();
1028 * Shortcut to get the skin being used for this instance
1033 public function getUser() {
1034 return $this->getContext()->getUser();
1038 * Shortcut to get the skin being used for this instance
1043 public function getSkin() {
1044 return $this->getContext()->getSkin();
1048 * Return the full title, including $par
1053 public function getFullTitle() {
1054 return $this->getContext()->getTitle();
1058 * Wrapper around wfMessage that sets the current context. Currently this
1059 * is only the title.
1063 public function msg( /* $args */ ) {
1064 return call_user_func_array( 'wfMessage', func_get_args() )->title( $this->getFullTitle() );
1069 * Shortcut to construct a special page which is unlisted by default
1070 * @ingroup SpecialPage
1072 class UnlistedSpecialPage
extends SpecialPage
1074 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
1075 parent
::__construct( $name, $restriction, false, $function, $file );
1080 * Shortcut to construct an includable special page
1081 * @ingroup SpecialPage
1083 class IncludableSpecialPage
extends SpecialPage
1085 function __construct( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
1086 parent
::__construct( $name, $restriction, $listed, $function, $file, true );
1091 * Shortcut to construct a special page alias.
1092 * @ingroup SpecialPage
1094 class SpecialRedirectToSpecial
extends UnlistedSpecialPage
{
1095 var $redirName, $redirSubpage;
1097 function __construct( $name, $redirName, $redirSubpage = false, $allowedRedirectParams = array(), $addedRedirectParams = array() ) {
1098 parent
::__construct( $name );
1099 $this->redirName
= $redirName;
1100 $this->redirSubpage
= $redirSubpage;
1101 $this->mAllowedRedirectParams
= $allowedRedirectParams;
1102 $this->mAddedRedirectParams
= $addedRedirectParams;
1105 function getRedirect( $subpage ) {
1106 if ( $this->redirSubpage
=== false ) {
1107 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
1109 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
1115 * SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
1116 * are used to get user independant links pointing to the user page, talk
1117 * page and list of contributions.
1118 * This can let us cache a single copy of any generated content for all
1123 * Shortcut to construct a special page pointing to current user user's page.
1124 * @ingroup SpecialPage
1126 class SpecialMypage
extends UnlistedSpecialPage
{
1127 function __construct() {
1128 parent
::__construct( 'Mypage' );
1129 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro',
1130 'section', 'oldid', 'diff', 'dir' );
1133 function getRedirect( $subpage ) {
1135 if ( strval( $subpage ) !== '' ) {
1136 return Title
::makeTitle( NS_USER
, $wgUser->getName() . '/' . $subpage );
1138 return Title
::makeTitle( NS_USER
, $wgUser->getName() );
1144 * Shortcut to construct a special page pointing to current user talk page.
1145 * @ingroup SpecialPage
1147 class SpecialMytalk
extends UnlistedSpecialPage
{
1148 function __construct() {
1149 parent
::__construct( 'Mytalk' );
1150 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro',
1151 'section', 'oldid', 'diff', 'dir' );
1154 function getRedirect( $subpage ) {
1156 if ( strval( $subpage ) !== '' ) {
1157 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() . '/' . $subpage );
1159 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() );
1165 * Shortcut to construct a special page pointing to current user contributions.
1166 * @ingroup SpecialPage
1168 class SpecialMycontributions
extends UnlistedSpecialPage
{
1169 function __construct() {
1170 parent
::__construct( 'Mycontributions' );
1171 $this->mAllowedRedirectParams
= array( 'limit', 'namespace', 'tagfilter',
1172 'offset', 'dir', 'year', 'month', 'feed' );
1175 function getRedirect( $subpage ) {
1177 return SpecialPage
::getTitleFor( 'Contributions', $wgUser->getName() );
1182 * Redirect to Special:Listfiles?user=$wgUser
1184 class SpecialMyuploads
extends UnlistedSpecialPage
{
1185 function __construct() {
1186 parent
::__construct( 'Myuploads' );
1187 $this->mAllowedRedirectParams
= array( 'limit' );
1190 function getRedirect( $subpage ) {
1192 return SpecialPage
::getTitleFor( 'Listfiles', $wgUser->getName() );
1197 * Redirect from Special:PermanentLink/### to index.php?oldid=###
1199 class SpecialPermanentLink
extends UnlistedSpecialPage
{
1200 function __construct() {
1201 parent
::__construct( 'PermanentLink' );
1202 $this->mAllowedRedirectParams
= array();
1205 function getRedirect( $subpage ) {
1206 $subpage = intval( $subpage );
1207 $this->mAddedRedirectParams
['oldid'] = $subpage;