If the site options are set in such a way that only sysops (or only
[lhc/web/wiklou.git] / includes / SpecialPage.php
1 <?php
2 global $wgSpecialPages, $wgWhitelistAccount;
3
4 # Special:Userlogin is a peculiar case: If the site options tell us to allow only sysops to
5 # create new accounts, we want it displayed under "For sysop use only". If it's for developers
6 # only, display it there. If anyone can create an account, we don't want it listed at all,
7 # because there would already be a "create account or login" link in the top-right corner of
8 # the page. If nobody can create an account, we don't want it listed either.
9
10 $userlogin_listed = true;
11 $userlogin_restr = '';
12 if ( $wgWhitelistAccount && $wgWhitelistAccount['sysop'] && !$wgWhitelistAccount['user'] )
13 $userlogin_restr = 'sysop';
14 else if ( $wgWhitelistAccount && $wgWhitelistAccount['developer'] &&
15 !$wgWhitelistAccount['sysop'] && !$wgWhitelistAccount['user'] )
16 $userlogin_restr = 'developer';
17 else
18 $userlogin_listed = false;
19
20 $wgSpecialPages = array(
21 "Userlogin" => new SpecialPage( "Userlogin", $userlogin_restr, $userlogin_listed ),
22 "Userlogout" => new UnlistedSpecialPage( "Userlogout" ),
23 "Preferences" => new SpecialPage( "Preferences" ),
24 "Watchlist" => new SpecialPage( "Watchlist" ),
25 "Recentchanges" => new SpecialPage( "Recentchanges" ),
26 "Upload" => new SpecialPage( "Upload" ),
27 "Imagelist" => new SpecialPage( "Imagelist" ),
28 "Listusers" => new SpecialPage( "Listusers" ),
29 "Listadmins" => new SpecialPage( "Listadmins" ),
30 "Statistics" => new SpecialPage( "Statistics" ),
31 "Randompage" => new SpecialPage( "Randompage" ),
32 "Lonelypages" => new SpecialPage( "Lonelypages" ),
33 "Uncategorizedpages"=> new SpecialPage( "Uncategorizedpages" ),
34 "Unusedimages" => new SpecialPage( "Unusedimages" )
35 );
36 global $wgDisableCounters;
37 if( !$wgDisableCounters )
38 {
39 $wgSpecialPages["Popularpages"] = new SpecialPage( "Popularpages" );
40 }
41 $wgSpecialPages = array_merge($wgSpecialPages, array (
42 "Wantedpages" => new SpecialPage( "Wantedpages" ),
43 "Shortpages" => new SpecialPage( "Shortpages" ),
44 "Longpages" => new SpecialPage( "Longpages" ),
45 "Newpages" => new SpecialPage( "Newpages" ),
46 "Ancientpages" => new SpecialPage( "Ancientpages" ),
47 "Deadendpages" => new SpecialPage( "Deadendpages" ),
48 "Allpages" => new SpecialPage( "Allpages" ),
49 "Ipblocklist" => new SpecialPage( "Ipblocklist" ),
50 "Maintenance" => new SpecialPage( "Maintenance" ),
51 "Specialpages" => new UnlistedSpecialPage( "Specialpages" ),
52 "Contributions" => new UnlistedSpecialPage( "Contributions" ),
53 "Emailuser" => new UnlistedSpecialPage( "Emailuser" ),
54 "Whatlinkshere" => new UnlistedSpecialPage( "Whatlinkshere" ),
55 "Recentchangeslinked" => new UnlistedSpecialPage( "Recentchangeslinked" ),
56 "Movepage" => new UnlistedSpecialPage( "Movepage" ),
57 "Blockme" => new UnlistedSpecialPage( "Blockme" ),
58 "Geo" => new UnlistedSpecialPage( "Geo" ),
59 "Validate" => new UnlistedSpecialPage( "Validate" ),
60 "Booksources" => new SpecialPage( "Booksources" ),
61 "Categories" => new SpecialPage( "Categories" ),
62 "Export" => new SpecialPage( "Export" ),
63 "Version" => new SpecialPage( "Version" ),
64 "Allmessages" => new SpecialPage( "Allmessages" ),
65 "Search" => new UnlistedSpecialPage( "Search" ),
66 "Blockip" => new SpecialPage( "Blockip", "sysop" ),
67 "Asksql" => new SpecialPage( "Asksql", "sysop" ),
68 "Undelete" => new SpecialPage( "Undelete", "sysop" ),
69 "Makesysop" => new SpecialPage( "Makesysop", "sysop" ),
70 # "Import" => new SpecialPage( "Import", "sysop" ),
71 "Lockdb" => new SpecialPage( "Lockdb", "developer" ),
72 "Unlockdb" => new SpecialPage( "Unlockdb", "developer" )
73 ));
74
75 class SpecialPage
76 {
77 /* private */ var $mName, $mRestriction, $mListed, $mFunction, $mFile;
78
79 /* static */ function addPage( &$obj ) {
80 global $wgSpecialPages;
81 $wgSpecialPages[$obj->mName] = $obj;
82 }
83
84 /* static */ function removePage( $name ) {
85 global $wgSpecialPages;
86 unset( $wgSpecialPages[$name] );
87 }
88
89 /* static */ function &getPage( $name ) {
90 global $wgSpecialPages;
91 if ( array_key_exists( $name, $wgSpecialPages ) ) {
92 return $wgSpecialPages[$name];
93 } else {
94 return NULL;
95 }
96 }
97
98 # Return categorised listable special pages
99 /* static */ function getPages() {
100 global $wgSpecialPages;
101 $pages = array(
102 "" => array(),
103 "sysop" => array(),
104 "developer" => array()
105 );
106
107 foreach ( $wgSpecialPages as $name => $page ) {
108 if ( $page->isListed() ) {
109 $pages[$page->getRestriction()][$page->getName()] =& $wgSpecialPages[$name];
110 }
111 }
112 return $pages;
113 }
114
115 # Execute a special page path, which may contain slashes
116 /* static */ function executePath( &$title ) {
117 global $wgSpecialPages, $wgOut, $wgTitle;
118
119 $bits = split( "/", $title->getDBkey(), 2 );
120 $name = $bits[0];
121 if( empty( $bits[1] ) ) {
122 $par = NULL;
123 } else {
124 $par = $bits[1];
125 }
126
127 $page =& SpecialPage::getPage( $name );
128 if ( is_null( $page ) ) {
129 $wgOut->setArticleRelated( false );
130 $wgOut->setRobotpolicy( "noindex,follow" );
131 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
132 } else {
133 if($par !== NULL) {
134 $wgTitle = Title::makeTitle( NS_SPECIAL, $name );
135 } else {
136 $wgTitle = $title;
137 }
138
139 $page->execute( $par );
140 }
141 }
142
143 function SpecialPage( $name = "", $restriction = "", $listed = true, $function = false, $file = "default" ) {
144 $this->mName = $name;
145 $this->mRestriction = $restriction;
146 $this->mListed = $listed;
147 if ( $function == false ) {
148 $this->mFunction = "wfSpecial{$name}";
149 } else {
150 $this->mFunction = $function;
151 }
152 if ( $file === "default" ) {
153 $this->mFile = "Special{$name}.php";
154 } else {
155 $this->mFile = $file;
156 }
157 }
158
159 function getName() { return $this->mName; }
160 function getRestriction() { return $this->mRestriction; }
161 function isListed() { return $this->mListed; }
162
163 function userCanExecute( &$user ) {
164 if ( $this->mRestriction == "" ) {
165 return true;
166 } else {
167 if ( in_array( $this->mRestriction, $user->getRights() ) ) {
168 return true;
169 } else {
170 return false;
171 }
172 }
173 }
174
175 function displayRestrictionError() {
176 global $wgOut;
177 if ( $this->mRestriction == "developer" ) {
178 $wgOut->developerRequired();
179 } else {
180 $wgOut->sysopRequired();
181 }
182 }
183
184 function setHeaders() {
185 global $wgOut;
186 $wgOut->setArticleRelated( false );
187 $wgOut->setRobotPolicy( "noindex,follow" );
188 $wgOut->setPageTitle( $this->getDescription() );
189 }
190
191 function execute( $par ) {
192 global $wgUser, $wgOut, $wgTitle;
193
194 $this->setHeaders();
195
196 if ( $this->userCanExecute( $wgUser ) ) {
197 if ( $this->mFile ) {
198 require_once( $this->mFile );
199 }
200 $func = $this->mFunction;
201 $func( $par );
202 } else {
203 $this->displayRestrictionError();
204 }
205 }
206
207 function getDescription() {
208 return wfMsg( strtolower( $this->mName ) );
209 }
210
211 function getTitle() {
212 return Title::makeTitle( NS_SPECIAL, $this->mName );
213 }
214
215 function setListed( $listed ) {
216 return wfSetVar( $this->mListed, $listed );
217 }
218 }
219
220 class UnlistedSpecialPage extends SpecialPage
221 {
222 function UnlistedSpecialPage( $name, $restriction = "", $function = false, $file = "default" ) {
223 SpecialPage::SpecialPage( $name, $restriction, false, $function, $file );
224 }
225 }