7c2cb870319dadd4d5808ca9705a8f8c1bbebb41
3 * SpecialPage: handling special pages and lists thereof
4 * $wgSpecialPages is a list of all SpecialPage objects. These objects are
5 * either instances of SpecialPage or a sub-class thereof. They have an
6 * execute() method, which sends the HTML for the special page to $wgOut.
7 * The parent class has an execute() method which distributes the call to
8 * the historical global functions. Additionally, execute() also checks if the
9 * user has the necessary access privileges and bails out if not.
11 * To add a special page at run-time, use SpecialPage::addPage().
12 * DO NOT manipulate this array at run-time.
15 * @subpackage SpecialPage
22 global $wgSpecialPages;
27 $wgSpecialPages = array(
28 'DoubleRedirects' => new SpecialPage ( 'DoubleRedirects' ),
29 'BrokenRedirects' => new SpecialPage ( 'BrokenRedirects' ),
30 'Disambiguations' => new SpecialPage ( 'Disambiguations' ),
32 'Userlogin' => new SpecialPage( 'Userlogin' ),
33 'Userlogout' => new UnlistedSpecialPage( 'Userlogout' ),
34 'Preferences' => new SpecialPage( 'Preferences' ),
35 'Watchlist' => new SpecialPage( 'Watchlist' ),
37 'Mytalk' => new UnlistedSpecialPage( 'Mytalk'),
38 'Mycontributions' => new UnlistedSpecialPage( 'Mycontributions'),
39 'Mypage' => new UnlistedSpecialPage( 'Mypage'),
41 'Recentchanges' => new SpecialPage( 'Recentchanges' ),
42 'Upload' => new SpecialPage( 'Upload' ),
43 'Imagelist' => new SpecialPage( 'Imagelist' ),
44 'Newimages' => new SpecialPage( 'Newimages' ),
45 'Listusers' => new SpecialPage( 'Listusers' ),
46 'Listadmins' => new UnlistedSpecialPage( 'Listadmins' ),
47 'Statistics' => new SpecialPage( 'Statistics' ),
48 'Randompage' => new SpecialPage( 'Randompage' ),
49 'Lonelypages' => new SpecialPage( 'Lonelypages' ),
50 'Uncategorizedpages'=> new SpecialPage( 'Uncategorizedpages' ),
51 'Uncategorizedcategories'=> new SpecialPage( 'Uncategorizedcategories' ),
52 'Unusedimages' => new SpecialPage( 'Unusedimages' ),
53 'Wantedpages' => new SpecialPage( 'Wantedpages' ),
54 'Shortpages' => new SpecialPage( 'Shortpages' ),
55 'Longpages' => new SpecialPage( 'Longpages' ),
56 'Newpages' => new SpecialPage( 'Newpages' ),
57 'Ancientpages' => new SpecialPage( 'Ancientpages' ),
58 'Deadendpages' => new SpecialPage( 'Deadendpages' ),
59 'Allpages' => new SpecialPage( 'Allpages' ),
60 'Ipblocklist' => new SpecialPage( 'Ipblocklist' ),
61 'Specialpages' => new UnlistedSpecialPage( 'Specialpages' ),
62 'Contributions' => new UnlistedSpecialPage( 'Contributions' ),
63 'Emailuser' => new UnlistedSpecialPage( 'Emailuser' ),
64 'Whatlinkshere' => new UnlistedSpecialPage( 'Whatlinkshere' ),
65 'Recentchangeslinked' => new UnlistedSpecialPage( 'Recentchangeslinked' ),
66 'Movepage' => new UnlistedSpecialPage( 'Movepage' ),
67 'Blockme' => new UnlistedSpecialPage( 'Blockme' ),
68 'Booksources' => new SpecialPage( 'Booksources' ),
69 'Categories' => new SpecialPage( 'Categories' ),
70 'Export' => new SpecialPage( 'Export' ),
71 'Version' => new SpecialPage( 'Version' ),
72 'Allmessages' => new SpecialPage( 'Allmessages' ),
73 'Log' => new SpecialPage( 'Log' ),
74 'Blockip' => new SpecialPage( 'Blockip', 'block' ),
75 'Undelete' => new SpecialPage( 'Undelete', 'delete' ),
76 "Import" => new SpecialPage( "Import", 'import' ),
77 'Lockdb' => new SpecialPage( 'Lockdb', 'siteadmin' ),
78 'Unlockdb' => new SpecialPage( 'Unlockdb', 'siteadmin' ),
79 # 'Sitesettings' => new SpecialPage( 'Sitesettings', 'siteadmin' ),
80 'Userrights' => new SpecialPage( 'Userrights', 'userrights' ),
81 'Groups' => new SpecialPage( 'Groups' ),
84 global $wgUseValidation ;
85 if ( $wgUseValidation )
86 $wgSpecialPages['Validate'] = new SpecialPage( 'Validate' );
88 global $wgDisableCounters;
89 if( !$wgDisableCounters ) {
90 $wgSpecialPages['Popularpages'] = new SpecialPage( 'Popularpages' );
93 global $wgDisableInternalSearch;
94 if( !$wgDisableInternalSearch ) {
95 $wgSpecialPages['Search'] = new UnlistedSpecialPage( 'Search' );
98 global $wgEmailAuthentication;
99 if( $wgEmailAuthentication ) {
100 $wgSpecialPages['Confirmemail'] = new UnlistedSpecialPage( 'Confirmemail' );
104 * Parent special page class, also static functions for handling the special
114 * The name of the class, used in the URL.
115 * Also used for the default <h1> heading, @see getDescription()
119 * Minimum user level required to access this page, or "" for anyone.
120 * Also used to categorise the pages in Special:Specialpages
124 * Listed in Special:Specialpages?
128 * Function name called by the default execute()
132 * File which needs to be included before the function above can be called
138 * Add a page to the list of valid special pages
139 * $obj->execute() must send HTML to $wgOut then return
140 * Use this for a special page extension
143 function addPage( &$obj ) {
144 global $wgSpecialPages;
145 $wgSpecialPages[$obj->mName
] = $obj;
149 * Remove a special page from the list
150 * Occasionally used to disable expensive or dangerous special pages
153 function removePage( $name ) {
154 global $wgSpecialPages;
155 unset( $wgSpecialPages[$name] );
159 * Find the object with a given name and return it (or NULL)
161 * @param string $name
163 function &getPage( $name ) {
164 global $wgSpecialPages;
165 if ( array_key_exists( $name, $wgSpecialPages ) ) {
166 return $wgSpecialPages[$name];
173 * Return categorised listable special pages
174 * Returns a 2d array where the first index is the restriction name
177 function getPages() {
178 global $wgSpecialPages;
182 'developer' => array()
185 foreach ( $wgSpecialPages as $name => $page ) {
186 if ( $page->isListed() ) {
187 $pages[$page->getRestriction()][$page->getName()] =& $wgSpecialPages[$name];
194 * Execute a special page path.
195 * The path may contain parameters, e.g. Special:Name/Params
196 * Extracts the special page name and call the execute method, passing the parameters
198 * @param $title should be a title object
200 function executePath( &$title ) {
201 global $wgSpecialPages, $wgOut, $wgTitle;
203 $bits = split( "/", $title->getDBkey(), 2 );
205 if( empty( $bits[1] ) ) {
211 $page =& SpecialPage
::getPage( $name );
212 if ( is_null( $page ) ) {
213 $wgOut->setArticleRelated( false );
214 $wgOut->setRobotpolicy( "noindex,follow" );
215 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
218 $wgTitle = Title
::makeTitle( NS_SPECIAL
, $name );
223 $page->execute( $par );
228 * Default constructor for special pages
229 * Derivative classes should call this from their constructor
230 * Note that if the user does not have the required level, an error message will
231 * be displayed by the default execute() method, without the global function ever
234 * If you override execute(), you can recover the default behaviour with userCanExecute()
235 * and displayRestrictionError()
237 * @param string $name Name of the special page, as seen in links and URLs
238 * @param string $restriction Minimum user level required, e.g. "sysop" or "developer".
239 * @param boolean $listed Whether the page is listed in Special:Specialpages
240 * @param string $function Function called by execute(). By default it is constructed from $name
241 * @param string $file File which is included by execute(). It is also constructed from $name by default
243 function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default' ) {
244 $this->mName
= $name;
245 $this->mRestriction
= $restriction;
246 $this->mListed
= $listed;
247 if ( $function == false ) {
248 $this->mFunction
= 'wfSpecial'.$name;
250 $this->mFunction
= $function;
252 if ( $file === 'default' ) {
253 $this->mFile
= "Special{$name}.php";
255 $this->mFile
= $file;
259 # Accessor functions, see the descriptions of the associated variables above
260 function getName() { return $this->mName
; }
261 function getRestriction() { return $this->mRestriction
; }
262 function isListed() { return $this->mListed
; }
263 function getFile() { return $this->mFile
; }
266 * Checks if the given user (identified by an object) can execute this
267 * special page (as defined by $mRestriction)
269 function userCanExecute( &$user ) {
270 if ( $this->mRestriction
== "" ) {
273 if ( in_array( $this->mRestriction
, $user->getRights() ) ) {
282 * Output an error message telling the user what access level they have to have
284 function displayRestrictionError() {
286 if ( $this->mRestriction
== "developer" ) {
287 $wgOut->developerRequired();
289 $wgOut->sysopRequired();
294 * Sets headers - this should be called from the execute() method of all derived classes!
296 function setHeaders() {
298 $wgOut->setArticleRelated( false );
299 $wgOut->setRobotPolicy( "noindex,follow" );
300 $wgOut->setPageTitle( $this->getDescription() );
304 * Default execute method
305 * Checks user permissions, calls the function given in mFunction
307 function execute( $par ) {
308 global $wgUser, $wgOut, $wgTitle;
312 if ( $this->userCanExecute( $wgUser ) ) {
313 if ( $this->mFile
) {
314 require_once( $this->mFile
);
316 $func = $this->mFunction
;
319 $this->displayRestrictionError();
323 # Returns the name that goes in the <h1> in the special page itself, and also the name that
324 # will be listed in Special:Specialpages
326 # Derived classes can override this, but usually it is easier to keep the default behaviour.
327 # Messages can be added at run-time, see MessageCache.php
328 function getDescription() {
329 return wfMsg( strtolower( $this->mName
) );
333 * Get a self-referential title object
335 function getTitle() {
336 return Title
::makeTitle( NS_SPECIAL
, $this->mName
);
340 * Set whether this page is listed in Special:Specialpages, at run-time
342 function setListed( $listed ) {
343 return wfSetVar( $this->mListed
, $listed );
348 * Shortcut to construct a special page which is unlisted by default
351 class UnlistedSpecialPage
extends SpecialPage
353 function UnlistedSpecialPage( $name, $restriction = '', $function = false, $file = 'default' ) {
354 SpecialPage
::SpecialPage( $name, $restriction, false, $function, $file );