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