r96260 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96259‎ | r96260 | r96261 >
Date:21:40, 4 September 2011
Author:reedy
Status:ok
Tags:
Comment:
Trim trailing whitespace

Add/tweak/update documentation

Simplify some boolean returns
Modified paths:
  • /trunk/phase3/includes/BacklinkCache.php (modified) (history)
  • /trunk/phase3/includes/Categoryfinder.php (modified) (history)
  • /trunk/phase3/includes/Cookie.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/Fallback.php (modified) (history)
  • /trunk/phase3/includes/FeedUtils.php (modified) (history)
  • /trunk/phase3/includes/ForkController.php (modified) (history)
  • /trunk/phase3/includes/IP.php (modified) (history)
  • /trunk/phase3/includes/Init.php (modified) (history)
  • /trunk/phase3/includes/Licenses.php (modified) (history)
  • /trunk/phase3/includes/LogEventsList.php (modified) (history)
  • /trunk/phase3/includes/LogPage.php (modified) (history)
  • /trunk/phase3/includes/MagicWord.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Categoryfinder.php
@@ -29,6 +29,10 @@
3030 var $targets = array(); # Array of DBKEY category names
3131 var $name2id = array();
3232 var $mode; # "AND" or "OR"
 33+
 34+ /**
 35+ * @var DatabaseBase
 36+ */
