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