Merge "copy paste comment should probably have end instead of start"
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index b07186d..3be66d3 100644 (file)
@@ -604,7 +604,7 @@ class LocalFile extends File {
         * Return the width of the image
         *
         * @param $page int
-        * @return bool|int Returns false on error
+        * @return int
         */
        public function getWidth( $page = 1 ) {
                $this->load();
@@ -614,7 +614,9 @@ class LocalFile extends File {
                        if ( $dim ) {
                                return $dim['width'];
                        } else {
-                               return false;
+                               // For non-paged media, the false goes through an
+                               // intval, turning failure into 0, so do same here.
+                               return 0;
                        }
                } else {
                        return $this->width;
@@ -625,7 +627,7 @@ class LocalFile extends File {
         * Return the height of the image
         *
         * @param $page int
-        * @return bool|int Returns false on error
+        * @return int
         */
        public function getHeight( $page = 1 ) {
                $this->load();
@@ -635,7 +637,9 @@ class LocalFile extends File {
                        if ( $dim ) {
                                return $dim['height'];
                        } else {
-                               return false;
+                               // For non-paged media, the false goes through an
+                               // intval, turning failure into 0, so do same here.
+                               return 0;
                        }
                } else {
                        return $this->height;
@@ -1294,11 +1298,16 @@ class LocalFile extends File {
                // creation, page doesn't exist yet, so log_page = 0
                // but we want it to point to the page we're making,
                // so we later modify the log entry.
+               // For a similar reason, we avoid making an RC entry
+               // now and wait until the page exists.
                $logId = $logEntry->insert();
-               $logEntry->publish( $logId );
 
-               wfProfileIn( __METHOD__ . '-edit' );
                $exists = $descTitle->exists();
+               if ( $exists ) {
+                       // Page exists, do RC entry now (otherwise we wait for later).
+                       $logEntry->publish( $logId );
+               }
+               wfProfileIn( __METHOD__ . '-edit' );
 
                if ( $exists ) {
                        # Create a null revision
@@ -1336,16 +1345,20 @@ class LocalFile extends File {
                        $content = ContentHandler::makeContent( $pageText, $descTitle );
                        $status = $wikiPage->doEditContent( $content, $comment, EDIT_NEW | EDIT_SUPPRESS_RC, false, $user );
 
-                       if ( isset( $status->value['revision'] ) ) { // XXX; doEdit() uses a transaction
-                               $dbw->begin( __METHOD__ );
+                       $dbw->begin( __METHOD__ ); // XXX; doEdit() uses a transaction
+                       // Now that the page exists, make an RC entry.
+                       $logEntry->publish( $logId );
+                       if ( isset( $status->value['revision'] ) ) {
                                $dbw->update( 'logging',
                                        array( 'log_page' => $status->value['revision']->getPage() ),
                                        array( 'log_id' => $logId ),
                                        __METHOD__
                                );
-                               $dbw->commit( __METHOD__ ); // commit before anything bad can happen
                        }
+                       $dbw->commit( __METHOD__ ); // commit before anything bad can happen
                }
+
+
                wfProfileOut( __METHOD__ . '-edit' );
 
                # Save to cache and purge the squid
@@ -1372,11 +1385,17 @@ class LocalFile extends File {
                # Invalidate cache for all pages using this file
                $update = new HTMLCacheUpdate( $this->getTitle(), 'imagelinks' );
                $update->doUpdate();
+               if ( !$reupload ) {
+                       LinksUpdate::queueRecursiveJobsForTable( $this->getTitle(), 'imagelinks' );
+               }
 
                # Invalidate cache for all pages that redirects on this page
                $redirs = $this->getTitle()->getRedirectsHere();
 
                foreach ( $redirs as $redir ) {
+                       if ( !$reupload && $redir->getNamespace() === NS_FILE ) {
+                               LinksUpdate::queueRecursiveJobsForTable( $redir, 'imagelinks' );
+                       }
                        $update = new HTMLCacheUpdate( $redir, 'imagelinks' );
                        $update->doUpdate();
                }
@@ -1686,8 +1705,9 @@ class LocalFile extends File {
         * @return bool Whether to cache in RepoGroup (this avoids OOMs)
         */
        function isCacheable() {
-               $this->load(); // if loaded from cache, metadata will be null if it didn't fit
-               return $this->metadata !== null
+               $this->load();
+               // If extra data (metadata) was not loaded then it must have been large
+               return $this->extraDataLoaded
                        && strlen( serialize( $this->metadata ) ) <= self::CACHE_FIELD_MAX_LEN;
        }