Introducing special page modular extensions, making the board vote special page the...
[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 # Execute a special page path, which may contain slashes
72 /* static */ function executePath( &$title ) {
73 global $wgSpecialPages, $wgOut, $wgTitle;
74
75 $bits = split( "/", $title->getDBkey(), 2 );
76 $name = $bits[0];
77 if( empty( $bits[1] ) ) {
78 $par = NULL;
79 } else {
80 $par = $bits[1];
81 }
82
83 $page =& SpecialPage::getPage( $name );
84 if ( is_null( $page ) ) {
85 $wgOut->setArticleRelated( false );
86 $wgOut->setRobotpolicy( "noindex,follow" );
87 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
88 } else {
89 if($par !== NULL) {
90 $wgTitle = Title::makeTitle( NS_SPECIAL, $name );
91 } else {
92 $wgTitle = $title;
93 }
94
95 $page->execute( $par );
96 }
97 }
98
99 function SpecialPage( $name = "", $restriction = "", $listed = true, $function = false, $file = "default" ) {
100 $this->mName = $name;
101 $this->mRestriction = $restriction;
102 $this->mListed = $listed;
103 if ( $function == false ) {
104 $this->mFunction = "wfSpecial{$name}";
105 } else {
106 $this->mFunction = $function;
107 }
108 if ( $file === "default" ) {
109 $this->mFile = "Special{$name}.php";
110 } else {
111 $this->mFile = $file;
112 }
113 }
114
115 function getName() { return $this->mName; }
116 function getRestriction() { return $this->mRestriction; }
117 function isListed() { return $this->mListed; }
118
119 function userCanExecute( &$user ) {
120 if ( $this->mRestriction == "" ) {
121 return true;
122 } else {
123 if ( in_array( $this->mRestriction, $user->getRights() ) ) {
124 return true;
125 } else {
126 return false;
127 }
128 }
129 }
130
131 function displayRestrictionError() {
132 if ( $this->mRestriction == "developer" ) {
133 $wgOut->developerRequired();
134 } else {
135 $wgOut->sysopRequired();
136 }
137 }
138
139 function setHeaders() {
140 global $wgOut;
141 $wgOut->setArticleRelated( false );
142 $wgOut->setRobotPolicy( "noindex,follow" );
143 $wgOut->setPageTitle( $this->getDescription() );
144 }
145
146 function execute( $par ) {
147 global $wgUser, $wgOut, $wgTitle;
148
149 $this->setHeaders();
150
151 if ( $this->userCanExecute( $wgUser ) ) {
152 if ( $this->mFile ) {
153 require_once( $this->mFile );
154 }
155 $func = $this->mFunction;
156 $func( $par );
157 } else {
158 $this->displayRestrictionError();
159 }
160 }
161
162 function getDescription() {
163 return wfMsg( strtolower( $this->mName ) );
164 }
165
166 function getTitle() {
167 return Title::makeTitle( NS_SPECIAL, $this->mName );
168 }
169
170 function setListed( $listed ) {
171 return wfSetVar( $this->mListed, $listed );
172 }
173 }
174
175 class UnlistedSpecialPage extends SpecialPage
176 {
177 function UnlistedSpecialPage( $name, $restriction = "", $function = false, $file = "default" ) {
178 SpecialPage::SpecialPage( $name, $restriction, false, $function, $file );
179 }
180 }