const OVERWRITE_SAME = 4;
const SKIP_LOCKING = 8;
- const TIME_ONLY = 1;
+ const NAME_AND_TIME_ONLY = 1;
/** @var bool Whether to fetch commons image description pages and display
* them on the local wiki */
*
* No title should appear in $items twice, as the result use titles as keys
* @param int $flags Supports:
- * - FileRepo::TIME_ONLY : return a (file name => timestamp) map instead
+ * - FileRepo::NAME_AND_TIME_ONLY : return a (search title => (title,timestamp)) map.
+ * The search title uses the input titles; the other is the final post-redirect title.
+ * All titles are returned as string DB keys and the inner array is associative.
* @return array Map of (file name => File objects) for matches
*/
public function findFiles( array $items, $flags = 0 ) {
}
$file = $this->findFile( $title, $options );
if ( $file ) {
- $result[$title->getDBkey()] =
- ( $flags & self::TIME_ONLY ) ? $file->getTimestamp() : $file;
+ $searchName = File::normalizeTitle( $title )->getDBkey(); // must be valid
+ if ( $flags & self::NAME_AND_TIME_ONLY ) {
+ $result[$searchName] = array(
+ 'title' => $file->getTitle()->getDBkey(),
+ 'timestamp' => $file->getTimestamp()
+ );
+ } else {
+ $result[$searchName] = $file;
+ }
}
}
public function findFiles( array $items, $flags = 0 ) {
$finalFiles = array(); // map of (DB key => corresponding File) for matches
- $searchSet = array(); // map of (DB key => normalized search params)
+ $searchSet = array(); // map of (normalized DB key => search params)
foreach ( $items as $item ) {
- $title = is_array( $item )
- ? File::normalizeTitle( $item['title'] )
- : File::normalizeTitle( $item );
- if ( $title ) { // valid title
- $searchSet[$title->getDbKey()] = ( is_array( $item ) ? $item : array() );
+ if ( is_array( $item ) ) {
+ $title = File::normalizeTitle( $item['title'] );
+ if ( $title ) {
+ $searchSet[$title->getDBkey()] = $item;
+ }
+ } else {
+ $title = File::normalizeTitle( $item );
+ if ( $title ) {
+ $searchSet[$title->getDBkey()] = array();
+ }
}
}
{
foreach ( $res as $row ) {
$file = $repo->newFileFromRow( $row );
- $dbKey = $file->getName();
- // There must have been a search for this DB Key
+ $dbKey = $file->getTitle()->getDBkey();
+ // There must have been a search for this exact DB Key
if ( $fileMatchesSearch( $file, $searchSet[$dbKey] ) ) {
- $finalFiles[$dbKey] =
- ( $flags & FileRepo::TIME_ONLY ) ? $file->getTimestamp() : $file;
+ $finalFiles[$dbKey] = ( $flags & FileRepo::NAME_AND_TIME_ONLY )
+ ? array( 'title' => $dbKey, 'timestamp' => $file->getTimestamp() )
+ : $file;
unset( $searchSet[$dbKey] );
}
}
$dbr = $this->getSlaveDB();
// Query image table
- $imgNames = array_keys( $searchSet );
+ $imgNames = array();
+ foreach ( array_keys( $searchSet ) as $dbKey ) {
+ $imgNames[] = $this->getNameFromTitle( File::normalizeTitle( $dbKey ) );
+ }
if ( count( $imgNames ) ) {
$res = $dbr->select( 'image',
LocalFile::selectFields(), array( 'img_name' => $imgNames ), __METHOD__ );
$oiConds = array(); // WHERE clause array for each file
foreach ( $searchSet as $dbKey => $search ) {
if ( isset( $search['params']['time'] ) ) {
- $oiConds[] = $dbr->makeList( array( 'oi_name' => $dbKey,
- 'oi_timestamp' => $dbr->timestamp( $search['params']['time'] ) ), LIST_AND );
+ $oiConds[] = $dbr->makeList(
+ array(
+ 'oi_name' => $this->getNameFromTitle( File::normalizeTitle( $dbKey ) ),
+ 'oi_timestamp' => $dbr->timestamp( $search['params']['time'] )
+ ),
+ LIST_AND
+ );
}
}
if ( count( $oiConds ) ) {
$file = $this->newFile( $redir );
if ( $file && $fileMatchesSearch( $file, $search ) ) {
$file->redirectedFrom( $title->getDBkey() );
- $finalFiles[$dbKey] =
- ( $flags & FileRepo::TIME_ONLY ) ? $file->getTimestamp() : $file;
+ if ( $flags & FileRepo::NAME_AND_TIME_ONLY ) {
+ $finalFiles[$dbKey] = array(
+ 'title' => $file->getTitle()->getDBkey(),
+ 'timestamp' => $file->getTimestamp()
+ );
+ } else {
+ $finalFiles[$dbKey] = $file;
+ }
}
}
}
}
/**
+ * Search repositories for many files at once.
+ *
+ * @param array $items An array of titles, or an array of findFile() options with
+ * the "title" option giving the title. Example:
+ *
+ * $findItem = array( 'title' => $title, 'private' => true );
+ * $findBatch = array( $findItem );
+ * $repo->findFiles( $findBatch );
+ *
+ * No title should appear in $items twice, as the result use titles as keys
+ * @param int $flags Supports:
+ * - FileRepo::NAME_AND_TIME_ONLY : return a (search title => (title,timestamp)) map.
+ * The search title uses the input titles; the other is the final post-redirect title.
+ * All titles are returned as string DB keys and the inner array is associative.
+ * @return array Map of (file name => File objects) for matches
+ *
* @param array $inputItems
+ * @param integer $flags
* @return array
*/
- function findFiles( $inputItems ) {
+ function findFiles( array $inputItems, $flags = 0 ) {
if ( !$this->reposInitialised ) {
$this->initialiseRepos();
}
}
}
- $images = $this->localRepo->findFiles( $items );
+ $images = $this->localRepo->findFiles( $items, $flags );
foreach ( $this->foreignRepos as $repo ) {
// Remove found files from $items
unset( $items[$name] );
}
- $images = array_merge( $images, $repo->findFiles( $items ) );
+ $images = array_merge( $images, $repo->findFiles( $items, $flags ) );
}
return $images;