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