r89047 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89046‎ | r89047 | r89048 >
Date:17:18, 28 May 2011
Author:reedy
Status:deferred
Tags:
Comment:
And more documentation. Yaaaay
Modified paths:
  • /trunk/phase3/includes/Autopromote.php (modified) (history)
  • /trunk/phase3/includes/Cdb_PHP.php (modified) (history)
  • /trunk/phase3/includes/HistoryBlob.php (modified) (history)
  • /trunk/phase3/includes/ImageFunctions.php (modified) (history)
  • /trunk/phase3/includes/OutputHandler.php (modified) (history)
  • /trunk/phase3/includes/StreamFile.php (modified) (history)
  • /trunk/phase3/includes/ZhClient.php (modified) (history)
  • /trunk/phase3/includes/filerepo/FileRepoStatus.php (modified) (history)
  • /trunk/phase3/includes/media/IPTC.php (modified) (history)
  • /trunk/phase3/includes/media/Tiff.php (modified) (history)
  • /trunk/phase3/includes/objectcache/MultiWriteBagOStuff.php (modified) (history)
  • /trunk/phase3/includes/objectcache/ObjectCache.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/includes/parser/Preprocessor.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialListredirects.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputHandler.php
@@ -7,7 +7,9 @@
88
99 /**
1010 * Standard output handler for use with ob_start
11 - *
 11+ *
 12+ * @param $s string
 13+ *
1214 * @return string
1315 */
1416 function wfOutputHandler( $s ) {
Index: trunk/phase3/includes/objectcache/ObjectCache.php
@@ -10,6 +10,10 @@
1111
1212 /**
1313 * Get a cached instance of the specified type of cache object.
 14+ *
 15+ * @param $id
 16+ *
 17+ * @return object
1418 */
1519 static function getInstance( $id ) {
1620 if ( isset( self::$instances[$id] ) ) {
@@ -44,6 +48,8 @@
4549
4650 /**
4751 * Create a new cache object from parameters
 52+ *
 53+ * @param $params array
4854 */
4955 static function newFromParams( $params ) {
5056 if ( isset( $params['factory'] ) ) {
@@ -94,6 +100,10 @@
95101 * Factory function that creates a memcached client object.
96102 * The idea of this is that it might eventually detect and automatically
97103 * support the PECL extension, assuming someone can get it to compile.
 104+ *
 105+ * @param $params array
 106+ *
 107+ * @return MemcachedPhpBagOStuff
98108 */
99109 static function newMemcached( $params ) {
100110 return new MemcachedPhpBagOStuff( $params );
Index: trunk/phase3/includes/objectcache/MultiWriteBagOStuff.php
@@ -14,6 +14,8 @@
1515 * - caches: This should have a numbered array of cache parameter
1616 * structures, in the style required by $wgObjectCaches. See
1717 * the documentation of $wgObjectCaches for more detail.
 18+ *
 19+ * @param $params array
1820 */
1921 public function __construct( $params ) {
2022 if ( !isset( $params['caches'] ) ) {
Index: trunk/phase3/includes/parser/Parser.php
@@ -111,6 +111,10 @@
112112 var $mFirstCall = true;
113113
114114 # Initialised by initialiseVariables()
 115+
 116+ /**
 117+ * @var MagicWordArray
 118+ */
115119 var $mVariables;
116120
117121 /**
@@ -169,6 +173,11 @@
170174 var $mRevIdForTs; # The revision ID which was used to fetch the timestamp
171175
172176 /**
 177+ * @var string
 178+ */
 179+ var $mUniqPrefix;
 180+
 181+ /**
173182 * Constructor
174183 */
175184 public function __construct( $conf = array() ) {
@@ -507,6 +516,8 @@
508517
509518 /**
510519 * Get a random string
 520+ *
 521+ * @return string
511522 */
512523 static public function getRandomString() {
513524 return dechex( mt_rand( 0, 0x7fffffff ) ) . dechex( mt_rand( 0, 0x7fffffff ) );
@@ -542,6 +553,8 @@
543554
544555 /**
545556 * Set the context title
 557+ *
 558+ * @param $t Title
546559 */
547560 function setTitle( $t ) {
548561 if ( !$t || $t instanceof FakeTitle ) {
@@ -630,10 +643,16 @@
631644 return wfSetVar( $this->mOptions, $x );
632645 }
633646
 647+ /**
 648+ * @return int
 649+ */
634650 function nextLinkID() {
635651 return $this->mLinkID++;
636652 }
637653
 654+ /**
 655+ * @param $id int
 656+ */
638657 function setLinkID( $id ) {
639658 $this->mLinkID = $id;
640659 }
@@ -689,10 +708,10 @@
690709 * array( 'param' => 'x' ),
691710 * '<element param="x">tag content</element>' ) )
692711 *
693 - * @param $elements list of element names. Comments are always extracted.
694 - * @param $text Source text string.
695 - * @param $matches Out parameter, Array: extracted tags
696 - * @param $uniq_prefix
 712+ * @param $elements array list of element names. Comments are always extracted.
 713+ * @param $text string Source text string.
 714+ * @param $matches array Out parameter, Array: extracted tags
 715+ * @param $uniq_prefix string
697716 * @return String: stripped text
698717 */
699718 public static function extractTagsAndParams( $elements, $text, &$matches, $uniq_prefix = '' ) {
@@ -759,6 +778,8 @@
760779
761780 /**
762781 * Get a list of strippable XML-like elements
 782+ *
 783+ * @return array
763784 */
764785 function getStripList() {
765786 return $this->mStripList;
@@ -960,6 +981,9 @@
961982 * is repeated twice.
962983 *
963984 * @private
 985+ * @param $cell
 986+ * @param $tagName
 987+ * @return array
964988 */
965989 function getCellAttr ( $cell, $tagName ) {
966990 $attributes = null;
@@ -1176,6 +1200,11 @@
11771201 return $text;
11781202 }
11791203
 1204+ /**
 1205+ * @throws MWException
 1206+ * @param $m array
 1207+ * @return HTML|string
 1208+ */
11801209 function magicLinkCallback( $m ) {
11811210 if ( isset( $m[1] ) && $m[1] !== '' ) {
11821211 # Skip anchor
Index: trunk/phase3/includes/parser/Preprocessor.php
@@ -22,6 +22,8 @@
2323 /**
2424 * Create a new custom frame for programmatic use of parameter replacement as used in some extensions
2525 *
 26+ * @param $args array
 27+ *
2628 * @return PPFrame
2729 */
2830 function newCustomFrame( $args );
@@ -51,6 +53,8 @@
5254
5355 /**
5456 * Create a child frame
 57+ *
 58+ * @return PPFrame
5559 */
5660 function newChild( $args = false, $title = false );
5761
Index: trunk/phase3/includes/filerepo/FileRepoStatus.php
@@ -13,6 +13,10 @@
1414 class FileRepoStatus extends Status {
1515 /**
1616 * Factory function for fatal errors
 17+ *
 18+ * @param $repo FileRepo
 19+ *
 20+ * @return FileRepoStatus
1721 */
1822 static function newFatal( $repo /*, parameters...*/ ) {
1923 $params = array_slice( func_get_args(), 1 );
@@ -22,6 +26,11 @@
2327 return $result;
2428 }
2529
 30+ /**
 31+ * @param $repo FileRepo
 32+ * @param $value
 33+ * @return FileRepoStatus
 34+ */
2635 static function newGood( $repo = false, $value = null ) {
2736 $result = new self( $repo );
2837 $result->value = $value;
Index: trunk/phase3/includes/ZhClient.php
@@ -19,6 +19,8 @@
2020
2121 /**
2222 * Check if connection to zhdaemon is successful
 23+ *
 24+ * @return bool
2325 */
2426 function isconnected() {
2527 return $this->mConnected;
@@ -28,6 +30,8 @@
2931 * Establish conncetion
3032 *
3133 * @access private
 34+ *
 35+ * @return bool
3236 */
3337 function connect() {
3438 wfSuppressWarnings();
Index: trunk/phase3/includes/Cdb_PHP.php
@@ -16,6 +16,7 @@
1717 /**
1818 * Take a modulo of a signed integer as if it were an unsigned integer.
1919 * $b must be less than 0x40000000 and greater than 0
 20+ * @return int
2021 */
2122 public static function unsignedMod( $a, $b ) {
2223 if ( $a & 0x80000000 ) {
@@ -25,9 +26,12 @@
2627 return $a % $b;
2728 }
2829 }
29 -
 30+
3031 /**
3132 * Shift a signed integer right as if it were unsigned
 33+ * @param $a
 34+ * @param $b
 35+ * @return int
3236 */
3337 public static function unsignedShiftRight( $a, $b ) {
3438 if ( $b == 0 ) {
@@ -42,6 +46,9 @@
4347
4448 /**
4549 * The CDB hash function.
 50+ *
 51+ * @param $s
 52+ * @return
4653 */
4754 public static function hash( $s ) {
4855 $h = 5381;
@@ -103,8 +110,9 @@
104111 }
105112
106113 function close() {
107 - if( isset($this->handle) )
 114+ if( isset( $this->handle ) ) {
108115 fclose( $this->handle );
 116+ }
109117 unset( $this->handle );
110118 }
111119
@@ -117,6 +125,11 @@
118126 }
119127 }
120128
 129+ /**
 130+ * @param $key
 131+ * @param $pos
 132+ * @return bool
 133+ */
121134 protected function match( $key, $pos ) {
122135 $buf = $this->read( strlen( $key ), $pos );
123136 return $buf === $key;
@@ -126,6 +139,12 @@
127140 $this->loop = 0;
128141 }
129142
 143+ /**
 144+ * @throws MWException
 145+ * @param $length
 146+ * @param $pos
 147+ * @return string
 148+ */
130149 protected function read( $length, $pos ) {
131150 if ( fseek( $this->handle, $pos ) == -1 ) {
132151 // This can easily happen if the internal pointers are incorrect
@@ -145,6 +164,8 @@
146165
147166 /**
148167 * Unpack an unsigned integer and throw an exception if it needs more than 31 bits
 168+ * @param $s
 169+ * @return
149170 */
150171 protected function unpack31( $s ) {
151172 $data = unpack( 'V', $s );
@@ -156,12 +177,18 @@
157178
158179 /**
159180 * Unpack a 32-bit signed integer
 181+ * @param $s
 182+ * @return int
160183 */
161184 protected function unpackSigned( $s ) {
162185 $data = unpack( 'va/vb', $s );
163186 return $data['a'] | ( $data['b'] << 16 );
164187 }
165188
 189+ /**
 190+ * @param $key
 191+ * @return bool
 192+ */
166193 protected function findNext( $key ) {
167194 if ( !$this->loop ) {
168195 $u = CdbFunctions::hash( $key );
@@ -204,6 +231,10 @@
205232 return false;
206233 }
207234
 235+ /**
 236+ * @param $key
 237+ * @return bool
 238+ */
208239 protected function find( $key ) {
209240 $this->findStart();
210241 return $this->findNext( $key );
@@ -240,6 +271,11 @@
241272 }
242273 }
243274
 275+ /**
 276+ * @param $key
 277+ * @param $value
 278+ * @return
 279+ */
244280 public function set( $key, $value ) {
245281 if ( strval( $key ) === '' ) {
246282 // DBA cross-check hack
@@ -251,10 +287,14 @@
252288 $this->addend( strlen( $key ), strlen( $value ), CdbFunctions::hash( $key ) );
253289 }
254290
 291+ /**
 292+ * @throws MWException
 293+ */
255294 public function close() {
256295 $this->finish();
257 - if( isset($this->handle) )
 296+ if( isset($this->handle) ) {
258297 fclose( $this->handle );
 298+ }
259299 if ( wfIsWindows() && file_exists($this->realFileName) ) {
260300 unlink( $this->realFileName );
261301 }
@@ -264,6 +304,10 @@
265305 unset( $this->handle );
266306 }
267307
 308+ /**
 309+ * @throws MWException
 310+ * @param $buf
 311+ */
268312 protected function write( $buf ) {
269313 $len = fwrite( $this->handle, $buf );
270314 if ( $len !== strlen( $buf ) ) {
@@ -271,6 +315,10 @@
272316 }
273317 }
274318
 319+ /**
 320+ * @throws MWException
 321+ * @param $len
 322+ */
275323 protected function posplus( $len ) {
276324 $newpos = $this->pos + $len;
277325 if ( $newpos > 0x7fffffff ) {
@@ -291,6 +339,11 @@
292340 $this->posplus( $datalen );
293341 }
294342
 343+ /**
 344+ * @throws MWException
 345+ * @param $keylen
 346+ * @param $datalen
 347+ */
295348 protected function addbegin( $keylen, $datalen ) {
296349 if ( $keylen > 0x7fffffff ) {
297350 throw new MWException( __METHOD__.': key length too long' );
Index: trunk/phase3/includes/media/IPTC.php
@@ -12,7 +12,7 @@
1313 *
1414 * @see http://www.iptc.org/std/IIM/4.1/specification/IIMV4.1.pdf
1515 *
16 - * @param String $data app13 block from jpeg containing iptc/iim data
 16+ * @param $rawData String app13 block from jpeg containing iptc/iim data
1717 * @return Array iptc metadata array
1818 */
1919 static function parse( $rawData ) {
Index: trunk/phase3/includes/media/Tiff.php
@@ -16,6 +16,8 @@
1717 /**
1818 * Conversion to PNG for inline display can be disabled here...
1919 * Note scaling should work with ImageMagick, but may not with GD scaling.
 20+ *
 21+ * @return bool
2022 */
2123 function canRender( $file ) {
2224 global $wgTiffThumbnailType;
@@ -25,29 +27,42 @@
2628 /**
2729 * Browsers don't support TIFF inline generally...
2830 * For inline display, we need to convert to PNG.
 31+ *
 32+ * @return bool
2933 */
3034 function mustRender( $file ) {
3135 return true;
3236 }
3337
 38+ /**
 39+ * @param $ext
 40+ * @param $mime
 41+ * @param null $params
 42+ * @return bool
 43+ */
3444 function getThumbType( $ext, $mime, $params = null ) {
3545 global $wgTiffThumbnailType;
3646 return $wgTiffThumbnailType;
3747 }
3848
39 - function getMetadata( $image, $filename ) {
40 - global $wgShowEXIF;
41 - if ( $wgShowEXIF && file_exists( $filename ) ) {
42 - $exif = new Exif( $filename );
43 - $data = $exif->getFilteredData();
44 - if ( $data ) {
45 - $data['MEDIAWIKI_EXIF_VERSION'] = Exif::version();
46 - return serialize( $data );
47 - } else {
48 - return JpegOrTiffHandler::BROKEN_FILE;
49 - }
50 - } else {
51 - return '';
52 - }
53 - }
 49+ /**
 50+ * @param $image
 51+ * @param $filename
 52+ * @return string
 53+ */
 54+ function getMetadata( $image, $filename ) {
 55+ global $wgShowEXIF;
 56+ if ( $wgShowEXIF && file_exists( $filename ) ) {
 57+ $exif = new Exif( $filename );
 58+ $data = $exif->getFilteredData();
 59+ if ( $data ) {
 60+ $data['MEDIAWIKI_EXIF_VERSION'] = Exif::version();
 61+ return serialize( $data );
 62+ } else {
 63+ return JpegOrTiffHandler::BROKEN_FILE;
 64+ }
 65+ } else {
 66+ return '';
 67+ }
 68+ }
5469 }
Index: trunk/phase3/includes/StreamFile.php
@@ -5,7 +5,10 @@
66 * @file
77 */
88
9 -/** */
 9+/**
 10+ * @param $fname string
 11+ * @param $headers array
 12+ */
1013 function wfStreamFile( $fname, $headers = array() ) {
1114 $stat = @stat( $fname );
1215 if ( !$stat ) {
Index: trunk/phase3/includes/specials/SpecialListredirects.php
@@ -65,6 +65,7 @@
6666 * Cache page existence for performance
6767 *
6868 * @param $db DatabaseBase
 69+ * @param $res ResultWrapper
6970 */
7071 function preprocessResults( $db, $res ) {
7172 $batch = new LinkBatch;
Index: trunk/phase3/includes/Autopromote.php
@@ -8,7 +8,7 @@
99 /**
1010 * Get the groups for the given user based on $wgAutopromote.
1111 *
12 - * @param $user The user to get the groups for
 12+ * @param $user User The user to get the groups for
1313 * @return array Array of groups to promote to.
1414 */
1515 public static function getAutopromoteGroups( User $user ) {
Index: trunk/phase3/includes/ImageFunctions.php
@@ -15,7 +15,7 @@
1616 * i.e. articles where the image may occur inline.
1717 *
1818 * @param $name string the image name to check
19 - * @param $contextTitle Title: the page on which the image occurs, if known
 19+ * @param $contextTitle Title the page on which the image occurs, if known
2020 * @return bool
2121 */
2222 function wfIsBadImage( $name, $contextTitle = false ) {
Index: trunk/phase3/includes/HistoryBlob.php
@@ -12,6 +12,8 @@
1313 * You must call setLocation() on the stub object before storing it to the
1414 * database
1515 *
 16+ * @param $text string
 17+ *
1618 * @return String: the key for getItem()
1719 */
1820 function addItem( $text );
@@ -19,6 +21,8 @@
2022 /**
2123 * Get item by key, or false if the key is not present
2224 *
 25+ * @param $key string
 26+ *
2327 * @return String or false
2428 */
2529 function getItem( $key );
@@ -30,6 +34,8 @@
3135 * be other revisions in the same object.
3236 *
3337 * Default text is not required for two-part external storage URLs.
 38+ *
 39+ * @param $text string
3440 */
3541 function setText( $text );
3642
@@ -59,6 +65,10 @@
6066 }
6167 }
6268
 69+ /**
 70+ * @param $text string
 71+ * @return string
 72+ */
6373 public function addItem( $text ) {
6474 $this->uncompress();
6575 $hash = md5( $text );
@@ -69,6 +79,10 @@
7080 return $hash;
7181 }
7282
 83+ /**
 84+ * @param $hash string
 85+ * @return array|bool
 86+ */
7387 public function getItem( $hash ) {
7488 $this->uncompress();
7589 if ( array_key_exists( $hash, $this->mItems ) ) {
@@ -78,11 +92,18 @@
7993 }
8094 }
8195
 96+ /**
 97+ * @param $text string
 98+ * @return void
 99+ */
82100 public function setText( $text ) {
83101 $this->uncompress();
84102 $this->mDefaultHash = $this->addItem( $text );
85103 }
86104
 105+ /**
 106+ * @return array|bool
 107+ */
87108 public function getText() {
88109 $this->uncompress();
89110 return $this->getItem( $this->mDefaultHash );
@@ -90,6 +111,8 @@
91112
92113 /**
93114 * Remove an item
 115+ *
 116+ * @param $hash string
94117 */
95118 public function removeItem( $hash ) {
96119 $this->mSize -= strlen( $this->mItems[$hash] );
@@ -116,7 +139,9 @@
117140 }
118141 }
119142
120 -
 143+ /**
 144+ * @return array
 145+ */
121146 function __sleep() {
122147 $this->compress();
123148 return array( 'mVersion', 'mCompressed', 'mItems', 'mDefaultHash' );
@@ -129,6 +154,8 @@
130155 /**
131156 * Helper function for compression jobs
132157 * Returns true until the object is "full" and ready to be committed
 158+ *
 159+ * @return bool
133160 */
134161 public function isHappy() {
135162 return $this->mSize < $this->mMaxSize
@@ -137,8 +164,6 @@
138165 }
139166
140167
141 -
142 -
143168 /**
144169 * Pointer object for an item within a CGZ blob stored in the text table.
145170 */
@@ -183,6 +208,9 @@
184209 return $this->mRef;
185210 }
186211
 212+ /**
 213+ * @return string
 214+ */
187215 function getText() {
188216 $fname = 'HistoryBlobStub::getText';
189217
@@ -198,11 +226,11 @@
199227 if( in_array( 'external', $flags ) ) {
200228 $url=$row->old_text;
201229 @list( /* $proto */ ,$path)=explode('://',$url,2);
202 - if ($path=="") {
 230+ if ( $path == "" ) {
203231 wfProfileOut( $fname );
204232 return false;
205233 }
206 - $row->old_text=ExternalStore::fetchFromUrl($url);
 234+ $row->old_text = ExternalStore::fetchFromUrl($url);
207235
208236 }
209237 if( !in_array( 'object', $flags ) ) {
@@ -232,6 +260,8 @@
233261
234262 /**
235263 * Get the content hash
 264+ *
 265+ * @return string
236266 */
237267 function getHash() {
238268 return $this->mHash;
@@ -265,6 +295,9 @@
266296 $this->mCurId = $id;
267297 }
268298
 299+ /**
 300+ * @return string|false
 301+ */
269302 function getText() {
270303 $dbr = wfGetDB( DB_SLAVE );
271304 $row = $dbr->selectRow( 'cur', array( 'cur_text' ), array( 'cur_id' => $this->mCurId ) );
@@ -336,6 +369,11 @@
337370 }
338371 }
339372
 373+ /**
 374+ * @throws MWException
 375+ * @param $text string
 376+ * @return int
 377+ */
340378 function addItem( $text ) {
341379 if ( $this->mFrozen ) {
342380 throw new MWException( __METHOD__.": Cannot add more items after sleep/wakeup" );
@@ -347,18 +385,31 @@
348386 return count( $this->mItems ) - 1;
349387 }
350388
 389+ /**
 390+ * @param $key string
 391+ * @return string
 392+ */
351393 function getItem( $key ) {
352394 return $this->mItems[$key];
353395 }
354396
 397+ /**
 398+ * @param $text string
 399+ */
355400 function setText( $text ) {
356401 $this->mDefaultKey = $this->addItem( $text );
357402 }
358403
 404+ /**
 405+ * @return string
 406+ */
359407 function getText() {
360408 return $this->getItem( $this->mDefaultKey );
361409 }
362410
 411+ /**
 412+ * @throws MWException
 413+ */
363414 function compress() {
364415 if ( !function_exists( 'xdiff_string_rabdiff' ) ){
365416 throw new MWException( "Need xdiff 1.5+ support to write DiffHistoryBlob\n" );

Status & tagging log