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