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