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