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