3337 var $dbr; # Read-DB slave
3438
3539 /**
Index: trunk/phase3/includes/FeedUtils.php
@@ -167,7 +167,6 @@
168168 *
169169 * @param $text String: diff's HTML output
170170 * @return String: modified HTML
171 - * @private
172171 */
173172 public static function applyDiffStyle( $text ) {
174173 $styles = array(
Index: trunk/phase3/includes/Licenses.php
@@ -134,6 +134,10 @@
135135 return str_repeat( "\t", $depth ) . Xml::element( 'option', $attribs, $val ) . "\n";
136136 }
137137
 138+ /**
 139+ * @param $str string
 140+ * @return String
 141+ */
138142 protected function msg( $str ) {
139143 $msg = wfMessage( $str );
140144 return $msg->exists() ? $msg->text() : $str;
Index: trunk/phase3/includes/Init.php
@@ -23,7 +23,7 @@
2424 }
2525
2626 /**
27 - * Returns true if we are running under HipHop, whether in compiled or
 27+ * Returns true if we are running under HipHop, whether in compiled or
2828 * interpreted mode.
2929 *
3030 * @return bool
@@ -47,10 +47,10 @@
4848 }
4949
5050 /**
51 - * If we are running code compiled by HipHop, this will pass through the
52 - * input path, assumed to be relative to $IP. If the code is interpreted,
53 - * it will converted to a fully qualified path. It is necessary to use a
54 - * path which is relative to $IP in order to make HipHop use its compiled
 51+ * If we are running code compiled by HipHop, this will pass through the
 52+ * input path, assumed to be relative to $IP. If the code is interpreted,
 53+ * it will converted to a fully qualified path. It is necessary to use a
 54+ * path which is relative to $IP in order to make HipHop use its compiled
5555 * code.
5656 *
5757 * @param $file string
@@ -94,7 +94,7 @@
9595 }
9696
9797 /**
98 - * Register an extension setup file and return its path for compiled
 98+ * Register an extension setup file and return its path for compiled
9999 * inclusion. Use this function in LocalSettings.php to add extensions
100100 * to the build. For example:
101101 *
@@ -130,13 +130,13 @@
131131 /**
132132 * Determine whether a class exists, using a method which works under HipHop.
133133 *
134 - * Note that it's not possible to implement this with any variant of
135 - * class_exists(), because class_exists() returns false for classes which
136 - * are compiled in.
 134+ * Note that it's not possible to implement this with any variant of
 135+ * class_exists(), because class_exists() returns false for classes which
 136+ * are compiled in.
137137 *
138 - * Calling class_exists() on a literal string causes the class to be made
139 - * "volatile", which means (as of March 2011) that the class is broken and
140 - * can't be used at all. So don't do that. See
 138+ * Calling class_exists() on a literal string causes the class to be made
 139+ * "volatile", which means (as of March 2011) that the class is broken and
 140+ * can't be used at all. So don't do that. See
141141 * https://github.com/facebook/hiphop-php/issues/314
142142 *
143143 * @param $class string
@@ -153,11 +153,11 @@
154154 }
155155
156156 /**
157 - * Determine whether a function exists, using a method which works under
 157+ * Determine whether a function exists, using a method which works under
158158 * HipHop.
159159 *
160160 * @param $function string
161 - *
 161+ *
162162 * @return bool
163163 */
164164 static function functionExists( $function ) {
Index: trunk/phase3/includes/EditPage.php
@@ -868,7 +868,7 @@
869869 function internalAttemptSave( &$result, $bot = false ) {
870870 global $wgFilterCallback, $wgUser, $wgRequest, $wgParser;
871871 global $wgMaxArticleSize;
872 -
 872+
873873 $status = Status::newGood();
874874
875875 wfProfileIn( __METHOD__ );
@@ -891,7 +891,6 @@
892892 $status->setResult( false, $code );
893893
894894 wfProfileOut( __METHOD__ . '-checks' );
895 -
896895 wfProfileOut( __METHOD__ );
897896
898897 return $status;
@@ -936,6 +935,7 @@
937936 wfProfileOut( __METHOD__ );
938937 return $status;
939938 }
 939+
940940 if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) {
941941 # Check block state against master, thus 'false'.
942942 $status->setResult( false, self::AS_BLOCKED_PAGE_FOR_USER );
@@ -943,6 +943,7 @@
944944 wfProfileOut( __METHOD__ );
945945 return $status;
946946 }
 947+
947948 $this->kblength = (int)( strlen( $this->textbox1 ) / 1024 );
948949 if ( $this->kblength > $wgMaxArticleSize ) {
949950 // Error will be displayed by showEditForm()
Index: trunk/phase3/includes/LogEventsList.php
@@ -279,7 +279,8 @@
280280 }
281281
282282 /**
283 - * @return boolean Checkbox
 283+ * @param $pattern
 284+ * @return string Checkbox
284285 */
285286 private function getTitlePattern( $pattern ) {
286287 return '<span style="white-space: nowrap">' .
@@ -287,6 +288,10 @@
288289 '</span>';
289290 }
290291
 292+ /**
 293+ * @param $types
 294+ * @return string
 295+ */
291296 private function getExtraInputs( $types ) {
292297 global $wgRequest;
293298 $offender = $wgRequest->getVal('offender');
@@ -301,10 +306,16 @@
302307 return '';
303308 }
304309
 310+ /**
 311+ * @return string
 312+ */
305313 public function beginLogEventsList() {
306314 return "<ul>\n";
307315 }
308316
 317+ /**
 318+ * @return string
 319+ */
309320 public function endLogEventsList() {
310321 return "</ul>\n";
311322 }
@@ -347,6 +358,10 @@
348359 return htmlspecialchars( $time );
349360 }
350361
 362+ /**
 363+ * @param $row
 364+ * @return String
 365+ */
