Fixed spacing and removed unneeded parenthesis
[lhc/web/wiklou.git] / includes / filerepo / file / ArchivedFile.php
index e1a8547..6c4bf8a 100644 (file)
@@ -68,7 +68,7 @@ class ArchivedFile {
         * @param int $id
         * @param string $key
         */
-       function __construct( $title, $id=0, $key='' ) {
+       function __construct( $title, $id = 0, $key = '' ) {
                $this->id = -1;
                $this->title = false;
                $this->name = false;
@@ -90,16 +90,16 @@ class ArchivedFile {
                $this->exists = false;
                $this->sha1 = '';
 
-               if( $title instanceof Title ) {
+               if ( $title instanceof Title ) {
                        $this->title = File::normalizeTitle( $title, 'exception' );
                        $this->name = $title->getDBkey();
                }
 
-               if ($id) {
+               if ( $id ) {
                        $this->id = $id;
                }
 
-               if ($key) {
+               if ( $key ) {
                        $this->key = $key;
                }
 
@@ -119,48 +119,30 @@ class ArchivedFile {
                }
                $conds = array();
 
-               if( $this->id > 0 ) {
+               if ( $this->id > 0 ) {
                        $conds['fa_id'] = $this->id;
                }
-               if( $this->key ) {
+               if ( $this->key ) {
                        $conds['fa_storage_group'] = $this->group;
                        $conds['fa_storage_key'] = $this->key;
                }
-               if( $this->title ) {
+               if ( $this->title ) {
                        $conds['fa_name'] = $this->title->getDBkey();
                }
 
-               if( !count($conds)) {
+               if ( !count( $conds ) ) {
                        throw new MWException( "No specific information for retrieving archived file" );
                }
 
-               if( !$this->title || $this->title->getNamespace() == NS_FILE ) {
+               if ( !$this->title || $this->title->getNamespace() == NS_FILE ) {
                        $this->dataLoaded = true; // set it here, to have also true on miss
                        $dbr = wfGetDB( DB_SLAVE );
-                       $row = $dbr->selectRow( 'filearchive',
-                               array(
-                                       'fa_id',
-                                       'fa_name',
-                                       'fa_archive_name',
-                                       'fa_storage_key',
-                                       'fa_storage_group',
-                                       'fa_size',
-                                       'fa_bits',
-                                       'fa_width',
-                                       'fa_height',
-                                       'fa_metadata',
-                                       'fa_media_type',
-                                       'fa_major_mime',
-                                       'fa_minor_mime',
-                                       'fa_description',
-                                       'fa_user',
-                                       'fa_user_text',
-                                       'fa_timestamp',
-                                       'fa_deleted',
-                                       'fa_sha1' ),
+                       $row = $dbr->selectRow(
+                               'filearchive',
+                               self::selectFields(),
                                $conds,
                                __METHOD__,
-                               array( 'ORDER BY' => 'fa_timestamp DESC')
+                               array( 'ORDER BY' => 'fa_timestamp DESC' )
                        );
                        if ( !$row ) {
                                // this revision does not exist?
@@ -190,6 +172,34 @@ class ArchivedFile {
                return $file;
        }
 
+       /**
+        * Fields in the filearchive table
+        * @return array
+        */
+       static function selectFields() {
+               return array(
+                       'fa_id',
+                       'fa_name',
+                       'fa_archive_name',
+                       'fa_storage_key',
+                       'fa_storage_group',
+                       'fa_size',
+                       'fa_bits',
+                       'fa_width',
+                       'fa_height',
+                       'fa_metadata',
+                       'fa_media_type',
+                       'fa_major_mime',
+                       'fa_minor_mime',
+                       'fa_description',
+                       'fa_user',
+                       'fa_user_text',
+                       'fa_timestamp',
+                       'fa_deleted',
+                       'fa_sha1',
+               );
+       }
+
        /**
         * Load ArchivedFile object fields from a DB row.
         *
@@ -197,7 +207,7 @@ class ArchivedFile {
         * @since 1.21
         */
        public function loadFromRow( $row ) {
-               $this->id = intval($row->fa_id);
+               $this->id = intval( $row->fa_id );
                $this->name = $row->fa_name;
                $this->archive_name = $row->fa_archive_name;
                $this->group = $row->fa_storage_group;
@@ -214,7 +224,7 @@ class ArchivedFile {
                $this->user_text = $row->fa_user_text;
                $this->timestamp = $row->fa_timestamp;
                $this->deleted = $row->fa_deleted;
-               if( isset( $row->fa_sha1 ) ) {
+               if ( isset( $row->fa_sha1 ) ) {
                        $this->sha1 = $row->fa_sha1;
                } else {
                        // old row, populate from key
@@ -399,7 +409,7 @@ class ArchivedFile {
         */
        public function getUser() {
                $this->load();
-               if( $this->isDeleted( File::DELETED_USER ) ) {
+               if ( $this->isDeleted( File::DELETED_USER ) ) {
                        return 0;
                } else {
                        return $this->user;
@@ -413,7 +423,7 @@ class ArchivedFile {
         */
        public function getUserText() {
                $this->load();
-               if( $this->isDeleted( File::DELETED_USER ) ) {
+               if ( $this->isDeleted( File::DELETED_USER ) ) {
                        return 0;
                } else {
                        return $this->user_text;
@@ -427,7 +437,7 @@ class ArchivedFile {
         */
        public function getDescription() {
                $this->load();
-               if( $this->isDeleted( File::DELETED_COMMENT ) ) {
+               if ( $this->isDeleted( File::DELETED_COMMENT ) ) {
                        return 0;
                } else {
                        return $this->description;
@@ -481,7 +491,7 @@ class ArchivedFile {
         */
        public function isDeleted( $field ) {
                $this->load();
-               return ($this->deleted & $field) == $field;
+               return ( $this->deleted & $field ) == $field;
        }
 
        /**