r62095 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62094‎ | r62095 | r62096 >
Date:19:31, 7 February 2010
Author:ashley
Status:ok
Tags:
Comment:
coding style tweaks, marked public functions as such
Modified paths:
  • /trunk/phase3/includes/filerepo/LocalFile.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/LocalFile.php
@@ -24,8 +24,7 @@
2525 *
2626 * @ingroup FileRepo
2727 */
28 -class LocalFile extends File
29 -{
 28+class LocalFile extends File {
3029 /**#@+
3130 * @private
3231 */
@@ -123,7 +122,7 @@
124123 */
125124 function __construct( $title, $repo ) {
126125 if( !is_object( $title ) ) {
127 - throw new MWException( __CLASS__.' constructor given bogus title.' );
 126+ throw new MWException( __CLASS__ . ' constructor given bogus title.' );
128127 }
129128 parent::__construct( $title, $repo );
130129 $this->metadata = '';
@@ -137,7 +136,7 @@
138137 * there is no access to the shared cache.
139138 */
140139 function getCacheKey() {
141 - $hashedName = md5($this->getName());
 140+ $hashedName = md5( $this->getName() );
142141 return $this->repo->getSharedCacheKey( 'file', $hashedName );
143142 }
144143
@@ -156,7 +155,7 @@
157156 $cachedValues = $wgMemc->get( $key );
158157
159158 // 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 ) ) {
161160 wfDebug( "Pulling file metadata from cache key $key\n" );
162161 $this->fileExists = $cachedValues['fileExists'];
163162 if ( $this->fileExists ) {
@@ -253,7 +252,7 @@
254253 $prefixLength = strlen( $prefix );
255254 // Sanity check prefix once
256255 if ( substr( key( $array ), 0, $prefixLength ) !== $prefix ) {
257 - throw new MWException( __METHOD__. ': incorrect $prefix parameter' );
 256+ throw new MWException( __METHOD__ . ': incorrect $prefix parameter' );
258257 }
259258 $decoded = array();
260259 foreach ( $array as $name => $value ) {
@@ -261,19 +260,19 @@
262261 }
263262 $decoded['timestamp'] = wfTimestamp( TS_MW, $decoded['timestamp'] );
264263 if ( empty( $decoded['major_mime'] ) ) {
265 - $decoded['mime'] = "unknown/unknown";
 264+ $decoded['mime'] = 'unknown/unknown';
266265 } else {
267 - if (!$decoded['minor_mime']) {
268 - $decoded['minor_mime'] = "unknown";
 266+ if ( !$decoded['minor_mime'] ) {
 267+ $decoded['minor_mime'] = 'unknown';
269268 }
270 - $decoded['mime'] = $decoded['major_mime'].'/'.$decoded['minor_mime'];
 269+ $decoded['mime'] = $decoded['major_mime'] . '/' . $decoded['minor_mime'];
271270 }
272271 # Trim zero padding from char/binary field
273272 $decoded['sha1'] = rtrim( $decoded['sha1'], "\0" );
274273 return $decoded;
275274 }
276275
277 - /*
 276+ /**
278277 * Load file metadata from a DB result row
279278 */
280279 function loadFromRow( $row, $prefix = 'img_' ) {
@@ -306,7 +305,7 @@
307306 if ( wfReadOnly() ) {
308307 return;
309308 }
310 - if ( is_null($this->media_type) ||
 309+ if ( is_null( $this->media_type ) ||
311310 $this->mime == 'image/svg'
312311 ) {
313312 $this->upgradeRow();
@@ -334,7 +333,7 @@
335334
336335 # Don't destroy file info of missing files
337336 if ( !$this->fileExists ) {
338 - wfDebug( __METHOD__.": file does not exist, aborting\n" );
 337+ wfDebug( __METHOD__ . ": file does not exist, aborting\n" );
339338 wfProfileOut( __METHOD__ );
340339 return;
341340 }
@@ -345,7 +344,7 @@
346345 wfProfileOut( __METHOD__ );
347346 return;
348347 }
349 - wfDebug(__METHOD__.': upgrading '.$this->getName()." to the current schema\n");
 348+ wfDebug( __METHOD__ . ': upgrading ' . $this->getName() . " to the current schema\n" );
350349
351350 $dbw->update( 'image',
352351 array(
@@ -408,9 +407,8 @@
409408 * Return the width of the image
410409 *
411410 * Returns false on error
412 - * @public
413411 */
414 - function getWidth( $page = 1 ) {
 412+ public function getWidth( $page = 1 ) {
415413 $this->load();
416414 if ( $this->isMultipage() ) {
417415 $dim = $this->getHandler()->getPageDimensions( $this, $page );
@@ -428,9 +426,8 @@
429427 * Return the height of the image
430428 *
431429 * Returns false on error
432 - * @public
433430 */
434 - function getHeight( $page = 1 ) {
 431+ public function getHeight( $page = 1 ) {
435432 $this->load();
436433 if ( $this->isMultipage() ) {
437434 $dim = $this->getHandler()->getPageDimensions( $this, $page );
@@ -449,7 +446,7 @@
450447 *
451448 * @param $type string 'text' or 'id'
452449 */
453 - function getUser($type='text') {
 450+ function getUser( $type = 'text' ) {
454451 $this->load();
455452 if( $type == 'text' ) {
456453 return $this->user_text;
@@ -473,9 +470,8 @@
474471
475472 /**
476473 * Return the size of the image file, in bytes
477 - * @public
478474 */
479 - function getSize() {
 475+ public function getSize() {
480476 $this->load();
481477 return $this->size;
482478 }
@@ -506,9 +502,8 @@
507503 /**
508504 * Returns true if the file file exists on disk.
509505 * @return boolean Whether file file exist on disk.
510 - * @public
511506 */
512 - function exists() {
 507+ public function exists() {
513508 $this->load();
514509 return $this->fileExists;
515510 }
@@ -531,7 +526,7 @@
532527 // This happened occasionally due to broken migration code in 1.5
533528 // Rename to broken-*
534529 for ( $i = 0; $i < 100 ; $i++ ) {
535 - $broken = $this->repo->getZonePath('public') . "/broken-$i-$thumbName";
 530+ $broken = $this->repo->getZonePath( 'public' ) . "/broken-$i-$thumbName";
536531 if ( !file_exists( $broken ) ) {
537532 rename( $thumbPath, $broken );
538533 break;
@@ -564,7 +559,7 @@
565560 $handle = opendir( $dir );
566561
567562 if ( $handle ) {
568 - while ( false !== ( $file = readdir($handle) ) ) {
 563+ while ( false !== ( $file = readdir( $handle ) ) ) {
569564 if ( $file{0} != '.' ) {
570565 $files[] = $file;
571566 }
@@ -590,7 +585,7 @@
591586 */
592587 function purgeHistory() {
593588 global $wgMemc;
594 - $hashedName = md5($this->getName());
 589+ $hashedName = md5( $this->getName() );
595590 $oldKey = $this->repo->getSharedCacheKey( 'oldfile', $hashedName );
596591 if ( $oldKey ) {
597592 $wgMemc->delete( $oldKey );
@@ -639,12 +634,12 @@
640635 /** purgeDescription inherited */
641636 /** purgeEverything inherited */
642637
643 - function getHistory($limit = null, $start = null, $end = null, $inc = true) {
 638+ function getHistory( $limit = null, $start = null, $end = null, $inc = true ) {
644639 $dbr = $this->repo->getSlaveDB();
645 - $tables = array('oldimage');
 640+ $tables = array( 'oldimage' );
646641 $fields = OldLocalFile::selectFields();
647642 $conds = $opts = $join_conds = array();
648 - $eq = $inc ? "=" : "";
 643+ $eq = $inc ? '=' : '';
649644 $conds[] = "oi_name = " . $dbr->addQuotes( $this->title->getDBkey() );
650645 if( $start ) {
651646 $conds[] = "oi_timestamp <$eq " . $dbr->addQuotes( $dbr->timestamp( $start ) );
@@ -656,19 +651,19 @@
657652 $opts['LIMIT'] = $limit;
658653 }
659654 // Search backwards for time > x queries
660 - $order = (!$start && $end !== null) ? "ASC" : "DESC";
 655+ $order = ( !$start && $end !== null ) ? 'ASC' : 'DESC';
661656 $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+
664659 wfRunHooks( 'LocalFile::getHistory', array( &$this, &$tables, &$fields,
665660 &$conds, &$opts, &$join_conds ) );
666 -
 661+
667662 $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $opts, $join_conds );
668663 $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 );
671666 }
672 - if( $order == "ASC" ) {
 667+ if( $order == 'ASC' ) {
673668 $r = array_reverse( $r ); // make sure it ends up descending
674669 }
675670 return $r;
@@ -681,10 +676,8 @@
682677 * 0 return line for current version
683678 * 1 query for old versions, return first one
684679 * 2, ... return next old version from above query
685 - *
686 - * @public
687680 */
688 - function nextHistoryLine() {
 681+ public function nextHistoryLine() {
689682 # Polymorphic function name to distinguish foreign and local fetches
690683 $fname = get_class( $this ) . '::' . __FUNCTION__;
691684
@@ -702,12 +695,12 @@
703696 $fname
704697 );
705698 if ( 0 == $dbr->numRows( $this->historyRes ) ) {
706 - $dbr->freeResult($this->historyRes);
 699+ $dbr->freeResult( $this->historyRes );
707700 $this->historyRes = null;
708 - return FALSE;
 701+ return false;
709702 }
710 - } else if ( $this->historyLine == 1 ) {
711 - $dbr->freeResult($this->historyRes);
 703+ } elseif ( $this->historyLine == 1 ) {
 704+ $dbr->freeResult( $this->historyRes );
712705 $this->historyRes = $dbr->select( 'oldimage', '*',
713706 array( 'oi_name' => $this->title->getDBkey() ),
714707 $fname,
@@ -721,12 +714,11 @@
722715
723716 /**
724717 * Reset the history pointer to the first element of the history
725 - * @public
726718 */
727 - function resetHistory() {
 719+ public function resetHistory() {
728720 $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 );
731723 $this->historyRes = null;
732724 }
733725 }
@@ -819,7 +811,7 @@
820812
821813 // Fail now if the file isn't there
822814 if ( !$this->fileExists ) {
823 - wfDebug( __METHOD__.": File ".$this->getPath()." went missing!\n" );
 815+ wfDebug( __METHOD__ . ": File " . $this->getPath() . " went missing!\n" );
824816 return false;
825817 }
826818
@@ -920,7 +912,7 @@
921913 $log->getRcComment(), false );
922914 $nullRevision->insertOn( $dbw );
923915
924 - wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, $latest, $user) );
 916+ wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $user ) );
925917 $article->updateRevisionOn( $dbw, $nullRevision );
926918
927919 # Invalidate the cache for the description page
@@ -1428,7 +1420,7 @@
14291421 foreach ( $this->srcRels as $name => $srcRel ) {
14301422 // Skip files that have no hash (missing source).
14311423 // 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 ) ) {
14331425 $hash = $hashes[$name];
14341426 $key = $hash . $dotExt;
14351427 $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
@@ -1721,9 +1713,10 @@
17221714 __METHOD__ );
17231715 }
17241716
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 ) {
17261719 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" );
17281721
17291722 // Update site_stats
17301723 $site_stats = $dbw->tableName( 'site_stats' );
@@ -1731,7 +1724,7 @@
17321725
17331726 $this->file->purgeEverything();
17341727 } else {
1735 - wfDebug( __METHOD__." restored {$status->successCount} as archived versions\n" );
 1728+ wfDebug( __METHOD__ . " restored {$status->successCount} as archived versions\n" );
17361729 $this->file->purgeDescription();
17371730 $this->file->purgeHistory();
17381731 }
@@ -1807,14 +1800,14 @@
18081801 $this->db = $file->repo->getMasterDb();
18091802 }
18101803
1811 - /*
 1804+ /**
18121805 * Add the current image to the batch
18131806 */
18141807 function addCurrent() {
18151808 $this->cur = array( $this->oldRel, $this->newRel );
18161809 }
18171810
1818 - /*
 1811+ /**
18191812 * Add the old versions of the image to the batch
18201813 */
18211814 function addOlds() {
@@ -1852,7 +1845,7 @@
18531846 $this->db->freeResult( $result );
18541847 }
18551848
1856 - /*
 1849+ /**
18571850 * Perform the move.
18581851 */
18591852 function execute() {
@@ -1875,7 +1868,7 @@
18761869 return $status;
18771870 }
18781871
1879 - /*
 1872+ /**
18801873 * Do the database updates and return a new WikiError indicating how many
18811874 * rows where updated.
18821875 */
@@ -1915,7 +1908,7 @@
19161909 return $status;
19171910 }
19181911
1919 - /*
 1912+ /**
19201913 * Generate triplets for FSRepo::storeBatch().
19211914 */
19221915 function getMoveTriplets() {
@@ -1930,7 +1923,7 @@
19311924 return $triplets;
19321925 }
19331926
1934 - /*
 1927+ /**
19351928 * Removes non-existent files from move batch.
19361929 */
19371930 function removeNonexistentFiles( $triplets ) {

Status & tagging log