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