*
* @ingroup FileRepo
*/
-class LocalFile extends File
-{
+class LocalFile extends File {
/**#@+
* @private
*/
*/
function __construct( $title, $repo ) {
if( !is_object( $title ) ) {
- throw new MWException( __CLASS__.' constructor given bogus title.' );
+ throw new MWException( __CLASS__ . ' constructor given bogus title.' );
}
parent::__construct( $title, $repo );
$this->metadata = '';
* there is no access to the shared cache.
*/
function getCacheKey() {
- $hashedName = md5($this->getName());
+ $hashedName = md5( $this->getName() );
return $this->repo->getSharedCacheKey( 'file', $hashedName );
}
$cachedValues = $wgMemc->get( $key );
// Check if the key existed and belongs to this version of MediaWiki
- if ( isset($cachedValues['version']) && ( $cachedValues['version'] == MW_FILE_VERSION ) ) {
+ if ( isset( $cachedValues['version'] ) && ( $cachedValues['version'] == MW_FILE_VERSION ) ) {
wfDebug( "Pulling file metadata from cache key $key\n" );
$this->fileExists = $cachedValues['fileExists'];
if ( $this->fileExists ) {
$prefixLength = strlen( $prefix );
// Sanity check prefix once
if ( substr( key( $array ), 0, $prefixLength ) !== $prefix ) {
- throw new MWException( __METHOD__. ': incorrect $prefix parameter' );
+ throw new MWException( __METHOD__ . ': incorrect $prefix parameter' );
}
$decoded = array();
foreach ( $array as $name => $value ) {
}
$decoded['timestamp'] = wfTimestamp( TS_MW, $decoded['timestamp'] );
if ( empty( $decoded['major_mime'] ) ) {
- $decoded['mime'] = "unknown/unknown";
+ $decoded['mime'] = 'unknown/unknown';
} else {
- if (!$decoded['minor_mime']) {
- $decoded['minor_mime'] = "unknown";
+ if ( !$decoded['minor_mime'] ) {
+ $decoded['minor_mime'] = 'unknown';
}
- $decoded['mime'] = $decoded['major_mime'].'/'.$decoded['minor_mime'];
+ $decoded['mime'] = $decoded['major_mime'] . '/' . $decoded['minor_mime'];
}
# Trim zero padding from char/binary field
$decoded['sha1'] = rtrim( $decoded['sha1'], "\0" );
return $decoded;
}
- /*
+ /**
* Load file metadata from a DB result row
*/
function loadFromRow( $row, $prefix = 'img_' ) {
if ( wfReadOnly() ) {
return;
}
- if ( is_null($this->media_type) ||
+ if ( is_null( $this->media_type ) ||
$this->mime == 'image/svg'
) {
$this->upgradeRow();
# Don't destroy file info of missing files
if ( !$this->fileExists ) {
- wfDebug( __METHOD__.": file does not exist, aborting\n" );
+ wfDebug( __METHOD__ . ": file does not exist, aborting\n" );
wfProfileOut( __METHOD__ );
return;
}
wfProfileOut( __METHOD__ );
return;
}
- wfDebug(__METHOD__.': upgrading '.$this->getName()." to the current schema\n");
+ wfDebug( __METHOD__ . ': upgrading ' . $this->getName() . " to the current schema\n" );
$dbw->update( 'image',
array(
* Return the width of the image
*
* Returns false on error
- * @public
*/
- function getWidth( $page = 1 ) {
+ public function getWidth( $page = 1 ) {
$this->load();
if ( $this->isMultipage() ) {
$dim = $this->getHandler()->getPageDimensions( $this, $page );
* Return the height of the image
*
* Returns false on error
- * @public
*/
- function getHeight( $page = 1 ) {
+ public function getHeight( $page = 1 ) {
$this->load();
if ( $this->isMultipage() ) {
$dim = $this->getHandler()->getPageDimensions( $this, $page );
*
* @param $type string 'text' or 'id'
*/
- function getUser($type='text') {
+ function getUser( $type = 'text' ) {
$this->load();
if( $type == 'text' ) {
return $this->user_text;
/**
* Return the size of the image file, in bytes
- * @public
*/
- function getSize() {
+ public function getSize() {
$this->load();
return $this->size;
}
/**
* Returns true if the file file exists on disk.
* @return boolean Whether file file exist on disk.
- * @public
*/
- function exists() {
+ public function exists() {
$this->load();
return $this->fileExists;
}
// This happened occasionally due to broken migration code in 1.5
// Rename to broken-*
for ( $i = 0; $i < 100 ; $i++ ) {
- $broken = $this->repo->getZonePath('public') . "/broken-$i-$thumbName";
+ $broken = $this->repo->getZonePath( 'public' ) . "/broken-$i-$thumbName";
if ( !file_exists( $broken ) ) {
rename( $thumbPath, $broken );
break;
$handle = opendir( $dir );
if ( $handle ) {
- while ( false !== ( $file = readdir($handle) ) ) {
+ while ( false !== ( $file = readdir( $handle ) ) ) {
if ( $file{0} != '.' ) {
$files[] = $file;
}
*/
function purgeHistory() {
global $wgMemc;
- $hashedName = md5($this->getName());
+ $hashedName = md5( $this->getName() );
$oldKey = $this->repo->getSharedCacheKey( 'oldfile', $hashedName );
if ( $oldKey ) {
$wgMemc->delete( $oldKey );
/** purgeDescription inherited */
/** purgeEverything inherited */
- function getHistory($limit = null, $start = null, $end = null, $inc = true) {
+ function getHistory( $limit = null, $start = null, $end = null, $inc = true ) {
$dbr = $this->repo->getSlaveDB();
- $tables = array('oldimage');
+ $tables = array( 'oldimage' );
$fields = OldLocalFile::selectFields();
$conds = $opts = $join_conds = array();
- $eq = $inc ? "=" : "";
+ $eq = $inc ? '=' : '';
$conds[] = "oi_name = " . $dbr->addQuotes( $this->title->getDBkey() );
if( $start ) {
$conds[] = "oi_timestamp <$eq " . $dbr->addQuotes( $dbr->timestamp( $start ) );
$opts['LIMIT'] = $limit;
}
// Search backwards for time > x queries
- $order = (!$start && $end !== null) ? "ASC" : "DESC";
+ $order = ( !$start && $end !== null ) ? 'ASC' : 'DESC';
$opts['ORDER BY'] = "oi_timestamp $order";
- $opts['USE INDEX'] = array('oldimage' => 'oi_name_timestamp');
-
+ $opts['USE INDEX'] = array( 'oldimage' => 'oi_name_timestamp' );
+
wfRunHooks( 'LocalFile::getHistory', array( &$this, &$tables, &$fields,
&$conds, &$opts, &$join_conds ) );
-
+
$res = $dbr->select( $tables, $fields, $conds, __METHOD__, $opts, $join_conds );
$r = array();
- while( $row = $dbr->fetchObject($res) ) {
- $r[] = OldLocalFile::newFromRow($row, $this->repo);
+ while( $row = $dbr->fetchObject( $res ) ) {
+ $r[] = OldLocalFile::newFromRow( $row, $this->repo );
}
- if( $order == "ASC" ) {
+ if( $order == 'ASC' ) {
$r = array_reverse( $r ); // make sure it ends up descending
}
return $r;
* 0 return line for current version
* 1 query for old versions, return first one
* 2, ... return next old version from above query
- *
- * @public
*/
- function nextHistoryLine() {
+ public function nextHistoryLine() {
# Polymorphic function name to distinguish foreign and local fetches
$fname = get_class( $this ) . '::' . __FUNCTION__;
$fname
);
if ( 0 == $dbr->numRows( $this->historyRes ) ) {
- $dbr->freeResult($this->historyRes);
+ $dbr->freeResult( $this->historyRes );
$this->historyRes = null;
- return FALSE;
+ return false;
}
- } else if ( $this->historyLine == 1 ) {
- $dbr->freeResult($this->historyRes);
+ } elseif ( $this->historyLine == 1 ) {
+ $dbr->freeResult( $this->historyRes );
$this->historyRes = $dbr->select( 'oldimage', '*',
array( 'oi_name' => $this->title->getDBkey() ),
$fname,
/**
* Reset the history pointer to the first element of the history
- * @public
*/
- function resetHistory() {
+ public function resetHistory() {
$this->historyLine = 0;
- if (!is_null($this->historyRes)) {
- $this->repo->getSlaveDB()->freeResult($this->historyRes);
+ if ( !is_null( $this->historyRes ) ) {
+ $this->repo->getSlaveDB()->freeResult( $this->historyRes );
$this->historyRes = null;
}
}
// Fail now if the file isn't there
if ( !$this->fileExists ) {
- wfDebug( __METHOD__.": File ".$this->getPath()." went missing!\n" );
+ wfDebug( __METHOD__ . ": File " . $this->getPath() . " went missing!\n" );
return false;
}
$log->getRcComment(), false );
$nullRevision->insertOn( $dbw );
- wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, $latest, $user) );
+ wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $user ) );
$article->updateRevisionOn( $dbw, $nullRevision );
# Invalidate the cache for the description page
foreach ( $this->srcRels as $name => $srcRel ) {
// Skip files that have no hash (missing source).
// Keep private files where they are.
- if ( isset($hashes[$name]) && !array_key_exists($name,$privateFiles) ) {
+ if ( isset( $hashes[$name] ) && !array_key_exists( $name, $privateFiles ) ) {
$hash = $hashes[$name];
$key = $hash . $dotExt;
$dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
__METHOD__ );
}
- if( $status->successCount > 0 || !$storeBatch ) { // If store batch is empty (all files are missing), deletion is to be considered successful
+ // If store batch is empty (all files are missing), deletion is to be considered successful
+ if( $status->successCount > 0 || !$storeBatch ) {
if( !$exists ) {
- wfDebug( __METHOD__." restored {$status->successCount} items, creating a new current\n" );
+ wfDebug( __METHOD__ . " restored {$status->successCount} items, creating a new current\n" );
// Update site_stats
$site_stats = $dbw->tableName( 'site_stats' );
$this->file->purgeEverything();
} else {
- wfDebug( __METHOD__." restored {$status->successCount} as archived versions\n" );
+ wfDebug( __METHOD__ . " restored {$status->successCount} as archived versions\n" );
$this->file->purgeDescription();
$this->file->purgeHistory();
}
$this->db = $file->repo->getMasterDb();
}
- /*
+ /**
* Add the current image to the batch
*/
function addCurrent() {
$this->cur = array( $this->oldRel, $this->newRel );
}
- /*
+ /**
* Add the old versions of the image to the batch
*/
function addOlds() {
$this->db->freeResult( $result );
}
- /*
+ /**
* Perform the move.
*/
function execute() {
return $status;
}
- /*
+ /**
* Do the database updates and return a new WikiError indicating how many
* rows where updated.
*/
return $status;
}
- /*
+ /**
* Generate triplets for FSRepo::storeBatch().
*/
function getMoveTriplets() {
return $triplets;
}
- /*
+ /**
* Removes non-existent files from move batch.
*/
function removeNonexistentFiles( $triplets ) {