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();
87 * Full title including $par
90 protected $mFullTitle;
93 * List of special pages, followed by parameters.
94 * If the only parameter is a string, that is the page name.
95 * Otherwise, it is an array. The format is one of:
96 ** array( 'SpecialPage', name, right )
97 ** array( 'IncludableSpecialPage', name, right, listed? )
98 ** array( 'UnlistedSpecialPage', name, right )
99 ** array( 'SpecialRedirectToSpecial', name, page to redirect to, special page param, ... )
101 static public $mList = array(
102 # Maintenance Reports
103 'BrokenRedirects' => 'BrokenRedirectsPage',
104 'Deadendpages' => 'DeadendpagesPage',
105 'DoubleRedirects' => 'DoubleRedirectsPage',
106 'Longpages' => 'LongpagesPage',
107 'Ancientpages' => 'AncientpagesPage',
108 'Lonelypages' => 'LonelypagesPage',
109 'Fewestrevisions' => 'FewestrevisionsPage',
110 'Withoutinterwiki' => 'WithoutinterwikiPage',
111 'Protectedpages' => 'SpecialProtectedpages',
112 'Protectedtitles' => 'SpecialProtectedtitles',
113 'Shortpages' => 'ShortpagesPage',
114 'Uncategorizedcategories' => 'UncategorizedcategoriesPage',
115 'Uncategorizedimages' => 'UncategorizedimagesPage',
116 'Uncategorizedpages' => 'UncategorizedpagesPage',
117 'Uncategorizedtemplates' => 'UncategorizedtemplatesPage',
118 'Unusedcategories' => 'UnusedcategoriesPage',
119 'Unusedimages' => 'UnusedimagesPage',
120 'Unusedtemplates' => 'UnusedtemplatesPage',
121 'Unwatchedpages' => 'UnwatchedpagesPage',
122 'Wantedcategories' => 'WantedcategoriesPage',
123 'Wantedfiles' => 'WantedfilesPage',
124 'Wantedpages' => 'WantedpagesPage',
125 'Wantedtemplates' => 'WantedtemplatesPage',
128 'Allpages' => 'SpecialAllpages',
129 'Prefixindex' => 'SpecialPrefixindex',
130 'Categories' => 'SpecialCategories',
131 'Disambiguations' => 'DisambiguationsPage',
132 'Listredirects' => 'ListredirectsPage',
134 # Login/create account
135 'Userlogin' => 'LoginForm',
136 'CreateAccount' => array( 'SpecialRedirectToSpecial', 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ),
139 'Block' => 'SpecialBlock',
140 'Unblock' => 'SpecialUnblock',
141 'BlockList' => 'SpecialBlockList',
142 'Resetpass' => 'SpecialResetpass',
143 'DeletedContributions' => 'DeletedContributionsPage',
144 'Preferences' => 'SpecialPreferences',
145 'Contributions' => 'SpecialContributions',
146 'Listgrouprights' => 'SpecialListGroupRights',
147 'Listusers' => 'SpecialListusers',
148 'Listadmins' => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
149 'Listbots' => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ),
150 'Activeusers' => 'SpecialActiveUsers',
151 'Userrights' => 'UserrightsPage',
152 'DisableAccount' => 'SpecialDisableAccount',
153 'EditWatchlist' => 'SpecialEditWatchlist',
155 # Recent changes and logs
156 'Newimages' => 'SpecialNewFiles',
157 'Log' => 'SpecialLog',
158 'Watchlist' => 'SpecialWatchlist',
159 'Newpages' => 'SpecialNewpages',
160 'Recentchanges' => 'SpecialRecentchanges',
161 'Recentchangeslinked' => 'SpecialRecentchangeslinked',
162 'Tags' => 'SpecialTags',
164 # Media reports and uploads
165 'Listfiles' => 'SpecialListFiles',
166 'Filepath' => 'SpecialFilepath',
167 'MIMEsearch' => 'MIMEsearchPage',
168 'FileDuplicateSearch' => 'FileDuplicateSearchPage',
169 'Upload' => 'SpecialUpload',
170 'UploadStash' => 'SpecialUploadStash',
172 # Wiki data and tools
173 'Statistics' => 'SpecialStatistics',
174 'Allmessages' => 'SpecialAllmessages',
175 'Version' => 'SpecialVersion',
176 'Lockdb' => 'SpecialLockdb',
177 'Unlockdb' => 'SpecialUnlockdb',
179 # Redirecting special pages
180 'LinkSearch' => 'LinkSearchPage',
181 'Randompage' => 'Randompage',
182 'Randomredirect' => 'SpecialRandomredirect',
185 'Mostlinkedcategories' => 'MostlinkedCategoriesPage',
186 'Mostimages' => 'MostimagesPage',
187 'Mostlinked' => 'MostlinkedPage',
188 'Mostlinkedtemplates' => 'MostlinkedTemplatesPage',
189 'Mostcategories' => 'MostcategoriesPage',
190 'Mostrevisions' => 'MostrevisionsPage',
193 'ComparePages' => 'SpecialComparePages',
194 'Export' => 'SpecialExport',
195 'Import' => 'SpecialImport',
196 'Undelete' => 'SpecialUndelete',
197 'Whatlinkshere' => 'SpecialWhatlinkshere',
198 'MergeHistory' => 'SpecialMergeHistory',
201 'Booksources' => 'SpecialBookSources',
203 # Unlisted / redirects
204 'Blankpage' => 'SpecialBlankpage',
205 'Blockme' => 'SpecialBlockme',
206 'Emailuser' => 'SpecialEmailUser',
207 'Movepage' => 'MovePageForm',
208 'Mycontributions' => 'SpecialMycontributions',
209 'Mypage' => 'SpecialMypage',
210 'Mytalk' => 'SpecialMytalk',
211 'Myuploads' => 'SpecialMyuploads',
212 'PermanentLink' => 'SpecialPermanentLink',
213 'Revisiondelete' => 'SpecialRevisionDelete',
214 'RevisionMove' => 'SpecialRevisionMove',
215 'Specialpages' => 'SpecialSpecialpages',
216 'Userlogout' => 'SpecialUserlogout',
219 static public $mAliases;
220 static public $mListInitialised = false;
225 * Initialise the special page list
226 * This must be called before accessing SpecialPage::$mList
228 static function initList() {
229 global $wgSpecialPages;
230 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
232 if ( self
::$mListInitialised ) {
235 wfProfileIn( __METHOD__
);
237 # Better to set this now, to avoid infinite recursion in carelessly written hooks
238 self
::$mListInitialised = true;
240 if( !$wgDisableCounters ) {
241 self
::$mList['Popularpages'] = 'PopularpagesPage';
244 if( !$wgDisableInternalSearch ) {
245 self
::$mList['Search'] = 'SpecialSearch';
248 if( $wgEmailAuthentication ) {
249 self
::$mList['Confirmemail'] = 'EmailConfirmation';
250 self
::$mList['Invalidateemail'] = 'EmailInvalidation';
253 # Add extension special pages
254 self
::$mList = array_merge( self
::$mList, $wgSpecialPages );
257 # This hook can be used to remove undesired built-in special pages
258 wfRunHooks( 'SpecialPage_initList', array( &self
::$mList ) );
259 wfProfileOut( __METHOD__
);
262 static function initAliasList() {
263 if ( !is_null( self
::$mAliases ) ) {
268 $aliases = $wgContLang->getSpecialPageAliases();
269 $missingPages = self
::$mList;
270 self
::$mAliases = array();
271 foreach ( $aliases as $realName => $aliasList ) {
272 foreach ( $aliasList as $alias ) {
273 self
::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
275 unset( $missingPages[$realName] );
277 foreach ( $missingPages as $name => $stuff ) {
278 self
::$mAliases[$wgContLang->caseFold( $name )] = $name;
283 * Given a special page alias, return the special page name.
284 * Returns false if there is no such alias.
286 * @param $alias String
287 * @return String or false
289 static function resolveAlias( $alias ) {
292 if ( !self
::$mListInitialised ) self
::initList();
293 if ( is_null( self
::$mAliases ) ) self
::initAliasList();
294 $caseFoldedAlias = $wgContLang->caseFold( $alias );
295 $caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
296 if ( isset( self
::$mAliases[$caseFoldedAlias] ) ) {
297 return self
::$mAliases[$caseFoldedAlias];
304 * Given a special page name with a possible subpage, return an array
305 * where the first element is the special page name and the second is the
308 * @param $alias String
311 static function resolveAliasWithSubpage( $alias ) {
312 $bits = explode( '/', $alias, 2 );
313 $name = self
::resolveAlias( $bits[0] );
314 if( !isset( $bits[1] ) ) { // bug 2087
319 return array( $name, $par );
323 * Add a page to the list of valid special pages. This used to be the preferred
324 * method for adding special pages in extensions. It's now suggested that you add
325 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
327 * @param $page SpecialPage
328 * Deprecated in 1.7, warnings in 1.17, might be removed in 1.20
330 static function addPage( &$page ) {
331 wfDeprecated( __METHOD__
);
332 if ( !self
::$mListInitialised ) {
335 self
::$mList[$page->mName
] = $page;
339 * Add a page to a certain display group for Special:SpecialPages
341 * @param $page Mixed: SpecialPage or string
342 * @param $group String
344 static function setGroup( $page, $group ) {
345 global $wgSpecialPageGroups;
346 $name = is_object($page) ?
$page->mName
: $page;
347 $wgSpecialPageGroups[$name] = $group;
351 * Add a page to a certain display group for Special:SpecialPages
353 * @param $page SpecialPage
355 static function getGroup( &$page ) {
356 global $wgSpecialPageGroups;
357 static $specialPageGroupsCache = array();
358 if( isset($specialPageGroupsCache[$page->mName
]) ) {
359 return $specialPageGroupsCache[$page->mName
];
361 $msg = wfMessage('specialpages-specialpagegroup-'.strtolower($page->mName
));
362 if ( !$msg->isBlank() ) {
363 $group = $msg->text();
365 $group = isset($wgSpecialPageGroups[$page->mName
])
366 ?
$wgSpecialPageGroups[$page->mName
]
369 if( $group == '-' ) $group = 'other';
370 $specialPageGroupsCache[$page->mName
] = $group;
375 * Remove a special page from the list
376 * Formerly used to disable expensive or dangerous special pages. The
377 * preferred method is now to add a SpecialPage_initList hook.
379 static function removePage( $name ) {
380 if ( !self
::$mListInitialised ) {
383 unset( self
::$mList[$name] );
387 * Check if a given name exist as a special page or as a special page alias
389 * @param $name String: name of a special page
390 * @return Boolean: true if a special page exists with this name
392 static function exists( $name ) {
394 if ( !self
::$mListInitialised ) {
397 if( !self
::$mAliases ) {
398 self
::initAliasList();
401 # Remove special pages inline parameters:
402 $bits = explode( '/', $name );
403 $name = $wgContLang->caseFold($bits[0]);
406 array_key_exists( $name, self
::$mList )
407 or array_key_exists( $name, self
::$mAliases )
412 * Find the object with a given name and return it (or NULL)
414 * @param $name String
415 * @return SpecialPage object or null if the page doesn't exist
417 static function getPage( $name ) {
418 if ( !self
::$mListInitialised ) {
421 if ( array_key_exists( $name, self
::$mList ) ) {
422 $rec = self
::$mList[$name];
423 if ( is_string( $rec ) ) {
425 self
::$mList[$name] = new $className;
426 } elseif ( is_array( $rec ) ) {
427 $className = array_shift( $rec );
428 self
::$mList[$name] = MWFunction
::newObj( $className, $rec );
430 return self
::$mList[$name];
437 * Get a special page with a given localised name, or NULL if there
438 * is no such special page.
440 * @return SpecialPage object or null if the page doesn't exist
442 static function getPageByAlias( $alias ) {
443 $realName = self
::resolveAlias( $alias );
445 return self
::getPage( $realName );
452 * Return categorised listable special pages which are available
453 * for the current user, and everyone.
455 * @return Associative array mapping page's name to its SpecialPage object
457 static function getUsablePages() {
459 if ( !self
::$mListInitialised ) {
464 foreach ( self
::$mList as $name => $rec ) {
465 $page = self
::getPage( $name );
466 if ( $page->isListed()
468 !$page->isRestricted()
469 ||
$page->userCanExecute( $wgUser )
472 $pages[$name] = $page;
479 * Return categorised listable special pages for all users
481 * @return Associative array mapping page's name to its SpecialPage object
483 static function getRegularPages() {
484 if ( !self
::$mListInitialised ) {
489 foreach ( self
::$mList as $name => $rec ) {
490 $page = self
::getPage( $name );
491 if ( $page->isListed() && !$page->isRestricted() ) {
492 $pages[$name] = $page;
499 * Return categorised listable special pages which are available
500 * for the current user, but not for everyone
502 * @return Associative array mapping page's name to its SpecialPage object
504 static function getRestrictedPages() {
506 if( !self
::$mListInitialised ) {
511 foreach( self
::$mList as $name => $rec ) {
512 $page = self
::getPage( $name );
515 && $page->isRestricted()
516 && $page->userCanExecute( $wgUser )
518 $pages[$name] = $page;
525 * Execute a special page path.
526 * The path may contain parameters, e.g. Special:Name/Params
527 * Extracts the special page name and call the execute method, passing the parameters
529 * Returns a title object if the page is redirected, false if there was no such special
530 * page, and true if it was successful.
532 * @param $title a title object
533 * @param $including output is being captured for use in {{special:whatever}}
535 static function executePath( &$title, $including = false ) {
536 global $wgOut, $wgTitle, $wgRequest;
537 wfProfileIn( __METHOD__
);
539 # FIXME: redirects broken due to this call
540 $bits = explode( '/', $title->getDBkey(), 2 );
542 if( !isset( $bits[1] ) ) { // bug 2087
547 $page = SpecialPage
::getPageByAlias( $name );
551 $wgOut->setArticleRelated( false );
552 $wgOut->setRobotPolicy( 'noindex,nofollow' );
553 $wgOut->setStatusCode( 404 );
554 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
556 wfProfileOut( __METHOD__
);
560 # Page exists, set the context
561 $page->setContext( $wgRequest, $wgOut );
565 $redirect = $page->getRedirect( $par );
566 $query = $page->getRedirectQuery();
567 if ( $redirect instanceof Title
) {
568 $url = $redirect->getFullUrl( $query );
569 $wgOut->redirect( $url );
570 wfProfileOut( __METHOD__
);
572 } elseif( $redirect === true ) {
574 $url = $wgScript . '?' . wfArrayToCGI( $query );
575 $wgOut->redirect( $url );
576 wfProfileOut( __METHOD__
);
581 # Redirect to canonical alias for GET commands
582 # Not for POST, we'd lose the post data, so it's best to just distribute
583 # the request. Such POST requests are possible for old extensions that
584 # generate self-links without being aware that their default name has
586 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
588 unset( $query['title'] );
589 $query = wfArrayToCGI( $query );
590 $title = $page->getTitle( $par );
591 $url = $title->getFullUrl( $query );
592 $wgOut->redirect( $url );
593 wfProfileOut( __METHOD__
);
597 if ( $including && !$page->includable() ) {
598 wfProfileOut( __METHOD__
);
600 } elseif ( !$including ) {
601 $wgTitle = $page->getTitle();
603 $page->including( $including );
605 // Execute special page
606 $profName = 'Special:' . $page->name();
607 wfProfileIn( $profName );
608 $page->execute( $par );
609 wfProfileOut( $profName );
610 wfProfileOut( __METHOD__
);
615 * Just like executePath() except it returns the HTML instead of outputting it
616 * Returns false if there was no such special page, or a title object if it was
619 * @return String: HTML fragment
621 static function capturePath( &$title ) {
622 global $wgOut, $wgTitle, $wgUser;
624 // preload the skin - Sometimes the SpecialPage loads it at a bad point in time making a includable special page override the skin title
625 // This hack is ok for now. The plan is for
626 // - Skin to stop storing it's own title
627 // - includable special pages to stop using $wgTitle and $wgOut
628 // - and OutputPage to store it's own skin object instead of askin $wgUser
629 // Once just about any of those are implemented preloading will not be necessarily
632 $oldTitle = $wgTitle;
634 $wgOut = new OutputPage
;
635 $wgOut->setTitle( $title );
636 $wgOut->setUser( $wgUser ); # for now, there may be a better idea in the future
638 $ret = SpecialPage
::executePath( $title, true );
639 if ( $ret === true ) {
640 $ret = $wgOut->getHTML();
642 $wgTitle = $oldTitle;
648 * Get the local name for a specified canonical name
650 * @param $name String
651 * @param $subpage Mixed: boolean false, or string
655 static function getLocalNameFor( $name, $subpage = false ) {
657 $aliases = $wgContLang->getSpecialPageAliases();
658 if ( isset( $aliases[$name][0] ) ) {
659 $name = $aliases[$name][0];
661 // Try harder in case someone misspelled the correct casing
663 foreach ( $aliases as $n => $values ) {
664 if ( strcasecmp( $name, $n ) === 0 ) {
665 wfWarn( "Found alias defined for $n when searching for " .
666 "special page aliases for $name. Case mismatch?" );
673 wfWarn( "Did not find alias for special page '$name'. " .
674 "Perhaps no aliases are defined for it?" );
677 if ( $subpage !== false && !is_null( $subpage ) ) {
678 $name = "$name/$subpage";
680 return $wgContLang->ucfirst( $name );
684 * Get a localised Title object for a specified special page name
686 * @return Title object
688 static function getTitleFor( $name, $subpage = false ) {
689 $name = self
::getLocalNameFor( $name, $subpage );
691 return Title
::makeTitle( NS_SPECIAL
, $name );
693 throw new MWException( "Invalid special page name \"$name\"" );
698 * Get a localised Title object for a page name with a possibly unvalidated subpage
700 * @return Title object or null if the page doesn't exist
702 static function getSafeTitleFor( $name, $subpage = false ) {
703 $name = self
::getLocalNameFor( $name, $subpage );
705 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
712 * Get a title for a given alias
714 * @return Title or null if there is no such alias
716 static function getTitleForAlias( $alias ) {
717 $name = self
::resolveAlias( $alias );
719 return self
::getTitleFor( $name );
726 * Default constructor for special pages
727 * Derivative classes should call this from their constructor
728 * Note that if the user does not have the required level, an error message will
729 * be displayed by the default execute() method, without the global function ever
732 * If you override execute(), you can recover the default behaviour with userCanExecute()
733 * and displayRestrictionError()
735 * @param $name String: name of the special page, as seen in links and URLs
736 * @param $restriction String: user right required, e.g. "block" or "delete"
737 * @param $listed Boolean: whether the page is listed in Special:Specialpages
738 * @param $function Callback: function called by execute(). By default it is constructed from $name
739 * @param $file String: file which is included by execute(). It is also constructed from $name by default
740 * @param $includable Boolean: whether the page can be included in normal pages
742 public function __construct( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
743 $this->init( $name, $restriction, $listed, $function, $file, $includable );
747 * Do the real work for the constructor, mainly so __call() can intercept
748 * calls to SpecialPage()
749 * @see __construct() for param docs
751 private function init( $name, $restriction, $listed, $function, $file, $includable ) {
752 $this->mName
= $name;
753 $this->mRestriction
= $restriction;
754 $this->mListed
= $listed;
755 $this->mIncludable
= $includable;
757 $this->mFunction
= 'wfSpecial'.$name;
759 $this->mFunction
= $function;
761 if ( $file === 'default' ) {
762 $this->mFile
= dirname(__FILE__
) . "/specials/Special$name.php";
764 $this->mFile
= $file;
769 * Use PHP's magic __call handler to get calls to the old PHP4 constructor
770 * because PHP E_STRICT yells at you for having __construct() and SpecialPage()
772 * @param $fName String Name of called method
773 * @param $a Array Arguments to the method
774 * @deprecated Call isn't deprecated, but SpecialPage::SpecialPage() is
776 public function __call( $fName, $a ) {
777 // Sometimes $fName is SpecialPage, sometimes it's specialpage. <3 PHP
778 if( strtolower( $fName ) == 'specialpage' ) {
779 // Debug messages now, warnings in 1.19 or 1.20?
780 wfDebug( "Deprecated SpecialPage::SpecialPage() called, use __construct();\n" );
781 $name = isset( $a[0] ) ?
$a[0] : '';
782 $restriction = isset( $a[1] ) ?
$a[1] : '';
783 $listed = isset( $a[2] ) ?
$a[2] : true;
784 $function = isset( $a[3] ) ?
$a[3] : false;
785 $file = isset( $a[4] ) ?
$a[4] : 'default';
786 $includable = isset( $a[5] ) ?
$a[5] : false;
787 $this->init( $name, $restriction, $listed, $function, $file, $includable );
789 $className = get_class( $this );
790 throw new MWException( "Call to undefined method $className::$fName" );
799 function getName() { return $this->mName
; }
800 function getRestriction() { return $this->mRestriction
; }
801 function getFile() { return $this->mFile
; }
802 function isListed() { return $this->mListed
; }
806 * Accessor and mutator
808 function name( $x = null ) { return wfSetVar( $this->mName
, $x ); }
809 function restrictions( $x = null) {
810 # Use the one below this
811 wfDeprecated( __METHOD__
);
812 return wfSetVar( $this->mRestriction
, $x );
814 function restriction( $x = null) { return wfSetVar( $this->mRestriction
, $x ); }
815 function listed( $x = null) { return wfSetVar( $this->mListed
, $x ); }
816 function func( $x = null) { return wfSetVar( $this->mFunction
, $x ); }
817 function file( $x = null) { return wfSetVar( $this->mFile
, $x ); }
818 function includable( $x = null ) { return wfSetVar( $this->mIncludable
, $x ); }
819 function including( $x = null ) { return wfSetVar( $this->mIncluding
, $x ); }
823 * Get the localised name of the special page
825 function getLocalName() {
826 if ( !isset( $this->mLocalName
) ) {
827 $this->mLocalName
= self
::getLocalNameFor( $this->mName
);
829 return $this->mLocalName
;
833 * Is this page expensive (for some definition of expensive)?
834 * Expensive pages are disabled or cached in miser mode. Originally used
835 * (and still overridden) by QueryPage and subclasses, moved here so that
836 * Special:SpecialPages can safely call it for all special pages.
840 public function isExpensive() {
845 * Can be overridden by subclasses with more complicated permissions
848 * @return Boolean: should the page be displayed with the restricted-access
851 public function isRestricted() {
852 global $wgGroupPermissions;
853 // DWIM: If all anons can do something, then it is not restricted
854 return $this->mRestriction
!= '' && empty($wgGroupPermissions['*'][$this->mRestriction
]);
858 * Checks if the given user (identified by an object) can execute this
859 * special page (as defined by $mRestriction). Can be overridden by sub-
860 * classes with more complicated permissions schemes.
862 * @param $user User: the user to check
863 * @return Boolean: does the user have permission to view the page?
865 public function userCanExecute( $user ) {
866 return $user->isAllowed( $this->mRestriction
);
870 * Output an error message telling the user what access level they have to have
872 function displayRestrictionError() {
873 $this->getOutput()->permissionRequired( $this->mRestriction
);
877 * Sets headers - this should be called from the execute() method of all derived classes!
879 function setHeaders() {
880 if ( $this->including() ) {
881 // Don't set these headers when special page is being included into an article
884 $out = $this->getOutput();
885 $out->setArticleRelated( false );
886 $out->setRobotPolicy( "noindex,nofollow" );
887 $out->setPageTitle( $this->getDescription() );
891 * Default execute method
892 * Checks user permissions, calls the function given in mFunction
894 * This may be overridden by subclasses.
896 function execute( $par ) {
901 if ( $this->userCanExecute( $wgUser ) ) {
902 $func = $this->mFunction
;
903 // only load file if the function does not exist
904 if(!is_callable($func) and $this->mFile
) {
905 require_once( $this->mFile
);
907 $this->outputHeader();
908 call_user_func( $func, $par, $this );
910 $this->displayRestrictionError();
915 * Outputs a summary message on top of special pages
916 * Per default the message key is the canonical name of the special page
917 * May be overriden, i.e. by extensions to stick with the naming conventions
918 * for message keys: 'extensionname-xxx'
920 * @param $summaryMessageKey String: message key of the summary
922 function outputHeader( $summaryMessageKey = '' ) {
925 if( $summaryMessageKey == '' ) {
926 $msg = $wgContLang->lc( $this->name() ) . '-summary';
928 $msg = $summaryMessageKey;
930 if ( !wfMessage( $msg )->isBlank() and ! $this->including() ) {
931 $this->getOutput()->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
937 * Returns the name that goes in the \<h1\> in the special page itself, and
938 * also the name that will be listed in Special:Specialpages
940 * Derived classes can override this, but usually it is easier to keep the
941 * default behaviour. Messages can be added at run-time, see
946 function getDescription() {
947 return wfMsg( strtolower( $this->mName
) );
951 * Get a self-referential title object
953 * @return Title object
955 function getTitle( $subpage = false ) {
956 return self
::getTitleFor( $this->mName
, $subpage );
960 * Set whether this page is listed in Special:Specialpages, at run-time
962 function setListed( $listed ) {
963 return wfSetVar( $this->mListed
, $listed );
967 * If the special page is a redirect, then get the Title object it redirects to.
970 function getRedirect( $subpage ) {
975 * Return part of the request string for a special redirect page
976 * This allows passing, e.g. action=history to Special:Mypage, etc.
980 function getRedirectQuery() {
984 foreach( $this->mAllowedRedirectParams
as $arg ) {
985 if( $wgRequest->getVal( $arg, null ) !== null ){
986 $params[$arg] = $wgRequest->getVal( $arg );
990 foreach( $this->mAddedRedirectParams
as $arg => $val ) {
991 $params[$arg] = $val;
994 return count( $params )
1000 * Sets the context this SpecialPage is executed in
1002 * @param $request WebRequest
1003 * @param $output OutputPage
1005 protected function setContext( $request, $output ) {
1006 $this->mRequest
= $request;
1007 $this->mOutput
= $output;
1008 $this->mFullTitle
= $output->getTitle();
1012 * Get the WebRequest being used for this instance
1014 * @return WebRequest
1016 public function getRequest() {
1017 if ( !isset($this->mRequest
) ) {
1018 wfDebug( __METHOD__
. " called and \$mRequest is null. Return \$wgRequest for sanity\n" );
1022 return $this->mRequest
;
1026 * Get the OutputPage being used for this instance
1028 * @return OutputPage
1030 public function getOutput() {
1031 if ( !isset($this->mOutput
) ) {
1032 wfDebug( __METHOD__
. " called and \$mOutput is null. Return \$wgOut for sanity\n" );
1036 return $this->mOutput
;
1040 * Shortcut to get the skin being used for this instance
1044 public function getUser() {
1045 return $this->getOutput()->getUser();
1049 * Shortcut to get the skin being used for this instance
1053 public function getSkin() {
1054 return $this->getOutput()->getSkin();
1058 * Shortcut to call OutputPage::allowClickjacking(); which also takes
1059 * transclusion into account.
1061 public function allowClickjacking() {
1062 if ( !$this->including() ) {
1063 $this->getOutput()->allowClickjacking();
1068 * Wrapper around wfMessage that sets the current context. Currently this
1069 * is only the title.
1073 public function msg( /* $args */ ) {
1074 return call_user_func_array( 'wfMessage', func_get_args() )->title( $this->mFullTitle
);
1079 * Shortcut to construct a special page which is unlisted by default
1080 * @ingroup SpecialPage
1082 class UnlistedSpecialPage
extends SpecialPage
1084 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
1085 parent
::__construct( $name, $restriction, false, $function, $file );
1090 * Shortcut to construct an includable special page
1091 * @ingroup SpecialPage
1093 class IncludableSpecialPage
extends SpecialPage
1095 function __construct( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
1096 parent
::__construct( $name, $restriction, $listed, $function, $file, true );
1101 * Shortcut to construct a special page alias.
1102 * @ingroup SpecialPage
1104 class SpecialRedirectToSpecial
extends UnlistedSpecialPage
{
1105 var $redirName, $redirSubpage;
1107 function __construct( $name, $redirName, $redirSubpage = false, $allowedRedirectParams = array(), $addedRedirectParams = array() ) {
1108 parent
::__construct( $name );
1109 $this->redirName
= $redirName;
1110 $this->redirSubpage
= $redirSubpage;
1111 $this->mAllowedRedirectParams
= $allowedRedirectParams;
1112 $this->mAddedRedirectParams
= $addedRedirectParams;
1115 function getRedirect( $subpage ) {
1116 if ( $this->redirSubpage
=== false ) {
1117 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
1119 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
1125 * SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
1126 * are used to get user independant links pointing to the user page, talk
1127 * page and list of contributions.
1128 * This can let us cache a single copy of any generated content for all
1133 * Shortcut to construct a special page pointing to current user user's page.
1134 * @ingroup SpecialPage
1136 class SpecialMypage
extends UnlistedSpecialPage
{
1137 function __construct() {
1138 parent
::__construct( 'Mypage' );
1139 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro',
1140 'section', 'oldid', 'diff', 'dir' );
1143 function getRedirect( $subpage ) {
1145 if ( strval( $subpage ) !== '' ) {
1146 return Title
::makeTitle( NS_USER
, $wgUser->getName() . '/' . $subpage );
1148 return Title
::makeTitle( NS_USER
, $wgUser->getName() );
1154 * Shortcut to construct a special page pointing to current user talk page.
1155 * @ingroup SpecialPage
1157 class SpecialMytalk
extends UnlistedSpecialPage
{
1158 function __construct() {
1159 parent
::__construct( 'Mytalk' );
1160 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro',
1161 'section', 'oldid', 'diff', 'dir' );
1164 function getRedirect( $subpage ) {
1166 if ( strval( $subpage ) !== '' ) {
1167 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() . '/' . $subpage );
1169 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() );
1175 * Shortcut to construct a special page pointing to current user contributions.
1176 * @ingroup SpecialPage
1178 class SpecialMycontributions
extends UnlistedSpecialPage
{
1179 function __construct() {
1180 parent
::__construct( 'Mycontributions' );
1181 $this->mAllowedRedirectParams
= array( 'limit', 'namespace', 'tagfilter',
1182 'offset', 'dir', 'year', 'month', 'feed' );
1185 function getRedirect( $subpage ) {
1187 return SpecialPage
::getTitleFor( 'Contributions', $wgUser->getName() );
1192 * Redirect to Special:Listfiles?user=$wgUser
1194 class SpecialMyuploads
extends UnlistedSpecialPage
{
1195 function __construct() {
1196 parent
::__construct( 'Myuploads' );
1197 $this->mAllowedRedirectParams
= array( 'limit' );
1200 function getRedirect( $subpage ) {
1202 return SpecialPage
::getTitleFor( 'Listfiles', $wgUser->getName() );
1207 * Redirect from Special:PermanentLink/### to index.php?oldid=###
1209 class SpecialPermanentLink
extends UnlistedSpecialPage
{
1210 function __construct() {
1211 parent
::__construct( 'PermanentLink' );
1212 $this->mAllowedRedirectParams
= array();
1215 function getRedirect( $subpage ) {
1216 $subpage = intval( $subpage );
1217 $this->mAddedRedirectParams
['oldid'] = $subpage;