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