r5304 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r5303‎ | r5304 | r5305 >
Date:19:37, 19 September 2004
Author:hashar
Status:old
Tags:
Comment:
comments
Modified paths:
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialPage.php
@@ -27,62 +27,61 @@
2828 'BrokenRedirects' => new UnlistedSpecialPage ( 'BrokenRedirects' ),
2929 'Disambiguations' => new UnlistedSpecialPage ( 'Disambiguations' ),
3030
31 - "Userlogin" => new SpecialPage( "Userlogin" ),
32 - "Userlogout" => new UnlistedSpecialPage( "Userlogout" ),
33 - "Preferences" => new SpecialPage( "Preferences" ),
34 - "Watchlist" => new SpecialPage( "Watchlist" ),
35 - "Recentchanges" => new SpecialPage( "Recentchanges" ),
36 - "Upload" => new SpecialPage( "Upload" ),
37 - "Imagelist" => new SpecialPage( "Imagelist" ),
38 - "Newimages" => new SpecialPage( "Newimages" ),
39 - "Listusers" => new SpecialPage( "Listusers" ),
40 - "Listadmins" => new SpecialPage( "Listadmins" ),
41 - "Statistics" => new SpecialPage( "Statistics" ),
42 - "Randompage" => new SpecialPage( "Randompage" ),
43 - "Lonelypages" => new SpecialPage( "Lonelypages" ),
44 - "Uncategorizedpages"=> new SpecialPage( "Uncategorizedpages" ),
45 - "Unusedimages" => new SpecialPage( "Unusedimages" )
 31+ 'Userlogin' => new SpecialPage( 'Userlogin' ),
 32+ 'Userlogout' => new UnlistedSpecialPage( 'Userlogout' ),
 33+ 'Preferences' => new SpecialPage( 'Preferences' ),
 34+ 'Watchlist' => new SpecialPage( 'Watchlist' ),
 35+ 'Recentchanges' => new SpecialPage( 'Recentchanges' ),
 36+ 'Upload' => new SpecialPage( 'Upload' ),
 37+ 'Imagelist' => new SpecialPage( 'Imagelist' ),
 38+ 'Newimages' => new SpecialPage( 'Newimages' ),
 39+ 'Listusers' => new SpecialPage( 'Listusers' ),
 40+ 'Listadmins' => new SpecialPage( 'Listadmins' ),
 41+ 'Statistics' => new SpecialPage( 'Statistics' ),
 42+ 'Randompage' => new SpecialPage( 'Randompage' ),
 43+ 'Lonelypages' => new SpecialPage( 'Lonelypages' ),
 44+ 'Uncategorizedpages'=> new SpecialPage( 'Uncategorizedpages' ),
 45+ 'Unusedimages' => new SpecialPage( 'Unusedimages' )
