X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Ffilerepo%2Ffile%2FArchivedFile.php;h=65e43459fefa35b3a19967c2dac036c80cad790a;hp=7f48659ba32fa10a8b333cd479719d32ef33d0e4;hb=478a58f63101f2b47d18a618296b5e7970fa3f24;hpb=587d08c5a626f8195def9f82ee83e17c85824db8 diff --git a/includes/filerepo/file/ArchivedFile.php b/includes/filerepo/file/ArchivedFile.php index 7f48659ba3..65e43459fe 100644 --- a/includes/filerepo/file/ArchivedFile.php +++ b/includes/filerepo/file/ArchivedFile.php @@ -21,6 +21,8 @@ * @ingroup FileAbstraction */ +use MediaWiki\MediaWikiServices; + /** * Class representing a row of the 'filearchive' table * @@ -63,12 +65,9 @@ class ArchivedFile { /** @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; @@ -116,8 +115,7 @@ class ArchivedFile { $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; @@ -218,9 +216,21 @@ class ArchivedFile { /** * Fields in the filearchive table * @deprecated since 1.31, use self::getQueryInfo() instead. - * @return array + * @return string[] */ 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', @@ -238,26 +248,28 @@ class ArchivedFile { '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 */ 'fa_sha1', - ] + CommentStore::newKey( 'fa_description' )->getFields(); + ] + MediaWikiServices::getInstance()->getCommentStore()->getFields( 'fa_description' ); } /** * Return the tables, fields, and join conditions to be selected to create * a new archivedfile object. * @since 1.31 - * @return array With three keys: + * @return array[] With three keys: * - tables: (string[]) to include in the `$table` to `IDatabase->select()` * - fields: (string[]) to include in the `$vars` to `IDatabase->select()` * - joins: (array) to include in the `$join_conds` to `IDatabase->select()` */ public static function getQueryInfo() { - $commentQuery = CommentStore::newKey( 'fa_description' )->getJoin(); + $commentQuery = MediaWikiServices::getInstance()->getCommentStore()->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', @@ -272,14 +284,12 @@ class ArchivedFile { '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'], ]; } @@ -302,11 +312,10 @@ class ArchivedFile { $this->metadata = $row->fa_metadata; $this->mime = "$row->fa_major_mime/$row->fa_minor_mime"; $this->media_type = $row->fa_media_type; - $this->description = CommentStore::newKey( 'fa_description' ) + $this->description = MediaWikiServices::getInstance()->getCommentStore() // Legacy because $row may have come from self::selectFields() - ->getCommentLegacy( wfGetDB( DB_REPLICA ), $row )->text; - $this->user = $row->fa_user; - $this->user_text = $row->fa_user_text; + ->getCommentLegacy( wfGetDB( DB_REPLICA ), 'fa_description', $row )->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 ) ) { @@ -519,17 +528,20 @@ class ArchivedFile { * @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'." ); @@ -555,9 +567,7 @@ class ArchivedFile { * @return int */ public function getRawUser() { - $this->load(); - - return $this->user; + return $this->getUser( 'id' ); } /** @@ -566,9 +576,7 @@ class ArchivedFile { * @return string */ public function getRawUserText() { - $this->load(); - - return $this->user_text; + return $this->getUser( 'text' ); } /**