Addshore has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/344115 )

Change subject: Fixes to construction of File & Text revision objects
......................................................................

Fixes to construction of File & Text revision objects

It turns out the method checking for the presence of various things was
broken, now fixed.
This change also removes a few elements that will later likely be derived
from the image itself rather than the metadata requests.

Change-Id: I07e12d7b271273bfe78edf84a0cde9d92c0e75bb
---
M src/Generic/Data/FileRevision.php
M src/Generic/Data/TextRevision.php
M src/MediaWiki/ApiDetailRetriever.php
3 files changed, 28 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/FileImporter 
refs/changes/15/344115/1

diff --git a/src/Generic/Data/FileRevision.php 
b/src/Generic/Data/FileRevision.php
index 3708f27..2adfd43 100644
--- a/src/Generic/Data/FileRevision.php
+++ b/src/Generic/Data/FileRevision.php
@@ -19,15 +19,15 @@
                'height',
                'metadata',
                'bits',
-               'media_type',
-               'major_mime',
-               'minor_mime',
+               //'media_type', // needed in the DB but derived from the file 
itself?
+               //'major_mime', // needed in the DB but derived from the file 
itself?
+               //'minor_mime', // needed in the DB but derived from the file 
itself?
                'description',
                'user',
                'user_text',
                'timestamp',
                'sha1',
-               'type',
+               //'type', // needed in the DB but derived from the file itself?
                // Needed for display on import page
                'thumburl'
        ];
@@ -47,10 +47,12 @@
        }
 
        private function throwExceptionIfMissingFields( array $fields ) {
-               $keys = array_keys( $fields );
-               $expectedKeys = self::$fieldNames;
-               if ( sort( $expectedKeys ) !== sort( $keys ) ) {
-                       throw new InvalidArgumentException( __CLASS__ . ': 
Missing fields on construction' );
+               foreach ( self::$fieldNames as $expectedKey ) {
+                       if ( !array_key_exists( $expectedKey, $fields ) ) {
+                               throw new InvalidArgumentException(
+                                       __CLASS__ . ': Missing ' . $expectedKey 
. ' field on construction'
+                               );
+                       }
                }
        }
 
diff --git a/src/Generic/Data/TextRevision.php 
b/src/Generic/Data/TextRevision.php
index a5e6bb6..d205eb6 100644
--- a/src/Generic/Data/TextRevision.php
+++ b/src/Generic/Data/TextRevision.php
@@ -26,7 +26,7 @@
                'comment',
                '*',
                // Needed for display on import page
-               'parsedomment',
+               'parsedcomment',
        ];
 
        /**
@@ -44,10 +44,12 @@
        }
 
        private function throwExceptionIfMissingFields( array $fields ) {
-               $keys = array_keys( $fields );
-               $expectedKeys = self::$fieldNames;
-               if ( sort( $expectedKeys ) !== sort( $keys ) ) {
-                       throw new InvalidArgumentException( __CLASS__ . ': 
Missing fields on construction' );
+               foreach ( self::$fieldNames as $expectedKey ) {
+                       if ( !array_key_exists( $expectedKey, $fields ) ) {
+                               throw new InvalidArgumentException(
+                                       __CLASS__ . ': Missing ' . $expectedKey 
. ' field on construction'
+                               );
+                       }
                }
        }
 
diff --git a/src/MediaWiki/ApiDetailRetriever.php 
b/src/MediaWiki/ApiDetailRetriever.php
index 8e447b7..fc849c1 100644
--- a/src/MediaWiki/ApiDetailRetriever.php
+++ b/src/MediaWiki/ApiDetailRetriever.php
@@ -178,6 +178,16 @@
                         *  - DB sha1 format is base 36 padded to 31 chars
                         */
                        $revisionInfo['sha1'] = \Wikimedia\base_convert( 
$revisionInfo['sha1'], 16, 36, 31 );
+                       $revisionInfo['bits'] = $revisionInfo['size'];
+                       $revisionInfo['user_text'] = $revisionInfo['user'];
+                       $revisionInfo['user'] = $revisionInfo['userid'];
+
+                       // TODO can we rely on this extmetadata being in the 
response?
+                       $revisionInfo['description'] =
+                               
$revisionInfo['extmetadata']['ImageDescription']['value'];
+                       $revisionInfo['name'] =
+                               
$revisionInfo['extmetadata']['ObjectName']['value'];
+
                        $revisions[] = new FileRevision( $revisionInfo );
                }
                return new FileRevisions( $revisions );
@@ -191,6 +201,7 @@
        private function getTextRevisionsFromRevisionsInfo( array 
$revisionsInfo ) {
                $revisions = [];
                foreach ( $revisionsInfo as $revisionInfo ) {
+                       $revisionInfo['minor'] = array_key_exists( 'minor', 
$revisionInfo );
                        $revisions[] = new TextRevision( $revisionInfo );
                }
                return $revisions;

-- 
To view, visit https://gerrit.wikimedia.org/r/344115
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I07e12d7b271273bfe78edf84a0cde9d92c0e75bb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/FileImporter
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to