/** @var string Upload description */
private $description;
- /** @var int User ID of uploader */
+ /** @var User|null Uploader */
private $user;
- /** @var string User name of uploader */
- private $user_text;
-
/** @var string Time of upload */
private $timestamp;
$this->mime = "unknown/unknown";
$this->media_type = '';
$this->description = '';
- $this->user = 0;
- $this->user_text = '';
+ $this->user = null;
$this->timestamp = null;
$this->deleted = 0;
$this->dataLoaded = false;
* @return array
*/
static function selectFields() {
+ global $wgActorTableSchemaMigrationStage;
+
+ if ( $wgActorTableSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
+ // If code is using this instead of self::getQueryInfo(), there's a
+ // decent chance it's going to try to directly access
+ // $row->fa_user or $row->fa_user_text and we can't give it
+ // useful values here once those aren't being written anymore.
+ throw new BadMethodCallException(
+ 'Cannot use ' . __METHOD__ . ' when $wgActorTableSchemaMigrationStage > MIGRATION_WRITE_BOTH'
+ );
+ }
+
wfDeprecated( __METHOD__, '1.31' );
return [
'fa_id',
'fa_minor_mime',
'fa_user',
'fa_user_text',
+ 'fa_actor' => $wgActorTableSchemaMigrationStage > MIGRATION_OLD ? 'fa_actor' : null,
'fa_timestamp',
'fa_deleted',
'fa_deleted_timestamp', /* Used by LocalFileRestoreBatch */
*/
public static function getQueryInfo() {
$commentQuery = CommentStore::getStore()->getJoin( 'fa_description' );
+ $actorQuery = ActorMigration::newMigration()->getJoin( 'fa_user' );
return [
- 'tables' => [ 'filearchive' ] + $commentQuery['tables'],
+ 'tables' => [ 'filearchive' ] + $commentQuery['tables'] + $actorQuery['tables'],
'fields' => [
'fa_id',
'fa_name',
'fa_media_type',
'fa_major_mime',
'fa_minor_mime',
- 'fa_user',
- 'fa_user_text',
'fa_timestamp',
'fa_deleted',
'fa_deleted_timestamp', /* Used by LocalFileRestoreBatch */
'fa_sha1',
- ] + $commentQuery['fields'],
- 'joins' => $commentQuery['joins'],
+ ] + $commentQuery['fields'] + $actorQuery['fields'],
+ 'joins' => $commentQuery['joins'] + $actorQuery['joins'],
];
}
$this->description = CommentStore::getStore()
// Legacy because $row may have come from self::selectFields()
->getCommentLegacy( wfGetDB( DB_REPLICA ), 'fa_description', $row )->text;
- $this->user = $row->fa_user;
- $this->user_text = $row->fa_user_text;
+ $this->user = User::newFromAnyId( $row->fa_user, $row->fa_user_text, $row->fa_actor );
$this->timestamp = $row->fa_timestamp;
$this->deleted = $row->fa_deleted;
if ( isset( $row->fa_sha1 ) ) {
* @note Prior to MediaWiki 1.23, this method always
* returned the user id, and was inconsistent with
* the rest of the file classes.
- * @param string $type 'text' or 'id'
- * @return int|string
+ * @param string $type 'text', 'id', or 'object'
+ * @return int|string|User|null
* @throws MWException
+ * @since 1.31 added 'object'
*/
public function getUser( $type = 'text' ) {
$this->load();
- if ( $type == 'text' ) {
- return $this->user_text;
- } elseif ( $type == 'id' ) {
- return (int)$this->user;
+ if ( $type === 'object' ) {
+ return $this->user;
+ } elseif ( $type === 'text' ) {
+ return $this->user ? $this->user->getName() : '';
+ } elseif ( $type === 'id' ) {
+ return $this->user ? $this->user->getId() : 0;
}
throw new MWException( "Unknown type '$type'." );
* @return int
*/
public function getRawUser() {
- $this->load();
-
- return $this->user;
+ return $this->getUser( 'id' );
}
/**
* @return string
*/
public function getRawUserText() {
- $this->load();
-
- return $this->user_text;
+ return $this->getUser( 'text' );
}
/**