(bug 13454) Article::updateCategoryCounts can attempt to execute empty inserts.
[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 }
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->isRestricted() ) {
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 (
376 $page->isListed()
377 and $page->isRestricted()
378 and $page->userCanExecute( $wgUser )
379 ) {
380 $pages[$name] = $page;
381 }
382 }
383 return $pages;
384 }
385
386 /**
387 * Execute a special page path.
388 * The path may contain parameters, e.g. Special:Name/Params
389 * Extracts the special page name and call the execute method, passing the parameters
390 *
391 * Returns a title object if the page is redirected, false if there was no such special
392 * page, and true if it was successful.
393 *
394 * @param $title a title object
395 * @param $including output is being captured for use in {{special:whatever}}
396 */
397 static function executePath( &$title, $including = false ) {
398 global $wgOut, $wgTitle, $wgRequest;
399 wfProfileIn( __METHOD__ );
400
401 # FIXME: redirects broken due to this call
402 $bits = explode( '/', $title->getDBkey(), 2 );
403 $name = $bits[0];
404 if( !isset( $bits[1] ) ) { // bug 2087
405 $par = NULL;
406 } else {
407 $par = $bits[1];
408 }
409 $page = SpecialPage::getPageByAlias( $name );
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 * Can be overridden by subclasses with more complicated permissions
614 * schemes.
615 *
616 * @return bool Should the page be displayed with the restricted-access
617 * pages?
618 */
619 public function isRestricted() {
620 return $this->mRestriction != '';
621 }
622
623 /**
624 * Checks if the given user (identified by an object) can execute this
625 * special page (as defined by $mRestriction). Can be overridden by sub-
626 * classes with more complicated permissions schemes.
627 *
628 * @param User $user The user to check
629 * @return bool Does the user have permission to view the page?
630 */
631 public function userCanExecute( $user ) {
632 return $user->isAllowed( $this->mRestriction );
633 }
634
635 /**
636 * Output an error message telling the user what access level they have to have
637 */
638 function displayRestrictionError() {
639 global $wgOut;
640 $wgOut->permissionRequired( $this->mRestriction );
641 }
642
643 /**
644 * Sets headers - this should be called from the execute() method of all derived classes!
645 */
646 function setHeaders() {
647 global $wgOut;
648 $wgOut->setArticleRelated( false );
649 $wgOut->setRobotPolicy( "noindex,nofollow" );
650 $wgOut->setPageTitle( $this->getDescription() );
651 }
652
653 /**
654 * Default execute method
655 * Checks user permissions, calls the function given in mFunction
656 *
657 * This may be overridden by subclasses.
658 */
659 function execute( $par ) {
660 global $wgUser;
661
662 $this->setHeaders();
663
664 if ( $this->userCanExecute( $wgUser ) ) {
665 $func = $this->mFunction;
666 // only load file if the function does not exist
667 if(!is_callable($func) and $this->mFile) {
668 require_once( $this->mFile );
669 }
670 # FIXME: these hooks are broken for extensions and anything else that subclasses SpecialPage.
671 if ( wfRunHooks( 'SpecialPageExecuteBeforeHeader', array( &$this, &$par, &$func ) ) )
672 $this->outputHeader();
673 if ( ! wfRunHooks( 'SpecialPageExecuteBeforePage', array( &$this, &$par, &$func ) ) )
674 return;
675 call_user_func( $func, $par, $this );
676 if ( ! wfRunHooks( 'SpecialPageExecuteAfterPage', array( &$this, &$par, &$func ) ) )
677 return;
678 } else {
679 $this->displayRestrictionError();
680 }
681 }
682
683 function outputHeader() {
684 global $wgOut, $wgContLang;
685
686 $msg = $wgContLang->lc( $this->name() ) . '-summary';
687 $out = wfMsgNoTrans( $msg );
688 if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() ) {
689 $wgOut->addWikiText( $out );
690 }
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' , 'preload' , 'editintro', 'section' );
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' , 'preload' , 'editintro', 'section' );
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 }