351366 private function logUserLinks( $row ) {
352367 if( self::isDeleted( $row, LogPage::DELETED_USER ) ) {
353368 $userLinks = '<span class="history-deleted">' .
@@ -362,6 +377,12 @@
363378 return $userLinks;
364379 }
365380
 381+ /**
 382+ * @param $row
 383+ * @param $title
 384+ * @param $paramArray
 385+ * @return string
 386+ */
366387 private function logAction( $row, $title, $paramArray ) {
367388 if( self::isDeleted( $row, LogPage::DELETED_ACTION ) ) {
368389 $action = '<span class="history-deleted">' .
@@ -373,6 +394,10 @@
374395 return $action;
375396 }
376397
 398+ /**
 399+ * @param $row
 400+ * @return string
 401+ */
377402 private function logComment( $row ) {
378403 if( self::isDeleted( $row, LogPage::DELETED_COMMENT ) ) {
379404 $comment = '<span class="history-deleted">' .
@@ -811,6 +836,9 @@
812837 return $query;
813838 }
814839
 840+ /**
 841+ * @return Title
 842+ */
815843 function getTitle() {
816844 return $this->mLogEventsList->getDisplayTitle();
817845 }
@@ -1038,10 +1066,16 @@
10391067 return $this->types;
10401068 }
10411069
 1070+ /**
 1071+ * @return string
 1072+ */
10421073 public function getUser() {
10431074 return $this->user;
10441075 }
10451076
 1077+ /**
 1078+ * @return string
 1079+ */
10461080 public function getPage() {
10471081 return $this->title;
10481082 }
Index: trunk/phase3/includes/BacklinkCache.php
@@ -75,6 +75,8 @@
7676 * Serialization handler, diasallows to serialize the database to prevent
7777 * failures after this class is deserialized from cache with dead DB
7878 * connection.
 79+ *
 80+ * @return array
7981 */
8082 function __sleep() {
8183 return array( 'partitionCache', 'fullResultCache', 'title' );
Index: trunk/phase3/includes/MagicWord.php
@@ -230,7 +230,7 @@
231231 * Get an array of parser substitution modifier IDs
232232 */
233233 static function getSubstIDs() {
234 - return self::$mSubstIDs;
 234+ return self::$mSubstIDs;
235235 }
236236
237237 /**
@@ -309,8 +309,8 @@
310310 }
311311
312312 /**
313 - * A comparison function that returns -1, 0 or 1 depending on whether the
314 - * first string is longer, the same length or shorter than the second
 313+ * A comparison function that returns -1, 0 or 1 depending on whether the
 314+ * first string is longer, the same length or shorter than the second
315315 * string.
316316 *
317317 * @param $s1 string
@@ -633,7 +633,7 @@
634634 /**
635635 * Add a number of magic words by name
636636 *
637 - * $param $names array
 637+ * @param $names array
638638 */
639639 public function addArray( $names ) {
640640 $this->names = array_merge( $this->names, array_values( $names ) );
@@ -721,7 +721,7 @@
722722 $newRegex[0] = "/^(?:{$base[0]})/iuS";
723723 }
724724 if ( $base[1] !== '' ) {
725 - $newRegex[1] = "/^(?:{$base[1]})/S";
 725+ $newRegex[1] = "/^(?:{$base[1]})/S";
726726 }
727727 return $newRegex;
728728 }
Index: trunk/phase3/includes/Fallback.php
@@ -22,7 +22,13 @@
2323 * Fallback functions for PHP installed without mbstring support
2424 */
2525 class Fallback {
26 -
 26+
 27+ /**
 28+ * @param $from
 29+ * @param $to
 30+ * @param $string
 31+ * @return string
 32+ */
2733 public static function iconv( $from, $to, $string ) {
2834 if ( substr( $to, -8 ) == '//IGNORE' ) {
2935 $to = substr( $to, 0, strlen( $to ) - 8 );
@@ -48,7 +54,7 @@
4955 * Larger offsets are still fairly efficient for Latin text, but
5056 * can be up to 100x slower than native if the text is heavily
5157 * multibyte and we have to slog through a few hundred kb.
52 - *
 58+ *
5359 * @param $str
5460 * @param $start
5561 * @param $count string
@@ -60,22 +66,27 @@
6167 $split = self::mb_substr_split_unicode( $str, intval( $start ) );
6268 $str = substr( $str, $split );
6369 }
64 -
 70+
6571 if( $count !== 'end' ) {
6672 $split = self::mb_substr_split_unicode( $str, intval( $count ) );
6773 $str = substr( $str, 0, $split );
6874 }
69 -
 75+
7076 return $str;
7177 }
72 -
 78+
 79+ /**
 80+ * @param $str
 81+ * @param $splitPos
 82+ * @return int
 83+ */
7384 public static function mb_substr_split_unicode( $str, $splitPos ) {
7485 if( $splitPos == 0 ) {
7586 return 0;
7687 }
77 -
 88+
7889 $byteLen = strlen( $str );
79 -
 90+
8091 if( $splitPos > 0 ) {
8192 if( $splitPos > 256 ) {
8293 // Optimize large string offsets by skipping ahead N bytes.
@@ -90,7 +101,7 @@
91102 $charPos = 0;
92103 $bytePos = 0;
93104 }
94 -
 105+
95106 while( $charPos++ < $splitPos ) {
96107 ++$bytePos;
97108 // Move past any tail bytes
@@ -110,10 +121,10 @@
111122 }
112123 }
113124 }
114 -
 125+
115126 return $bytePos;
116127 }
117 -
 128+
118129 /**
119130 * Fallback implementation of mb_strlen, hardcoded to UTF-8.
120131 * @param string $str
@@ -123,20 +134,20 @@
124135 public static function mb_strlen( $str, $enc = '' ) {
125136 $counts = count_chars( $str );
126137 $total = 0;
127 -
 138+
128139 // Count ASCII bytes
129140 for( $i = 0; $i < 0x80; $i++ ) {
130141 $total += $counts[$i];
131142 }
132 -
 143+
133144 // Count multibyte sequence heads
134145 for( $i = 0xc0; $i < 0xff; $i++ ) {
135146 $total += $counts[$i];
136147 }
137148 return $total;
138149 }
139 -
140 -
 150+
 151+
141152 /**
142153 * Fallback implementation of mb_strpos, hardcoded to UTF-8.
143154 * @param $haystack String
@@ -147,17 +158,17 @@
148159 */
149160 public static function mb_strpos( $haystack, $needle, $offset = 0, $encoding = '' ) {
150161 $needle = preg_quote( $needle, '/' );
151 -
 162+
152163 $ar = array();
153164 preg_match( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
154 -
 165+
155166 if( isset( $ar[0][1] ) ) {
156167 return $ar[0][1];
157168 } else {
158169 return false;
159170 }
160 - }
161 -
 171+ }
 172+
162173 /**
163174 * Fallback implementation of mb_strrpos, hardcoded to UTF-8.
164175 * @param $haystack String
@@ -168,10 +179,10 @@
169180 */
170181 public static function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = '' ) {
171182 $needle = preg_quote( $needle, '/' );
172 -
 183+
173184 $ar = array();
174185 preg_match_all( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
175 -
 186+
176187 if( isset( $ar[0] ) && count( $ar[0] ) > 0 &&
177188 isset( $ar[0][count( $ar[0] ) - 1][1] ) ) {
178189 return $ar[0][count( $ar[0] ) - 1][1];
@@ -196,5 +207,5 @@
197208 }
198209 return false;
199210 }
200 -
 211+
201212 }
Index: trunk/phase3/includes/ForkController.php
@@ -125,7 +125,7 @@
126126 /**
127127 * Fork a number of worker processes.
128128 *
129 - * return string
 129+ * @return string
130130 */
131131 protected function forkWorkers( $numProcs ) {
132132 $this->prepareEnvironment();
Index: trunk/phase3/includes/LogPage.php
@@ -123,6 +123,8 @@
124124
125125 /**
126126 * Get the RC comment from the last addEntry() call
 127+ *
 128+ * @return string
127129 */
128130 public function getRcComment() {
129131 $rcComment = $this->actionText;
@@ -434,6 +436,8 @@
435437 * @param $comment String: description associated
436438 * @param $params Array: parameters passed later to wfMsg.* functions
437439 * @param $doer User object: the user doing the action
 440+ *
 441+ * @return bool|int|null
438442 */
439443 public function addEntry( $action, $target, $comment, $params = array(), $doer = null ) {
440444 global $wgContLang;
Index: trunk/phase3/includes/IP.php
@@ -186,14 +186,14 @@
187187 }
188188
189189 /**
190 - * Given a host/port string, like one might find in the host part of a URL
191 - * per RFC 2732, split the hostname part and the port part and return an
192 - * array with an element for each. If there is no port part, the array will
193 - * have false in place of the port. If the string was invalid in some way,
 190+ * Given a host/port string, like one might find in the host part of a URL
 191+ * per RFC 2732, split the hostname part and the port part and return an
 192+ * array with an element for each. If there is no port part, the array will
 193+ * have false in place of the port. If the string was invalid in some way,
194194 * false is returned.
195195 *
196 - * This was easy with IPv4 and was generally done in an ad-hoc way, but
197 - * with IPv6 it's somewhat more complicated due to the need to parse the
 196+ * This was easy with IPv4 and was generally done in an ad-hoc way, but
 197+ * with IPv6 it's somewhat more complicated due to the need to parse the
198198 * square brackets and colons.
199199 *
200200 * A bare IPv6 address is accepted despite the lack of square brackets.
@@ -241,8 +241,13 @@
242242 /**
243243 * Given a host name and a port, combine them into host/port string like
244244 * you might find in a URL. If the host contains a colon, wrap it in square
245 - * brackets like in RFC 2732. If the port matches the default port, omit
 245+ * brackets like in RFC 2732. If the port matches the default port, omit
246246 * the port specification
 247+ *
 248+ * @param $host string
 249+ * @param $port int
 250+ * @param $defaultPort bool|int
 251+ * @return string
247252 */
248253 public static function combineHostAndPort( $host, $port, $defaultPort = false ) {
249254 if ( strpos( $host, ':' ) !== false ) {
@@ -449,6 +454,10 @@
450455 return $n;
451456 }
452457
 458+ /**
 459+ * @param $ip
 460+ * @return String
 461+ */
453462 private static function toUnsigned6( $ip ) {
454463 return wfBaseConvert( self::IPv6ToRawHex( $ip ), 16, 10 );
455464 }
@@ -548,6 +557,8 @@
549558 * Convert a network specification in IPv6 CIDR notation to an
550559 * integer network and a number of bits
551560 *
 561+ * @param $range
 562+ *
552563 * @return array(string, int)
553564 */
554565 private static function parseCIDR6( $range ) {
@@ -585,6 +596,9 @@
586597 * 2001:0db8:85a3::7344/96 CIDR
587598 * 2001:0db8:85a3::7344 - 2001:0db8:85a3::7344 Explicit range
588599 * 2001:0db8:85a3::7344/96 Single IP
 600+ *
 601+ * @param $range
 602+ *
589603 * @return array(string, string)
590604 */
591605 private static function parseRange6( $range ) {
Index: trunk/phase3/includes/Cookie.php
@@ -139,6 +139,10 @@
140140 return $ret;
141141 }
142142
 143+ /**
 144+ * @param $domain
 145+ * @return bool
 146+ */
143147 protected function canServeDomain( $domain ) {
144148 if ( $domain == $this->domain
145149 || ( strlen( $domain ) > strlen( $this->domain )
@@ -151,20 +155,19 @@
152156 return false;
153157 }
154158
 159+ /**
 160+ * @param $path
 161+ * @return bool
 162+ */
155163 protected function canServePath( $path ) {
156 - if ( $this->path && substr_compare( $this->path, $path, 0, strlen( $this->path ) ) == 0 ) {
157 - return true;
158 - }
159 -
160 - return false;
 164+ return ( $this->path && substr_compare( $this->path, $path, 0, strlen( $this->path ) ) == 0 );
161165 }
162166
 167+ /**
 168+ * @return bool
 169+ */
163170 protected function isUnExpired() {
164 - if ( $this->isSessionKey || $this->expires > time() ) {
165 - return true;
166 - }
167 -
168 - return false;
 171+ return $this->isSessionKey || $this->expires > time();
169172 }
170173 }
171174

Status & tagging log