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