Index: trunk/phase3/includes/filerepo/LocalFile.php |
— | — | @@ -24,8 +24,7 @@ |
25 | 25 | * |
26 | 26 | * @ingroup FileRepo |
27 | 27 | */ |
28 | | -class LocalFile extends File |
29 | | -{ |
| 28 | +class LocalFile extends File { |
30 | 29 | /**#@+ |
31 | 30 | * @private |
32 | 31 | */ |
— | — | @@ -123,7 +122,7 @@ |
124 | 123 | */ |
125 | 124 | function __construct( $title, $repo ) { |
126 | 125 | if( !is_object( $title ) ) { |
127 | | - throw new MWException( __CLASS__.' constructor given bogus title.' ); |
| 126 | + throw new MWException( __CLASS__ . ' constructor given bogus title.' ); |
128 | 127 | } |
129 | 128 | parent::__construct( $title, $repo ); |
130 | 129 | $this->metadata = ''; |
— | — | @@ -137,7 +136,7 @@ |
138 | 137 | * there is no access to the shared cache. |
139 | 138 | */ |
140 | 139 | function getCacheKey() { |
141 | | - $hashedName = md5($this->getName()); |
| 140 | + $hashedName = md5( $this->getName() ); |
142 | 141 | return $this->repo->getSharedCacheKey( 'file', $hashedName ); |
143 | 142 | } |
144 | 143 | |
— | — | @@ -156,7 +155,7 @@ |
157 | 156 | $cachedValues = $wgMemc->get( $key ); |
158 | 157 | |
159 | 158 | // Check if the key existed and belongs to this version of MediaWiki |
160 | | - if ( isset($cachedValues['version']) && ( $cachedValues['version'] == MW_FILE_VERSION ) ) { |
| 159 | + if ( isset( $cachedValues['version'] ) && ( $cachedValues['version'] == MW_FILE_VERSION ) ) { |
161 | 160 | wfDebug( "Pulling file metadata from cache key $key\n" ); |
162 | 161 | $this->fileExists = $cachedValues['fileExists']; |
163 | 162 | if ( $this->fileExists ) { |
— | — | @@ -253,7 +252,7 @@ |
254 | 253 | $prefixLength = strlen( $prefix ); |
255 | 254 | // Sanity check prefix once |
256 | 255 | if ( substr( key( $array ), 0, $prefixLength ) !== $prefix ) { |
257 | | - throw new MWException( __METHOD__. ': incorrect $prefix parameter' ); |
| 256 | + throw new MWException( __METHOD__ . ': incorrect $prefix parameter' ); |
258 | 257 | } |
259 | 258 | $decoded = array(); |
260 | 259 | foreach ( $array as $name => $value ) { |
— | — | @@ -261,19 +260,19 @@ |
262 | 261 | } |
263 | 262 | $decoded['timestamp'] = wfTimestamp( TS_MW, $decoded['timestamp'] ); |
264 | 263 | if ( empty( $decoded['major_mime'] ) ) { |
265 | | - $decoded['mime'] = "unknown/unknown"; |
| 264 | + $decoded['mime'] = 'unknown/unknown'; |
266 | 265 | } else { |
267 | | - if (!$decoded['minor_mime']) { |
268 | | - $decoded['minor_mime'] = "unknown"; |
| 266 | + if ( !$decoded['minor_mime'] ) { |
| 267 | + $decoded['minor_mime'] = 'unknown'; |
269 | 268 | } |
270 | | - $decoded['mime'] = $decoded['major_mime'].'/'.$decoded['minor_mime']; |
| 269 | + $decoded['mime'] = $decoded['major_mime'] . '/' . $decoded['minor_mime']; |
271 | 270 | } |
272 | 271 | # Trim zero padding from char/binary field |
273 | 272 | $decoded['sha1'] = rtrim( $decoded['sha1'], "\0" ); |
274 | 273 | return $decoded; |
275 | 274 | } |
276 | 275 | |
277 | | - /* |
| 276 | + /** |
278 | 277 | * Load file metadata from a DB result row |
279 | 278 | */ |
280 | 279 | function loadFromRow( $row, $prefix = 'img_' ) { |
— | — | @@ -306,7 +305,7 @@ |
307 | 306 | if ( wfReadOnly() ) { |
308 | 307 | return; |
309 | 308 | } |
310 | | - if ( is_null($this->media_type) || |
| 309 | + if ( is_null( $this->media_type ) || |
311 | 310 | $this->mime == 'image/svg' |
312 | 311 | ) { |
313 | 312 | $this->upgradeRow(); |
— | — | @@ -334,7 +333,7 @@ |
335 | 334 | |
336 | 335 | # Don't destroy file info of missing files |
337 | 336 | if ( !$this->fileExists ) { |
338 | | - wfDebug( __METHOD__.": file does not exist, aborting\n" ); |
| 337 | + wfDebug( __METHOD__ . ": file does not exist, aborting\n" ); |
339 | 338 | wfProfileOut( __METHOD__ ); |
340 | 339 | return; |
341 | 340 | } |
— | — | @@ -345,7 +344,7 @@ |
346 | 345 | wfProfileOut( __METHOD__ ); |
347 | 346 | return; |
348 | 347 | } |
349 | | - wfDebug(__METHOD__.': upgrading '.$this->getName()." to the current schema\n"); |
| 348 | + wfDebug( __METHOD__ . ': upgrading ' . $this->getName() . " to the current schema\n" ); |
350 | 349 | |
351 | 350 | $dbw->update( 'image', |
352 | 351 | array( |
— | — | @@ -408,9 +407,8 @@ |
409 | 408 | * Return the width of the image |
410 | 409 | * |
411 | 410 | * Returns false on error |
412 | | - * @public |
413 | 411 | */ |
414 | | - function getWidth( $page = 1 ) { |
| 412 | + public function getWidth( $page = 1 ) { |
415 | 413 | $this->load(); |
416 | 414 | if ( $this->isMultipage() ) { |
417 | 415 | $dim = $this->getHandler()->getPageDimensions( $this, $page ); |
— | — | @@ -428,9 +426,8 @@ |
429 | 427 | * Return the height of the image |
430 | 428 | * |
431 | 429 | * Returns false on error |
432 | | - * @public |
433 | 430 | */ |
434 | | - function getHeight( $page = 1 ) { |
| 431 | + public function getHeight( $page = 1 ) { |
435 | 432 | $this->load(); |
436 | 433 | if ( $this->isMultipage() ) { |
437 | 434 | $dim = $this->getHandler()->getPageDimensions( $this, $page ); |
— | — | @@ -449,7 +446,7 @@ |
450 | 447 | * |
451 | 448 | * @param $type string 'text' or 'id' |
452 | 449 | */ |
453 | | - function getUser($type='text') { |
| 450 | + function getUser( $type = 'text' ) { |
454 | 451 | $this->load(); |
455 | 452 | if( $type == 'text' ) { |
456 | 453 | return $this->user_text; |
— | — | @@ -473,9 +470,8 @@ |
474 | 471 | |
475 | 472 | /** |
476 | 473 | * Return the size of the image file, in bytes |
477 | | - * @public |
478 | 474 | */ |
479 | | - function getSize() { |
| 475 | + public function getSize() { |
480 | 476 | $this->load(); |
481 | 477 | return $this->size; |
482 | 478 | } |
— | — | @@ -506,9 +502,8 @@ |
507 | 503 | /** |
508 | 504 | * Returns true if the file file exists on disk. |
509 | 505 | * @return boolean Whether file file exist on disk. |
510 | | - * @public |
511 | 506 | */ |
512 | | - function exists() { |
| 507 | + public function exists() { |
513 | 508 | $this->load(); |
514 | 509 | return $this->fileExists; |
515 | 510 | } |
— | — | @@ -531,7 +526,7 @@ |
532 | 527 | // This happened occasionally due to broken migration code in 1.5 |
533 | 528 | // Rename to broken-* |
534 | 529 | for ( $i = 0; $i < 100 ; $i++ ) { |
535 | | - $broken = $this->repo->getZonePath('public') . "/broken-$i-$thumbName"; |
| 530 | + $broken = $this->repo->getZonePath( 'public' ) . "/broken-$i-$thumbName"; |
536 | 531 | if ( !file_exists( $broken ) ) { |
537 | 532 | rename( $thumbPath, $broken ); |
538 | 533 | break; |
— | — | @@ -564,7 +559,7 @@ |
565 | 560 | $handle = opendir( $dir ); |
566 | 561 | |
567 | 562 | if ( $handle ) { |
568 | | - while ( false !== ( $file = readdir($handle) ) ) { |
| 563 | + while ( false !== ( $file = readdir( $handle ) ) ) { |
569 | 564 | if ( $file{0} != '.' ) { |
570 | 565 | $files[] = $file; |
571 | 566 | } |
— | — | @@ -590,7 +585,7 @@ |
591 | 586 | */ |
592 | 587 | function purgeHistory() { |
593 | 588 | global $wgMemc; |
594 | | - $hashedName = md5($this->getName()); |
| 589 | + $hashedName = md5( $this->getName() ); |
595 | 590 | $oldKey = $this->repo->getSharedCacheKey( 'oldfile', $hashedName ); |
596 | 591 | if ( $oldKey ) { |
597 | 592 | $wgMemc->delete( $oldKey ); |
— | — | @@ -639,12 +634,12 @@ |
640 | 635 | /** purgeDescription inherited */ |
641 | 636 | /** purgeEverything inherited */ |
642 | 637 | |
643 | | - function getHistory($limit = null, $start = null, $end = null, $inc = true) { |
| 638 | + function getHistory( $limit = null, $start = null, $end = null, $inc = true ) { |
644 | 639 | $dbr = $this->repo->getSlaveDB(); |
645 | | - $tables = array('oldimage'); |
| 640 | + $tables = array( 'oldimage' ); |
646 | 641 | $fields = OldLocalFile::selectFields(); |
647 | 642 | $conds = $opts = $join_conds = array(); |
648 | | - $eq = $inc ? "=" : ""; |
| 643 | + $eq = $inc ? '=' : ''; |
649 | 644 | $conds[] = "oi_name = " . $dbr->addQuotes( $this->title->getDBkey() ); |
650 | 645 | if( $start ) { |
651 | 646 | $conds[] = "oi_timestamp <$eq " . $dbr->addQuotes( $dbr->timestamp( $start ) ); |
— | — | @@ -656,19 +651,19 @@ |
657 | 652 | $opts['LIMIT'] = $limit; |
658 | 653 | } |
659 | 654 | // Search backwards for time > x queries |
660 | | - $order = (!$start && $end !== null) ? "ASC" : "DESC"; |
| 655 | + $order = ( !$start && $end !== null ) ? 'ASC' : 'DESC'; |
661 | 656 | $opts['ORDER BY'] = "oi_timestamp $order"; |
662 | | - $opts['USE INDEX'] = array('oldimage' => 'oi_name_timestamp'); |
663 | | - |
| 657 | + $opts['USE INDEX'] = array( 'oldimage' => 'oi_name_timestamp' ); |
| 658 | + |
664 | 659 | wfRunHooks( 'LocalFile::getHistory', array( &$this, &$tables, &$fields, |
665 | 660 | &$conds, &$opts, &$join_conds ) ); |
666 | | - |
| 661 | + |
667 | 662 | $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $opts, $join_conds ); |
668 | 663 | $r = array(); |
669 | | - while( $row = $dbr->fetchObject($res) ) { |
670 | | - $r[] = OldLocalFile::newFromRow($row, $this->repo); |
| 664 | + while( $row = $dbr->fetchObject( $res ) ) { |
| 665 | + $r[] = OldLocalFile::newFromRow( $row, $this->repo ); |
671 | 666 | } |
672 | | - if( $order == "ASC" ) { |
| 667 | + if( $order == 'ASC' ) { |
673 | 668 | $r = array_reverse( $r ); // make sure it ends up descending |
674 | 669 | } |
675 | 670 | return $r; |
— | — | @@ -681,10 +676,8 @@ |
682 | 677 | * 0 return line for current version |
683 | 678 | * 1 query for old versions, return first one |
684 | 679 | * 2, ... return next old version from above query |
685 | | - * |
686 | | - * @public |
687 | 680 | */ |
688 | | - function nextHistoryLine() { |
| 681 | + public function nextHistoryLine() { |
689 | 682 | # Polymorphic function name to distinguish foreign and local fetches |
690 | 683 | $fname = get_class( $this ) . '::' . __FUNCTION__; |
691 | 684 | |
— | — | @@ -702,12 +695,12 @@ |
703 | 696 | $fname |
704 | 697 | ); |
705 | 698 | if ( 0 == $dbr->numRows( $this->historyRes ) ) { |
706 | | - $dbr->freeResult($this->historyRes); |
| 699 | + $dbr->freeResult( $this->historyRes ); |
707 | 700 | $this->historyRes = null; |
708 | | - return FALSE; |
| 701 | + return false; |
709 | 702 | } |
710 | | - } else if ( $this->historyLine == 1 ) { |
711 | | - $dbr->freeResult($this->historyRes); |
| 703 | + } elseif ( $this->historyLine == 1 ) { |
| 704 | + $dbr->freeResult( $this->historyRes ); |
712 | 705 | $this->historyRes = $dbr->select( 'oldimage', '*', |
713 | 706 | array( 'oi_name' => $this->title->getDBkey() ), |
714 | 707 | $fname, |
— | — | @@ -721,12 +714,11 @@ |
722 | 715 | |
723 | 716 | /** |
724 | 717 | * Reset the history pointer to the first element of the history |
725 | | - * @public |
726 | 718 | */ |
727 | | - function resetHistory() { |
| 719 | + public function resetHistory() { |
728 | 720 | $this->historyLine = 0; |
729 | | - if (!is_null($this->historyRes)) { |
730 | | - $this->repo->getSlaveDB()->freeResult($this->historyRes); |
| 721 | + if ( !is_null( $this->historyRes ) ) { |
| 722 | + $this->repo->getSlaveDB()->freeResult( $this->historyRes ); |
731 | 723 | $this->historyRes = null; |
732 | 724 | } |
733 | 725 | } |
— | — | @@ -819,7 +811,7 @@ |
820 | 812 | |
821 | 813 | // Fail now if the file isn't there |
822 | 814 | if ( !$this->fileExists ) { |
823 | | - wfDebug( __METHOD__.": File ".$this->getPath()." went missing!\n" ); |
| 815 | + wfDebug( __METHOD__ . ": File " . $this->getPath() . " went missing!\n" ); |
824 | 816 | return false; |
825 | 817 | } |
826 | 818 | |
— | — | @@ -920,7 +912,7 @@ |
921 | 913 | $log->getRcComment(), false ); |
922 | 914 | $nullRevision->insertOn( $dbw ); |
923 | 915 | |
924 | | - wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, $latest, $user) ); |
| 916 | + wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $user ) ); |
925 | 917 | $article->updateRevisionOn( $dbw, $nullRevision ); |
926 | 918 | |
927 | 919 | # Invalidate the cache for the description page |
— | — | @@ -1428,7 +1420,7 @@ |
1429 | 1421 | foreach ( $this->srcRels as $name => $srcRel ) { |
1430 | 1422 | // Skip files that have no hash (missing source). |
1431 | 1423 | // Keep private files where they are. |
1432 | | - if ( isset($hashes[$name]) && !array_key_exists($name,$privateFiles) ) { |
| 1424 | + if ( isset( $hashes[$name] ) && !array_key_exists( $name, $privateFiles ) ) { |
1433 | 1425 | $hash = $hashes[$name]; |
1434 | 1426 | $key = $hash . $dotExt; |
1435 | 1427 | $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key; |
— | — | @@ -1721,9 +1713,10 @@ |
1722 | 1714 | __METHOD__ ); |
1723 | 1715 | } |
1724 | 1716 | |
1725 | | - if( $status->successCount > 0 || !$storeBatch ) { // If store batch is empty (all files are missing), deletion is to be considered successful |
| 1717 | + // If store batch is empty (all files are missing), deletion is to be considered successful |
| 1718 | + if( $status->successCount > 0 || !$storeBatch ) { |
1726 | 1719 | if( !$exists ) { |
1727 | | - wfDebug( __METHOD__." restored {$status->successCount} items, creating a new current\n" ); |
| 1720 | + wfDebug( __METHOD__ . " restored {$status->successCount} items, creating a new current\n" ); |
1728 | 1721 | |
1729 | 1722 | // Update site_stats |
1730 | 1723 | $site_stats = $dbw->tableName( 'site_stats' ); |
— | — | @@ -1731,7 +1724,7 @@ |
1732 | 1725 | |
1733 | 1726 | $this->file->purgeEverything(); |
1734 | 1727 | } else { |
1735 | | - wfDebug( __METHOD__." restored {$status->successCount} as archived versions\n" ); |
| 1728 | + wfDebug( __METHOD__ . " restored {$status->successCount} as archived versions\n" ); |
1736 | 1729 | $this->file->purgeDescription(); |
1737 | 1730 | $this->file->purgeHistory(); |
1738 | 1731 | } |
— | — | @@ -1807,14 +1800,14 @@ |
1808 | 1801 | $this->db = $file->repo->getMasterDb(); |
1809 | 1802 | } |
1810 | 1803 | |
1811 | | - /* |
| 1804 | + /** |
1812 | 1805 | * Add the current image to the batch |
1813 | 1806 | */ |
1814 | 1807 | function addCurrent() { |
1815 | 1808 | $this->cur = array( $this->oldRel, $this->newRel ); |
1816 | 1809 | } |
1817 | 1810 | |
1818 | | - /* |
| 1811 | + /** |
1819 | 1812 | * Add the old versions of the image to the batch |
1820 | 1813 | */ |
1821 | 1814 | function addOlds() { |
— | — | @@ -1852,7 +1845,7 @@ |
1853 | 1846 | $this->db->freeResult( $result ); |
1854 | 1847 | } |
1855 | 1848 | |
1856 | | - /* |
| 1849 | + /** |
1857 | 1850 | * Perform the move. |
1858 | 1851 | */ |
1859 | 1852 | function execute() { |
— | — | @@ -1875,7 +1868,7 @@ |
1876 | 1869 | return $status; |
1877 | 1870 | } |
1878 | 1871 | |
1879 | | - /* |
| 1872 | + /** |
1880 | 1873 | * Do the database updates and return a new WikiError indicating how many |
1881 | 1874 | * rows where updated. |
1882 | 1875 | */ |
— | — | @@ -1915,7 +1908,7 @@ |
1916 | 1909 | return $status; |
1917 | 1910 | } |
1918 | 1911 | |
1919 | | - /* |
| 1912 | + /** |
1920 | 1913 | * Generate triplets for FSRepo::storeBatch(). |
1921 | 1914 | */ |
1922 | 1915 | function getMoveTriplets() { |
— | — | @@ -1930,7 +1923,7 @@ |
1931 | 1924 | return $triplets; |
1932 | 1925 | } |
1933 | 1926 | |
1934 | | - /* |
| 1927 | + /** |
1935 | 1928 | * Removes non-existent files from move batch. |
1936 | 1929 | */ |
1937 | 1930 | function removeNonexistentFiles( $triplets ) { |