Merge "copy paste comment should probably have end instead of start"
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index b21b87a..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