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 * 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(
87 'BrokenRedirects' => 'BrokenRedirectsPage',
88 'Deadendpages' => 'DeadendpagesPage',
89 'DoubleRedirects' => 'DoubleRedirectsPage',
90 'Longpages' => 'LongpagesPage',
91 'Ancientpages' => 'AncientpagesPage',
92 'Lonelypages' => 'LonelypagesPage',
93 'Fewestrevisions' => 'FewestrevisionsPage',
94 'Withoutinterwiki' => 'WithoutinterwikiPage',
95 'Protectedpages' => 'SpecialProtectedpages',
96 'Protectedtitles' => 'SpecialProtectedtitles',
97 'Shortpages' => 'ShortpagesPage',
98 'Uncategorizedcategories' => 'UncategorizedcategoriesPage',
99 'Uncategorizedimages' => 'UncategorizedimagesPage',
100 'Uncategorizedpages' => 'UncategorizedpagesPage',
101 'Uncategorizedtemplates' => 'UncategorizedtemplatesPage',
102 'Unusedcategories' => 'UnusedcategoriesPage',
103 'Unusedimages' => 'UnusedimagesPage',
104 'Unusedtemplates' => 'UnusedtemplatesPage',
105 'Unwatchedpages' => 'UnwatchedpagesPage',
106 'Wantedcategories' => 'WantedcategoriesPage',
107 'Wantedfiles' => 'WantedfilesPage',
108 'Wantedpages' => 'WantedpagesPage',
109 'Wantedtemplates' => 'WantedtemplatesPage',
112 'Allpages' => 'SpecialAllpages',
113 'Prefixindex' => 'SpecialPrefixindex',
114 'Categories' => 'SpecialCategories',
115 'Disambiguations' => 'DisambiguationsPage',
116 'Listredirects' => 'ListredirectsPage',
118 # Login/create account
119 'Userlogin' => 'LoginForm',
120 'CreateAccount' => array( 'SpecialRedirectToSpecial', 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ),
123 'Blockip' => 'IPBlockForm',
124 'Ipblocklist' => 'IPUnblockForm',
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 'Listadmins' => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
133 'Listbots' => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ),
134 'Activeusers' => 'SpecialActiveUsers',
135 'Userrights' => 'UserrightsPage',
136 'DisableAccount' => 'SpecialDisableAccount',
138 # Recent changes and logs
139 'Newimages' => array( 'IncludableSpecialPage', 'Newimages' ),
140 'Log' => 'SpecialLog',
141 'Watchlist' => array( 'SpecialPage', 'Watchlist' ),
142 'Newpages' => 'SpecialNewpages',
143 'Recentchanges' => 'SpecialRecentchanges',
144 'Recentchangeslinked' => 'SpecialRecentchangeslinked',
145 'Tags' => 'SpecialTags',
147 # Media reports and uploads
148 'Listfiles' => array( 'SpecialPage', 'Listfiles' ),
149 'Filepath' => 'SpecialFilepath',
150 'MIMEsearch' => 'MIMEsearchPage',
151 'FileDuplicateSearch' => 'FileDuplicateSearchPage',
152 'Upload' => 'SpecialUpload',
153 'UploadStash' => 'SpecialUploadStash',
155 # Wiki data and tools
156 'Statistics' => 'SpecialStatistics',
157 'Allmessages' => 'SpecialAllmessages',
158 'Version' => 'SpecialVersion',
159 'Lockdb' => 'SpecialLockdb',
160 'Unlockdb' => 'SpecialUnlockdb',
162 # Redirecting special pages
163 'LinkSearch' => 'LinkSearchPage',
164 'Randompage' => 'Randompage',
165 'Randomredirect' => 'SpecialRandomredirect',
168 'Mostlinkedcategories' => 'MostlinkedCategoriesPage',
169 'Mostimages' => 'MostimagesPage',
170 'Mostlinked' => 'MostlinkedPage',
171 'Mostlinkedtemplates' => 'MostlinkedTemplatesPage',
172 'Mostcategories' => 'MostcategoriesPage',
173 'Mostrevisions' => 'MostrevisionsPage',
176 'ComparePages' => 'SpecialComparePages',
177 'Export' => 'SpecialExport',
178 'Import' => 'SpecialImport',
179 'Undelete' => 'UndeleteForm',
180 'Whatlinkshere' => 'SpecialWhatlinkshere',
181 'MergeHistory' => 'SpecialMergeHistory',
184 'Booksources' => 'SpecialBookSources',
186 # Unlisted / redirects
187 'Blankpage' => 'SpecialBlankpage',
188 'Blockme' => 'SpecialBlockme',
189 'Emailuser' => 'SpecialEmailUser',
190 'Movepage' => 'MovePageForm',
191 'Mycontributions' => 'SpecialMycontributions',
192 'Mypage' => 'SpecialMypage',
193 'Mytalk' => 'SpecialMytalk',
194 'Myuploads' => 'SpecialMyuploads',
195 'PermanentLink' => 'SpecialPermanentLink',
196 'Revisiondelete' => 'SpecialRevisionDelete',
197 'RevisionMove' => 'SpecialRevisionMove',
198 'Specialpages' => 'SpecialSpecialpages',
199 'Userlogout' => 'SpecialUserlogout',
202 static public $mAliases;
203 static public $mListInitialised = false;
208 * Initialise the special page list
209 * This must be called before accessing SpecialPage::$mList
211 static function initList() {
212 global $wgSpecialPages;
213 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
215 if ( self
::$mListInitialised ) {
218 wfProfileIn( __METHOD__
);
220 # Better to set this now, to avoid infinite recursion in carelessly written hooks
221 self
::$mListInitialised = true;
223 if( !$wgDisableCounters ) {
224 self
::$mList['Popularpages'] = 'PopularpagesPage';
227 if( !$wgDisableInternalSearch ) {
228 self
::$mList['Search'] = 'SpecialSearch';
231 if( $wgEmailAuthentication ) {
232 self
::$mList['Confirmemail'] = 'EmailConfirmation';
233 self
::$mList['Invalidateemail'] = 'EmailInvalidation';
236 # Add extension special pages
237 self
::$mList = array_merge( self
::$mList, $wgSpecialPages );
240 # This hook can be used to remove undesired built-in special pages
241 wfRunHooks( 'SpecialPage_initList', array( &self
::$mList ) );
242 wfProfileOut( __METHOD__
);
245 static function initAliasList() {
246 if ( !is_null( self
::$mAliases ) ) {
251 $aliases = $wgContLang->getSpecialPageAliases();
252 $missingPages = self
::$mList;
253 self
::$mAliases = array();
254 foreach ( $aliases as $realName => $aliasList ) {
255 foreach ( $aliasList as $alias ) {
256 self
::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
258 unset( $missingPages[$realName] );
260 foreach ( $missingPages as $name => $stuff ) {
261 self
::$mAliases[$wgContLang->caseFold( $name )] = $name;
266 * Given a special page alias, return the special page name.
267 * Returns false if there is no such alias.
269 * @param $alias String
270 * @return String or false
272 static function resolveAlias( $alias ) {
275 if ( !self
::$mListInitialised ) self
::initList();
276 if ( is_null( self
::$mAliases ) ) self
::initAliasList();
277 $caseFoldedAlias = $wgContLang->caseFold( $alias );
278 $caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
279 if ( isset( self
::$mAliases[$caseFoldedAlias] ) ) {
280 return self
::$mAliases[$caseFoldedAlias];
287 * Given a special page name with a possible subpage, return an array
288 * where the first element is the special page name and the second is the
291 * @param $alias String
294 static function resolveAliasWithSubpage( $alias ) {
295 $bits = explode( '/', $alias, 2 );
296 $name = self
::resolveAlias( $bits[0] );
297 if( !isset( $bits[1] ) ) { // bug 2087
302 return array( $name, $par );
306 * Add a page to the list of valid special pages. This used to be the preferred
307 * method for adding special pages in extensions. It's now suggested that you add
308 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
310 * @param $page SpecialPage
311 * Deprecated in 1.7, warnings in 1.17, might be removed in 1.20
313 static function addPage( &$page ) {
314 wfDeprecated( __METHOD__
);
315 if ( !self
::$mListInitialised ) {
318 self
::$mList[$page->mName
] = $page;
322 * Add a page to a certain display group for Special:SpecialPages
324 * @param $page Mixed: SpecialPage or string
325 * @param $group String
327 static function setGroup( $page, $group ) {
328 global $wgSpecialPageGroups;
329 $name = is_object($page) ?
$page->mName
: $page;
330 $wgSpecialPageGroups[$name] = $group;
334 * Add a page to a certain display group for Special:SpecialPages
336 * @param $page SpecialPage
338 static function getGroup( &$page ) {
339 global $wgSpecialPageGroups;
340 static $specialPageGroupsCache = array();
341 if( isset($specialPageGroupsCache[$page->mName
]) ) {
342 return $specialPageGroupsCache[$page->mName
];
344 $group = wfMsg('specialpages-specialpagegroup-'.strtolower($page->mName
));
346 ||
wfEmptyMsg('specialpages-specialpagegroup-'.strtolower($page->mName
), $group ) ) {
347 $group = isset($wgSpecialPageGroups[$page->mName
])
348 ?
$wgSpecialPageGroups[$page->mName
]
351 if( $group == '-' ) $group = 'other';
352 $specialPageGroupsCache[$page->mName
] = $group;
357 * Remove a special page from the list
358 * Formerly used to disable expensive or dangerous special pages. The
359 * preferred method is now to add a SpecialPage_initList hook.
361 static function removePage( $name ) {
362 if ( !self
::$mListInitialised ) {
365 unset( self
::$mList[$name] );
369 * Check if a given name exist as a special page or as a special page alias
371 * @param $name String: name of a special page
372 * @return Boolean: true if a special page exists with this name
374 static function exists( $name ) {
376 if ( !self
::$mListInitialised ) {
379 if( !self
::$mAliases ) {
380 self
::initAliasList();
383 # Remove special pages inline parameters:
384 $bits = explode( '/', $name );
385 $name = $wgContLang->caseFold($bits[0]);
388 array_key_exists( $name, self
::$mList )
389 or array_key_exists( $name, self
::$mAliases )
394 * Find the object with a given name and return it (or NULL)
396 * @param $name String
397 * @return SpecialPage object or null if the page doesn't exist
399 static function getPage( $name ) {
400 if ( !self
::$mListInitialised ) {
403 if ( array_key_exists( $name, self
::$mList ) ) {
404 $rec = self
::$mList[$name];
405 if ( is_string( $rec ) ) {
407 self
::$mList[$name] = new $className;
408 } elseif ( is_array( $rec ) ) {
409 $className = array_shift( $rec );
410 self
::$mList[$name] = wfCreateObject( $className, $rec );
412 return self
::$mList[$name];
419 * Get a special page with a given localised name, or NULL if there
420 * is no such special page.
422 * @return SpecialPage object or null if the page doesn't exist
424 static function getPageByAlias( $alias ) {
425 $realName = self
::resolveAlias( $alias );
427 return self
::getPage( $realName );
434 * Return categorised listable special pages which are available
435 * for the current user, and everyone.
437 * @return Associative array mapping page's name to its SpecialPage object
439 static function getUsablePages() {
441 if ( !self
::$mListInitialised ) {
446 foreach ( self
::$mList as $name => $rec ) {
447 $page = self
::getPage( $name );
448 if ( $page->isListed()
450 !$page->isRestricted()
451 ||
$page->userCanExecute( $wgUser )
454 $pages[$name] = $page;
461 * Return categorised listable special pages for all users
463 * @return Associative array mapping page's name to its SpecialPage object
465 static function getRegularPages() {
466 if ( !self
::$mListInitialised ) {
471 foreach ( self
::$mList as $name => $rec ) {
472 $page = self
::getPage( $name );
473 if ( $page->isListed() && !$page->isRestricted() ) {
474 $pages[$name] = $page;
481 * Return categorised listable special pages which are available
482 * for the current user, but not for everyone
484 * @return Associative array mapping page's name to its SpecialPage object
486 static function getRestrictedPages() {
488 if( !self
::$mListInitialised ) {
493 foreach( self
::$mList as $name => $rec ) {
494 $page = self
::getPage( $name );
497 && $page->isRestricted()
498 && $page->userCanExecute( $wgUser )
500 $pages[$name] = $page;
507 * Execute a special page path.
508 * The path may contain parameters, e.g. Special:Name/Params
509 * Extracts the special page name and call the execute method, passing the parameters
511 * Returns a title object if the page is redirected, false if there was no such special
512 * page, and true if it was successful.
514 * @param $title a title object
515 * @param $including output is being captured for use in {{special:whatever}}
517 static function executePath( &$title, $including = false ) {
518 global $wgOut, $wgTitle, $wgRequest;
519 wfProfileIn( __METHOD__
);
521 # FIXME: redirects broken due to this call
522 $bits = explode( '/', $title->getDBkey(), 2 );
524 if( !isset( $bits[1] ) ) { // bug 2087
529 $page = SpecialPage
::getPageByAlias( $name );
533 $wgOut->setArticleRelated( false );
534 $wgOut->setRobotPolicy( 'noindex,nofollow' );
535 $wgOut->setStatusCode( 404 );
536 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
538 wfProfileOut( __METHOD__
);
544 $redirect = $page->getRedirect( $par );
545 $query = $page->getRedirectQuery();
546 if ( $redirect instanceof Title
) {
547 $url = $redirect->getFullUrl( $query );
548 $wgOut->redirect( $url );
549 wfProfileOut( __METHOD__
);
551 } elseif( $redirect === true ) {
553 $url = $wgScript . '?' . wfArrayToCGI( $query );
554 $wgOut->redirect( $url );
555 wfProfileOut( __METHOD__
);
560 # Redirect to canonical alias for GET commands
561 # Not for POST, we'd lose the post data, so it's best to just distribute
562 # the request. Such POST requests are possible for old extensions that
563 # generate self-links without being aware that their default name has
565 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
567 unset( $query['title'] );
568 $query = wfArrayToCGI( $query );
569 $title = $page->getTitle( $par );
570 $url = $title->getFullUrl( $query );
571 $wgOut->redirect( $url );
572 wfProfileOut( __METHOD__
);
576 if ( $including && !$page->includable() ) {
577 wfProfileOut( __METHOD__
);
579 } elseif ( !$including ) {
580 $wgTitle = $page->getTitle();
582 $page->including( $including );
584 // Execute special page
585 $profName = 'Special:' . $page->name();
586 wfProfileIn( $profName );
587 $page->execute( $par );
588 wfProfileOut( $profName );
589 wfProfileOut( __METHOD__
);
594 * Just like executePath() except it returns the HTML instead of outputting it
595 * Returns false if there was no such special page, or a title object if it was
598 * @return String: HTML fragment
600 static function capturePath( &$title ) {
601 global $wgOut, $wgTitle;
603 $oldTitle = $wgTitle;
605 $wgOut = new OutputPage
;
606 $wgOut->setTitle( $title );
608 $ret = SpecialPage
::executePath( $title, true );
609 if ( $ret === true ) {
610 $ret = $wgOut->getHTML();
612 $wgTitle = $oldTitle;
618 * Get the local name for a specified canonical name
620 * @param $name String
621 * @param $subpage Mixed: boolean false, or string
625 static function getLocalNameFor( $name, $subpage = false ) {
627 $aliases = $wgContLang->getSpecialPageAliases();
628 if ( isset( $aliases[$name][0] ) ) {
629 $name = $aliases[$name][0];
631 // Try harder in case someone misspelled the correct casing
633 foreach ( $aliases as $n => $values ) {
634 if ( strcasecmp( $name, $n ) === 0 ) {
635 wfWarn( "Found alias defined for $n when searching for" .
636 "special page aliases for $name. Case mismatch?" );
643 wfWarn( "Did not find alias for special page '$name'. " .
644 "Perhaps no aliases are defined for it?" );
647 if ( $subpage !== false && !is_null( $subpage ) ) {
648 $name = "$name/$subpage";
650 return $wgContLang->ucfirst( $name );
654 * Get a localised Title object for a specified special page name
656 * @return Title object
658 static function getTitleFor( $name, $subpage = false ) {
659 $name = self
::getLocalNameFor( $name, $subpage );
661 return Title
::makeTitle( NS_SPECIAL
, $name );
663 throw new MWException( "Invalid special page name \"$name\"" );
668 * Get a localised Title object for a page name with a possibly unvalidated subpage
670 * @return Title object or null if the page doesn't exist
672 static function getSafeTitleFor( $name, $subpage = false ) {
673 $name = self
::getLocalNameFor( $name, $subpage );
675 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
682 * Get a title for a given alias
684 * @return Title or null if there is no such alias
686 static function getTitleForAlias( $alias ) {
687 $name = self
::resolveAlias( $alias );
689 return self
::getTitleFor( $name );
696 * Default constructor for special pages
697 * Derivative classes should call this from their constructor
698 * Note that if the user does not have the required level, an error message will
699 * be displayed by the default execute() method, without the global function ever
702 * If you override execute(), you can recover the default behaviour with userCanExecute()
703 * and displayRestrictionError()
705 * @param $name String: name of the special page, as seen in links and URLs
706 * @param $restriction String: user right required, e.g. "block" or "delete"
707 * @param $listed Boolean: whether the page is listed in Special:Specialpages
708 * @param $function Callback: function called by execute(). By default it is constructed from $name
709 * @param $file String: file which is included by execute(). It is also constructed from $name by default
710 * @param $includable Boolean: whether the page can be included in normal pages
712 public function __construct( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
713 $this->init( $name, $restriction, $listed, $function, $file, $includable );
717 * Do the real work for the constructor, mainly so __call() can intercept
718 * calls to SpecialPage()
719 * @see __construct() for param docs
721 private function init( $name, $restriction, $listed, $function, $file, $includable ) {
722 $this->mName
= $name;
723 $this->mRestriction
= $restriction;
724 $this->mListed
= $listed;
725 $this->mIncludable
= $includable;
727 $this->mFunction
= 'wfSpecial'.$name;
729 $this->mFunction
= $function;
731 if ( $file === 'default' ) {
732 $this->mFile
= dirname(__FILE__
) . "/specials/Special$name.php";
734 $this->mFile
= $file;
739 * Use PHP's magic __call handler to get calls to the old PHP4 constructor
740 * because PHP E_STRICT yells at you for having __construct() and SpecialPage()
742 * @param $fName String Name of called method
743 * @param $a Array Arguments to the method
744 * @deprecated Call isn't deprecated, but SpecialPage::SpecialPage() is
746 public function __call( $fName, $a ) {
747 // Sometimes $fName is SpecialPage, sometimes it's specialpage. <3 PHP
748 if( strtolower( $fName ) == 'specialpage' ) {
749 // Debug messages now, warnings in 1.19 or 1.20?
750 wfDebug( "Deprecated SpecialPage::SpecialPage() called, use __construct();\n" );
751 $name = isset( $a[0] ) ?
$a[0] : '';
752 $restriction = isset( $a[1] ) ?
$a[1] : '';
753 $listed = isset( $a[2] ) ?
$a[2] : true;
754 $function = isset( $a[3] ) ?
$a[3] : false;
755 $file = isset( $a[4] ) ?
$a[4] : 'default';
756 $includable = isset( $a[5] ) ?
$a[5] : false;
757 $this->init( $name, $restriction, $listed, $function, $file, $includable );
759 $className = get_class( $this );
760 throw new MWException( "Call to undefined method $className::$fName" );
769 function getName() { return $this->mName
; }
770 function getRestriction() { return $this->mRestriction
; }
771 function getFile() { return $this->mFile
; }
772 function isListed() { return $this->mListed
; }
776 * Accessor and mutator
778 function name( $x = null ) { return wfSetVar( $this->mName
, $x ); }
779 function restrictions( $x = null) {
780 # Use the one below this
781 wfDeprecated( __METHOD__
);
782 return wfSetVar( $this->mRestriction
, $x );
784 function restriction( $x = null) { return wfSetVar( $this->mRestriction
, $x ); }
785 function listed( $x = null) { return wfSetVar( $this->mListed
, $x ); }
786 function func( $x = null) { return wfSetVar( $this->mFunction
, $x ); }
787 function file( $x = null) { return wfSetVar( $this->mFile
, $x ); }
788 function includable( $x = null ) { return wfSetVar( $this->mIncludable
, $x ); }
789 function including( $x = null ) { return wfSetVar( $this->mIncluding
, $x ); }
793 * Get the localised name of the special page
795 function getLocalName() {
796 if ( !isset( $this->mLocalName
) ) {
797 $this->mLocalName
= self
::getLocalNameFor( $this->mName
);
799 return $this->mLocalName
;
803 * Can be overridden by subclasses with more complicated permissions
806 * @return Boolean: should the page be displayed with the restricted-access
809 public function isRestricted() {
810 global $wgGroupPermissions;
811 // DWIM: If all anons can do something, then it is not restricted
812 return $this->mRestriction
!= '' && empty($wgGroupPermissions['*'][$this->mRestriction
]);
816 * Checks if the given user (identified by an object) can execute this
817 * special page (as defined by $mRestriction). Can be overridden by sub-
818 * classes with more complicated permissions schemes.
820 * @param $user User: the user to check
821 * @return Boolean: does the user have permission to view the page?
823 public function userCanExecute( $user ) {
824 return $user->isAllowed( $this->mRestriction
);
828 * Output an error message telling the user what access level they have to have
830 function displayRestrictionError() {
832 $wgOut->permissionRequired( $this->mRestriction
);
836 * Sets headers - this should be called from the execute() method of all derived classes!
838 function setHeaders() {
840 $wgOut->setArticleRelated( false );
841 $wgOut->setRobotPolicy( "noindex,nofollow" );
842 $wgOut->setPageTitle( $this->getDescription() );
846 * Default execute method
847 * Checks user permissions, calls the function given in mFunction
849 * This may be overridden by subclasses.
851 function execute( $par ) {
856 if ( $this->userCanExecute( $wgUser ) ) {
857 $func = $this->mFunction
;
858 // only load file if the function does not exist
859 if(!is_callable($func) and $this->mFile
) {
860 require_once( $this->mFile
);
862 $this->outputHeader();
863 call_user_func( $func, $par, $this );
865 $this->displayRestrictionError();
870 * Outputs a summary message on top of special pages
871 * Per default the message key is the canonical name of the special page
872 * May be overriden, i.e. by extensions to stick with the naming conventions
873 * for message keys: 'extensionname-xxx'
875 * @param $summaryMessageKey String: message key of the summary
877 function outputHeader( $summaryMessageKey = '' ) {
878 global $wgOut, $wgContLang;
880 if( $summaryMessageKey == '' ) {
881 $msg = $wgContLang->lc( $this->name() ) . '-summary';
883 $msg = $summaryMessageKey;
885 $out = wfMsgNoTrans( $msg );
886 if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() ) {
887 $wgOut->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
893 * Returns the name that goes in the \<h1\> in the special page itself, and
894 * also the name that will be listed in Special:Specialpages
896 * Derived classes can override this, but usually it is easier to keep the
897 * default behaviour. Messages can be added at run-time, see
902 function getDescription() {
903 return wfMsg( strtolower( $this->mName
) );
907 * Get a self-referential title object
909 * @return Title object
911 function getTitle( $subpage = false ) {
912 return self
::getTitleFor( $this->mName
, $subpage );
916 * Set whether this page is listed in Special:Specialpages, at run-time
918 function setListed( $listed ) {
919 return wfSetVar( $this->mListed
, $listed );
923 * If the special page is a redirect, then get the Title object it redirects to.
926 function getRedirect( $subpage ) {
931 * Return part of the request string for a special redirect page
932 * This allows passing, e.g. action=history to Special:Mypage, etc.
936 function getRedirectQuery() {
940 foreach( $this->mAllowedRedirectParams
as $arg ) {
941 if( $wgRequest->getVal( $arg, null ) !== null ){
942 $params[$arg] = $wgRequest->getVal( $arg );
946 foreach( $this->mAddedRedirectParams
as $arg => $val ) {
947 $params[$arg] = $val;
950 return count( $params )
957 * Shortcut to construct a special page which is unlisted by default
958 * @ingroup SpecialPage
960 class UnlistedSpecialPage
extends SpecialPage
962 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
963 parent
::__construct( $name, $restriction, false, $function, $file );
968 * Shortcut to construct an includable special page
969 * @ingroup SpecialPage
971 class IncludableSpecialPage
extends SpecialPage
973 function __construct( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
974 parent
::__construct( $name, $restriction, $listed, $function, $file, true );
979 * Shortcut to construct a special page alias.
980 * @ingroup SpecialPage
982 class SpecialRedirectToSpecial
extends UnlistedSpecialPage
{
983 var $redirName, $redirSubpage;
985 function __construct( $name, $redirName, $redirSubpage = false, $allowedRedirectParams = array(), $addedRedirectParams = array() ) {
986 parent
::__construct( $name );
987 $this->redirName
= $redirName;
988 $this->redirSubpage
= $redirSubpage;
989 $this->mAllowedRedirectParams
= $allowedRedirectParams;
990 $this->mAddedRedirectParams
= $addedRedirectParams;
993 function getRedirect( $subpage ) {
994 if ( $this->redirSubpage
=== false ) {
995 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
997 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
1003 * SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
1004 * are used to get user independant links pointing to the user page, talk
1005 * page and list of contributions.
1006 * This can let us cache a single copy of any generated content for all
1011 * Shortcut to construct a special page pointing to current user user's page.
1012 * @ingroup SpecialPage
1014 class SpecialMypage
extends UnlistedSpecialPage
{
1015 function __construct() {
1016 parent
::__construct( 'Mypage' );
1017 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro',
1018 'section', 'oldid', 'diff', 'dir' );
1021 function getRedirect( $subpage ) {
1023 if ( strval( $subpage ) !== '' ) {
1024 return Title
::makeTitle( NS_USER
, $wgUser->getName() . '/' . $subpage );
1026 return Title
::makeTitle( NS_USER
, $wgUser->getName() );
1032 * Shortcut to construct a special page pointing to current user talk page.
1033 * @ingroup SpecialPage
1035 class SpecialMytalk
extends UnlistedSpecialPage
{
1036 function __construct() {
1037 parent
::__construct( 'Mytalk' );
1038 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro',
1039 'section', 'oldid', 'diff', 'dir' );
1042 function getRedirect( $subpage ) {
1044 if ( strval( $subpage ) !== '' ) {
1045 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() . '/' . $subpage );
1047 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() );
1053 * Shortcut to construct a special page pointing to current user contributions.
1054 * @ingroup SpecialPage
1056 class SpecialMycontributions
extends UnlistedSpecialPage
{
1057 function __construct() {
1058 parent
::__construct( 'Mycontributions' );
1059 $this->mAllowedRedirectParams
= array( 'limit', 'namespace', 'tagfilter',
1060 'offset', 'dir', 'year', 'month', 'feed' );
1063 function getRedirect( $subpage ) {
1065 return SpecialPage
::getTitleFor( 'Contributions', $wgUser->getName() );
1070 * Redirect to Special:Listfiles?user=$wgUser
1072 class SpecialMyuploads
extends UnlistedSpecialPage
{
1073 function __construct() {
1074 parent
::__construct( 'Myuploads' );
1075 $this->mAllowedRedirectParams
= array( 'limit' );
1078 function getRedirect( $subpage ) {
1080 return SpecialPage
::getTitleFor( 'Listfiles', $wgUser->getName() );
1085 * Redirect to Special:Listfiles?user=$wgUser
1087 class SpecialPermanentLink
extends UnlistedSpecialPage
{
1088 function __construct() {
1089 parent
::__construct( 'PermanentLink' );
1090 $this->mAllowedRedirectParams
= array();
1093 function getRedirect( $subpage ) {
1094 $subpage = intval( $subpage );
1095 $this->mAddedRedirectParams
['oldid'] = $subpage;