Index: trunk/phase3/includes/SpecialPage.php |
— | — | @@ -1,13 +1,14 @@ |
2 | 2 | <?php |
3 | 3 | # SpecialPage: handling special pages and lists thereof |
4 | 4 | |
5 | | -# $wgSpecialPages is a list of all SpecialPage objects. These objects should be derived from |
6 | | -# SpecialPage. At a minimum, they must have an execute() method, which sends the HTML for the |
7 | | -# special page to $wgOut. The parent object has an execute() method which distributes the call |
8 | | -# to the historical global functions. |
| 5 | +# $wgSpecialPages is a list of all SpecialPage objects. These objects are either instances of |
| 6 | +# SpecialPage or a sub-class thereof. They have an execute() method, which sends the HTML for the |
| 7 | +# special page to $wgOut. The parent class has an execute() method which distributes the call to |
| 8 | +# the historical global functions. Additionally, execute() also checks if the user has the |
| 9 | +# necessary access privileges and bails out if not. |
9 | 10 | |
10 | | -# To add a special page at run-time, use SpecialPage::addPage(). DO NOT add objects directly to |
11 | | -# this list. |
| 11 | +# To add a special page at run-time, use SpecialPage::addPage(). |
| 12 | +# DO NOT manipulate this array at run-time. |
12 | 13 | |
13 | 14 | global $wgSpecialPages; |
14 | 15 | |
— | — | @@ -72,15 +73,15 @@ |
73 | 74 | # Parent special page class, also static functions for handling the special page list |
74 | 75 | class SpecialPage |
75 | 76 | { |
76 | | - /* private */ var $mName; # The name of the class, used in the URL. Also used for the default |
| 77 | + /* private */ var $mName; # The name of the class, used in the URL. Also used for the default |
77 | 78 | # <h1> heading, see getDescription() |
78 | | - /* private */ var $mRestriction; # Minimum user level required to access this page, or "" |
79 | | - # for anyone. Also used to categorise the pages in |
| 79 | + /* private */ var $mRestriction; # Minimum user level required to access this page, or "" |
| 80 | + # for anyone. Also used to categorise the pages in |
80 | 81 | # Special:Specialpages |
81 | 82 | /* private */ var $mListed; # Listed in Special:Specialpages? |
82 | 83 | /* private */ var $mFunction; # Function name called by the default execute() |
83 | 84 | /* private */ var $mFile; # File which needs to be included before the function above can be called |
84 | | - |
| 85 | + |
85 | 86 | # Add a page to the list of valid special pages |
86 | 87 | # $obj->execute() must send HTML to $wgOut then return |
87 | 88 | # Use this for a special page extension |
— | — | @@ -157,15 +158,15 @@ |
158 | 159 | # Default constructor for special pages |
159 | 160 | # Derivative classes should call this from their constructor |
160 | 161 | # $name - the name of the special page, as seen in links and URLs |
161 | | - # $restriction - the minimum user level required, e.g. "sysop" or "developer". |
| 162 | + # $restriction - the minimum user level required, e.g. "sysop" or "developer". |
162 | 163 | # |
163 | | - # Note that if the user does not have the required level, an error message will |
164 | | - # be displayed by the default execute() method, without the global function ever |
165 | | - # being called. |
| 164 | + # Note that if the user does not have the required level, an error message will |
| 165 | + # be displayed by the default execute() method, without the global function ever |
| 166 | + # being called. |
166 | 167 | # |
167 | 168 | # If you override execute(), you can recover the default behaviour with userCanExecute() |
168 | 169 | # and displayRestrictionError() |
169 | | - # |
| 170 | + # |
170 | 171 | # $listed - whether the page is listed in Special:Specialpages |
171 | 172 | # $function - the function called by execute(). By default it is constructed from $name |
172 | 173 | # $file - the file which is included by execute(). It is also constructed from $name by default |
— | — | @@ -179,7 +180,7 @@ |
180 | 181 | } else { |
181 | 182 | $this->mFunction = $function; |
182 | 183 | } |
183 | | - if ( $file === "default" ) { |
| 184 | + if ( $file === "default" ) { |
184 | 185 | $this->mFile = "Special{$name}.php"; |
185 | 186 | } else { |
186 | 187 | $this->mFile = $file; |
— | — | @@ -191,7 +192,7 @@ |
192 | 193 | function getRestriction() { return $this->mRestriction; } |
193 | 194 | function isListed() { return $this->mListed; } |
194 | 195 | |
195 | | - # Checks if the given user (identified by an object) can execute this special page (as |
| 196 | + # Checks if the given user (identified by an object) can execute this special page (as |
196 | 197 | # defined by $mRestriction) |
197 | 198 | function userCanExecute( &$user ) { |
198 | 199 | if ( $this->mRestriction == "" ) { |
— | — | @@ -204,7 +205,7 @@ |
205 | 206 | } |
206 | 207 | } |
207 | 208 | } |
208 | | - |
| 209 | + |
209 | 210 | # Output an error message telling the user what access level they have to have |
210 | 211 | function displayRestrictionError() { |
211 | 212 | global $wgOut; |
— | — | @@ -214,7 +215,7 @@ |
215 | 216 | $wgOut->sysopRequired(); |
216 | 217 | } |
217 | 218 | } |
218 | | - |
| 219 | + |
219 | 220 | # Sets headers - this should be called from the execute() method of all derived classes! |
220 | 221 | function setHeaders() { |
221 | 222 | global $wgOut; |
— | — | @@ -229,11 +230,11 @@ |
230 | 231 | global $wgUser, $wgOut, $wgTitle; |
231 | 232 | |
232 | 233 | $this->setHeaders(); |
233 | | - |
| 234 | + |
234 | 235 | if ( $this->userCanExecute( $wgUser ) ) { |
235 | 236 | if ( $this->mFile ) { |
236 | 237 | require_once( $this->mFile ); |
237 | | - } |
| 238 | + } |
238 | 239 | $func = $this->mFunction; |
239 | 240 | $func( $par ); |
240 | 241 | } else { |
— | — | @@ -241,10 +242,10 @@ |
242 | 243 | } |
243 | 244 | } |
244 | 245 | |
245 | | - # Returns the name that goes in the <h1> in the special page itself, and also the name that |
| 246 | + # Returns the name that goes in the <h1> in the special page itself, and also the name that |
246 | 247 | # will be listed in Special:Specialpages |
247 | 248 | # |
248 | | - # Derived classes can override this, but usually it is easier to keep the default behaviour. |
| 249 | + # Derived classes can override this, but usually it is easier to keep the default behaviour. |
249 | 250 | # Messages can be added at run-time, see MessageCache.php |
250 | 251 | function getDescription() { |
251 | 252 | return wfMsg( strtolower( $this->mName ) ); |