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