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