make sure revisions are created consistently in case a content object is supplied
authordaniel <daniel.kinzler@wikimedia.de>
Mon, 23 Apr 2012 09:30:24 +0000 (11:30 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Mon, 23 Apr 2012 09:30:24 +0000 (11:30 +0200)
includes/Revision.php

index 82a4a94..0aee4eb 100644 (file)
@@ -482,14 +482,25 @@ class Revision {
                        $this->mParentId  = isset( $row['parent_id']  ) ? intval( $row['parent_id']  ) : null;
                        $this->mSha1      = isset( $row['sha1']  )      ? strval( $row['sha1']  )      : null;
 
-            $this->mContentModelName = isset( $row['content_model']  )  ? strval( $row['content_model'] ) : null;
-            $this->mContentFormat    = isset( $row['content_format']  )   ? strval( $row['content_format'] ) : null;
+            $this->mContentModelName = isset( $row['content_model']  )  ? strval( $row['content_model'] )  : null;
+            $this->mContentFormat    = isset( $row['content_format']  ) ? strval( $row['content_format'] ) : null;
 
                        // Enforce spacing trimming on supplied text
                        $this->mComment   = isset( $row['comment']    ) ?  trim( strval( $row['comment'] ) ) : null;
                        $this->mText      = isset( $row['text']       ) ? rtrim( strval( $row['text']    ) ) : null;
                        $this->mTextRow   = null;
 
+                       # if we have a content object, override mText and mContentModelName
+                       if ( !empty( $row['content'] ) ) {
+                               $handler = $this->getContentHandler();
+                               $this->mContent = $row['content'];
+
+                               $this->mContentModelName = $this->mContent->getModelName();
+                               $this->mContentHandler = null;
+                               
+                               $this->mText = $handler->serializeContent( $row['content'], $this->getContentFormat() );
+                       }
+
                        $this->mTitle     = null; # Load on demand if needed
                        $this->mCurrent   = false;
                        # If we still have no length, see it we have the text to figure it out
@@ -504,12 +515,6 @@ class Revision {
 
             $this->getContentModelName(); # force lazy init
             $this->getContentFormat();      # force lazy init
-
-            # if we have a content object, serialize it, overriding mText
-            if ( !empty( $row['content'] ) ) {
-                $handler = $this->getContentHandler();
-                $this->mText = $handler->serializeContent( $row['content'], $this->getContentFormat() );
-            }
                } else {
                        throw new MWException( 'Revision constructor passed invalid row format.' );
                }
@@ -865,6 +870,9 @@ class Revision {
         return $this->mContentFormat;
     }
 
+       /**
+        * @return ContentHandlert
+        */
     public function getContentHandler() {
         if ( !$this->mContentHandler ) {
             $model = $this->getContentModelName();