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