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