convert "::1" and other pseudo-IPv6 addresses that Apache may throw at us to their...
[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 if ( $name ) {
479 return Title::makeTitle( NS_SPECIAL, $name );
480 } else {
481 throw new MWException( "Invalid special page name \"$name\"" );
482 }
483 }
484
485 /**
486 * Get a localised Title object for a page name with a possibly unvalidated subpage
487 */
488 static function getSafeTitleFor( $name, $subpage = false ) {
489 $name = self::getLocalNameFor( $name, $subpage );
490 if ( $name ) {
491 return Title::makeTitleSafe( NS_SPECIAL, $name );
492 } else {
493 return null;
494 }
495 }
496
497 /**
498 * Get a title for a given alias
499 * @return Title or null if there is no such alias
500 */
501 static function getTitleForAlias( $alias ) {
502 $name = self::resolveAlias( $alias );
503 if ( $name ) {
504 return self::getTitleFor( $name );
505 } else {
506 return null;
507 }
508 }
509
510 /**
511 * Default constructor for special pages
512 * Derivative classes should call this from their constructor
513 * Note that if the user does not have the required level, an error message will
514 * be displayed by the default execute() method, without the global function ever
515 * being called.
516 *
517 * If you override execute(), you can recover the default behaviour with userCanExecute()
518 * and displayRestrictionError()
519 *
520 * @param string $name Name of the special page, as seen in links and URLs
521 * @param string $restriction User right required, e.g. "block" or "delete"
522 * @param boolean $listed Whether the page is listed in Special:Specialpages
523 * @param string $function Function called by execute(). By default it is constructed from $name
524 * @param string $file File which is included by execute(). It is also constructed from $name by default
525 */
526 function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
527 $this->mName = $name;
528 $this->mRestriction = $restriction;
529 $this->mListed = $listed;
530 $this->mIncludable = $includable;
531 if ( $function == false ) {
532 $this->mFunction = 'wfSpecial'.$name;
533 } else {
534 $this->mFunction = $function;
535 }
536 if ( $file === 'default' ) {
537 $this->mFile = "Special{$name}.php";
538 } else {
539 $this->mFile = $file;
540 }
541 }
542
543 /**#@+
544 * Accessor
545 *
546 * @deprecated
547 */
548 function getName() { return $this->mName; }
549 function getRestriction() { return $this->mRestriction; }
550 function getFile() { return $this->mFile; }
551 function isListed() { return $this->mListed; }
552 /**#@-*/
553
554 /**#@+
555 * Accessor and mutator
556 */
557 function name( $x = NULL ) { return wfSetVar( $this->mName, $x ); }
558 function restrictions( $x = NULL) { return wfSetVar( $this->mRestrictions, $x ); }
559 function listed( $x = NULL) { return wfSetVar( $this->mListed, $x ); }
560 function func( $x = NULL) { return wfSetVar( $this->mFunction, $x ); }
561 function file( $x = NULL) { return wfSetVar( $this->mFile, $x ); }
562 function includable( $x = NULL ) { return wfSetVar( $this->mIncludable, $x ); }
563 function including( $x = NULL ) { return wfSetVar( $this->mIncluding, $x ); }
564 /**#@-*/
565
566 /**
567 * Get the localised name of the special page
568 */
569 function getLocalName() {
570 if ( !isset( $this->mLocalName ) ) {
571 $this->mLocalName = self::getLocalNameFor( $this->mName );
572 }
573 return $this->mLocalName;
574 }
575
576 /**
577 * Checks if the given user (identified by an object) can execute this
578 * special page (as defined by $mRestriction)
579 */
580 function userCanExecute( &$user ) {
581 return $user->isAllowed( $this->mRestriction );
582 }
583
584 /**
585 * Output an error message telling the user what access level they have to have
586 */
587 function displayRestrictionError() {
588 global $wgOut;
589 $wgOut->permissionRequired( $this->mRestriction );
590 }
591
592 /**
593 * Sets headers - this should be called from the execute() method of all derived classes!
594 */
595 function setHeaders() {
596 global $wgOut;
597 $wgOut->setArticleRelated( false );
598 $wgOut->setRobotPolicy( "noindex,nofollow" );
599 $wgOut->setPageTitle( $this->getDescription() );
600 }
601
602 /**
603 * Default execute method
604 * Checks user permissions, calls the function given in mFunction
605 *
606 * This may be overridden by subclasses.
607 */
608 function execute( $par ) {
609 global $wgUser;
610
611 $this->setHeaders();
612
613 if ( $this->userCanExecute( $wgUser ) ) {
614 $func = $this->mFunction;
615 // only load file if the function does not exist
616 if(!function_exists($func) and $this->mFile) {
617 require_once( $this->mFile );
618 }
619 # FIXME: these hooks are broken for extensions and anything else that subclasses SpecialPage.
620 if ( wfRunHooks( 'SpecialPageExecuteBeforeHeader', array( &$this, &$par, &$func ) ) )
621 $this->outputHeader();
622 if ( ! wfRunHooks( 'SpecialPageExecuteBeforePage', array( &$this, &$par, &$func ) ) )
623 return;
624 $func( $par, $this );
625 if ( ! wfRunHooks( 'SpecialPageExecuteAfterPage', array( &$this, &$par, &$func ) ) )
626 return;
627 } else {
628 $this->displayRestrictionError();
629 }
630 }
631
632 function outputHeader() {
633 global $wgOut, $wgContLang;
634
635 $msg = $wgContLang->lc( $this->name() ) . '-summary';
636 $out = wfMsg( $msg );
637 if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() )
638 $wgOut->addWikiText( $out );
639
640 }
641
642 # Returns the name that goes in the <h1> in the special page itself, and also the name that
643 # will be listed in Special:Specialpages
644 #
645 # Derived classes can override this, but usually it is easier to keep the default behaviour.
646 # Messages can be added at run-time, see MessageCache.php
647 function getDescription() {
648 return wfMsg( strtolower( $this->mName ) );
649 }
650
651 /**
652 * Get a self-referential title object
653 */
654 function getTitle( $subpage = false) {
655 return self::getTitleFor( $this->mName, $subpage );
656 }
657
658 /**
659 * Set whether this page is listed in Special:Specialpages, at run-time
660 */
661 function setListed( $listed ) {
662 return wfSetVar( $this->mListed, $listed );
663 }
664
665 /**
666 * If the special page is a redirect, then get the Title object it redirects to.
667 * False otherwise.
668 */
669 function getRedirect( $subpage = false ) {
670 return false;
671 }
672
673 /**
674 * Return part of the request string for a special redirect page
675 * This allows passing, e.g. action=history to Special:Mypage, etc.
676 *
677 * @return string
678 */
679 function getRedirectQuery() {
680 global $wgRequest;
681 $params = array();
682 foreach( $this->mAllowedRedirectParams as $arg ) {
683 if( $val = $wgRequest->getVal( $arg, false ) )
684 $params[] = $arg . '=' . $val;
685 }
686
687 return count( $params ) ? implode( '&', $params ) : false;
688 }
689 }
690
691 /**
692 * Shortcut to construct a special page which is unlisted by default
693 * @package MediaWiki
694 */
695 class UnlistedSpecialPage extends SpecialPage
696 {
697 function UnlistedSpecialPage( $name, $restriction = '', $function = false, $file = 'default' ) {
698 SpecialPage::SpecialPage( $name, $restriction, false, $function, $file );
699 }
700 }
701
702 /**
703 * Shortcut to construct an includable special page
704 * @package MediaWiki
705 */
706 class IncludableSpecialPage extends SpecialPage
707 {
708 function IncludableSpecialPage( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
709 SpecialPage::SpecialPage( $name, $restriction, $listed, $function, $file, true );
710 }
711 }
712
713 class SpecialRedirectToSpecial extends UnlistedSpecialPage {
714 var $redirName, $redirSubpage;
715
716 function __construct( $name, $redirName, $redirSubpage = false, $redirectParams = array() ) {
717 parent::__construct( $name );
718 $this->redirName = $redirName;
719 $this->redirSubpage = $redirSubpage;
720 $this->mAllowedRedirectParams = $redirectParams;
721 }
722
723 function getRedirect( $subpage ) {
724 if ( $this->redirSubpage === false ) {
725 return SpecialPage::getTitleFor( $this->redirName, $subpage );
726 } else {
727 return SpecialPage::getTitleFor( $this->redirName, $this->redirSubpage );
728 }
729 }
730 }
731
732 class SpecialMypage extends UnlistedSpecialPage {
733 function __construct() {
734 parent::__construct( 'Mypage' );
735 $this->mAllowedRedirectParams = array( 'action' );
736 }
737
738 function getRedirect( $subpage ) {
739 global $wgUser;
740 if ( strval( $subpage ) !== '' ) {
741 return Title::makeTitle( NS_USER, $wgUser->getName() . '/' . $subpage );
742 } else {
743 return Title::makeTitle( NS_USER, $wgUser->getName() );
744 }
745 }
746 }
747
748 class SpecialMytalk extends UnlistedSpecialPage {
749 function __construct() {
750 parent::__construct( 'Mytalk' );
751 $this->mAllowedRedirectParams = array( 'action' );
752 }
753
754 function getRedirect( $subpage ) {
755 global $wgUser;
756 if ( strval( $subpage ) !== '' ) {
757 return Title::makeTitle( NS_USER_TALK, $wgUser->getName() . '/' . $subpage );
758 } else {
759 return Title::makeTitle( NS_USER_TALK, $wgUser->getName() );
760 }
761 }
762 }
763
764 class SpecialMycontributions extends UnlistedSpecialPage {
765 function __construct() {
766 parent::__construct( 'Mycontributions' );
767 }
768
769 function getRedirect( $subpage ) {
770 global $wgUser;
771 return SpecialPage::getTitleFor( 'Contributions', $wgUser->getName() );
772 }
773 }
774
775 ?>