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

Change subject: WIP get history of file
......................................................................

WIP get history of file

Change-Id: I66ce4952f9ec407e0946a67e236763befefabf1e
---
M extension.json
A src/Generic/Exceptions/InvalidArgumentException.php
A src/Generic/FileRevision.php
3 files changed, 79 insertions(+), 0 deletions(-)


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

diff --git a/extension.json b/extension.json
index 3f3e1aa..af08cf7 100644
--- a/extension.json
+++ b/extension.json
@@ -23,6 +23,8 @@
     "FileImporter\\Generic\\Exceptions\\HttpRequestException": 
"src/Generic/Exceptions/HttpRequestException.php",
     "FileImporter\\Generic\\Exceptions\\ImportException": 
"src/Generic/Exceptions/ImportException.php",
     "FileImporter\\Generic\\Exceptions\\ImportTargetException": 
"src/Generic/Exceptions/ImportTargetException.php",
+    "FileImporter\\Generic\\Exceptions\\InvalidArgumentException": 
"src/Generic/Exceptions/InvalidArgumentException.php",
+    "FileImporter\\Generic\\FileRevision": "src/Generic/FileRevision.php",
     "FileImporter\\Generic\\ImportAdjustments": 
"src/Generic/ImportAdjustments.php",
     "FileImporter\\Generic\\ImportDetails": "src/Generic/ImportDetails.php",
     "FileImporter\\Generic\\Importer": "src/Generic/Importer.php",
diff --git a/src/Generic/Exceptions/InvalidArgumentException.php 
b/src/Generic/Exceptions/InvalidArgumentException.php
new file mode 100644
index 0000000..f1c9144
--- /dev/null
+++ b/src/Generic/Exceptions/InvalidArgumentException.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace FileImporter\Generic\Exceptions;
+
+class InvalidArgumentException extends \InvalidArgumentException{
+
+}
\ No newline at end of file
diff --git a/src/Generic/FileRevision.php b/src/Generic/FileRevision.php
new file mode 100644
index 0000000..5707464
--- /dev/null
+++ b/src/Generic/FileRevision.php
@@ -0,0 +1,70 @@
+<?php
+
+namespace FileImporter\Generic;
+
+use FileImporter\Generic\Exceptions\InvalidArgumentException;
+
+/**
+ * This class represents a single revision of a files, as recognized by 
MediaWiki.
+ * This data can all be retrieved from the API or the Database and can be used 
to copy
+ * the exact revision onto another site.
+ */
+class FileRevision {
+
+       private static $fieldNames = [
+               'name',
+               'size',
+               'width',
+               'height',
+               'metadata',
+               'bits',
+               'media_type',
+               'major_mime',
+               'minor_mime',
+               'description',
+               'user',
+               'user_text',
+               'timestamp',
+               'sha1',
+               'type',
+       ];
+
+       /**
+        * @var array
+        */
+       private $fields;
+
+       /**
+        * FileRevision constructor.
+        *
+        * @param array $fields
+        * @throws InvalidArgumentException if incorrect fields are entered
+        */
+       public function __construct( array $fields ) {
+               $this->throwExceptionIfMissingFields( $fields );
+               $this->fields = $fields;
+       }
+
+       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' );
+               }
+       }
+
+       /**
+        * @param string $name
+        *
+        * @return mixed
+        * @throws InvalidArgumentException if an unrecognized field is 
requested
+        */
+       public function getField( $name ) {
+               if ( !in_array( $name, self::$fieldNames ) ) {
+                       throw new InvalidArgumentException( __CLASS__ . ': 
Unrecognized field requested' );
+               }
+               return $this->fields[$name];
+
+       }
+
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I66ce4952f9ec407e0946a67e236763befefabf1e
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