X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ffilerepo%2Ffile%2FArchivedFile.php;h=1d45428310131baab9775582d6389980f134dede;hb=59ebff658ce912c1b0e7ef8d8f9bfec5a4e17b39;hp=a71acdeba03059f138b6f123939ab455979b5536;hpb=7eddc5caaaa92108836c8191b16520f862af94ce;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/filerepo/file/ArchivedFile.php b/includes/filerepo/file/ArchivedFile.php index a71acdeba0..1aec446412 100644 --- a/includes/filerepo/file/ArchivedFile.php +++ b/includes/filerepo/file/ArchivedFile.php @@ -100,8 +100,9 @@ class ArchivedFile { * @param Title $title * @param int $id * @param string $key + * @param string $sha1 */ - function __construct( $title, $id = 0, $key = '' ) { + function __construct( $title, $id = 0, $key = '', $sha1 = '' ) { $this->id = -1; $this->title = false; $this->name = false; @@ -136,7 +137,11 @@ class ArchivedFile { $this->key = $key; } - if ( !$id && !$key && !( $title instanceof Title ) ) { + if ( $sha1 ) { + $this->sha1 = $sha1; + } + + if ( !$id && !$key && !( $title instanceof Title ) && !$sha1 ) { throw new MWException( "No specifications provided to ArchivedFile constructor." ); } } @@ -162,6 +167,9 @@ class ArchivedFile { if ( $this->title ) { $conds['fa_name'] = $this->title->getDBkey(); } + if ( $this->sha1 ) { + $conds['fa_sha1'] = $this->sha1; + } if ( !count( $conds ) ) { throw new MWException( "No specific information for retrieving archived file" ); @@ -264,6 +272,9 @@ class ArchivedFile { // old row, populate from key $this->sha1 = LocalRepo::getHashFromKey( $this->key ); } + if ( !$this->title ) { + $this->title = Title::makeTitleSafe( NS_FILE, $row->fa_name ); + } } /** @@ -272,6 +283,9 @@ class ArchivedFile { * @return Title */ public function getTitle() { + if ( !$this->title ) { + $this->load(); + } return $this->title; } @@ -407,6 +421,7 @@ class ArchivedFile { /** * Returns the number of pages of a multipage document, or false for * documents which aren't multipage documents + * @return bool|int */ function pageCount() { if ( !isset( $this->pageCount ) ) { @@ -470,7 +485,7 @@ class ArchivedFile { if ( $type == 'text' ) { return $this->user_text; } elseif ( $type == 'id' ) { - return $this->user; + return (int)$this->user; } throw new MWException( "Unknown type '$type'." ); @@ -571,6 +586,7 @@ class ArchivedFile { public function userCan( $field, User $user = null ) { $this->load(); - return Revision::userCanBitfield( $this->deleted, $field, $user ); + $title = $this->getTitle(); + return Revision::userCanBitfield( $this->deleted, $field, $user, $title ?: null ); } }