[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add form API module

2017-09-28 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/376704 )

Change subject: Add form API module
..


Add form API module

Bug: T164742
Change-Id: I93b23c591b2a08c2106291d0ca1832b3ab3c7cf6
---
M extension.json
M i18n/en.json
M i18n/qqq.json
A src/Api/AddForm.php
M src/Api/AddFormRequest.php
M src/ChangeOp/ChangeOpAddForm.php
M src/DataModel/Serialization/ExternalLexemeSerializer.php
M src/DataModel/Services/Diff/LexemeDiff.php
M tests/phpunit/composer/DataModel/Serialization/StorageLexemeSerializerTest.php
M tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferTest.php
A tests/phpunit/mediawiki/Api/AddFormTest.php
11 files changed, 466 insertions(+), 3 deletions(-)

Approvals:
  WMDE-leszek: Checked; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index ad5163b..1e939df 100644
--- a/extension.json
+++ b/extension.json
@@ -381,5 +381,11 @@
"SpecialPages": {
"NewLexeme": 
"Wikibase\\Lexeme\\Specials\\SpecialNewLexeme::newFromGlobalState"
},
+   "APIModules": {
+   "wblexemeaddform": {
+   "class": "Wikibase\\Lexeme\\Api\\AddForm",
+   "factory": 
"Wikibase\\Lexeme\\Api\\AddForm::newFromGlobalState"
+   }
+   },
"manifest_version": 1
 }
diff --git a/i18n/en.json b/i18n/en.json
index ce2af99..01bd811 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -29,5 +29,22 @@
"datatypes-type-wikibase-lexeme-form": "Lexeme Form",
"datatypes-type-wikibase-lexeme-sense": "Lexeme Sense",
"wikibase-lexeme-add-sense": "add sense",
-   "wikibase-lexeme-add-form": "add form"
+   "wikibase-lexeme-add-form": "add form",
+   "apihelp-wblexemeaddform-summary": "Adds Form to Lexeme",
+   "apihelp-wblexemeaddform-param-lexemeId": "ID of the Lexeme e.g. L10",
+   "apihelp-wblexemeaddform-param-data": "JSON encoded data for Form i.e. 
representations and grammaticalFeatures",
+   "apihelp-wblexemeaddform-param-bot": "Mark this edit as bot. This URL 
flag will only be respected if the user belongs to the group 
\"{{int:group-bot}}\".",
+   "wikibase-lexeme-api-addform-lexemeid-invalid": "Invalid lexeme ID 
provided as \"lexemeId\"",
+   "wikibase-lexeme-api-addform-lexemeid-not-lexeme-id": "$1 is not a 
lexeme ID",
+   "wikibase-lexeme-api-addform-data-not-array": "\"data\" must be an 
array",
+   "wikibase-lexeme-api-addform-data-representations-key-missing": "No 
\"representations\" key in \"data\"",
+   "wikibase-lexeme-api-addform-data-invalid-json": "\"data\" is not a 
valid JSON",
+   "wikibase-lexeme-api-addform-data-grammatical-features-key-missing": 
"No \"grammaticalFeatures\" key in \"data\"",
+   "wikibase-lexeme-api-addform-data-representations-not-array": 
"\"representations\" must be an array",
+   "wikibase-lexeme-api-addform-data-grammatical-features-not-array": 
"\"grammaticalFeatures\" must be an array",
+   "wikibase-lexeme-api-addform-representations-empty": "At least a single 
representation must be provided",
+   "wikibase-lexeme-api-addform-representation-text-missing": "No 
representation string provided for representation at position $1",
+   "wikibase-lexeme-api-addform-representation-language-missing": "No 
language provided for representation at position $1",
+   "wikibase-lexeme-api-addform-grammatical-feature-itemid-invalid": 
"Invalid grammatical feature: $1",
+   "wikibase-lexeme-api-addform-grammatical-feature-not-item-id": "Not an 
item ID: $1"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index a319135..9d4241c 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -34,5 +34,22 @@
"datatypes-type-wikibase-lexeme-form": "The name of a data type for 
lexeme forms in Wikibase.",
"datatypes-type-wikibase-lexeme-sense": "The name of a data type for 
lexeme senses in Wikibase.",
"wikibase-lexeme-add-sense": "Label for button to add a new sense",
-   "wikibase-lexeme-add-form": "Label for button to add a new form"
+   "wikibase-lexeme-add-form": "Label for button to add a new form",
+   "apihelp-wblexemeaddform-summary": 
"{{doc-apihelp-summary|wblexemeaddform}}",
+   "apihelp-wblexemeaddform-param-lexemeId": 
"{{doc-apihelp-param|wblexemeaddform|lexemeId}}",
+   "apihelp-wblexemeaddform-param-data": 
"{{doc-apihelp-param|wblexemeaddform|data}}",
+   "apihelp-wblexemeaddform-param-bot": 
"{{doc-apihelp-param|wblexemeaddform|bot}}",
+   "wikibase-lexeme-api-addform-lexemeid-invalid": "API error description",
+   "wikibase-lexeme-api-addform-lexemeid-not-lexeme-id": "API error 
description",
+   "wikibase-lexeme-api-addform-data-not-array": "API error description",
+   "wikibase-lexeme-api-addform-data-representations-key-missing": "API 
error description",
+   

