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