Merge "Allow passing detailed permission errors data to API"
[lhc/web/wiklou.git] / includes / Import.php
index db4a6b2..3d94c33 100644 (file)
@@ -265,7 +265,7 @@ class WikiImporter {
                        // No rootpage
                        $this->setImportTitleFactory( new NaiveImportTitleFactory() );
                } elseif ( $rootpage !== '' ) {
-                       $rootpage = rtrim( $rootpage, '/' ); //avoid double slashes
+                       $rootpage = rtrim( $rootpage, '/' ); // avoid double slashes
                        $title = Title::newFromText( $rootpage );
 
                        if ( !$title || $title->isExternal() ) {
@@ -515,6 +515,7 @@ class WikiImporter {
                while ( $this->reader->read() ) {
                        switch ( $this->reader->nodeType ) {
                        case XMLReader::TEXT:
+                       case XMLReader::CDATA:
                        case XMLReader::SIGNIFICANT_WHITESPACE:
                                $buffer .= $this->reader->value;
                                break;
@@ -1606,6 +1607,20 @@ class WikiRevision {
                        }
                }
 
+               // Select previous version to make size diffs correct
+               $prevId = $dbw->selectField( 'revision', 'rev_id',
+                       array(
+                               'rev_page' => $pageId,
+                               'rev_timestamp <= ' . $dbw->timestamp( $this->timestamp ),
+                       ),
+                       __METHOD__,
+                       array( 'ORDER BY' => array(
+                                       'rev_timestamp DESC',
+                                       'rev_id DESC', // timestamp is not unique per page
+                               )
+                       )
+               );
+
                # @todo FIXME: Use original rev_id optionally (better for backups)
                # Insert the row
                $revision = new Revision( array(
@@ -1613,13 +1628,14 @@ class WikiRevision {
                        'page' => $pageId,
                        'content_model' => $this->getModel(),
                        'content_format' => $this->getFormat(),
-                       //XXX: just set 'content' => $this->getContent()?
+                       // XXX: just set 'content' => $this->getContent()?
                        'text' => $this->getContent()->serialize( $this->getFormat() ),
                        'comment' => $this->getComment(),
                        'user' => $userId,
                        'user_text' => $userText,
                        'timestamp' => $this->timestamp,
                        'minor_edit' => $this->minor,
+                       'parent_id' => $prevId,
                        ) );
                $revision->insertOn( $dbw );
                $changed = $page->updateIfNewerOn( $dbw, $revision );
@@ -1654,7 +1670,7 @@ class WikiRevision {
                                'log_namespace' => $this->getTitle()->getNamespace(),
                                'log_title' => $this->getTitle()->getDBkey(),
                                'log_comment' => $this->getComment(),
-                               #'log_user_text' => $this->user_text,
+                               # 'log_user_text' => $this->user_text,
                                'log_params' => $this->params ),
                        __METHOD__
                );
@@ -1672,7 +1688,7 @@ class WikiRevision {
                        'log_action' => $this->action,
                        'log_timestamp' => $dbw->timestamp( $this->timestamp ),
                        'log_user' => User::idFromName( $this->user_text ),
-                       #'log_user_text' => $this->user_text,
+                       # 'log_user_text' => $this->user_text,
                        'log_namespace' => $this->getTitle()->getNamespace(),
                        'log_title' => $this->getTitle()->getDBkey(),
                        'log_comment' => $this->getComment(),