Added EditFilterMerged hook: like EditFilter but uses the text after section merging...
[lhc/web/wiklou.git] / includes / SpecialPage.php
1 <?php
2 /**
3 * SpecialPage: handling special pages and lists thereof.
4 *
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.
8 *
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.
15 *
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.
19 *
20 * @addtogroup SpecialPage
21 */
22
23 /**
24 * @access private
25 */
26
27 /**
28 * Parent special page class, also static functions for handling the special
29 * page list.
30 * @addtogroup SpecialPage
31 */
32 class SpecialPage
33 {
34 /**#@+
35 * @access private
36 */
37 /**
38 * The canonical name of this special page
39 * Also used for the default <h1> heading, @see getDescription()
40 */
41 var $mName;
42 /**
43 * The local name of this special page
44 */
45 var $mLocalName;
46 /**
47 * Minimum user level required to access this page, or "" for anyone.
48 * Also used to categorise the pages in Special:Specialpages
49 */
50 var $mRestriction;
51 /**
52 * Listed in Special:Specialpages?
53 */
54 var $mListed;
55 /**
56 * Function name called by the default execute()
57 */
58 var $mFunction;
59 /**
60 * File which needs to be included before the function above can be called
61 */
62 var $mFile;
63 /**
64 * Whether or not this special page is being included from an article
65 */
66 var $mIncluding;
67 /**
68 * Whether the special page can be included in an article
69 */
70 var $mIncludable;
71 /**
72 * Query parameters that can be passed through redirects
73 */
74 var $mAllowedRedirectParams = array();
75
76 static public $mList = array(
77 'DoubleRedirects' => array( 'SpecialPage', 'DoubleRedirects' ),
78 'BrokenRedirects' => array( 'SpecialPage', 'BrokenRedirects' ),
79 'Disambiguations' => array( 'SpecialPage', 'Disambiguations' ),
80
81 'Userlogin' => array( 'SpecialPage', 'Userlogin' ),
82 'Userlogout' => array( 'UnlistedSpecialPage', 'Userlogout' ),
83 'Preferences' => array( 'SpecialPage', 'Preferences' ),
84 'Watchlist' => array( 'SpecialPage', 'Watchlist' ),
85
86 'Recentchanges' => array( 'IncludableSpecialPage', 'Recentchanges' ),
87 'Upload' => array( 'SpecialPage', 'Upload' ),
88 'Imagelist' => array( 'SpecialPage', 'Imagelist' ),
89 'Newimages' => array( 'IncludableSpecialPage', 'Newimages' ),
90 'Listusers' => array( 'SpecialPage', 'Listusers' ),
91 'Statistics' => array( 'SpecialPage', 'Statistics' ),
92 'Randompage' => array( 'SpecialPage', 'Randompage' ),
93 'Randomincategory' => array( 'SpecialPage', 'Randomincategory' ),
94 'Lonelypages' => array( 'SpecialPage', 'Lonelypages' ),
95 'Uncategorizedpages' => array( 'SpecialPage', 'Uncategorizedpages' ),
96 'Uncategorizedcategories' => array( 'SpecialPage', 'Uncategorizedcategories' ),
97 'Uncategorizedimages' => array( 'SpecialPage', 'Uncategorizedimages' ),
98 'Uncategorizedtemplates' => array( 'SpecialPage', 'Uncategorizedtemplates' ),
99 'Unusedcategories' => array( 'SpecialPage', 'Unusedcategories' ),
100 'Unusedimages' => array( 'SpecialPage', 'Unusedimages' ),
101 'Wantedpages' => array( 'IncludableSpecialPage', 'Wantedpages' ),
102 'Wantedcategories' => array( 'SpecialPage', 'Wantedcategories' ),
103 'Mostlinked' => array( 'SpecialPage', 'Mostlinked' ),
104 'Mostlinkedcategories' => array( 'SpecialPage', 'Mostlinkedcategories' ),
105 'Mostlinkedtemplates' => array( 'SpecialPage', 'Mostlinkedtemplates' ),
106 'Mostcategories' => array( 'SpecialPage', 'Mostcategories' ),
107 'Mostimages' => array( 'SpecialPage', 'Mostimages' ),
108 'Mostrevisions' => array( 'SpecialPage', 'Mostrevisions' ),
109 'Fewestrevisions' => array( 'SpecialPage', 'Fewestrevisions' ),
110 'Shortpages' => array( 'SpecialPage', 'Shortpages' ),
111 'Longpages' => array( 'SpecialPage', 'Longpages' ),
112 'Newpages' => array( 'IncludableSpecialPage', 'Newpages' ),
113 'Ancientpages' => array( 'SpecialPage', 'Ancientpages' ),
114 'Deadendpages' => array( 'SpecialPage', 'Deadendpages' ),
115 'Protectedpages' => array( 'SpecialPage', 'Protectedpages' ),
116 'Allpages' => array( 'IncludableSpecialPage', 'Allpages' ),
117 'Prefixindex' => array( 'IncludableSpecialPage', 'Prefixindex' ) ,
118 'Ipblocklist' => array( 'SpecialPage', 'Ipblocklist' ),
119 'Specialpages' => array( 'UnlistedSpecialPage', 'Specialpages' ),
120 'Contributions' => array( 'SpecialPage', 'Contributions' ),
121 'Emailuser' => array( 'UnlistedSpecialPage', 'Emailuser' ),
122 'Whatlinkshere' => array( 'SpecialPage', 'Whatlinkshere' ),
123 'Recentchangeslinked' => array( 'UnlistedSpecialPage', 'Recentchangeslinked' ),
124 'Movepage' => array( 'UnlistedSpecialPage', 'Movepage' ),
125 'Blockme' => array( 'UnlistedSpecialPage', 'Blockme' ),
126 'Resetpass' => array( 'UnlistedSpecialPage', 'Resetpass' ),
127 'Booksources' => 'SpecialBookSources',
128 'Categories' => array( 'SpecialPage', 'Categories' ),
129 'Export' => array( 'SpecialPage', 'Export' ),
130 'Version' => array( 'SpecialPage', 'Version' ),
131 'Allmessages' => array( 'SpecialPage', 'Allmessages' ),
132 'Log' => array( 'SpecialPage', 'Log' ),
133 'Blockip' => array( 'SpecialPage', 'Blockip', 'block' ),
134 'Undelete' => array( 'SpecialPage', 'Undelete', 'deletedhistory' ),
135 'Import' => array( 'SpecialPage', "Import", 'import' ),
136 'Lockdb' => array( 'SpecialPage', 'Lockdb', 'siteadmin' ),
137 'Unlockdb' => array( 'SpecialPage', 'Unlockdb', 'siteadmin' ),
138 'Userrights' => array( 'SpecialPage', 'Userrights', 'userrights' ),
139 'MIMEsearch' => array( 'SpecialPage', 'MIMEsearch' ),
140 'Unwatchedpages' => array( 'SpecialPage', 'Unwatchedpages', 'unwatchedpages' ),
141 'Listredirects' => array( 'SpecialPage', 'Listredirects' ),
142 'Revisiondelete' => array( 'SpecialPage', 'Revisiondelete', 'deleterevision' ),
143 'Unusedtemplates' => array( 'SpecialPage', 'Unusedtemplates' ),
144 'Randomredirect' => array( 'SpecialPage', 'Randomredirect' ),
145 'Withoutinterwiki' => array( 'SpecialPage', 'Withoutinterwiki' ),
146
147 'Mypage' => array( 'SpecialMypage' ),
148 'Mytalk' => array( 'SpecialMytalk' ),
149 'Mycontributions' => array( 'SpecialMycontributions' ),
150 'Listadmins' => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
151 );
152
153 static public $mAliases;
154 static public $mListInitialised = false;
155
156 /**#@-*/
157
158 /**
159 * Initialise the special page list
160 * This must be called before accessing SpecialPage::$mList
161 */
162 static function initList() {
163 global $wgSpecialPages;
164 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
165
166 if ( self::$mListInitialised ) {
167 return;
168 }
169 wfProfileIn( __METHOD__ );
170
171 # Better to set this now, to avoid infinite recursion in carelessly written hooks
172 self::$mListInitialised = true;
173
174 if( !$wgDisableCounters ) {
175 self::$mList['Popularpages'] = array( 'SpecialPage', 'Popularpages' );
176 }
177
178 if( !$wgDisableInternalSearch ) {
179 self::$mList['Search'] = array( 'SpecialPage', 'Search' );
180 }
181
182 if( $wgEmailAuthentication ) {
183 self::$mList['Confirmemail'] = 'EmailConfirmation';
184 }
185
186 # Add extension special pages
187 self::$mList = array_merge( self::$mList, $wgSpecialPages );
188
189 # Run hooks
190 # This hook can be used to remove undesired built-in special pages
191 wfRunHooks( 'SpecialPage_initList', array( &self::$mList ) );
192 wfProfileOut( __METHOD__ );
193 }
194
195 static function initAliasList() {
196 if ( !is_null( self::$mAliases ) ) {
197 return;
198 }
199
200 global $wgContLang;
201 $aliases = $wgContLang->getSpecialPageAliases();
202 $missingPages = self::$mList;
203 self::$mAliases = array();
204 foreach ( $aliases as $realName => $aliasList ) {
205 foreach ( $aliasList as $alias ) {
206 self::$mAliases[$wgContLang->caseFold( $alias )] = $realName;
207 }
208 unset( $missingPages[$realName] );
209 }
210 foreach ( $missingPages as $name => $stuff ) {
211 self::$mAliases[$wgContLang->caseFold( $name )] = $name;
212 }
213 }
214
215 /**
216 * Given a special page alias, return the special page name.
217 * Returns false if there is no such alias.
218 */
219 static function resolveAlias( $alias ) {
220 global $wgContLang;
221
222 if ( !self::$mListInitialised ) self::initList();
223 if ( is_null( self::$mAliases ) ) self::initAliasList();
224 $caseFoldedAlias = $wgContLang->caseFold( $alias );
225 if ( isset( self::$mAliases[$caseFoldedAlias] ) ) {
226 return self::$mAliases[$caseFoldedAlias];
227 } else {
228 return false;
229 }
230 }
231
232 /**
233 * Given a special page name with a possible subpage, return an array
234 * where the first element is the special page name and the second is the
235 * subpage.
236 */
237 static function resolveAliasWithSubpage( $alias ) {
238 $bits = explode( '/', $alias, 2 );
239 $name = self::resolveAlias( $bits[0] );
240 if( !isset( $bits[1] ) ) { // bug 2087
241 $par = NULL;
242 } else {
243 $par = $bits[1];
244 }
245 return array( $name, $par );
246 }
247
248 /**
249 * Add a page to the list of valid special pages. This used to be the preferred
250 * method for adding special pages in extensions. It's now suggested that you add
251 * an associative record to $wgSpecialPages. This avoids autoloading SpecialPage.
252 *
253 * @param mixed $page Must either be an array specifying a class name and
254 * constructor parameters, or an object. The object,
255 * when constructed, must have an execute() method which
256 * sends HTML to $wgOut.
257 * @static
258 */
259 static function addPage( &$page ) {
260 if ( !self::$mListInitialised ) {
261 self::initList();
262 }
263 self::$mList[$page->mName] = $page;
264 }
265
266 /**
267 * Remove a special page from the list
268 * Formerly used to disable expensive or dangerous special pages. The
269 * preferred method is now to add a SpecialPage_initList hook.
270 *
271 * @static
272 */
273 static function removePage( $name ) {
274 if ( !self::$mListInitialised ) {
275 self::initList();
276 }
277 unset( self::$mList[$name] );
278 }
279
280 /**
281 * Check if a given name exist as a special page or as a special page alias
282 * @param $name string: name of a special page
283 * @return boolean: true if a special page exists with this name
284 */
285 static function exists( $name ) {
286 global $wgContLang;
287 if ( !self::$mListInitialised ) {
288 self::initList();
289 }
290 if( !self::$mAliases ) {
291 self::initAliasList();
292 }
293
294 # Remove special pages inline parameters:
295 $bits = explode( '/', $name );
296 $name = $wgContLang->caseFold($bits[0]);
297
298 return
299 array_key_exists( $name, self::$mList )
300 or array_key_exists( $name, self::$mAliases )
301 ;
302 }
303
304 /**
305 * Find the object with a given name and return it (or NULL)
306 * @static
307 * @param string $name
308 */
309 static function getPage( $name ) {
310 if ( !self::$mListInitialised ) {
311 self::initList();
312 }
313 if ( array_key_exists( $name, self::$mList ) ) {
314 $rec = self::$mList[$name];
315 if ( is_string( $rec ) ) {
316 $className = $rec;
317 self::$mList[$name] = new $className;
318 } elseif ( is_array( $rec ) ) {
319 $className = array_shift( $rec );
320 self::$mList[$name] = wfCreateObject( $className, $rec );
321 }
322 return self::$mList[$name];
323 } else {
324 return NULL;
325 }
326 }
327
328 /**
329 * Get a special page with a given localised name, or NULL if there
330 * is no such special page.
331 */
332 static function getPageByAlias( $alias ) {
333 $realName = self::resolveAlias( $alias );
334 if ( $realName ) {
335 return self::getPage( $realName );
336 } else {
337 return NULL;
338 }
339 }
340
341 /**
342 * Return categorised listable special pages for all users
343 * @static
344 */
345 static function getRegularPages() {
346 if ( !self::$mListInitialised ) {
347 self::initList();
348 }
349 $pages = array();
350
351 foreach ( self::$mList as $name => $rec ) {
352 $page = self::getPage( $name );
353 if ( $page->isListed() && $page->getRestriction() == '' ) {
354 $pages[$name] = $page;
355 }
356 }
357 return $pages;
358 }
359
360 /**
361 * Return categorised listable special pages which are available
362 * for the current user, but not for everyone
363 * @static
364 */
365 static function getRestrictedPages() {
366 global $wgUser;
367 if ( !self::$mListInitialised ) {
368 self::initList();
369 }
370 $pages = array();
371
372 foreach ( self::$mList as $name => $rec ) {
373 $page = self::getPage( $name );
374 if ( $page->isListed() ) {
375 $restriction = $page->getRestriction();
376 if ( $restriction != '' && $wgUser->isAllowed( $restriction ) ) {
377 $pages[$name] = $page;
378 }
379 }
380 }
381 return $pages;
382 }
383
384 /**
385 * Execute a special page path.
386 * The path may contain parameters, e.g. Special:Name/Params
387 * Extracts the special page name and call the execute method, passing the parameters
388 *
389 * Returns a title object if the page is redirected, false if there was no such special
390 * page, and true if it was successful.
391 *
392 * @param $title a title object
393 * @param $including output is being captured for use in {{special:whatever}}
394 */
395 static function executePath( &$title, $including = false ) {
396 global $wgOut, $wgTitle, $wgRequest;
397 wfProfileIn( __METHOD__ );
398
399 # FIXME: redirects broken due to this call
400 $bits = explode( '/', $title->getDBkey(), 2 );
401 $name = $bits[0];
402 if( !isset( $bits[1] ) ) { // bug 2087
403 $par = NULL;
404 } else {
405 $par = $bits[1];
406 }
407 $page = SpecialPage::getPageByAlias( $name );
408
409 # Nonexistent?
410 if ( !$page ) {
411 if ( !$including ) {
412 $wgOut->setArticleRelated( false );
413 $wgOut->setRobotpolicy( 'noindex,nofollow' );
414 $wgOut->setStatusCode( 404 );
415 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
416 }
417 wfProfileOut( __METHOD__ );
418 return false;
419 }
420
421 # Check for redirect
422 if ( !$including ) {
423 $redirect = $page->getRedirect( $par );
424 if ( $redirect ) {
425 $query = $page->getRedirectQuery();
426 $url = $redirect->getFullUrl( $query );
427 $wgOut->redirect( $url );
428 wfProfileOut( __METHOD__ );
429 return $redirect;
430 }
431 }
432
433 # Redirect to canonical alias for GET commands
434 # Not for POST, we'd lose the post data, so it's best to just distribute
435 # the request. Such POST requests are possible for old extensions that
436 # generate self-links without being aware that their default name has
437 # changed.
438 if ( !$including && $name != $page->getLocalName() && !$wgRequest->wasPosted() ) {
439 $query = $_GET;
440 unset( $query['title'] );
441 $query = wfArrayToCGI( $query );
442 $title = $page->getTitle( $par );
443 $url = $title->getFullUrl( $query );
444 $wgOut->redirect( $url );
445 wfProfileOut( __METHOD__ );
446 return $redirect;
447 }
448
449 if ( $including && !$page->includable() ) {
450 wfProfileOut( __METHOD__ );
451 return false;
452 } elseif ( !$including ) {
453 $wgTitle = $page->getTitle();
454 }
455 $page->including( $including );
456
457 // Execute special page
458 $profName = 'Special:' . $page->getName();
459 wfProfileIn( $profName );
460 $page->execute( $par );
461 wfProfileOut( $profName );
462 wfProfileOut( __METHOD__ );
463 return true;
464 }
465
466 /**
467 * Just like executePath() except it returns the HTML instead of outputting it
468 * Returns false if there was no such special page, or a title object if it was
469 * a redirect.
470 * @static
471 */
472 static function capturePath( &$title ) {
473 global $wgOut, $wgTitle;
474
475 $oldTitle = $wgTitle;
476 $oldOut = $wgOut;
477 $wgOut = new OutputPage;
478
479 $ret = SpecialPage::executePath( $title, true );
480 if ( $ret === true ) {
481 $ret = $wgOut->getHTML();
482 }
483 $wgTitle = $oldTitle;
484 $wgOut = $oldOut;
485 return $ret;
486 }
487
488 /**
489 * Get the local name for a specified canonical name
490 */
491 static function getLocalNameFor( $name, $subpage = false ) {
492 global $wgContLang;
493 $aliases = $wgContLang->getSpecialPageAliases();
494 if ( isset( $aliases[$name][0] ) ) {
495 $name = $aliases[$name][0];
496 }
497 if ( $subpage !== false && !is_null( $subpage ) ) {
498 $name = "$name/$subpage";
499 }
500 return $name;
501 }
502
503 /**
504 * Get a localised Title object for a specified special page name
505 */
506 static function getTitleFor( $name, $subpage = false ) {
507 $name = self::getLocalNameFor( $name, $subpage );
508 if ( $name ) {
509 return Title::makeTitle( NS_SPECIAL, $name );
510 } else {
511 throw new MWException( "Invalid special page name \"$name\"" );
512 }
513 }
514
515 /**
516 * Get a localised Title object for a page name with a possibly unvalidated subpage
517 */
518 static function getSafeTitleFor( $name, $subpage = false ) {
519 $name = self::getLocalNameFor( $name, $subpage );
520 if ( $name ) {
521 return Title::makeTitleSafe( NS_SPECIAL, $name );
522 } else {
523 return null;
524 }
525 }
526
527 /**
528 * Get a title for a given alias
529 * @return Title or null if there is no such alias
530 */
531 static function getTitleForAlias( $alias ) {
532 $name = self::resolveAlias( $alias );
533 if ( $name ) {
534 return self::getTitleFor( $name );
535 } else {
536 return null;
537 }
538 }
539
540 /**
541 * Default constructor for special pages
542 * Derivative classes should call this from their constructor
543 * Note that if the user does not have the required level, an error message will
544 * be displayed by the default execute() method, without the global function ever
545 * being called.
546 *
547 * If you override execute(), you can recover the default behaviour with userCanExecute()
548 * and displayRestrictionError()
549 *
550 * @param string $name Name of the special page, as seen in links and URLs
551 * @param string $restriction User right required, e.g. "block" or "delete"
552 * @param boolean $listed Whether the page is listed in Special:Specialpages
553 * @param string $function Function called by execute(). By default it is constructed from $name
554 * @param string $file File which is included by execute(). It is also constructed from $name by default
555 */
556 function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
557 $this->mName = $name;
558 $this->mRestriction = $restriction;
559 $this->mListed = $listed;
560 $this->mIncludable = $includable;
561 if ( $function == false ) {
562 $this->mFunction = 'wfSpecial'.$name;
563 } else {
564 $this->mFunction = $function;
565 }
566 if ( $file === 'default' ) {
567 $this->mFile = dirname(__FILE__) . "/Special{$name}.php";
568 } else {
569 $this->mFile = $file;
570 }
571 }
572
573 /**#@+
574 * Accessor
575 *
576 * @deprecated
577 */
578 function getName() { return $this->mName; }
579 function getRestriction() { return $this->mRestriction; }
580 function getFile() { return $this->mFile; }
581 function isListed() { return $this->mListed; }
582 /**#@-*/
583
584 /**#@+
585 * Accessor and mutator
586 */
587 function name( $x = NULL ) { return wfSetVar( $this->mName, $x ); }
588 function restrictions( $x = NULL) { return wfSetVar( $this->mRestrictions, $x ); }
589 function listed( $x = NULL) { return wfSetVar( $this->mListed, $x ); }
590 function func( $x = NULL) { return wfSetVar( $this->mFunction, $x ); }
591 function file( $x = NULL) { return wfSetVar( $this->mFile, $x ); }
592 function includable( $x = NULL ) { return wfSetVar( $this->mIncludable, $x ); }
593 function including( $x = NULL ) { return wfSetVar( $this->mIncluding, $x ); }
594 /**#@-*/
595
596 /**
597 * Get the localised name of the special page
598 */
599 function getLocalName() {
600 if ( !isset( $this->mLocalName ) ) {
601 $this->mLocalName = self::getLocalNameFor( $this->mName );
602 }
603 return $this->mLocalName;
604 }
605
606 /**
607 * Checks if the given user (identified by an object) can execute this
608 * special page (as defined by $mRestriction)
609 */
610 function userCanExecute( &$user ) {
611 return $user->isAllowed( $this->mRestriction );
612 }
613
614 /**
615 * Output an error message telling the user what access level they have to have
616 */
617 function displayRestrictionError() {
618 global $wgOut;
619 $wgOut->permissionRequired( $this->mRestriction );
620 }
621
622 /**
623 * Sets headers - this should be called from the execute() method of all derived classes!
624 */
625 function setHeaders() {
626 global $wgOut;
627 $wgOut->setArticleRelated( false );
628 $wgOut->setRobotPolicy( "noindex,nofollow" );
629 $wgOut->setPageTitle( $this->getDescription() );
630 }
631
632 /**
633 * Default execute method
634 * Checks user permissions, calls the function given in mFunction
635 *
636 * This may be overridden by subclasses.
637 */
638 function execute( $par ) {
639 global $wgUser;
640
641 $this->setHeaders();
642
643 if ( $this->userCanExecute( $wgUser ) ) {
644 $func = $this->mFunction;
645 // only load file if the function does not exist
646 if(!function_exists($func) and $this->mFile) {
647 require_once( $this->mFile );
648 }
649 # FIXME: these hooks are broken for extensions and anything else that subclasses SpecialPage.
650 if ( wfRunHooks( 'SpecialPageExecuteBeforeHeader', array( &$this, &$par, &$func ) ) )
651 $this->outputHeader();
652 if ( ! wfRunHooks( 'SpecialPageExecuteBeforePage', array( &$this, &$par, &$func ) ) )
653 return;
654 $func( $par, $this );
655 if ( ! wfRunHooks( 'SpecialPageExecuteAfterPage', array( &$this, &$par, &$func ) ) )
656 return;
657 } else {
658 $this->displayRestrictionError();
659 }
660 }
661
662 function outputHeader() {
663 global $wgOut, $wgContLang;
664
665 $msg = $wgContLang->lc( $this->name() ) . '-summary';
666 $out = wfMsg( $msg );
667 if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() )
668 $wgOut->addWikiText( $out );
669
670 }
671
672 # Returns the name that goes in the <h1> in the special page itself, and also the name that
673 # will be listed in Special:Specialpages
674 #
675 # Derived classes can override this, but usually it is easier to keep the default behaviour.
676 # Messages can be added at run-time, see MessageCache.php
677 function getDescription() {
678 return wfMsg( strtolower( $this->mName ) );
679 }
680
681 /**
682 * Get a self-referential title object
683 */
684 function getTitle( $subpage = false) {
685 return self::getTitleFor( $this->mName, $subpage );
686 }
687
688 /**
689 * Set whether this page is listed in Special:Specialpages, at run-time
690 */
691 function setListed( $listed ) {
692 return wfSetVar( $this->mListed, $listed );
693 }
694
695 /**
696 * If the special page is a redirect, then get the Title object it redirects to.
697 * False otherwise.
698 */
699 function getRedirect( $subpage ) {
700 return false;
701 }
702
703 /**
704 * Return part of the request string for a special redirect page
705 * This allows passing, e.g. action=history to Special:Mypage, etc.
706 *
707 * @return string
708 */
709 function getRedirectQuery() {
710 global $wgRequest;
711 $params = array();
712 foreach( $this->mAllowedRedirectParams as $arg ) {
713 if( $val = $wgRequest->getVal( $arg, false ) )
714 $params[] = $arg . '=' . $val;
715 }
716
717 return count( $params ) ? implode( '&', $params ) : false;
718 }
719 }
720
721 /**
722 * Shortcut to construct a special page which is unlisted by default
723 * @addtogroup SpecialPage
724 */
725 class UnlistedSpecialPage extends SpecialPage
726 {
727 function UnlistedSpecialPage( $name, $restriction = '', $function = false, $file = 'default' ) {
728 SpecialPage::SpecialPage( $name, $restriction, false, $function, $file );
729 }
730 }
731
732 /**
733 * Shortcut to construct an includable special page
734 * @addtogroup SpecialPage
735 */
736 class IncludableSpecialPage extends SpecialPage
737 {
738 function IncludableSpecialPage( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
739 SpecialPage::SpecialPage( $name, $restriction, $listed, $function, $file, true );
740 }
741 }
742
743 /**
744 * Shortcut to construct a special page alias.
745 * @addtogroup SpecialPage
746 */
747 class SpecialRedirectToSpecial extends UnlistedSpecialPage {
748 var $redirName, $redirSubpage;
749
750 function __construct( $name, $redirName, $redirSubpage = false, $redirectParams = array() ) {
751 parent::__construct( $name );
752 $this->redirName = $redirName;
753 $this->redirSubpage = $redirSubpage;
754 $this->mAllowedRedirectParams = $redirectParams;
755 }
756
757 function getRedirect( $subpage ) {
758 if ( $this->redirSubpage === false ) {
759 return SpecialPage::getTitleFor( $this->redirName, $subpage );
760 } else {
761 return SpecialPage::getTitleFor( $this->redirName, $this->redirSubpage );
762 }
763 }
764 }
765
766 /** SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
767 * are used to get user independant links pointing to the user page, talk
768 * page and list of contributions.
769 * This can let us cache a single copy of any generated content for all
770 * users.
771 */
772
773 /**
774 * Shortcut to construct a special page pointing to current user user's page.
775 * @addtogroup SpecialPage
776 */
777 class SpecialMypage extends UnlistedSpecialPage {
778 function __construct() {
779 parent::__construct( 'Mypage' );
780 $this->mAllowedRedirectParams = array( 'action' , 'preload' , 'editintro' );
781 }
782
783 function getRedirect( $subpage ) {
784 global $wgUser;
785 if ( strval( $subpage ) !== '' ) {
786 return Title::makeTitle( NS_USER, $wgUser->getName() . '/' . $subpage );
787 } else {
788 return Title::makeTitle( NS_USER, $wgUser->getName() );
789 }
790 }
791 }
792
793 /**
794 * Shortcut to construct a special page pointing to current user talk page.
795 * @addtogroup SpecialPage
796 */
797 class SpecialMytalk extends UnlistedSpecialPage {
798 function __construct() {
799 parent::__construct( 'Mytalk' );
800 $this->mAllowedRedirectParams = array( 'action' , 'preload' , 'editintro' );
801 }
802
803 function getRedirect( $subpage ) {
804 global $wgUser;
805 if ( strval( $subpage ) !== '' ) {
806 return Title::makeTitle( NS_USER_TALK, $wgUser->getName() . '/' . $subpage );
807 } else {
808 return Title::makeTitle( NS_USER_TALK, $wgUser->getName() );
809 }
810 }
811 }
812
813 /**
814 * Shortcut to construct a special page pointing to current user contributions.
815 * @addtogroup SpecialPage
816 */
817 class SpecialMycontributions extends UnlistedSpecialPage {
818 function __construct() {
819 parent::__construct( 'Mycontributions' );
820 }
821
822 function getRedirect( $subpage ) {
823 global $wgUser;
824 return SpecialPage::getTitleFor( 'Contributions', $wgUser->getName() );
825 }
826 }