Merge "Don't check namespace in SpecialWantedtemplates"
[lhc/web/wiklou.git] / includes / filerepo / file / ArchivedFile.php
index 8bf9040..1aec446 100644 (file)
@@ -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;
        }
 
@@ -471,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'." );
@@ -572,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 );
        }
 }