Index: trunk/phase3/includes/filerepo/FileRepo.php |
— | — | @@ -164,6 +164,8 @@ |
165 | 165 | * $findItem = array( 'title' => $title, 'private' => true ); |
166 | 166 | * $findBatch = array( $findItem ); |
167 | 167 | * $repo->findFiles( $findBatch ); |
| 168 | + * |
| 169 | + * @return array |
168 | 170 | */ |
169 | 171 | function findFiles( $items ) { |
170 | 172 | $result = array(); |
— | — | @@ -259,6 +261,8 @@ |
260 | 262 | |
261 | 263 | /** |
262 | 264 | * Returns true if the repository can transform files via a 404 handler |
| 265 | + * |
| 266 | + * @return bool |
263 | 267 | */ |
264 | 268 | function canTransformVia404() { |
265 | 269 | return $this->transformVia404; |
— | — | @@ -281,6 +285,11 @@ |
282 | 286 | return $name; |
283 | 287 | } |
284 | 288 | |
| 289 | + /** |
| 290 | + * @param $name |
| 291 | + * @param $levels |
| 292 | + * @return string |
| 293 | + */ |
285 | 294 | static function getHashPathForLevel( $name, $levels ) { |
286 | 295 | if ( $levels == 0 ) { |
287 | 296 | return ''; |
— | — | @@ -297,6 +306,10 @@ |
298 | 307 | /** |
299 | 308 | * Get a relative path including trailing slash, e.g. f/fa/ |
300 | 309 | * If the repo is not hashed, returns an empty string |
| 310 | + * |
| 311 | + * @param $name string |
| 312 | + * |
| 313 | + * @return string |
301 | 314 | */ |
302 | 315 | function getHashPath( $name ) { |
303 | 316 | return self::getHashPathForLevel( $name, $this->hashLevels ); |
— | — | @@ -497,6 +510,11 @@ |
498 | 511 | */ |
499 | 512 | abstract function publishBatch( $triplets, $flags = 0 ); |
500 | 513 | |
| 514 | + /** |
| 515 | + * @param $file |
| 516 | + * @param int $flags |
| 517 | + * @return bool |
| 518 | + */ |
501 | 519 | function fileExists( $file, $flags = 0 ) { |
502 | 520 | $result = $this->fileExistsBatch( array( $file ), $flags ); |
503 | 521 | return $result[0]; |
— | — | @@ -547,6 +565,8 @@ |
548 | 566 | * Get properties of a file with a given virtual URL |
549 | 567 | * The virtual URL must refer to this repo |
550 | 568 | * Properties should ultimately be obtained via File::getPropsFromPath() |
| 569 | + * |
| 570 | + * @param $virtualUrl string |
551 | 571 | */ |
552 | 572 | abstract function getFileProps( $virtualUrl ); |
553 | 573 | |
— | — | @@ -561,6 +581,10 @@ |
562 | 582 | |
563 | 583 | /** |
564 | 584 | * Determine if a relative path is valid, i.e. not blank or involving directory traveral |
| 585 | + * |
| 586 | + * @param $filename string |
| 587 | + * |
| 588 | + * @return bool |
565 | 589 | */ |
566 | 590 | function validateFilename( $filename ) { |
567 | 591 | if ( strval( $filename ) == '' ) { |
— | — | @@ -573,11 +597,11 @@ |
574 | 598 | * Use the same traversal protection as Title::secureAndSplit() |
575 | 599 | */ |
576 | 600 | if ( strpos( $filename, '.' ) !== false && |
577 | | - ( $filename === '.' || $filename === '..' || |
578 | | - strpos( $filename, './' ) === 0 || |
579 | | - strpos( $filename, '../' ) === 0 || |
580 | | - strpos( $filename, '/./' ) !== false || |
581 | | - strpos( $filename, '/../' ) !== false ) ) |
| 601 | + ( $filename === '.' || $filename === '..' || |
| 602 | + strpos( $filename, './' ) === 0 || |
| 603 | + strpos( $filename, '../' ) === 0 || |
| 604 | + strpos( $filename, '/./' ) !== false || |
| 605 | + strpos( $filename, '/../' ) !== false ) ) |
582 | 606 | { |
583 | 607 | return false; |
584 | 608 | } else { |
— | — | @@ -589,6 +613,11 @@ |
590 | 614 | * Path disclosure protection functions |
591 | 615 | */ |
592 | 616 | function paranoidClean( $param ) { return '[hidden]'; } |
| 617 | + |
| 618 | + /** |
| 619 | + * @param $param |
| 620 | + * @return |
| 621 | + */ |
593 | 622 | function passThrough( $param ) { return $param; } |
594 | 623 | |
595 | 624 | /** |
— | — | @@ -617,6 +646,8 @@ |
618 | 647 | |
619 | 648 | /** |
620 | 649 | * Create a new good result |
| 650 | + * |
| 651 | + * @return FileRepoStatus |
621 | 652 | */ |
622 | 653 | function newGood( $value = null ) { |
623 | 654 | return FileRepoStatus::newGood( $this, $value ); |
— | — | @@ -681,7 +712,6 @@ |
682 | 713 | return $this->getName() == 'local'; |
683 | 714 | } |
684 | 715 | |
685 | | - |
686 | 716 | /** |
687 | 717 | * Get a key on the primary cache for this repository. |
688 | 718 | * Returns false if the repository's cache is not accessible at this site. |
Index: trunk/phase3/includes/filerepo/File.php |
— | — | @@ -70,8 +70,18 @@ |
71 | 71 | */ |
72 | 72 | protected $handler; |
73 | 73 | |
| 74 | + protected $url, $extension, $name, $path, $hashPath, $pageCount, $transformScript; |
| 75 | + |
74 | 76 | /** |
| 77 | + * @var bool |
| 78 | + */ |
| 79 | + protected $canRender, $isSafeFile; |
| 80 | + |
| 81 | + /** |
75 | 82 | * Call this constructor from child classes |
| 83 | + * |
| 84 | + * @param $title |
| 85 | + * @param $repo |
76 | 86 | */ |
77 | 87 | function __construct( $title, $repo ) { |
78 | 88 | $this->title = $title; |
— | — | @@ -117,7 +127,7 @@ |
118 | 128 | * |
119 | 129 | * @param $old File Old file |
120 | 130 | * @param $new string New name |
121 | | - * |
| 131 | + * |
122 | 132 | * @return bool|null |
123 | 133 | */ |
124 | 134 | static function checkExtensionCompatibility( File $old, $new ) { |
— | — | @@ -217,7 +227,10 @@ |
218 | 228 | public function getFullUrl() { |
219 | 229 | return wfExpandUrl( $this->getUrl(), PROTO_RELATIVE ); |
220 | 230 | } |
221 | | - |
| 231 | + |
| 232 | + /** |
| 233 | + * @return string |
| 234 | + */ |
222 | 235 | public function getCanonicalUrl() { |
223 | 236 | return wfExpandUrl( $this->getUrl(), PROTO_CANONICAL ); |
224 | 237 | } |
— | — | @@ -292,6 +305,8 @@ |
293 | 306 | * STUB |
294 | 307 | * Overridden by LocalFile, UnregisteredLocalFile |
295 | 308 | * |
| 309 | + * @param $page int |
| 310 | + * |
296 | 311 | * @return false|number |
297 | 312 | */ |
298 | 313 | public function getHeight( $page = 1 ) { |
— | — | @@ -475,7 +490,7 @@ |
476 | 491 | |
477 | 492 | /** |
478 | 493 | * Accessor for __get() |
479 | | - * |
| 494 | + * |
480 | 495 | * @return bool |
481 | 496 | */ |
482 | 497 | protected function getIsSafeFile() { |
— | — | @@ -891,10 +906,10 @@ |
892 | 907 | |
893 | 908 | /** |
894 | 909 | * Get the relative path for an archived file |
895 | | - * |
| 910 | + * |
896 | 911 | * @param $suffix bool|string if not false, the name of an archived thumbnail file |
897 | 912 | * |
898 | | - * @return string |
| 913 | + * @return string |
899 | 914 | */ |
900 | 915 | function getArchiveRel( $suffix = false ) { |
901 | 916 | $path = 'archive/' . $this->getHashPath(); |
— | — | @@ -909,9 +924,11 @@ |
910 | 925 | /** |
911 | 926 | * Get the relative path for an archived file's thumbs directory |
912 | 927 | * or a specific thumb if the $suffix is given. |
913 | | - * |
| 928 | + * |
914 | 929 | * @param $archiveName string the timestamped name of an archived image |
915 | 930 | * @param $suffix bool|string if not false, the name of a thumbnail file |
| 931 | + * |
| 932 | + * @return string |
916 | 933 | */ |
917 | 934 | function getArchiveThumbRel( $archiveName, $suffix = false ) { |
918 | 935 | $path = 'archive/' . $this->getHashPath() . $archiveName . "/"; |
Index: trunk/phase3/includes/filerepo/ForeignAPIFile.php |
— | — | @@ -13,13 +13,13 @@ |
14 | 14 | * @ingroup FileRepo |
15 | 15 | */ |
16 | 16 | class ForeignAPIFile extends File { |
17 | | - |
| 17 | + |
18 | 18 | private $mExists; |
19 | 19 | |
20 | 20 | /** |
21 | | - * @param $title |
22 | | - * @param $repo ForeignApiRepo |
23 | | - * @param $info |
| 21 | + * @param $title |
| 22 | + * @param $repo ForeignApiRepo |
| 23 | + * @param $info |
24 | 24 | * @param bool $exists |
25 | 25 | */ |
26 | 26 | function __construct( $title, $repo, $info, $exists = false ) { |
— | — | @@ -29,8 +29,8 @@ |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
33 | | - * @param $title Title |
34 | | - * @param $repo ForeignApiRepo |
| 33 | + * @param $title Title |
| 34 | + * @param $repo ForeignApiRepo |
35 | 35 | * @return ForeignAPIFile|null |
36 | 36 | */ |
37 | 37 | static function newFromTitle( $title, $repo ) { |
— | — | @@ -61,19 +61,19 @@ |
62 | 62 | return null; |
63 | 63 | } |
64 | 64 | } |
65 | | - |
| 65 | + |
66 | 66 | /** |
67 | 67 | * Get the property string for iiprop and aiprop |
68 | 68 | */ |
69 | 69 | static function getProps() { |
70 | 70 | return 'timestamp|user|comment|url|size|sha1|metadata|mime'; |
71 | 71 | } |
72 | | - |
| 72 | + |
73 | 73 | // Dummy functions... |
74 | 74 | public function exists() { |
75 | 75 | return $this->mExists; |
76 | 76 | } |
77 | | - |
| 77 | + |
78 | 78 | public function getPath() { |
79 | 79 | return false; |
80 | 80 | } |
— | — | @@ -100,18 +100,22 @@ |
101 | 101 | public function getWidth( $page = 1 ) { |
102 | 102 | return isset( $this->mInfo['width'] ) ? intval( $this->mInfo['width'] ) : 0; |
103 | 103 | } |
104 | | - |
| 104 | + |
| 105 | + /** |
| 106 | + * @param $page int |
| 107 | + * @return int |
| 108 | + */ |
105 | 109 | public function getHeight( $page = 1 ) { |
106 | 110 | return isset( $this->mInfo['height'] ) ? intval( $this->mInfo['height'] ) : 0; |
107 | 111 | } |
108 | | - |
| 112 | + |
109 | 113 | public function getMetadata() { |
110 | 114 | if ( isset( $this->mInfo['metadata'] ) ) { |
111 | 115 | return serialize( self::parseMetadata( $this->mInfo['metadata'] ) ); |
112 | 116 | } |
113 | 117 | return null; |
114 | 118 | } |
115 | | - |
| 119 | + |
116 | 120 | public static function parseMetadata( $metadata ) { |
117 | 121 | if( !is_array( $metadata ) ) { |
118 | 122 | return $metadata; |
— | — | @@ -122,11 +126,11 @@ |
123 | 127 | } |
124 | 128 | return $ret; |
125 | 129 | } |
126 | | - |
| 130 | + |
127 | 131 | public function getSize() { |
128 | 132 | return isset( $this->mInfo['size'] ) ? intval( $this->mInfo['size'] ) : null; |
129 | 133 | } |
130 | | - |
| 134 | + |
131 | 135 | public function getUrl() { |
132 | 136 | return isset( $this->mInfo['url'] ) ? strval( $this->mInfo['url'] ) : null; |
133 | 137 | } |
— | — | @@ -134,25 +138,25 @@ |
135 | 139 | public function getUser( $method='text' ) { |
136 | 140 | return isset( $this->mInfo['user'] ) ? strval( $this->mInfo['user'] ) : null; |
137 | 141 | } |
138 | | - |
| 142 | + |
139 | 143 | public function getDescription() { |
140 | 144 | return isset( $this->mInfo['comment'] ) ? strval( $this->mInfo['comment'] ) : null; |
141 | 145 | } |
142 | 146 | |
143 | 147 | function getSha1() { |
144 | | - return isset( $this->mInfo['sha1'] ) ? |
145 | | - wfBaseConvert( strval( $this->mInfo['sha1'] ), 16, 36, 31 ) : |
| 148 | + return isset( $this->mInfo['sha1'] ) ? |
| 149 | + wfBaseConvert( strval( $this->mInfo['sha1'] ), 16, 36, 31 ) : |
146 | 150 | null; |
147 | 151 | } |
148 | | - |
| 152 | + |
149 | 153 | function getTimestamp() { |
150 | | - return wfTimestamp( TS_MW, |
| 154 | + return wfTimestamp( TS_MW, |
151 | 155 | isset( $this->mInfo['timestamp'] ) ? |
152 | | - strval( $this->mInfo['timestamp'] ) : |
| 156 | + strval( $this->mInfo['timestamp'] ) : |
153 | 157 | null |
154 | 158 | ); |
155 | 159 | } |
156 | | - |
| 160 | + |
157 | 161 | function getMimeType() { |
158 | 162 | if( !isset( $this->mInfo['mime'] ) ) { |
159 | 163 | $magic = MimeMagic::singleton(); |
— | — | @@ -160,19 +164,19 @@ |
161 | 165 | } |
162 | 166 | return $this->mInfo['mime']; |
163 | 167 | } |
164 | | - |
| 168 | + |
165 | 169 | /// @todo FIXME: May guess wrong on file types that can be eg audio or video |
166 | 170 | function getMediaType() { |
167 | 171 | $magic = MimeMagic::singleton(); |
168 | 172 | return $magic->getMediaType( null, $this->getMimeType() ); |
169 | 173 | } |
170 | | - |
| 174 | + |
171 | 175 | function getDescriptionUrl() { |
172 | 176 | return isset( $this->mInfo['descriptionurl'] ) |
173 | 177 | ? $this->mInfo['descriptionurl'] |
174 | 178 | : false; |
175 | 179 | } |
176 | | - |
| 180 | + |
177 | 181 | /** |
178 | 182 | * Only useful if we're locally caching thumbs anyway... |
179 | 183 | */ |
— | — | @@ -187,7 +191,7 @@ |
188 | 192 | return null; |
189 | 193 | } |
190 | 194 | } |
191 | | - |
| 195 | + |
192 | 196 | function getThumbnails() { |
193 | 197 | $files = array(); |
194 | 198 | $dir = $this->getThumbPath( $this->getName() ); |
— | — | @@ -204,19 +208,19 @@ |
205 | 209 | } |
206 | 210 | return $files; |
207 | 211 | } |
208 | | - |
| 212 | + |
209 | 213 | function purgeCache() { |
210 | 214 | $this->purgeThumbnails(); |
211 | 215 | $this->purgeDescriptionPage(); |
212 | 216 | } |
213 | | - |
| 217 | + |
214 | 218 | function purgeDescriptionPage() { |
215 | 219 | global $wgMemc, $wgContLang; |
216 | 220 | $url = $this->repo->getDescriptionRenderUrl( $this->getName(), $wgContLang->getCode() ); |
217 | 221 | $key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', md5($url) ); |
218 | 222 | $wgMemc->delete( $key ); |
219 | 223 | } |
220 | | - |
| 224 | + |
221 | 225 | function purgeThumbnails() { |
222 | 226 | global $wgMemc; |
223 | 227 | $key = $this->repo->getLocalCacheKey( 'ForeignAPIRepo', 'ThumbUrl', $this->getName() ); |
Index: trunk/phase3/includes/filerepo/ArchivedFile.php |
— | — | @@ -177,6 +177,9 @@ |
178 | 178 | |
179 | 179 | /** |
180 | 180 | * Loads a file object from the filearchive table |
| 181 | + * |
| 182 | + * @param $row |
| 183 | + * |
181 | 184 | * @return ArchivedFile |
182 | 185 | */ |
183 | 186 | public static function newFromRow( $row ) { |
— | — | @@ -205,6 +208,8 @@ |
206 | 209 | |
207 | 210 | /** |
208 | 211 | * Return the associated title object |
| 212 | + * |
| 213 | + * @return Title |
209 | 214 | */ |
210 | 215 | public function getTitle() { |
211 | 216 | return $this->title; |
— | — | @@ -212,16 +217,24 @@ |
213 | 218 | |
214 | 219 | /** |
215 | 220 | * Return the file name |
| 221 | + * |
| 222 | + * @return string |
216 | 223 | */ |
217 | 224 | public function getName() { |
218 | 225 | return $this->name; |
219 | 226 | } |
220 | 227 | |
| 228 | + /** |
| 229 | + * @return int |
| 230 | + */ |
221 | 231 | public function getID() { |
222 | 232 | $this->load(); |
223 | 233 | return $this->id; |
224 | 234 | } |
225 | 235 | |
| 236 | + /** |
| 237 | + * @return bool |
| 238 | + */ |
226 | 239 | public function exists() { |
227 | 240 | $this->load(); |
228 | 241 | return $this->exists; |
— | — | @@ -229,6 +242,7 @@ |
230 | 243 | |
231 | 244 | /** |
232 | 245 | * Return the FileStore key |
| 246 | + * @return string |
233 | 247 | */ |
234 | 248 | public function getKey() { |
235 | 249 | $this->load(); |
— | — | @@ -237,6 +251,7 @@ |
238 | 252 | |
239 | 253 | /** |
240 | 254 | * Return the FileStore key (overriding base File class) |
| 255 | + * @return string |
241 | 256 | */ |
242 | 257 | public function getStorageKey() { |
243 | 258 | return $this->getKey(); |
— | — | @@ -244,6 +259,7 @@ |
245 | 260 | |
246 | 261 | /** |
247 | 262 | * Return the FileStore storage group |
| 263 | + * @return string |
248 | 264 | */ |
249 | 265 | public function getGroup() { |
250 | 266 | return $this->group; |
— | — | @@ -251,6 +267,7 @@ |
252 | 268 | |
253 | 269 | /** |
254 | 270 | * Return the width of the image |
| 271 | + * @return int |
255 | 272 | */ |
256 | 273 | public function getWidth() { |
257 | 274 | $this->load(); |
— | — | @@ -259,6 +276,7 @@ |
260 | 277 | |
261 | 278 | /** |
262 | 279 | * Return the height of the image |
| 280 | + * @return int |
263 | 281 | */ |
264 | 282 | public function getHeight() { |
265 | 283 | $this->load(); |
— | — | @@ -267,6 +285,7 @@ |
268 | 286 | |
269 | 287 | /** |
270 | 288 | * Get handler-specific metadata |
| 289 | + * @return string |
271 | 290 | */ |
272 | 291 | public function getMetadata() { |
273 | 292 | $this->load(); |
— | — | @@ -275,6 +294,7 @@ |
276 | 295 | |
277 | 296 | /** |
278 | 297 | * Return the size of the image file, in bytes |
| 298 | + * @return int |
279 | 299 | */ |
280 | 300 | public function getSize() { |
281 | 301 | $this->load(); |
— | — | @@ -283,6 +303,7 @@ |
284 | 304 | |
285 | 305 | /** |
286 | 306 | * Return the bits of the image file, in bytes |
| 307 | + * @return int |
287 | 308 | */ |
288 | 309 | public function getBits() { |
289 | 310 | $this->load(); |
— | — | @@ -291,6 +312,7 @@ |
292 | 313 | |
293 | 314 | /** |
294 | 315 | * Returns the mime type of the file. |
| 316 | + * @return string |
295 | 317 | */ |
296 | 318 | public function getMimeType() { |
297 | 319 | $this->load(); |
— | — | @@ -326,6 +348,7 @@ |
327 | 349 | /** |
328 | 350 | * Return the type of the media in the file. |
329 | 351 | * Use the value returned by this function with the MEDIATYPE_xxx constants. |
| 352 | + * @return string |
330 | 353 | */ |
331 | 354 | public function getMediaType() { |
332 | 355 | $this->load(); |
— | — | @@ -334,6 +357,8 @@ |
335 | 358 | |
336 | 359 | /** |
337 | 360 | * Return upload timestamp. |
| 361 | + * |
| 362 | + * @return string |
338 | 363 | */ |
339 | 364 | public function getTimestamp() { |
340 | 365 | $this->load(); |
— | — | @@ -342,6 +367,8 @@ |
343 | 368 | |
344 | 369 | /** |
345 | 370 | * Return the user ID of the uploader. |
| 371 | + * |
| 372 | + * @return int |
346 | 373 | */ |
347 | 374 | public function getUser() { |
348 | 375 | $this->load(); |
— | — | @@ -354,6 +381,8 @@ |
355 | 382 | |
356 | 383 | /** |
357 | 384 | * Return the user name of the uploader. |
| 385 | + * |
| 386 | + * @return string |
358 | 387 | */ |
359 | 388 | public function getUserText() { |
360 | 389 | $this->load(); |
— | — | @@ -366,6 +395,8 @@ |
367 | 396 | |
368 | 397 | /** |
369 | 398 | * Return upload description. |
| 399 | + * |
| 400 | + * @return string |
370 | 401 | */ |
371 | 402 | public function getDescription() { |
372 | 403 | $this->load(); |
— | — | @@ -378,6 +409,8 @@ |
379 | 410 | |
380 | 411 | /** |
381 | 412 | * Return the user ID of the uploader. |
| 413 | + * |
| 414 | + * @return int |
382 | 415 | */ |
383 | 416 | public function getRawUser() { |
384 | 417 | $this->load(); |
— | — | @@ -386,6 +419,8 @@ |
387 | 420 | |
388 | 421 | /** |
389 | 422 | * Return the user name of the uploader. |
| 423 | + * |
| 424 | + * @return string |
390 | 425 | */ |
391 | 426 | public function getRawUserText() { |
392 | 427 | $this->load(); |
— | — | @@ -394,6 +429,8 @@ |
395 | 430 | |
396 | 431 | /** |
397 | 432 | * Return upload description. |
| 433 | + * |
| 434 | + * @return string |
398 | 435 | */ |
399 | 436 | public function getRawDescription() { |
400 | 437 | $this->load(); |
Index: trunk/phase3/includes/media/Generic.php |
— | — | @@ -200,6 +200,8 @@ |
201 | 201 | * @param $dstUrl String: destination URL to use in output HTML |
202 | 202 | * @param $params Array: arbitrary set of parameters validated by $this->validateParam() |
203 | 203 | * @param $flags Integer: a bitfield, may contain self::TRANSFORM_LATER |
| 204 | + * |
| 205 | + * @return MediaTransformOutput |
204 | 206 | */ |
205 | 207 | abstract function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ); |
206 | 208 | |