[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add form API module

2017-09-05 Thread Aleksey Bekh-Ivanov (WMDE) (Code Review)
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/376044 )

Change subject: Add form API module
..

Add form API module

Change-Id: Icf04fc9aaa4256f76ff54f89aed741061c5a
---
A src/Api/CreateForm.php
A src/ChangeOp/ChangeOpAddForm.php
M src/DataModel/Lexeme.php
A tests/phpunit/mediawiki/ChangeOp/ChangeOpAddFormTest.php
4 files changed, 158 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme 
refs/changes/44/376044/1

diff --git a/src/Api/CreateForm.php b/src/Api/CreateForm.php
new file mode 100644
index 000..fdaa855
--- /dev/null
+++ b/src/Api/CreateForm.php
@@ -0,0 +1,55 @@
+ 'L1',
+   'representations'=>[
+   ['representation' => '', 'language' => ''],
+   ['representation' => '', 'language' => ''],
+   ],
+   'grammaticalFeatures'=>[
+   'Q1','Q2'
+   ]
+   ];
+
+
+   }
+
+   /**
+* @see ApiBase::getAllowedParams
+*/
+   protected function getAllowedParams() {
+   return array_merge(
+   [
+   'lexemeId' => [
+   self::PARAM_TYPE => 'string',
+   self::PARAM_REQUIRED => true,
+   ],
+   'data' => [
+   self::PARAM_TYPE => 'text',
+   self::PARAM_REQUIRED => true,
+   ],
+   'token' => [
+   self::PARAM_TYPE => 'string',
+   self::PARAM_REQUIRED => true,
+   ],
+   'baserevid' => [
+   self::PARAM_TYPE => 'integer',
+   ],
+   'bot' => [
+   self::PARAM_TYPE => 'boolean',
+   self::PARAM_DFLT => false,
+   ]
+   ]
+   );
+   }
+}
diff --git a/src/ChangeOp/ChangeOpAddForm.php b/src/ChangeOp/ChangeOpAddForm.php
new file mode 100644
index 000..0abeabd
--- /dev/null
+++ b/src/ChangeOp/ChangeOpAddForm.php
@@ -0,0 +1,50 @@
+representations = $representations;
+   $this->grammaticalFeatures = $grammaticalFeatures;
+   }
+
+   public function validate( EntityDocument $lexeme ) {
+   Assert::parameterType( Lexeme::class, $lexeme, '$entity' );
+
+   return Result::newSuccess();
+   }
+
+   public function apply( EntityDocument $lexeme, Summary $summary = null 
) {
+   Assert::parameterType( Lexeme::class, $lexeme, '$entity' );
+   /** @var Lexeme $lexeme */
+   $lexeme->addForm($this->representations, 
$this->grammaticalFeatures);
+
+// $this->updateSummary($summary, 'add')
+   }
+}
diff --git a/src/DataModel/Lexeme.php b/src/DataModel/Lexeme.php
index 836aca2..f72bac4 100644
--- a/src/DataModel/Lexeme.php
+++ b/src/DataModel/Lexeme.php
@@ -270,4 +270,10 @@
&& $this->lexicalCategory !== null;
}
 
+   public function addForm(TermList $representataions, array 
$grammaticalFeatures) {
+   //FIXME: Test it
+   $formId = new FormId('F1');
+   $this->forms[] = new Form( $formId, $representataions, 
$grammaticalFeatures );
+   }
+
 }
diff --git a/tests/phpunit/mediawiki/ChangeOp/ChangeOpAddFormTest.php 
b/tests/phpunit/mediawiki/ChangeOp/ChangeOpAddFormTest.php
new file mode 100644
index 000..dfc3e90
--- /dev/null
+++ b/tests/phpunit/mediawiki/ChangeOp/ChangeOpAddFormTest.php
@@ -0,0 +1,47 @@
+setExpectedException(\InvalidArgumentException::class);
+   $changeOpAddForm->validate( NewItem::withId( 'Q1' )->build() );
+   }
+
+   public function test_validatePassesIfProvidedEntityIsALexeme() {
+   $changeOpAddForm = new ChangeOpAddForm(new TermList(), []);
+
+   $result = $changeOpAddForm->validate( 
NewLexeme::create()->build() );
+
+   $this->assertTrue( $result->isValid() );
+   }
+
+   public function test_applyFailsIfProvidedEntityIsNotALexeme() {
+   $changeOpAddForm = new ChangeOpAddForm(new TermList(), []);
+
+   $this->setExpectedException(\InvalidArgumentException::class);
+   $changeOpAddForm->apply( NewItem::withId( 'Q1' )->build() );
+   }
+
+   public function test_applyAddsFormIfGivenALexeme() {
+   $representations = new TermList([new Term('en', 'goat')]);
+