* (bug 27588) list=filearchive&faprop=sha1 returns empty attribute
[lhc/web/wiklou.git] / includes / filerepo / OldLocalFile.php
index 4c31997..0d224fc 100644 (file)
@@ -1,4 +1,10 @@
 <?php
+/**
+ * Old file in the in the oldimage table
+ *
+ * @file
+ * @ingroup FileRepo
+ */
 
 /**
  * Class to represent a file in the oldimage table
@@ -28,16 +34,21 @@ class OldLocalFile extends LocalFile {
                $file->loadFromRow( $row, 'oi_' );
                return $file;
        }
-       
-       static function newFromKey( $sha1, $repo, $timestamp = false ) {
-               # Polymorphic function name to distinguish foreign and local fetches
-               $fname = get_class( $this ) . '::' . __FUNCTION__;
 
+       /**
+        * @static
+        * @param  $sha1
+        * @param $repo LocalRepo
+        * @param bool $timestamp
+        * @return bool|OldLocalFile
+        */
+       static function newFromKey( $sha1, $repo, $timestamp = false ) {
                $conds = array( 'oi_sha1' => $sha1 );
                if( $timestamp ) {
                        $conds['oi_timestamp'] = $timestamp;
                }
-               $row = $dbr->selectRow( 'oldimage', $this->getCacheFields( 'oi_' ), $conds, $fname );
+               $dbr = $repo->getSlaveDB();
+               $row = $dbr->selectRow( 'oldimage', self::selectFields(), $conds, __METHOD__ );
                if( $row ) {
                        return self::newFromRow( $row, $repo );
                } else {
@@ -70,10 +81,10 @@ class OldLocalFile extends LocalFile {
        }
 
        /**
-        * @param Title $title
-        * @param FileRepo $repo
-        * @param string $time Timestamp or null to load by archive name
-        * @param string $archiveName Archive name or null to load by timestamp
+        * @param $title Title
+        * @param $repo FileRepo
+        * @param $time String: timestamp or null to load by archive name
+        * @param $archiveName String: archive name or null to load by timestamp
         */
        function __construct( $title, $repo, $time, $archiveName ) {
                parent::__construct( $title, $repo );
@@ -135,7 +146,7 @@ class OldLocalFile extends LocalFile {
        }
 
        function getUrlRel() {
-               return 'archive/' . $this->getHashPath() . urlencode( $this->getArchiveName() );
+               return 'archive/' . $this->getHashPath() . rawurlencode( $this->getArchiveName() );
        }
 
        function upgradeRow() {
@@ -172,11 +183,12 @@ class OldLocalFile extends LocalFile {
        }
 
        /**
-        * int $field one of DELETED_* bitfield constants
-        * for file or revision rows
+        * @param $field Integer: one of DELETED_* bitfield constants
+        *               for file or revision rows
         * @return bool
         */
        function isDeleted( $field ) {
+               $this->load();
                return ($this->deleted & $field) == $field;
        }
 
@@ -185,25 +197,19 @@ class OldLocalFile extends LocalFile {
         * @return int
         */
        function getVisibility() {
+               $this->load();
                return (int)$this->deleted;
        }
 
        /**
         * Determine if the current user is allowed to view a particular
         * field of this image file, if it's marked as deleted.
-        * @param int $field
+        *
+        * @param $field Integer
         * @return bool
         */
        function userCan( $field ) {
-               if( isset($this->deleted) && ($this->deleted & $field) ) {
-                       global $wgUser;
-                       $permission = ( $this->deleted & File::DELETED_RESTRICTED )
-                               ? 'suppressrevision'
-                               : ( $field & File::DELETED_FILE ) ? 'deletedtext' : 'deletedhistory';
-                       wfDebug( "Checking for $permission due to $field match on $this->mDeleted\n" );
-                       return $wgUser->isAllowed( $permission );
-               } else {
-                       return true;
-               }
+               $this->load();
+               return Revision::userCanBitfield( $this->deleted, $field );
        }
 }