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 'Blockip' => 'IPBlockForm',
140 'Ipblocklist' => 'IPUnblockForm',
141 'Unblock' => array( 'SpecialRedirectToSpecial', 'Unblock', 'Ipblocklist', false, array( 'uselang', 'ip', 'id' ), array( 'action' => 'unblock' ) ),
142 'Resetpass' => 'SpecialResetpass',
143 'DeletedContributions' => 'DeletedContributionsPage',
144 'Preferences' => 'SpecialPreferences',
145 'Contributions' => 'SpecialContributions',
146 'Listgrouprights' => 'SpecialListGroupRights',
147 'Listusers' => array( 'SpecialPage', 'Listusers' ),
148 'Listadmins' => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
149 'Listbots' => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ),
150 'Activeusers' => 'SpecialActiveUsers',
151 'Userrights' => 'UserrightsPage',
152 'DisableAccount' => 'SpecialDisableAccount',
154 # Recent changes and logs
155 'Newimages' => array( 'IncludableSpecialPage', 'Newimages' ),
156 'Log' => 'SpecialLog',
157 'Watchlist' => array( 'SpecialPage', 'Watchlist' ),
158 'Newpages' => 'SpecialNewpages',
159 'Recentchanges' => 'SpecialRecentchanges',
160 'Recentchangeslinked' => 'SpecialRecentchangeslinked',
161 'Tags' => 'SpecialTags',
163 # Media reports and uploads
164 'Listfiles' => array( 'SpecialPage', 'Listfiles' ),
165 'Filepath' => 'SpecialFilepath',
166 'MIMEsearch' => 'MIMEsearchPage',
167 'FileDuplicateSearch' => 'FileDuplicateSearchPage',
168 'Upload' => 'SpecialUpload',
169 'UploadStash' => 'SpecialUploadStash',
171 # Wiki data and tools
172 'Statistics' => 'SpecialStatistics',
173 'Allmessages' => 'SpecialAllmessages',
174 'Version' => 'SpecialVersion',
175 'Lockdb' => 'SpecialLockdb',
176 'Unlockdb' => 'SpecialUnlockdb',
178 # Redirecting special pages
179 'LinkSearch' => 'LinkSearchPage',
180 'Randompage' => 'Randompage',
181 'Randomredirect' => 'SpecialRandomredirect',
184 'Mostlinkedcategories' => 'MostlinkedCategoriesPage',
185 'Mostimages' => 'MostimagesPage',
186 'Mostlinked' => 'MostlinkedPage',
187 'Mostlinkedtemplates' => 'MostlinkedTemplatesPage',
188 'Mostcategories' => 'MostcategoriesPage',
189 'Mostrevisions' => 'MostrevisionsPage',
192 'ComparePages' => 'SpecialComparePages',
193 'Export' => 'SpecialExport',
194 'Import' => 'SpecialImport',
195 'Undelete' => 'SpecialUndelete',
196 'Whatlinkshere' => 'SpecialWhatlinkshere',
197 'MergeHistory' => 'SpecialMergeHistory',
200 'Booksources' => 'SpecialBookSources',
202 # Unlisted / redirects
203 'Blankpage' => 'SpecialBlankpage',
204 'Blockme' => 'SpecialBlockme',
205 'Emailuser' => 'SpecialEmailUser',
206 'Movepage' => 'MovePageForm',
207 'Mycontributions' => 'SpecialMycontributions',
208 'Mypage' => 'SpecialMypage',
209 'Mytalk' => 'SpecialMytalk',
210 'Myuploads' => 'SpecialMyuploads',
211 'PermanentLink' => 'SpecialPermanentLink',
212 'Revisiondelete' => 'SpecialRevisionDelete',
213 'RevisionMove' => 'SpecialRevisionMove',
214 'Specialpages' => 'SpecialSpecialpages',
215 'Userlogout' => 'SpecialUserlogout',
218 static public $mAliases;
219 static public $mListInitialised = false;
224 * Initialise the special page list
225 * This must be called before accessing SpecialPage::$mList
227 static function initList() {
228 global $wgSpecialPages;
229 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
231 if ( self
::$mListInitialised ) {
234 wfProfileIn( __METHOD__
);
236 # Better to set this now, to avoid infinite recursion in carelessly written hooks
237 self
::$mListInitialised = true;
239 if( !$wgDisableCounters ) {
240 self
::$mList['Popularpages'] = 'PopularpagesPage';
243 if( !$wgDisableInternalSearch ) {
244 self
::$mList['Search'] = 'SpecialSearch';
247 if( $wgEmailAuthentication ) {
248 self
::$mList['Confirmemail'] = 'EmailConfirmation';
249 self
::$mList['Invalidateemail'] = 'EmailInvalidation';
252 # Add extension special pages
253 self
::$mList = array_merge( self
::$mList, $wgSpecialPages );
256 # This hook can be used to remove undesired built-in special pages
257 wfRunHooks( 'SpecialPage_initList', array( &self
::$mList ) );
258 wfProfileOut( __METHOD__
);
261 static function initAliasList() {
262 if ( !is_null( self
::$mAliases ) ) {
267 $aliases = $wgContLang->getSpecialPageAliases();
268 $missingPages = self
::$mList;
269 self
::$mAliases = array();
270 foreach ( $aliases as $realName => $aliasList ) {
271 foreach ( $aliasList as $alias ) {
272 self
::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
274 unset( $missingPages[$realName] );
276 foreach ( $missingPages as $name => $stuff ) {
277 self
::$mAliases[$wgContLang->caseFold( $name )] = $name;
282 * Given a special page alias, return the special page name.
283 * Returns false if there is no such alias.
285 * @param $alias String
286 * @return String or false
288 static function resolveAlias( $alias ) {
291 if ( !self
::$mListInitialised ) self
::initList();
292 if ( is_null( self
::$mAliases ) ) self
::initAliasList();
293 $caseFoldedAlias = $wgContLang->caseFold( $alias );
294 $caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
295 if ( isset( self
::$mAliases[$caseFoldedAlias] ) ) {
296 return self
::$mAliases[$caseFoldedAlias];
303 * Given a special page name with a possible subpage, return an array
304 * where the first element is the special page name and the second is the
307 * @param $alias String
310 static function resolveAliasWithSubpage( $alias ) {
311 $bits = explode( '/', $alias, 2 );
312 $name = self
::resolveAlias( $bits[0] );
313 if( !isset( $bits[1] ) ) { // bug 2087
318 return array( $name, $par );
322 * Add a page to the list of valid special pages. This used to be the preferred
323 * method for adding special pages in extensions. It's now suggested that you add
324 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
326 * @param $page SpecialPage
327 * Deprecated in 1.7, warnings in 1.17, might be removed in 1.20
329 static function addPage( &$page ) {
330 wfDeprecated( __METHOD__
);
331 if ( !self
::$mListInitialised ) {
334 self
::$mList[$page->mName
] = $page;
338 * Add a page to a certain display group for Special:SpecialPages
340 * @param $page Mixed: SpecialPage or string
341 * @param $group String
343 static function setGroup( $page, $group ) {
344 global $wgSpecialPageGroups;
345 $name = is_object($page) ?
$page->mName
: $page;
346 $wgSpecialPageGroups[$name] = $group;
350 * Add a page to a certain display group for Special:SpecialPages
352 * @param $page SpecialPage
354 static function getGroup( &$page ) {
355 global $wgSpecialPageGroups;
356 static $specialPageGroupsCache = array();
357 if( isset($specialPageGroupsCache[$page->mName
]) ) {
358 return $specialPageGroupsCache[$page->mName
];
360 $msg = wfMessage('specialpages-specialpagegroup-'.strtolower($page->mName
));
361 if ( !$msg->isBlank() ) {
362 $group = $msg->text();
364 $group = isset($wgSpecialPageGroups[$page->mName
])
365 ?
$wgSpecialPageGroups[$page->mName
]
368 if( $group == '-' ) $group = 'other';
369 $specialPageGroupsCache[$page->mName
] = $group;
374 * Remove a special page from the list
375 * Formerly used to disable expensive or dangerous special pages. The
376 * preferred method is now to add a SpecialPage_initList hook.
378 static function removePage( $name ) {
379 if ( !self
::$mListInitialised ) {
382 unset( self
::$mList[$name] );
386 * Check if a given name exist as a special page or as a special page alias
388 * @param $name String: name of a special page
389 * @return Boolean: true if a special page exists with this name
391 static function exists( $name ) {
393 if ( !self
::$mListInitialised ) {
396 if( !self
::$mAliases ) {
397 self
::initAliasList();
400 # Remove special pages inline parameters:
401 $bits = explode( '/', $name );
402 $name = $wgContLang->caseFold($bits[0]);
405 array_key_exists( $name, self
::$mList )
406 or array_key_exists( $name, self
::$mAliases )
411 * Find the object with a given name and return it (or NULL)
413 * @param $name String
414 * @return SpecialPage object or null if the page doesn't exist
416 static function getPage( $name ) {
417 if ( !self
::$mListInitialised ) {
420 if ( array_key_exists( $name, self
::$mList ) ) {
421 $rec = self
::$mList[$name];
422 if ( is_string( $rec ) ) {
424 self
::$mList[$name] = new $className;
425 } elseif ( is_array( $rec ) ) {
426 $className = array_shift( $rec );
427 self
::$mList[$name] = MWFunction
::newObj( $className, $rec );
429 return self
::$mList[$name];
436 * Get a special page with a given localised name, or NULL if there
437 * is no such special page.
439 * @return SpecialPage object or null if the page doesn't exist
441 static function getPageByAlias( $alias ) {
442 $realName = self
::resolveAlias( $alias );
444 return self
::getPage( $realName );
451 * Return categorised listable special pages which are available
452 * for the current user, and everyone.
454 * @return Associative array mapping page's name to its SpecialPage object
456 static function getUsablePages() {
458 if ( !self
::$mListInitialised ) {
463 foreach ( self
::$mList as $name => $rec ) {
464 $page = self
::getPage( $name );
465 if ( $page->isListed()
467 !$page->isRestricted()
468 ||
$page->userCanExecute( $wgUser )
471 $pages[$name] = $page;
478 * Return categorised listable special pages for all users
480 * @return Associative array mapping page's name to its SpecialPage object
482 static function getRegularPages() {
483 if ( !self
::$mListInitialised ) {
488 foreach ( self
::$mList as $name => $rec ) {
489 $page = self
::getPage( $name );
490 if ( $page->isListed() && !$page->isRestricted() ) {
491 $pages[$name] = $page;
498 * Return categorised listable special pages which are available
499 * for the current user, but not for everyone
501 * @return Associative array mapping page's name to its SpecialPage object
503 static function getRestrictedPages() {
505 if( !self
::$mListInitialised ) {
510 foreach( self
::$mList as $name => $rec ) {
511 $page = self
::getPage( $name );
514 && $page->isRestricted()
515 && $page->userCanExecute( $wgUser )
517 $pages[$name] = $page;
524 * Execute a special page path.
525 * The path may contain parameters, e.g. Special:Name/Params
526 * Extracts the special page name and call the execute method, passing the parameters
528 * Returns a title object if the page is redirected, false if there was no such special
529 * page, and true if it was successful.
531 * @param $title a title object
532 * @param $including output is being captured for use in {{special:whatever}}
534 static function executePath( &$title, $including = false ) {
535 global $wgOut, $wgTitle, $wgRequest;
536 wfProfileIn( __METHOD__
);
538 # FIXME: redirects broken due to this call
539 $bits = explode( '/', $title->getDBkey(), 2 );
541 if( !isset( $bits[1] ) ) { // bug 2087
546 $page = SpecialPage
::getPageByAlias( $name );
550 $wgOut->setArticleRelated( false );
551 $wgOut->setRobotPolicy( 'noindex,nofollow' );
552 $wgOut->setStatusCode( 404 );
553 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
555 wfProfileOut( __METHOD__
);
559 # Page exists, set the context
560 $page->setContext( $wgRequest, $wgOut );
564 $redirect = $page->getRedirect( $par );
565 $query = $page->getRedirectQuery();
566 if ( $redirect instanceof Title
) {
567 $url = $redirect->getFullUrl( $query );
568 $wgOut->redirect( $url );
569 wfProfileOut( __METHOD__
);
571 } elseif( $redirect === true ) {
573 $url = $wgScript . '?' . wfArrayToCGI( $query );
574 $wgOut->redirect( $url );
575 wfProfileOut( __METHOD__
);
580 # Redirect to canonical alias for GET commands
581 # Not for POST, we'd lose the post data, so it's best to just distribute
582 # the request. Such POST requests are possible for old extensions that
583 # generate self-links without being aware that their default name has
585 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
587 unset( $query['title'] );
588 $query = wfArrayToCGI( $query );
589 $title = $page->getTitle( $par );
590 $url = $title->getFullUrl( $query );
591 $wgOut->redirect( $url );
592 wfProfileOut( __METHOD__
);
596 if ( $including && !$page->includable() ) {
597 wfProfileOut( __METHOD__
);
599 } elseif ( !$including ) {
600 $wgTitle = $page->getTitle();
602 $page->including( $including );
604 // Execute special page
605 $profName = 'Special:' . $page->name();
606 wfProfileIn( $profName );
607 $page->execute( $par );
608 wfProfileOut( $profName );
609 wfProfileOut( __METHOD__
);
614 * Just like executePath() except it returns the HTML instead of outputting it
615 * Returns false if there was no such special page, or a title object if it was
618 * @return String: HTML fragment
620 static function capturePath( &$title ) {
621 global $wgOut, $wgTitle;
623 $oldTitle = $wgTitle;
625 $wgOut = new OutputPage
;
626 $wgOut->setTitle( $title );
628 $ret = SpecialPage
::executePath( $title, true );
629 if ( $ret === true ) {
630 $ret = $wgOut->getHTML();
632 $wgTitle = $oldTitle;
638 * Get the local name for a specified canonical name
640 * @param $name String
641 * @param $subpage Mixed: boolean false, or string
645 static function getLocalNameFor( $name, $subpage = false ) {
647 $aliases = $wgContLang->getSpecialPageAliases();
648 if ( isset( $aliases[$name][0] ) ) {
649 $name = $aliases[$name][0];
651 // Try harder in case someone misspelled the correct casing
653 foreach ( $aliases as $n => $values ) {
654 if ( strcasecmp( $name, $n ) === 0 ) {
655 wfWarn( "Found alias defined for $n when searching for " .
656 "special page aliases for $name. Case mismatch?" );
663 wfWarn( "Did not find alias for special page '$name'. " .
664 "Perhaps no aliases are defined for it?" );
667 if ( $subpage !== false && !is_null( $subpage ) ) {
668 $name = "$name/$subpage";
670 return $wgContLang->ucfirst( $name );
674 * Get a localised Title object for a specified special page name
676 * @return Title object
678 static function getTitleFor( $name, $subpage = false ) {
679 $name = self
::getLocalNameFor( $name, $subpage );
681 return Title
::makeTitle( NS_SPECIAL
, $name );
683 throw new MWException( "Invalid special page name \"$name\"" );
688 * Get a localised Title object for a page name with a possibly unvalidated subpage
690 * @return Title object or null if the page doesn't exist
692 static function getSafeTitleFor( $name, $subpage = false ) {
693 $name = self
::getLocalNameFor( $name, $subpage );
695 return Title
::makeTitleSafe( NS_SPECIAL
, $name );
702 * Get a title for a given alias
704 * @return Title or null if there is no such alias
706 static function getTitleForAlias( $alias ) {
707 $name = self
::resolveAlias( $alias );
709 return self
::getTitleFor( $name );
716 * Default constructor for special pages
717 * Derivative classes should call this from their constructor
718 * Note that if the user does not have the required level, an error message will
719 * be displayed by the default execute() method, without the global function ever
722 * If you override execute(), you can recover the default behaviour with userCanExecute()
723 * and displayRestrictionError()
725 * @param $name String: name of the special page, as seen in links and URLs
726 * @param $restriction String: user right required, e.g. "block" or "delete"
727 * @param $listed Boolean: whether the page is listed in Special:Specialpages
728 * @param $function Callback: function called by execute(). By default it is constructed from $name
729 * @param $file String: file which is included by execute(). It is also constructed from $name by default
730 * @param $includable Boolean: whether the page can be included in normal pages
732 public function __construct( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
733 $this->init( $name, $restriction, $listed, $function, $file, $includable );
737 * Do the real work for the constructor, mainly so __call() can intercept
738 * calls to SpecialPage()
739 * @see __construct() for param docs
741 private function init( $name, $restriction, $listed, $function, $file, $includable ) {
742 $this->mName
= $name;
743 $this->mRestriction
= $restriction;
744 $this->mListed
= $listed;
745 $this->mIncludable
= $includable;
747 $this->mFunction
= 'wfSpecial'.$name;
749 $this->mFunction
= $function;
751 if ( $file === 'default' ) {
752 $this->mFile
= dirname(__FILE__
) . "/specials/Special$name.php";
754 $this->mFile
= $file;
759 * Use PHP's magic __call handler to get calls to the old PHP4 constructor
760 * because PHP E_STRICT yells at you for having __construct() and SpecialPage()
762 * @param $fName String Name of called method
763 * @param $a Array Arguments to the method
764 * @deprecated Call isn't deprecated, but SpecialPage::SpecialPage() is
766 public function __call( $fName, $a ) {
767 // Sometimes $fName is SpecialPage, sometimes it's specialpage. <3 PHP
768 if( strtolower( $fName ) == 'specialpage' ) {
769 // Debug messages now, warnings in 1.19 or 1.20?
770 wfDebug( "Deprecated SpecialPage::SpecialPage() called, use __construct();\n" );
771 $name = isset( $a[0] ) ?
$a[0] : '';
772 $restriction = isset( $a[1] ) ?
$a[1] : '';
773 $listed = isset( $a[2] ) ?
$a[2] : true;
774 $function = isset( $a[3] ) ?
$a[3] : false;
775 $file = isset( $a[4] ) ?
$a[4] : 'default';
776 $includable = isset( $a[5] ) ?
$a[5] : false;
777 $this->init( $name, $restriction, $listed, $function, $file, $includable );
779 $className = get_class( $this );
780 throw new MWException( "Call to undefined method $className::$fName" );
789 function getName() { return $this->mName
; }
790 function getRestriction() { return $this->mRestriction
; }
791 function getFile() { return $this->mFile
; }
792 function isListed() { return $this->mListed
; }
796 * Accessor and mutator
798 function name( $x = null ) { return wfSetVar( $this->mName
, $x ); }
799 function restrictions( $x = null) {
800 # Use the one below this
801 wfDeprecated( __METHOD__
);
802 return wfSetVar( $this->mRestriction
, $x );
804 function restriction( $x = null) { return wfSetVar( $this->mRestriction
, $x ); }
805 function listed( $x = null) { return wfSetVar( $this->mListed
, $x ); }
806 function func( $x = null) { return wfSetVar( $this->mFunction
, $x ); }
807 function file( $x = null) { return wfSetVar( $this->mFile
, $x ); }
808 function includable( $x = null ) { return wfSetVar( $this->mIncludable
, $x ); }
809 function including( $x = null ) { return wfSetVar( $this->mIncluding
, $x ); }
813 * Get the localised name of the special page
815 function getLocalName() {
816 if ( !isset( $this->mLocalName
) ) {
817 $this->mLocalName
= self
::getLocalNameFor( $this->mName
);
819 return $this->mLocalName
;
823 * Can be overridden by subclasses with more complicated permissions
826 * @return Boolean: should the page be displayed with the restricted-access
829 public function isRestricted() {
830 global $wgGroupPermissions;
831 // DWIM: If all anons can do something, then it is not restricted
832 return $this->mRestriction
!= '' && empty($wgGroupPermissions['*'][$this->mRestriction
]);
836 * Checks if the given user (identified by an object) can execute this
837 * special page (as defined by $mRestriction). Can be overridden by sub-
838 * classes with more complicated permissions schemes.
840 * @param $user User: the user to check
841 * @return Boolean: does the user have permission to view the page?
843 public function userCanExecute( $user ) {
844 return $user->isAllowed( $this->mRestriction
);
848 * Output an error message telling the user what access level they have to have
850 function displayRestrictionError() {
852 $wgOut->permissionRequired( $this->mRestriction
);
856 * Sets headers - this should be called from the execute() method of all derived classes!
858 function setHeaders() {
860 $wgOut->setArticleRelated( false );
861 $wgOut->setRobotPolicy( "noindex,nofollow" );
862 $wgOut->setPageTitle( $this->getDescription() );
866 * Default execute method
867 * Checks user permissions, calls the function given in mFunction
869 * This may be overridden by subclasses.
871 function execute( $par ) {
876 if ( $this->userCanExecute( $wgUser ) ) {
877 $func = $this->mFunction
;
878 // only load file if the function does not exist
879 if(!is_callable($func) and $this->mFile
) {
880 require_once( $this->mFile
);
882 $this->outputHeader();
883 call_user_func( $func, $par, $this );
885 $this->displayRestrictionError();
890 * Outputs a summary message on top of special pages
891 * Per default the message key is the canonical name of the special page
892 * May be overriden, i.e. by extensions to stick with the naming conventions
893 * for message keys: 'extensionname-xxx'
895 * @param $summaryMessageKey String: message key of the summary
897 function outputHeader( $summaryMessageKey = '' ) {
898 global $wgOut, $wgContLang;
900 if( $summaryMessageKey == '' ) {
901 $msg = $wgContLang->lc( $this->name() ) . '-summary';
903 $msg = $summaryMessageKey;
905 if ( !wfMessage( $msg )->isBlank() and ! $this->including() ) {
906 $wgOut->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
912 * Returns the name that goes in the \<h1\> in the special page itself, and
913 * also the name that will be listed in Special:Specialpages
915 * Derived classes can override this, but usually it is easier to keep the
916 * default behaviour. Messages can be added at run-time, see
921 function getDescription() {
922 return wfMsg( strtolower( $this->mName
) );
926 * Get a self-referential title object
928 * @return Title object
930 function getTitle( $subpage = false ) {
931 return self
::getTitleFor( $this->mName
, $subpage );
935 * Set whether this page is listed in Special:Specialpages, at run-time
937 function setListed( $listed ) {
938 return wfSetVar( $this->mListed
, $listed );
942 * If the special page is a redirect, then get the Title object it redirects to.
945 function getRedirect( $subpage ) {
950 * Return part of the request string for a special redirect page
951 * This allows passing, e.g. action=history to Special:Mypage, etc.
955 function getRedirectQuery() {
959 foreach( $this->mAllowedRedirectParams
as $arg ) {
960 if( $wgRequest->getVal( $arg, null ) !== null ){
961 $params[$arg] = $wgRequest->getVal( $arg );
965 foreach( $this->mAddedRedirectParams
as $arg => $val ) {
966 $params[$arg] = $val;
969 return count( $params )
975 * Sets the context this SpecialPage is executed in
977 * @param $request WebRequest
978 * @param $output OutputPage
980 protected function setContext( $request, $output ) {
981 $this->mRequest
= $request;
982 $this->mOutput
= $output;
983 $this->mFullTitle
= $output->getTitle();
986 * Wrapper around wfMessage that sets the current context. Currently this
991 public function msg( /* $args */ ) {
992 return call_user_func_array( 'wfMessage', func_get_args() )->title( $this->mFullTitle
);
997 * Shortcut to construct a special page which is unlisted by default
998 * @ingroup SpecialPage
1000 class UnlistedSpecialPage
extends SpecialPage
1002 function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
1003 parent
::__construct( $name, $restriction, false, $function, $file );
1008 * Shortcut to construct an includable special page
1009 * @ingroup SpecialPage
1011 class IncludableSpecialPage
extends SpecialPage
1013 function __construct( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
1014 parent
::__construct( $name, $restriction, $listed, $function, $file, true );
1019 * Shortcut to construct a special page alias.
1020 * @ingroup SpecialPage
1022 class SpecialRedirectToSpecial
extends UnlistedSpecialPage
{
1023 var $redirName, $redirSubpage;
1025 function __construct( $name, $redirName, $redirSubpage = false, $allowedRedirectParams = array(), $addedRedirectParams = array() ) {
1026 parent
::__construct( $name );
1027 $this->redirName
= $redirName;
1028 $this->redirSubpage
= $redirSubpage;
1029 $this->mAllowedRedirectParams
= $allowedRedirectParams;
1030 $this->mAddedRedirectParams
= $addedRedirectParams;
1033 function getRedirect( $subpage ) {
1034 if ( $this->redirSubpage
=== false ) {
1035 return SpecialPage
::getTitleFor( $this->redirName
, $subpage );
1037 return SpecialPage
::getTitleFor( $this->redirName
, $this->redirSubpage
);
1043 * SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
1044 * are used to get user independant links pointing to the user page, talk
1045 * page and list of contributions.
1046 * This can let us cache a single copy of any generated content for all
1051 * Shortcut to construct a special page pointing to current user user's page.
1052 * @ingroup SpecialPage
1054 class SpecialMypage
extends UnlistedSpecialPage
{
1055 function __construct() {
1056 parent
::__construct( 'Mypage' );
1057 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro',
1058 'section', 'oldid', 'diff', 'dir' );
1061 function getRedirect( $subpage ) {
1063 if ( strval( $subpage ) !== '' ) {
1064 return Title
::makeTitle( NS_USER
, $wgUser->getName() . '/' . $subpage );
1066 return Title
::makeTitle( NS_USER
, $wgUser->getName() );
1072 * Shortcut to construct a special page pointing to current user talk page.
1073 * @ingroup SpecialPage
1075 class SpecialMytalk
extends UnlistedSpecialPage
{
1076 function __construct() {
1077 parent
::__construct( 'Mytalk' );
1078 $this->mAllowedRedirectParams
= array( 'action' , 'preload' , 'editintro',
1079 'section', 'oldid', 'diff', 'dir' );
1082 function getRedirect( $subpage ) {
1084 if ( strval( $subpage ) !== '' ) {
1085 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() . '/' . $subpage );
1087 return Title
::makeTitle( NS_USER_TALK
, $wgUser->getName() );
1093 * Shortcut to construct a special page pointing to current user contributions.
1094 * @ingroup SpecialPage
1096 class SpecialMycontributions
extends UnlistedSpecialPage
{
1097 function __construct() {
1098 parent
::__construct( 'Mycontributions' );
1099 $this->mAllowedRedirectParams
= array( 'limit', 'namespace', 'tagfilter',
1100 'offset', 'dir', 'year', 'month', 'feed' );
1103 function getRedirect( $subpage ) {
1105 return SpecialPage
::getTitleFor( 'Contributions', $wgUser->getName() );
1110 * Redirect to Special:Listfiles?user=$wgUser
1112 class SpecialMyuploads
extends UnlistedSpecialPage
{
1113 function __construct() {
1114 parent
::__construct( 'Myuploads' );
1115 $this->mAllowedRedirectParams
= array( 'limit' );
1118 function getRedirect( $subpage ) {
1120 return SpecialPage
::getTitleFor( 'Listfiles', $wgUser->getName() );
1125 * Redirect from Special:PermanentLink/### to index.php?oldid=###
1127 class SpecialPermanentLink
extends UnlistedSpecialPage
{
1128 function __construct() {
1129 parent
::__construct( 'PermanentLink' );
1130 $this->mAllowedRedirectParams
= array();
1133 function getRedirect( $subpage ) {
1134 $subpage = intval( $subpage );
1135 $this->mAddedRedirectParams
['oldid'] = $subpage;