Make ArchivedFile load title regardless of how constructed.
authorBrian Wolff <bawolff+wn@gmail.com>
Thu, 18 Sep 2014 19:11:42 +0000 (16:11 -0300)
committerBrian Wolff <bawolff+wn@gmail.com>
Thu, 18 Sep 2014 19:14:59 +0000 (16:14 -0300)
If someone did $f = new ArchivedFile( null, 10 ); (ie load an
archived file based on id), $f->getTitle() would always return
false. We should populate the title when loading properties
from the db to prevent this. Having $f->getTitle() return
false only sometimes is sketchy.

Change-Id: Ia9d25d6b159aa45696c318d8c4a8ef0adffb3e47

includes/filerepo/file/ArchivedFile.php

index 8bf9040..effa3ee 100644 (file)
@@ -264,6 +264,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 +275,9 @@ class ArchivedFile {
         * @return Title
         */
        public function getTitle() {
+               if ( !$this->title ) {
+                       $this->load();
+               }
                return $this->title;
        }