# Hmm... too many to fit!
if ( $cnt > 0 && $contributors->count() > $cnt ) {
$others_link = $this->othersLink();
- if ( !$showIfMax )
+ if ( !$showIfMax ) {
return $this->msg( 'othercontribs' )->rawParams(
$others_link )->params( $contributors->count() )->escaped();
+ }
}
$real_names = array();
*/
function fetchRevisions( $limit, $offset, $direction ) {
// Fail if article doesn't exist.
- if( !$this->getTitle()->exists() ) {
+ if ( !$this->getTitle()->exists() ) {
return new FakeResultWrapper( array() );
}
function getQueryInfo() {
$queryInfo = array(
- 'tables' => array( 'revision', 'user' ),
- 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
- 'conds' => array_merge(
+ 'tables' => array( 'revision', 'user' ),
+ 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
+ 'conds' => array_merge(
array( 'rev_page' => $this->getWikiPage()->getId() ),
$this->conds ),
'options' => array( 'USE INDEX' => array( 'revision' => 'page_timestamp' ) ),
'join_conds' => array(
- 'user' => Revision::userJoinCond(),
+ 'user' => Revision::userJoinCond(),
'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ),
);
ChangeTags::modifyDisplayQuery(
$batch = new LinkBatch();
$revIds = array();
foreach ( $this->mResult as $row ) {
- if( $row->rev_parent_id ) {
+ if ( $row->rev_parent_id ) {
$revIds[] = $row->rev_parent_id;
}
- if( !is_null( $row->user_name ) ) {
+ if ( !is_null( $row->user_name ) ) {
$batch->add( NS_USER, $row->user_name );
$batch->add( NS_USER_TALK, $row->user_name );
} else { # for anons or usernames of imported revisions
$this->msg( 'editundo' )->escaped(),
$undoTooltip,
array(
- 'action' => 'edit',
+ 'action' => 'edit',
'undoafter' => $prevRev->getId(),
- 'undo' => $rev->getId()
+ 'undo' => $rev->getId()
)
);
$tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
function diffButtons( $rev, $firstInList ) {
if ( $this->getNumRows() > 1 ) {
$id = $rev->getId();
- $radio = array( 'type' => 'radio', 'value' => $id );
+ $radio = array( 'type' => 'radio', 'value' => $id );
/** @todo: move title texts to javascript */
if ( $firstInList ) {
$first = Xml::element( 'input',
array_merge( $radio, array(
'style' => 'visibility:hidden',
- 'name' => 'oldid',
+ 'name' => 'oldid',
'id' => 'mw-oldid-null' ) )
);
$checkmark = array( 'checked' => 'checked' );
}
$first = Xml::element( 'input',
array_merge( $radio, $checkmark, array(
- 'name' => 'oldid',
+ 'name' => 'oldid',
'id' => "mw-oldid-$id" ) ) );
$checkmark = array();
}
$second = Xml::element( 'input',
array_merge( $radio, $checkmark, array(
- 'name' => 'diff',
+ 'name' => 'diff',
'id' => "mw-diff-$id" ) ) );
return $first . $second;
} else {
'COUNT(*)',
array(
'wl_namespace' => $title->getNamespace(),
- 'wl_title' => $title->getDBkey(),
+ 'wl_title' => $title->getDBkey(),
),
__METHOD__
);
$this->getRequest()->getQueryValues(),
array( 'title' => null, 'action' => null )
) );
- if( $this->onSubmit( array() ) ) {
+ if ( $this->onSubmit( array() ) ) {
$this->onSuccess();
}
} else {
global $wgParser;
# No longer used
- if( $this->mGen ) {
+ if ( $this->mGen ) {
return '';
}
switch ( $this->getRequest()->getText( 'direction' ) ) {
case 'next':
# output next revision, or nothing if there isn't one
- if( $oldid ) {
+ if ( $oldid ) {
$oldid = $this->getTitle()->getNextRevisionID( $oldid );
}
$oldid = $oldid ? $oldid : -1;
break;
case 'prev':
# output previous revision, or nothing if there isn't one
- if( !$oldid ) {
+ if ( !$oldid ) {
# get the current revision so we can get the penultimate one
$oldid = $this->page->getLatest();
}
} else {
$prefix = null;
wfRunHooks( 'BacklinkCacheGetPrefix', array( $table, &$prefix ) );
- if( $prefix ) {
+ if ( $prefix ) {
return $prefix;
} else {
throw new MWException( "Invalid table \"$table\" in " . __CLASS__ );
default:
$conds = null;
wfRunHooks( 'BacklinkCacheGetConditions', array( $table, $this->title, &$conds ) );
- if( !$conds ) {
+ if ( !$conds ) {
throw new MWException( "Invalid table \"$table\" in " . __CLASS__ );
}
}
* @return bool
*/
function isExpired() {
- if( !isset( $GLOBALS[$this->name] ) ) {
+ if ( !isset( $GLOBALS[$this->name] ) ) {
return true;
}
return $GLOBALS[$this->name] != $this->value;
* @return string
*/
public function fetchText() {
- if( $this->useGzip() ) {
+ if ( $this->useGzip() ) {
$fh = gzopen( $this->cachePath(), 'rb' );
return stream_get_contents( $fh );
} else {
public function getGenderOf( $username, $caller = '' ) {
global $wgUser;
- if( $username instanceof User ) {
+ if ( $username instanceof User ) {
$username = $username->getName();
}
$username = self::normalizeUsername( $username );
if ( !isset( $this->cache[$username] ) ) {
-
if ( $this->misses >= $this->missLimit && $wgUser->getName() !== $username ) {
- if( $this->misses === $this->missLimit ) {
+ if ( $this->misses === $this->missLimit ) {
$this->misses++;
wfDebug( __METHOD__ . ": too many misses, returning default onwards\n" );
}
$this->misses++;
$this->doQuery( $username, $caller );
}
-
}
/* Undefined if there is a valid username which for some reason doesn't
public function doLinkBatch( $data, $caller = '' ) {
$users = array();
foreach ( $data as $ns => $pagenames ) {
- if ( !MWNamespace::hasGenderDistinction( $ns ) ) continue;
+ if ( !MWNamespace::hasGenderDistinction( $ns ) ) {
+ continue;
+ }
foreach ( array_keys( $pagenames ) as $username ) {
$users[$username] = true;
}
// For existing users, this value will be overwritten by the correct value
$this->cache[$name] = $default;
// query only for valid names, which can be in the database
- if( User::isValidUserName( $name ) ) {
+ if ( User::isValidUserName( $name ) ) {
$usersToCheck[] = $name;
}
}
protected $caller;
function __construct( $arr = array() ) {
- foreach( $arr as $item ) {
+ foreach ( $arr as $item ) {
$this->addObj( $item );
}
}
unset( $this->mGoodLinkFields[$dbkey] );
}
- public function getGoodLinks() { return $this->mGoodLinks; }
- public function getBadLinks() { return array_keys( $this->mBadLinks ); }
+ public function getGoodLinks() {
+ return $this->mGoodLinks;
+ }
+
+ public function getBadLinks() {
+ return array_keys( $this->mBadLinks );
+ }
/**
* Add a title to the link cache, return the page_id or zero if non-existent
*/
public function addLink( $title ) {
$nt = Title::newFromDBkey( $title );
- if( $nt ) {
+ if ( $nt ) {
return $this->addLinkObj( $nt );
} else {
return 0;
}
$f = array( 'page_id', 'page_len', 'page_is_redirect', 'page_latest' );
- if ( $wgContentHandlerUseDB ) $f[] = 'page_content_model';
+ if ( $wgContentHandlerUseDB ) {
+ $f[] = 'page_content_model';
+ }
$s = $db->selectRow( 'page', $f,
array( 'page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey() ),
function load( $code = false ) {
global $wgUseLocalMessageCache;
- if( !is_string( $code ) ) {
+ if ( !is_string( $code ) ) {
# This isn't really nice, so at least make a note about it and try to
# fall back
wfDebug( __METHOD__ . " called without providing a language code\n" );
static function purge( $urlArr ) {
global $wgSquidServers, $wgHTCPMulticastRouting;
- if( !$urlArr ) {
+ if ( !$urlArr ) {
return;
}
$htcpOpCLR = 4; // HTCP CLR
// @todo FIXME: PHP doesn't support these socket constants (include/linux/in.h)
- if( !defined( "IPPROTO_IP" ) ) {
+ if ( !defined( "IPPROTO_IP" ) ) {
define( "IPPROTO_IP", 0 );
define( "IP_MULTICAST_LOOP", 34 );
define( "IP_MULTICAST_TTL", 33 );
if ( $conn ) {
// Set socket options
socket_set_option( $conn, IPPROTO_IP, IP_MULTICAST_LOOP, 0 );
- if ( $wgHTCPMulticastTTL != 1 )
+ if ( $wgHTCPMulticastTTL != 1 ) {
socket_set_option( $conn, IPPROTO_IP, IP_MULTICAST_TTL,
$wgHTCPMulticastTTL );
+ }
$urlArr = array_unique( $urlArr ); // Remove duplicates
foreach ( $urlArr as $url ) {
- if( !is_string( $url ) ) {
+ if ( !is_string( $url ) ) {
wfProfileOut( __METHOD__ );
throw new MWException( 'Bad purge URL' );
}
if ( $stat ) {
return array(
'mtime' => wfTimestamp( TS_MW, $stat['mtime'] ),
- 'size' => $stat['size']
+ 'size' => $stat['size']
);
} elseif ( !$hadError ) {
return false; // file does not exist
*/
public function __construct( $dir, array $params ) {
$path = realpath( $dir ); // normalize
- if( $path === false ) {
+ if ( $path === false ) {
$path = $dir;
}
$this->suffixStart = strlen( $path ) + 1; // size of "path/to/dir/"
*/
protected function getRelPath( $dir ) {
$path = realpath( $dir );
- if( $path === false ) {
+ if ( $path === false ) {
$path = $dir;
}
return strtr( substr( $path, $this->suffixStart ), '\\', '/' );
final protected function getScopedPHPBehaviorForOps() {
if ( php_sapi_name() != 'cli' ) { // http://bugs.php.net/bug.php?id=47540
$old = ignore_user_abort( true ); // avoid half-finished operations
- return new ScopedCallback( function() use ( $old ) { ignore_user_abort( $old ); } );
+ return new ScopedCallback( function() use ( $old ) {
+ ignore_user_abort( $old );
+ } );
}
return null;
}
: 0644;
// Get the FS backend configuration
$autoBackends[] = array(
- 'name' => $backendName,
- 'class' => 'FSFileBackend',
- 'lockManager' => 'fsLockManager',
+ 'name' => $backendName,
+ 'class' => 'FSFileBackend',
+ 'lockManager' => 'fsLockManager',
'containerPaths' => array(
- "{$repoName}-public" => "{$directory}",
- "{$repoName}-thumb" => $thumbDir,
- "{$repoName}-transcoded" => $transcodedDir,
+ "{$repoName}-public" => "{$directory}",
+ "{$repoName}-thumb" => $thumbDir,
+ "{$repoName}-transcoded" => $transcodedDir,
"{$repoName}-deleted" => $deletedDir,
- "{$repoName}-temp" => "{$directory}/temp"
+ "{$repoName}-temp" => "{$directory}/temp"
),
- 'fileMode' => $fileMode,
+ 'fileMode' => $fileMode,
);
}
unset( $config['class'] ); // backend won't need this
$this->backends[$name] = array(
- 'class' => $class,
- 'config' => $config,
+ 'class' => $class,
+ 'config' => $config,
'instance' => null
);
}
*/
final public function getOperationsInternal( array $ops ) {
$supportedOps = array(
- 'store' => 'StoreFileOp',
- 'copy' => 'CopyFileOp',
- 'move' => 'MoveFileOp',
- 'delete' => 'DeleteFileOp',
- 'create' => 'CreateFileOp',
+ 'store' => 'StoreFileOp',
+ 'copy' => 'CopyFileOp',
+ 'move' => 'MoveFileOp',
+ 'delete' => 'DeleteFileOp',
+ 'create' => 'CreateFileOp',
'describe' => 'DescribeFileOp',
- 'null' => 'NullFileOp'
+ 'null' => 'NullFileOp'
);
$performOps = array(); // array of FileOp objects
$pathsUsed = array_merge( $this->storagePathsRead(), $this->storagePathsChanged() );
foreach ( array_unique( $pathsUsed ) as $path ) {
$nullEntries[] = array( // assertion for recovery
- 'op' => 'null',
- 'path' => $path,
+ 'op' => 'null',
+ 'path' => $path,
'newSha1' => $this->fileSha1( $path, $oPredicates )
);
}
foreach ( $this->storagePathsChanged() as $path ) {
if ( $nPredicates['sha1'][$path] === false ) { // deleted
$deleteEntries[] = array(
- 'op' => 'delete',
- 'path' => $path,
+ 'op' => 'delete',
+ 'path' => $path,
'newSha1' => ''
);
} else { // created/updated
$updateEntries[] = array(
- 'op' => $this->fileExists( $path, $oPredicates ) ? 'update' : 'create',
- 'path' => $path,
+ 'op' => $this->fileExists( $path, $oPredicates ) ? 'update' : 'create',
+ 'path' => $path,
'newSha1' => $nPredicates['sha1'][$path]
);
}
$stat = array(
// Convert dates like "Tue, 03 Jan 2012 22:01:04 GMT" to TS_MW
'mtime' => wfTimestamp( TS_MW, $srcObj->last_modified ),
- 'size' => (int)$srcObj->content_length,
- 'sha1' => $srcObj->getMetadataValue( 'Sha1base36' )
+ 'size' => (int)$srcObj->content_length,
+ 'sha1' => $srcObj->getMetadataValue( 'Sha1base36' )
);
} catch ( NoSuchContainerException $e ) {
} catch ( NoSuchObjectException $e ) {
str_replace( '/swift/v1', '', // S3 API is the rgw default
$sContObj->cfs_http->getStorageUrl() . $spath ),
array(
- 'Signature' => $signature,
- 'Expires' => $expires,
+ 'Signature' => $signature,
+ 'Expires' => $expires,
'AWSAccessKeyId' => $this->rgwS3AccessKey )
);
}
foreach ( $entries as $entry ) {
$data[] = array(
'fj_batch_uuid' => $batchId,
- 'fj_backend' => $this->backend,
- 'fj_op' => $entry['op'],
- 'fj_path' => $entry['path'],
- 'fj_new_sha1' => $entry['newSha1'],
- 'fj_timestamp' => $dbw->timestamp( $now )
+ 'fj_backend' => $this->backend,
+ 'fj_op' => $entry['op'],
+ 'fj_path' => $entry['path'],
+ 'fj_new_sha1' => $entry['newSha1'],
+ 'fj_timestamp' => $dbw->timestamp( $now )
);
}
$db = $this->getConnection( $lockSrv ); // checked in isServerUp()
$bigints = array_unique( array_map(
- function( $key ) { return wfBaseConvert( substr( $key, 0, 15 ), 16, 10 ); },
+ function( $key ) {
+ return wfBaseConvert( substr( $key, 0, 15 ), 16, 10 );
+ },
array_map( array( $this, 'sha1Base16Absolute' ), $paths )
) );
$class = $config['class'];
unset( $config['class'] ); // lock manager won't need this
$this->managers[$name] = array(
- 'class' => $class,
- 'config' => $config,
+ 'class' => $class,
+ 'config' => $config,
'instance' => null
);
}
$repoName = $info['name'];
// Get the FS backend configuration
$backend = new FSFileBackend( array(
- 'name' => $info['name'] . '-backend',
- 'lockManager' => 'fsLockManager',
+ 'name' => $info['name'] . '-backend',
+ 'lockManager' => 'fsLockManager',
'containerPaths' => array(
- "{$repoName}-public" => "{$directory}",
- "{$repoName}-temp" => "{$directory}/temp",
- "{$repoName}-thumb" => $thumbDir,
- "{$repoName}-transcoded" => $transcodedDir,
+ "{$repoName}-public" => "{$directory}",
+ "{$repoName}-temp" => "{$directory}/temp",
+ "{$repoName}-thumb" => $thumbDir,
+ "{$repoName}-transcoded" => $transcodedDir,
"{$repoName}-deleted" => $deletedDir
),
- 'fileMode' => $fileMode,
+ 'fileMode' => $fileMode,
) );
// Update repo config to use this backend
$info['backend'] = $backend;
*/
public function __construct( array $info = null ) {
// Verify required settings presence
- if(
+ if (
$info === null
|| !array_key_exists( 'name', $info )
|| !array_key_exists( 'backend', $info )
}
}
$operations[] = array(
- 'op' => $opName,
- 'src' => $srcPath,
- 'dst' => $dstPath,
- 'overwrite' => $flags & self::OVERWRITE,
+ 'op' => $opName,
+ 'src' => $srcPath,
+ 'dst' => $dstPath,
+ 'overwrite' => $flags & self::OVERWRITE,
'overwriteSame' => $flags & self::OVERWRITE_SAME,
);
}
$src = $this->resolveToStoragePath( $src );
$dst = $this->resolveToStoragePath( $dst );
$operations[] = array(
- 'op' => FileBackend::isStoragePath( $src ) ? 'copy' : 'store',
- 'src' => $src,
- 'dst' => $dst,
+ 'op' => FileBackend::isStoragePath( $src ) ? 'copy' : 'store',
+ 'src' => $src,
+ 'dst' => $dst,
'disposition' => isset( $triple[2] ) ? $triple[2] : null
);
$status->merge( $this->initDirectory( dirname( $dst ) ) );
$operations = array();
foreach ( $paths as $path ) {
$operations[] = array(
- 'op' => 'delete',
- 'src' => $this->resolveToStoragePath( $path ),
+ 'op' => 'delete',
+ 'src' => $this->resolveToStoragePath( $path ),
'ignoreMissingSource' => true
);
}
// race conditions unless an functioning LockManager is used.
// LocalFile also uses SELECT FOR UPDATE for synchronization.
$operations[] = array(
- 'op' => 'copy',
- 'src' => $dstPath,
- 'dst' => $archivePath,
+ 'op' => 'copy',
+ 'src' => $dstPath,
+ 'dst' => $archivePath,
'ignoreMissingSource' => true
);
if ( FileBackend::isStoragePath( $srcPath ) ) {
if ( $flags & self::DELETE_SOURCE ) {
$operations[] = array(
- 'op' => 'move',
- 'src' => $srcPath,
- 'dst' => $dstPath,
+ 'op' => 'move',
+ 'src' => $srcPath,
+ 'dst' => $dstPath,
'overwrite' => true, // replace current
- 'headers' => $headers
+ 'headers' => $headers
);
} else {
$operations[] = array(
- 'op' => 'copy',
- 'src' => $srcPath,
- 'dst' => $dstPath,
+ 'op' => 'copy',
+ 'src' => $srcPath,
+ 'dst' => $dstPath,
'overwrite' => true, // replace current
- 'headers' => $headers
+ 'headers' => $headers
);
}
} else { // FS source path
$operations[] = array(
- 'op' => 'store',
- 'src' => $srcPath,
- 'dst' => $dstPath,
+ 'op' => 'store',
+ 'src' => $srcPath,
+ 'dst' => $dstPath,
'overwrite' => true, // replace current
- 'headers' => $headers
+ 'headers' => $headers
);
if ( $flags & self::DELETE_SOURCE ) {
$sourceFSFilesToDelete[] = $srcPath;
}
$operations[] = array(
- 'op' => 'move',
- 'src' => $srcPath,
- 'dst' => $archivePath,
+ 'op' => 'move',
+ 'src' => $srcPath,
+ 'dst' => $archivePath,
// We may have 2+ identical files being deleted,
// all of which will map to the same destination file
'overwriteSame' => true // also see bug 31792
*/
public function getTempRepo() {
return new TempFileRepo( array(
- 'name' => "{$this->name}-temp",
- 'backend' => $this->backend,
- 'zones' => array(
+ 'name' => "{$this->name}-temp",
+ 'backend' => $this->backend,
+ 'zones' => array(
'public' => array(
'container' => $this->zones['temp']['container'],
'directory' => $this->zones['temp']['directory']
),
- 'thumb' => array(
+ 'thumb' => array(
'container' => $this->zones['thumb']['container'],
'directory' => ( $this->zones['thumb']['directory'] == '' )
? 'temp'
: $this->zones['thumb']['directory'] . '/temp'
),
- 'transcoded' => array(
+ 'transcoded' => array(
'container' => $this->zones['transcoded']['container'],
'directory' => ( $this->zones['transcoded']['directory'] == '' )
? 'temp'
: $this->zones['transcoded']['directory'] . '/temp'
)
),
- 'url' => $this->getZoneUrl( 'temp' ),
- 'thumbUrl' => $this->getZoneUrl( 'thumb' ) . '/temp',
- 'transcodedUrl' => $this->getZoneUrl( 'transcoded' ) . '/temp',
+ 'url' => $this->getZoneUrl( 'temp' ),
+ 'thumbUrl' => $this->getZoneUrl( 'thumb' ) . '/temp',
+ 'transcodedUrl' => $this->getZoneUrl( 'transcoded' ) . '/temp',
'hashLevels' => $this->hashLevels // performance
) );
}
// http://commons.wikimedia.org/w/api.php
$this->mApiBase = isset( $info['apibase'] ) ? $info['apibase'] : null;
- if( isset( $info['apiThumbCacheExpiry'] ) ) {
+ if ( isset( $info['apiThumbCacheExpiry'] ) ) {
$this->apiThumbCacheExpiry = $info['apiThumbCacheExpiry'];
}
- if( isset( $info['fileCacheExpiry'] ) ) {
+ if ( isset( $info['fileCacheExpiry'] ) ) {
$this->fileCacheExpiry = $info['fileCacheExpiry'];
}
- if( !$this->scriptDirUrl ) {
+ if ( !$this->scriptDirUrl ) {
// hack for description fetches
$this->scriptDirUrl = dirname( $this->mApiBase );
}
// If we can cache thumbs we can guess sane defaults for these
- if( $this->canCacheThumbs() && !$this->url ) {
+ if ( $this->canCacheThumbs() && !$this->url ) {
$this->url = $wgLocalFileRepo['url'];
}
- if( $this->canCacheThumbs() && !$this->thumbUrl ) {
+ if ( $this->canCacheThumbs() && !$this->thumbUrl ) {
$this->thumbUrl = $this->url . '/thumb';
}
}
if ( isset( $this->mFileExists[$k] ) ) {
$results[$k] = true;
unset( $files[$k] );
- } elseif( self::isVirtualUrl( $f ) ) {
+ } elseif ( self::isVirtualUrl( $f ) ) {
# @todo FIXME: We need to be able to handle virtual
# URLs better, at least when we know they refer to the
# same repo.
$data = $this->fetchImageQuery( array( 'titles' => implode( $files, '|' ),
'prop' => 'imageinfo' ) );
- if( isset( $data['query']['pages'] ) ) {
+ if ( isset( $data['query']['pages'] ) ) {
$i = 0;
- foreach( $files as $key => $file ) {
+ foreach ( $files as $key => $file ) {
$results[$key] = $this->mFileExists[$key] = !isset( $data['query']['pages'][$i]['missing'] );
$i++;
}
$query = array_merge( $query,
array(
- 'format' => 'json',
- 'action' => 'query',
+ 'format' => 'json',
+ 'action' => 'query',
'redirects' => 'true'
) );
if ( $this->mApiBase ) {
$url = $this->makeUrl( $query, 'api' );
}
- if( !isset( $this->mQueryCache[$url] ) ) {
+ if ( !isset( $this->mQueryCache[$url] ) ) {
$key = $this->getLocalCacheKey( 'ForeignAPIRepo', 'Metadata', md5( $url ) );
$data = $wgMemc->get( $key );
- if( !$data ) {
+ if ( !$data ) {
$data = self::httpGet( $url );
if ( !$data ) {
return null;
$wgMemc->set( $key, $data, 3600 );
}
- if( count( $this->mQueryCache ) > 100 ) {
+ if ( count( $this->mQueryCache ) > 100 ) {
// Keep the cache from growing infinitely
$this->mQueryCache = array();
}
* @return bool|array
*/
function getImageInfo( $data ) {
- if( $data && isset( $data['query']['pages'] ) ) {
- foreach( $data['query']['pages'] as $info ) {
- if( isset( $info['imageinfo'][0] ) ) {
+ if ( $data && isset( $data['query']['pages'] ) ) {
+ foreach ( $data['query']['pages'] as $info ) {
+ if ( isset( $info['imageinfo'][0] ) ) {
return $info['imageinfo'][0];
}
}
*/
function findBySha1( $hash ) {
$results = $this->fetchImageQuery( array(
- 'aisha1base36' => $hash,
- 'aiprop' => ForeignAPIFile::getProps(),
- 'list' => 'allimages', ) );
+ 'aisha1base36' => $hash,
+ 'aiprop' => ForeignAPIFile::getProps(),
+ 'list' => 'allimages',
+ ) );
$ret = array();
if ( isset( $results['query']['allimages'] ) ) {
foreach ( $results['query']['allimages'] as $img ) {
// 1.14 was broken, doesn't return name attribute
- if( !isset( $img['name'] ) ) {
+ if ( !isset( $img['name'] ) ) {
continue;
}
$ret[] = new ForeignAPIFile( Title::makeTitle( NS_FILE, $img['name'] ), $this, $img );
'iiprop' => 'url|timestamp',
'iiurlwidth' => $width,
'iiurlheight' => $height,
- 'iiurlparam' => $otherParams,
+ 'iiurlparam' => $otherParams,
'prop' => 'imageinfo' ) );
$info = $this->getImageInfo( $data );
- if( $data && $info && isset( $info['thumburl'] ) ) {
+ if ( $data && $info && isset( $info['thumburl'] ) ) {
wfDebug( __METHOD__ . " got remote thumb " . $info['thumburl'] . "\n" );
$result = $info;
return $info['thumburl'];
/* Get the array of urls that we already know */
$knownThumbUrls = $wgMemc->get( $key );
- if( !$knownThumbUrls ) {
+ if ( !$knownThumbUrls ) {
/* No knownThumbUrls for this file */
$knownThumbUrls = array();
} else {
- if( isset( $knownThumbUrls[$sizekey] ) ) {
+ if ( isset( $knownThumbUrls[$sizekey] ) ) {
wfDebug( __METHOD__ . ': Got thumburl from local cache: ' .
"{$knownThumbUrls[$sizekey]} \n" );
return $knownThumbUrls[$sizekey];
$metadata = null;
$foreignUrl = $this->getThumbUrl( $name, $width, $height, $metadata, $params );
- if( !$foreignUrl ) {
+ if ( !$foreignUrl ) {
wfDebug( __METHOD__ . " Could not find thumburl\n" );
return false;
}
// We need the same filename as the remote one :)
$fileName = rawurldecode( pathinfo( $foreignUrl, PATHINFO_BASENAME ) );
- if( !$this->validateFilename( $fileName ) ) {
+ if ( !$this->validateFilename( $fileName ) ) {
wfDebug( __METHOD__ . " The deduced filename $fileName is not safe\n" );
return false;
}
$localFilename = $localPath . "/" . $fileName;
$localUrl = $this->getZoneUrl( 'thumb' ) . "/" . $this->getHashPath( $name ) . rawurlencode( $name ) . "/" . rawurlencode( $fileName );
- if( $backend->fileExists( array( 'src' => $localFilename ) )
- && isset( $metadata['timestamp'] ) )
- {
+ if ( $backend->fileExists( array( 'src' => $localFilename ) )
+ && isset( $metadata['timestamp'] ) ) {
wfDebug( __METHOD__ . " Thumbnail was already downloaded before\n" );
$modified = $backend->getFileTimestamp( array( 'src' => $localFilename ) );
$remoteModified = strtotime( $metadata['timestamp'] );
$current = time();
$diff = abs( $modified - $current );
- if( $remoteModified < $modified && $diff < $this->fileCacheExpiry ) {
+ if ( $remoteModified < $modified && $diff < $this->fileCacheExpiry ) {
/* Use our current and already downloaded thumbnail */
$knownThumbUrls[$sizekey] = $localUrl;
$wgMemc->set( $key, $knownThumbUrls, $this->apiThumbCacheExpiry );
/* There is a new Commons file, or existing thumbnail older than a month */
}
$thumb = self::httpGet( $foreignUrl );
- if( !$thumb ) {
+ if ( !$thumb ) {
wfDebug( __METHOD__ . " Could not download thumb\n" );
return false;
}
# @todo FIXME: Delete old thumbs that aren't being used. Maintenance script?
$backend->prepare( array( 'dir' => dirname( $localFilename ) ) );
$params = array( 'dst' => $localFilename, 'content' => $thumb );
- if( !$backend->quickCreate( $params )->isOK() ) {
+ if ( !$backend->quickCreate( $params )->isOK() ) {
wfDebug( __METHOD__ . " could not write to thumb path '$localFilename'\n" );
return $foreignUrl;
}
$this->dbConn = DatabaseBase::factory( $this->dbType,
array(
'host' => $this->dbServer,
- 'user' => $this->dbUser,
+ 'user' => $this->dbUser,
'password' => $this->dbPassword,
'dbname' => $this->dbName,
'flags' => $this->dbFlags,
} // else $cachedValue is false or null: cache miss
$id = $this->getArticleID( $title );
- if( !$id ) {
+ if ( !$id ) {
$wgMemc->set( $memcKey, " ", $expiry );
return false;
}
__METHOD__
);
- if( $row && $row->rd_namespace == NS_FILE ) {
+ if ( $row && $row->rd_namespace == NS_FILE ) {
$targetTitle = Title::makeTitle( $row->rd_namespace, $row->rd_title );
$wgMemc->set( $memcKey, $targetTitle->getDBkey(), $expiry );
return $targetTitle;
* @return bool|int|mixed
*/
protected function getArticleID( $title ) {
- if( !$title instanceof Title ) {
+ if ( !$title instanceof Title ) {
return 0;
}
$dbr = $this->getSlaveDB();
* @return array An Array of arrays or iterators of file objects and the hash as key
*/
function findBySha1s( array $hashes ) {
- if( !count( $hashes ) ) {
+ if ( !count( $hashes ) ) {
return array(); //empty parameter
}
}
$redir = $this->localRepo->checkRedirect( $title );
- if( $redir ) {
+ if ( $redir ) {
return $redir;
}
foreach ( $this->foreignRepos as $repo ) {
if ( !$file ) {
foreach ( $this->foreignRepos as $repo ) {
$file = $repo->findFileFromKey( $hash, $options );
- if ( $file ) break;
+ if ( $file ) {
+ break;
+ }
}
}
return $file;
$result = array_merge_recursive( $result, $repo->findBySha1s( $hashes ) );
}
//sort the merged (and presorted) sublist of each hash
- foreach( $result as $hash => $files ) {
+ foreach ( $result as $hash => $files ) {
usort( $result[$hash], 'File::compare' );
}
return $result;
* @return bool
*/
function forEachForeignRepo( $callback, $params = array() ) {
- foreach( $this->foreignRepos as $repo ) {
+ foreach ( $this->foreignRepos as $repo ) {
$args = array_merge( array( $repo ), $params );
- if( call_user_func_array( $callback, $args ) ) {
+ if ( call_user_func_array( $callback, $args ) ) {
return true;
}
}
$this->exists = false;
$this->sha1 = '';
- if( $title instanceof Title ) {
+ if ( $title instanceof Title ) {
$this->title = File::normalizeTitle( $title, 'exception' );
$this->name = $title->getDBkey();
}
}
$conds = array();
- if( $this->id > 0 ) {
+ if ( $this->id > 0 ) {
$conds['fa_id'] = $this->id;
}
- if( $this->key ) {
+ if ( $this->key ) {
$conds['fa_storage_group'] = $this->group;
$conds['fa_storage_key'] = $this->key;
}
- if( $this->title ) {
+ if ( $this->title ) {
$conds['fa_name'] = $this->title->getDBkey();
}
- if( !count( $conds ) ) {
+ if ( !count( $conds ) ) {
throw new MWException( "No specific information for retrieving archived file" );
}
- if( !$this->title || $this->title->getNamespace() == NS_FILE ) {
+ if ( !$this->title || $this->title->getNamespace() == NS_FILE ) {
$this->dataLoaded = true; // set it here, to have also true on miss
$dbr = wfGetDB( DB_SLAVE );
$row = $dbr->selectRow(
$this->user_text = $row->fa_user_text;
$this->timestamp = $row->fa_timestamp;
$this->deleted = $row->fa_deleted;
- if( isset( $row->fa_sha1 ) ) {
+ if ( isset( $row->fa_sha1 ) ) {
$this->sha1 = $row->fa_sha1;
} else {
// old row, populate from key
*/
public function getUser() {
$this->load();
- if( $this->isDeleted( File::DELETED_USER ) ) {
+ if ( $this->isDeleted( File::DELETED_USER ) ) {
return 0;
} else {
return $this->user;
*/
public function getUserText() {
$this->load();
- if( $this->isDeleted( File::DELETED_USER ) ) {
+ if ( $this->isDeleted( File::DELETED_USER ) ) {
return 0;
} else {
return $this->user_text;
*/
public function getDescription() {
$this->load();
- if( $this->isDeleted( File::DELETED_COMMENT ) ) {
+ if ( $this->isDeleted( File::DELETED_COMMENT ) ) {
return 0;
} else {
return $this->description;
'mpeg' => 'mpg',
'tiff' => 'tif',
'ogv' => 'ogg' );
- if( isset( $squish[$lower] ) ) {
+ if ( isset( $squish[$lower] ) ) {
return $squish[$lower];
- } elseif( preg_match( '/^[0-9a-z]+$/', $lower ) ) {
+ } elseif ( preg_match( '/^[0-9a-z]+$/', $lower ) ) {
return $lower;
} else {
return '';
* @return array ("text", "html") etc
*/
public static function splitMime( $mime ) {
- if( strpos( $mime, '/' ) !== false ) {
+ if ( strpos( $mime, '/' ) !== false ) {
return explode( '/', $mime, 2 );
} else {
return array( $mime, 'unknown' );
*/
static function newFromTitle( Title $title, $repo ) {
$data = $repo->fetchImageQuery( array(
- 'titles' => 'File:' . $title->getDBkey(),
- 'iiprop' => self::getProps(),
- 'prop' => 'imageinfo',
+ 'titles' => 'File:' . $title->getDBkey(),
+ 'iiprop' => self::getProps(),
+ 'prop' => 'imageinfo',
'iimetadataversion' => MediaHandler::getMetadataVersion()
) );
$info = $repo->getImageInfo( $data );
- if( $info ) {
+ if ( $info ) {
$lastRedirect = isset( $data['query']['redirects'] )
? count( $data['query']['redirects'] ) - 1
: -1;
- if( $lastRedirect >= 0 ) {
+ if ( $lastRedirect >= 0 ) {
$newtitle = Title::newFromText( $data['query']['redirects'][$lastRedirect]['to'] );
$img = new self( $newtitle, $repo, $info, true );
- if( $img ) {
+ if ( $img ) {
$img->redirectedFrom( $title->getDBkey() );
}
} else {
* @return bool|MediaTransformOutput
*/
function transform( $params, $flags = 0 ) {
- if( !$this->canRender() ) {
+ if ( !$this->canRender() ) {
// show icon
return parent::transform( $params, $flags );
}
* @return array
*/
public static function parseMetadata( $metadata ) {
- if( !is_array( $metadata ) ) {
+ if ( !is_array( $metadata ) ) {
return $metadata;
}
$ret = array();
- foreach( $metadata as $meta ) {
+ foreach ( $metadata as $meta ) {
$ret[$meta['name']] = self::parseMetadata( $meta['value'] );
}
return $ret;
* @return string
*/
function getMimeType() {
- if( !isset( $this->mInfo['mime'] ) ) {
+ if ( !isset( $this->mInfo['mime'] ) ) {
$magic = MimeMagic::singleton();
$this->mInfo['mime'] = $magic->guessTypesForExtension( $this->getExtension() );
}
$dbw->update( 'image',
array(
- 'img_size' => $this->size, // sanity
- 'img_width' => $this->width,
- 'img_height' => $this->height,
- 'img_bits' => $this->bits,
+ 'img_size' => $this->size, // sanity
+ 'img_width' => $this->width,
+ 'img_height' => $this->height,
+ 'img_bits' => $this->bits,
'img_media_type' => $this->media_type,
'img_major_mime' => $major,
'img_minor_mime' => $minor,
- 'img_metadata' => $this->metadata,
- 'img_sha1' => $this->sha1,
+ 'img_metadata' => $this->metadata,
+ 'img_sha1' => $this->sha1,
),
array( 'img_name' => $this->getName() ),
__METHOD__
$oldKey = $this->repo->getSharedCacheKey( 'oldfile', $hashedName );
// Must purge thumbnails for old versions too! bug 30192
- foreach( $this->getHistory() as $oldFile ) {
+ foreach ( $this->getHistory() as $oldFile ) {
$oldFile->purgeThumbnails();
}
// Purge the squid
if ( $wgUseSquid ) {
$urls = array();
- foreach( $files as $file ) {
+ foreach ( $files as $file ) {
$urls[] = $this->getArchiveThumbUrl( $archiveName, $file );
}
SquidUpdate::purge( $urls );
// Always purge all files from squid regardless of handler filters
if ( $wgUseSquid ) {
$urls = array();
- foreach( $files as $file ) {
+ foreach ( $files as $file ) {
$urls[] = $this->getThumbUrl( $file );
}
array_shift( $urls ); // don't purge directory
# doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
$dbw->insert( 'image',
array(
- 'img_name' => $this->getName(),
- 'img_size' => $this->size,
- 'img_width' => intval( $this->width ),
- 'img_height' => intval( $this->height ),
- 'img_bits' => $this->bits,
- 'img_media_type' => $this->media_type,
- 'img_major_mime' => $this->major_mime,
- 'img_minor_mime' => $this->minor_mime,
- 'img_timestamp' => $timestamp,
+ 'img_name' => $this->getName(),
+ 'img_size' => $this->size,
+ 'img_width' => intval( $this->width ),
+ 'img_height' => intval( $this->height ),
+ 'img_bits' => $this->bits,
+ 'img_media_type' => $this->media_type,
+ 'img_major_mime' => $this->major_mime,
+ 'img_minor_mime' => $this->minor_mime,
+ 'img_timestamp' => $timestamp,
'img_description' => $comment,
- 'img_user' => $user->getId(),
- 'img_user_text' => $user->getName(),
- 'img_metadata' => $this->metadata,
- 'img_sha1' => $this->sha1
+ 'img_user' => $user->getId(),
+ 'img_user_text' => $user->getName(),
+ 'img_metadata' => $this->metadata,
+ 'img_sha1' => $this->sha1
),
__METHOD__,
'IGNORE'
*/
function getDescriptionText() {
$revision = Revision::newFromTitle( $this->title, false, Revision::READ_NORMAL );
- if ( !$revision ) return false;
+ if ( !$revision ) {
+ return false;
+ }
$content = $revision->getContent();
- if ( !$content ) return false;
+ if ( !$content ) {
+ return false;
+ }
$pout = $content->getParserOutput( $this->title, null, new ParserOptions() );
return $pout->getText();
}
$deletedRel = $this->file->repo->getDeletedHashPath( $row->fa_storage_key ) . $row->fa_storage_key;
$deletedUrl = $this->file->repo->getVirtualUrl() . '/deleted/' . $deletedRel;
- if( isset( $row->fa_sha1 ) ) {
+ if ( isset( $row->fa_sha1 ) ) {
$sha1 = $row->fa_sha1;
} else {
// old row, populate from key
*/
public static function factory( $command, Title $title, $params = false, $id = 0 ) {
global $wgJobClasses;
- if( isset( $wgJobClasses[$command] ) ) {
+ if ( isset( $wgJobClasses[$command] ) ) {
$class = $wgJobClasses[$command];
return new $class( $title, $params, $id );
}
*/
public function getDeduplicationInfo() {
$info = array(
- 'type' => $this->getType(),
+ 'type' => $this->getType(),
'namespace' => $this->getTitle()->getNamespace(),
- 'title' => $this->getTitle()->getDBkey(),
- 'params' => $this->getParams()
+ 'title' => $this->getTitle()->getDBkey(),
+ 'params' => $this->getParams()
);
if ( is_array( $info['params'] ) ) {
// Identical jobs with different "root" jobs should count as duplicates
if ( $this->cache->add( "$key:rebuild", 1, 1800 ) ) { // lock
$pendingDbInfo = array(
'pendingDBs' => $this->findPendingWikiQueues(),
- 'timestamp' => time()
+ 'timestamp' => time()
);
for ( $attempts = 1; $attempts <= 25; ++$attempts ) {
if ( $this->cache->add( "$key:lock", 1, 60 ) ) { // lock
$res = $dbw->select( 'job', 'job_sha1',
array(
// No job_type condition since it's part of the job_sha1 hash
- 'job_sha1' => array_keys( $rowSet ),
+ 'job_sha1' => array_keys( $rowSet ),
'job_token' => '' // unclaimed
),
$method
$job->metadata['id'] = $row->job_id;
$job->id = $row->job_id; // XXX: work around broken subclasses
break; // done
- } while( true );
+ } while ( true );
return $job;
}
$dir = $gte ? 'ASC' : 'DESC';
$row = $dbw->selectRow( 'job', '*', // find a random job
array(
- 'job_cmd' => $this->type,
+ 'job_cmd' => $this->type,
'job_token' => '', // unclaimed
"job_random {$ineq} {$dbw->addQuotes( $rand )}" ),
__METHOD__,
// instead of job_random for reducing excess claim retries.
$row = $dbw->selectRow( 'job', '*', // find a random job
array(
- 'job_cmd' => $this->type,
+ 'job_cmd' => $this->type,
'job_token' => '', // unclaimed
),
__METHOD__,
if ( $row ) { // claim the job
$dbw->update( 'job', // update by PK
array(
- 'job_token' => $uuid,
+ 'job_token' => $uuid,
'job_token_timestamp' => $dbw->timestamp(),
'job_attempts = job_attempts+1' ),
array( 'job_cmd' => $this->type, 'job_id' => $row->job_id, 'job_token' => '' ),
// This uses as much of the DB wrapper functions as possible.
$dbw->update( 'job',
array(
- 'job_token' => $uuid,
+ 'job_token' => $uuid,
'job_token_timestamp' => $dbw->timestamp(),
'job_attempts = job_attempts+1' ),
array( 'job_id = (' .
return array(
'recycleAndDeleteStaleJobs' => array(
'callback' => array( $this, 'recycleAndDeleteStaleJobs' ),
- 'period' => ceil( $this->claimTTL / 2 )
+ 'period' => ceil( $this->claimTTL / 2 )
)
);
}
"job_attempts < {$dbw->addQuotes( $this->maxTries )}" ), // retries left
__METHOD__
);
- $ids = array_map( function( $o ) { return $o->job_id; }, iterator_to_array( $res ) );
+ $ids = array_map(
+ function( $o ) {
+ return $o->job_id;
+ }, iterator_to_array( $res )
+ );
if ( count( $ids ) ) {
// Reset job_token for these jobs so that other runners will pick them up.
// Set the timestamp to the current time, as it is useful to now that the job
// Get the IDs of jobs that are considered stale and should be removed. Selecting
// the IDs first means that the UPDATE can be done by primary key (less deadlocks).
$res = $dbw->select( 'job', 'job_id', $conds, __METHOD__ );
- $ids = array_map( function( $o ) { return $o->job_id; }, iterator_to_array( $res ) );
+ $ids = array_map(
+ function( $o ) {
+ return $o->job_id;
+ }, iterator_to_array( $res )
+ );
if ( count( $ids ) ) {
$dbw->delete( 'job', array( 'job_id' => $ids ), __METHOD__ );
$count += $dbw->affectedRows();
protected $cache;
const CACHE_TTL_SHORT = 30; // integer; seconds to cache info without re-validating
- const CACHE_TTL_LONG = 300; // integer; seconds to cache info that is kept up to date
+ const CACHE_TTL_LONG = 300; // integer; seconds to cache info that is kept up to date
/**
* @params include:
if ( $this->claimTTL > 0 ) {
$tasks['recycleAndDeleteStaleJobs'] = array(
'callback' => array( $this, 'recycleAndDeleteStaleJobs' ),
- 'period' => ceil( $this->claimTTL / 2 )
+ 'period' => ceil( $this->claimTTL / 2 )
);
}
if ( $this->checkDelay ) {
$tasks['releaseReadyDelayedJobs'] = array(
'callback' => array( $this, 'releaseReadyDelayedJobs' ),
- 'period' => 300 // 5 minutes
+ 'period' => 300 // 5 minutes
);
}
return $tasks;
UploadBase::setSessionStatus(
$this->params['filekey'],
array(
- 'result' => 'Success',
- 'stage' => 'assembling',
- 'filekey' => $newFileKey,
+ 'result' => 'Success',
+ 'stage' => 'assembling',
+ 'filekey' => $newFileKey,
'imageinfo' => $imageInfo,
- 'status' => Status::newGood()
+ 'status' => Status::newGood()
)
);
} catch ( MWException $e ) {
$this->params['filekey'],
array(
'result' => 'Failure',
- 'stage' => 'assembling',
+ 'stage' => 'assembling',
'status' => Status::newFatal( 'api-error-stashfailed' )
)
);
function run() {
$enotif = new EmailNotification();
// Get the user from ID (rename safe). Anons are 0, so defer to name.
- if( isset( $this->params['editorID'] ) && $this->params['editorID'] ) {
+ if ( isset( $this->params['editorID'] ) && $this->params['editorID'] ) {
$editor = User::newFromId( $this->params['editorID'] );
// B/C, only the name might be given.
} else {
array(
'table' => $this->params['table'],
'start' => $start,
- 'end' => $id - 1
+ 'end' => $id - 1
) + $rootJobParams // carry over information for de-duplication
);
$start = $id;
array(
'table' => $this->params['table'],
'start' => $start,
- 'end' => $this->params['end']
+ 'end' => $this->params['end']
) + $rootJobParams // carry over information for de-duplication
);
wfDebug( __METHOD__ . ": repartitioning into " . count( $jobs ) . " jobs\n" );
array(
'table' => $this->params['table'],
'start' => $start,
- 'end' => $end,
+ 'end' => $end,
) + $rootJobParams // carry over information for de-duplication
);
}
}
# Update file cache
- if ( $wgUseFileCache ) {
+ if ( $wgUseFileCache ) {
foreach ( $titleArray as $title ) {
HTMLFileCache::clearFileCache( $title );
}
UploadBase::setSessionStatus(
$this->params['filekey'],
array(
- 'result' => 'Success',
- 'stage' => 'publish',
- 'filename' => $upload->getLocalFile()->getName(),
+ 'result' => 'Success',
+ 'stage' => 'publish',
+ 'filename' => $upload->getLocalFile()->getName(),
'imageinfo' => $imageInfo,
- 'status' => Status::newGood()
+ 'status' => Status::newGood()
)
);
} catch ( MWException $e ) {
$this->params['filekey'],
array(
'result' => 'Failure',
- 'stage' => 'publish',
+ 'stage' => 'publish',
'status' => Status::newFatal( 'api-error-publishfailed' )
)
);
list( $start, $end ) = $batch;
$jobs[] = new RefreshLinksJob2( $this->title,
array(
- 'table' => $table,
- 'start' => $start,
- 'end' => $end,
- 'masterPos' => $masterPos,
+ 'table' => $table,
+ 'start' => $start,
+ 'end' => $end,
+ 'masterPos' => $masterPos,
) + $this->getRootJobParams() // carry over information for de-duplication
);
}