title escaping
[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 global $wgOut;
150 if ( $this->mRestriction == "developer" ) {
151 $wgOut->developerRequired();
152 } else {
153 $wgOut->sysopRequired();
154 }
155 }
156
157 function setHeaders() {
158 global $wgOut;
159 $wgOut->setArticleRelated( false );
160 $wgOut->setRobotPolicy( "noindex,follow" );
161 $wgOut->setPageTitle( $this->getDescription() );
162 }
163
164 function execute( $par ) {
165 global $wgUser, $wgOut, $wgTitle;
166
167 $this->setHeaders();
168
169 if ( $this->userCanExecute( $wgUser ) ) {
170 if ( $this->mFile ) {
171 require_once( $this->mFile );
172 }
173 $func = $this->mFunction;
174 $func( $par );
175 } else {
176 $this->displayRestrictionError();
177 }
178 }
179
180 function getDescription() {
181 return wfMsg( strtolower( $this->mName ) );
182 }
183
184 function getTitle() {
185 return Title::makeTitle( NS_SPECIAL, $this->mName );
186 }
187
188 function setListed( $listed ) {
189 return wfSetVar( $this->mListed, $listed );
190 }
191 }
192
193 class UnlistedSpecialPage extends SpecialPage
194 {
195 function UnlistedSpecialPage( $name, $restriction = "", $function = false, $file = "default" ) {
196 SpecialPage::SpecialPage( $name, $restriction, false, $function, $file );
197 }
198 }