4646 );
4747 global $wgDisableCounters;
4848 if( !$wgDisableCounters ) {
49 - $wgSpecialPages["Popularpages"] = new SpecialPage( "Popularpages" );
 49+ $wgSpecialPages['Popularpages'] = new SpecialPage( 'Popularpages' );
5050 }
5151 $wgSpecialPages = array_merge($wgSpecialPages, array (
52 - "Wantedpages" => new SpecialPage( "Wantedpages" ),
53 - "Shortpages" => new SpecialPage( "Shortpages" ),
54 - "Longpages" => new SpecialPage( "Longpages" ),
55 - "Newpages" => new SpecialPage( "Newpages" ),
56 - "Ancientpages" => new SpecialPage( "Ancientpages" ),
57 - "Deadendpages" => new SpecialPage( "Deadendpages" ),
58 - "Allpages" => new SpecialPage( "Allpages" ),
59 - "Ipblocklist" => new SpecialPage( "Ipblocklist" ),
60 - "Maintenance" => new SpecialPage( "Maintenance" ),
61 - "Specialpages" => new UnlistedSpecialPage( "Specialpages" ),
62 - "Contributions" => new UnlistedSpecialPage( "Contributions" ),
63 - "Emailuser" => new UnlistedSpecialPage( "Emailuser" ),
64 - "Whatlinkshere" => new UnlistedSpecialPage( "Whatlinkshere" ),
65 - "Recentchangeslinked" => new UnlistedSpecialPage( "Recentchangeslinked" ),
66 - "Movepage" => new UnlistedSpecialPage( "Movepage" ),
67 - "Blockme" => new UnlistedSpecialPage( "Blockme" ),
68 - "Geo" => new UnlistedSpecialPage( "Geo" ),
69 - "Validate" => new UnlistedSpecialPage( "Validate" ),
70 - "Booksources" => new SpecialPage( "Booksources" ),
71 - "Categories" => new SpecialPage( "Categories" ),
72 - "Export" => new SpecialPage( "Export" ),
73 - "Version" => new SpecialPage( "Version" ),
74 - "Allmessages" => new SpecialPage( "Allmessages" ),
75 - "Search" => new UnlistedSpecialPage( "Search" ),
76 - "Log" => new SpecialPage( "Log" ),
77 - "Blockip" => new SpecialPage( "Blockip", "sysop" ),
78 - "Asksql" => new SpecialPage( "Asksql", "sysop" ),
79 - "Undelete" => new SpecialPage( "Undelete", "sysop" ),
80 - "Makesysop" => new SpecialPage( "Makesysop", "sysop" ),
 52+ 'Wantedpages' => new SpecialPage( 'Wantedpages' ),
 53+ 'Shortpages' => new SpecialPage( 'Shortpages' ),
 54+ 'Longpages' => new SpecialPage( 'Longpages' ),
 55+ 'Newpages' => new SpecialPage( 'Newpages' ),
 56+ 'Ancientpages' => new SpecialPage( 'Ancientpages' ),
 57+ 'Deadendpages' => new SpecialPage( 'Deadendpages' ),
 58+ 'Allpages' => new SpecialPage( 'Allpages' ),
 59+ 'Ipblocklist' => new SpecialPage( 'Ipblocklist' ),
 60+ 'Maintenance' => new SpecialPage( 'Maintenance' ),
 61+ 'Specialpages' => new UnlistedSpecialPage( 'Specialpages' ),
 62+ 'Contributions' => new UnlistedSpecialPage( 'Contributions' ),
 63+ 'Emailuser' => new UnlistedSpecialPage( 'Emailuser' ),
 64+ 'Whatlinkshere' => new UnlistedSpecialPage( 'Whatlinkshere' ),
 65+ 'Recentchangeslinked' => new UnlistedSpecialPage( 'Recentchangeslinked' ),
 66+ 'Movepage' => new UnlistedSpecialPage( 'Movepage' ),
 67+ 'Blockme' => new UnlistedSpecialPage( 'Blockme' ),
 68+ 'Geo' => new UnlistedSpecialPage( 'Geo' ),
 69+ 'Validate' => new UnlistedSpecialPage( 'Validate' ),
 70+ 'Booksources' => new SpecialPage( 'Booksources' ),
 71+ 'Categories' => new SpecialPage( 'Categories' ),
 72+ 'Export' => new SpecialPage( 'Export' ),
 73+ 'Version' => new SpecialPage( 'Version' ),
 74+ 'Allmessages' => new SpecialPage( 'Allmessages' ),
 75+ 'Search' => new UnlistedSpecialPage( 'Search' ),
 76+ 'Log' => new SpecialPage( 'Log' ),
 77+ 'Blockip' => new SpecialPage( 'Blockip', 'sysop' ),
 78+ 'Asksql' => new SpecialPage( 'Asksql', 'sysop' ),
 79+ 'Undelete' => new SpecialPage( 'Undelete', 'sysop' ),
 80+ 'Makesysop' => new SpecialPage( 'Makesysop', 'sysop' ),
8181
8282 # Special:Import is half-written
8383 # "Import" => new SpecialPage( "Import", "sysop" ),
84 -
85 - "Lockdb" => new SpecialPage( "Lockdb", "developer" ),
86 - "Unlockdb" => new SpecialPage( "Unlockdb", "developer" ),
 84+ 'Lockdb' => new SpecialPage( 'Lockdb', 'developer' ),
 85+ 'Unlockdb' => new SpecialPage( 'Unlockdb', 'developer' ),
8786 // "Sitesettings" => new SpecialPage( "Sitesettings" )
8887 ));
8988
@@ -93,32 +92,60 @@
9493 */
9594 class SpecialPage
9695 {
97 - /* private */ var $mName; # The name of the class, used in the URL. Also used for the default
98 - # <h1> heading, see getDescription()
99 - /* private */ var $mRestriction; # Minimum user level required to access this page, or ""
100 - # for anyone. Also used to categorise the pages in
101 - # Special:Specialpages
102 - /* private */ var $mListed; # Listed in Special:Specialpages?
103 - /* private */ var $mFunction; # Function name called by the default execute()
104 - /* private */ var $mFile; # File which needs to be included before the function above can be called
 96+ /**#@+
 97+ * @access private
 98+ */
 99+ /**
 100+ * The name of the class, used in the URL.
 101+ * Also used for the default <h1> heading, @see getDescription()
 102+ */
 103+ var $mName;
 104+ /**
 105+ * Minimum user level required to access this page, or "" for anyone.
 106+ * Also used to categorise the pages in Special:Specialpages
 107+ */
 108+ var $mRestriction;
 109+ /**
 110+ * Listed in Special:Specialpages?
 111+ */
 112+ var $mListed;
 113+ /**
 114+ * Function name called by the default execute()
 115+ */
 116+ var $mFunction;
 117+ /**
 118+ * File which needs to be included before the function above can be called
 119+ */
 120+ var $mFile;
 121+ /**#@- */
105122
106 - # Add a page to the list of valid special pages
107 - # $obj->execute() must send HTML to $wgOut then return
108 - # Use this for a special page extension
109 - /* static */ function addPage( &$obj ) {
 123+ /**
 124+ * Add a page to the list of valid special pages
 125+ * $obj->execute() must send HTML to $wgOut then return
 126+ * Use this for a special page extension
 127+ * @static
 128+ */
 129+ function addPage( &$obj ) {
110130 global $wgSpecialPages;
111131 $wgSpecialPages[$obj->mName] = $obj;
112132 }
113133
114 - # Remove a special page from the list
115 - # Occasionally used to disable expensive or dangerous special pages
116 - /* static */ function removePage( $name ) {
 134+ /**
 135+ * Remove a special page from the list
 136+ * Occasionally used to disable expensive or dangerous special pages
 137+ * @static
 138+ */
 139+ function removePage( $name ) {
117140 global $wgSpecialPages;
118141 unset( $wgSpecialPages[$name] );
119142 }
120143
121 - # Find the object with a given name and return it (or NULL)
122 - /* static */ function &getPage( $name ) {
 144+ /**
 145+ * Find the object with a given name and return it (or NULL)
 146+ * @static
 147+ * @param string $name
 148+ */
 149+ function &getPage( $name ) {
123150 global $wgSpecialPages;
124151 if ( array_key_exists( $name, $wgSpecialPages ) ) {
125152 return $wgSpecialPages[$name];
@@ -127,14 +154,17 @@
128155 }
129156 }
130157
131 - # Return categorised listable special pages
132 - # Returns a 2d array where the first index is the restriction name
133 - /* static */ function getPages() {
 158+ /**
 159+ * Return categorised listable special pages
 160+ * Returns a 2d array where the first index is the restriction name
 161+ * @static
 162+ */
 163+ function getPages() {
134164 global $wgSpecialPages;
135165 $pages = array(
136 - "" => array(),
137 - "sysop" => array(),
138 - "developer" => array()
 166+ '' => array(),
 167+ 'sysop' => array(),
 168+ 'developer' => array()
139169 );
140170
141171 foreach ( $wgSpecialPages as $name => $page ) {
@@ -145,10 +175,14 @@
146176 return $pages;
147177 }
148178
149 - # Execute a special page path, which may contain parameters, e.g. Special:Name/Params
150 - # $title should be a title object
151 - # Extracts the special page name and call the execute method, passing the parameters
152 - /* static */ function executePath( &$title ) {
 179+ /**
 180+ * Execute a special page path.
 181+ * The path may contain parameters, e.g. Special:Name/Params
 182+ * Extracts the special page name and call the execute method, passing the parameters
 183+ *
 184+ * @param $title should be a title object
 185+ */
 186+ function executePath( &$title ) {
153187 global $wgSpecialPages, $wgOut, $wgTitle;
154188
155189 $bits = split( "/", $title->getDBkey(), 2 );
@@ -175,32 +209,32 @@
176210 }
177211 }
178212
179 - # Default constructor for special pages
180 - # Derivative classes should call this from their constructor
181 - # $name - the name of the special page, as seen in links and URLs
182 - # $restriction - the minimum user level required, e.g. "sysop" or "developer".
183 - #
184 - # Note that if the user does not have the required level, an error message will
185 - # be displayed by the default execute() method, without the global function ever
186 - # being called.
187 - #
188 - # If you override execute(), you can recover the default behaviour with userCanExecute()
189 - # and displayRestrictionError()
190 - #
191 - # $listed - whether the page is listed in Special:Specialpages
192 - # $function - the function called by execute(). By default it is constructed from $name
193 - # $file - the file which is included by execute(). It is also constructed from $name by default
194 - #
195 - function SpecialPage( $name = "", $restriction = "", $listed = true, $function = false, $file = "default" ) {
 213+ /**
 214+ * Default constructor for special pages
 215+ * Derivative classes should call this from their constructor
 216+ * Note that if the user does not have the required level, an error message will
 217+ * be displayed by the default execute() method, without the global function ever
 218+ * being called.
 219+ *
 220+ * If you override execute(), you can recover the default behaviour with userCanExecute()
 221+ * and displayRestrictionError()
 222+ *
 223+ * @param string $name Name of the special page, as seen in links and URLs
 224+ * @param string $restriction Minimum user level required, e.g. "sysop" or "developer".
 225+ * @param boolean $listed Whether the page is listed in Special:Specialpages
 226+ * @param string $function Function called by execute(). By default it is constructed from $name
 227+ * @param string $file File which is included by execute(). It is also constructed from $name by default
 228+ */
 229+ function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default' ) {
196230 $this->mName = $name;
197231 $this->mRestriction = $restriction;
198232 $this->mListed = $listed;
199233 if ( $function == false ) {
200 - $this->mFunction = "wfSpecial{$name}";
 234+ $this->mFunction = 'wfSpecial'.$name;
201235 } else {
202236 $this->mFunction = $function;
203237 }
204 - if ( $file === "default" ) {
 238+ if ( $file === 'default' ) {
205239 $this->mFile = "Special{$name}.php";
206240 } else {
207241 $this->mFile = $file;
@@ -212,8 +246,10 @@
213247 function getRestriction() { return $this->mRestriction; }
214248 function isListed() { return $this->mListed; }
215249
216 - # Checks if the given user (identified by an object) can execute this special page (as
217 - # defined by $mRestriction)
 250+ /**
 251+ * Checks if the given user (identified by an object) can execute this
 252+ * special page (as defined by $mRestriction)
 253+ */
218254 function userCanExecute( &$user ) {
219255 if ( $this->mRestriction == "" ) {
220256 return true;
@@ -226,7 +262,9 @@
227263 }
228264 }
229265
230 - # Output an error message telling the user what access level they have to have
 266+ /**
 267+ * Output an error message telling the user what access level they have to have
 268+ */
231269 function displayRestrictionError() {
232270 global $wgOut;
233271 if ( $this->mRestriction == "developer" ) {
@@ -236,7 +274,9 @@
237275 }
238276 }
239277
240 - # Sets headers - this should be called from the execute() method of all derived classes!
 278+ /**
 279+ * Sets headers - this should be called from the execute() method of all derived classes!
 280+ */
241281 function setHeaders() {
242282 global $wgOut;
243283 $wgOut->setArticleRelated( false );
@@ -244,8 +284,10 @@
245285 $wgOut->setPageTitle( $this->getDescription() );
246286 }
247287
248 - # Default execute method
249 - # Checks user permissions, calls the function given in mFunction
 288+ /**
 289+ * Default execute method
 290+ * Checks user permissions, calls the function given in mFunction
 291+ */
250292 function execute( $par ) {
251293 global $wgUser, $wgOut, $wgTitle;
252294
@@ -271,12 +313,16 @@
272314 return wfMsg( strtolower( $this->mName ) );
273315 }
274316
275 - # Get a self-referential title object
 317+ /**
 318+ * Get a self-referential title object
 319+ */
276320 function getTitle() {
277321 return Title::makeTitle( NS_SPECIAL, $this->mName );
278322 }
279323
280 - # Set whether this page is listed in Special:Specialpages, at run-time
 324+ /**
 325+ * Set whether this page is listed in Special:Specialpages, at run-time
 326+ */
281327 function setListed( $listed ) {
282328 return wfSetVar( $this->mListed, $listed );
283329 }
@@ -288,7 +334,7 @@
289335 */
290336 class UnlistedSpecialPage extends SpecialPage
291337 {
292 - function UnlistedSpecialPage( $name, $restriction = "", $function = false, $file = "default" ) {
 338+ function UnlistedSpecialPage( $name, $restriction = '', $function = false, $file = 'default' ) {
293339 SpecialPage::SpecialPage( $name, $restriction, false, $function, $file );
294340 }
295341 }

Status & tagging log