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