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