* Revert r45062 and related (Merge Interwiki extension to core) per brion.
[mediawiki.git] / includes / SpecialPage.php
blob6df071ef8e52975e6739ebf912317633d0f38782
1 <?php
2 /**
3 * SpecialPage: handling special pages and lists thereof.
5 * To add a special page in an extension, add to $wgSpecialPages either
6 * an object instance or an array containing the name and constructor
7 * parameters. The latter is preferred for performance reasons.
9 * The object instantiated must be either an instance of SpecialPage or a
10 * sub-class thereof. It must have an execute() method, which sends the HTML
11 * for the special page to $wgOut. The parent class has an execute() method
12 * which distributes the call to the historical global functions. Additionally,
13 * execute() also checks if the user has the necessary access privileges
14 * and bails out if not.
16 * To add a core special page, use the similar static list in
17 * SpecialPage::$mList. To remove a core static special page at runtime, use
18 * a SpecialPage_initList hook.
20 * @file
21 * @ingroup SpecialPage
22 * @defgroup SpecialPage SpecialPage
25 /**
26 * Parent special page class, also static functions for handling the special
27 * page list.
28 * @ingroup SpecialPage
30 class SpecialPage
32 /**#@+
33 * @access private
35 /**
36 * The canonical name of this special page
37 * Also used for the default <h1> heading, @see getDescription()
39 var $mName;
40 /**
41 * The local name of this special page
43 var $mLocalName;
44 /**
45 * Minimum user level required to access this page, or "" for anyone.
46 * Also used to categorise the pages in Special:Specialpages
48 var $mRestriction;
49 /**
50 * Listed in Special:Specialpages?
52 var $mListed;
53 /**
54 * Function name called by the default execute()
56 var $mFunction;
57 /**
58 * File which needs to be included before the function above can be called
60 var $mFile;
61 /**
62 * Whether or not this special page is being included from an article
64 var $mIncluding;
65 /**
66 * Whether the special page can be included in an article
68 var $mIncludable;
69 /**
70 * Query parameters that can be passed through redirects
72 var $mAllowedRedirectParams = array();
73 /**
74 * List of special pages, followed by parameters.
75 * If the only parameter is a string, that is the page name.
76 * Otherwise, it is an array. The format is one of:
77 ** array( 'SpecialPage', name, right )
78 ** array( 'IncludableSpecialPage', name, right, listed? )
79 ** array( 'UnlistedSpecialPage', name, right )
80 ** array( 'SpecialRedirectToSpecial', name, page to redirect to, special page param, ... )
82 static public $mList = array(
83 'DoubleRedirects' => array( 'SpecialPage', 'DoubleRedirects' ),
84 'BrokenRedirects' => array( 'SpecialPage', 'BrokenRedirects' ),
85 'Disambiguations' => array( 'SpecialPage', 'Disambiguations' ),
87 'Userlogin' => array( 'SpecialPage', 'Userlogin' ),
88 'Userlogout' => array( 'UnlistedSpecialPage', 'Userlogout' ),
89 'CreateAccount' => array( 'SpecialRedirectToSpecial', 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ),
90 'Preferences' => array( 'SpecialPage', 'Preferences' ),
91 'Watchlist' => array( 'SpecialPage', 'Watchlist' ),
92 'Resetpass' => 'SpecialResetpass',
95 'Recentchanges' => 'SpecialRecentchanges',
96 'Upload' => array( 'SpecialPage', 'Upload' ),
97 'Imagelist' => array( 'SpecialPage', 'Imagelist' ),
98 'Newimages' => array( 'IncludableSpecialPage', 'Newimages' ),
99 'Listusers' => array( 'SpecialPage', 'Listusers' ),
100 'Listgrouprights' => 'SpecialListGroupRights',
101 'DeletedContributions' => 'DeletedContributionsPage',
102 'Statistics' => 'SpecialStatistics',
103 'Randompage' => 'Randompage',
104 'Lonelypages' => array( 'SpecialPage', 'Lonelypages' ),
105 'Uncategorizedpages' => array( 'SpecialPage', 'Uncategorizedpages' ),
106 'Uncategorizedcategories' => array( 'SpecialPage', 'Uncategorizedcategories' ),
107 'Uncategorizedimages' => array( 'SpecialPage', 'Uncategorizedimages' ),
108 'Uncategorizedtemplates' => array( 'SpecialPage', 'Uncategorizedtemplates' ),
109 'Unusedcategories' => array( 'SpecialPage', 'Unusedcategories' ),
110 'Unusedimages' => array( 'SpecialPage', 'Unusedimages' ),
111 'Wantedpages' => array( 'IncludableSpecialPage', 'Wantedpages' ),
112 'Wantedcategories' => array( 'SpecialPage', 'Wantedcategories' ),
113 'Wantedfiles' => array( 'SpecialPage', 'Wantedfiles' ),
114 'Wantedtemplates' => array( 'SpecialPage', 'Wantedtemplates' ),
115 'Mostlinked' => array( 'SpecialPage', 'Mostlinked' ),
116 'Mostlinkedcategories' => array( 'SpecialPage', 'Mostlinkedcategories' ),
117 'Mostlinkedtemplates' => array( 'SpecialPage', 'Mostlinkedtemplates' ),
118 'Mostcategories' => array( 'SpecialPage', 'Mostcategories' ),
119 'Mostimages' => array( 'SpecialPage', 'Mostimages' ),
120 'Mostrevisions' => array( 'SpecialPage', 'Mostrevisions' ),
121 'Fewestrevisions' => array( 'SpecialPage', 'Fewestrevisions' ),
122 'Shortpages' => array( 'SpecialPage', 'Shortpages' ),
123 'Longpages' => array( 'SpecialPage', 'Longpages' ),
124 'Newpages' => 'SpecialNewpages',
125 'Ancientpages' => array( 'SpecialPage', 'Ancientpages' ),
126 'Deadendpages' => array( 'SpecialPage', 'Deadendpages' ),
127 'Protectedpages' => array( 'SpecialPage', 'Protectedpages' ),
128 'Protectedtitles' => array( 'SpecialPage', 'Protectedtitles' ),
129 'Allpages' => 'SpecialAllpages',
130 'Prefixindex' => 'SpecialPrefixindex',
131 'Ipblocklist' => array( 'SpecialPage', 'Ipblocklist' ),
132 'ListUserRestrictions' => array( 'SpecialPage', 'ListUserRestrictions' ),
133 'RemoveRestrictions' => array( 'UnlistedSpecialPage', 'RemoveRestrictions', 'restrict' ),
134 'RestrictUser' => array( 'SpecialPage', 'RestrictUser', 'restrict' ),
135 'Specialpages' => array( 'UnlistedSpecialPage', 'Specialpages' ),
136 'Contributions' => 'SpecialContributions',
137 'Emailuser' => array( 'UnlistedSpecialPage', 'Emailuser' ),
138 'Whatlinkshere' => array( 'SpecialPage', 'Whatlinkshere' ),
139 'LinkSearch' => array( 'SpecialPage', 'LinkSearch' ),
140 'Recentchangeslinked' => 'SpecialRecentchangeslinked',
141 'Movepage' => array( 'UnlistedSpecialPage', 'Movepage' ),
142 'Blockme' => array( 'UnlistedSpecialPage', 'Blockme' ),
143 'Booksources' => 'SpecialBookSources',
144 'Categories' => array( 'SpecialPage', 'Categories' ),
145 'Export' => array( 'SpecialPage', 'Export' ),
146 'Version' => 'SpecialVersion',
147 'Blankpage' => array( 'UnlistedSpecialPage', 'Blankpage' ),
148 'Allmessages' => array( 'SpecialPage', 'Allmessages' ),
149 'Log' => array( 'SpecialPage', 'Log' ),
150 'Blockip' => array( 'SpecialPage', 'Blockip', 'block' ),
151 'Undelete' => array( 'SpecialPage', 'Undelete', 'deletedhistory' ),
152 'Import' => 'SpecialImport',
153 'Lockdb' => array( 'SpecialPage', 'Lockdb', 'siteadmin' ),
154 'Unlockdb' => array( 'SpecialPage', 'Unlockdb', 'siteadmin' ),
155 'Userrights' => 'UserrightsPage',
156 'MIMEsearch' => array( 'SpecialPage', 'MIMEsearch' ),
157 'FileDuplicateSearch' => array( 'SpecialPage', 'FileDuplicateSearch' ),
158 'Unwatchedpages' => array( 'SpecialPage', 'Unwatchedpages', 'unwatchedpages' ),
159 'Listredirects' => array( 'SpecialPage', 'Listredirects' ),
160 'Revisiondelete' => array( 'UnlistedSpecialPage', 'Revisiondelete', 'deleterevision' ),
161 'Unusedtemplates' => array( 'SpecialPage', 'Unusedtemplates' ),
162 'Randomredirect' => 'SpecialRandomredirect',
163 'Withoutinterwiki' => array( 'SpecialPage', 'Withoutinterwiki' ),
164 'Filepath' => array( 'SpecialPage', 'Filepath' ),
166 'Mypage' => array( 'SpecialMypage' ),
167 'Mytalk' => array( 'SpecialMytalk' ),
168 'Mycontributions' => array( 'SpecialMycontributions' ),
169 'Listadmins' => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
170 'MergeHistory' => array( 'SpecialPage', 'MergeHistory', 'mergehistory' ),
171 'Listbots' => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ),
174 static public $mAliases;
175 static public $mListInitialised = false;
177 /**#@-*/
180 * Initialise the special page list
181 * This must be called before accessing SpecialPage::$mList
183 static function initList() {
184 global $wgSpecialPages;
185 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
187 if ( self::$mListInitialised ) {
188 return;
190 wfProfileIn( __METHOD__ );
192 # Better to set this now, to avoid infinite recursion in carelessly written hooks
193 self::$mListInitialised = true;
195 if( !$wgDisableCounters ) {
196 self::$mList['Popularpages'] = array( 'SpecialPage', 'Popularpages' );
199 if( !$wgDisableInternalSearch ) {
200 self::$mList['Search'] = array( 'SpecialPage', 'Search' );
203 if( $wgEmailAuthentication ) {
204 self::$mList['Confirmemail'] = 'EmailConfirmation';
205 self::$mList['Invalidateemail'] = 'EmailInvalidation';
208 # Add extension special pages
209 self::$mList = array_merge( self::$mList, $wgSpecialPages );
211 # Run hooks
212 # This hook can be used to remove undesired built-in special pages
213 wfRunHooks( 'SpecialPage_initList', array( &self::$mList ) );
214 wfProfileOut( __METHOD__ );
217 static function initAliasList() {
218 if ( !is_null( self::$mAliases ) ) {
219 return;
222 global $wgContLang;
223 $aliases = $wgContLang->getSpecialPageAliases();
224 $missingPages = self::$mList;
225 self::$mAliases = array();
226 foreach ( $aliases as $realName => $aliasList ) {
227 foreach ( $aliasList as $alias ) {
228 self::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
230 unset( $missingPages[$realName] );
232 foreach ( $missingPages as $name => $stuff ) {
233 self::$mAliases[$wgContLang->caseFold( $name )] = $name;
238 * Given a special page alias, return the special page name.
239 * Returns false if there is no such alias.
241 static function resolveAlias( $alias ) {
242 global $wgContLang;
244 if ( !self::$mListInitialised ) self::initList();
245 if ( is_null( self::$mAliases ) ) self::initAliasList();
246 $caseFoldedAlias = $wgContLang->caseFold( $alias );
247 if ( isset( self::$mAliases[$caseFoldedAlias] ) ) {
248 return self::$mAliases[$caseFoldedAlias];
249 } else {
250 return false;
255 * Given a special page name with a possible subpage, return an array
256 * where the first element is the special page name and the second is the
257 * subpage.
259 static function resolveAliasWithSubpage( $alias ) {
260 $bits = explode( '/', $alias, 2 );
261 $name = self::resolveAlias( $bits[0] );
262 if( !isset( $bits[1] ) ) { // bug 2087
263 $par = NULL;
264 } else {
265 $par = $bits[1];
267 return array( $name, $par );
271 * Add a page to the list of valid special pages. This used to be the preferred
272 * method for adding special pages in extensions. It's now suggested that you add
273 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
275 * @param SpecialPage $page
276 * @static
278 static function addPage( &$page ) {
279 if ( !self::$mListInitialised ) {
280 self::initList();
282 self::$mList[$page->mName] = $page;
286 * Add a page to a certain display group for Special:SpecialPages
288 * @param mixed $page (SpecialPage or string)
289 * @param string $group
290 * @static
292 static function setGroup( $page, $group ) {
293 global $wgSpecialPageGroups;
294 $name = is_object($page) ? $page->mName : $page;
295 $wgSpecialPageGroups[$name] = $group;
299 * Add a page to a certain display group for Special:SpecialPages
301 * @param SpecialPage $page
302 * @static
304 static function getGroup( &$page ) {
305 global $wgSpecialPageGroups;
306 static $specialPageGroupsCache = array();
307 if( isset($specialPageGroupsCache[$page->mName]) ) {
308 return $specialPageGroupsCache[$page->mName];
310 $group = wfMsg('specialpages-specialpagegroup-'.strtolower($page->mName));
311 if( $group == ''
312 || wfEmptyMsg('specialpages-specialpagegroup-'.strtolower($page->mName), $group ) ) {
313 $group = isset($wgSpecialPageGroups[$page->mName])
314 ? $wgSpecialPageGroups[$page->mName]
315 : '-';
317 if( $group == '-' ) $group = 'other';
318 $specialPageGroupsCache[$page->mName] = $group;
319 return $group;
323 * Remove a special page from the list
324 * Formerly used to disable expensive or dangerous special pages. The
325 * preferred method is now to add a SpecialPage_initList hook.
327 * @static
329 static function removePage( $name ) {
330 if ( !self::$mListInitialised ) {
331 self::initList();
333 unset( self::$mList[$name] );
337 * Check if a given name exist as a special page or as a special page alias
338 * @param $name string: name of a special page
339 * @return boolean: true if a special page exists with this name
341 static function exists( $name ) {
342 global $wgContLang;
343 if ( !self::$mListInitialised ) {
344 self::initList();
346 if( !self::$mAliases ) {
347 self::initAliasList();
350 # Remove special pages inline parameters:
351 $bits = explode( '/', $name );
352 $name = $wgContLang->caseFold($bits[0]);
354 return
355 array_key_exists( $name, self::$mList )
356 or array_key_exists( $name, self::$mAliases )
361 * Find the object with a given name and return it (or NULL)
362 * @static
363 * @param string $name
365 static function getPage( $name ) {
366 if ( !self::$mListInitialised ) {
367 self::initList();
369 if ( array_key_exists( $name, self::$mList ) ) {
370 $rec = self::$mList[$name];
371 if ( is_string( $rec ) ) {
372 $className = $rec;
373 self::$mList[$name] = new $className;
374 } elseif ( is_array( $rec ) ) {
375 $className = array_shift( $rec );
376 self::$mList[$name] = wfCreateObject( $className, $rec );
378 return self::$mList[$name];
379 } else {
380 return NULL;
385 * Get a special page with a given localised name, or NULL if there
386 * is no such special page.
388 static function getPageByAlias( $alias ) {
389 $realName = self::resolveAlias( $alias );
390 if ( $realName ) {
391 return self::getPage( $realName );
392 } else {
393 return NULL;
398 * Return categorised listable special pages which are available
399 * for the current user, and everyone.
400 * @static
402 static function getUsablePages() {
403 global $wgUser;
404 if ( !self::$mListInitialised ) {
405 self::initList();
407 $pages = array();
409 foreach ( self::$mList as $name => $rec ) {
410 $page = self::getPage( $name );
411 if ( $page->isListed()
412 && (
413 !$page->isRestricted()
414 || $page->userCanExecute( $wgUser )
417 $pages[$name] = $page;
420 return $pages;
424 * Return categorised listable special pages for all users
425 * @static
427 static function getRegularPages() {
428 if ( !self::$mListInitialised ) {
429 self::initList();
431 $pages = array();
433 foreach ( self::$mList as $name => $rec ) {
434 $page = self::getPage( $name );
435 if ( $page->isListed() && !$page->isRestricted() ) {
436 $pages[$name] = $page;
439 return $pages;
443 * Return categorised listable special pages which are available
444 * for the current user, but not for everyone
445 * @static
447 static function getRestrictedPages() {
448 global $wgUser;
449 if( !self::$mListInitialised ) {
450 self::initList();
452 $pages = array();
454 foreach( self::$mList as $name => $rec ) {
455 $page = self::getPage( $name );
457 $page->isListed()
458 && $page->isRestricted()
459 && $page->userCanExecute( $wgUser )
461 $pages[$name] = $page;
464 return $pages;
468 * Execute a special page path.
469 * The path may contain parameters, e.g. Special:Name/Params
470 * Extracts the special page name and call the execute method, passing the parameters
472 * Returns a title object if the page is redirected, false if there was no such special
473 * page, and true if it was successful.
475 * @param $title a title object
476 * @param $including output is being captured for use in {{special:whatever}}
478 static function executePath( &$title, $including = false ) {
479 global $wgOut, $wgTitle, $wgRequest;
480 wfProfileIn( __METHOD__ );
482 # FIXME: redirects broken due to this call
483 $bits = explode( '/', $title->getDBkey(), 2 );
484 $name = $bits[0];
485 if( !isset( $bits[1] ) ) { // bug 2087
486 $par = NULL;
487 } else {
488 $par = $bits[1];
490 $page = SpecialPage::getPageByAlias( $name );
491 # Nonexistent?
492 if ( !$page ) {
493 if ( !$including ) {
494 $wgOut->setArticleRelated( false );
495 $wgOut->setRobotPolicy( 'noindex,nofollow' );
496 $wgOut->setStatusCode( 404 );
497 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
499 wfProfileOut( __METHOD__ );
500 return false;
503 # Check for redirect
504 if ( !$including ) {
505 $redirect = $page->getRedirect( $par );
506 if ( $redirect ) {
507 $query = $page->getRedirectQuery();
508 $url = $redirect->getFullUrl( $query );
509 $wgOut->redirect( $url );
510 wfProfileOut( __METHOD__ );
511 return $redirect;
515 # Redirect to canonical alias for GET commands
516 # Not for POST, we'd lose the post data, so it's best to just distribute
517 # the request. Such POST requests are possible for old extensions that
518 # generate self-links without being aware that their default name has
519 # changed.
520 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
521 $query = $_GET;
522 unset( $query['title'] );
523 $query = wfArrayToCGI( $query );
524 $title = $page->getTitle( $par );
525 $url = $title->getFullUrl( $query );
526 $wgOut->redirect( $url );
527 wfProfileOut( __METHOD__ );
528 return $redirect;
531 if ( $including && !$page->includable() ) {
532 wfProfileOut( __METHOD__ );
533 return false;
534 } elseif ( !$including ) {
535 $wgTitle = $page->getTitle();
537 $page->including( $including );
539 // Execute special page
540 $profName = 'Special:' . $page->getName();
541 wfProfileIn( $profName );
542 $page->execute( $par );
543 wfProfileOut( $profName );
544 wfProfileOut( __METHOD__ );
545 return true;
549 * Just like executePath() except it returns the HTML instead of outputting it
550 * Returns false if there was no such special page, or a title object if it was
551 * a redirect.
552 * @static
554 static function capturePath( &$title ) {
555 global $wgOut, $wgTitle;
557 $oldTitle = $wgTitle;
558 $oldOut = $wgOut;
559 $wgOut = new OutputPage;
561 $ret = SpecialPage::executePath( $title, true );
562 if ( $ret === true ) {
563 $ret = $wgOut->getHTML();
565 $wgTitle = $oldTitle;
566 $wgOut = $oldOut;
567 return $ret;
571 * Get the local name for a specified canonical name
573 * @param $name
574 * @param mixed $subpage Boolean false, or string
576 * @return string
578 static function getLocalNameFor( $name, $subpage = false ) {
579 global $wgContLang;
580 $aliases = $wgContLang->getSpecialPageAliases();
581 if ( isset( $aliases[$name][0] ) ) {
582 $name = $aliases[$name][0];
584 if ( $subpage !== false && !is_null( $subpage ) ) {
585 $name = "$name/$subpage";
587 return ucfirst( $name );
591 * Get a localised Title object for a specified special page name
593 static function getTitleFor( $name, $subpage = false ) {
594 $name = self::getLocalNameFor( $name, $subpage );
595 if ( $name ) {
596 return Title::makeTitle( NS_SPECIAL, $name );
597 } else {
598 throw new MWException( "Invalid special page name \"$name\"" );
603 * Get a localised Title object for a page name with a possibly unvalidated subpage
605 static function getSafeTitleFor( $name, $subpage = false ) {
606 $name = self::getLocalNameFor( $name, $subpage );
607 if ( $name ) {
608 return Title::makeTitleSafe( NS_SPECIAL, $name );
609 } else {
610 return null;
615 * Get a title for a given alias
616 * @return Title or null if there is no such alias
618 static function getTitleForAlias( $alias ) {
619 $name = self::resolveAlias( $alias );
620 if ( $name ) {
621 return self::getTitleFor( $name );
622 } else {
623 return null;
628 * Default constructor for special pages
629 * Derivative classes should call this from their constructor
630 * Note that if the user does not have the required level, an error message will
631 * be displayed by the default execute() method, without the global function ever
632 * being called.
634 * If you override execute(), you can recover the default behaviour with userCanExecute()
635 * and displayRestrictionError()
637 * @param string $name Name of the special page, as seen in links and URLs
638 * @param string $restriction User right required, e.g. "block" or "delete"
639 * @param boolean $listed Whether the page is listed in Special:Specialpages
640 * @param string $function Function called by execute(). By default it is constructed from $name
641 * @param string $file File which is included by execute(). It is also constructed from $name by default
643 function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
644 $this->mName = $name;
645 $this->mRestriction = $restriction;
646 $this->mListed = $listed;
647 $this->mIncludable = $includable;
648 if ( $function == false ) {
649 $this->mFunction = 'wfSpecial'.$name;
650 } else {
651 $this->mFunction = $function;
653 if ( $file === 'default' ) {
654 $this->mFile = dirname(__FILE__) . "/specials/Special$name.php";
655 } else {
656 $this->mFile = $file;
660 /**#@+
661 * Accessor
663 * @deprecated
665 function getName() { return $this->mName; }
666 function getRestriction() { return $this->mRestriction; }
667 function getFile() { return $this->mFile; }
668 function isListed() { return $this->mListed; }
669 /**#@-*/
671 /**#@+
672 * Accessor and mutator
674 function name( $x = NULL ) { return wfSetVar( $this->mName, $x ); }
675 function restrictions( $x = NULL) { return wfSetVar( $this->mRestrictions, $x ); }
676 function listed( $x = NULL) { return wfSetVar( $this->mListed, $x ); }
677 function func( $x = NULL) { return wfSetVar( $this->mFunction, $x ); }
678 function file( $x = NULL) { return wfSetVar( $this->mFile, $x ); }
679 function includable( $x = NULL ) { return wfSetVar( $this->mIncludable, $x ); }
680 function including( $x = NULL ) { return wfSetVar( $this->mIncluding, $x ); }
681 /**#@-*/
684 * Get the localised name of the special page
686 function getLocalName() {
687 if ( !isset( $this->mLocalName ) ) {
688 $this->mLocalName = self::getLocalNameFor( $this->mName );
690 return $this->mLocalName;
694 * Can be overridden by subclasses with more complicated permissions
695 * schemes.
697 * @return bool Should the page be displayed with the restricted-access
698 * pages?
700 public function isRestricted() {
701 return $this->mRestriction != '';
705 * Checks if the given user (identified by an object) can execute this
706 * special page (as defined by $mRestriction). Can be overridden by sub-
707 * classes with more complicated permissions schemes.
709 * @param User $user The user to check
710 * @return bool Does the user have permission to view the page?
712 public function userCanExecute( $user ) {
713 return $user->isAllowed( $this->mRestriction );
717 * Output an error message telling the user what access level they have to have
719 function displayRestrictionError() {
720 global $wgOut;
721 $wgOut->permissionRequired( $this->mRestriction );
725 * Sets headers - this should be called from the execute() method of all derived classes!
727 function setHeaders() {
728 global $wgOut;
729 $wgOut->setArticleRelated( false );
730 $wgOut->setRobotPolicy( "noindex,nofollow" );
731 $wgOut->setPageTitle( $this->getDescription() );
735 * Default execute method
736 * Checks user permissions, calls the function given in mFunction
738 * This may be overridden by subclasses.
740 function execute( $par ) {
741 global $wgUser;
743 $this->setHeaders();
745 if ( $this->userCanExecute( $wgUser ) ) {
746 $func = $this->mFunction;
747 // only load file if the function does not exist
748 if(!is_callable($func) and $this->mFile) {
749 require_once( $this->mFile );
751 $this->outputHeader();
752 call_user_func( $func, $par, $this );
753 } else {
754 $this->displayRestrictionError();
758 function outputHeader() {
759 global $wgOut, $wgContLang;
761 $msg = $wgContLang->lc( $this->name() ) . '-summary';
762 $out = wfMsgNoTrans( $msg );
763 if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() ) {
764 $wgOut->addWikiMsg( $msg );
769 # Returns the name that goes in the <h1> in the special page itself, and also the name that
770 # will be listed in Special:Specialpages
772 # Derived classes can override this, but usually it is easier to keep the default behaviour.
773 # Messages can be added at run-time, see MessageCache.php
774 function getDescription() {
775 return wfMsg( strtolower( $this->mName ) );
779 * Get a self-referential title object
781 function getTitle( $subpage = false) {
782 return self::getTitleFor( $this->mName, $subpage );
786 * Set whether this page is listed in Special:Specialpages, at run-time
788 function setListed( $listed ) {
789 return wfSetVar( $this->mListed, $listed );
793 * If the special page is a redirect, then get the Title object it redirects to.
794 * False otherwise.
796 function getRedirect( $subpage ) {
797 return false;
801 * Return part of the request string for a special redirect page
802 * This allows passing, e.g. action=history to Special:Mypage, etc.
804 * @return string
806 function getRedirectQuery() {
807 global $wgRequest;
808 $params = array();
809 foreach( $this->mAllowedRedirectParams as $arg ) {
810 if( $val = $wgRequest->getVal( $arg, false ) )
811 $params[] = $arg . '=' . $val;
814 return count( $params ) ? implode( '&', $params ) : false;
819 * Shortcut to construct a special page which is unlisted by default
820 * @ingroup SpecialPage
822 class UnlistedSpecialPage extends SpecialPage
824 function UnlistedSpecialPage( $name, $restriction = '', $function = false, $file = 'default' ) {
825 SpecialPage::SpecialPage( $name, $restriction, false, $function, $file );
830 * Shortcut to construct an includable special page
831 * @ingroup SpecialPage
833 class IncludableSpecialPage extends SpecialPage
835 function IncludableSpecialPage( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
836 SpecialPage::SpecialPage( $name, $restriction, $listed, $function, $file, true );
841 * Shortcut to construct a special page alias.
842 * @ingroup SpecialPage
844 class SpecialRedirectToSpecial extends UnlistedSpecialPage {
845 var $redirName, $redirSubpage;
847 function __construct( $name, $redirName, $redirSubpage = false, $redirectParams = array() ) {
848 parent::__construct( $name );
849 $this->redirName = $redirName;
850 $this->redirSubpage = $redirSubpage;
851 $this->mAllowedRedirectParams = $redirectParams;
854 function getRedirect( $subpage ) {
855 if ( $this->redirSubpage === false ) {
856 return SpecialPage::getTitleFor( $this->redirName, $subpage );
857 } else {
858 return SpecialPage::getTitleFor( $this->redirName, $this->redirSubpage );
863 /** SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
864 * are used to get user independant links pointing to the user page, talk
865 * page and list of contributions.
866 * This can let us cache a single copy of any generated content for all
867 * users.
871 * Shortcut to construct a special page pointing to current user user's page.
872 * @ingroup SpecialPage
874 class SpecialMypage extends UnlistedSpecialPage {
875 function __construct() {
876 parent::__construct( 'Mypage' );
877 $this->mAllowedRedirectParams = array( 'action' , 'preload' , 'editintro', 'section' );
880 function getRedirect( $subpage ) {
881 global $wgUser;
882 if ( strval( $subpage ) !== '' ) {
883 return Title::makeTitle( NS_USER, $wgUser->getName() . '/' . $subpage );
884 } else {
885 return Title::makeTitle( NS_USER, $wgUser->getName() );
891 * Shortcut to construct a special page pointing to current user talk page.
892 * @ingroup SpecialPage
894 class SpecialMytalk extends UnlistedSpecialPage {
895 function __construct() {
896 parent::__construct( 'Mytalk' );
897 $this->mAllowedRedirectParams = array( 'action' , 'preload' , 'editintro', 'section' );
900 function getRedirect( $subpage ) {
901 global $wgUser;
902 if ( strval( $subpage ) !== '' ) {
903 return Title::makeTitle( NS_USER_TALK, $wgUser->getName() . '/' . $subpage );
904 } else {
905 return Title::makeTitle( NS_USER_TALK, $wgUser->getName() );
911 * Shortcut to construct a special page pointing to current user contributions.
912 * @ingroup SpecialPage
914 class SpecialMycontributions extends UnlistedSpecialPage {
915 function __construct() {
916 parent::__construct( 'Mycontributions' );
919 function getRedirect( $subpage ) {
920 global $wgUser;
921 return SpecialPage::getTitleFor( 'Contributions', $wgUser->getName() );