[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Use Item selector for language and lexical category
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/383550 ) Change subject: Use Item selector for language and lexical category .. Use Item selector for language and lexical category Change-Id: I3cb0e80b5101d6eceb31938770866c5f4590dffa --- M extension.json A resources/widgets/ItemSelectorWrapper.js M resources/widgets/LanguageAndLexicalCategoryWidget.js M src/View/LexemeView.php 4 files changed, 59 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/50/383550/1 diff --git a/extension.json b/extension.json index c9460ca..63079f2 100644 --- a/extension.json +++ b/extension.json @@ -211,7 +211,13 @@ "scripts": "widgets/LexemeHeader.newLexemeHeader.js" }, "wikibase.lexeme.widgets.LanguageAndLexicalCategoryWidget": { - "scripts": "widgets/LanguageAndLexicalCategoryWidget.js" + "scripts": "widgets/LanguageAndLexicalCategoryWidget.js", + "dependencies": [ + "wikibase.lexeme.widgets.ItemSelectorWrapper" + ] + }, + "wikibase.lexeme.widgets.ItemSelectorWrapper": { + "scripts": "widgets/ItemSelectorWrapper.js" }, "wikibase.templates.lexeme": { "class": "\\Wikibase\\Lexeme\\View\\TemplateModule", diff --git a/resources/widgets/ItemSelectorWrapper.js b/resources/widgets/ItemSelectorWrapper.js new file mode 100644 index 000..d2c85e6 --- /dev/null +++ b/resources/widgets/ItemSelectorWrapper.js @@ -0,0 +1,41 @@ +module.exports = ( function () { + 'use strict'; + + return { + props: [ 'value' ], + template: '', + mounted: function () { + var vm = this; + + var repoConfig = mw.config.get( 'wbRepo' ); + var repoApiUrl = repoConfig.url + repoConfig.scriptPath + '/api.php'; + var expertType = 'item'; + + var $input = $( this.$el ); + $input.val( this.value ); + + $input.entityselector( { + url: repoApiUrl, + type: expertType, + selectOnAutocomplete: true + } ); + + $input.on( 'entityselectorselected', function ( e ) { + var entitySelector = $( vm.$el ).data( 'entityselector' ), + selectedEntity = entitySelector.selectedEntity(); + + var value = selectedEntity ? selectedEntity.id : ''; + + vm.$emit( 'input', value ); + } ); + }, + watch: { + value: function ( value ) { + $( this.$el ).data( 'entityselector' ).selectedEntity( value ); + } + }, + destroyed: function () { + $( this.$el ).data( 'entityselector' ).destroy(); + } + }; +} )(); diff --git a/resources/widgets/LanguageAndLexicalCategoryWidget.js b/resources/widgets/LanguageAndLexicalCategoryWidget.js index 045e0fb..6ebf943 100644 --- a/resources/widgets/LanguageAndLexicalCategoryWidget.js +++ b/resources/widgets/LanguageAndLexicalCategoryWidget.js @@ -1,6 +1,8 @@ module.exports = ( function () { 'use strict'; + var ItemSelectorWrapper = require( 'wikibase.lexeme.widgets.ItemSelectorWrapper' ); + /** * @callback wikibase.lexeme.widgets.LanguageAndLexicalCategoryWidget * @@ -11,6 +13,9 @@ return { props: [ 'language', 'lexicalCategory', 'inEditMode', 'isSaving' ], template: template, + components: { + 'item-selector': ItemSelectorWrapper + }, filters: { message: function ( key ) { diff --git a/src/View/LexemeView.php b/src/View/LexemeView.php index 6cfa1bc..ff0de6c 100644 --- a/src/View/LexemeView.php +++ b/src/View/LexemeView.php @@ -304,22 +304,21 @@ {{'wikibase-lexeme-language'|message}} - + @input="$emit('update:language', $event)"> {{'wikibase-lexeme-lexical-category'|message}} - + @input="$emit('update:lexicalCategory', $event)"> HTML; - } priva
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add question to discuss
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/383113 ) Change subject: Add question to discuss .. Add question to discuss Change-Id: I048323c4d8dfc9ca4fe2a1f8d569ba0dd84170f6 --- M src/Api/AddForm.php 1 file changed, 1 insertion(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/13/383113/1 diff --git a/src/Api/AddForm.php b/src/Api/AddForm.php index 1e3716b..50db5d6 100644 --- a/src/Api/AddForm.php +++ b/src/Api/AddForm.php @@ -196,6 +196,7 @@ $serializedForm = $this->formSerializer->serialize( $newForm ); + //TODO: Do we really need `success` property in response? $apiResult->addValue( null, 'success', 1 ); $apiResult->addValue( null, 'form', $serializedForm ); } -- To view, visit https://gerrit.wikimedia.org/r/383113 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I048323c4d8dfc9ca4fe2a1f8d569ba0dd84170f6 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Handle "Lexeme not found" error while adding form
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/383106 ) Change subject: Handle "Lexeme not found" error while adding form .. Handle "Lexeme not found" error while adding form Change-Id: Iafdc8a930498184a4b15b71f9753ec6ca64bca1e --- M src/Api/AddForm.php M tests/phpunit/mediawiki/Api/AddFormTest.php 2 files changed, 20 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/06/383106/1 diff --git a/src/Api/AddForm.php b/src/Api/AddForm.php index 2378733..fec 100644 --- a/src/Api/AddForm.php +++ b/src/Api/AddForm.php @@ -136,13 +136,22 @@ $request = $parserResult->getRequest(); - //FIXME Check if found try { + $lexemeId = $request->getLexemeId(); $lexemeRevision = $this->entityRevisionLookup->getEntityRevision( - $request->getLexemeId(), + $lexemeId, self::LATEST_REVISION, EntityRevisionLookup::LATEST_FROM_MASTER ); + + if ( !$lexemeRevision ) { + $message = new \Message( + 'wikibase-lexeme-api-error-lexeme-not-found', + [ $lexemeId->serialize() ] + ); + $apiMessage = new \ApiMessage( $message, 'not-found' ); + $this->dieWithError( $apiMessage ); + } } catch ( StorageException $e ) { //TODO Test it if ( $e->getStatus() ) { diff --git a/tests/phpunit/mediawiki/Api/AddFormTest.php b/tests/phpunit/mediawiki/Api/AddFormTest.php index 65f2d89..fce1365 100644 --- a/tests/phpunit/mediawiki/Api/AddFormTest.php +++ b/tests/phpunit/mediawiki/Api/AddFormTest.php @@ -101,6 +101,15 @@ 'api-error-data' => [] ], ], + 'Lexeme is not found' => [ + [ 'lexemeId' => 'L999', 'data' => $this->getDataParam() ], + [ + 'message-key' => 'wikibase-lexeme-api-error-lexeme-not-found', + 'message-parameters' => [ 'L999' ], + 'api-error-code' => 'not-found', + 'api-error-data' => [] + ], + ], ]; } -- To view, visit https://gerrit.wikimedia.org/r/383106 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iafdc8a930498184a4b15b71f9753ec6ca64bca1e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Stop using using EntitySavingHelper in AddForm API module
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/381419 ) Change subject: Stop using using EntitySavingHelper in AddForm API module .. Stop using using EntitySavingHelper in AddForm API module Change-Id: Idfc3318293ba99cd2c78a0500f7e32648761f3c7 --- M src/Api/AddForm.php M src/Api/AddFormRequestParserResult.php M src/DataModel/Services/Diff/LexemeDiff.php 3 files changed, 86 insertions(+), 30 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/19/381419/1 diff --git a/src/Api/AddForm.php b/src/Api/AddForm.php index e80c206..1274752 100644 --- a/src/Api/AddForm.php +++ b/src/Api/AddForm.php @@ -4,25 +4,15 @@ use ApiBase; use ApiMain; -use Wikibase\DataModel\Entity\ItemId; -use Wikibase\DataModel\Term\Term; -use Wikibase\DataModel\Term\TermList; -use Wikibase\Lexeme\ChangeOp\ChangeOpAddForm; -use Wikibase\Lexeme\DataModel\Form; -use Wikibase\Lexeme\DataModel\Serialization\ExternalLexemeSerializer; +use Wikibase\EditEntity; +use Wikibase\EditEntityFactory; +use Wikibase\Lexeme\DataModel\Lexeme; use Wikibase\Lexeme\DataModel\Serialization\FormSerializer; -use Wikibase\Lexeme\DataModel\Serialization\LexemeSerializer; -use Wikibase\Lexeme\DataModel\Serialization\StorageLexemeSerializer; +use Wikibase\Lib\Store\EntityRevisionLookup; use Wikibase\Repo\Api\ApiErrorReporter; -use Wikibase\Repo\Api\EntitySavingHelper; -use Wikibase\Summary; class AddForm extends ApiBase { - - /** -* @var EntitySavingHelper -*/ - private $entitySavingHelper; + const LATEST_REVISION = 0; /** * @var AddFormRequestParser @@ -35,14 +25,18 @@ private $errorReporter; /** -* @var ExternalLexemeSerializer -*/ - private $lexemeSerializer; - - /** * @var FormSerializer */ private $formSerializer; + /** +* @var EditEntityFactory +*/ + private $editEntityFactory; + + /** +* @var EntityRevisionLookup +*/ + private $entityRevisionLookup; /** * @return AddForm @@ -63,9 +57,8 @@ $moduleName, new AddFormRequestParser( $wikibaseRepo->getEntityIdParser() ), $formSerializer, - function ( $module ) use ( $apiHelperFactory ) { - return $apiHelperFactory->getEntitySavingHelper( $module ); - }, + $wikibaseRepo->getEntityRevisionLookup( 'uncached' ), + $wikibaseRepo->newEditEntityFactory( $mainModule->getContext() ), function ( $module ) use ( $apiHelperFactory ) { return $apiHelperFactory->getErrorReporter( $module ); } @@ -77,15 +70,17 @@ $moduleName, AddFormRequestParser $requestParser, FormSerializer $formSerializer, - callable $entitySavingHelperInstantiator, + EntityRevisionLookup $entityRevisionLookup, + EditEntityFactory $editEntityFactory, callable $errorReporterInstantiator ) { parent::__construct( $mainModule, $moduleName ); - $this->entitySavingHelper = $entitySavingHelperInstantiator( $this ); $this->errorReporter = $errorReporterInstantiator( $this ); $this->requestParser = $requestParser; $this->formSerializer = $formSerializer; + $this->editEntityFactory = $editEntityFactory; + $this->entityRevisionLookup = $entityRevisionLookup; } /** @@ -96,7 +91,8 @@ //FIXME: Response structure? - Added form //TODO: Documenting response structure. Is it possible? - $parserResult = $this->requestParser->parse( $this->extractRequestParams() ); + $params = $this->extractRequestParams(); + $parserResult = $this->requestParser->parse( $params ); if ( $parserResult->hasErrors() ) { $errorMessage = $parserResult->getErrors()[0]; @@ -111,12 +107,31 @@ $request = $parserResult->getRequest(); - $lexeme = $this->entitySavingHelper->loadEntity( $request->getLexemeId() ); + //FIXME Check if found + $lexemeRevision = $this->entityRevisionLookup->getEntityRevision( + $request->getLexemeId(), + self::LATEST_REVISION, + EntityRevisionLookup::LATEST_FROM_MASTER + ); + /** @var Lexeme $lexeme */ + $lexeme = $lexemeRevision->getEntity(); $newForm = $request->addFormTo( $lexeme ); -
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Extract FormSerializer from LexemeSerializer
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/381002 ) Change subject: Extract FormSerializer from LexemeSerializer .. Extract FormSerializer from LexemeSerializer Change-Id: I58c6eaf40bd3c07be8d355ae81df99929deeed11 --- A src/DataModel/Serialization/FormSerializer.php M src/DataModel/Serialization/StorageLexemeSerializer.php M tests/phpunit/composer/DataModel/Serialization/ExternalLexemeSerializerTest.php 3 files changed, 61 insertions(+), 25 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/02/381002/1 diff --git a/src/DataModel/Serialization/FormSerializer.php b/src/DataModel/Serialization/FormSerializer.php new file mode 100644 index 000..430e3bf --- /dev/null +++ b/src/DataModel/Serialization/FormSerializer.php @@ -0,0 +1,57 @@ +termListSerializer = $termListSerializer; + $this->statementListSerializer = $statementListSerializer; + } + + /** +* @param Form $form +* +* @return array +*/ + public function serialize( Form $form ) { + $serialization = []; + + $serialization['id'] = $form->getId()->getSerialization(); + + $serialization['representations'] = $this->termListSerializer->serialize( + $form->getRepresentations() + ); + $serialization['grammaticalFeatures'] = array_map( + function ( ItemId $itemId ) { + return $itemId->getSerialization(); + }, + $form->getGrammaticalFeatures() + ); + + $serialization['claims'] = $this->statementListSerializer->serialize( + $form->getStatements() + ); + + return $serialization; + } + +} diff --git a/src/DataModel/Serialization/StorageLexemeSerializer.php b/src/DataModel/Serialization/StorageLexemeSerializer.php index 97edbf5..0bf2f14 100644 --- a/src/DataModel/Serialization/StorageLexemeSerializer.php +++ b/src/DataModel/Serialization/StorageLexemeSerializer.php @@ -34,6 +34,7 @@ ) { $this->termListSerializer = $termListSerializer; $this->statementListSerializer = $statementListSerializer; + $this->formSerializer = new FormSerializer( $termListSerializer, $statementListSerializer ); } /** @@ -132,29 +133,7 @@ * @return array */ private function serializeForm( Form $form ) { - $serialization = []; - - $id = $form->getId(); - if ( $id !== null ) { - // Note: This ID serialization is final, because there is no EntityIdSerializer - $serialization['id'] = $id->getSerialization(); - } - - $serialization['representations'] = $this->termListSerializer->serialize( - $form->getRepresentations() - ); - $serialization['grammaticalFeatures'] = array_map( - function ( ItemId $itemId ) { - return $itemId->getSerialization(); - }, - $form->getGrammaticalFeatures() - ); - - $serialization['claims'] = $this->statementListSerializer->serialize( - $form->getStatements() - ); - - return $serialization; + return $this->formSerializer->serialize( $form ); } /** diff --git a/tests/phpunit/composer/DataModel/Serialization/ExternalLexemeSerializerTest.php b/tests/phpunit/composer/DataModel/Serialization/ExternalLexemeSerializerTest.php index 3c198e1..b4f0f5d 100644 --- a/tests/phpunit/composer/DataModel/Serialization/ExternalLexemeSerializerTest.php +++ b/tests/phpunit/composer/DataModel/Serialization/ExternalLexemeSerializerTest.php @@ -17,10 +17,10 @@ use Wikibase\Lexeme\Tests\DataModel\NewForm; use Wikibase\Lexeme\Tests\DataModel\NewLexeme; use Wikibase\Lexeme\Tests\DataModel\NewSense; -use Wikibase\Repo\Tests\NewStatement; /** - * @covers Wikibase\Lexeme\DataModel\Serialization\ExternalLexemeSerializer + * @covers \Wikibase\Lexeme\DataModel\Serialization\LexemeSerializer + * @covers \Wikibase\Lexeme\DataModel\Serialization\FormSerializer * * @group WikibaseLexeme * -- To view, visit https://gerrit.wikimedia.org/r/381002 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I58c6eaf40bd3c07be8d355ae81df99929deeed11 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list Med
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Create `AddForm` example for documentation
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/380999 ) Change subject: Create `AddForm` example for documentation .. Create `AddForm` example for documentation Change-Id: I209c5d2612874994d3e2ba9a10236aaa3e7a8199 --- M i18n/en.json M src/Api/AddForm.php 2 files changed, 45 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/99/380999/1 diff --git a/i18n/en.json b/i18n/en.json index 01bd811..18f33f5 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -34,6 +34,7 @@ "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}}\".", + "apihelp-wblexemeaddform-example-1": "Add Form to the Lexeme with ID $1 having representations $2 with languages $3 respectively and grammatical features $4", "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", diff --git a/src/Api/AddForm.php b/src/Api/AddForm.php index eca1ae3..9920c9b 100644 --- a/src/Api/AddForm.php +++ b/src/Api/AddForm.php @@ -176,6 +176,50 @@ return true; } + protected function getExamplesMessages() { + $lexemeId = 'L12'; + $exampleData = [ + 'representations' => [ + [ 'representation' => 'color', 'language' => 'en-US' ], + [ 'representation' => 'colour', 'language' => 'en-GB' ], + ], + 'grammaticalFeatures' => [ + 'Q1', 'Q2' + ] + ]; + + $query = http_build_query( [ + 'action' => $this->getModuleName(), + 'lexemeId' => $lexemeId, + 'data' => json_encode( $exampleData ) + ] ); + + $languages = array_map( function ( $r ) { + return $r['language']; + }, $exampleData['representations'] ); + $representations = array_map( function ( $r ) { + return $r['representation']; + }, $exampleData['representations'] ); + + $representationsText = $this->getLanguage()->commaList( $representations ); + $languagesText = $this->getLanguage()->commaList( $languages ); + $grammaticalFeaturesText = $this->getLanguage()->commaList( $exampleData['grammaticalFeatures'] ); + + $exampleMessage = new \Message( + 'apihelp-wblexemeaddform-example-1', + [ + $lexemeId, + $representationsText, + $languagesText, + $grammaticalFeaturesText + ] + ); + + return [ + $query => $exampleMessage + ]; + } + private function createChangeOp( array $data ) { $representations = new TermList( array_map( -- To view, visit https://gerrit.wikimedia.org/r/380999 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I209c5d2612874994d3e2ba9a10236aaa3e7a8199 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Fix inability of fetching message object
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/380725 ) Change subject: Fix inability of fetching message object .. Fix inability of fetching message object Fatal error was happening due to the fact that ApiUsageException was trying to call `getMessage()` on StatusValue which doesn't have this method. Change-Id: Idd9c7d47d9e24a6a32db6daf75a827bf958c9b76 --- M includes/api/ApiUsageException.php A tests/phpunit/includes/api/ApiUsageExceptionTest.php 2 files changed, 27 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/25/380725/1 diff --git a/includes/api/ApiUsageException.php b/includes/api/ApiUsageException.php index 47902a7..0d7f091 100644 --- a/includes/api/ApiUsageException.php +++ b/includes/api/ApiUsageException.php @@ -146,7 +146,7 @@ ) { return new static( $module, - StatusValue::newFatal( ApiMessage::create( $msg, $code, $data ) ), + Status::newFatal( ApiMessage::create( $msg, $code, $data ) ), $httpCode ); } diff --git a/tests/phpunit/includes/api/ApiUsageExceptionTest.php b/tests/phpunit/includes/api/ApiUsageExceptionTest.php new file mode 100644 index 000..46cba79 --- /dev/null +++ b/tests/phpunit/includes/api/ApiUsageExceptionTest.php @@ -0,0 +1,26 @@ +getMessageObject(); + + $this->assertInstanceOf( \ApiMessage::class, $gotMessage ); + $this->assertEquals( $expectedMessage->getKey(), $gotMessage->getKey() ); + $this->assertEquals( $expectedMessage->getParams(), $gotMessage->getParams() ); + $this->assertEquals( $expectedCode, $gotMessage->getApiCode() ); + $this->assertEquals( $expectedData, $gotMessage->getApiData() ); + } + +} -- To view, visit https://gerrit.wikimedia.org/r/380725 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idd9c7d47d9e24a6a32db6daf75a827bf958c9b76 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Make ApiUsageException and ApiErrorFormatter able to handle ...
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/380547 ) Change subject: Make ApiUsageException and ApiErrorFormatter able to handle IApiMessage .. Make ApiUsageException and ApiErrorFormatter able to handle IApiMessage As was discussed in I94416fe4 and in I214f8c55 this should be done in `ApiMessage::create()` Also, found that ApiUsageException can't accept StatusValue as it's constructor says. Created a skipped test for it but didn't fix in this patch. Change-Id: I4a2a9861ed9c8e33e084a1018dfbc876463aa47f --- M includes/api/ApiMessage.php M tests/phpunit/includes/api/ApiErrorFormatterTest.php M tests/phpunit/includes/api/ApiMessageTest.php A tests/phpunit/includes/api/ApiUsageExceptionTest.php 4 files changed, 143 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/47/380547/1 diff --git a/includes/api/ApiMessage.php b/includes/api/ApiMessage.php index 9e42d5f..47c478b 100644 --- a/includes/api/ApiMessage.php +++ b/includes/api/ApiMessage.php @@ -227,6 +227,10 @@ } if ( $msg instanceof IApiMessage ) { + if ( !$msg instanceof Message ) { + return new ApiMessage( $msg, $msg->getApiCode(), $msg->getApiData() ); + } + return $msg; } elseif ( $msg instanceof RawMessage ) { return new ApiRawMessage( $msg, $code, $data ); diff --git a/tests/phpunit/includes/api/ApiErrorFormatterTest.php b/tests/phpunit/includes/api/ApiErrorFormatterTest.php index d47481c..c57fb52 100644 --- a/tests/phpunit/includes/api/ApiErrorFormatterTest.php +++ b/tests/phpunit/includes/api/ApiErrorFormatterTest.php @@ -639,4 +639,40 @@ ]; } + public function testAddErrorCanHandleIApiMessage() { + $result = new ApiResult( 1 ); + $apiErrorFormatter = new ApiErrorFormatter( + $result, + Language::factory( 'en' ), + 'none', + false + ); + + $apiErrorFormatter->addError( + null, + $this->createIApiMessage( 'some-error-code', [ 'some-error-data' ] ) + ); + + $resultData = $result->getResultData(); + $error = $resultData['errors'][0]; + $this->assertEquals( 'some-error-code', $error['code'] ); + $this->assertContains( 'some-error-data', $error['data'] ); + } + + /** +* @param string $code +* @param array $data +* +* @return IApiMessage +*/ + private function createIApiMessage( $code, array $data ) { + /** @var IApiMessage|\Prophecy\Prophecy\ObjectProphecy $message */ + $message = $this->prophesize( IApiMessage::class ); + $message->getKey()->willReturn( 'some-IApiMessage-key' ); + $message->getParams()->willReturn( [ 'some-IApiMessage-param' ] ); + $message->getApiCode()->willReturn( $code ); + $message->getApiData()->willReturn( $data ); + + return $message->reveal(); + } } diff --git a/tests/phpunit/includes/api/ApiMessageTest.php b/tests/phpunit/includes/api/ApiMessageTest.php index c6f5a8e..1ba8e95 100644 --- a/tests/phpunit/includes/api/ApiMessageTest.php +++ b/tests/phpunit/includes/api/ApiMessageTest.php @@ -186,4 +186,29 @@ $this->assertSame( $msg, ApiMessage::create( $msg ) ); } + public function testCreate_GivenIApiMessageWhichDoesNotExtendMessage_ConvertsToApiMessage() { + $IApiMessage = $this->createIApiMessage(); + $result = ApiMessage::create( $IApiMessage ); + + $this->assertInstanceOf( ApiMessage::class, $result ); + $this->assertEquals( $IApiMessage->getKey(), $result->getKey() ); + $this->assertEquals( $IApiMessage->getParams(), $result->getParams() ); + $this->assertEquals( $IApiMessage->getApiCode(), $result->getApiCode() ); + $this->assertEquals( $IApiMessage->getApiData(), $result->getApiData() ); + } + + /** +* @return IApiMessage +*/ + private function createIApiMessage() { + /** @var IApiMessage|\Prophecy\Prophecy\ObjectProphecy $message */ + $message = $this->prophesize( IApiMessage::class ); + $message->getKey()->willReturn( 'some-IApiMessage-key' ); + $message->getParams()->willReturn( [ 'some-IApiMessage-param' ] ); + $message->getApiCode()->willReturn( 'some-api-code' ); + $message->getApiData()->willReturn( [ 'some-api-data' ] ); + + return $message->reveal();
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Fix tests regarding newly added entity type callback in Wiki...
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/380532 ) Change subject: Fix tests regarding newly added entity type callback in Wikibase .. Fix tests regarding newly added entity type callback in Wikibase Change-Id: I3a39a470f97127b8ad020f7ce879a32389853b94 --- M WikibaseLexeme.entitytypes.php 1 file changed, 16 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/32/380532/1 diff --git a/WikibaseLexeme.entitytypes.php b/WikibaseLexeme.entitytypes.php index 06a5230..226b9a7 100644 --- a/WikibaseLexeme.entitytypes.php +++ b/WikibaseLexeme.entitytypes.php @@ -43,19 +43,25 @@ return [ 'lexeme' => [ - 'serializer-factory-callback' => function( SerializerFactory $serializerFactory ) { + 'serializer-factory-callback' => function ( SerializerFactory $serializerFactory ) { return new LexemeSerializer( $serializerFactory->newTermListSerializer(), $serializerFactory->newStatementListSerializer() ); }, - 'deserializer-factory-callback' => function( DeserializerFactory $deserializerFactory ) { + 'storage-serializer-factory-callback' => function ( SerializerFactory $serializerFactory ) { + return new LexemeSerializer( + $serializerFactory->newTermListSerializer(), + $serializerFactory->newStatementListSerializer() + ); + }, + 'deserializer-factory-callback' => function ( DeserializerFactory $deserializerFactory ) { return new LexemeDeserializer( $deserializerFactory->newEntityIdDeserializer(), $deserializerFactory->newStatementListDeserializer() ); }, - 'view-factory-callback' => function( + 'view-factory-callback' => function ( $languageCode, LabelDescriptionLookup $labelDescriptionLookup, LanguageFallbackChain $fallbackChain, @@ -74,7 +80,7 @@ return $factory->newLexemeView(); }, 'content-model-id' => LexemeContent::CONTENT_MODEL_ID, - 'content-handler-factory-callback' => function() { + 'content-handler-factory-callback' => function () { $wikibaseRepo = WikibaseRepo::getDefaultInstance(); return new LexemeHandler( $wikibaseRepo->getStore()->newEntityPerPage(), @@ -89,23 +95,23 @@ ); }, 'entity-id-pattern' => LexemeId::PATTERN, - 'entity-id-builder' => function( $serialization ) { + 'entity-id-builder' => function ( $serialization ) { return new LexemeId( $serialization ); }, - 'entity-id-composer-callback' => function( $repositoryName, $uniquePart ) { + 'entity-id-composer-callback' => function ( $repositoryName, $uniquePart ) { return new LexemeId( EntityId::joinSerialization( [ $repositoryName, '', 'L' . $uniquePart ] ) ); }, - 'entity-differ-strategy-builder' => function() { + 'entity-differ-strategy-builder' => function () { return new LexemeDiffer(); }, - 'entity-patcher-strategy-builder' => function() { + 'entity-patcher-strategy-builder' => function () { return new LexemePatcher(); }, - 'entity-factory-callback' => function() { + 'entity-factory-callback' => function () { return new Lexeme(); }, // Identifier of a resource loader module that, when `require`d, returns a function @@ -142,7 +148,7 @@ ) ); }, - 'rdf-builder-factory-callback' => function( + 'rdf-builder-factory-callback' => function ( $flavorFlags, RdfVocabulary $vocabulary, RdfWriter $writer, -- To view, visit https://gerrit.wikimedia.org/r/380532 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3a39a470f97127b8ad020f7ce879a32389853b94 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/exte
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Fix tests regarding `Summary` api change
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/380531 ) Change subject: Fix tests regarding `Summary` api change .. Fix tests regarding `Summary` api change Change-Id: I89f0ac297ca4f4dcbaa40342f4c82d259fe3408a --- M src/ChangeOp/ChangeOpAddForm.php M tests/phpunit/mediawiki/ChangeOp/ChangeOpAddFormTest.php M tests/phpunit/mediawiki/ChangeOp/ChangeOpLanguageTest.php M tests/phpunit/mediawiki/ChangeOp/ChangeOpLemmaTest.php M tests/phpunit/mediawiki/ChangeOp/ChangeOpLexicalCategoryTest.php 5 files changed, 10 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/31/380531/1 diff --git a/src/ChangeOp/ChangeOpAddForm.php b/src/ChangeOp/ChangeOpAddForm.php index 3632752..194f9b2 100644 --- a/src/ChangeOp/ChangeOpAddForm.php +++ b/src/ChangeOp/ChangeOpAddForm.php @@ -45,7 +45,7 @@ $this->updateSummary( $summary, - 'add', + 'add-form', '', array_values( $form->getRepresentations()->toTextArray() ) ); diff --git a/tests/phpunit/mediawiki/ChangeOp/ChangeOpAddFormTest.php b/tests/phpunit/mediawiki/ChangeOp/ChangeOpAddFormTest.php index fd4337b..9d8e503 100644 --- a/tests/phpunit/mediawiki/ChangeOp/ChangeOpAddFormTest.php +++ b/tests/phpunit/mediawiki/ChangeOp/ChangeOpAddFormTest.php @@ -54,7 +54,7 @@ $changeOp->apply( $lexeme, $summary ); - $this->assertEquals( 'add', $summary->getActionName() ); + $this->assertEquals( 'add-form', $summary->getMessageKey() ); $this->assertEquals( [ 'goat' ], $summary->getAutoSummaryArgs() ); } diff --git a/tests/phpunit/mediawiki/ChangeOp/ChangeOpLanguageTest.php b/tests/phpunit/mediawiki/ChangeOp/ChangeOpLanguageTest.php index 89a5496..9e9a3f1 100644 --- a/tests/phpunit/mediawiki/ChangeOp/ChangeOpLanguageTest.php +++ b/tests/phpunit/mediawiki/ChangeOp/ChangeOpLanguageTest.php @@ -70,7 +70,7 @@ $this->assertSame( 'Q321', $lexeme->getLanguage()->getSerialization() ); - $this->assertSame( 'set', $summary->getActionName() ); + $this->assertSame( 'set', $summary->getMessageKey() ); $this->assertSame( [ 'Q321' ], $summary->getAutoSummaryArgs() ); } @@ -87,7 +87,7 @@ $this->assertSame( 'Q123', $lexeme->getLanguage()->getSerialization() ); - $this->assertSame( 'set', $summary->getActionName() ); + $this->assertSame( 'set', $summary->getMessageKey() ); $this->assertSame( [ 'Q123' ], $summary->getAutoSummaryArgs() ); } diff --git a/tests/phpunit/mediawiki/ChangeOp/ChangeOpLemmaTest.php b/tests/phpunit/mediawiki/ChangeOp/ChangeOpLemmaTest.php index 6e51873..6483354 100644 --- a/tests/phpunit/mediawiki/ChangeOp/ChangeOpLemmaTest.php +++ b/tests/phpunit/mediawiki/ChangeOp/ChangeOpLemmaTest.php @@ -122,7 +122,7 @@ $this->assertTrue( $lexeme->getLemmas()->hasTermForLanguage( 'en' ) ); $this->assertSame( 'duck', $lexeme->getLemmas()->getByLanguage( 'en' )->getText() ); - $this->assertSame( 'remove', $summary->getActionName() ); + $this->assertSame( 'remove', $summary->getMessageKey() ); $this->assertSame( 'de', $summary->getLanguageCode() ); $this->assertSame( [ 'Ente' ], $summary->getAutoSummaryArgs() ); } @@ -143,7 +143,7 @@ $this->assertTrue( $lexeme->getLemmas()->hasTermForLanguage( 'en' ) ); $this->assertSame( 'duck', $lexeme->getLemmas()->getByLanguage( 'en' )->getText() ); - $this->assertSame( 'add', $summary->getActionName() ); + $this->assertSame( 'add', $summary->getMessageKey() ); $this->assertSame( 'de', $summary->getLanguageCode() ); $this->assertSame( [ 'Ente' ], $summary->getAutoSummaryArgs() ); } @@ -161,7 +161,7 @@ $this->assertSame( 'bar', $lexeme->getLemmas()->getByLanguage( 'en' )->getText() ); - $this->assertSame( 'set', $summary->getActionName() ); + $this->assertSame( 'set', $summary->getMessageKey() ); $this->assertSame( 'en', $summary->getLanguageCode() ); $this->assertSame( [ 'bar' ], $summary->getAutoSummaryArgs() ); } @@ -174,7 +174,7 @@ $changeOp->apply( $lexeme, $summary ); $this->assertFalse( $lexeme->getLemmas()->hasTermForLanguage( 'en' ) ); - $this->assertNull( $summary->getActionName() ); + $this->assertNull( $summary->getMessageKey() ); } private function getLexemeValidatorFactory() { diff --git a/tests/phpunit/mediawiki/Change
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Bugfix: make ApiErrorFormatter to be able to handle IApiMessage
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/380479 ) Change subject: Bugfix: make ApiErrorFormatter to be able to handle IApiMessage .. Bugfix: make ApiErrorFormatter to be able to handle IApiMessage Change-Id: I94416fe48ffde0bbcfb14b6c5dbed328ddd60cef --- M includes/api/ApiErrorFormatter.php M tests/phpunit/includes/api/ApiErrorFormatterTest.php 2 files changed, 46 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/79/380479/1 diff --git a/includes/api/ApiErrorFormatter.php b/includes/api/ApiErrorFormatter.php index 7fb1352..af4d53f 100644 --- a/includes/api/ApiErrorFormatter.php +++ b/includes/api/ApiErrorFormatter.php @@ -101,7 +101,16 @@ * @param array|null $data See ApiMessage::create(). */ public function addError( $modulePath, $msg, $code = null, $data = null ) { - $msg = ApiMessage::create( $msg, $code, $data ) + $apiMessage = ApiMessage::create( $msg, $code, $data ); + if (!$apiMessage instanceof Message) { + $apiMessage = new ApiMessage( + $apiMessage, + $apiMessage->getApiCode(), + $apiMessage->getApiData() + ); + } + + $msg = $apiMessage ->inLanguage( $this->lang ) ->title( $this->getDummyTitle() ) ->useDatabase( $this->useDB ); diff --git a/tests/phpunit/includes/api/ApiErrorFormatterTest.php b/tests/phpunit/includes/api/ApiErrorFormatterTest.php index d47481c..c57fb52 100644 --- a/tests/phpunit/includes/api/ApiErrorFormatterTest.php +++ b/tests/phpunit/includes/api/ApiErrorFormatterTest.php @@ -639,4 +639,40 @@ ]; } + public function testAddErrorCanHandleIApiMessage() { + $result = new ApiResult( 1 ); + $apiErrorFormatter = new ApiErrorFormatter( + $result, + Language::factory( 'en' ), + 'none', + false + ); + + $apiErrorFormatter->addError( + null, + $this->createIApiMessage( 'some-error-code', [ 'some-error-data' ] ) + ); + + $resultData = $result->getResultData(); + $error = $resultData['errors'][0]; + $this->assertEquals( 'some-error-code', $error['code'] ); + $this->assertContains( 'some-error-data', $error['data'] ); + } + + /** +* @param string $code +* @param array $data +* +* @return IApiMessage +*/ + private function createIApiMessage( $code, array $data ) { + /** @var IApiMessage|\Prophecy\Prophecy\ObjectProphecy $message */ + $message = $this->prophesize( IApiMessage::class ); + $message->getKey()->willReturn( 'some-IApiMessage-key' ); + $message->getParams()->willReturn( [ 'some-IApiMessage-param' ] ); + $message->getApiCode()->willReturn( $code ); + $message->getApiData()->willReturn( $data ); + + return $message->reveal(); + } } -- To view, visit https://gerrit.wikimedia.org/r/380479 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I94416fe48ffde0bbcfb14b6c5dbed328ddd60cef Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Make ApiUsageException be able to handle status containing I...
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/380463 ) Change subject: Make ApiUsageException be able to handle status containing IApiMessage .. Make ApiUsageException be able to handle status containing IApiMessage Change-Id: I214f8c55d43860fbb470d3a388c34408347d4b2a --- A tests/phpunit/includes/api/ApiUsageExceptionTest.php 1 file changed, 47 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/63/380463/1 diff --git a/tests/phpunit/includes/api/ApiUsageExceptionTest.php b/tests/phpunit/includes/api/ApiUsageExceptionTest.php new file mode 100644 index 000..7e7e2f4 --- /dev/null +++ b/tests/phpunit/includes/api/ApiUsageExceptionTest.php @@ -0,0 +1,47 @@ +createIApiMessage(); + $status->fatal( $expectedMessage ); + + $apiUsageException = new ApiUsageException( + $this->createApiBase(), + $status, + 500 + ); + + $message = $apiUsageException->getMessageObject(); + $this->assertEquals( $expectedMessage->getKey(), $message->getKey() ); + $this->assertEquals( $expectedMessage->getParams(), $message->getParams() ); + $this->assertEquals( $expectedMessage->getApiCode(), $message->getApiCode()); + $this->assertEquals( $expectedMessage->getApiData(), $message->getApiData()); + } + + /** +* @return ApiBase +*/ + private function createApiBase() { + /** @var ApiBase|\Prophecy\Prophecy\ObjectProphecy $apiBase */ + $apiBase = $this->prophesize( ApiBase::class ); + + return $apiBase->reveal(); + } + + /** +* @return IApiMessage +*/ + private function createIApiMessage() { + + /** @var IApiMessage|\Prophecy\Prophecy\ObjectProphecy $message */ + $message = $this->prophesize( IApiMessage::class ); + $message->getKey()->willReturn( 'some-message' ); + $message->getParams()->willReturn( ['some-message-param'] ); + $message->getApiCode()->willReturn( 'some-api-code' ); + $message->getApiData()->willReturn( ['some-api-data'] ); + + return $message->reveal(); + } +} -- To view, visit https://gerrit.wikimedia.org/r/380463 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I214f8c55d43860fbb470d3a388c34408347d4b2a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: [WIP] Make ApiMessage::create throw exception if call is inc...
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/379823 ) Change subject: [WIP] Make ApiMessage::create throw exception if call is inconsistent .. [WIP] Make ApiMessage::create throw exception if call is inconsistent Change-Id: I3ce3f8ed5ebaad9840f615f8996394d690ef3b0e --- M includes/api/ApiMessage.php 1 file changed, 4 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/23/379823/1 diff --git a/includes/api/ApiMessage.php b/includes/api/ApiMessage.php index 9e42d5f..b1814bc 100644 --- a/includes/api/ApiMessage.php +++ b/includes/api/ApiMessage.php @@ -227,6 +227,10 @@ } if ( $msg instanceof IApiMessage ) { + if ( $code !== null || $data !== null ) { + //FIXME Test it + throw new \LogicException( 'Error code or data is specified but should not be' ); + } return $msg; } elseif ( $msg instanceof RawMessage ) { return new ApiRawMessage( $msg, $code, $data ); -- To view, visit https://gerrit.wikimedia.org/r/379823 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3ce3f8ed5ebaad9840f615f8996394d690ef3b0e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Make `ApiUploadTest` up to date so it passes
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/379817 ) Change subject: Make `ApiUploadTest` up to date so it passes .. Make `ApiUploadTest` up to date so it passes Although the test is still might fail from time to time and needs refactoring. Bug: T28169 Change-Id: Ib27a36e0d76495a133eb8941300e4940e5eb670e --- M tests/phpunit/includes/api/ApiUploadTest.php 1 file changed, 5 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/17/379817/1 diff --git a/tests/phpunit/includes/api/ApiUploadTest.php b/tests/phpunit/includes/api/ApiUploadTest.php index 9b79e6c53..159a0e3 100644 --- a/tests/phpunit/includes/api/ApiUploadTest.php +++ b/tests/phpunit/includes/api/ApiUploadTest.php @@ -51,7 +51,6 @@ $this->assertArrayHasKey( "login", $result ); $this->assertArrayHasKey( "result", $result['login'] ); $this->assertEquals( "Success", $result['login']['result'] ); - $this->assertArrayHasKey( 'lgtoken', $result['login'] ); $this->assertNotEmpty( $session, 'API Login must return a session' ); @@ -69,7 +68,7 @@ ] ); } catch ( ApiUsageException $e ) { $exception = true; - $this->assertEquals( 'The "token" parameter must be set', $e->getMessage() ); + $this->assertContains( 'The "token" parameter must be set', $e->getMessage() ); } $this->assertTrue( $exception, "Got exception" ); } @@ -85,8 +84,10 @@ ], $session, self::$users['uploader']->getUser() ); } catch ( ApiUsageException $e ) { $exception = true; - $this->assertEquals( "One of the parameters filekey, file, url is required", - $e->getMessage() ); + $this->assertEquals( + 'One of the parameters "filekey", "file" and "url" is required.', + $e->getMessage() + ); } $this->assertTrue( $exception, "Got exception" ); } -- To view, visit https://gerrit.wikimedia.org/r/379817 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib27a36e0d76495a133eb8941300e4940e5eb670e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Make `setApiData()` protected
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/379815 ) Change subject: Make `setApiData()` protected .. Make `setApiData()` protected Because it is unused Change-Id: I5adfdff92dbd6947b688fd398552b5711c3ba639 Depends-On: I1d31089dd0d2706684875d0d9758a3b50b3cdbc1 --- M includes/api/ApiMessage.php M tests/phpunit/includes/api/ApiMessageTest.php 2 files changed, 1 insertion(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/15/379815/1 diff --git a/includes/api/ApiMessage.php b/includes/api/ApiMessage.php index 9ac2e85..8dcc721 100644 --- a/includes/api/ApiMessage.php +++ b/includes/api/ApiMessage.php @@ -165,11 +165,8 @@ /** * Sets additional machine-readable data about the error condition * @param array $data -* -* @deprecated Use constructor instead. Will be made protected as soon as -* \Wikibase\Repo\Api\ApiErrorReporter doesn't depend on it anymore */ - public function setApiData( array $data ) { + protected function setApiData( array $data ) { $this->apiData = $data; } diff --git a/tests/phpunit/includes/api/ApiMessageTest.php b/tests/phpunit/includes/api/ApiMessageTest.php index fe4057e..f3b3247 100644 --- a/tests/phpunit/includes/api/ApiMessageTest.php +++ b/tests/phpunit/includes/api/ApiMessageTest.php @@ -95,9 +95,6 @@ $this->compareMessages( $msg, $msg2 ); $this->assertEquals( 'foo', $msg2->getApiCode() ); $this->assertEquals( [], $msg2->getApiData() ); - - $msg2->setApiData( [ 'data2' ] ); - $this->assertEquals( [ 'data2' ], $msg2->getApiData() ); } /** @@ -138,9 +135,6 @@ $this->compareMessages( $msg, $msg2 ); $this->assertEquals( 'code', $msg2->getApiCode() ); $this->assertEquals( [ 'data' ], $msg2->getApiData() ); - - $msg2->setApiData( [ 'data2' ] ); - $this->assertEquals( [ 'data2' ], $msg2->getApiData() ); } /** * @covers ApiRawMessage -- To view, visit https://gerrit.wikimedia.org/r/379815 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5adfdff92dbd6947b688fd398552b5711c3ba639 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Remove `setApiData()` usage form ApiErrorReporter
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/379789 ) Change subject: Remove `setApiData()` usage form ApiErrorReporter .. Remove `setApiData()` usage form ApiErrorReporter In all the mediawiki code this method is only used by ApiErrorReporter. This blocks removing the method from the ApiMessage class. Change-Id: I1d31089dd0d2706684875d0d9758a3b50b3cdbc1 --- M repo/includes/Api/ApiErrorReporter.php 1 file changed, 24 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/89/379789/1 diff --git a/repo/includes/Api/ApiErrorReporter.php b/repo/includes/Api/ApiErrorReporter.php index f210e6f..2b4b9a5 100644 --- a/repo/includes/Api/ApiErrorReporter.php +++ b/repo/includes/Api/ApiErrorReporter.php @@ -124,14 +124,16 @@ } $error = $this->getPlainErrorMessageFromStatus( $status ); - $msg = $this->getMessageForCode( $errorCode, $error ); + + $extraData = $this->convertStatusErrorsToExtraData( $status ); + + $msg = $this->getMessageForCode( $errorCode, $error, $extraData ); $extendedStatus = StatusValue::newFatal( $msg ); $extendedStatus->merge( $status, true ); $status = $extendedStatus; - $this->addStatusToResult( $status, $extraData ); - $msg->setApiData( $extraData ); + $this->addStatusToResult( $status, $_ignore ); $stats = MediaWikiServices::getInstance()->getStatsdDataFactory(); $stats->increment( 'wikibase.repo.api.errors.total' ); @@ -241,7 +243,6 @@ $msg = $this->getMessageForCode( $errorCode, $description, $extraData ); $this->addMessageToResult( $msg, $extraData ); - $msg->setApiData( $extraData ); $this->trackAndDieWithError( $msg, $errorCode, $extraData, $httpRespCode ); @@ -266,6 +267,11 @@ // TODO: Should we use the ApiRawMessage class instead? $msg = wfMessage( [ $messageKey, 'rawmessage' ], $params ); } + + $this->addMessageToResult( $msg, $extraData ); + + $thisMessage = array_pop( $extraData['messages'] ); + array_unshift( $extraData['messages'], $thisMessage ); return ApiMessage::create( $msg, $errorCode, $extraData ); } @@ -521,4 +527,18 @@ return null; } + /** +* @param StatusValue $status +* @return array +*/ + private function convertStatusErrorsToExtraData( StatusValue $status ) { + $errors = $status->getErrorsByType( 'error' ); + $errorMessages = $this->convertToMessageList( $errors ); + $extraData = []; + foreach ( $errorMessages as $errorMessage ) { + $this->addMessageToResult( $errorMessage, $extraData ); + } + return $extraData; + } + } -- To view, visit https://gerrit.wikimedia.org/r/379789 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1d31089dd0d2706684875d0d9758a3b50b3cdbc1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Removed unused methods `setApiCode` and `setApiData` from IA...
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/379761 ) Change subject: Removed unused methods `setApiCode` and `setApiData` from IApiMessage .. Removed unused methods `setApiCode` and `setApiData` from IApiMessage To be honest `setApiData` method is not completely unused. The method is called in `\Wikibase\Repo\Api\ApiErrorReporter` so that is why it is still left public in ApiMessageTrait but marked as `@deprecated` Change-Id: Ib246932262c4dd0c1bb4f055c73d2ff866870cce --- M includes/api/ApiMessage.php M tests/phpunit/includes/api/ApiMessageTest.php 2 files changed, 32 insertions(+), 34 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/61/379761/1 diff --git a/includes/api/ApiMessage.php b/includes/api/ApiMessage.php index 9e42d5f..9ac2e85 100644 --- a/includes/api/ApiMessage.php +++ b/includes/api/ApiMessage.php @@ -49,19 +49,6 @@ * @return array */ public function getApiData(); - - /** -* Sets the machine-readable code for use by the API -* @param string|null $code If null, uses the default (see self::getApiCode()) -* @param array|null $data If non-null, passed to self::setApiData() -*/ - public function setApiCode( $code, array $data = null ); - - /** -* Sets additional machine-readable data about the error condition -* @param array $data -*/ - public function setApiData( array $data ); } /** @@ -155,7 +142,12 @@ return $this->apiCode; } - public function setApiCode( $code, array $data = null ) { + /** +* Sets the machine-readable code for use by the API +* @param string|null $code If null, uses the default (see self::getApiCode()) +* @param array|null $data If non-null, passed to self::setApiData() +*/ + protected function setApiCode( $code, array $data = null ) { if ( $code !== null && !( is_string( $code ) && $code !== '' ) ) { throw new InvalidArgumentException( "Invalid code \"$code\"" ); } @@ -170,6 +162,13 @@ return $this->apiData; } + /** +* Sets additional machine-readable data about the error condition +* @param array $data +* +* @deprecated Use constructor instead. Will be made protected as soon as +* \Wikibase\Repo\Api\ApiErrorReporter doesn't depend on it anymore +*/ public function setApiData( array $data ) { $this->apiData = $data; } diff --git a/tests/phpunit/includes/api/ApiMessageTest.php b/tests/phpunit/includes/api/ApiMessageTest.php index c6f5a8e..fe4057e 100644 --- a/tests/phpunit/includes/api/ApiMessageTest.php +++ b/tests/phpunit/includes/api/ApiMessageTest.php @@ -52,14 +52,6 @@ * @param mixed $code */ public function testInvalidCode( $code ) { - $msg = new ApiMessage( 'foo' ); - try { - $msg->setApiCode( $code ); - $this->fail( 'Expected exception not thrown' ); - } catch ( InvalidArgumentException $ex ) { - $this->assertTrue( true ); - } - try { new ApiMessage( 'foo', $code ); $this->fail( 'Expected exception not thrown' ); @@ -104,14 +96,18 @@ $this->assertEquals( 'foo', $msg2->getApiCode() ); $this->assertEquals( [], $msg2->getApiData() ); - $msg2->setApiCode( 'code', [ 'data' ] ); - $this->assertEquals( 'code', $msg2->getApiCode() ); - $this->assertEquals( [ 'data' ], $msg2->getApiData() ); - $msg2->setApiCode( null ); - $this->assertEquals( 'foo', $msg2->getApiCode() ); - $this->assertEquals( [ 'data' ], $msg2->getApiData() ); $msg2->setApiData( [ 'data2' ] ); $this->assertEquals( [ 'data2' ], $msg2->getApiData() ); + } + + /** +* @covers ApiMessage +* @covers ApiMessageTrait +*/ + public function testApiMessage_CreatedWithoutCode_UsesMessageKeyAsAnApiCode() { + $msg = new ApiMessage( 'foo' ); + + $this->assertEquals( 'foo', $msg->getApiCode() ); } /** @@ -143,15 +139,18 @@ $this->assertEquals( 'code', $msg2->getApiCode() ); $this->assertEquals( [ 'data' ], $msg2->getApiData() ); - $msg2->setApiCode( 'code', [ 'data' ] ); - $this->assertEquals( 'code', $msg2->getApiCode() ); - $this->assertEquals( [ 'data' ], $msg2->getApiData() ); - $msg2->setApiCode( null ); - $this->assertEquals( 'foo', $msg2->getA
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Extract SummaryDescription interface
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/379214 ) Change subject: Extract SummaryDescription interface .. Extract SummaryDescription interface Code related to formatting doesn't care about half of the methods on the Summary class, so here is the interface describing what is really important. Change-Id: Ifb13e562ad8cd74a60f66f18f453f72b899ef4c2 --- M lib/includes/Summary.php A lib/includes/SummaryDescription.php M repo/includes/Api/EntitySavingHelper.php M repo/includes/Interactors/ItemMergeInteractor.php M repo/includes/Interactors/RedirectCreationInteractor.php M repo/includes/Specials/SpecialWikibaseRepoPage.php M repo/includes/SummaryFormatter.php M repo/includes/UpdateRepo/UpdateRepoJob.php 8 files changed, 79 insertions(+), 18 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/14/379214/1 diff --git a/lib/includes/Summary.php b/lib/includes/Summary.php index e75f5ad..a0c2691 100644 --- a/lib/includes/Summary.php +++ b/lib/includes/Summary.php @@ -10,7 +10,7 @@ * @author Daniel Kinzler * @author Tobias Gritschacher < tobias.gritschac...@wikimedia.de > */ -class Summary { +class Summary implements SummaryDescription { /** * @var string|null diff --git a/lib/includes/SummaryDescription.php b/lib/includes/SummaryDescription.php new file mode 100644 index 000..cce1a1c --- /dev/null +++ b/lib/includes/SummaryDescription.php @@ -0,0 +1,59 @@ +-summary" then with "wikibase-entity-summary". +* Displayed message will be the first one that exists. +* +* @note When displaying to the user, arguments to the target message will be: +* - $1: number of AutoSummaryArgs +* - $2: language code (empty if no language code is provided in summary) +* - $3: CommentArg with index 0 (if present) +* - ... +* - $n: CommentArg with index n-3 (if present) +* +* @return string with a non-prefixed message key +*/ + public function getMessageKey(); + + /** +* Comment args will be used as parameters for the message. +* +* @note Element with index 0 in comment args will be $3 in the message +* +* @return array +*/ + public function getCommentArgs(); + + /** +* Get the user-provided edit summary +* +* @return string|null +*/ + public function getUserSummary(); + + /** +* Get the language part of the autocomment +* +* @note Will be passed as $2 argument to the message. +* +* @return string|null +*/ + public function getLanguageCode(); + + /** +* @return array Array or associative array of values that were changed in new revision +* +* @note Simple array will be displayed as comma separated list of values: e.g. "a, b". +* Associative array will be displayed as comma separated list of values +* prefixed with keys, e.g. "en: en-label, fr: fr-label" +*/ + public function getAutoSummaryArgs(); + +} diff --git a/repo/includes/Api/EntitySavingHelper.php b/repo/includes/Api/EntitySavingHelper.php index eeca24c..ecc2231 100644 --- a/repo/includes/Api/EntitySavingHelper.php +++ b/repo/includes/Api/EntitySavingHelper.php @@ -17,7 +17,7 @@ use Wikibase\Lib\Store\EntityRevisionLookup; use Wikibase\Lib\Store\EntityStore; use Wikibase\Lib\Store\StorageException; -use Wikibase\Summary; +use Wikibase\SummaryDescription; use Wikibase\SummaryFormatter; /** @@ -296,7 +296,7 @@ * handleStatus()). * * @param EntityDocument $entity The entity to save -* @param string|Summary $summary The edit summary +* @param string|SummaryDescription $summary The edit summary * @param int $flags The edit flags (see WikiPage::doEditContent) * * @throws LogicException if not in write mode @@ -319,7 +319,7 @@ ); } - if ( $summary instanceof Summary ) { + if ( $summary instanceof SummaryDescription ) { $summary = $this->summaryFormatter->formatSummary( $summary ); } diff --git a/repo/includes/Interactors/ItemMergeInteractor.php b/repo/includes/Interactors/ItemMergeInteractor.php index a712427..7149348 100644 --- a/repo/includes/Interactors/ItemMergeInteractor.php +++ b/repo/includes/Interactors/ItemMergeInteractor.php @@ -19,6 +19,7 @@ use Wikibase\Lib\Store\StorageException; use Wikibase\Repo\Store\EntityPermissionChecker; use Wikibase\Summary; +use Wikibase\SummaryDescription; use Wikibase\SummaryFormatter; /** @@ -264,7 +265,7 @@ return [ $fromRev, $toRev ]; } -
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: [WIP] Add add form summary
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/379135 ) Change subject: [WIP] Add add form summary .. [WIP] Add add form summary Change-Id: I921f9e7356645ef9fb5dce4c6c1c771900c36cb4 TODO: Add message --- M src/Api/AddForm.php A src/Api/AddFormSummary.php 2 files changed, 78 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/35/379135/1 diff --git a/src/Api/AddForm.php b/src/Api/AddForm.php index 74df872..708024a 100644 --- a/src/Api/AddForm.php +++ b/src/Api/AddForm.php @@ -101,9 +101,7 @@ //FIXME: Module description message //FIXME: Parameters messages //FIXME: Examples - //FIXME: Serialize nextFormId //FIXME: Response structure? - Added form - //FIXME: Don't show nextFormId in response $params = $this->extractRequestParams(); $parserResult = $this->requestParser->parse( $params ); @@ -126,7 +124,8 @@ $lexemeId = $request->getLexemeId(); $lexeme = $this->entitySavingHelper->loadEntity( $lexemeId ); $newForm = $request->addFormTo( $lexeme ); - $status = $this->entitySavingHelper->attemptSaveEntity( $lexeme, new Summary() ); + $summary = new AddFormSummary( $lexemeId, $newForm ); + $status = $this->entitySavingHelper->attemptSaveEntity( $lexeme, $summary ); $apiResult = $this->getResult(); @@ -151,9 +150,6 @@ self::PARAM_REQUIRED => true, ], 'token' => null, - 'baserevid' => [ - self::PARAM_TYPE => 'integer', - ], 'bot' => [ self::PARAM_TYPE => 'boolean', self::PARAM_DFLT => false, diff --git a/src/Api/AddFormSummary.php b/src/Api/AddFormSummary.php new file mode 100644 index 000..e8eba16 --- /dev/null +++ b/src/Api/AddFormSummary.php @@ -0,0 +1,76 @@ +lexemeId = $lexemeId; + $this->addedForm = $addedForm; + } + + public function getUserSummary() { + return null; + } + + public function getLanguageCode() { + return null; + } + + public function getMessageKey() { + return 'add-form'; + } + + public function getCommentArgs() { + return [ $this->addedForm->getId()->getSerialization() ]; + } + + public function getAutoSummaryArgs() { + return array_values( $this->addedForm->getRepresentations()->toTextArray() ); + } + + public function getModuleName() { + throw new \LogicException( "Should not be called" ); + } + + public function getActionName() { + throw new \LogicException( "Should not be called" ); + } + + public function addAutoCommentArgs( $args /*...*/ ) { + throw new \LogicException( "Should not be called" ); + } + + public function addAutoSummaryArgs( $args /*...*/ ) { + throw new \LogicException( "Should not be called" ); + } + + public function setUserSummary( $summary = null ) { + throw new \LogicException( "Should not be called" ); + } + + public function setLanguage( $languageCode = null ) { + throw new \LogicException( "Should not be called" ); + } + + public function setModuleName( $name ) { + throw new \LogicException( "Should not be called" ); + } + + public function setAction( $name ) { + throw new \LogicException( "Should not be called" ); + } + +} -- To view, visit https://gerrit.wikimedia.org/r/379135 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I921f9e7356645ef9fb5dce4c6c1c771900c36cb4 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: [WIP] Browser tests for Form ID counter when revert/undo
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378730 ) Change subject: [WIP] Browser tests for Form ID counter when revert/undo .. [WIP] Browser tests for Form ID counter when revert/undo Change-Id: I45f1c9c4a0ff9a1b8637e90bf0b78da3f6a0a27f --- M tests/browser/features/forms.feature M tests/browser/features/step_definitions/forms_steps.rb A tests/browser/features/support/pages/entity_history_page.rb M tests/browser/features/support/pages/lexeme_page.rb A tests/browser/features/support/pages/undo_page.rb 5 files changed, 72 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/30/378730/1 diff --git a/tests/browser/features/forms.feature b/tests/browser/features/forms.feature index 537fe03..d151fd2 100644 --- a/tests/browser/features/forms.feature +++ b/tests/browser/features/forms.feature @@ -81,3 +81,21 @@ Scenario: I can see each Form's statements Given I have a Lexeme with a Form Then for each Form there is a statement list + + @integration + Scenario: FormId counter is not decremented when change is undone +Given I am on a Lexeme page + Then I add a Form + Then I go to the history page + And I undo the latest change + When I add a Form + Then the new Form has the ID greater than the previous one + + @integration + Scenario: FormId counter is not decremented when old revision is restored +Given I am on a Lexeme page + And I add a Form + Then I go to the history page + And I restore the previous revision + When I add a Form + Then the new Form has the ID greater than the previous one diff --git a/tests/browser/features/step_definitions/forms_steps.rb b/tests/browser/features/step_definitions/forms_steps.rb index 7bbe413..2c237c6 100644 --- a/tests/browser/features/step_definitions/forms_steps.rb +++ b/tests/browser/features/step_definitions/forms_steps.rb @@ -148,3 +148,38 @@ Then(/^the first Form should no longer have the removed grammatical feature$/) do expect(@form_I_am_currently_editing.grammatical_feature?(@grammatical_feature_to_delete)).to be false end + +Then(/^I add a Form$/) do + step 'I click the Forms list add button' + step 'I enter "some representation" as the "en" form representation' + step 'I save the Form' +end + +Then(/^I go to the history page$/) do + @last_form_id_before_undo = on(LexemePage).forms[-1].id_element.text + on(LexemePage).history_link_element.when_visible.click +end + + +Then(/^I undo the latest change$/) do + # pick latest revision and click "undo" link + on(EntityHistoryPage).revisions[0].undo_element.when_visible.click + # confirm "undo" + on(UndoPage).save_page.when_visible.click + # got back to the initial Lexeme page +end + +Then(/^I restore the previous revision$/) do + # pick latest revision and click "undo" link + on(EntityHistoryPage).revisions[1].undo_element.when_visible.click + # confirm "undo" + on(UndoPage).save_page.when_visible.click + # got back to the initial Lexeme page +end + +Then(/^the new Form has the ID greater than the previous one$/) do + last_form_id = on(LexemePage).forms[-1].id_element.text + + expect(last_form_id).to > @last_form_id_before_undo +end + diff --git a/tests/browser/features/support/pages/entity_history_page.rb b/tests/browser/features/support/pages/entity_history_page.rb new file mode 100644 index 000..6c7f6d2 --- /dev/null +++ b/tests/browser/features/support/pages/entity_history_page.rb @@ -0,0 +1,12 @@ +class EntityRevision + include PageObject + + a(:undo, css: '.mw-history-undo a') + a(:restore, text: 'restore') #This link doesn't have any css identifier +end + +class EntityHistoryPage + include PageObject + + page_sections(:revisions, EntityRevision, css: 'ul#pagehistory > li') +end \ No newline at end of file diff --git a/tests/browser/features/support/pages/lexeme_page.rb b/tests/browser/features/support/pages/lexeme_page.rb index e254a00..4da7f07 100644 --- a/tests/browser/features/support/pages/lexeme_page.rb +++ b/tests/browser/features/support/pages/lexeme_page.rb @@ -112,6 +112,8 @@ include PageObject include EntityPage + element(:history_link, css: '#ca-history a') + span(:forms_header, id: 'forms') div(:forms_container, class: 'wikibase-lexeme-forms') h3(:form_representation, class: 'wikibase-lexeme-form-representation') diff --git a/tests/browser/features/support/pages/undo_page.rb b/tests/browser/features/support/pages/undo_page.rb new file mode 100644 index 000..40a57bc --- /dev/null +++ b/tests/browser/features/support/pages/undo_page.rb @@ -0,0 +1,5 @@ +class UndoPage + include PageObject + + button(:save_page, css:'form#undo button') +end \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/378730 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Simplify Eris usage in tests
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378421 ) Change subject: Simplify Eris usage in tests .. Simplify Eris usage in tests Added ErisTest trait that controls correct setUp and tearDown Change-Id: Ib43a6812e3efb02b1cfff0d7144f0bc94b0704ae --- M tests/phpunit/composer/DataModel/Services/Diff/FormDifferPatcherTest.php M tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php A tests/phpunit/composer/ErisGenerators/ErisTest.php A tests/phpunit/composer/ErisGenerators/PHPUnitTestCaseWrapper.php 4 files changed, 123 insertions(+), 24 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/21/378421/1 diff --git a/tests/phpunit/composer/DataModel/Services/Diff/FormDifferPatcherTest.php b/tests/phpunit/composer/DataModel/Services/Diff/FormDifferPatcherTest.php index 4443d8c..45205cc 100644 --- a/tests/phpunit/composer/DataModel/Services/Diff/FormDifferPatcherTest.php +++ b/tests/phpunit/composer/DataModel/Services/Diff/FormDifferPatcherTest.php @@ -2,7 +2,6 @@ namespace Wikibase\Lexeme\Tests\DataModel\Services\Diff; -use Eris\Facade; use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\Entity\PropertyId; use Wikibase\DataModel\Snak\PropertySomeValueSnak; @@ -12,25 +11,22 @@ use Wikibase\Lexeme\DataModel\Services\Diff\FormDiffer; use Wikibase\Lexeme\DataModel\Services\Diff\FormPatcher; use Wikibase\Lexeme\Tests\DataModel\NewForm; +use Wikibase\Lexeme\Tests\ErisGenerators\ErisTest; use Wikibase\Lexeme\Tests\ErisGenerators\WikibaseLexemeGenerators; class FormDifferPatcherTest extends \PHPUnit_Framework_TestCase { - public function testProperty_PatchingLexemeWithGeneratedDiffAlwaysRestoresItToTheTargetState() { - if ( !class_exists( Facade::class ) ) { - $this->markTestSkipped( 'Package `giorgiosironi/eris` is not installed. Skipping' ); - } + use ErisTest; + public function testProperty_PatchingLexemeWithGeneratedDiffAlwaysRestoresItToTheTargetState() { $differ = new FormDiffer(); $patcher = new FormPatcher(); - //Lines below is needed to reproduce failures. In case of failure seed will be in the output - //$seed = 1504876177284329; - //putenv("ERIS_SEED=$seed"); + //Line below is needed to reproduce failures. In case of failure seed will be in the output + //$this->eris()->seed(1504876177284329)->forAll( ... - $eris = new Facade(); - - $eris->forAll( + $this->eris() + ->forAll( WikibaseLexemeGenerators::form( new FormId( 'F1' ) ), WikibaseLexemeGenerators::form( new FormId( 'F1' ) ) ) diff --git a/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php b/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php index 0b7e26e..d500d3b 100644 --- a/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php +++ b/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php @@ -2,14 +2,12 @@ namespace Wikibase\Lexeme\Tests\DataModel\Services\Diff; -use Wikibase\DataModel\Entity\ItemId; -use Wikibase\Lexeme\DataModel\Form; use Wikibase\Lexeme\DataModel\FormId; -use Eris\Facade; use Wikibase\Lexeme\DataModel\Lexeme; use Wikibase\Lexeme\DataModel\LexemeId; use Wikibase\Lexeme\DataModel\Services\Diff\LexemeDiffer; use Wikibase\Lexeme\DataModel\Services\Diff\LexemePatcher; +use Wikibase\Lexeme\Tests\ErisGenerators\ErisTest; use Wikibase\Lexeme\Tests\ErisGenerators\WikibaseLexemeGenerators; use Wikibase\Lexeme\Tests\DataModel\NewForm; use Wikibase\Lexeme\Tests\DataModel\NewLexeme; @@ -24,21 +22,17 @@ */ class LexemeDifferPatcherTest extends \PHPUnit_Framework_TestCase { - public function testProperty_PatchingLexemeWithGeneratedDiffAlwaysRestoresItToTheTargetState() { - if ( !class_exists( Facade::class ) ) { - $this->markTestSkipped( 'Package `giorgiosironi/eris` is not installed. Skipping' ); - } + use ErisTest; + public function testProperty_PatchingLexemeWithGeneratedDiffAlwaysRestoresItToTheTargetState() { $differ = new LexemeDiffer(); $patcher = new LexemePatcher(); - //Lines below is needed to reproduce failures. In case of failure seed will be in the output - //$seed = 1504876177284329; - //putenv("ERIS_SEED=$seed"); + //Line below is needed to reproduce failures. In case of failure seed will be in the output + //$this->eris()->seed(1504876177284329)->forAll( ... - $eris = new Facade(); - - $eris-
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add TermList (lemmaList) shrinking
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378414 ) Change subject: Add TermList (lemmaList) shrinking .. Add TermList (lemmaList) shrinking Change-Id: I5a3e09b2393fb2e4f4239efee90be3de6c79cfbb --- A tests/phpunit/composer/ErisGenerators/CartesianProduct.php A tests/phpunit/composer/ErisGenerators/CartesianProductTest.php M tests/phpunit/composer/ErisGenerators/LexemeGenerator.php M tests/phpunit/composer/ErisGenerators/TermListGenerator.php 4 files changed, 290 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/14/378414/1 diff --git a/tests/phpunit/composer/ErisGenerators/CartesianProduct.php b/tests/phpunit/composer/ErisGenerators/CartesianProduct.php new file mode 100644 index 000..fe8b232 --- /dev/null +++ b/tests/phpunit/composer/ErisGenerators/CartesianProduct.php @@ -0,0 +1,115 @@ +generatedValues = $generatedValues; + } + + public function map( callable $fn, $generatorName = 'CartesianProduct' ) { + $result = $this->combine( $generatorName ); + + return $result->map( + function ( array $args ) use ( $fn ) { + return call_user_func_array( $fn, $args ); + }, + $generatorName + ); + } + + /** +* @param $generatorName +* +* @return GeneratedValueOptions +*/ + private function combine( $generatorName ) { + if ( count( $this->generatedValues ) === 1 ) { + return $this->generatedValues[0]->map( + function ( $v ) { + return [ $v ]; + }, + $generatorName + ); + } + + $result = $this->cartesianProduct( + $this->generatedValues[0], + $this->generatedValues[1], + $generatorName, + function ( $v1, $v2 ) { + return [ $v1, $v2 ]; + } + ); + + for ( $i = 2; $i < count( $this->generatedValues ); $i++ ) { + $result = $this->cartesianProduct( + $result, + $this->generatedValues[$i], + $generatorName, + function ( array $args, $value ) { + $args[] = $value; + return $args; + } + ); + } + + return $result; + } + + private function cartesianProduct( + GeneratedValueOptions $v1, + GeneratedValueOptions $v2, + $generatorName, + callable $merge + ) { + $options = []; + foreach ( $v1 as $firstPart ) { + foreach ( $v2 as $secondPart ) { + $options[] = GeneratedValueSingle::fromValueAndInput( + $merge( $firstPart->unbox(), $secondPart->unbox() ), + $merge( $firstPart->input(), $secondPart->input() ), + $generatorName + ); + } + } + return new GeneratedValueOptions( $options ); + } + +} diff --git a/tests/phpunit/composer/ErisGenerators/CartesianProductTest.php b/tests/phpunit/composer/ErisGenerators/CartesianProductTest.php new file mode 100644 index 000..90e120f --- /dev/null +++ b/tests/phpunit/composer/ErisGenerators/CartesianProductTest.php @@ -0,0 +1,135 @@ +createOptionsWithSingleValue( 1 ); + + /** @var GeneratedValueOptions $result */ + $result = CartesianProduct::create( $opt1 ) + ->map( + function ( $n1 ) { + return $n1; + } + ); + + $this->assertEquals( 1, $result->count() ); + $this->assertEquals( 1, $result->first()->unbox() ); + } + + public function testCanHandleTwoGeneratedValueOptions() { + $opt1 = $this->createOptionsWithSingleValue( 1 ); + $opt2 = $this->createOptionsWithSingleValue( 2 ); + + /** @var GeneratedValueOptions $result */ + $result = CartesianProduct::create( $opt1, $opt2 ) + ->map( + function ( $n1, $n2 ) { + return [ $n1
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add FormSet shrinking
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378413 ) Change subject: Add FormSet shrinking .. Add FormSet shrinking Change-Id: I4b3500f7587cf68435a758e10cb5ddf4c9163bd2 --- M tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php A tests/phpunit/composer/ErisGenerators/CartesianProduct.php A tests/phpunit/composer/ErisGenerators/CartesianProductTest.php M tests/phpunit/composer/ErisGenerators/FormSetGenerator.php M tests/phpunit/composer/ErisGenerators/LexemeGenerator.php 5 files changed, 278 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/13/378413/1 diff --git a/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php b/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php index 42572ba..0b7e26e 100644 --- a/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php +++ b/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php @@ -43,6 +43,10 @@ WikibaseLexemeGenerators::lexeme( new LexemeId( 'L1' ) ) ) ->then( function ( Lexeme $lexeme1, Lexeme $lexeme2 ) use ( $differ, $patcher ) { + // Deep cloning is needed because $lexeme1 gets mutated in this test. + // Because of mutation shrinking will work incorrectly + $lexeme1 = unserialize( serialize( $lexeme1 ) ); + $patch = $differ->diffEntities( $lexeme1, $lexeme2 ); $patcher->patchEntity( $lexeme1, $patch ); diff --git a/tests/phpunit/composer/ErisGenerators/CartesianProduct.php b/tests/phpunit/composer/ErisGenerators/CartesianProduct.php new file mode 100644 index 000..7649459 --- /dev/null +++ b/tests/phpunit/composer/ErisGenerators/CartesianProduct.php @@ -0,0 +1,91 @@ +generatedValues = $generatedValues; + } + + public function map( callable $fn, $generatorName = 'CartesianProduct' ) { + $result = $this->combine( $generatorName ); + + return $result->map( + function ( array $args ) use ( $fn ) { + return call_user_func_array( $fn, $args ); + }, + $generatorName + ); + } + + /** +* @param $generatorName +* +* @return GeneratedValueOptions +*/ + private function combine( $generatorName ) { + if ( count( $this->generatedValues ) === 1 ) { + return $this->generatedValues[0]->map( + function ( $v ) { + return [ $v ]; + }, + $generatorName + ); + } + + $result = $this->generatedValues[0]->cartesianProduct( + $this->generatedValues[1], + function ( $v1, $v2 ) { + return [ $v1, $v2 ]; + } + ); + + for ( $i = 2; $i < count( $this->generatedValues ); $i++ ) { + $result = $result->cartesianProduct( + $this->generatedValues[2], + function ( array $args, $value ) { + $args[] = $value; + return $args; + } + ); + } + return $result; + } + +} diff --git a/tests/phpunit/composer/ErisGenerators/CartesianProductTest.php b/tests/phpunit/composer/ErisGenerators/CartesianProductTest.php new file mode 100644 index 000..5f52aa7 --- /dev/null +++ b/tests/phpunit/composer/ErisGenerators/CartesianProductTest.php @@ -0,0 +1,119 @@ +createOptionsWithSingleValue( 1 ); + + /** @var GeneratedValueOptions $result */ + $result = CartesianProduct::create( $opt1 ) + ->map( + function ( $n1 ) { + return $n1; + } + ); + + $this->assertEquals( 1, $result->count() ); + $this->assertEquals( 1, $result->first()->unbox() ); + } + + public function testCanHandleTwoGeneratedValueOptions() { + $opt1 = $this->createOptionsWithSingleValue( 1 ); + $opt2 = $this->createOptionsWithSingleValue( 2 ); + + /** @var GeneratedValueOptions $result */ + $result = CartesianProduct::create( $opt1, $opt2 ) + ->map( +
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Consider FormSets equal if they contain the same forms
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378412 ) Change subject: Consider FormSets equal if they contain the same forms .. Consider FormSets equal if they contain the same forms Make toArray() return Forms ordered by their ID Change-Id: I735fbf133b846354637a12f3294a60e4db687f86 --- M src/DataModel/FormSet.php M tests/phpunit/composer/DataModel/FormSetTest.php 2 files changed, 22 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/12/378412/1 diff --git a/src/DataModel/FormSet.php b/src/DataModel/FormSet.php index eec9ea5..31d7c6a 100644 --- a/src/DataModel/FormSet.php +++ b/src/DataModel/FormSet.php @@ -32,7 +32,9 @@ * @return Form[] */ public function toArray() { - return array_values( $this->forms ); + $forms = $this->forms; + ksort( $forms ); + return array_values( $forms ); } public function count() { diff --git a/tests/phpunit/composer/DataModel/FormSetTest.php b/tests/phpunit/composer/DataModel/FormSetTest.php index 4e5ba36..6d603c8 100644 --- a/tests/phpunit/composer/DataModel/FormSetTest.php +++ b/tests/phpunit/composer/DataModel/FormSetTest.php @@ -88,4 +88,23 @@ $this->assertCount( 0, $formSet->toArray() ); } + public function testIndependentlyOnFormAdditionOrder_TwoSetsAreEqualIfTheyHaveTheSameForms() { + $form1 = NewForm::havingId( 'F1' )->build(); + $form2 = NewForm::havingId( 'F2' )->build(); + + $formSet1 = new FormSet( [ $form1, $form2 ] ); + $formSet2 = new FormSet( [ $form2, $form1 ] ); + + $this->assertEquals( $formSet1, $formSet2 ); + } + + public function testToArray_ReturnedFormsAreSortedByTheirId() { + $form1 = NewForm::havingId( 'F1' )->build(); + $form2 = NewForm::havingId( 'F2' )->build(); + + $formSet2 = new FormSet( [ $form2, $form1 ] ); + + $this->assertEquals( [ $form1, $form2 ], $formSet2->toArray() ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/378412 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I735fbf133b846354637a12f3294a60e4db687f86 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Make grammaticalFeatures as set
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378411 ) Change subject: Make grammaticalFeatures as set .. Make grammaticalFeatures as set Add type assertion to the setter Change-Id: I412cd8b8192297d4714ace2a9c73be4dc8b73f44 --- M src/DataModel/Form.php M tests/phpunit/composer/DataModel/FormTest.php 2 files changed, 42 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/11/378411/1 diff --git a/src/DataModel/Form.php b/src/DataModel/Form.php index 067864a..2ba1464 100644 --- a/src/DataModel/Form.php +++ b/src/DataModel/Form.php @@ -53,11 +53,10 @@ '$representations', 'Form must have at least one representation' ); - Assert::parameterElementType( ItemId::class, $grammaticalFeatures, '$grammaticalFeatures' ); $this->id = $id; $this->representations = $representations; - $this->grammaticalFeatures = $grammaticalFeatures; + $this->setGrammaticalFeatures( $grammaticalFeatures ); $this->statementList = $statementList ?: new StatementList(); } @@ -83,8 +82,20 @@ } public function setGrammaticalFeatures( array $grammaticalFeatures ) { - //TODO Add uniqueness check because grammaticalFeatures is a set - $this->grammaticalFeatures = $grammaticalFeatures; + Assert::parameterElementType( ItemId::class, $grammaticalFeatures, '$grammaticalFeatures' ); + + $result = []; + foreach ( $grammaticalFeatures as $grammaticalFeature ) { + if ( array_search( $grammaticalFeature, $result ) === false ) { + $result[] = $grammaticalFeature; + } + } + + usort( $result, function ( ItemId $a, ItemId $b ) { + return strcmp( $a->getSerialization(), $b->getSerialization() ); + } ); + + $this->grammaticalFeatures = $result; } /** diff --git a/tests/phpunit/composer/DataModel/FormTest.php b/tests/phpunit/composer/DataModel/FormTest.php index 2f914f3..eeddd4d 100644 --- a/tests/phpunit/composer/DataModel/FormTest.php +++ b/tests/phpunit/composer/DataModel/FormTest.php @@ -4,6 +4,7 @@ use InvalidArgumentException; use PHPUnit_Framework_TestCase; +use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\Term\Term; use Wikibase\DataModel\Term\TermList; use Wikibase\Lexeme\DataModel\Form; @@ -40,4 +41,30 @@ ); } + public function testSetGrammaticalFeatures_RemovesDuplicateItemIds() { + $form = NewForm::havingId( 'F1' )->build(); + + $form->setGrammaticalFeatures( [ new ItemId( 'Q1' ), new ItemId( 'Q1' ) ] ); + + $this->assertEquals( [ new ItemId( 'Q1' ) ], $form->getGrammaticalFeatures() ); + } + + public function testSetGrammaticalFeatures_AlphabeticallySortsItemIdsByTheirSerialization() { + $form = NewForm::havingId( 'F1' )->build(); + + $form->setGrammaticalFeatures( [ new ItemId( 'z:Q1' ), new ItemId( 'a:Q1' ) ] ); + + $this->assertEquals( + [ new ItemId( 'a:Q1' ), new ItemId( 'z:Q1' ) ], + $form->getGrammaticalFeatures() + ); + } + + public function testSetGrammaticalFeatures_NonItemIdIsGiven_ThrowsException() { + $form = NewForm::havingId( 'F1' )->build(); + + $this->setExpectedException( \InvalidArgumentException::class ); + $form->setGrammaticalFeatures( [ "Q1" ] ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/378411 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I412cd8b8192297d4714ace2a9c73be4dc8b73f44 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add patching of multiple forms
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378410 ) Change subject: Add patching of multiple forms .. Add patching of multiple forms Change-Id: I8cab581cf9291f942aa597d4db249ae5865a03c5 --- M src/DataModel/Services/Diff/ChangeFormDiffOp.php M src/DataModel/Services/Diff/LexemePatcher.php M tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php 3 files changed, 50 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/10/378410/1 diff --git a/src/DataModel/Services/Diff/ChangeFormDiffOp.php b/src/DataModel/Services/Diff/ChangeFormDiffOp.php index 67d9496..7cdc8fb 100644 --- a/src/DataModel/Services/Diff/ChangeFormDiffOp.php +++ b/src/DataModel/Services/Diff/ChangeFormDiffOp.php @@ -24,6 +24,13 @@ } /** +* @return FormId +*/ + public function getFormId() { + return $this->formId; + } + + /** * @return Diff */ public function getRepresentationDiffOps() { diff --git a/src/DataModel/Services/Diff/LexemePatcher.php b/src/DataModel/Services/Diff/LexemePatcher.php index 1c20b2c..ea72bce 100644 --- a/src/DataModel/Services/Diff/LexemePatcher.php +++ b/src/DataModel/Services/Diff/LexemePatcher.php @@ -141,7 +141,7 @@ } } - private function patchForms( Lexeme $entity, LexemeDiff $patch ) { + private function patchForms( Lexeme $lexeme, LexemeDiff $patch ) { $formsDiff = $patch->getFormsDiff(); foreach ( $formsDiff as $formDiff ) { switch ( get_class( $formDiff ) ) { @@ -149,7 +149,7 @@ /** @var DiffOpAdd $formDiff */ /** @var Form $form */ $form = $formDiff->getNewValue(); - $entity->patch( + $lexeme->patch( function ( LexemePatchAccess $patchAccess ) use ( $form ) { $patchAccess->addForm( $form ); } @@ -159,15 +159,15 @@ /** @var DiffOpRemove $formDiff */ /** @var Form $form */ $form = $formDiff->getOldValue(); - $entity->removeForm( $form->getId() ); + $lexeme->removeForm( $form->getId() ); break; case ChangeFormDiffOp::class: /** @var ChangeFormDiffOp $formDiff */ /** @var Form $form */ - //TODO: This implementation is incomplete/incorrect. - //TODO: Proper implementation of Forms patching is needed - $form = $entity->getForms()[0]; - $this->formPatcher->patch( $form, $formDiff ); + if ( $lexeme->hasForm( $formDiff->getFormId() ) ) { + $form = $lexeme->getForm( $formDiff->getFormId() ); + $this->formPatcher->patch( $form, $formDiff ); + } break; default: throw new PatcherException( 'Invalid forms list diff: ' . get_class( $formDiff ) ); diff --git a/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php b/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php index 9632933..35ac4ea 100644 --- a/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php +++ b/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php @@ -159,4 +159,40 @@ ); } + public function testDiffAndPatchCanPatchAllForms() { + $differ = new LexemeDiffer(); + $patcher = new LexemePatcher(); + $initialLexeme = NewLexeme::create(); + $lexeme1 = $initialLexeme + ->withForm( + NewForm::havingId( 'F1' ) + ->andRepresentation( 'en', 'value-1-1' ) + )->withForm( + NewForm::havingId( 'F2' ) + ->andRepresentation( 'en', 'value-1-2' ) + )->build(); + $lexeme2 = $initial
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add ability to get exact Form from Lexeme
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378409 ) Change subject: Add ability to get exact Form from Lexeme .. Add ability to get exact Form from Lexeme Change-Id: I0bfbcd4cf0692ce61670c18bb75b6c30e5d1dd84 --- M src/DataModel/FormSet.php M src/DataModel/Lexeme.php M tests/phpunit/composer/DataModel/LexemeTest.php 3 files changed, 51 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/09/378409/1 diff --git a/src/DataModel/FormSet.php b/src/DataModel/FormSet.php index 6933dbc..eec9ea5 100644 --- a/src/DataModel/FormSet.php +++ b/src/DataModel/FormSet.php @@ -68,4 +68,15 @@ unset( $this->forms[$formId->getSerialization()] ); } + /** +* @param FormId $formId +* +* @return Form|null +*/ + public function getById( FormId $formId ) { + return isset( $this->forms[$formId->getSerialization()] ) ? + $this->forms[$formId->getSerialization()] + : null; + } + } diff --git a/src/DataModel/Lexeme.php b/src/DataModel/Lexeme.php index 7c92c22..37c54af 100644 --- a/src/DataModel/Lexeme.php +++ b/src/DataModel/Lexeme.php @@ -281,6 +281,21 @@ return $this->nextFormId; } + public function hasForm( FormId $formId ) { + return (bool)$this->forms->getById( $formId ); + } + + public function getForm( FormId $formId ) { + if ( !$this->hasForm( $formId ) ) { + throw new \OutOfRangeException( + "Lexeme {$this->id->getSerialization()} doesn't have Form " . + "{$formId->getSerialization()}. Use hasForm() to check first" + ); + } + + return $this->forms->getById( $formId ); + } + /** * @param TermList $representations * @param ItemId[] $grammaticalFeatures diff --git a/tests/phpunit/composer/DataModel/LexemeTest.php b/tests/phpunit/composer/DataModel/LexemeTest.php index 788f61d..2627288 100644 --- a/tests/phpunit/composer/DataModel/LexemeTest.php +++ b/tests/phpunit/composer/DataModel/LexemeTest.php @@ -481,6 +481,31 @@ $this->assertEquals( [], $lexeme->getForms() ); } + public function testHasForm_LexemeDoesnHaveForms_ReturnsFalse() { + $lexeme = NewLexeme::create()->build(); + + $this->assertFalse( $lexeme->hasForm( new FormId( 'F1' ) ) ); + } + + public function testHasForm_LexemeHaveFormWithThatId_ReturnsTrue() { + $lexeme = NewLexeme::havingForm( NewForm::havingId( 'F1' ) )->build(); + + $this->assertTrue( $lexeme->hasForm( new FormId( 'F1' ) ) ); + } + + public function testGetForm_LexemeHaveFormWithThatId_ReturnsThatForm() { + $lexeme = NewLexeme::havingForm( NewForm::havingId( 'F1' ) )->build(); + + $this->assertInstanceOf( Form::class, $lexeme->getForm( new FormId( 'F1' ) ) ); + } + + public function testGetForm_LexemeDoesntHabeFormWithThatId_ThrowsAnException() { + $lexeme = NewLexeme::havingId( 'L1' )->build(); + + $this->setExpectedException( \OutOfRangeException::class ); + $lexeme->getForm( new FormId( 'F1' ) ); + } + public function testPatch_IncreaseNextFormIdTo_GivenLexemWithGreaterId_Increases() { $lexemeWithoutForm = NewLexeme::create()->build(); $this->assertEquals( 1, $lexemeWithoutForm->getNextFormId() ); -- To view, visit https://gerrit.wikimedia.org/r/378409 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0bfbcd4cf0692ce61670c18bb75b6c30e5d1dd84 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Diffing and patching individual Forms
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378050 ) Change subject: Diffing and patching individual Forms .. Diffing and patching individual Forms Change-Id: Ifd7021ad3f7267c7c894aa6b21a930e781ab697e --- M src/DataModel/Form.php A src/DataModel/Services/Diff/ChangeFormDiffOp.php A src/DataModel/Services/Diff/FormDiffer.php A src/DataModel/Services/Diff/FormPatcher.php A tests/phpunit/composer/DataModel/Services/Diff/FormDifferPatcherTest.php 5 files changed, 322 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/50/378050/1 diff --git a/src/DataModel/Form.php b/src/DataModel/Form.php index fa3f73f..067864a 100644 --- a/src/DataModel/Form.php +++ b/src/DataModel/Form.php @@ -82,6 +82,11 @@ return $this->grammaticalFeatures; } + public function setGrammaticalFeatures( array $grammaticalFeatures ) { + //TODO Add uniqueness check because grammaticalFeatures is a set + $this->grammaticalFeatures = $grammaticalFeatures; + } + /** * @see StatementListProvider::getStatements() */ diff --git a/src/DataModel/Services/Diff/ChangeFormDiffOp.php b/src/DataModel/Services/Diff/ChangeFormDiffOp.php new file mode 100644 index 000..e89e9f3 --- /dev/null +++ b/src/DataModel/Services/Diff/ChangeFormDiffOp.php @@ -0,0 +1,76 @@ +formId = $formId; + $this->diffOps = $diffOps; + } + + /** +* @return Diff +*/ + public function getRepresentataionDiffOps() { + return isset( $this->diffOps['representations'] ) ? + $this->diffOps['representations'] + : new Diff( [] ); + } + + /** +* @return Diff +*/ + public function getGrammaticalFeaturesDiffOps() { + return isset( $this->diffOps['grammaticalFeatures'] ) ? + $this->diffOps['grammaticalFeatures'] + : new Diff( [] ); + } + + /** +* @return Diff +*/ + public function getStatementsDiffOps() { + return isset( $this->diffOps['claim'] ) ? + $this->diffOps['claim'] + : new Diff( [] ); + } + + public function serialize() { + } + + public function unserialize( $serialized ) { + } + + public function getType() { +// return 'diff/lexeme/form'; + return 'diff'; + } + + public function isAtomic() { + return false; + } + + public function toArray( $valueConverter = null ) { + throw new \LogicException( "toArray() is not implemented" ); + } + + public function count() { + throw new \LogicException( "count() is not implemented" ); + } + +} diff --git a/src/DataModel/Services/Diff/FormDiffer.php b/src/DataModel/Services/Diff/FormDiffer.php new file mode 100644 index 000..58d624a --- /dev/null +++ b/src/DataModel/Services/Diff/FormDiffer.php @@ -0,0 +1,61 @@ +recursiveMapDiffer = new MapDiffer( true ); + $this->statementListDiffer = new StatementListDiffer(); + } + + /** +* @param Form $old +* @param Form $new +* +* @return ChangeFormDiffOp +*/ + public function diff( Form $old, Form $new ) { + //TODO: Assert same ID + $diffOps = $this->recursiveMapDiffer->doDiff( + $this->toFormDiffArray( $old ), + $this->toFormDiffArray( $new ) + ); + + $diffOps['claim'] = $this->statementListDiffer->getDiff( + $old->getStatements(), + $new->getStatements() + ); + + return new ChangeFormDiffOp( $old->getId(), new Diff( $diffOps ) ); + } + + /** +* @param Form $form +* +* @return string[] +*/ + private function toFormDiffArray( Form $form ) { + $result = []; + $result['representations'] = $form->getRepresentations()->toTextArray(); + $result['grammaticalFeatures'] = $form->getGrammaticalFeatures(); + + return $result; + } + +} diff --git a/src/DataModel/Services/Diff/FormPatcher.php b/src/DataModel/Services/Diff/FormPatcher.php new file mode 100644 index 000..0c3541a --- /dev/null +++ b/src/DataModel/Services/Diff/FormPatcher.php @@ -0,0 +1,36 @@ +termListPatcher = new TermListPatcher(); + $this->statementListPatcher = new StatementListPatcher(); + $this->listPatcher = new ListPatcher( true ); + } + + public function patch( Form $form, ChangeFormDiffOp $diff ) { + $this->termListPa
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Introduce `patch()` method on Lexeme to have more control ov...
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378036 ) Change subject: Introduce `patch()` method on Lexeme to have more control over state .. Introduce `patch()` method on Lexeme to have more control over state Change-Id: I7efe71832d1b7b0b1cba765e2b1c3c80e8e836bd --- M src/DataModel/Lexeme.php A src/DataModel/LexemePatchAccess.php A tests/phpunit/composer/DataModel/LexemePatchAccessTest.php M tests/phpunit/composer/DataModel/LexemeTest.php 4 files changed, 319 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/36/378036/1 diff --git a/src/DataModel/Lexeme.php b/src/DataModel/Lexeme.php index d7e5fee..7c92c22 100644 --- a/src/DataModel/Lexeme.php +++ b/src/DataModel/Lexeme.php @@ -300,6 +300,40 @@ } /** +* @param int $number +*/ + private function increaseNextFormIdTo( $number ) { + if ( !is_int( $number ) ) { + throw new \InvalidArgumentException( '$nextFormId` must be integer' ); + } + + if ( $number < $this->nextFormId ) { + throw new \LogicException( + "Cannot increase `nextFormId` because given number is less than counter value " . + "of this Lexeme. Current=`{$this->nextFormId}`, given=`{$number}`" + ); + } + + $this->nextFormId = $number; + } + + public function patch( callable $patcher ) { + $lexemePatchAccess = new LexemePatchAccess( $this->nextFormId, $this->forms ); + try { + $patcher( $lexemePatchAccess ); + } finally { + $lexemePatchAccess->close(); + } + $newFormSet = new FormSet( $lexemePatchAccess->getForms() ); + $newNextFormId = $lexemePatchAccess->getNextFormId(); + + $this->assertCorrectNextFormIdIsGiven( $newNextFormId, $newFormSet ); + + $this->increaseNextFormIdTo( $newNextFormId ); + $this->forms = $newFormSet; + } + + /** * @param mixed $nextFormId * @param Form[] $forms */ diff --git a/src/DataModel/LexemePatchAccess.php b/src/DataModel/LexemePatchAccess.php new file mode 100644 index 000..3224958 --- /dev/null +++ b/src/DataModel/LexemePatchAccess.php @@ -0,0 +1,82 @@ +nextFormId = $nextFormId; + $this->forms = clone $forms; + } + + public function addForm( Form $form ) { + $this->assertIsNotClosed(); + + $this->forms->add( $form ); + } + + /** +* @param int $number +*/ + public function increaseNextFormIdTo( $number ) { + if ( !is_int( $number ) ) { + throw new \InvalidArgumentException( '$nextFormId` must be integer' ); + } + + if ( $number < $this->nextFormId ) { + throw new \LogicException( + "Cannot increase `nextFormId` because given number is less than counter value " . + "of this Lexeme. Current=`{$this->nextFormId}`, given=`{$number}`" + ); + } + + $this->nextFormId = $number; + } + + public function close() { + $this->isClosed = true; + } + + /** +* @return Form[] +*/ + public function getForms() { + return $this->forms->toArray(); + } + + /** +* @return int +*/ + public function getNextFormId() { + return $this->nextFormId; + } + + private function assertIsNotClosed() { + if ( $this->isClosed ) { + throw new \LogicException( "Cannot modify closed LexemePatchAccess" ); + } + } + +} diff --git a/tests/phpunit/composer/DataModel/LexemePatchAccessTest.php b/tests/phpunit/composer/DataModel/LexemePatchAccessTest.php new file mode 100644 index 000..9ee745c --- /dev/null +++ b/tests/phpunit/composer/DataModel/LexemePatchAccessTest.php @@ -0,0 +1,68 @@ +build(); + + $lexemePatchAccess->addForm( $form ); + + $this->assertEquals( [ $form ], $lexemePatchAccess->getForms() ); + } + + public function testCanNotAddAFormIfPatchAccessIsClosed() { + $forms = new FormSet( [] ); + $lexemePatchAccess = new LexemePatchAccess( 1, $forms ); + $form = NewForm::any()->build(); + $lexemePatchAccess->close(); + + $this->setExpectedException( \Exception::class ); + $lexemePatchAccess->addForm( $form ); + } + + public function testDoe
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: [DNM] Generate Lexeme with forms
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378029 ) Change subject: [DNM] Generate Lexeme with forms .. [DNM] Generate Lexeme with forms Change-Id: I8e5ca10ce400c92d95cfcdda10a5a9ca8f78f9a1 WARNING: There is a bug in the code patching grammatical features --- M src/DataModel/Form.php M src/DataModel/FormSet.php M tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php A tests/phpunit/composer/ErisGenerators/FormGenerator.php A tests/phpunit/composer/ErisGenerators/FormSetGenerator.php M tests/phpunit/composer/ErisGenerators/LexemeGenerator.php M tests/phpunit/composer/ErisGenerators/TermGenerator.php M tests/phpunit/composer/ErisGenerators/TermListGenerator.php 8 files changed, 198 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/29/378029/1 diff --git a/src/DataModel/Form.php b/src/DataModel/Form.php index 4b58842..6b2b57e 100644 --- a/src/DataModel/Form.php +++ b/src/DataModel/Form.php @@ -57,7 +57,7 @@ $this->id = $id; $this->representations = $representations; - $this->grammaticalFeatures = $grammaticalFeatures; + $this->setGrammaticalFeatures( $grammaticalFeatures ); $this->statementList = $statementList ?: new StatementList(); } @@ -83,6 +83,10 @@ } public function setGrammaticalFeatures( array $grammaticalFeatures ) { + usort( $grammaticalFeatures, function ( ItemId $a, ItemId $b ) { + return strcmp( $a->getSerialization(), $b->getSerialization() ); + } ); + //TODO Add uniqueness check as soon as grammaticalFeatures is a set $this->grammaticalFeatures = $grammaticalFeatures; } diff --git a/src/DataModel/FormSet.php b/src/DataModel/FormSet.php index 6933dbc..36cedf3 100644 --- a/src/DataModel/FormSet.php +++ b/src/DataModel/FormSet.php @@ -32,7 +32,9 @@ * @return Form[] */ public function toArray() { - return array_values( $this->forms ); + $forms = $this->forms; + ksort( $forms ); + return array_values( $forms ); } public function count() { @@ -68,4 +70,15 @@ unset( $this->forms[$formId->getSerialization()] ); } + /** +* @param FormId $formId +* +* @return Form|null +*/ + public function getForm( FormId $formId ) { + return isset( $this->forms[$formId->getSerialization()] ) ? + $this->forms[$formId->getSerialization()] + : null; + } + } diff --git a/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php b/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php index 5a8af91..d191f24 100644 --- a/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php +++ b/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php @@ -39,15 +39,43 @@ $eris = new Facade(); + $counter = 0; $eris->forAll( WikibaseLexemeGenerators::lexeme( new LexemeId( 'L1' ) ), WikibaseLexemeGenerators::lexeme( new LexemeId( 'L1' ) ) ) - ->then( function ( Lexeme $lexeme1, Lexeme $lexeme2 ) use ( $differ, $patcher ) { + ->then( function ( Lexeme $lexeme1, Lexeme $lexeme2 ) use ( $differ, $patcher, &$counter ) { + $counter++; $patch = $differ->diffEntities( $lexeme1, $lexeme2 ); $patcher->patchEntity( $lexeme1, $patch ); - $this->assertTrue( $lexeme1->equals( $lexeme2 ), 'Lexemes are not equal' ); + $this->assertTrue( + $lexeme1->getLanguage()->equals( $lexeme2->getLanguage() ), + 'Lexemes have different languages' + ); + $this->assertTrue( + $lexeme1->getLexicalCategory()->equals( $lexeme2->getLexicalCategory() ), + 'Lexemes have different lexical categories' + ); + $this->assertTrue( + $lexeme1->getStatements()->equals( $lexeme2->getStatements() ), + 'Lexemes have different statements' + ); + $this->assertTrue( + $lexeme1->getLemmas()->
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Move ErisGenerators outside the `DataModel\Services\Diff` na...
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378014 ) Change subject: Move ErisGenerators outside the `DataModel\Services\Diff` namespace .. Move ErisGenerators outside the `DataModel\Services\Diff` namespace Change-Id: I88a6c93b1fea2b6221e4caf60da0c56f3c13dd65 --- M tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php R tests/phpunit/composer/ErisGenerators/ItemIdGenerator.php R tests/phpunit/composer/ErisGenerators/LanguageCodeGenerator.php R tests/phpunit/composer/ErisGenerators/LexemeGenerator.php R tests/phpunit/composer/ErisGenerators/TermGenerator.php R tests/phpunit/composer/ErisGenerators/TermListGenerator.php R tests/phpunit/composer/ErisGenerators/WikibaseLexemeGenerators.php 7 files changed, 7 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/14/378014/1 diff --git a/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php b/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php index 9fc0663..5a8af91 100644 --- a/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php +++ b/tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php @@ -12,6 +12,7 @@ use Wikibase\Lexeme\DataModel\Services\Diff\LexemePatcher; use Wikibase\Lexeme\Tests\DataModel\NewForm; use Wikibase\Lexeme\Tests\DataModel\NewLexeme; +use Wikibase\Lexeme\Tests\ErisGenerators\WikibaseLexemeGenerators; use Wikibase\Repo\Tests\NewStatement; /** diff --git a/tests/phpunit/composer/DataModel/Services/Diff/ErisGenerators/ItemIdGenerator.php b/tests/phpunit/composer/ErisGenerators/ItemIdGenerator.php similarity index 94% rename from tests/phpunit/composer/DataModel/Services/Diff/ErisGenerators/ItemIdGenerator.php rename to tests/phpunit/composer/ErisGenerators/ItemIdGenerator.php index 3210a75..bbe69dd 100644 --- a/tests/phpunit/composer/DataModel/Services/Diff/ErisGenerators/ItemIdGenerator.php +++ b/tests/phpunit/composer/ErisGenerators/ItemIdGenerator.php @@ -1,6 +1,6 @@ https://gerrit.wikimedia.org/r/378014 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I88a6c93b1fea2b6221e4caf60da0c56f3c13dd65 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: [WIP] Diffing and Patching Lexeme forms and nextFormId
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/377798 ) Change subject: [WIP] Diffing and Patching Lexeme forms and nextFormId .. [WIP] Diffing and Patching Lexeme forms and nextFormId Change-Id: Icfa5d5bfcbe7e48cab9f1d4c99eeba1bd656d39f --- M docs/federation.wiki M docs/options.wiki M lib/includes/RepositoryDefinitions.php M repo/includes/Specials/SpecialEntityData.php M repo/includes/Store/Sql/SqlStore.php M repo/includes/WikibaseRepo.php M repo/tests/phpunit/includes/Content/EntityHandlerTest.php M repo/tests/phpunit/includes/Store/Sql/SqlStoreTest.php M repo/tests/phpunit/includes/Store/StoreTest.php M repo/tests/phpunit/includes/WikibaseRepoTest.php 10 files changed, 136 insertions(+), 271 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/98/377798/1 diff --git a/docs/federation.wiki b/docs/federation.wiki index 3b0ed1e..240e1f6 100644 --- a/docs/federation.wiki +++ b/docs/federation.wiki @@ -4,8 +4,8 @@ * Foreign EntityIds and mappings are documented in the file docs/foreign-entity-ids.wiki in the wikibase/data-model component. As of March 2017, in order to enable access to entities from federated repositories both Repo and Client components must be enabled. Also as of March 2017, accessing data of foreign entities relies on the shared database access (databases of federated repositories must be in the same database cluster). -* Local repository is configured as documented in docs/options.wiki. Note that as of March 2017, database of the local repository is configured based on Client's settings (''repoDatabase'' setting). -* Configuration of foreign repositories is done using the ''foreignRepositories'' setting in $wgWBClientSettings, as documented in the file docs/options.wiki. +* Local repository is configured as documented in docs/options.wiki. +* Configuration of foreign repositories is done using the ''foreignRepositories'' setting in $wgWBRepoSettings or $wgWBClientSettings, as documented in the file docs/options.wiki. * In order to correctly link entities from foreign repositories, the local wiki must have MediaWiki interwiki prefixes configured for each foreign repository. As of March 2017, the interwiki prefix must be the same as the name used for the foreign repository. If there is no interwiki prefix configured for the wiki containing the foreign repository, it can be added e.g. by adding a row to the interwiki database table, or by using [[Special:Interwiki]] if the Interwiki extension is enabled on the local wiki. Note that as of March 2017 it is only possible for Wikibase to use entities from a single repository, either local or foreign. For instance, it is not possible to use both local and foreign items in statements. @@ -17,7 +17,7 @@ Note that as only foreign properties from the repository "prop" are to be used, this example configuration only enables local items explicitly. -$wgWBClientSettings['foreignRepositories'] = [ +$wgWBRepoSettings['foreignRepositories'] = [ 'prop' => [ 'repoDatabase' => 'propwiki', 'entityNamespaces' => [ 'property' => WB_NS_PROPERTY ], @@ -25,5 +25,5 @@ 'baseUri' => 'http://prop.wiki/entity/', ], ]; -$wgWBClientSettings['repoNamespaces'] = [ 'item' => WB_NS_ITEM ]; +$wgWBRepoSettings['entityNamespaces'] = [ 'item' => WB_NS_ITEM ]; diff --git a/docs/options.wiki b/docs/options.wiki index e2b8f95..fb35a24 100644 --- a/docs/options.wiki +++ b/docs/options.wiki @@ -12,6 +12,11 @@ ;siteLinkGroups: The site groups to use in sitelinks. Must correspond to a value used to give the site group in the MediaWiki sites table. Default is array( 'wikipedia' ). This defines which groups of sites can be linked to Wikibase items. :'''Note''' that this setting replaces the old ''siteLinkGroup'' setting, which only allowed for a single group. ;specialSiteLinkGroups: This maps one or more site groups into a single "special" group. This is useful if sites from multiple site groups should be shown in a single "special" section on item pages, instead of one section per site group. To show these site-groups you have to add the group "special" to the '''siteLinkGroups''' setting (see above). +;foreignRepositories: An associative array mapping foreign repository names to settings relevant to the particular repository. Each repository's settings are an associative array containing the following keys: +:;'entityNamespaces': A map of entity type identifiers (strings) that the local wiki supports from the foreign repository to namespaces identifiers (numbers) related to pages of entities of the given type on foreign repository's wiki.. +:;'repoDatabase': A symbolic database identifier (string) that MediaWiki's LBFactory class understands. +:;'baseUri': A base URI (string) for concept URIs. It should
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Remove performance enhancement
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/377298 ) Change subject: Remove performance enhancement .. Remove performance enhancement As soon as there is some internal state in Lexeme that had to be carried over the revisions, the assumption made here is not valid anymore Change-Id: Ic7193898a570ecead807f1a77f1cced0abe8be89 --- M repo/includes/Actions/SubmitEntityAction.php 1 file changed, 0 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/98/377298/1 diff --git a/repo/includes/Actions/SubmitEntityAction.php b/repo/includes/Actions/SubmitEntityAction.php index df6c88e..4e8a624 100644 --- a/repo/includes/Actions/SubmitEntityAction.php +++ b/repo/includes/Actions/SubmitEntityAction.php @@ -157,11 +157,6 @@ $newerContent = $newerRevision->getContent(); $latestContent = $latestRevision->getContent(); - // Skip diffing and patching when possible for performance reasons - if ( $newerRevision->getId() === $latestRevision->getId() ) { - return $olderContent; - } - return $latestContent->getPatchedCopy( $newerContent->getDiff( $olderContent ) ); } -- To view, visit https://gerrit.wikimedia.org/r/377298 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic7193898a570ecead807f1a77f1cced0abe8be89 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Remove DemoData
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/377284 ) Change subject: Remove DemoData .. Remove DemoData Change-Id: Idd8b20fcca349a06f0fb18d92cf2608b113b163e --- M src/Content/LexemeContent.php M src/DataModel/Lexeme.php D src/DemoData/AskOut1Populator.php D src/DemoData/AskOut2Populator.php D src/DemoData/AskOut3Populator.php D src/DemoData/HardLexemePopulator.php D src/DemoData/Id.php D src/DemoData/LeiterLexemePopulator.php 8 files changed, 1 insertion(+), 438 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/84/377284/1 diff --git a/src/Content/LexemeContent.php b/src/Content/LexemeContent.php index 5856d90..2f4649a 100644 --- a/src/Content/LexemeContent.php +++ b/src/Content/LexemeContent.php @@ -51,24 +51,7 @@ throw new LogicException( 'This content object is empty!' ); } - /** @var Lexeme $lexeme */ - $lexeme = $this->lexemeHolder->getEntity( Lexeme::class ); - - // TODO: This is a test dummy that must be removed later - $id = $lexeme->getId()->getSerialization(); - if ( $id === DemoData\Id::L_HARD ) { - ( new DemoData\HardLexemePopulator() )->populate( $lexeme ); - } elseif ( $id === DemoData\Id::L_LEITER ) { - ( new DemoData\LeiterLexemePopulator() )->populate( $lexeme ); - } elseif ( $id === DemoData\Id::L_ASK_1 ) { - ( new DemoData\AskOut1Populator() )->populate( $lexeme ); - } elseif ( $id === DemoData\Id::L_ASK_2 ) { - ( new DemoData\AskOut2Populator() )->populate( $lexeme ); - } elseif ( $id === DemoData\Id::L_ASK_OUT ) { - ( new DemoData\AskOut3Populator() )->populate( $lexeme ); - } - - return $lexeme; + return $this->lexemeHolder->getEntity( Lexeme::class ); } /** diff --git a/src/DataModel/Lexeme.php b/src/DataModel/Lexeme.php index d6cba22..62977a7 100644 --- a/src/DataModel/Lexeme.php +++ b/src/DataModel/Lexeme.php @@ -256,26 +256,10 @@ } /** -* @param Form[] $forms -* @deprecated Temporary method, for demo. Just don't use. -*/ - public function setForms( array $forms ) { - $this->forms = $forms; - } - - /** * @return Sense[] */ public function getSenses() { return $this->senses; - } - - /** -* @param Sense[] $senses -* @deprecated Only for demonstration purposes. Do not use otherwise! -*/ - public function setSenses( array $senses ) { - $this->senses = $senses; } /** diff --git a/src/DemoData/AskOut1Populator.php b/src/DemoData/AskOut1Populator.php deleted file mode 100644 index e0944c1..000 --- a/src/DemoData/AskOut1Populator.php +++ /dev/null @@ -1,26 +0,0 @@ -buildDefaultSense(); - - $lexeme->setForms( [] ); - $lexeme->setSenses( [ $defaultSense ] ); - } - - /** -* @return \Wikibase\Lexeme\DataModel\Sense -*/ - private function buildDefaultSense() { - return NewSense::havingId( 'S5' ) - ->withGloss( 'en', '’To ask somebody out’: To request a romantic date' ) - ->build(); - } - -} diff --git a/src/DemoData/AskOut2Populator.php b/src/DemoData/AskOut2Populator.php deleted file mode 100644 index f10315a..000 --- a/src/DemoData/AskOut2Populator.php +++ /dev/null @@ -1,32 +0,0 @@ -buildDefaultSense(); - - $lexeme->setForms( [] ); - $lexeme->setSenses( [ $defaultSense ] ); - } - - /** -* @return \Wikibase\Lexeme\DataModel\Sense -*/ - private function buildDefaultSense() { - return NewSense::havingId( 'S5' ) - ->withGloss( 'en', 'To request a romantic date' ) - ->withStatement( - NewStatement::forProperty( Id::P_GRAMMATICAL_FRAME ) - ->withValue( 'to $somebody out' ) - ->withSomeGuid() - ) - ->build(); - } - -} diff --git a/src/DemoData/AskOut3Populator.php b/src/DemoData/AskOut3Populator.php deleted file mode 100644 index afd8062..000 --- a/src/DemoData/AskOut3Populator.php +++ /dev/null @@ -1,26 +0,0 @@ -buildDefaultSense(); - - $lexeme->setForms( [] ); - $lexeme->setSenses( [ $defaultSense ] ); - } - - /** -* @return \Wikibase\Lexeme\DataModel\Sense -*/ - private function buildDefaultSense() { -
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: [WIP] Diffing and Patching Lexeme forms and nextFormId
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/376781 ) Change subject: [WIP] Diffing and Patching Lexeme forms and nextFormId .. [WIP] Diffing and Patching Lexeme forms and nextFormId Change-Id: Icfa5d5bfcbe7e48cab9f1d4c99eeba1bd656d39f --- M src/DataModel/Lexeme.php A src/DataModel/LexemePatchAccess.php M src/DataModel/Services/Diff/LexemeDiff.php M src/DataModel/Services/Diff/LexemeDiffer.php M src/DataModel/Services/Diff/LexemePatcher.php M tests/phpunit/composer/DataModel/LexemeTest.php A tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php 7 files changed, 241 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/81/376781/1 diff --git a/src/DataModel/Lexeme.php b/src/DataModel/Lexeme.php index 81aa582..b81ae22 100644 --- a/src/DataModel/Lexeme.php +++ b/src/DataModel/Lexeme.php @@ -296,6 +296,24 @@ } /** +* @param int $number +*/ + public function increaseNextFormIdTo( $number ) { + if ( !is_int( $number ) ) { + throw new \InvalidArgumentException( '$nextFormId` must be integer' ); + } + + if ( $number < $this->nextFormId ) { + throw new \LogicException( + "Cannot increase `nextFormId` because given number is less than counter value " . + "of this Lexeme. Current=`{$this->nextFormId}`, given=`{$number}`" + ); + } + + $this->nextFormId = $number; + } + + /** * @param TermList $representations * @param ItemId[] $grammaticalFeatures * @@ -313,6 +331,17 @@ $this->forms->remove( $formId ); } + public function patch( callable $patcher ) { + try { + $lexemePatchAccess = new LexemePatchAccess(); + $patcher( $lexemePatchAccess ); + + } finally { + $lexemePatchAccess->close(); + $this->assertCorrectNextFormIdIsGiven( $this->nextFormId, $this->forms ); + } + } + /** * @param mixed $nextFormId * @param Form[] $forms diff --git a/src/DataModel/LexemePatchAccess.php b/src/DataModel/LexemePatchAccess.php new file mode 100644 index 000..270ab4c --- /dev/null +++ b/src/DataModel/LexemePatchAccess.php @@ -0,0 +1,13 @@ +fixSubstructureDiff( $operations, 'lemmas' ); $this->fixSubstructureDiff( $operations, 'lexicalCategory' ); $this->fixSubstructureDiff( $operations, 'language' ); @@ -56,13 +57,24 @@ } /** +* @return Diff +*/ + public function getFormsDiff() { + return isset( $this['forms'] ) ? $this['forms'] : new Diff( [], true ); + } + + /** * Returns if there are any changes (equivalent to: any differences between the entities). * * @return bool */ public function isEmpty() { return $this->getLemmasDiff()->isEmpty() - && $this->getClaimsDiff()->isEmpty(); + && $this->getClaimsDiff()->isEmpty(); + } + + public function getNextFormIdDiff() { + return $this['nextFormId']; } } diff --git a/src/DataModel/Services/Diff/LexemeDiffer.php b/src/DataModel/Services/Diff/LexemeDiffer.php index 374c147..fb4fff2 100644 --- a/src/DataModel/Services/Diff/LexemeDiffer.php +++ b/src/DataModel/Services/Diff/LexemeDiffer.php @@ -3,11 +3,14 @@ namespace Wikibase\Lexeme\DataModel\Services\Diff; use Diff\Differ\MapDiffer; +use Diff\DiffOp\Diff\Diff; +use Diff\DiffOp\DiffOpChange; use UnexpectedValueException; use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Services\Diff\EntityDiff; use Wikibase\DataModel\Services\Diff\EntityDifferStrategy; use Wikibase\DataModel\Services\Diff\StatementListDiffer; +use Wikibase\Lexeme\DataModel\Form; use Wikibase\Lexeme\DataModel\Lexeme; use Wikimedia\Assert\Assert; use InvalidArgumentException; @@ -75,6 +78,13 @@ $to->getStatements() ); + $diffOps['nextFormId'] = $this->getNextFormIdCounterDiff( $from, $to ); + + $diffOps['forms'] = $this->getFormsDiff( + $from->getForms(), + $to->getForms() + ); + return new LexemeDiff( $diffOps ); } @@ -132,4 +142,43 @@ return $this->diffEntities( $entity, new Lexeme() ); } + /** +* @param Form[] $from +* @param Form[] $to +* +* @return Diff; +*/ + private function getFormsDiff( array $
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Take Lexeme's `nextFormId` into account when compare for equ...
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/376758 ) Change subject: Take Lexeme's `nextFormId` into account when compare for equality .. Take Lexeme's `nextFormId` into account when compare for equality Change-Id: I3b3e01b98dd96fa0282e6ed1d901ec65a76909cc --- M src/DataModel/FormSet.php M src/DataModel/Lexeme.php M tests/phpunit/composer/DataModel/FormSetTest.php M tests/phpunit/composer/DataModel/LexemeTest.php 4 files changed, 37 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/58/376758/1 diff --git a/src/DataModel/FormSet.php b/src/DataModel/FormSet.php index 93018d4..6933dbc 100644 --- a/src/DataModel/FormSet.php +++ b/src/DataModel/FormSet.php @@ -64,4 +64,8 @@ $this->forms[$formId] = $form; } + public function remove( FormId $formId ) { + unset( $this->forms[$formId->getSerialization()] ); + } + } diff --git a/src/DataModel/Lexeme.php b/src/DataModel/Lexeme.php index 7f8a4ab..81aa582 100644 --- a/src/DataModel/Lexeme.php +++ b/src/DataModel/Lexeme.php @@ -167,11 +167,13 @@ || ( $this->language !== null && $this->language->equals( $target->language ) ); + $sameFormIdCounter = $this->nextFormId === $target->nextFormId; $sameForms = $this->forms == $target->forms; return $this->lemmas->equals( $target->lemmas ) && $sameLexicalCategory && $sameLanguage + && $sameFormIdCounter && $sameForms && $this->statements->equals( $target->statements ); } @@ -307,6 +309,10 @@ return $form; } + public function removeForm( FormId $formId ) { + $this->forms->remove( $formId ); + } + /** * @param mixed $nextFormId * @param Form[] $forms diff --git a/tests/phpunit/composer/DataModel/FormSetTest.php b/tests/phpunit/composer/DataModel/FormSetTest.php index b542844..d6e0134 100644 --- a/tests/phpunit/composer/DataModel/FormSetTest.php +++ b/tests/phpunit/composer/DataModel/FormSetTest.php @@ -2,6 +2,7 @@ namespace Wikibase\Lexeme\Tests\DataModel; +use Wikibase\Lexeme\DataModel\FormId; use Wikibase\Lexeme\DataModel\FormSet; class FormSetTest extends \PHPUnit_Framework_TestCase { @@ -72,4 +73,12 @@ $formSet->add( NewForm::havingId( 'F1' )->build() ); } + public function testRemove_CanRemoveAForm() { + $formSet = new FormSet( [ NewForm::havingId( 'F1' )->build() ] ); + + $formSet->remove( new FormId( 'F1' ) ); + + $this->assertCount( 0, $formSet->toArray() ); + } + } diff --git a/tests/phpunit/composer/DataModel/LexemeTest.php b/tests/phpunit/composer/DataModel/LexemeTest.php index e290ce4..711bd19 100644 --- a/tests/phpunit/composer/DataModel/LexemeTest.php +++ b/tests/phpunit/composer/DataModel/LexemeTest.php @@ -275,6 +275,12 @@ $language1 = new ItemId( 'Q3' ); $language2 = new ItemId( 'Q5' ); + + $newLexeme = NewLexeme::create(); + $lexemeWithInitialFormCounter = $newLexeme->build(); + $lexemeWithChangedFormCounter = $newLexeme->withForm( NewForm::havingId( 'F1' ) )->build(); + $lexemeWithChangedFormCounter->removeForm( new FormId( 'F1' ) ); + return [ 'null' => [ new Lexeme(), @@ -307,6 +313,10 @@ new Lexeme( new LexemeId( 'L1' ), null, null, null, null, 2, [ NewForm::havingId( 'F1' )->build() ] ), + ], + 'different internal form index counter state' => [ + $lexemeWithInitialFormCounter, + $lexemeWithChangedFormCounter, ] ]; } @@ -446,4 +456,12 @@ $this->assertEquals( new FormId( 'F2' ), $newForm2->getId() ); } + public function testRemoveAForm() { + $lexeme = NewLexeme::havingForm( NewForm::havingId( 'F1' ) )->build(); + + $lexeme->removeForm( new FormId( 'F1' ) ); + + $this->assertEquals( [], $lexeme->getForms() ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/376758 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3b3e01b98dd96fa0282e6ed1d901ec65a76909cc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) _
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Property based test for LexemeDiffer and LexemePatcher
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/376718 ) Change subject: Property based test for LexemeDiffer and LexemePatcher .. Property based test for LexemeDiffer and LexemePatcher Change-Id: I70d36bb963dba8616008da85d13df421db6a706b --- M composer.json A tests/phpunit/composer/DataModel/Services/Diff/ErisGenerators.php A tests/phpunit/composer/DataModel/Services/Diff/ErisGenerators/ItemIdGenerator.php A tests/phpunit/composer/DataModel/Services/Diff/ErisGenerators/LanguageCodeGenerator.php A tests/phpunit/composer/DataModel/Services/Diff/ErisGenerators/LexemeGenerator.php A tests/phpunit/composer/DataModel/Services/Diff/ErisGenerators/TermGenerator.php A tests/phpunit/composer/DataModel/Services/Diff/ErisGenerators/TermListGenerator.php A tests/phpunit/composer/DataModel/Services/Diff/LexemeDifferPatcherTest.php 8 files changed, 385 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/18/376718/1 diff --git a/composer.json b/composer.json index 44bb16e..cd9cd09 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,9 @@ "phpunit/phpunit": "~4.8", "wikibase/wikibase-codesniffer": "^0.1.0", "jakub-onderka/php-console-highlighter": "0.3.2", - "hamcrest/hamcrest-php": "^2.0" + "hamcrest/hamcrest-php": "^2.0", + "giorgiosironi/eris":"^0.9.0", + "icomefromthenet/reverse-regex": "^0.0.6.3" }, "autoload": { "psr-4": { diff --git a/tests/phpunit/composer/DataModel/Services/Diff/ErisGenerators.php b/tests/phpunit/composer/DataModel/Services/Diff/ErisGenerators.php new file mode 100644 index 000..d510c54 --- /dev/null +++ b/tests/phpunit/composer/DataModel/Services/Diff/ErisGenerators.php @@ -0,0 +1,14 @@ +chooseGenerator = new ChooseGenerator( 1, 2147483647 ); + } + + /** +* @param $size +* @param $rand +* @return GeneratedValueSingle +*/ + public function generate( $size, $rand ) { + return call_user_func( $this, $size, $rand ); + } + + /** +* @param int The generation size +* @param callable a rand() function +* @return GeneratedValueSingle +*/ + public function __invoke( $size, $rand ) { + $chooseGenerator = $this->chooseGenerator; + /** @var GeneratedValueSingle $value */ + $value = $chooseGenerator( $size, $rand ); + return $value->map( + function ( $value ) { + return new ItemId( 'Q' . $value ); + }, + 'itemId' + ); + } + + /** +* The conditions for terminating are either: +* - returning the same GeneratedValueSingle passed in +* - returning an empty GeneratedValueOptions +* +* @param GeneratedValueSingle +* @return GeneratedValueSingle|GeneratedValueOptions +*/ + public function shrink( GeneratedValueSingle $element ) { + return $element; + } + + /** +* @param GeneratedValueSingle +* @return bool +*/ + public function contains( GeneratedValueSingle $element ) { + return $element->unbox() instanceof ItemId; + } + +} diff --git a/tests/phpunit/composer/DataModel/Services/Diff/ErisGenerators/LanguageCodeGenerator.php b/tests/phpunit/composer/DataModel/Services/Diff/ErisGenerators/LanguageCodeGenerator.php new file mode 100644 index 000..cff75cd --- /dev/null +++ b/tests/phpunit/composer/DataModel/Services/Diff/ErisGenerators/LanguageCodeGenerator.php @@ -0,0 +1,70 @@ + +*/ + public function __invoke( $size, $rand ) { + $length = $rand( 2, 3 ); + + $built = ''; + for ( $i = 0; $i < $length; $i++ ) { + $built .= chr( $rand( ord( 'a' ), ord( 'z' ) ) ); + } + return GeneratedValueSingle::fromJustValue( $built, 'languageCode' ); + } + + /** +* The conditions for terminating are either: +* - returning the same GeneratedValueSingle passed in +* - returning an empty GeneratedValueOptions +* +* @param GeneratedValueSingle +* @return GeneratedValueSingle|GeneratedValueOptions +*/ + public function shrink( GeneratedValueSingle $element ) { + if ( !$this->contains( $element ) ) { + throw new DomainException( + 'Cannot shrink ' . $element . ' because it does not belong ' . + 'to the domain of the Strings.' + ); + } + + if ( str
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Use `FormSet` inside of the `Lexeme` class
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/376705 ) Change subject: Use `FormSet` inside of the `Lexeme` class .. Use `FormSet` inside of the `Lexeme` class Bug: T173742 Change-Id: I9ca79e748f016fb4917377172924b4c5266d28ad --- M src/DataModel/Lexeme.php 1 file changed, 10 insertions(+), 12 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/05/376705/1 diff --git a/src/DataModel/Lexeme.php b/src/DataModel/Lexeme.php index 3b15fef..7f8a4ab 100644 --- a/src/DataModel/Lexeme.php +++ b/src/DataModel/Lexeme.php @@ -44,7 +44,7 @@ private $language; /** -* @var Form[] +* @var FormSet */ private $forms; @@ -87,13 +87,13 @@ $this->lexicalCategory = $lexicalCategory; $this->language = $language; $this->statements = $statements ?: new StatementList(); - //TODO add assertion on Forms and Senses types - $this->assertCorrectNextFormIdIsGiven( $nextFormId, $forms ); - + $formSet = new FormSet( $forms ); + $this->assertCorrectNextFormIdIsGiven( $nextFormId, $formSet ); $this->nextFormId = $nextFormId; + $this->forms = $formSet; - $this->forms = $forms; + //TODO add assertion on Senses types $this->senses = $senses; } @@ -251,7 +251,7 @@ * @return Form[] */ public function getForms() { - return $this->forms; + return $this->forms->toArray(); } /** @@ -302,7 +302,7 @@ public function addForm( TermList $representations, array $grammaticalFeatures ) { $formId = new FormId( 'F' . $this->nextFormId++ ); $form = new Form( $formId, $representations, $grammaticalFeatures ); - $this->forms[] = $form; + $this->forms->add( $form ); return $form; } @@ -311,23 +311,21 @@ * @param mixed $nextFormId * @param Form[] $forms */ - private function assertCorrectNextFormIdIsGiven( $nextFormId, array $forms ) { + private function assertCorrectNextFormIdIsGiven( $nextFormId, FormSet $formSet ) { if ( !is_int( $nextFormId ) || $nextFormId < 1 ) { throw new \InvalidArgumentException( '$nextFormId should be a positive integer' ); } - if ( $nextFormId <= count( $forms ) ) { + if ( $nextFormId <= $formSet->count() ) { throw new \LogicException( sprintf( '$nextFormId must always be greater than the number of Forms. ' . '$nextFormId = `%s`, number of forms = `%s`', $nextFormId, - count( $forms ) + $formSet->count() ) ); } - - $formSet = new FormSet( $forms ); if ( $nextFormId <= $formSet->maxFormIdNumber() ) { throw new \LogicException( -- To view, visit https://gerrit.wikimedia.org/r/376705 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9ca79e748f016fb4917377172924b4c5266d28ad Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add assertions to ensure `$nextFormId` correctness in Lexeme
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/376703 ) Change subject: Add assertions to ensure `$nextFormId` correctness in Lexeme .. Add assertions to ensure `$nextFormId` correctness in Lexeme Bug: T173742 Change-Id: I11c4198e5a9a3c538695e8da123c5e0b766dd1cb --- M src/DataModel/Lexeme.php M tests/phpunit/composer/DataModel/LexemeTest.php M tests/phpunit/composer/DataModel/NewLexeme.php M tests/phpunit/mediawiki/DataModel/Serialization/LexemeDeserializerTest.php 4 files changed, 95 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/03/376703/1 diff --git a/src/DataModel/Lexeme.php b/src/DataModel/Lexeme.php index 97f54f1..3b15fef 100644 --- a/src/DataModel/Lexeme.php +++ b/src/DataModel/Lexeme.php @@ -88,14 +88,13 @@ $this->language = $language; $this->statements = $statements ?: new StatementList(); //TODO add assertion on Forms and Senses types + + $this->assertCorrectNextFormIdIsGiven( $nextFormId, $forms ); + + $this->nextFormId = $nextFormId; + $this->forms = $forms; $this->senses = $senses; - //FIXME: Add assertions regarding $nextFormId: - // * int - // * >=1 - // * > max FormId in provided form list - // * > form count - $this->nextFormId = $nextFormId; } /** @@ -308,4 +307,38 @@ return $form; } + /** +* @param mixed $nextFormId +* @param Form[] $forms +*/ + private function assertCorrectNextFormIdIsGiven( $nextFormId, array $forms ) { + if ( !is_int( $nextFormId ) || $nextFormId < 1 ) { + throw new \InvalidArgumentException( '$nextFormId should be a positive integer' ); + } + + if ( $nextFormId <= count( $forms ) ) { + throw new \LogicException( + sprintf( + '$nextFormId must always be greater than the number of Forms. ' . + '$nextFormId = `%s`, number of forms = `%s`', + $nextFormId, + count( $forms ) + ) + ); + } + + $formSet = new FormSet( $forms ); + + if ( $nextFormId <= $formSet->maxFormIdNumber() ) { + throw new \LogicException( + sprintf( + '$nextFormId must always be greater than the max ID number of provided Forms. ' . + '$nextFormId = `%s`, max ID number of provided Forms = `%s`', + $nextFormId, + $formSet->maxFormIdNumber() + ) + ); + } + } + } diff --git a/tests/phpunit/composer/DataModel/LexemeTest.php b/tests/phpunit/composer/DataModel/LexemeTest.php index 18f0bb5..e290ce4 100644 --- a/tests/phpunit/composer/DataModel/LexemeTest.php +++ b/tests/phpunit/composer/DataModel/LexemeTest.php @@ -77,11 +77,62 @@ } public function testOverrideId() { + //FIXME: This behaviour seems wrong. Should probably be changed $lexeme = new Lexeme( new LexemeId( 'L1' ) ); $id = new LexemeId( 'L2' ); $lexeme->setId( $id ); $this->assertSame( $id, $lexeme->getId() ); + } + + public function testCanNotCreateWithNonIntNextFormId() { + $this->setExpectedException( \Exception::class ); + new Lexeme( + new LexemeId( 'L1' ), + null, + null, + null, + null, + 1.0 + ); + } + + public function testCanNotCreateWithNonPositiveNextFormId() { + $this->setExpectedException( \Exception::class ); + new Lexeme( + new LexemeId( 'L1' ), + null, + null, + null, + null, + 0 + ); + } + + public function testCanNotCreateWithNextFormIdSmallerOrEqualThanNumberOfProvidedForms() { + $this->setExpectedException( \Exception::class ); + new Lexeme( + new LexemeId( 'L1' ), + null, + null, + null, + null, +
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: [WIP] Add form API module
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/376704 ) Change subject: [WIP] Add form API module .. [WIP] Add form API module Bug: T173742 Change-Id: I93b23c591b2a08c2106291d0ca1832b3ab3c7cf6 --- M extension.json A src/Api/AddForm.php 2 files changed, 162 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/04/376704/1 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/src/Api/AddForm.php b/src/Api/AddForm.php new file mode 100644 index 000..333d596 --- /dev/null +++ b/src/Api/AddForm.php @@ -0,0 +1,156 @@ +getApiHelperFactory( $mainModule->getContext() ); + + return new AddForm( + $mainModule, + $moduleName, + function ( $module ) use ( $apiHelperFactory ) { + return $apiHelperFactory->getEntitySavingHelper( $module ); + } + ); + } + + public function __construct( + ApiMain $mainModule, + $moduleName, + callable $entitySavingHelperInstantiator + ) { + parent::__construct( $mainModule, $moduleName ); + + $this->entitySavingHelper = $entitySavingHelperInstantiator( $this ); + } + + /** +* @see ApiBase::execute() +*/ + public function execute() { + [ + 'lexemeId' => 'L1', + 'representations' => [ + [ 'representation' => '', 'language' => '' ], + [ 'representation' => '', 'language' => '' ], + ], + 'grammaticalFeatures' => [ + 'Q1','Q2' + ] + ]; + + //FIXME: Validation + //FIXME: Error reporting + //FIXME: Summary + //FIXME: Module description message + //FIXME: Parameters messages + //FIXME: Examples + //FIXME: Serialize nextFormId + //FIXME: Response structure? - Added form + //FIXME: Don't show nextFormId in response + + $params = $this->extractRequestParams(); + + $data = json_decode( $params['data'], true ); + + $changeOpAddForm = $this->createChangeOp( $data ); + + $lexemeId = new LexemeId( $params['lexemeId'] ); + $lexeme = $this->entitySavingHelper->loadEntity( $lexemeId ); + $changeOpAddForm->apply( $lexeme ); + $status = $this->entitySavingHelper->attemptSaveEntity( $lexeme, new Summary() ); + + $apiResult = $this->getResult(); + + $apiResult->addValue( null, 'success', 1 ); + } + + /** +* @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' => null, + 'baserevid' => [ + self::PARAM_TYPE => 'integer', + ], + 'bot' => [ + self::PARAM_TYPE => 'boolean', + self::PARAM_DFLT => false, + ] + ] + ); + } + + /** +* @see ApiBase::isWriteMode() +*/ + public function isWriteMode() { + return true; + } + + /** +* @see ApiBase::needsToken() +*/ + public function needsToken() { + return 'csrf'; + } + + /** +* @see ApiBase::mustBePosted() +*/ + public function mustBePosted() { + re
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Introduce FormSet to simplify Lexeme state control
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/376558 ) Change subject: Introduce FormSet to simplify Lexeme state control .. Introduce FormSet to simplify Lexeme state control Bug: T173742 Change-Id: I314df1c54eabe17466f8f2dfdbd911a329ed029b --- A src/DataModel/FormSet.php A tests/phpunit/composer/DataModel/FormSetTest.php 2 files changed, 142 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/58/376558/1 diff --git a/src/DataModel/FormSet.php b/src/DataModel/FormSet.php new file mode 100644 index 000..93018d4 --- /dev/null +++ b/src/DataModel/FormSet.php @@ -0,0 +1,67 @@ +add( $form ); + } + } + + /** +* @return Form[] +*/ + public function toArray() { + return array_values( $this->forms ); + } + + public function count() { + return count( $this->forms ); + } + + /** +* @return int +*/ + public function maxFormIdNumber() { + if ( empty( $this->forms ) ) { + return 0; + } + + $numbers = array_map( function ( $formId ){ + return (int)substr( $formId, 1 ); + }, array_keys( $this->forms ) ); + return max( $numbers ); + } + + public function add( Form $form ) { + $formId = $form->getId()->getSerialization(); + if ( isset( $this->forms[$formId] ) ) { + throw new \InvalidArgumentException( + 'At least two forms with the same ID were provided: `' . $formId . '`' + ); + } + + $this->forms[$formId] = $form; + } + +} diff --git a/tests/phpunit/composer/DataModel/FormSetTest.php b/tests/phpunit/composer/DataModel/FormSetTest.php new file mode 100644 index 000..b542844 --- /dev/null +++ b/tests/phpunit/composer/DataModel/FormSetTest.php @@ -0,0 +1,75 @@ +setExpectedException( \Exception::class ); + new FormSet( [ 1 ] ); + } + + public function testToArray() { + $form = NewForm::any()->build(); + $formSet = new FormSet( [ $form ] ); + + $this->assertEquals( [ $form ], $formSet->toArray() ); + } + + public function testCanNotCreateWithTwoFormsHavingTheSameId() { + $this->setExpectedException( \Exception::class ); + + new FormSet( + [ + NewForm::havingId( 'F1' )->build(), + NewForm::havingId( 'F1' )->build(), + ] + ); + } + + public function testCount() { + $this->assertEquals( 0, ( new FormSet( [] ) )->count() ); + $this->assertEquals( 1, ( new FormSet( [ NewForm::any()->build() ] ) )->count() ); + } + + public function testMaxFormIdNumber_EmptySet_ReturnsZero() { + $this->assertEquals( 0, ( new FormSet( [] ) )->maxFormIdNumber() ); + } + + public function testMaxFormIdNumber_SetWithOneForm_ReturnsThatFormIdNumber() { + $formSet = new FormSet( [ NewForm::havingId( 'F1' )->build() ] ); + + $this->assertEquals( 1, $formSet->maxFormIdNumber() ); + } + + public function testMaxFormIdNumber_SetWithManyForms_ReturnsMaximumFormIdNumber() { + $formSet = new FormSet( + [ + NewForm::havingId( 'F1' )->build(), + NewForm::havingId( 'F3' )->build(), + NewForm::havingId( 'F2' )->build(), + ] + ); + + $this->assertEquals( 3, $formSet->maxFormIdNumber() ); + } + + public function testAddForm_EmptySet_FormIsAdded() { + $formSet = new FormSet( [] ); + $form = NewForm::havingId( 'F1' )->build(); + + $formSet->add( $form ); + + $this->assertEquals( [ $form ], $formSet->toArray() ); + } + + public function testAddForm_AddFormWithIdThatAlreadyPresentInTheSet_ThrowsAnException() { + $formSet = new FormSet( [ NewForm::havingId( 'F1' )->build() ] ); + + $this->setExpectedException( \Exception::class ); + $formSet->add( NewForm::havingId( 'F1' )->build() ); + } + +} -- To view, visit https://gerrit.wikimedia.org/r/376558 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I314df1c54eabe17466f8f2dfdbd911a329ed029b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) __
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add ChangeOp for Form addition
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/376540 ) Change subject: Add ChangeOp for Form addition .. Add ChangeOp for Form addition Bug: T173742 Change-Id: I0d0de36364ac4490a6640d68942f19aded3dad31 --- A src/ChangeOp/ChangeOpAddForm.php A tests/phpunit/mediawiki/ChangeOp/ChangeOpAddFormTest.php 2 files changed, 115 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/40/376540/1 diff --git a/src/ChangeOp/ChangeOpAddForm.php b/src/ChangeOp/ChangeOpAddForm.php new file mode 100644 index 000..3632752 --- /dev/null +++ b/src/ChangeOp/ChangeOpAddForm.php @@ -0,0 +1,54 @@ +representations = $representations; + $this->grammaticalFeatures = $grammaticalFeatures; + } + + public function validate( EntityDocument $entity ) { + Assert::parameterType( Lexeme::class, $entity, '$entity' ); + + return Result::newSuccess(); + } + + public function apply( EntityDocument $entity, Summary $summary = null ) { + Assert::parameterType( Lexeme::class, $entity, '$entity' ); + + /** @var Lexeme $entity */ + $form = $entity->addForm( $this->representations, $this->grammaticalFeatures ); + + $this->updateSummary( + $summary, + 'add', + '', + array_values( $form->getRepresentations()->toTextArray() ) + ); + } + +} diff --git a/tests/phpunit/mediawiki/ChangeOp/ChangeOpAddFormTest.php b/tests/phpunit/mediawiki/ChangeOp/ChangeOpAddFormTest.php new file mode 100644 index 000..fd4337b --- /dev/null +++ b/tests/phpunit/mediawiki/ChangeOp/ChangeOpAddFormTest.php @@ -0,0 +1,61 @@ +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' ) ] ); + $changeOp = new ChangeOpAddForm( $representations, [ new ItemId( 'Q1' ) ] ); + $lexeme = NewLexeme::create()->build(); + + $changeOp->apply( $lexeme ); + + $this->assertEquals( $representations, $lexeme->getForms()[0]->getRepresentations() ); + $this->assertEquals( [ new ItemId( 'Q1' ) ], $lexeme->getForms()[0]->getGrammaticalFeatures() ); + } + + public function test_applySetsTheSummary() { + $representations = new TermList( [ new Term( 'en', 'goat' ) ] ); + $changeOp = new ChangeOpAddForm( $representations, [] ); + $lexeme = NewLexeme::create()->build(); + + $summary = new Summary(); + + $changeOp->apply( $lexeme, $summary ); + + $this->assertEquals( 'add', $summary->getActionName() ); + $this->assertEquals( [ 'goat' ], $summary->getAutoSummaryArgs() ); + } + +} -- To view, visit https://gerrit.wikimedia.org/r/376540 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0d0de36364ac4490a6640d68942f19aded3dad31 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Consider forms when compare Lexemes for equality
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/376539 ) Change subject: Consider forms when compare Lexemes for equality .. Consider forms when compare Lexemes for equality Bug: T173742 Change-Id: I00490799a8aeab1eb22d97094b2a3e4bb4adb4c2 --- M src/DataModel/Lexeme.php M tests/phpunit/composer/DataModel/LexemeTest.php 2 files changed, 46 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/39/376539/1 diff --git a/src/DataModel/Lexeme.php b/src/DataModel/Lexeme.php index 474e796..94d66c2 100644 --- a/src/DataModel/Lexeme.php +++ b/src/DataModel/Lexeme.php @@ -160,9 +160,12 @@ || ( $this->language !== null && $this->language->equals( $target->language ) ); + $sameForms = $this->forms == $target->forms; + return $this->lemmas->equals( $target->lemmas ) && $sameLexicalCategory && $sameLanguage + && $sameForms && $this->statements->equals( $target->statements ); } diff --git a/tests/phpunit/composer/DataModel/LexemeTest.php b/tests/phpunit/composer/DataModel/LexemeTest.php index 3f4a424..bc3b61a 100644 --- a/tests/phpunit/composer/DataModel/LexemeTest.php +++ b/tests/phpunit/composer/DataModel/LexemeTest.php @@ -152,6 +152,27 @@ $withStatement = new Lexeme(); $withStatement->getStatements()->addNewStatement( new PropertyNoValueSnak( 42 ) ); + $form = NewForm::havingId( 'F1' ) + ->andRepresentation( 'en', 'goat' ) + ->andGrammaticalFeature( 'Q1' ); + + $withForm1 = new Lexeme( + new LexemeId( 'L1' ), + null, + null, + null, + null, + [ $form->build() ] + ); + $withForm2 = new Lexeme( + new LexemeId( 'L1' ), + null, + null, + null, + null, + [ $form->build() ] + ); + return [ 'empty' => [ $empty, @@ -176,6 +197,10 @@ 'same statements' => [ $withStatement, clone $withStatement + ], + 'same forms' => [ + $withForm1, + $withForm2 ], ]; } @@ -233,6 +258,24 @@ 'different languages' => [ new Lexeme( new LexemeId( 'l2' ), null, null, $language1 ), new Lexeme( new LexemeId( 'l2' ), null, null, $language2 ), + ], + 'different Form set' => [ + new Lexeme( + new LexemeId( 'L1' ), + null, + null, + null, + null, + [] + ), + new Lexeme( + new LexemeId( 'L1' ), + null, + null, + null, + null, + [ NewForm::any() ] + ), ] ]; } -- To view, visit https://gerrit.wikimedia.org/r/376539 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I00490799a8aeab1eb22d97094b2a3e4bb4adb4c2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add `addForm` method to Lexeme
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/376537 ) Change subject: Add `addForm` method to Lexeme .. Add `addForm` method to Lexeme Bug: T173742 Change-Id: If145dfa789b41caad91bad573506b04f4b14fb35 --- M src/DataModel/Lexeme.php M tests/phpunit/composer/DataModel/LexemeTest.php 2 files changed, 71 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/37/376537/1 diff --git a/src/DataModel/Lexeme.php b/src/DataModel/Lexeme.php index 836aca2..94d66c2 100644 --- a/src/DataModel/Lexeme.php +++ b/src/DataModel/Lexeme.php @@ -54,6 +54,11 @@ private $senses; /** +* @var int +*/ + private $nextFormId = 1; + + /** * Note that $lexicalCategory and $language can only be null during construction time. Their * setters can not be called with null, and their getters will throw an exception if the * corresponding field was never initialized. @@ -80,6 +85,7 @@ $this->lexicalCategory = $lexicalCategory; $this->language = $language; $this->statements = $statements ?: new StatementList(); + //TODO add assertion on Forms and Senses types $this->forms = $forms; $this->senses = $senses; } @@ -154,9 +160,12 @@ || ( $this->language !== null && $this->language->equals( $target->language ) ); + $sameForms = $this->forms == $target->forms; + return $this->lemmas->equals( $target->lemmas ) && $sameLexicalCategory && $sameLanguage + && $sameForms && $this->statements->equals( $target->statements ); } @@ -270,4 +279,18 @@ && $this->lexicalCategory !== null; } + /** +* @param TermList $representations +* @param array $grammaticalFeatures +* +* @return Form +*/ + public function addForm( TermList $representations, array $grammaticalFeatures ) { + $formId = new FormId( 'F' . $this->nextFormId++ ); + $form = new Form( $formId, $representations, $grammaticalFeatures ); + $this->forms[] = $form; + + return $form; + } + } diff --git a/tests/phpunit/composer/DataModel/LexemeTest.php b/tests/phpunit/composer/DataModel/LexemeTest.php index 9302a58..3f4a424 100644 --- a/tests/phpunit/composer/DataModel/LexemeTest.php +++ b/tests/phpunit/composer/DataModel/LexemeTest.php @@ -11,12 +11,14 @@ use Wikibase\DataModel\Statement\StatementList; use Wikibase\DataModel\Term\Term; use Wikibase\DataModel\Term\TermList; +use Wikibase\Lexeme\DataModel\Form; +use Wikibase\Lexeme\DataModel\FormId; use Wikibase\Lexeme\DataModel\Lexeme; use Wikibase\Lexeme\DataModel\LexemeId; use InvalidArgumentException; /** - * @covers Wikibase\Lexeme\DataModel\Lexeme + * @covers \Wikibase\Lexeme\DataModel\Lexeme * * @group WikibaseLexeme * @@ -325,4 +327,49 @@ $this->assertSame( $language, $lexeme->getLanguage() ); } + public function testAddForm_ReturnsANewFormWithProvidedParameters() { + $lexeme = NewLexeme::create()->build(); + + $newForm = $lexeme->addForm( + new TermList( [ new Term( 'en', 'goat' ) ] ), + [ new ItemId( 'Q1' ) ] + ); + + $this->assertEquals( + new TermList( [ new Term( 'en', 'goat' ) ] ), + $newForm->getRepresentations() + ); + $this->assertEquals( + [ new ItemId( 'Q1' ) ], + $newForm->getGrammaticalFeatures() + ); + } + + public function testAddForm_ReturnedFormIsAddedToTheLexeme() { + $lexeme = NewLexeme::create()->build(); + + $newForm = $lexeme->addForm( + new TermList( [ new Term( 'en', 'goat' ) ] ), + [] + ); + + $this->assertEquals( [ $newForm ], $lexeme->getForms() ); + } + + public function testAddFormTwoTimes_SecondFormHasAnIdWithNextNumber() { + $lexeme = NewLexeme::create()->build(); + + $newForm1 = $lexeme->addForm( + new TermList( [ new Term( 'en', 'goat' ) ] ), + [] + ); + $newForm2 = $lexeme->addForm( + new TermList( [ new Term( 'en', 'goat1' ) ] ), + [] + ); + + $this->assertEquals( new FormId( 'F1' ), $newForm1->getId() ); + $this->assertEquals( new FormId(
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add more asserts to Form and FormId constructors
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/376535 ) Change subject: Add more asserts to Form and FormId constructors .. Add more asserts to Form and FormId constructors Change-Id: I72b1c6dc0d5680d79991e20f817489fb1db01523 --- M src/DataModel/Form.php M src/DataModel/FormId.php A tests/phpunit/composer/DataModel/FormIdTest.php M tests/phpunit/composer/DataModel/FormTest.php 4 files changed, 43 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/35/376535/1 diff --git a/src/DataModel/Form.php b/src/DataModel/Form.php index a7e42c0..a4ce62b 100644 --- a/src/DataModel/Form.php +++ b/src/DataModel/Form.php @@ -48,6 +48,12 @@ throw new \InvalidArgumentException( 'Form must have at least one representation' ); } + foreach ( $grammaticalFeatures as $grammaticalFeature ) { + if ( !$grammaticalFeature instanceof ItemId ) { + throw new \InvalidArgumentException( '$grammaticalFeatures should be array of ItemId' ); + } + } + $this->id = $id; $this->representations = $representations; $this->grammaticalFeatures = $grammaticalFeatures; diff --git a/src/DataModel/FormId.php b/src/DataModel/FormId.php index 0fe5ee5..edb4b6b 100644 --- a/src/DataModel/FormId.php +++ b/src/DataModel/FormId.php @@ -17,6 +17,11 @@ * @param string $serialization */ public function __construct( $serialization ) { + if ( !preg_match( '/^F\d+$/', $serialization ) ) { + throw new \InvalidArgumentException( + "Form ID should have format `F\d+`. Given: $serialization" + ); + } $this->serialization = $serialization; } diff --git a/tests/phpunit/composer/DataModel/FormIdTest.php b/tests/phpunit/composer/DataModel/FormIdTest.php new file mode 100644 index 000..5af779b --- /dev/null +++ b/tests/phpunit/composer/DataModel/FormIdTest.php @@ -0,0 +1,23 @@ +assertInstanceOf( FormId::class, new FormId( 'F1' ) ); + } + + public function testCreateFormId_IncorrectSerialization_ThrowsAnException() { + $this->setExpectedException( \Exception::class ); + new FormId( 'F' ); + } + + public function testCreateFormId_GivenSerializationWithSpacesAround_ThrowsAnException() { + $this->setExpectedException( \Exception::class ); + new FormId( ' F1 ' ); + } + +} diff --git a/tests/phpunit/composer/DataModel/FormTest.php b/tests/phpunit/composer/DataModel/FormTest.php index f482a67..7a04313 100644 --- a/tests/phpunit/composer/DataModel/FormTest.php +++ b/tests/phpunit/composer/DataModel/FormTest.php @@ -23,4 +23,13 @@ ); } + public function testCreateForm_GrammaticalFeaturesIsNotAnArrayOfItemIds_ThrowsAnException() { + $this->setExpectedException( \Exception::class ); + new Form( + new FormId( 'F1' ), + new TermList( [ new Term( 'en', 'representation' ) ] ), + [ 1 ] + ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/376535 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I72b1c6dc0d5680d79991e20f817489fb1db01523 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add form API module
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')]); +
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Remove data-access dependency on `WikibaseClient::getSettings`
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/369953 ) Change subject: Remove data-access dependency on `WikibaseClient::getSettings` .. Remove data-access dependency on `WikibaseClient::getSettings` Change-Id: I50771e3de6bf8eee4ab49e4aa5546229ee03b8d5 --- M client/includes/WikibaseClient.php A data-access/src/DataAccessSettings.php M data-access/src/RepositoryServiceContainer.php M data-access/src/RepositoryServiceContainerFactory.php M data-access/src/RepositoryServiceWiring.php A data-access/tests/phpunit/DataAccessSettingsTest.php M data-access/tests/phpunit/MultiRepositoryServiceWiringTest.php M data-access/tests/phpunit/RepositoryServiceContainerFactoryTest.php M data-access/tests/phpunit/RepositoryServiceContainerTest.php M data-access/tests/phpunit/RepositoryServiceWiringTest.php 10 files changed, 101 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/53/369953/1 diff --git a/client/includes/WikibaseClient.php b/client/includes/WikibaseClient.php index cd41de3..7c69a7f 100644 --- a/client/includes/WikibaseClient.php +++ b/client/includes/WikibaseClient.php @@ -46,6 +46,7 @@ use Wikibase\Client\Serializer\ForbiddenSerializer; use Wikibase\Client\Store\TitleFactory; use Wikibase\Client\Store\ClientStore; +use Wikibase\DataAccess\DataAccessSettings; use Wikibase\DataAccess\GenericServices; use Wikibase\DataAccess\MultiRepositoryServices; use Wikibase\DataAccess\MultipleRepositoryAwareWikibaseServices; @@ -409,14 +410,20 @@ ); $genericServices = new GenericServices( $this->getEntityNamespaceLookup() ); + $clientSettings = $this->getSettings(); + $dataAccessSettings = new DataAccessSettings( + $clientSettings->getSetting( 'maxSerializedEntitySize' ), + $clientSettings->getSetting( 'readFullEntityIdColumn' ) + ); return new RepositoryServiceContainerFactory( $idParserFactory, $this->getEntityIdComposer(), new RepositorySpecificDataValueDeserializerFactory( $idParserFactory ), $this->repositoryDefinitions->getDatabaseNames(), - $this->getSettings()->getSetting( 'repositoryServiceWiringFiles' ), + $clientSettings->getSetting( 'repositoryServiceWiringFiles' ), $genericServices, + $dataAccessSettings, $this ); } diff --git a/data-access/src/DataAccessSettings.php b/data-access/src/DataAccessSettings.php new file mode 100644 index 000..f051ddd --- /dev/null +++ b/data-access/src/DataAccessSettings.php @@ -0,0 +1,45 @@ +maxSerializedEntitySizeInBytes = $maxSerializedEntitySizeInKiloBytes * 1024; + $this->readFullEntityIdColumn = $readFullEntityIdColumn; + } + + /** +* @return int +*/ + public function maxSerializedEntitySizeInBytes() { + return $this->maxSerializedEntitySizeInBytes; + } + + /** +* @return bool +*/ + public function readFullEntityIdColumn() { + return $this->readFullEntityIdColumn; + } + +} diff --git a/data-access/src/RepositoryServiceContainer.php b/data-access/src/RepositoryServiceContainer.php index b1b000e..c89e7e2 100644 --- a/data-access/src/RepositoryServiceContainer.php +++ b/data-access/src/RepositoryServiceContainer.php @@ -61,6 +61,7 @@ * @param EntityIdComposer $entityIdComposer * @param DataValueDeserializer $dataValueDeserializer * @param GenericServices $genericServices +* @param DataAccessSettings $settings * @param WikibaseClient $client Top-level factory passed to service instantiators // TODO: fix this! */ public function __construct( @@ -70,9 +71,10 @@ EntityIdComposer $entityIdComposer, DataValueDeserializer $dataValueDeserializer, GenericServices $genericServices, + DataAccessSettings $settings, WikibaseClient $client ) { - parent::__construct( [ $genericServices, $client ] ); + parent::__construct( [ $genericServices, $settings, $client ] ); $this->databaseName = $databaseName; $this->repositoryName = $repositoryName; diff --git a/data-access/src/RepositoryServiceContainerFactory.php b/data-access/src/RepositoryServiceContainerFactory.php index 154c95f..99498df 100644 --- a/data-access/src/RepositoryServiceContainerFactory.php +++ b/data-access/src/RepositoryServiceContainerFactory.php @@ -52,6 +52,10 @@ * @var WikibaseClient */ private $client; +
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Remove data-access dependency on `WikibaseClient::getEntityN...
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/369942 ) Change subject: Remove data-access dependency on `WikibaseClient::getEntityNamespaceLookup` .. Remove data-access dependency on `WikibaseClient::getEntityNamespaceLookup` Change-Id: I5e83de5ccbcca39710e4f6f53b4d154910d919f5 --- M client/includes/WikibaseClient.php A data-access/src/GenericServices.php M data-access/src/RepositoryServiceContainer.php M data-access/src/RepositoryServiceContainerFactory.php M data-access/src/RepositoryServiceWiring.php M data-access/src/WikibaseServices.php M data-access/tests/phpunit/MultiRepositoryServiceWiringTest.php M data-access/tests/phpunit/NoReverseDependencyTest.php M data-access/tests/phpunit/RepositoryServiceContainerFactoryTest.php M data-access/tests/phpunit/RepositoryServiceContainerTest.php M data-access/tests/phpunit/RepositoryServiceWiringTest.php 11 files changed, 86 insertions(+), 25 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/42/369942/1 diff --git a/client/includes/WikibaseClient.php b/client/includes/WikibaseClient.php index d233585..cd41de3 100644 --- a/client/includes/WikibaseClient.php +++ b/client/includes/WikibaseClient.php @@ -46,6 +46,7 @@ use Wikibase\Client\Serializer\ForbiddenSerializer; use Wikibase\Client\Store\TitleFactory; use Wikibase\Client\Store\ClientStore; +use Wikibase\DataAccess\GenericServices; use Wikibase\DataAccess\MultiRepositoryServices; use Wikibase\DataAccess\MultipleRepositoryAwareWikibaseServices; use Wikibase\DataAccess\RepositoryServiceContainerFactory; @@ -407,12 +408,15 @@ $this->repositoryDefinitions->getPrefixMappings() ); + $genericServices = new GenericServices( $this->getEntityNamespaceLookup() ); + return new RepositoryServiceContainerFactory( $idParserFactory, $this->getEntityIdComposer(), new RepositorySpecificDataValueDeserializerFactory( $idParserFactory ), $this->repositoryDefinitions->getDatabaseNames(), $this->getSettings()->getSetting( 'repositoryServiceWiringFiles' ), + $genericServices, $this ); } @@ -1050,7 +1054,7 @@ 'monolingualtext' => MonolingualTextValue::class, 'quantity' => QuantityValue::class, 'time' => TimeValue::class, - 'wikibase-entityid' => function( $value ) { + 'wikibase-entityid' => function ( $value ) { return isset( $value['id'] ) ? new EntityIdValue( $this->getEntityIdParser()->parse( $value['id'] ) ) : EntityIdValue::newFromArray( $value ); diff --git a/data-access/src/GenericServices.php b/data-access/src/GenericServices.php new file mode 100644 index 000..d7bf2a2 --- /dev/null +++ b/data-access/src/GenericServices.php @@ -0,0 +1,25 @@ +entityNamespaceLookup = $entityNamespaceLookup; + } + + /** +* @return EntityNamespaceLookup +*/ + public function getEntityNamespaceLookup() { + return $this->entityNamespaceLookup; + } + +} diff --git a/data-access/src/RepositoryServiceContainer.php b/data-access/src/RepositoryServiceContainer.php index 57cda6b..b1b000e 100644 --- a/data-access/src/RepositoryServiceContainer.php +++ b/data-access/src/RepositoryServiceContainer.php @@ -60,6 +60,7 @@ * @param EntityIdParser $entityIdParser * @param EntityIdComposer $entityIdComposer * @param DataValueDeserializer $dataValueDeserializer +* @param GenericServices $genericServices * @param WikibaseClient $client Top-level factory passed to service instantiators // TODO: fix this! */ public function __construct( @@ -68,9 +69,10 @@ EntityIdParser $entityIdParser, EntityIdComposer $entityIdComposer, DataValueDeserializer $dataValueDeserializer, + GenericServices $genericServices, WikibaseClient $client ) { - parent::__construct( [ $client ] ); + parent::__construct( [ $genericServices, $client ] ); $this->databaseName = $databaseName; $this->repositoryName = $repositoryName; diff --git a/data-access/src/RepositoryServiceContainerFactory.php b/data-access/src/RepositoryServiceContainerFactory.php index a9a0839..154c95f 100644 --- a/data-access/src/RepositoryServiceContainerFactory.php +++ b/data-access/src/RepositoryServiceContainerFactory.php @@ -44,6 +44,11 @@ private $wiringFiles; /** +
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Decouple `GlossWidget` from `mediaWiki` global variable
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/369674 ) Change subject: Decouple `GlossWidget` from `mediaWiki` global variable .. Decouple `GlossWidget` from `mediaWiki` global variable Bug: T171571 Change-Id: If0507861fdb3d021e69e2bbe673516603b8c8ec1 --- M extension.json M resources/i18n/Messages.js M resources/widgets/GlossWidget.js M src/WikibaseLexeme.hooks.php M tests/jasmine/GlossWidget.spec.js M tests/qunit/i18n/Messages.tests.js 6 files changed, 102 insertions(+), 27 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/74/369674/1 diff --git a/extension.json b/extension.json index 7d96f00..6fb2ab8 100644 --- a/extension.json +++ b/extension.json @@ -185,6 +185,9 @@ "wikibase.lexeme.datamodel.Lemma" ] }, + "wikibase.lexeme.i18n.Messages": { + "scripts": "i18n/Messages.js" + }, "wikibase.templates.lexeme": { "class": "\\Wikibase\\Lexeme\\View\\TemplateModule", "dependencies": [ diff --git a/resources/i18n/Messages.js b/resources/i18n/Messages.js index 2978632..25a5eb6 100644 --- a/resources/i18n/Messages.js +++ b/resources/i18n/Messages.js @@ -2,18 +2,37 @@ 'use strict'; /** -* @class wikibase.lexeme.i18n.Messages wikibase.lexeme.i18n.Messages +* This module is a wrapper for `mw.messages` introduced to decouple our code from Mediawiki. +* Interface is made as simple as possible intentionally to simplify it's mocking in tests. +* +* Important: Most of the components should not require this module directly (except ones that +*deal with wiring), although it is perfectly fine to depend on it's interface. */ - var Messages = function Messages() {}; /** -* @param {string} key +* @param {string} messageKey * @return {string} -* @public */ - Messages.prototype.get = function messagesGet( key ) { - return mw.messages.get( key ); - }; + function getUnparameterizedTranslation( messageKey ) { + if ( arguments.length !== 1 ) { + throw new Error( 'Accepts exactly one argument: key' ); + } - return Messages; + if ( typeof messageKey !== 'string' ) { + throw new Error( 'Key should be of type string. `' + typeof messageKey + '` given' ); + } + + if ( !mw.messages.exists( messageKey ) ) { + throw new Error( 'Message `' + messageKey + '` doesn\'t exist' ); + } + + return mw.messages.get( messageKey ); + } + + /** +* @class wikibase.lexeme.i18n.Messages +*/ + return { + getUnparameterizedTranslation: getUnparameterizedTranslation + }; } )( mediaWiki ); diff --git a/resources/widgets/GlossWidget.js b/resources/widgets/GlossWidget.js index a4e68fc..ce1a5fa 100644 --- a/resources/widgets/GlossWidget.js +++ b/resources/widgets/GlossWidget.js @@ -1,4 +1,4 @@ -module.exports = ( function ( $, mw, require, Vue, Vuex ) { +module.exports = ( function ( $, require, Vue ) { 'use strict'; function deepClone( object ) { @@ -7,11 +7,21 @@ function applyGlossWidget( widgetElement, glosses, beforeUpdate ) { var template = '#gloss-widget-vue-template'; + var messages = require( 'wikibase.lexeme.i18n.Messages' ); - return new Vue( newGlossWidget( widgetElement, template, glosses, beforeUpdate ) ); + return new Vue( newGlossWidget( messages, widgetElement, template, glosses, beforeUpdate ) ); } - function newGlossWidget( widgetElement, template, glosses, beforeUpdate ) { + /** +* +* @param {wikibase.lexeme.i18n.Messages} messages +* @param {string|HTMLElement} widgetElement +* @param {string} template +* @param {[{ value: string, language: string }]} glosses +* @param {function} beforeUpdate +* @return {object} +*/ + function newGlossWidget( messages, widgetElement, template, glosses, beforeUpdate ) { return { el: widgetElement, template: template, @@ -42,7 +52,7 @@ }, filters: { message: function ( key ) { - return mw.messages.get( key ); + return messages.getUnparameterizedTranslation( key ); }, directionality: fun
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Fix nested modules' test execution
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/369662 ) Change subject: Fix nested modules' test execution .. Fix nested modules' test execution Change-Id: Ia79d8fa99aa7d344e1c65cfb3edd6b6baeec13d1 --- M tests/qunit/data/testrunner.js 1 file changed, 32 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/62/369662/1 diff --git a/tests/qunit/data/testrunner.js b/tests/qunit/data/testrunner.js index 52210e7..92b1a6f 100644 --- a/tests/qunit/data/testrunner.js +++ b/tests/qunit/data/testrunner.js @@ -170,6 +170,11 @@ ( function () { var orgModule = QUnit.module; QUnit.module = function ( name, localEnv, executeNow ) { + if ( arguments.length === 2 && typeof localEnv === 'function' ) { + executeNow = localEnv; + localEnv = undefined; + } + if ( typeof localEnv === 'object' ) { localEnv = makeSafeEnv( localEnv ); } @@ -684,4 +689,31 @@ assert.ok(beforeHookWasExecuted); } ); + var nestedTestsExecuted = 0; + QUnit.module( 'testrunner-nested-modules', { + after: function () { + // This way we can be sure that module `testrunner-nested-modules-execution` will always + // be executed after module `testrunner-nested-modules` + QUnit.module( 'testrunner-nested-modules-execution'); + QUnit.test( + 'all nested tests in `testrunner-nested-modules` were executed', + function ( assert ) { + assert.equal(nestedTestsExecuted, 2); + } + ); + } + }, function () { + QUnit.module( 'inner', function () { + QUnit.test( 'inner test', function ( assert ) { + nestedTestsExecuted++; + assert.ok(true); + } ); + } ); + + QUnit.test( 'test', function ( assert ) { + nestedTestsExecuted++; + assert.ok(true); + } ); + } ); + }( jQuery, mediaWiki, QUnit ) ); -- To view, visit https://gerrit.wikimedia.org/r/369662 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia79d8fa99aa7d344e1c65cfb3edd6b6baeec13d1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Enable `before` and `after` QUnit hooks
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/369661 ) Change subject: Enable `before` and `after` QUnit hooks .. Enable `before` and `after` QUnit hooks Change-Id: Ib5b5d29e860d37dbec675e5d24c31b57c5e64102 --- M tests/qunit/data/testrunner.js 1 file changed, 28 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/61/369661/1 diff --git a/tests/qunit/data/testrunner.js b/tests/qunit/data/testrunner.js index e944ef0..52210e7 100644 --- a/tests/qunit/data/testrunner.js +++ b/tests/qunit/data/testrunner.js @@ -15,8 +15,10 @@ */ function makeSafeEnv( localEnv ) { return { + before: localEnv.before, beforeEach: localEnv.setup || localEnv.beforeEach, - afterEach: localEnv.teardown || localEnv.afterEach + afterEach: localEnv.teardown || localEnv.afterEach, + after: localEnv.after }; } @@ -657,4 +659,29 @@ } ); } ); + var beforeHookWasExecuted = false; + var afterHookWasExecuted = false; + QUnit.module( 'testrunner-hooks', { + before: function () { + beforeHookWasExecuted = true; + + // This way we can be sure that module `testrunner-hook-after` will always + // be executed after module `testrunner-hooks` + QUnit.module( 'testrunner-hooks-after'); + QUnit.test( + '`after` hook for module `testrunner-hooks` was executed', + function ( assert ) { + assert.ok(afterHookWasExecuted); + } + ); + }, + after: function () { + afterHookWasExecuted = true; + } + }); + + QUnit.test( '`before` hook was executed', function ( assert ) { + assert.ok(beforeHookWasExecuted); + } ); + }( jQuery, mediaWiki, QUnit ) ); -- To view, visit https://gerrit.wikimedia.org/r/369661 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib5b5d29e860d37dbec675e5d24c31b57c5e64102 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Use LESS instead of CSS
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/369440 ) Change subject: Use LESS instead of CSS .. Use LESS instead of CSS Change-Id: I0346e81e452898a88ab9e0d71162d19f75587194 --- M view/resources/wikibase/resources.php R view/resources/wikibase/wikibase.less 2 files changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/40/369440/1 diff --git a/view/resources/wikibase/resources.php b/view/resources/wikibase/resources.php index 253e564..07889bf 100644 --- a/view/resources/wikibase/resources.php +++ b/view/resources/wikibase/resources.php @@ -23,7 +23,7 @@ 'position' => 'top', 'styles' => [ // Order must be hierarchical, do not order alphabetically - 'wikibase.css', + 'wikibase.less', '../jquery/wikibase/themes/default/jquery.wikibase.aliasesview.css', '../jquery/wikibase/themes/default/jquery.wikibase.descriptionview.css', '../jquery/wikibase/themes/default/jquery.wikibase.entityview.css', diff --git a/view/resources/wikibase/wikibase.css b/view/resources/wikibase/wikibase.less similarity index 100% rename from view/resources/wikibase/wikibase.css rename to view/resources/wikibase/wikibase.less -- To view, visit https://gerrit.wikimedia.org/r/369440 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0346e81e452898a88ab9e0d71162d19f75587194 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Remove unused styles
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/369437 ) Change subject: Remove unused styles .. Remove unused styles Change-Id: Ifc9918289d03f82ea50ced4e0570ecc1250be196 --- M resources/lexeme.less 1 file changed, 0 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/37/369437/1 diff --git a/resources/lexeme.less b/resources/lexeme.less index 4a6bbd9..be91b6e 100644 --- a/resources/lexeme.less +++ b/resources/lexeme.less @@ -31,12 +31,6 @@ float: none; } -.wb-lexeme .wikibase-entitytermsforlanguagelistview-aliases, -.wb-lexeme .wikibase-entitytermsforlanguageview-aliases, -.wb-lexeme .wikibase-entitytermsview-aliases .wikibase-entitytermsforlanguagelistview-description { - display: none; -} - .wb-lexeme .wikibase-entitytermsforlanguagelistview .wikibase-entitytermsforlanguagelistview-header .wikibase-entitytermsforlanguagelistview-header-row { border-right: 0; width: 60%; -- To view, visit https://gerrit.wikimedia.org/r/369437 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifc9918289d03f82ea50ced4e0570ecc1250be196 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add `clearfix` to some blocks to make markup more predictable
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/369427 ) Change subject: Add `clearfix` to some blocks to make markup more predictable .. Add `clearfix` to some blocks to make markup more predictable Change-Id: I5ccec42eac4e77c6712418c7a7e6028a36008479 --- M resources/lexeme.less 1 file changed, 23 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/27/369427/1 diff --git a/resources/lexeme.less b/resources/lexeme.less index 8b45ade..4a6bbd9 100644 --- a/resources/lexeme.less +++ b/resources/lexeme.less @@ -1,3 +1,11 @@ +.clearfix() { + &::after { + content: ""; + display: table; + clear: both; + } +} + .wb-lexemepage #firstHeading { display: none; } @@ -63,6 +71,10 @@ font-size: 1.2em; } +.wikibase-lexeme-forms-section { + .clearfix; +} + .wikibase-lexeme-forms-section > .wikibase-toolbar-container { position: static; float: left; @@ -81,14 +93,11 @@ flex-grow: 1; } -.wikibase-lexeme-form .wikibase-statementgrouplistview::after, -.wikibase-lexeme-form .wikibase-listview::after, -.wikibase-lexeme-form .wikibase-addtoolbar::after { - /* This is clearfix */ - /* TODO: Should be done in Wikibase for all elements */ - content: ""; - display: table; - clear: both; + +.wikibase-lexeme-form .wikibase-statementgrouplistview, +.wikibase-lexeme-form .wikibase-listview, +.wikibase-lexeme-form .wikibase-addtoolbar { + .clearfix; } .wb-lexeme { @@ -108,18 +117,18 @@ clear: left; } +.wikibase-lexeme-senses-section { + .clearfix; +} + .wikibase-lexeme-senses-section > .wikibase-toolbar-container { position: static; float: left; } -.wikibase-lexeme-sense .wikibase-statementgrouplistview::after { - /* This is clearfix */ - /* TODO: Should be done in Wikibase for all elements */ - content: ""; - display: table; - clear: both; +.wikibase-lexeme-sense .wikibase-statementgrouplistview { + .clearfix; } .wikibase-lexeme-sense-id { -- To view, visit https://gerrit.wikimedia.org/r/369427 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5ccec42eac4e77c6712418c7a7e6028a36008479 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Make language column smaller in gloss widget
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/369425 ) Change subject: Make language column smaller in gloss widget .. Make language column smaller in gloss widget Bug: T172196 Change-Id: Ifce7ff75c999189b4f76cd8d1d592fa7f38a9c22 --- M resources/lexeme.less M resources/sense-gloss-widget.less M src/View/SensesView.php 3 files changed, 15 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/25/369425/1 diff --git a/resources/lexeme.less b/resources/lexeme.less index f7e3c52..8b45ade 100644 --- a/resources/lexeme.less +++ b/resources/lexeme.less @@ -124,7 +124,8 @@ .wikibase-lexeme-sense-id { padding: 5px 0; - min-width: 3.75em; + flex-basis: 3.75em; + flex-shrink: 0; } .wikibase-lexeme-sense-header { diff --git a/resources/sense-gloss-widget.less b/resources/sense-gloss-widget.less index 71e8855..c7eb934 100644 --- a/resources/sense-gloss-widget.less +++ b/resources/sense-gloss-widget.less @@ -33,13 +33,22 @@ white-space: nowrap; } -.wikibase-lexeme-sense-gloss-value-cell { - width: 99%; /* ... because it is a table cell */ +.wikibase-lexeme-sense-gloss-language { + width: 25%; } +.wikibase-lexeme-sense-gloss-value-cell { + width: auto; +} + +.wikibase-lexeme-sense-gloss-actions-cell { + width: .01%; +} + +.wikibase-lexeme-sense-gloss-language-input, .wikibase-lexeme-sense-gloss-value-input { - width: 100%; resize: horizontal; + width: 100% } .wikibase-lexeme-sense-glosses-control { diff --git a/src/View/SensesView.php b/src/View/SensesView.php index 4d5e69e..3b4d1a4 100644 --- a/src/View/SensesView.php +++ b/src/View/SensesView.php @@ -201,7 +201,7 @@ - + https://gerrit.wikimedia.org/r/369425 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifce7ff75c999189b4f76cd8d1d592fa7f38a9c22 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Move gloss widget styles to separate file
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/369423 ) Change subject: Move gloss widget styles to separate file .. Move gloss widget styles to separate file Bug: T172196 Change-Id: I1a70c1185723e0d919ae9af7ac9c723029641e21 --- M resources/lexeme.less A resources/sense-gloss-widget.less 2 files changed, 56 insertions(+), 60 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/23/369423/1 diff --git a/resources/lexeme.less b/resources/lexeme.less index a580f8c..f7e3c52 100644 --- a/resources/lexeme.less +++ b/resources/lexeme.less @@ -93,10 +93,8 @@ .wb-lexeme { @import 'lemma-widget'; -} - -.wb-lexeme { @import 'form-representation-widget'; + @import 'sense-gloss-widget'; } .wikibase-lexeme-senses .wikibase-lexeme-sense { @@ -115,63 +113,6 @@ float: left; } -/* === wikibase-lexeme-sense-glosses === */ - -.wikibase-lexeme-sense-glosses { - margin-right: 252px; -} - -.wikibase-lexeme-sense-glosses-table { - color: #565a60; - width: 100%; - border-left: 6px solid #ededed; -} - -.wikibase-lexeme-sense-gloss-table-header { - color: #000; -} - -.wikibase-lexeme-sense-glosses-table td { - vertical-align: top; -} - -.wikibase-lexeme-sense-gloss:first-of-type { - color: #000; -} - -.wikibase-lexeme-sense-glosses-sense-id { - display: none; -} - -.wikibase-lexeme-sense-gloss:first-of-type .wikibase-lexeme-sense-glosses-sense-id { - display: inline; -} - -.wikibase-lexeme-sense-gloss-language { - padding: 0 5px; - white-space: nowrap; -} - -.wikibase-lexeme-sense-gloss-value-cell { - width: 99%; /* ... because it is a table cell */ -} - -.wikibase-lexeme-sense-gloss-value-input { - width: 100%; - resize: horizontal; -} - -.wikibase-lexeme-sense-glosses-control { - text-transform: capitalize; - color: #1f66cc; - background: transparent; - border: none; - cursor: pointer; -} - -.wikibase-lexeme-sense-glosses-control:hover { - text-decoration: underline; -} .wikibase-lexeme-sense .wikibase-statementgrouplistview::after { /* This is clearfix */ diff --git a/resources/sense-gloss-widget.less b/resources/sense-gloss-widget.less new file mode 100644 index 000..71e8855 --- /dev/null +++ b/resources/sense-gloss-widget.less @@ -0,0 +1,55 @@ +.wikibase-lexeme-sense-glosses { + margin-right: 252px; +} + +.wikibase-lexeme-sense-glosses-table { + color: #565a60; + width: 100%; + border-left: 6px solid #ededed; +} + +.wikibase-lexeme-sense-gloss-table-header { + color: #000; +} + +.wikibase-lexeme-sense-glosses-table td { + vertical-align: top; +} + +.wikibase-lexeme-sense-gloss:first-of-type { + color: #000; +} + +.wikibase-lexeme-sense-glosses-sense-id { + display: none; +} + +.wikibase-lexeme-sense-gloss:first-of-type .wikibase-lexeme-sense-glosses-sense-id { + display: inline; +} + +.wikibase-lexeme-sense-gloss-language { + padding: 0 5px; + white-space: nowrap; +} + +.wikibase-lexeme-sense-gloss-value-cell { + width: 99%; /* ... because it is a table cell */ +} + +.wikibase-lexeme-sense-gloss-value-input { + width: 100%; + resize: horizontal; +} + +.wikibase-lexeme-sense-glosses-control { + text-transform: capitalize; + color: #1f66cc; + background: transparent; + border: none; + cursor: pointer; +} + +.wikibase-lexeme-sense-glosses-control:hover { + text-decoration: underline; +} -- To view, visit https://gerrit.wikimedia.org/r/369423 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1a70c1185723e0d919ae9af7ac9c723029641e21 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Make ChangeOps to set generic summary message if several cha...
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/367706 ) Change subject: Make ChangeOps to set generic summary message if several changeOps given .. Make ChangeOps to set generic summary message if several changeOps given Change-Id: I8f73a0c292b3d7ecefb8d1cb7eab74d09366f4bd --- M repo/includes/ChangeOp/ChangeOps.php M repo/tests/phpunit/includes/ChangeOp/ChangeOpsTest.php 2 files changed, 69 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/06/367706/1 diff --git a/repo/includes/ChangeOp/ChangeOps.php b/repo/includes/ChangeOp/ChangeOps.php index 120d34a..8cbd8ed 100644 --- a/repo/includes/ChangeOp/ChangeOps.php +++ b/repo/includes/ChangeOp/ChangeOps.php @@ -71,8 +71,17 @@ * @throws ChangeOpException */ public function apply( EntityDocument $entity, Summary $summary = null ) { - foreach ( $this->changeOps as $changeOp ) { - $changeOp->apply( $entity, $summary ); + if ( count( $this->changeOps ) === 1 ) { + current( $this->changeOps )->apply( $entity, $summary ); + } elseif ( count( $this->changeOps ) === 0 ) { + return; + } else { + foreach ( $this->changeOps as $changeOp ) { + $changeOp->apply( $entity, null ); + } + if ( $summary ) { + $summary->setAction( 'update' ); + } } } diff --git a/repo/tests/phpunit/includes/ChangeOp/ChangeOpsTest.php b/repo/tests/phpunit/includes/ChangeOp/ChangeOpsTest.php index 9996693..ec26946 100644 --- a/repo/tests/phpunit/includes/ChangeOp/ChangeOpsTest.php +++ b/repo/tests/phpunit/includes/ChangeOp/ChangeOpsTest.php @@ -4,8 +4,10 @@ use DataValues\StringValue; use InvalidArgumentException; +use Prophecy\Argument; use ValueValidators\Error; use ValueValidators\Result; +use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\Repo\ChangeOp\ChangeOp; use Wikibase\Repo\ChangeOp\ChangeOpDescription; use Wikibase\Repo\ChangeOp\ChangeOpLabel; @@ -16,7 +18,9 @@ use Wikibase\DataModel\Services\Statement\GuidGenerator; use Wikibase\DataModel\Snak\PropertyValueSnak; use Wikibase\Repo\Store\EntityPermissionChecker; +use Wikibase\Repo\Tests\NewItem; use Wikibase\Repo\Validators\SnakValidator; +use Wikibase\Summary; /** * @covers Wikibase\Repo\ChangeOp\ChangeOps @@ -198,4 +202,58 @@ $this->assertContains( EntityPermissionChecker::ACTION_EDIT, $actions ); } + public function testApply_HasTwoChangeOps_DoesNotPassSummaryObject() { + $changeOp1 = $this->prophesize( ChangeOp::class ); + $changeOp2 = $this->prophesize( ChangeOp::class ); + + $changeOps = new ChangeOps( [ $changeOp1->reveal(), $changeOp2->reveal() ] ); + $changeOps->apply( + $this->prophesize( EntityDocument::class )->reveal(), + $this->prophesize( Summary::class )->reveal() + ); + + $changeOp1->apply( Argument::any(), null )->shouldHaveBeenCalled(); + $changeOp2->apply( Argument::any(), null )->shouldHaveBeenCalled(); + } + + public function testApply_HasOneChangeOp_PassesSummaryObject() { + $changeOp = $this->prophesize( ChangeOp::class ); + + $changeOps = new ChangeOps( [ $changeOp->reveal() ] ); + $changeOps->apply( + $this->prophesize( EntityDocument::class )->reveal(), + $this->prophesize( Summary::class )->reveal() + ); + + $changeOp->apply( Argument::any(), Argument::type( Summary::class ) ) + ->shouldHaveBeenCalled(); + } + + public function testApply_HasTwoChangeOps_SetsGenericSummaryMessage() { + $changeOps = new ChangeOps( [ + $this->prophesize( ChangeOp::class )->reveal(), + $this->prophesize( ChangeOp::class )->reveal() + ] ); + + $summary = $this->prophesize( Summary::class ); + $changeOps->apply( + $this->prophesize( EntityDocument::class )->reveal(), + $summary->reveal() + ); + + $summary->setAction( 'update' )->shouldHaveBeenCalled(); + } + + public function testApply_HasZeroChangeOps_DoesNotUpdateSummaryAction() { + $changeOps = new ChangeOps( [] ); + + $summary = $this->prophesize( Summary::class ); + $changeOps->apply( + $this->prophesize( EntityDocument::class )->reveal(), + $sum
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Use consistent naming for `preparedParameters` argument
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/367397 ) Change subject: Use consistent naming for `preparedParameters` argument .. Use consistent naming for `preparedParameters` argument Change-Id: I6b04be514297f38e49c19579341aa6989bcf87c7 --- M repo/includes/Api/SetAliases.php M repo/includes/Api/SetDescription.php M repo/includes/Api/SetLabel.php M repo/includes/Api/SetSiteLink.php 4 files changed, 29 insertions(+), 29 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/97/367397/1 diff --git a/repo/includes/Api/SetAliases.php b/repo/includes/Api/SetAliases.php index 36610d9..5571a7d 100644 --- a/repo/includes/Api/SetAliases.php +++ b/repo/includes/Api/SetAliases.php @@ -164,38 +164,38 @@ } /** -* @param array $params +* @param array $preparedParameters * * @return ChangeOpAliases[] */ - private function getChangeOps( array $params ) { + private function getChangeOps( array $preparedParameters ) { $changeOps = []; - $language = $params['language']; + $language = $preparedParameters['language']; // Set the list of aliases to a user given one OR add/ remove certain entries - if ( isset( $params['set'] ) ) { + if ( isset( $preparedParameters['set'] ) ) { $changeOps[] = $this->termChangeOpFactory->newSetAliasesOp( $language, - $this->normalizeAliases( $params['set'] ) + $this->normalizeAliases( $preparedParameters['set'] ) ); } else { // FIXME: if we have ADD and REMOVE operations in the same call, // we will also have two ChangeOps updating the same edit summary. // This will cause the edit summary to be overwritten by the last ChangeOp beeing applied. - if ( !empty( $params['add'] ) ) { + if ( !empty( $preparedParameters['add'] ) ) { $changeOps[] = $this->termChangeOpFactory->newAddAliasesOp( $language, - $this->normalizeAliases( $params['add'] ) + $this->normalizeAliases( $preparedParameters['add'] ) ); } - if ( !empty( $params['remove'] ) ) { + if ( !empty( $preparedParameters['remove'] ) ) { $changeOps[] = $this->termChangeOpFactory->newRemoveAliasesOp( $language, - $this->normalizeAliases( $params['remove'] ) + $this->normalizeAliases( $preparedParameters['remove'] ) ); } } diff --git a/repo/includes/Api/SetDescription.php b/repo/includes/Api/SetDescription.php index 9377a9c..8c3c3c1 100644 --- a/repo/includes/Api/SetDescription.php +++ b/repo/includes/Api/SetDescription.php @@ -73,16 +73,16 @@ } /** -* @param array $params +* @param array $preparedParameters * * @return ChangeOpDescription */ - private function getChangeOp( array $params ) { + private function getChangeOp( array $preparedParameters ) { $description = ""; - $language = $params['language']; + $language = $preparedParameters['language']; - if ( isset( $params['value'] ) ) { - $description = $this->stringNormalizer->trimToNFC( $params['value'] ); + if ( isset( $preparedParameters['value'] ) ) { + $description = $this->stringNormalizer->trimToNFC( $preparedParameters['value'] ); } if ( $description === "" ) { diff --git a/repo/includes/Api/SetLabel.php b/repo/includes/Api/SetLabel.php index 2f355a6..c9a5ce6 100644 --- a/repo/includes/Api/SetLabel.php +++ b/repo/includes/Api/SetLabel.php @@ -73,16 +73,16 @@ } /** -* @param array $params +* @param array $preparedParameters * * @return ChangeOpLabel */ - private function getChangeOp( array $params ) { + private function getChangeOp( array $preparedParameters ) { $label = ""; - $language = $par
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Introduce `validateEntitySpecificParameters` method on Modif...
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/367392 ) Change subject: Introduce `validateEntitySpecificParameters` method on ModifyEntity .. Introduce `validateEntitySpecificParameters` method on ModifyEntity Needed for EditEntity Change-Id: Id6f7e1938ff9855658859689af46a783b9801b44 --- M repo/includes/Api/EditEntity.php M repo/includes/Api/ModifyEntity.php 2 files changed, 48 insertions(+), 23 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/92/367392/1 diff --git a/repo/includes/Api/EditEntity.php b/repo/includes/Api/EditEntity.php index 738e0c3..0848879 100644 --- a/repo/includes/Api/EditEntity.php +++ b/repo/includes/Api/EditEntity.php @@ -198,6 +198,45 @@ return parent::prepareParameters( $params ); } + protected function validateEntitySpecificParameters( + array $preparedParameters, + EntityDocument $entity, + $entityRevId + ) { + $data = $preparedParameters['data']; + $this->validateDataProperties( $data, $entity, $entityRevId ); + + $exists = $this->entityExists( $entity->getId() ); + + if ( $preparedParameters['clear'] ) { + if ( $preparedParameters['baserevid'] && $exists ) { + $latestRevision = $this->revisionLookup->getLatestRevisionId( + $entity->getId(), + EntityRevisionLookup::LATEST_FROM_MASTER + ); + + if ( !$entityRevId === $latestRevision ) { + $this->errorReporter->dieError( + 'Tried to clear entity using baserevid of entity not equal to current revision', + 'editconflict' + ); + } + } + } + + // if we create a new property, make sure we set the datatype + if ( !$exists && $entity instanceof Property ) { + if ( !isset( $data['datatype'] ) + || !in_array( $data['datatype'], $this->propertyDataTypes ) + ) { + $this->errorReporter->dieWithError( + 'wikibase-api-not-recognized-datatype', + 'param-illegal' + ); + } + } + } + /** * @see ModifyEntity::modifyEntity * @@ -214,34 +253,11 @@ $exists = $this->entityExists( $entity->getId() ); if ( $preparedParameters['clear'] ) { - if ( $preparedParameters['baserevid'] && $exists ) { - $latestRevision = $this->revisionLookup->getLatestRevisionId( - $entity->getId(), - EntityRevisionLookup::LATEST_FROM_MASTER - ); - - if ( !$baseRevId === $latestRevision ) { - $this->errorReporter->dieError( - 'Tried to clear entity using baserevid of entity not equal to current revision', - 'editconflict' - ); - } - } - $entity = $this->clearEntity( $entity ); } // if we create a new property, make sure we set the datatype if ( !$exists && $entity instanceof Property ) { - if ( !isset( $data['datatype'] ) - || !in_array( $data['datatype'], $this->propertyDataTypes ) - ) { - $this->errorReporter->dieWithError( - 'wikibase-api-not-recognized-datatype', - 'param-illegal' - ); - } - $entity->setDataTypeId( $data['datatype'] ); } diff --git a/repo/includes/Api/ModifyEntity.php b/repo/includes/Api/ModifyEntity.php index fb354f5..00c4032 100644 --- a/repo/includes/Api/ModifyEntity.php +++ b/repo/includes/Api/ModifyEntity.php @@ -206,6 +206,13 @@ return $params; } + protected function validateEntitySpecificParameters( + array $preparedParameters, + EntityDocument $entity, + $entityRevId +
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Introduce concept of "prepared parameters"
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/367390 ) Change subject: Introduce concept of "prepared parameters" .. Introduce concept of "prepared parameters" Needed specifically for EditEntity, which needs to decode JSON in "data" parameter. Change-Id: I41370d8d10531a7289fc7fded8f78f828714528d --- M repo/includes/Api/EditEntity.php M repo/includes/Api/ModifyEntity.php M repo/includes/Api/SetAliases.php M repo/includes/Api/SetDescription.php M repo/includes/Api/SetLabel.php M repo/includes/Api/SetSiteLink.php 6 files changed, 53 insertions(+), 37 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/90/367390/1 diff --git a/repo/includes/Api/EditEntity.php b/repo/includes/Api/EditEntity.php index 63a2dcd..738e0c3 100644 --- a/repo/includes/Api/EditEntity.php +++ b/repo/includes/Api/EditEntity.php @@ -192,24 +192,29 @@ } } + protected function prepareParameters( array $params ) { + $this->validateDataParameter( $params ); + $params['data'] = json_decode( $params['data'], true ); + return parent::prepareParameters( $params ); + } + /** * @see ModifyEntity::modifyEntity * * @param EntityDocument &$entity -* @param array $params +* @param array $preparedParameters * @param int $baseRevId * * @return Summary */ - protected function modifyEntity( EntityDocument &$entity, array $params, $baseRevId ) { - $this->validateDataParameter( $params ); - $data = json_decode( $params['data'], true ); + protected function modifyEntity( EntityDocument &$entity, array $preparedParameters, $baseRevId ) { + $data = $preparedParameters['data']; $this->validateDataProperties( $data, $entity, $baseRevId ); $exists = $this->entityExists( $entity->getId() ); - if ( $params['clear'] ) { - if ( $params['baserevid'] && $exists ) { + if ( $preparedParameters['clear'] ) { + if ( $preparedParameters['baserevid'] && $exists ) { $latestRevision = $this->revisionLookup->getLatestRevisionId( $entity->getId(), EntityRevisionLookup::LATEST_FROM_MASTER @@ -245,7 +250,7 @@ $this->applyChangeOp( $changeOps, $entity ); $this->buildResult( $entity ); - return $this->getSummary( $params ); + return $this->getSummary( $preparedParameters ); } /** @@ -267,16 +272,16 @@ } /** -* @param array $params +* @param array $preparedParameters * * @return Summary */ - private function getSummary( array $params ) { + private function getSummary( array $preparedParameters ) { //TODO: Construct a nice and meaningful summary from the changes that get applied! // Perhaps that could be based on the resulting diff? - $summary = $this->createSummary( $params ); - if ( isset( $params['id'] ) xor ( isset( $params['site'] ) && isset( $params['title'] ) ) ) { - $summary->setAction( $params['clear'] === false ? 'update' : 'override' ); + $summary = $this->createSummary( $preparedParameters ); + if ( isset( $preparedParameters['id'] ) xor ( isset( $preparedParameters['site'] ) && isset( $preparedParameters['title'] ) ) ) { + $summary->setAction( $preparedParameters['clear'] === false ? 'update' : 'override' ); } else { $summary->setAction( 'create' ); } diff --git a/repo/includes/Api/ModifyEntity.php b/repo/includes/Api/ModifyEntity.php index b5047bb..fb354f5 100644 --- a/repo/includes/Api/ModifyEntity.php +++ b/repo/includes/Api/ModifyEntity.php @@ -156,12 +156,12 @@ * Actually modify the entity. * * @param EntityDocument &$entity -* @param array $params +* @param array $preparedParameters * @param int $baseRevId * * @return Summary|null a summary of the modification, or null to indicate failure. */ - abstract protected function modifyEntity( EntityDocument &$entity, array $params, $baseRevId ); + abstract protected function modifyEntity( EntityDocument &$entity, array $preparedParameters, $baseRevId ); /** * Applies the given ChangeOp to the given Entity. @@ -196,6 +196,14 @@ } catch ( ChangeOpException $ex ) { $this->errorReporter->dieException( $ex, 'modification-fail
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Improve readability in `validateParameters` condition
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/367389 ) Change subject: Improve readability in `validateParameters` condition .. Improve readability in `validateParameters` condition Change-Id: I0e91b994c23db6808f1857f083c6a3dd923dda08 --- M repo/includes/Api/ModifyEntity.php 1 file changed, 10 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/89/367389/1 diff --git a/repo/includes/Api/ModifyEntity.php b/repo/includes/Api/ModifyEntity.php index 7bb82bd..b5047bb 100644 --- a/repo/includes/Api/ModifyEntity.php +++ b/repo/includes/Api/ModifyEntity.php @@ -204,9 +204,16 @@ * @param array $params */ protected function validateParameters( array $params ) { - if ( ( isset( $params['id'] ) || isset( $params['new'] ) ) - === ( isset( $params['site'] ) && isset( $params['title'] ) ) - ) { + $entityReferenceBySiteLinkGiven = isset( $params['site'] ) && isset( $params['title'] ); + $entityIdGiven = isset( $params['id'] ); + $shouldCreateNewWithSomeType = isset( $params['new'] ); + + $createNew_AndOr_IdIsGiven = $entityIdGiven || $shouldCreateNewWithSomeType; + + $noReferenceIsGiven = !$createNew_AndOr_IdIsGiven && !$entityReferenceBySiteLinkGiven; + $bothReferencesAreGiven = $createNew_AndOr_IdIsGiven && $entityReferenceBySiteLinkGiven; + + if ( $noReferenceIsGiven || $bothReferencesAreGiven ) { $this->errorReporter->dieWithError( 'wikibase-api-illegal-entity-selector', 'param-illegal' -- To view, visit https://gerrit.wikimedia.org/r/367389 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0e91b994c23db6808f1857f083c6a3dd923dda08 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: [WIP] Introduce JS tests running without browser
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/367379 ) Change subject: [WIP] Introduce JS tests running without browser .. [WIP] Introduce JS tests running without browser Change-Id: Ibb15850f86545bc1311a0ef4695ac5a0783a124e --- M Gruntfile.js M package.json M resources/widgets/GlossWidget.js A resources/widgets/Localization.js A tests/jasmine/some.spec.js 5 files changed, 55 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/79/367379/1 diff --git a/Gruntfile.js b/Gruntfile.js index f14dc80..20b6a68 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,6 +4,9 @@ grunt.loadNpmTasks( 'grunt-eslint' ); grunt.loadNpmTasks( 'grunt-jsonlint' ); grunt.loadNpmTasks( 'grunt-banana-checker' ); + grunt.loadNpmTasks( 'grunt-jasmine-nodejs' ); + + require( 'module-alias/register' ); grunt.initConfig( { eslint: { @@ -18,6 +21,16 @@ '!node_modules/**', '!vendor/**' ] + }, + jasmine_nodejs: { + all: { + options: { + random: true + }, + specs: [ + 'tests/jasmine/**/*.spec.js' + ] + } } } ); diff --git a/package.json b/package.json index 1fca5de..d4d137d 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "private": true, + "name": "Lexeme", "scripts": { "test": "grunt test" }, @@ -7,8 +8,15 @@ "eslint-config-wikimedia": "0.4.0", "grunt": "0.4.5", "grunt-banana-checker": "0.4.0", -"grunt-eslint": "19.0.0", "grunt-cli": "0.1.13", -"grunt-jsonlint": "1.0.7" +"grunt-eslint": "19.0.0", +"grunt-jasmine-nodejs": "^1.6.0", +"grunt-jsonlint": "1.0.7", +"jasmine": "^2.6.0", +"module-alias": "^2.0.0", +"vue": "2.3.3" + }, + "_moduleAliases":{ +"wikibase.lexeme.widgets.GlossWidget": "./resources/widgets/GlossWidget.js" } } diff --git a/resources/widgets/GlossWidget.js b/resources/widgets/GlossWidget.js index a4e68fc..370409d 100644 --- a/resources/widgets/GlossWidget.js +++ b/resources/widgets/GlossWidget.js @@ -1,5 +1,6 @@ -module.exports = ( function ( $, mw, require, Vue, Vuex ) { +module.exports = ( function ( require ) { 'use strict'; + var Vue = require( 'vue' ); function deepClone( object ) { return JSON.parse( JSON.stringify( object ) ); @@ -56,4 +57,4 @@ newGlossWidget: newGlossWidget }; -} )( jQuery, mediaWiki, require, Vue, Vuex ); +} )( require ); diff --git a/resources/widgets/Localization.js b/resources/widgets/Localization.js new file mode 100644 index 000..0ef2477 --- /dev/null +++ b/resources/widgets/Localization.js @@ -0,0 +1,21 @@ +module.exports = ( function ( $, mw ) { + 'use strict'; + + //TODO Test + return { + message: function message( key, parameters ) { + parameters = parameters || []; + var messageArguments = []; + messageArguments.push( key ); + parameters.forEach( function ( argument ) { + messageArguments.push( argument ); + } ); + + return mw.message.apply( mw.message, messageArguments ).text(); + }, + directionality: function directionality( languageCode ) { + return $.util.getDirectionality( languageCode ); + } + }; + +} )( jQuery, mw ); diff --git a/tests/jasmine/some.spec.js b/tests/jasmine/some.spec.js new file mode 100644 index 000..bffacf6 --- /dev/null +++ b/tests/jasmine/some.spec.js @@ -0,0 +1,8 @@ +describe( 'A suite', function() { + + var GlossWidget = require( 'wikibase.lexeme.widgets.GlossWidget' ); + + it( 'contains spec with an expectation', function() { + expect( true ).toBe( true ); + } ); +} ); -- To view, visit https://gerrit.wikimedia.org/r/367379 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibb15850f86545bc1311a0ef4695ac5a0783a124e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Remove generic CSS class `lemma-widget_control`
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/366833 ) Change subject: Remove generic CSS class `lemma-widget_control` .. Remove generic CSS class `lemma-widget_control` Used LESS mixin instead - provides better maintainability and makes markup more semantic oriented. Change-Id: I13c72047507475ee23973fd1e94c6285e67e1ab0 --- M resources/lemma-widget.less M src/View/LexemeView.php 2 files changed, 16 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/33/366833/1 diff --git a/resources/lemma-widget.less b/resources/lemma-widget.less index b48b108..02bec88 100644 --- a/resources/lemma-widget.less +++ b/resources/lemma-widget.less @@ -41,17 +41,6 @@ align-items: flex-start; } - &_control { - background: transparent; - border: none; - cursor: pointer; - color: #0d4c99; - } - - &_control:hover { - text-decoration: underline; - } - .prepend-with-wikibase-oojs-icon(@image) { &:before { content:''; @@ -81,13 +70,26 @@ } } + .button-displayed-as-link() { + background: transparent; + border: none; + cursor: pointer; + color: #0d4c99; + &:hover { + text-decoration: underline; + } + } + &_edit { + .button-displayed-as-link; .prepend-with-wikibase-oojs-icon('edit-ltr.png'); } &_save { + .button-displayed-as-link; .prepend-with-wikibase-oojs-icon('check.png'); } &_cancel { + .button-displayed-as-link; .prepend-with-wikibase-oojs-icon('close-ltr.png'); } diff --git a/src/View/LexemeView.php b/src/View/LexemeView.php index 6b00945..9d1e276 100644 --- a/src/View/LexemeView.php +++ b/src/View/LexemeView.php @@ -272,11 +272,11 @@ - {{'wikibase-edit'|message}} - {{'wikibase-save'|message}} - {{'wikibase-cancel'|message}} -- To view, visit https://gerrit.wikimedia.org/r/366833 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I13c72047507475ee23973fd1e94c6285e67e1ab0 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Move lemma widget style to separate file
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/366831 ) Change subject: Move lemma widget style to separate file .. Move lemma widget style to separate file Change-Id: I23391c1b6c2dc0451a14f096e06431b4a7953c1a --- A resources/lemma-widget.less M resources/lexeme.less 2 files changed, 151 insertions(+), 148 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/31/366831/1 diff --git a/resources/lemma-widget.less b/resources/lemma-widget.less new file mode 100644 index 000..47c2bbf --- /dev/null +++ b/resources/lemma-widget.less @@ -0,0 +1,149 @@ +.lemma-widget { + display: flex; +} + +.lemma-widget_lemma-list { + margin: 0; + padding: 0; + list-style: none; + display: flex; + flex-wrap: wrap; + flex-grow: 1; +} + +.lemma-widget_lemma { + display: flex; + flex-direction: column; + border-left: 6px solid #ededed; + padding: 0 9px; + margin: 11px; +} + +.lemma-widget_lemma-value { + font-size: 3em; +} + +.lemma-widget_lemma-language { + font-size: 1.5em; + font-family: sans-serif; +} + +.lemma-widget_edit-area { + flex-grow: 1; + display: flex; + border: 3px solid #99ccff; +} + +.lemma-widget_controls { + width: 18em; /* Same as div.wikibase-statementview-mainsnak right margin */ + display: flex; + flex-direction: column; + justify-content: center; + align-items: flex-start; +} + +.lemma-widget_control { + background: transparent; + border: none; + cursor: pointer; + color: #0d4c99; +} + +.lemma-widget_control:hover { + text-decoration: underline; +} + +.prepend-with-wikibase-oojs-icon(@image) { + &:before { + content:''; + + /* Copied from .wikibase-toolbar-button .wb-icon */ + background-size: 20px 20px; + width: 20px; + height: 20px; + display: inline-block; + vertical-align: middle; + background-position: center; + + @wikibase-root: "../../Wikibase"; + @wb-oojs-icon-path: "view/resources/jquery/wikibase/toolbar/themes/default/images/icons/oojs-ui"; + @icon-path: "@{wikibase-root}/@{wb-oojs-icon-path}/@{image}"; + /* @embed */ + background-image: url(@icon-path); + /* @embed */ + background-image: -webkit-linear-gradient(transparent, transparent), url(@icon-path); + /* @embed */ + background-image: linear-gradient(transparent, transparent), url(@icon-path); + + opacity: .7; + } + &:hover:before { + opacity: 1; + } +} + +.lemma-widget_edit { + .prepend-with-wikibase-oojs-icon('edit-ltr.png'); +} +.lemma-widget_save { + .prepend-with-wikibase-oojs-icon('check.png'); +} +.lemma-widget_cancel { + .prepend-with-wikibase-oojs-icon('close-ltr.png'); +} + +.lemma-widget_lemma-edit-box { + position: relative; + display: flex; + flex-direction: column; + justify-content: space-around; + border-left: 6px solid #dae8fc; + padding: 0 45px 0 9px; + margin: 0; + + height: 132px; +} + +.lemma-widget_lemma-value-input { + resize: horizontal; + min-width: 120px; + padding-right: 20px; + + font-size: 3em; +} + +.lemma-widget_lemma-value-input:active { + width: auto; +} + +.lemma-widget_lemma-language-input { + resize: horizontal; + min-width: 120px; + font-size: 1.5em; + padding-right: 20px; +} + +.lemma-widget_lemma-language-input:active { + width: auto; +} + +.lemma-widget_lemma-remove { + border: none; + background: transparent; + color: #074c99; + font-size: 2em; + cursor: pointer; + + position: absolute; + top: -5px; + right: 23px; +} + +.lemma-widget_add { + height: 132px; + border: none; + font-size: 3em; + text-align: center; + background: #dae8fc; + cursor: pointer; +} diff --git a/resources/lexeme.less b/resources/lexeme.less index de287ca..cb4d4e8 100644 --- a/resources/lexeme.less +++ b/resources/lexeme.less @@ -91,154 +91,8 @@ clear: both; } -.wb-lexeme .lemma-widget { - display: flex; -} - -.wb-lexeme .lemma-widget_lemma-list { - margin: 0; - padding: 0; - list-style: none; - display: flex; - flex-wrap: wrap; - flex-grow: 1; -} - -.wb-lexeme .lemma-widget_lemma { - display: flex; - flex-direction: column; - border-left: 6px solid #ededed; - padding: 0 9px; - margin: 11px; -} - -.wb-lexeme .lemma-widget_lemma-value { - font-size: 3em; -} - -.wb-lexeme .lemma-widget_lemma-language { -
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Use parent reference instead of repeating the same string in...
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/366832 ) Change subject: Use parent reference instead of repeating the same string in class name .. Use parent reference instead of repeating the same string in class name Change-Id: I75538f768173a006c6b320c13aab76414a703cd1 --- M resources/lemma-widget.less 1 file changed, 132 insertions(+), 132 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/32/366832/1 diff --git a/resources/lemma-widget.less b/resources/lemma-widget.less index 47c2bbf..b48b108 100644 --- a/resources/lemma-widget.less +++ b/resources/lemma-widget.less @@ -1,149 +1,149 @@ .lemma-widget { display: flex; -} -.lemma-widget_lemma-list { - margin: 0; - padding: 0; - list-style: none; - display: flex; - flex-wrap: wrap; - flex-grow: 1; -} - -.lemma-widget_lemma { - display: flex; - flex-direction: column; - border-left: 6px solid #ededed; - padding: 0 9px; - margin: 11px; -} - -.lemma-widget_lemma-value { - font-size: 3em; -} - -.lemma-widget_lemma-language { - font-size: 1.5em; - font-family: sans-serif; -} - -.lemma-widget_edit-area { - flex-grow: 1; - display: flex; - border: 3px solid #99ccff; -} - -.lemma-widget_controls { - width: 18em; /* Same as div.wikibase-statementview-mainsnak right margin */ - display: flex; - flex-direction: column; - justify-content: center; - align-items: flex-start; -} - -.lemma-widget_control { - background: transparent; - border: none; - cursor: pointer; - color: #0d4c99; -} - -.lemma-widget_control:hover { - text-decoration: underline; -} - -.prepend-with-wikibase-oojs-icon(@image) { - &:before { - content:''; - - /* Copied from .wikibase-toolbar-button .wb-icon */ - background-size: 20px 20px; - width: 20px; - height: 20px; - display: inline-block; - vertical-align: middle; - background-position: center; - - @wikibase-root: "../../Wikibase"; - @wb-oojs-icon-path: "view/resources/jquery/wikibase/toolbar/themes/default/images/icons/oojs-ui"; - @icon-path: "@{wikibase-root}/@{wb-oojs-icon-path}/@{image}"; - /* @embed */ - background-image: url(@icon-path); - /* @embed */ - background-image: -webkit-linear-gradient(transparent, transparent), url(@icon-path); - /* @embed */ - background-image: linear-gradient(transparent, transparent), url(@icon-path); - - opacity: .7; + &_lemma-list { + margin: 0; + padding: 0; + list-style: none; + display: flex; + flex-wrap: wrap; + flex-grow: 1; } - &:hover:before { - opacity: 1; + + &_lemma { + display: flex; + flex-direction: column; + border-left: 6px solid #ededed; + padding: 0 9px; + margin: 11px; } -} -.lemma-widget_edit { - .prepend-with-wikibase-oojs-icon('edit-ltr.png'); -} -.lemma-widget_save { - .prepend-with-wikibase-oojs-icon('check.png'); -} -.lemma-widget_cancel { - .prepend-with-wikibase-oojs-icon('close-ltr.png'); -} + &_lemma-value { + font-size: 3em; + } -.lemma-widget_lemma-edit-box { - position: relative; - display: flex; - flex-direction: column; - justify-content: space-around; - border-left: 6px solid #dae8fc; - padding: 0 45px 0 9px; - margin: 0; + &_lemma-language { + font-size: 1.5em; + font-family: sans-serif; + } - height: 132px; -} + &_edit-area { + flex-grow: 1; + display: flex; + border: 3px solid #99ccff; + } -.lemma-widget_lemma-value-input { - resize: horizontal; - min-width: 120px; - padding-right: 20px; + &_controls { + width: 18em; /* Same as div.wikibase-statementview-mainsnak right margin */ + display: flex; + flex-direction: column; + justify-content: center; + align-items: flex-start; + } - font-size: 3em; -} + &_control { + background: transparent; + border: none; + cursor: pointer; + color: #0d4c99; + } -.lemma-widget_lemma-value-input:active { - width: auto; -} + &_control:hover { + text-decoration: underline; + } -.lemma-widget_lemma-language-input { - resize: horizontal
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add icons to save an cancel buttons
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/366828 ) Change subject: Add icons to save an cancel buttons .. Add icons to save an cancel buttons Also fixed bug: edit button was not disappearing when was switching to edit mode Change-Id: I201e7621ae120db45a1a38f0c4b3df2f46deae7c --- M resources/lexeme.less M src/View/LexemeView.php 2 files changed, 39 insertions(+), 23 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/28/366828/1 diff --git a/resources/lexeme.less b/resources/lexeme.less index 1c74abf..de287ca 100644 --- a/resources/lexeme.less +++ b/resources/lexeme.less @@ -146,25 +146,43 @@ text-decoration: underline; } -.wb-lexeme .lemma-widget_edit-icon { - /* Copied from .wikibase-toolbar-button .wb-icon */ - background-size: 20px 20px; - width: 20px; - height: 20px; - display: inline-block; - vertical-align: middle; - opacity: .7; - /* @embed */ - background-image: url(../../Wikibase/view/resources/jquery/wikibase/toolbar/themes/default/images/icons/oojs-ui/edit-ltr.png); - /* @embed */ - background-image: -webkit-linear-gradient(transparent, transparent), url(../../Wikibase/view/resources/jquery/wikibase/toolbar/themes/default/images/icons/oojs-ui/edit-ltr.svg); - /* @embed */ - background-image: linear-gradient(transparent, transparent), url(../../Wikibase/view/resources/jquery/wikibase/toolbar/themes/default/images/icons/oojs-ui/edit-ltr.svg); - background-position: 0 40%; +.prepend-with-wikibase-oojs-icon(@image) { + &:before { + content:''; + + /* Copied from .wikibase-toolbar-button .wb-icon */ + background-size: 20px 20px; + width: 20px; + height: 20px; + display: inline-block; + vertical-align: middle; + background-position: center; + + @wikibase-root: "../../Wikibase"; + @wb-oojs-icon-path: "view/resources/jquery/wikibase/toolbar/themes/default/images/icons/oojs-ui"; + @icon-path: "@{wikibase-root}/@{wb-oojs-icon-path}/@{image}"; + /* @embed */ + background-image: url(@icon-path); + /* @embed */ + background-image: -webkit-linear-gradient(transparent, transparent), url(@icon-path); + /* @embed */ + background-image: linear-gradient(transparent, transparent), url(@icon-path); + + opacity: .7; + } + &:hover:before { + opacity: 1; + } } -.wb-lexeme *:hover > .lemma-widget_edit-icon { - opacity: 1; +.wb-lexeme .lemma-widget_edit { + .prepend-with-wikibase-oojs-icon('edit-ltr.png'); +} +.wb-lexeme .lemma-widget_save { + .prepend-with-wikibase-oojs-icon('check.png'); +} +.wb-lexeme .lemma-widget_cancel { + .prepend-with-wikibase-oojs-icon('close-ltr.png'); } .wb-lexeme .lemma-widget_lemma-edit-box { diff --git a/src/View/LexemeView.php b/src/View/LexemeView.php index 70351fe..6b00945 100644 --- a/src/View/LexemeView.php +++ b/src/View/LexemeView.php @@ -272,13 +272,11 @@ - - {{'wikibase-edit'|message}} - - {{'wikibase-edit'|message}} + {{'wikibase-save'|message}} - {{'wikibase-cancel'|message}} -- To view, visit https://gerrit.wikimedia.org/r/366828 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I201e7621ae120db45a1a38f0c4b3df2f46deae7c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Use LESS instead of CSS
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/366579 ) Change subject: Use LESS instead of CSS .. Use LESS instead of CSS Change-Id: I14fe9c4dd536742b3d8d5819988781fbe374af44 --- M extension.json R resources/lexeme.less 2 files changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/79/366579/1 diff --git a/extension.json b/extension.json index 715fdf0..59ce1cb 100644 --- a/extension.json +++ b/extension.json @@ -364,7 +364,7 @@ "wikibase.lexeme.styles": { "position": "top", "styles": [ - "lexeme.css" + "lexeme.less" ] } }, diff --git a/resources/lexeme.css b/resources/lexeme.less similarity index 100% rename from resources/lexeme.css rename to resources/lexeme.less -- To view, visit https://gerrit.wikimedia.org/r/366579 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I14fe9c4dd536742b3d8d5819988781fbe374af44 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Hide LemmaWidget controls before JS kicks in
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/366259 ) Change subject: Hide LemmaWidget controls before JS kicks in .. Hide LemmaWidget controls before JS kicks in Added `isInitialized` parameter which is always set to `false` in PHP and to `true` in JS code. Change-Id: I0a621c1094431eb40830f0d64684683f265fd5b3 --- M resources/widgets/LemmaWidget.newLemmaWidget.js M src/View/LexemeView.php 2 files changed, 4 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/59/366259/1 diff --git a/resources/widgets/LemmaWidget.newLemmaWidget.js b/resources/widgets/LemmaWidget.newLemmaWidget.js index 0f1912a..2b953d6 100644 --- a/resources/widgets/LemmaWidget.newLemmaWidget.js +++ b/resources/widgets/LemmaWidget.newLemmaWidget.js @@ -24,6 +24,7 @@ el: element, template: template, data: { + isInitialized: true, inEditMode: false, lemmas: copyLemmaList( store.state.lemmas ) }, diff --git a/src/View/LexemeView.php b/src/View/LexemeView.php index cafcb9c..52f98fe 100644 --- a/src/View/LexemeView.php +++ b/src/View/LexemeView.php @@ -269,8 +269,8 @@ - - + {{'wikibase-edit'|message}} @@ -299,6 +299,7 @@ $result = $templating->render( $this->getRawLemmaVueTemplate(), [ + 'isInitialized' => false, 'inEditMode' => false, 'isSaving' => false, 'lemmas' => $lemmas -- To view, visit https://gerrit.wikimedia.org/r/366259 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0a621c1094431eb40830f0d64684683f265fd5b3 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: [WIP] Fix lexeme page heading
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/366003 ) Change subject: [WIP] Fix lexeme page heading .. [WIP] Fix lexeme page heading Change-Id: Ib66b5662f2fb28810485d6116847ba15aa406ce5 TODO: show to UX --- M resources/lexeme.css M src/View/LexemeView.php 2 files changed, 74 insertions(+), 39 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/03/366003/1 diff --git a/resources/lexeme.css b/resources/lexeme.css index 4ceeb41..4d1f3e3 100644 --- a/resources/lexeme.css +++ b/resources/lexeme.css @@ -1,3 +1,24 @@ +.wb-lexemepage #firstHeading { + display: none; +} + +#wb-lexeme-header { + font-size: 100%; + margin: -1.428em 0 0.25em 0; + display: flex; + align-items: center; +} + +.wb-lexeme-header_id { + font-size: 1.25em; + color: #72777d; +} + +.wb-lexeme-header_lemma-widget { + flex-grow: 1; + margin-left: 1.6em; +} + .wb-lexeme.wikibase-entityview { float: none; } @@ -70,11 +91,11 @@ clear: both; } -.lemma-widget { +.wb-lexeme .lemma-widget { display: flex; } -.lemma-widget_lemma-list { +.wb-lexeme .lemma-widget_lemma-list { margin: 0; padding: 0; list-style: none; @@ -83,29 +104,30 @@ flex-grow: 1; } -.lemma-widget_lemma { +.wb-lexeme .lemma-widget_lemma { display: flex; flex-direction: column; border-left: 6px solid #ededed; padding: 0 9px; - margin-bottom: 22px; + margin: 11px; } -.lemma-widget_lemma-value { +.wb-lexeme .lemma-widget_lemma-value { font-size: 3em; font-weight: bold; } -.lemma-widget_lemma-language { +.wb-lexeme .lemma-widget_lemma-language { font-size: 1.5em; } -.lemma-widget_edit-area { +.wb-lexeme .lemma-widget_edit-area { + flex-grow: 1; display: flex; border: 3px solid #99ccff; } -.lemma-widget_controls { +.wb-lexeme .lemma-widget_controls { width: 100px; padding: 20px 40px; background: #dae8fc; @@ -114,7 +136,7 @@ justify-content: center; } -.lemma-widget_control { +.wb-lexeme .lemma-widget_control { background: transparent; border: none; font-size: 1.5em; @@ -123,19 +145,19 @@ color: #0d4c99; } -.lemma-widget_lemma-edit-box { +.wb-lexeme .lemma-widget_lemma-edit-box { position: relative; display: flex; flex-direction: column; justify-content: space-around; border-left: 6px solid #dae8fc; padding: 0 45px 0 9px; - margin-bottom: 22px; + margin: 0; height: 132px; } -.lemma-widget_lemma-value-input { +.wb-lexeme .lemma-widget_lemma-value-input { resize: horizontal; min-width: 120px; padding-right: 20px; @@ -143,22 +165,22 @@ font-size: 3em; } -.lemma-widget_lemma-value-input:active { +.wb-lexeme .lemma-widget_lemma-value-input:active { width: auto; } -.lemma-widget_lemma-language-input { +.wb-lexeme .lemma-widget_lemma-language-input { resize: horizontal; min-width: 120px; font-size: 1.5em; padding-right: 20px; } -.lemma-widget_lemma-language-input:active { +.wb-lexeme .lemma-widget_lemma-language-input:active { width: auto; } -.lemma-widget_lemma-remove { +.wb-lexeme .lemma-widget_lemma-remove { border: none; background: transparent; color: #074c99; @@ -166,11 +188,11 @@ cursor: pointer; position: absolute; - top: -11px; + top: -5px; right: 23px; } -.lemma-widget_add { +.wb-lexeme .lemma-widget_add { height: 132px; border: none; font-size: 3em; diff --git a/src/View/LexemeView.php b/src/View/LexemeView.php index 4ae5799..0007b92 100644 --- a/src/View/LexemeView.php +++ b/src/View/LexemeView.php @@ -102,8 +102,23 @@ /** @var Lexeme $entity */ Assert::parameterType( Lexeme::class, $entity, '$entity' ); - return $this->getHtmlForLexicalCategoryAndLanguage( $entity ) - . $this->renderLemmaWidget( $entity ) . $this->getLemmaVueTemplate() + $id = htmlspecialchars( + $this->getLocalizedMessage( 'parentheses', [ $entity->getId()->getSerialization() ] ) + ); + + $lemmaWidget = $this->renderLemmaWidget( $entity ) . $this->getLemmaVueTemplate(); + + $lexemeHeader = << + $id + + $lemmaWidget + + +HTML; + + return $lexemeHeader + . $this->getHtmlForLexicalCategoryAndLanguage( $entity ) . $this->templateFactory->render( 'wi
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Fix lexeme data type labels
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365982 ) Change subject: Fix lexeme data type labels .. Fix lexeme data type labels Created temporary LexemeId HTML formatter Bug: T170918 Change-Id: I844e0acbf73224a395f6dc7050a8419ff37c6e73 --- M WikibaseLexeme.datatypes.php A src/PropertyType/LexemeIdHtmlFormatter.php 2 files changed, 137 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/82/365982/1 diff --git a/WikibaseLexeme.datatypes.php b/WikibaseLexeme.datatypes.php index 77fb280..7a5115c 100644 --- a/WikibaseLexeme.datatypes.php +++ b/WikibaseLexeme.datatypes.php @@ -21,7 +21,9 @@ use Wikibase\Lexeme\DataModel\Lexeme; use Wikibase\Lexeme\PropertyType\FormIdFormatter; use Wikibase\Lexeme\PropertyType\FormIdParser; +use Wikibase\Lexeme\PropertyType\LexemeIdHtmlFormatter; use Wikibase\Lexeme\PropertyType\SenseIdFormatter; +use Wikibase\Lib\SnakFormatter; use Wikibase\Repo\WikibaseRepo; return [ @@ -31,6 +33,18 @@ $factory = WikibaseRepo::getDefaultValidatorBuilders(); return $factory->getEntityValidators( Lexeme::ENTITY_TYPE ); }, + 'formatter-factory-callback' => function ( $format, FormatterOptions $options ) { + if ( $format === SnakFormatter::FORMAT_HTML_WIDGET || + $format === SnakFormatter::FORMAT_HTML ) { + return new LexemeIdHtmlFormatter( + WikibaseRepo::getDefaultInstance()->getEntityLookup(), + WikibaseRepo::getDefaultInstance()->getEntityTitleLookup() + ); + } + + return WikibaseRepo::getDefaultValueFormatterBuilders() + ->newEntityIdFormatter( $format, $options ); + }, 'value-type' => 'wikibase-entityid', ], 'PT:wikibase-lexeme-form' => [ diff --git a/src/PropertyType/LexemeIdHtmlFormatter.php b/src/PropertyType/LexemeIdHtmlFormatter.php new file mode 100644 index 000..34a251d --- /dev/null +++ b/src/PropertyType/LexemeIdHtmlFormatter.php @@ -0,0 +1,123 @@ +entityLookup = $entityLookup; + $this->entityTitleLookup = $entityTitleLookup; + } + + /** +* @param mixed $value +* +* @return string +* @throws FormattingException +*/ + public function format( $value ) { + if ( !( $value instanceof EntityIdValue ) ) { + throw new InvalidArgumentException( + 'Data value type mismatch. Expected an EntityIdValue.' + ); + } + + if ( !( $value->getEntityId() instanceof LexemeId ) ) { + throw new InvalidArgumentException( + 'Data value type mismatch. Expected an EntityIdValue referencing Lexeme.' + ); + } + + /** @var LexemeId $lexemeId */ + $lexemeId = $value->getEntityId(); + /** @var Lexeme $lexeme */ + $lexeme = $this->entityLookup->getEntity( $lexemeId ); + + $title = $this->entityTitleLookup->getTitleForId( $lexemeId ); + + if ( $title === null ) { + return $this->getHtmlForNonExistent( $lexemeId ); + } + + $url = $title->isLocal() ? $title->getLocalURL() : $title->getFullURL(); + + $label = $this->buildLabel( $lexeme ); + $attributes = [ + 'href' => $url + ]; + + return Html::element( 'a', $attributes, $label ); + } + + /** +* @param LexemeId $lexemeId +* +* @return string HTML +*/ + private function getHtmlForNonExistent( LexemeId $lexemeId ) { + $attributes = [ 'class' => 'wb-entity-undefinedinfo' ]; + + $message = wfMessage( 'parentheses', + wfMessage( 'wikibase-deletedentity-lexeme' )->text() + ); + + $undefinedInfo = Html::element( 'span', $attributes, $message ); + + $separator = wfMessage( 'word-separator' )->text(); + return $lexemeId->getSerialization() . $separator . $undefinedInfo; + } + + private function buildLabel( Lexeme $lexeme ) { + $label = ''; + + $label .= wfMessage( 'parentheses', + $lexeme->getId()->getSerialization() + ); + $label .= ' '; + + $glossTexts = []; + forea
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add region qualifiers for "hard" in demo data
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365646 ) Change subject: Add region qualifiers for "hard" in demo data .. Add region qualifiers for "hard" in demo data Bug: T168373 Change-Id: I32e219a923175fc8ad558661fba847f8c930046c Depends-On: I7db5cd2f613a73d1921fc0dac13c2f9e4b2cfc97 --- M src/DemoData/HardLexemePopulator.php 1 file changed, 21 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/46/365646/1 diff --git a/src/DemoData/HardLexemePopulator.php b/src/DemoData/HardLexemePopulator.php index e77c5b7..2f49593 100644 --- a/src/DemoData/HardLexemePopulator.php +++ b/src/DemoData/HardLexemePopulator.php @@ -31,15 +31,22 @@ ->andStatement( NewStatement::forProperty( Id::P_IPA_PRONUNCIATION ) ->withValue( '/hɑːd/' ) + ->withQualifier( Id::P_REGION, new ItemId( Id::Q_SCOTLAND ) ) ->withSomeGuid() )->andStatement( NewStatement::forProperty( Id::P_IPA_PRONUNCIATION ) ->withValue( '/hɑɹd/' ) - ->withSomeGuid() + ->withQualifier( + Id::P_REGION, + new ItemId( Id::Q_UNITED_STATES_OF_AMERICA ) + )->withSomeGuid() )->andStatement( NewStatement::forProperty( Id::P_PRONUNCIATION_AUDIO ) ->withValue( 'hard.ogg' ) - ->withSomeGuid() + ->withQualifier( + Id::P_REGION, + new ItemId( Id::Q_UNITED_STATES_OF_AMERICA ) + )->withSomeGuid() )->andStatement( NewStatement::forProperty( Id::P_RHYME ) ->withValue( Id::LF_CARD ) @@ -70,8 +77,8 @@ ->withGloss( 'de', 'Schwierig oder kompliziert' ) ->withStatement( NewStatement::forProperty( Id::P_SYNONYM ) - ->withValue( Id::LS_DIFFICULT ) - ->withSomeGuid() + ->withValue( Id::LS_DIFFICULT ) + ->withSomeGuid() ) ->withStatement( NewStatement::forProperty( Id::P_REGISTER ) @@ -80,23 +87,23 @@ ) ->withStatement( NewStatement::forProperty( Id::P_TRANSLATION ) - ->withValue( Id::LS_SCHWIERIG ) - ->withSomeGuid() + ->withValue( Id::LS_SCHWIERIG ) + ->withSomeGuid() ) ->withStatement( NewStatement::forProperty( Id::P_TRANSLATION ) - ->withValue( Id::LS_DUR ) - ->withSomeGuid() + ->withValue( Id::LS_DUR ) + ->withSomeGuid() ) ->withStatement( NewStatement::forProperty( Id::P_ANTONYM ) - ->withValue( Id::LS_EASY ) - ->withSomeGuid() + ->withValue( Id::LS_EASY ) + ->withSomeGuid() ) ->withStatement( NewStatement::forProperty( Id::P_ANTONYM ) - ->withValue( Id::LS_SIMPLE ) - ->withSomeGuid() + ->withValue( Id::LS_SIMPLE ) + ->withSomeGuid() ) ->build(); } @@ -125,8 +132,8 @@ ) ->withStatement( NewStatement::forProperty( Id::P_ANTONYM ) - ->withValue( Id::LS_SOFT ) - ->withSomeGuid() + ->withValue( Id::LS_SOFT ) + ->withSomeG
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Add `withQualifier` NewStatement method
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365642 ) Change subject: Add `withQualifier` NewStatement method .. Add `withQualifier` NewStatement method Bug: T168373 Change-Id: I7db5cd2f613a73d1921fc0dac13c2f9e4b2cfc97 --- M repo/tests/phpunit/includes/NewStatement.php 1 file changed, 48 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/42/365642/1 diff --git a/repo/tests/phpunit/includes/NewStatement.php b/repo/tests/phpunit/includes/NewStatement.php index bc206a8..521cf23 100644 --- a/repo/tests/phpunit/includes/NewStatement.php +++ b/repo/tests/phpunit/includes/NewStatement.php @@ -11,6 +11,7 @@ use Wikibase\DataModel\Snak\PropertyNoValueSnak; use Wikibase\DataModel\Snak\PropertySomeValueSnak; use Wikibase\DataModel\Snak\PropertyValueSnak; +use Wikibase\DataModel\Snak\Snak; use Wikibase\DataModel\Statement\Statement; class NewStatement { @@ -38,6 +39,11 @@ private $rank = Statement::RANK_NORMAL; private $guid; + + /** +* @var Snak[] +*/ + private $qualifiers = []; /** * @param PropertyId|string $propertyId @@ -83,15 +89,7 @@ public function withValue( $dataValue ) { $result = clone $this; - if ( $dataValue instanceof EntityId ) { - $dataValue = new EntityIdValue( $dataValue ); - } elseif ( is_string( $dataValue ) ) { - $dataValue = new StringValue( $dataValue ); - } elseif ( !( $dataValue instanceof DataValue ) ) { - throw new InvalidArgumentException( 'Unsupported $dataValue type' ); - } - - $result->dataValue = $dataValue; + $result->dataValue = $this->createDataValueObject( $dataValue ); $result->type = PropertyValueSnak::class; return $result; @@ -150,6 +148,26 @@ return $result; } + /** +* @param string|PropertyId $propertyId +* @param DataValue|EntityId|string $value If not a DataValue object, the builder tries to +* guess the type and turns it into a DataValue object. +* +* @return self +*/ + public function withQualifier( $propertyId, $value ) { + $result = clone $this; + if ( is_string( $propertyId ) ) { + $propertyId = new PropertyId( $propertyId ); + } + + $value = $this->createDataValueObject( $value ); + + $result->qualifiers[] = new PropertyValueSnak( $propertyId, $value ); + + return $result; + } + private function __construct() { } @@ -189,6 +207,10 @@ } } + foreach ( $this->qualifiers as $qualifier ) { + $result->getQualifiers()->addSnak( $qualifier ); + } + return $result; } @@ -206,4 +228,21 @@ ); } + /** +* @param DataValue|EntityId|string $dataValue If not a DataValue object, the builder tries to +* guess the type and turns it into a DataValue object. +* @return DataValue +*/ + private function createDataValueObject( $dataValue ) { + if ( $dataValue instanceof EntityId ) { + $dataValue = new EntityIdValue( $dataValue ); + } elseif ( is_string( $dataValue ) ) { + $dataValue = new StringValue( $dataValue ); + } elseif ( !( $dataValue instanceof DataValue ) ) { + throw new InvalidArgumentException( 'Unsupported $dataValue type' ); + } + + return $dataValue; + } + } -- To view, visit https://gerrit.wikimedia.org/r/365642 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7db5cd2f613a73d1921fc0dac13c2f9e4b2cfc97 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Override forms existing in DB for "ask out" examples
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365631 ) Change subject: Override forms existing in DB for "ask out" examples .. Override forms existing in DB for "ask out" examples Bug: T168373 Change-Id: I33b40d0ac79d4bc0ecba07da5324a1234bb4151b --- M src/DemoData/AskOut1Populator.php M src/DemoData/AskOut2Populator.php M src/DemoData/AskOut3Populator.php 3 files changed, 3 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/31/365631/1 diff --git a/src/DemoData/AskOut1Populator.php b/src/DemoData/AskOut1Populator.php index 15ab63b..930851a 100644 --- a/src/DemoData/AskOut1Populator.php +++ b/src/DemoData/AskOut1Populator.php @@ -10,6 +10,7 @@ public function populate( Lexeme $lexeme ) { $defaultSense = $this->buildDefaultSense(); + $lexeme->setForms( [] ); $lexeme->setSenses( [ $defaultSense ] ); } diff --git a/src/DemoData/AskOut2Populator.php b/src/DemoData/AskOut2Populator.php index 3534377..f10315a 100644 --- a/src/DemoData/AskOut2Populator.php +++ b/src/DemoData/AskOut2Populator.php @@ -11,6 +11,7 @@ public function populate( Lexeme $lexeme ) { $defaultSense = $this->buildDefaultSense(); + $lexeme->setForms( [] ); $lexeme->setSenses( [ $defaultSense ] ); } diff --git a/src/DemoData/AskOut3Populator.php b/src/DemoData/AskOut3Populator.php index 28851bd..afd8062 100644 --- a/src/DemoData/AskOut3Populator.php +++ b/src/DemoData/AskOut3Populator.php @@ -10,6 +10,7 @@ public function populate( Lexeme $lexeme ) { $defaultSense = $this->buildDefaultSense(); + $lexeme->setForms( [] ); $lexeme->setSenses( [ $defaultSense ] ); } -- To view, visit https://gerrit.wikimedia.org/r/365631 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I33b40d0ac79d4bc0ecba07da5324a1234bb4151b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Remove fake item ids
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365625 ) Change subject: Remove fake item ids .. Remove fake item ids Those not needed anymore as soon as we now have proper property types Bug: T168373 Change-Id: Ie7157fbf71b94f74b40ade2c305677b79215aaa7 --- M src/DemoData/Id.php 1 file changed, 0 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/25/365625/1 diff --git a/src/DemoData/Id.php b/src/DemoData/Id.php index ee0f967..6631dea 100644 --- a/src/DemoData/Id.php +++ b/src/DemoData/Id.php @@ -73,12 +73,4 @@ const Q_ENGLISH = 'Q3'; const Q_VERB = 'Q2'; - //Fake Forms to use in statements - const FAKE_F_RHYMES_WITH_FORM = 'Q10'; - const FAKE_F_HOMOPHONE_FORM = 'Q11'; - - //Fake Senses to use in statements - const FAKE_S_SYNONYM_SENSE = 'Q13'; - const FAKE_S_TRANSLATES_TO_SENSE = 'Q12'; - } -- To view, visit https://gerrit.wikimedia.org/r/365625 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie7157fbf71b94f74b40ade2c305677b79215aaa7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add statements referencing senses
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365621 ) Change subject: Add statements referencing senses .. Add statements referencing senses Bug: T168373 Change-Id: I764c9d0ed7eb17964e1da4c9243f2063e62097ab --- M src/DemoData/HardLexemePopulator.php M src/DemoData/Id.php M src/DemoData/LeiterLexemePopulator.php M src/PropertyType/SenseIdFormatter.php 4 files changed, 57 insertions(+), 21 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/21/365621/1 diff --git a/src/DemoData/HardLexemePopulator.php b/src/DemoData/HardLexemePopulator.php index 53d4322..e77c5b7 100644 --- a/src/DemoData/HardLexemePopulator.php +++ b/src/DemoData/HardLexemePopulator.php @@ -68,21 +68,36 @@ return NewSense::havingId( 'S1' ) ->withGloss( 'en', 'presenting difficulty' ) ->withGloss( 'de', 'Schwierig oder kompliziert' ) -// ->withStatement( -// NewStatement::forProperty(Id::P_SYNONYM_OF) -// ->withValue(Id::___difficult) -// ->withSomeGuid() -// ) + ->withStatement( + NewStatement::forProperty( Id::P_SYNONYM ) + ->withValue( Id::LS_DIFFICULT ) + ->withSomeGuid() + ) ->withStatement( NewStatement::forProperty( Id::P_REGISTER ) ->withValue( new ItemId( Id::Q_COLLOQUIALISM ) ) ->withSomeGuid() ) -// ->withStatement( -// NewStatement::forProperty(Id::P_Translation) -// ->withValue(Id::S_schwierig) -// ->withSomeGuid() -// ) + ->withStatement( + NewStatement::forProperty( Id::P_TRANSLATION ) + ->withValue( Id::LS_SCHWIERIG ) + ->withSomeGuid() + ) + ->withStatement( + NewStatement::forProperty( Id::P_TRANSLATION ) + ->withValue( Id::LS_DUR ) + ->withSomeGuid() + ) + ->withStatement( + NewStatement::forProperty( Id::P_ANTONYM ) + ->withValue( Id::LS_EASY ) + ->withSomeGuid() + ) + ->withStatement( + NewStatement::forProperty( Id::P_ANTONYM ) + ->withValue( Id::LS_SIMPLE ) + ->withSomeGuid() + ) ->build(); } @@ -93,11 +108,6 @@ return NewSense::havingId( 'S2' ) ->withGloss( 'en', 'resisting deformation' ) ->withGloss( 'de', 'schwer verformbar' ) -// ->withStatement( -// NewStatement::forProperty(Id::P_SYNONYM_OF) -// ->withValue(Id::___difficult) -// ->withSomeGuid() -// ) ->withStatement( NewStatement::forProperty( Id::P_RELATED_CONCEPT ) ->withValue( new ItemId( Id::Q_ELASTICITY ) ) @@ -113,11 +123,11 @@ ->withValue( new ItemId( Id::Q_HARDNESS ) ) ->withSomeGuid() ) -// ->withStatement( -// NewStatement::forProperty(Id::P_Translation) -// ->withValue(Id::S_schwierig) -// ->withSomeGuid() -// ) + ->withStatement( + NewStatement::forProperty( Id::P_ANTONYM ) + ->withValue( Id::LS_SOFT ) + ->withSomeGuid() + ) ->build(); } diff --git a/src/DemoData/Id.php b/src/DemoData/Id.php index e5e5f00..ee0f967 100644 --- a/src/DemoData/Id.php +++ b/src/DemoData/Id.php @@ -15,12 +15,19 @@ const LF_CARD = 'L456-F4'; const LF_BARD = 'L888-F1'; + const LS_DIFFICULT = 'L3627-S4'; + const LS_SCHWIERIG = 'L283-S2'; + const LS_DUR = 'L465-S1'; + const LS_EASY = 'L801-S1'; + const LS_SIMPLE = 'L802-S1'; +
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add statements referencing forms
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365617 ) Change subject: Add statements referencing forms .. Add statements referencing forms Bug: T168373 Change-Id: Iffc7022f1572f69f8a1940b2a94e62fc38c502bc --- M src/DemoData/HardLexemePopulator.php M src/DemoData/Id.php M src/PropertyType/FormIdFormatter.php 3 files changed, 14 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/17/365617/1 diff --git a/src/DemoData/HardLexemePopulator.php b/src/DemoData/HardLexemePopulator.php index 19d81f5..53d4322 100644 --- a/src/DemoData/HardLexemePopulator.php +++ b/src/DemoData/HardLexemePopulator.php @@ -40,6 +40,14 @@ NewStatement::forProperty( Id::P_PRONUNCIATION_AUDIO ) ->withValue( 'hard.ogg' ) ->withSomeGuid() + )->andStatement( + NewStatement::forProperty( Id::P_RHYME ) + ->withValue( Id::LF_CARD ) + ->withSomeGuid() + )->andStatement( + NewStatement::forProperty( Id::P_RHYME ) + ->withValue( Id::LF_BARD ) + ->withSomeGuid() )->build(); } diff --git a/src/DemoData/Id.php b/src/DemoData/Id.php index 0eaab7c..e5e5f00 100644 --- a/src/DemoData/Id.php +++ b/src/DemoData/Id.php @@ -12,10 +12,12 @@ const L_ASK_2 = 'L18'; const L_ASK_OUT = 'L19'; + const LF_CARD = 'L456-F4'; + const LF_BARD = 'L888-F1'; + const P_LANGUAGE_CODE = 'P2'; const P_INSTANCE_OF = 'P3'; const P_LEXEME_PROPERTY = 'P4'; - const P_RHYMES_WITH = 'P5'; const P_HOMOPHONE = 'P6'; const P_TRANSLATES_TO = 'P7'; const P_SYNONYM_OF = 'P8'; @@ -30,6 +32,7 @@ const P_GENDERED_FORM = 'P17'; const P_SYLLABIFICATION = 'P18'; const P_GRAMMATICAL_FRAME = 'P19'; + const P_RHYME = 'P20'; const Q_VERBAL_PHRASE = 'Q31'; const Q_FEMALE = 'Q30'; diff --git a/src/PropertyType/FormIdFormatter.php b/src/PropertyType/FormIdFormatter.php index 6ff5b66..2d2ab75 100644 --- a/src/PropertyType/FormIdFormatter.php +++ b/src/PropertyType/FormIdFormatter.php @@ -17,7 +17,9 @@ //If you change something here, change also there $this->addForm( 'L13', 'hard English adjective', 'F1', 'hard', [ 'normative' ] ); $this->addForm( 'L13', 'hard English adjective', 'F2', 'harder', [ 'comparative' ] ); + // @see \Wikibase\Lexeme\DemoData\Id::LF_CARD $this->addForm( 'L456', 'card English noun', 'F4', 'card', [ 'normative' ] ); + // @see \Wikibase\Lexeme\DemoData\Id::LF_BARD $this->addForm( 'L888', 'bard English noun', 'F1', 'bard', [ 'normative' ] ); $this->addForm( 'L14', -- To view, visit https://gerrit.wikimedia.org/r/365617 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iffc7022f1572f69f8a1940b2a94e62fc38c502bc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Remove empty arrays removal from serialized entity
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365604 ) Change subject: Remove empty arrays removal from serialized entity .. Remove empty arrays removal from serialized entity This code brings inconsistency. In API those keys are present, but in wbEntity they don't. Also, there should be a difference between "not present" and "empty list" Change-Id: I4f75c396dfca382671844bf376d32a0726ce1a75 --- M repo/includes/ParserOutput/ParserOutputJsConfigBuilder.php M repo/tests/phpunit/includes/ParserOutput/ParserOutputJsConfigBuilderTest.php 2 files changed, 9 insertions(+), 12 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/04/365604/1 diff --git a/repo/includes/ParserOutput/ParserOutputJsConfigBuilder.php b/repo/includes/ParserOutput/ParserOutputJsConfigBuilder.php index 08c5560..e8221f6 100644 --- a/repo/includes/ParserOutput/ParserOutputJsConfigBuilder.php +++ b/repo/includes/ParserOutput/ParserOutputJsConfigBuilder.php @@ -48,17 +48,7 @@ * @return string */ private function getSerializedEntity( EntityDocument $entity ) { - $serialization = $this->entitySerializer->serialize( $entity ); - - // Remove empty parts of the serialization (Added when Lib Serializers were removed) - // We could allow parts if we are sure it would not break anything - foreach ( $serialization as $key => $serializationPart ) { - if ( is_array( $serializationPart ) && empty( $serializationPart ) ) { - unset( $serialization[$key] ); - } - } - - return $serialization; + return $this->entitySerializer->serialize( $entity ); } } diff --git a/repo/tests/phpunit/includes/ParserOutput/ParserOutputJsConfigBuilderTest.php b/repo/tests/phpunit/includes/ParserOutput/ParserOutputJsConfigBuilderTest.php index 1e2d144..784e664 100644 --- a/repo/tests/phpunit/includes/ParserOutput/ParserOutputJsConfigBuilderTest.php +++ b/repo/tests/phpunit/includes/ParserOutput/ParserOutputJsConfigBuilderTest.php @@ -136,7 +136,7 @@ } private function getSerialization( EntityDocument $entity, PropertyId $propertyId ) { - return [ + $serialization = [ 'id' => $entity->getId()->getSerialization(), 'type' => $entity->getType(), 'labels' => [ @@ -149,6 +149,8 @@ 'value' => 'Cake' ] ], + 'descriptions' => [], + 'aliases' => [], 'claims' => [ $propertyId->getSerialization() => [ [ @@ -167,6 +169,11 @@ ], ], ]; + + if ( $entity instanceof Item ) { + $serialization['sitelinks'] = []; + } + return $serialization; } } -- To view, visit https://gerrit.wikimedia.org/r/365604 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4f75c396dfca382671844bf376d32a0726ce1a75 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: SenseId property type with demo data
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365246 ) Change subject: SenseId property type with demo data .. SenseId property type with demo data Didn't want to introduce extra complexity, so just put test data in both Sense.js and SenseIdFormatter.php If you will need to add something don't forget that you need to add in both. Change-Id: I1d91aae24c4aa9577d08690ddc32ac2be7ebb6e3 --- M WikibaseLexeme.datatypes.php M extension.json M i18n/en.json M i18n/qqq.json A resources/experts/Sense.js A src/PropertyType/SenseIdFormatter.php 6 files changed, 242 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/46/365246/1 diff --git a/WikibaseLexeme.datatypes.php b/WikibaseLexeme.datatypes.php index 5f140fa..68669de 100644 --- a/WikibaseLexeme.datatypes.php +++ b/WikibaseLexeme.datatypes.php @@ -21,6 +21,7 @@ use Wikibase\Lexeme\DataModel\Lexeme; use Wikibase\Lexeme\PropertyType\FormIdFormatter; use Wikibase\Lexeme\PropertyType\FormIdParser; +use Wikibase\Lexeme\PropertyType\SenseIdFormatter; use Wikibase\Repo\WikibaseRepo; return [ @@ -45,4 +46,14 @@ }, 'value-type' => 'string', ], + 'PT:wikibase-lexeme-sense' => [ + 'expert-module' => 'wikibase.experts.Sense', + 'validator-factory-callback' => function() { + return []; + }, + 'formatter-factory-callback' => function( $format, FormatterOptions $options ) { + return new SenseIdFormatter(); + }, + 'value-type' => 'string', + ], ]; diff --git a/extension.json b/extension.json index 62912b6..5199467 100644 --- a/extension.json +++ b/extension.json @@ -346,6 +346,15 @@ "wikibase.experts.Entity" ] }, + "wikibase.experts.Sense": { + "scripts": [ + "experts/Sense.js" + ], + "dependencies": [ + "jquery.valueview.Expert", + "wikibase.experts.Entity" + ] + }, "wikibase.lexeme.styles": { "position": "top", "styles": [ diff --git a/i18n/en.json b/i18n/en.json index 423d1de..42a7abb 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -20,5 +20,6 @@ "wikibase-lexeme-gloss-empty": "No gloss defined", "wikibase-lexeme-summary-wbeditentity-update": "Changed a lexeme", "datatypes-type-wikibase-lexeme": "Lexeme", - "datatypes-type-wikibase-lexeme-form": "Lexeme Form" + "datatypes-type-wikibase-lexeme-form": "Lexeme Form", + "datatypes-type-wikibase-lexeme-sense": "Lexeme Sense" } diff --git a/i18n/qqq.json b/i18n/qqq.json index ba2e92e..0f2a3cc 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -25,5 +25,6 @@ "wikibase-lexeme-gloss-empty": "Placeholder message displayed instead of the gloss of the sense in case the gloss in the display language has not been specified yet.", "wikibase-lexeme-summary-wbeditentity-update": "Auto-generated edit summary when editing a lexeme", "datatypes-type-wikibase-lexeme": "The name of a data type for lexemes in Wikibase.\n{{Identical|Lexeme}}", - "datatypes-type-wikibase-lexeme-form": "The name of a data type for lexeme forms in Wikibase." + "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." } diff --git a/resources/experts/Sense.js b/resources/experts/Sense.js new file mode 100644 index 000..9f54e87 --- /dev/null +++ b/resources/experts/Sense.js @@ -0,0 +1,123 @@ +module.exports = ( function ( wb, vv ) { + 'use strict'; + + var PARENT = wb.experts.Entity; + + //Basically, copy-paste of src/PropertyType/SenseIdFormatter.php:18-48 + //If you change something here, change also there + var existingSenses = [ + new Sense( 'L13', 'hard', 'English adjective', 'S1', 'presenting difficulty' ), + new Sense( 'L13', 'hard', 'English adjective', 'S2', 'resisting deformation' ), + new Sense( 'L3627', 'difficult', 'English adjective', 'S4', 'not easy, requiring skill' ), + new Sense( 'L283', 'schwierig', 'German adjective', 'S2', 'complicated' ), + new Sense( 'L465', 'dur', 'French adjective', 'S1', 'hard' ), + new Sense( 'L801', 'easy', 'English adjective', 'S1', 'not difficult' ), + new Sense( 'L802', 'simple', 'English adjective', 'S1', 'not difficult' ), + new Sense
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Fix Form statements so they won't switch to edit mode on load
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365226 ) Change subject: Fix Form statements so they won't switch to edit mode on load .. Fix Form statements so they won't switch to edit mode on load Bug: T168373 Change-Id: I503aebacca0f5d4e2e390f778347e57447c8074b Depends-On: Ief497288f19c69e11295659492568ef4c794b951 --- M src/DemoData/HardLexemePopulator.php 1 file changed, 7 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/26/365226/1 diff --git a/src/DemoData/HardLexemePopulator.php b/src/DemoData/HardLexemePopulator.php index c294c11..199e255 100644 --- a/src/DemoData/HardLexemePopulator.php +++ b/src/DemoData/HardLexemePopulator.php @@ -30,12 +30,15 @@ ->andStatement( NewStatement::forProperty( Id::P_IPA_PRONUNCIATION ) ->withValue( '/hɑːd/' ) + ->withSomeGuid() )->andStatement( NewStatement::forProperty( Id::P_IPA_PRONUNCIATION ) ->withValue( '/hɑɹd/' ) + ->withSomeGuid() )->andStatement( NewStatement::forProperty( Id::P_PRONUNCIATION_AUDIO ) ->withValue( 'hard.ogg' ) + ->withSomeGuid() )->build(); } @@ -63,6 +66,7 @@ ->withStatement( NewStatement::forProperty( Id::P_REGISTER ) ->withValue( Id::Q_COLLOQUIALISM ) + ->withSomeGuid() ) // ->withStatement( // NewStatement::forProperty(Id::P_Translation) @@ -85,14 +89,17 @@ ->withStatement( NewStatement::forProperty( Id::P_RELATED_CONCEPT ) ->withValue( Id::Q_ELASTICITY ) + ->withSomeGuid() ) ->withStatement( NewStatement::forProperty( Id::P_RELATED_CONCEPT ) ->withValue( Id::Q_DUCTILITY ) + ->withSomeGuid() ) ->withStatement( NewStatement::forProperty( Id::P_RELATED_CONCEPT ) ->withValue( Id::Q_HARDNESS ) + ->withSomeGuid() ) // ->withStatement( // NewStatement::forProperty(Id::P_Translation) -- To view, visit https://gerrit.wikimedia.org/r/365226 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I503aebacca0f5d4e2e390f778347e57447c8074b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: [WIP] FormId property type
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365072 ) Change subject: [WIP] FormId property type .. [WIP] FormId property type Change-Id: Ie131f174175fa7b97bdbbc1f2af7eadf25f71753 --- M WikibaseLexeme.datatypes.php M extension.json A resources/experts/Form.js A src/PropertyType/FormIdFormatter.php A src/PropertyType/FormIdParser.php 5 files changed, 178 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/72/365072/1 diff --git a/WikibaseLexeme.datatypes.php b/WikibaseLexeme.datatypes.php index 7d27897..5f140fa 100644 --- a/WikibaseLexeme.datatypes.php +++ b/WikibaseLexeme.datatypes.php @@ -17,7 +17,10 @@ * @license GPL-2.0+ */ +use ValueFormatters\FormatterOptions; use Wikibase\Lexeme\DataModel\Lexeme; +use Wikibase\Lexeme\PropertyType\FormIdFormatter; +use Wikibase\Lexeme\PropertyType\FormIdParser; use Wikibase\Repo\WikibaseRepo; return [ @@ -29,4 +32,17 @@ }, 'value-type' => 'wikibase-entityid', ], + 'PT:wikibase-lexeme-form' => [ + 'expert-module' => 'wikibase.experts.Form', + 'validator-factory-callback' => function() { + return []; + }, + 'parser-factory-callback' => function( ParserOptions $options ) { + return new FormIdParser(); + }, + 'formatter-factory-callback' => function( $format, FormatterOptions $options ) { + return new FormIdFormatter(); + }, + 'value-type' => 'string', + ], ]; diff --git a/extension.json b/extension.json index ac879ba..62912b6 100644 --- a/extension.json +++ b/extension.json @@ -337,6 +337,15 @@ "wikibase.experts.Entity" ] }, + "wikibase.experts.Form": { + "scripts": [ + "experts/Form.js" + ], + "dependencies": [ + "jquery.valueview.Expert", + "wikibase.experts.Entity" + ] + }, "wikibase.lexeme.styles": { "position": "top", "styles": [ diff --git a/resources/experts/Form.js b/resources/experts/Form.js new file mode 100644 index 000..244956e --- /dev/null +++ b/resources/experts/Form.js @@ -0,0 +1,122 @@ +module.exports = ( function ( wb, vv ) { + 'use strict'; + + var PARENT = wb.experts.Entity; + + function FormSuggestion( + lexemeId, + firstGloss, + formId, + firstRepresentation, + grammaticalFeatures + ) { + this.repository = ''; + this.id = lexemeId + '-' + formId; + this.description = grammaticalFeatures.join( ', ' ); + this.title = '(' + this.id + ') ' + this.description; + this.pageid = 999; + this.datatype = 'string'; + this.label = firstRepresentation + ' (' + firstGloss + ')'; + this.match = { type: 'label', language: 'en', text: this.label }; + + Object.defineProperty( this, 'url', { + get: function () { + //TODO url prefix ? + return 'Lexeme:' + lexemeId + '#' + formId; + } + } ); + Object.defineProperty( this, 'concepturi', { + get: function () { + //TODO url prefix ? + return '/entity/' + lexemeId + '#' + formId; + } + } ); + } + + FormSuggestion.prototype.match = function ( query ) { + var terms = [ + this.id, + this.description, + this.title, + this.label + ]; + }; + /** +* `valueview` `Expert` for specifying a reference to a Wikibase `Lexeme`. +* @see jQuery.valueview.expert +* @see jQuery.valueview.Expert +* @class wikibase.experts.Lexeme +* @extends wikibase.experts.Entity +* @license GPL-2.0+ +*/ + var SELF = vv.expert( 'wikibaselexemeform', PARENT, { + /** +* @inheritdoc +*/ + _init: function () { + var viewState = this.viewState(); + viewState.value = function fakeFormValueGetter() { + if ( !this._value ) { + return null; +
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Add Guid related methods to `NewStatement`
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365054 ) Change subject: Add Guid related methods to `NewStatement` .. Add Guid related methods to `NewStatement` Change-Id: Ief497288f19c69e11295659492568ef4c794b951 --- M repo/tests/phpunit/includes/NewStatement.php 1 file changed, 55 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/54/365054/1 diff --git a/repo/tests/phpunit/includes/NewStatement.php b/repo/tests/phpunit/includes/NewStatement.php index a3860d7..bc206a8 100644 --- a/repo/tests/phpunit/includes/NewStatement.php +++ b/repo/tests/phpunit/includes/NewStatement.php @@ -15,6 +15,8 @@ class NewStatement { + const GENERATE_GUID = true; + /** * @var PropertyId */ @@ -34,6 +36,8 @@ * @var int */ private $rank = Statement::RANK_NORMAL; + + private $guid; /** * @param PropertyId|string $propertyId @@ -117,6 +121,35 @@ return $this->withRank( Statement::RANK_PREFERRED ); } + /** +* @param string $guid +* @return self +*/ + public function withGuid( $guid ) { + $result = clone $this; + if ( $result->guid !== null ) { + throw new \LogicException( 'Cannot redefine GUID' ); + } + + $result->guid = (string)$guid; + + return $result; + } + + /** +* @return self +*/ + public function withSomeGuid() { + $result = clone $this; + if ( $result->guid !== null ) { + throw new \LogicException( 'Cannot redefine GUID' ); + } + + $result->guid = self::GENERATE_GUID; + + return $result; + } + private function __construct() { } @@ -148,7 +181,29 @@ $result = new Statement( $snack ); $result->setRank( $this->rank ); + if ( $this->guid ) { + if ( $this->guid === self::GENERATE_GUID ) { + $result->setGuid( $this->generateUuidV4() ); + } else { + $result->setGuid( $this->guid ); + } + } + return $result; } + private function generateUuidV4() { + return sprintf( + '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', + mt_rand( 0, 0x ), + mt_rand( 0, 0x ), + mt_rand( 0, 0x ), + mt_rand( 0, 0x0fff ) | 0x4000, + mt_rand( 0, 0x3fff ) | 0x8000, + mt_rand( 0, 0x ), + mt_rand( 0, 0x ), + mt_rand( 0, 0x ) + ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/365054 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ief497288f19c69e11295659492568ef4c794b951 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Organize fake items IDs that should be used as forms or sens...
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365040 ) Change subject: Organize fake items IDs that should be used as forms or senses in statements .. Organize fake items IDs that should be used as forms or senses in statements Bug: T168373 Change-Id: I64db6081af679045dc6e76a0365d8afb61ceb2b4 --- M src/DemoData/Id.php 1 file changed, 8 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/40/365040/1 diff --git a/src/DemoData/Id.php b/src/DemoData/Id.php index 3c90d50..0eaab7c 100644 --- a/src/DemoData/Id.php +++ b/src/DemoData/Id.php @@ -48,10 +48,6 @@ const Q_SCOTLAND = 'Q16'; const Q_OLDENGLISH = 'Q15'; const Q_ADJECTIVE = 'Q14'; - const Q_SYNONYM_SENSE = 'Q13'; - const Q_TRANSLATES_TO_SENSE = 'Q12'; - const Q_HOMOPHONE_FORM = 'Q11'; - const Q_RHYMES_WITH_FORM = 'Q10'; const Q_FORM_ITEM = 'Q9'; const Q_NOUN = 'Q8'; const Q_GERMAN = 'Q7'; @@ -61,4 +57,12 @@ const Q_ENGLISH = 'Q3'; const Q_VERB = 'Q2'; + //Fake Forms to use in statements + const FAKE_F_RHYMES_WITH_FORM = 'Q10'; + const FAKE_F_HOMOPHONE_FORM = 'Q11'; + + //Fake Senses to use in statements + const FAKE_S_SYNONYM_SENSE = 'Q13'; + const FAKE_S_TRANSLATES_TO_SENSE = 'Q12'; + } -- To view, visit https://gerrit.wikimedia.org/r/365040 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I64db6081af679045dc6e76a0365d8afb61ceb2b4 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Populate "Ask out" (modeling 3) Lexeme for demo system
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365037 ) Change subject: Populate "Ask out" (modeling 3) Lexeme for demo system .. Populate "Ask out" (modeling 3) Lexeme for demo system Bug: T168373 Change-Id: Id8fb37ab057f9d1a00ed7756b40493e569089811 --- M src/Content/LexemeContent.php A src/DemoData/AskOut3Populator.php 2 files changed, 27 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/37/365037/1 diff --git a/src/Content/LexemeContent.php b/src/Content/LexemeContent.php index 774c125..dfd3e5f 100644 --- a/src/Content/LexemeContent.php +++ b/src/Content/LexemeContent.php @@ -64,6 +64,8 @@ ( new DemoData\AskOut1Populator() )->populate( $lexeme ); } elseif ( $id === DemoData\Id::L_ASK_2 ) { ( new DemoData\AskOut2Populator() )->populate( $lexeme ); + } elseif ( $id === DemoData\Id::L_ASK_OUT ) { + ( new DemoData\AskOut3Populator() )->populate( $lexeme ); } else { ( new DemoData\DefaultPopulator() )->populate( $lexeme ); } diff --git a/src/DemoData/AskOut3Populator.php b/src/DemoData/AskOut3Populator.php new file mode 100644 index 000..28851bd --- /dev/null +++ b/src/DemoData/AskOut3Populator.php @@ -0,0 +1,25 @@ +buildDefaultSense(); + + $lexeme->setSenses( [ $defaultSense ] ); + } + + /** +* @return \Wikibase\Lexeme\DataModel\Sense +*/ + private function buildDefaultSense() { + return NewSense::havingId( 'S1' ) + ->withGloss( 'en', 'To request a romantic date' ) + ->build(); + } + +} -- To view, visit https://gerrit.wikimedia.org/r/365037 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id8fb37ab057f9d1a00ed7756b40493e569089811 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Populate "Ask out" (modeling 2) Lexeme for demo system
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365034 ) Change subject: Populate "Ask out" (modeling 2) Lexeme for demo system .. Populate "Ask out" (modeling 2) Lexeme for demo system Bug: T168373 Change-Id: I593e7a9a813735492cb14974045911ee7c402a19 --- M src/Content/LexemeContent.php A src/DemoData/AskOut2Populator.php 2 files changed, 32 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/34/365034/1 diff --git a/src/Content/LexemeContent.php b/src/Content/LexemeContent.php index c6c3af3..774c125 100644 --- a/src/Content/LexemeContent.php +++ b/src/Content/LexemeContent.php @@ -62,6 +62,8 @@ ( new DemoData\LeiterLexemePopulator() )->populate( $lexeme ); } elseif ( $id === DemoData\Id::L_ASK_1 ) { ( new DemoData\AskOut1Populator() )->populate( $lexeme ); + } elseif ( $id === DemoData\Id::L_ASK_2 ) { + ( new DemoData\AskOut2Populator() )->populate( $lexeme ); } else { ( new DemoData\DefaultPopulator() )->populate( $lexeme ); } diff --git a/src/DemoData/AskOut2Populator.php b/src/DemoData/AskOut2Populator.php new file mode 100644 index 000..87bfb8c --- /dev/null +++ b/src/DemoData/AskOut2Populator.php @@ -0,0 +1,30 @@ +buildDefaultSense(); + + $lexeme->setSenses( [ $defaultSense ] ); + } + + /** +* @return \Wikibase\Lexeme\DataModel\Sense +*/ + private function buildDefaultSense() { + return NewSense::havingId( 'S5' ) + ->withGloss( 'en', 'To request a romantic date' ) + ->withStatement( + NewStatement::forProperty( Id::P_GRAMMATICAL_FRAME ) + ->withValue( 'to $somebody out' ) + ) + ->build(); + } + +} -- To view, visit https://gerrit.wikimedia.org/r/365034 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I593e7a9a813735492cb14974045911ee7c402a19 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Populate "Ask out" (modeling 1) Lexeme for demo system
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365032 ) Change subject: Populate "Ask out" (modeling 1) Lexeme for demo system .. Populate "Ask out" (modeling 1) Lexeme for demo system Bug: T168373 Change-Id: I45f501f19a12439c3e814576394692dd9348a730 --- M src/Content/LexemeContent.php A src/DemoData/AskOut1Populator.php 2 files changed, 27 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/32/365032/1 diff --git a/src/Content/LexemeContent.php b/src/Content/LexemeContent.php index d2e0605..c6c3af3 100644 --- a/src/Content/LexemeContent.php +++ b/src/Content/LexemeContent.php @@ -60,6 +60,8 @@ ( new DemoData\HardLexemePopulator() )->populate( $lexeme ); } elseif ( $id === DemoData\Id::L_LEITER ) { ( new DemoData\LeiterLexemePopulator() )->populate( $lexeme ); + } elseif ( $id === DemoData\Id::L_ASK_1 ) { + ( new DemoData\AskOut1Populator() )->populate( $lexeme ); } else { ( new DemoData\DefaultPopulator() )->populate( $lexeme ); } diff --git a/src/DemoData/AskOut1Populator.php b/src/DemoData/AskOut1Populator.php new file mode 100644 index 000..15ab63b --- /dev/null +++ b/src/DemoData/AskOut1Populator.php @@ -0,0 +1,25 @@ +buildDefaultSense(); + + $lexeme->setSenses( [ $defaultSense ] ); + } + + /** +* @return \Wikibase\Lexeme\DataModel\Sense +*/ + private function buildDefaultSense() { + return NewSense::havingId( 'S5' ) + ->withGloss( 'en', 'To ask somebody out’: To request a romantic date' ) + ->build(); + } + +} -- To view, visit https://gerrit.wikimedia.org/r/365032 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I45f501f19a12439c3e814576394692dd9348a730 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Populate "Leiter" Lexeme for demo system
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365029 ) Change subject: Populate "Leiter" Lexeme for demo system .. Populate "Leiter" Lexeme for demo system Bug: T168373 Change-Id: Ib85210af058ea39d9ab100e51eb5cbe29f8aeff0 --- M src/Content/LexemeContent.php A src/DemoData/LeiterLexemePopulator.php 2 files changed, 85 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/29/365029/1 diff --git a/src/Content/LexemeContent.php b/src/Content/LexemeContent.php index 7c0430d..d2e0605 100644 --- a/src/Content/LexemeContent.php +++ b/src/Content/LexemeContent.php @@ -55,8 +55,11 @@ $lexeme = $this->lexemeHolder->getEntity( Lexeme::class ); // TODO: This is a test dummy that must be removed later - if ( $lexeme->getId()->getSerialization() === DemoData\Id::L_HARD ) { + $id = $lexeme->getId()->getSerialization(); + if ( $id === DemoData\Id::L_HARD ) { ( new DemoData\HardLexemePopulator() )->populate( $lexeme ); + } elseif ( $id === DemoData\Id::L_LEITER ) { + ( new DemoData\LeiterLexemePopulator() )->populate( $lexeme ); } else { ( new DemoData\DefaultPopulator() )->populate( $lexeme ); } diff --git a/src/DemoData/LeiterLexemePopulator.php b/src/DemoData/LeiterLexemePopulator.php new file mode 100644 index 000..f0447db --- /dev/null +++ b/src/DemoData/LeiterLexemePopulator.php @@ -0,0 +1,81 @@ +buildLeiterForm(); + $leitersForm = $this->buildLeitersForm(); + $leiterinForm = $this->buildLeiterinForm(); + + $leaderSense = $this->buildLeaderSense(); + $electricalConductorSense = $this->buildElectricalConductorSense(); + + $lexeme->setForms( [ $leiterForm, $leitersForm, $leiterinForm ] ); + $lexeme->setSenses( [ $leaderSense, $electricalConductorSense ] ); + } + + /** +* @return \Wikibase\Lexeme\DataModel\Form +*/ + private function buildLeiterForm() { + return NewForm::havingId( 'F1' ) + ->andRepresentation( 'de', 'Leiter' ) + ->andGrammaticalFeature( Id::Q_NOMINATIVE ) + ->andGrammaticalFeature( Id::Q_SINGULAR ) + ->andStatement( + NewStatement::forProperty( Id::P_IPA_PRONUNCIATION ) + ->withValue( '/.../' ) + )->andStatement( + NewStatement::forProperty( Id::P_SYLLABIFICATION ) + ->withValue( 'Lei-ter' ) + )->build(); + } + + /** +* @return \Wikibase\Lexeme\DataModel\Form +*/ + private function buildLeitersForm() { + return NewForm::havingId( 'F2' ) + ->andRepresentation( 'de', 'Leiters' ) + ->andGrammaticalFeature( Id::Q_GENITIVE ) + ->andGrammaticalFeature( Id::Q_SINGULAR ) + ->build(); + } + + private function buildLeiterinForm() { + return NewForm::havingId( 'F3' ) + ->andRepresentation( 'de', 'Leiterin' ) + ->andGrammaticalFeature( Id::Q_NOMINATIVE ) + ->andGrammaticalFeature( Id::Q_SINGULAR ) + ->andGrammaticalFeature( Id::Q_FEMALE ) + ->build(); + } + + /** +* @return \Wikibase\Lexeme\DataModel\Sense +*/ + private function buildLeaderSense() { + return NewSense::havingId( 'S1' ) + ->withGloss( 'de', 'Führungsperson' ) + ->withGloss( 'en', 'leader' ) + ->build(); + } + + /** +* @return \Wikibase\Lexeme\DataModel\Sense +*/ + private function buildElectricalConductorSense() { + return NewSense::havingId( 'S2' ) + ->withGloss( 'de', 'elektrischer Leiter' ) + ->withGloss( 'en', 'electrical conductor' ) + ->build(); + } + +} -- To view, visit https://gerrit.wikimedia.org/r/365029 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib85210af058ea39d9ab100e51eb5cbe29f8aeff0 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Move TODO to proper place
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365026 ) Change subject: Move TODO to proper place .. Move TODO to proper place Change-Id: I33598873e7f5c5908fc36fbd0cd1c80a301b29a7 --- M src/Content/LexemeContent.php M src/DemoData/DefaultPopulator.php 2 files changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/26/365026/1 diff --git a/src/Content/LexemeContent.php b/src/Content/LexemeContent.php index 64d702b..7c0430d 100644 --- a/src/Content/LexemeContent.php +++ b/src/Content/LexemeContent.php @@ -54,6 +54,7 @@ /** @var Lexeme $lexeme */ $lexeme = $this->lexemeHolder->getEntity( Lexeme::class ); + // TODO: This is a test dummy that must be removed later if ( $lexeme->getId()->getSerialization() === DemoData\Id::L_HARD ) { ( new DemoData\HardLexemePopulator() )->populate( $lexeme ); } else { diff --git a/src/DemoData/DefaultPopulator.php b/src/DemoData/DefaultPopulator.php index faf2d96..408bc53 100644 --- a/src/DemoData/DefaultPopulator.php +++ b/src/DemoData/DefaultPopulator.php @@ -21,7 +21,6 @@ class DefaultPopulator { public function populate( Lexeme $lexeme ) { - // TODO: This obviously is a dummy that must be removed $grammaticalFeatures1 = [ new ItemId( 'Q2' ) ]; $grammaticalFeatures2 = [ new ItemId( 'Q2' ), new ItemId( 'Q3' ) ]; $statements1 = new StatementList( -- To view, visit https://gerrit.wikimedia.org/r/365026 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I33598873e7f5c5908fc36fbd0cd1c80a301b29a7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Setup data for demo system
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365025 ) Change subject: Setup data for demo system .. Setup data for demo system All ID values were taken from http://wikidata-lexeme.wmflabs.org Used Test builders to make code more readable. I don't see a problem here as soon as this code is temporary. Change-Id: Iaacf73a9b3135462dde212ecf773c90ba12ae55c --- M src/Content/LexemeContent.php A src/DemoData/DefaultPopulator.php A src/DemoData/HardLexemePopulator.php A src/DemoData/Id.php 4 files changed, 278 insertions(+), 92 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/25/365025/1 diff --git a/src/Content/LexemeContent.php b/src/Content/LexemeContent.php index 8c97975..64d702b 100644 --- a/src/Content/LexemeContent.php +++ b/src/Content/LexemeContent.php @@ -5,23 +5,10 @@ use InvalidArgumentException; use LogicException; use Wikibase\Content\EntityHolder; -use Wikibase\DataModel\Term\Term; -use Wikibase\DataModel\Term\TermList; use Wikibase\EntityContent; use Wikibase\Lexeme\DataModel\Lexeme; -use Wikibase\Lexeme\DataModel\Sense; -use Wikibase\Lexeme\DataModel\SenseId; +use Wikibase\Lexeme\DemoData; use Wikimedia\Assert\Assert; - -use DataValues\StringValue; -use Wikibase\DataModel\Entity\ItemId; -use Wikibase\DataModel\Entity\PropertyId; -use Wikibase\DataModel\Snak\PropertyNoValueSnak; -use Wikibase\DataModel\Snak\PropertyValueSnak; -use Wikibase\DataModel\Statement\Statement; -use Wikibase\DataModel\Statement\StatementList; -use Wikibase\Lexeme\DataModel\Form; -use Wikibase\Lexeme\DataModel\FormId; /** * @license GPL-2.0+ @@ -67,84 +54,11 @@ /** @var Lexeme $lexeme */ $lexeme = $this->lexemeHolder->getEntity( Lexeme::class ); - // TODO: This obviously is a dummy that must be removed - $grammaticalFeatures1 = [ new ItemId( 'Q2' ) ]; - $grammaticalFeatures2 = [ new ItemId( 'Q2' ), new ItemId( 'Q3' ) ]; - $statements1 = new StatementList( - [ - new Statement( new PropertyNoValueSnak( new PropertyId( 'P2' ) ), null, null, 'guid1' ) - ] - ); - $statements2 = new StatementList( - [ - new Statement( new PropertyNoValueSnak( new PropertyId( 'P2' ) ), null, null, 'guid2' ), - new Statement( - new PropertyValueSnak( - new PropertyId( 'P3' ), - new StringValue( 'asd' ) - ), - null, - null, - 'guid3' - ), - ] - ); - - $forms = [ - new Form( - new FormId( 'F1' ), - new TermList( [ new Term( 'en', 'A' ) ] ), - [] - ), - new Form( - new FormId( 'F2' ), - new TermList( [ new Term( 'en', 'B' ) ] ), - $grammaticalFeatures1, - $statements1 - ), - new Form( - new FormId( 'F3' ), - new TermList( [ new Term( 'en', 'C' ) ] ), - $grammaticalFeatures2, - $statements2 - ), - ]; - - $lexeme->setForms( $forms ); - - $senses = [ - new Sense( - new SenseId( 'S1' ), - new TermList( [ - new Term( - 'en', - 'A mammal, Capra aegagrus hircus, and similar species of the genus Capra.' - ), - new Term( - 'fr', - 'Un mammale, Capra aegagruse hircuse, et similare species de un genuse Capra.' - ), - ] ), - new StatementList() - ), - new Sense( - new SenseId( 'S2' ), - new TermList( [ new Term( 'en', 'A scapegoat.' ) ] ), - ne
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Add `NewSense` integration with `NewStatement`
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365024 ) Change subject: Add `NewSense` integration with `NewStatement` .. Add `NewSense` integration with `NewStatement` Change-Id: I3dd90bc0c5408d8f272d7530eb8b1158860702f1 --- M tests/phpunit/composer/DataModel/NewSense.php 1 file changed, 6 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/24/365024/1 diff --git a/tests/phpunit/composer/DataModel/NewSense.php b/tests/phpunit/composer/DataModel/NewSense.php index 8ff1482..45c48ef 100644 --- a/tests/phpunit/composer/DataModel/NewSense.php +++ b/tests/phpunit/composer/DataModel/NewSense.php @@ -11,6 +11,7 @@ use Wikibase\DataModel\Term\TermList; use Wikibase\Lexeme\DataModel\Sense; use Wikibase\Lexeme\DataModel\SenseId; +use Wikibase\Repo\Tests\NewStatement; /** * Sense builder to use in tests @@ -82,17 +83,18 @@ } /** -* @param Statement|Snak|PropertyId $arg +* @param Statement|Snak|PropertyId|NewStatement $arg * * @return NewSense */ public function withStatement( $arg ) { $result = clone $this; $statement = $arg; - if ( $arg instanceof PropertyId ) { + if ( $arg instanceof NewStatement ) { + $statement = $arg->build(); + } elseif ( $arg instanceof PropertyId ) { $statement = new Statement( new PropertyNoValueSnak( $arg ) ); - } - if ( $arg instanceof Snak ) { + } elseif ( $arg instanceof Snak ) { $statement = new Statement( $arg ); } $result->statements[] = clone $statement; -- To view, visit https://gerrit.wikimedia.org/r/365024 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3dd90bc0c5408d8f272d7530eb8b1158860702f1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: [Proposal] Use LESS instead of CSS
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/364990 ) Change subject: [Proposal] Use LESS instead of CSS .. [Proposal] Use LESS instead of CSS Change-Id: Id6487f6d5f26098418be3479904ab0b8f9a77730 --- M extension.json A resources/lemma-widget.less D resources/lexeme.css A resources/lexeme.less A resources/representation-widget.less 5 files changed, 400 insertions(+), 395 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/90/364990/1 diff --git a/extension.json b/extension.json index 3b6b2ab..92173c7 100644 --- a/extension.json +++ b/extension.json @@ -340,7 +340,7 @@ "wikibase.lexeme.styles": { "position": "top", "styles": [ - "lexeme.css" + "lexeme.less" ] } }, diff --git a/resources/lemma-widget.less b/resources/lemma-widget.less new file mode 100644 index 000..e8ec406 --- /dev/null +++ b/resources/lemma-widget.less @@ -0,0 +1,109 @@ +.lemma-widget { + display: flex; + + &_lemma-list { + margin: 0; + padding: 0; + list-style: none; + display: flex; + flex-wrap: wrap; + flex-grow: 1; + } + + &_lemma { + display: flex; + flex-direction: column; + border-left: 6px solid #ededed; + padding: 0 9px; + margin-bottom: 22px; + } + + &_lemma-value { + font-size: 3em; + font-weight: bold; + } + + &_lemma-language { + font-size: 1.5em; + } + + &_edit-area { + display: flex; + border: 3px solid #99ccff; + } + + &_controls { + width: 100px; + padding: 20px 40px; + background: #dae8fc; + display: flex; + flex-direction: column; + justify-content: center; + } + + &_control { + background: transparent; + border: none; + font-size: 1.5em; + margin: 10px; + cursor: pointer; + color: #0d4c99; + } + + &_lemma-edit-box { + position: relative; + display: flex; + flex-direction: column; + justify-content: space-around; + border-left: 6px solid #dae8fc; + padding: 0 45px 0 9px; + margin-bottom: 22px; + + height: 132px; + } + + &_lemma-value-input { + resize: horizontal; + min-width: 120px; + padding-right: 20px; + + font-size: 3em; + } + + &_lemma-value-input:active { + width: auto; + } + + &_lemma-language-input { + resize: horizontal; + min-width: 120px; + font-size: 1.5em; + padding-right: 20px; + } + + &_lemma-language-input:active { + width: auto; + } + + &_lemma-remove { + border: none; + background: transparent; + color: #074c99; + font-size: 2em; + cursor: pointer; + + position: absolute; + top: -11px; + right: 23px; + } + + &_add { + height: 132px; + border: none; + font-size: 3em; + text-align: center; + background: #dae8fc; + cursor: pointer; + } + +} diff --git a/resources/lexeme.css b/resources/lexeme.css deleted file mode 100644 index 4ceeb41..000 --- a/resources/lexeme.css +++ /dev/null @@ -1,394 +0,0 @@ -.wb-lexeme.wikibase-entityview { - float: none; -} - -.wb-lexeme .wikibase-entitytermsforlanguagelistview-aliases, -.wb-lexeme .wikibase-entitytermsforlanguageview-aliases, -.wb-lexeme .wikibase-entitytermsview-aliases .wikibase-entitytermsforlanguagelistview-description { - display: none; -} - -.wb-lexeme .wikibase-entitytermsforlanguagelistview .wikibase-entitytermsforlanguagelistview-header .wikibase-entitytermsforlanguagelistview-header-row { - border-right: 0; - width: 60%; -} - -.wikibase-lexeme-forms { - margin-left: 10px; -} - -.wikibase-lexeme-forms .wikibase-lexeme-form { - position: relative; - clear: left; - margin-bottom: 2em; -} - -.wikibase-lexeme-form-header { - display: flex; - align-items: center; -} -.wikibase-lexeme-form-id { - font-size: 1em; - min-width: 2.5em; - margin-right: 1.25em; -} - -.wikibase-lexeme-form-body { - margin-left: 3.75em; -} - -.wikibas
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: [DNM] Stylus introduction
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/364891 ) Change subject: [DNM] Stylus introduction .. [DNM] Stylus introduction Change-Id: Ie4c4abfd272590271bc8aaf9882b487078c0147f --- M Gruntfile.js M package.json A resources/stylus/lemma-widget.styl A resources/stylus/lexeme.styl A resources/stylus/representation-widget.styl A resources/stylus/senses.styl 6 files changed, 412 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/91/364891/1 diff --git a/Gruntfile.js b/Gruntfile.js index f14dc80..1f1acc3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,6 +4,8 @@ grunt.loadNpmTasks( 'grunt-eslint' ); grunt.loadNpmTasks( 'grunt-jsonlint' ); grunt.loadNpmTasks( 'grunt-banana-checker' ); + grunt.loadNpmTasks( 'grunt-contrib-stylus' ); + grunt.loadNpmTasks( 'grunt-then' ); grunt.initConfig( { eslint: { @@ -18,9 +20,53 @@ '!node_modules/**', '!vendor/**' ] + }, + stylus: { + all: { + options: { + compress: false, + paths: [ 'resources/stylus' ] + }, + files: { + 'resources/lexeme.css': [ 'resources/stylus/lexeme.styl' ] + } + } } } ); - grunt.registerTask( 'test', [ 'eslint', 'jsonlint', 'banana' ] ); + grunt.registerTask( + 'test-stylus-compilation', + 'Check that every stylus task was executed before commit', + function () { + 'use strict'; + const crypto = require( 'crypto' ); + const stylusFilesConfig = grunt.config.data.stylus.all.files; + const oldHashes = {}; + for ( var fileName in stylusFilesConfig ) { + if ( stylusFilesConfig.hasOwnProperty( fileName ) ) { + let hash = crypto.createHash( 'sha256' ); + hash.update( grunt.file.read( fileName ) ); + oldHashes[ fileName ] = hash; + } + } + + grunt.registerTask( '__check-css-file-hashes', '', function () { + for ( var fileName in oldHashes ) { + if ( oldHashes.hasOwnProperty( fileName ) ) { + let oldHash = oldHashes[ fileName ]; + let newHash = crypto.createHash( 'sha256' ); + newHash.update( grunt.file.read( fileName ) ); + + if ( oldHash.digest( 'latin1' ) !== newHash.digest( 'latin1' ) ) { + throw new Error( fileName + " was changed during compilation!" ); + } + } + } + } ); + + grunt.task.run( [ 'stylus:all', '__check-css-file-hashes' ] ); + } ); + + grunt.registerTask( 'test', [ 'eslint', 'jsonlint', 'banana', 'test-stylus-compilation' ] ); grunt.registerTask( 'default', 'test' ); }; diff --git a/package.json b/package.json index 1fca5de..6913992 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,10 @@ "eslint-config-wikimedia": "0.4.0", "grunt": "0.4.5", "grunt-banana-checker": "0.4.0", -"grunt-eslint": "19.0.0", "grunt-cli": "0.1.13", -"grunt-jsonlint": "1.0.7" +"grunt-contrib-stylus": "^1.2.0", +"grunt-eslint": "19.0.0", +"grunt-jsonlint": "1.0.7", +"stylus": "^0.54.5" } } diff --git a/resources/stylus/lemma-widget.styl b/resources/stylus/lemma-widget.styl new file mode 100644 index 000..1b771fd --- /dev/null +++ b/resources/stylus/lemma-widget.styl @@ -0,0 +1,103 @@ +.lemma-widget { + display: flex; + + &_lemma-list { +margin: 0; +padding: 0; +list-style: none; +display: flex; +flex-wrap: wrap; +flex-grow: 1; + } + + &_lemma { +display: flex; +flex-direction: column; +border-left: 6px solid #ededed; +padding: 0 9px; +margin-bottom: 22px; + } + + &_lemma-value { +font-size: 3em; +font-weight: bold; + } + + &_lemma-language { +font-size: 1.5em; + } + + &_edit-area { +display: flex; +border:
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Change Sense's statement header to "Statements about S..."
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/364781 ) Change subject: Change Sense's statement header to "Statements about S..." .. Change Sense's statement header to "Statements about S..." Bug: T170379 Change-Id: Ife809e007726d0b09dfeb8a902ac15865d1ab158 --- M src/View/LexemeViewFactory.php M src/View/SensesView.php 2 files changed, 35 insertions(+), 11 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/81/364781/1 diff --git a/src/View/LexemeViewFactory.php b/src/View/LexemeViewFactory.php index cc444b2..b8c6536 100644 --- a/src/View/LexemeViewFactory.php +++ b/src/View/LexemeViewFactory.php @@ -122,7 +122,7 @@ $localizedTextProvider, $languageDirectionalityLookup, $templateFactory, - $statementSectionsView, + $statementGroupListView, $this->languageCode ); diff --git a/src/View/SensesView.php b/src/View/SensesView.php index b0aa4e4..3bb1c60 100644 --- a/src/View/SensesView.php +++ b/src/View/SensesView.php @@ -9,7 +9,7 @@ use Wikibase\Lexeme\View\Template\LexemeTemplateFactory; use Wikibase\View\LanguageDirectionalityLookup; use Wikibase\View\LocalizedTextProvider; -use Wikibase\View\StatementSectionsView; +use Wikibase\View\StatementGroupListView; use WMDE\VueJsTemplating\Templating; /** @@ -33,33 +33,33 @@ private $templateFactory; /** -* @var StatementSectionsView -*/ - private $statementSectionsView; - - /** * @var string */ private $languageCode; /** +* @var StatementGroupListView +*/ + private $statementGroupListView; + + /** * @param LocalizedTextProvider $textProvider * @param LanguageDirectionalityLookup $languageDirectionalityLookup * @param LexemeTemplateFactory $templateFactory -* @param StatementSectionsView $statementSectionsView +* @param StatementGroupListView $statementGroupListView * @param string $languageCode */ public function __construct( LocalizedTextProvider $textProvider, LanguageDirectionalityLookup $languageDirectionalityLookup, LexemeTemplateFactory $templateFactory, - StatementSectionsView $statementSectionsView, + StatementGroupListView $statementGroupListView, $languageCode ) { $this->textProvider = $textProvider; $this->languageDirectionalityLookup = $languageDirectionalityLookup; $this->templateFactory = $templateFactory; - $this->statementSectionsView = $statementSectionsView; + $this->statementGroupListView = $statementGroupListView; $this->languageCode = $languageCode; } @@ -126,12 +126,36 @@ [ $sense->getId()->getSerialization(), $glossWidget, - $this->statementSectionsView->getHtml( $sense->getStatements() ) + $this->getStatementSectionHtml( $sense ) ] ); } /** +* @param Sense $sense +* @return string +*/ + private function getStatementSectionHtml( Sense $sense ) { + $headerText = htmlspecialchars( + $this->textProvider->get( + 'wikibase-lexeme-statementsection-statements-about', + [ $sense->getId()->getSerialization() ] + ) + ); + + $statementHeader = << + {$headerText} + +HTML; + + $statementSection = $this->statementGroupListView->getHtml( + $sense->getStatements()->toArray() + ); + return $statementHeader . $statementSection; + } + + /** * @param string $key * * @return string Plain text -- To view, visit https://gerrit.wikimedia.org/r/364781 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ife809e007726d0b09dfeb8a902ac15865d1ab158 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Change Form's statements header text
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/364768 ) Change subject: Change Form's statements header text .. Change Form's statements header text Bug: T170388 Change-Id: I76f6152c2544af75cf716d9342c9e5f44d2639a4 --- M extension.json M i18n/en.json M i18n/qqq.json M resources/jquery.wikibase.lexemeformview.js M src/View/LexemeFormsView.php M src/View/LexemeViewFactory.php 6 files changed, 43 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/68/364768/1 diff --git a/extension.json b/extension.json index 3b6b2ab..cc22539 100644 --- a/extension.json +++ b/extension.json @@ -84,7 +84,7 @@ "messages": [ "wikibase-lexeme-empty-form-representation", "wikibase-lexeme-enter-form-representation", - "wikibase-statementsection-statements" + "wikibase-lexeme-statementsection-statements-for" ] }, "jquery.wikibase.grammaticalfeatureview": { diff --git a/i18n/en.json b/i18n/en.json index 6480be1..4abf84c 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -11,6 +11,7 @@ "wikibase-newlexeme-lexicalcategory": "Lexical category", "wikibase-newlexeme-language": "Language of lexeme", "wikibase-lexeme-view-language-lexical-category": "$1 in $2", + "wikibase-lexeme-statementsection-statements-for": "Statements for $1", "wikibase-lexeme-view-forms": "Morphology", "wikibase-lexeme-enter-form-representation": "Enter new form representation", "wikibase-lexeme-empty-form-representation": "No form representation defined", diff --git a/i18n/qqq.json b/i18n/qqq.json index 0d013fe..dfdb6c9 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -16,6 +16,7 @@ "wikibase-newlexeme-lexicalcategory": "Name for \"lexical category\"", "wikibase-newlexeme-language": "Label for field in the lexeme creation form.", "wikibase-lexeme-view-language-lexical-category": "Description when both lexical category and language are present\n{{Identical|In}}", + "wikibase-lexeme-statementsection-statements-for": "Heading for the list of statements giving specific information about the currently viewed Form or Sense of a Lexeme.\n{{Identical|Statements}}", "wikibase-lexeme-view-forms": "Subheading for the morphology (forms) section on a lexeme page.\n{{Identical|Form}}", "wikibase-lexeme-enter-form-representation": "Placeholder for the lexeme form representation input field.", "wikibase-lexeme-empty-form-representation": "Placeholder message displayed instead of the lexeme form representation in case no representation has been specified yet.", diff --git a/resources/jquery.wikibase.lexemeformview.js b/resources/jquery.wikibase.lexemeformview.js index b057626..6040a4f 100644 --- a/resources/jquery.wikibase.lexemeformview.js +++ b/resources/jquery.wikibase.lexemeformview.js @@ -51,10 +51,11 @@ function () { var $container = $( '' ); this.deferredFormWithId.promise().then( function ( form ) { + var messageKey = 'wikibase-lexeme-statementsection-statements-for'; var $header = $( '' ).applyTemplate( 'wb-section-heading', [ - mw.message( 'wikibase-statementsection-statements' ).escaped(), + mw.message( messageKey, form.getId() ).escaped(), '', 'wikibase-statements' ] diff --git a/src/View/LexemeFormsView.php b/src/View/LexemeFormsView.php index 20d119b..8794b8f 100644 --- a/src/View/LexemeFormsView.php +++ b/src/View/LexemeFormsView.php @@ -8,7 +8,7 @@ use Wikibase\Lexeme\View\Template\LexemeTemplateFactory; use Wikibase\Lib\EntityIdHtmlLinkFormatter; use Wikibase\View\LocalizedTextProvider; -use Wikibase\View\StatementSectionsView; +use Wikibase\View\StatementGroupListView; use WMDE\VueJsTemplating\Templating; /** @@ -33,9 +33,9 @@ private $entityIdHtmlFormatter; /** -* @var StatementSectionsView +* @var StatementGroupListView */ - private $statementSectionView; + private $statementGroupListView; /** * @var string @@ -46,12 +46,12 @@ LocalizedT
[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Add method creating StatementGroupListView
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/364767 ) Change subject: Add method creating StatementGroupListView .. Add method creating StatementGroupListView Needed for Lexeme view to be able to change the statement header Bug: T170388 Change-Id: Ic522ad291c299a4c60993c304f340a10f625fb9b --- M view/src/ViewFactory.php 1 file changed, 31 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/67/364767/1 diff --git a/view/src/ViewFactory.php b/view/src/ViewFactory.php index a924963..381a0a0 100644 --- a/view/src/ViewFactory.php +++ b/view/src/ViewFactory.php @@ -278,6 +278,35 @@ LanguageFallbackChain $fallbackChain, EditSectionGenerator $editSectionGenerator ) { + $statementGroupListView = $this->newStatementGroupListView( + $languageCode, + $labelDescriptionLookup, + $fallbackChain, + $editSectionGenerator + ); + + return new StatementSectionsView( + $this->templateFactory, + $this->statementGrouper, + $statementGroupListView, + $this->textProvider + ); + } + + /** +* @param string $languageCode +* @param LabelDescriptionLookup $labelDescriptionLookup +* @param LanguageFallbackChain $fallbackChain +* @param EditSectionGenerator $editSectionGenerator +* +* @return StatementGroupListView +*/ + public function newStatementGroupListView( + $languageCode, + LabelDescriptionLookup $labelDescriptionLookup, + LanguageFallbackChain $fallbackChain, + EditSectionGenerator $editSectionGenerator + ) { $snakFormatter = $this->htmlSnakFormatterFactory->getSnakFormatter( $languageCode, $fallbackChain, @@ -298,19 +327,13 @@ $this->numberLocalizer, $this->textProvider ); - $statementGroupListView = new StatementGroupListView( + + return new StatementGroupListView( $this->propertyOrderProvider, $this->templateFactory, $propertyIdFormatter, $editSectionGenerator, $statementHtmlGenerator - ); - - return new StatementSectionsView( - $this->templateFactory, - $this->statementGrouper, - $statementGroupListView, - $this->textProvider ); } -- To view, visit https://gerrit.wikimedia.org/r/364767 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic522ad291c299a4c60993c304f340a10f625fb9b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Representation widget doesn't explode vertically
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/364723 ) Change subject: Representation widget doesn't explode vertically .. Representation widget doesn't explode vertically Bug: T170388 Change-Id: I42bc85fd7e1a9ca5100eed1471b5f3172da05fdc --- M resources/lexeme.css M src/View/LexemeFormsView.php 2 files changed, 23 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/23/364723/1 diff --git a/resources/lexeme.css b/resources/lexeme.css index cec2726..fe9b5d5 100644 --- a/resources/lexeme.css +++ b/resources/lexeme.css @@ -50,6 +50,10 @@ .wikibase-lexeme-form-grammatical-features { display: flex; } +.wikibase-lexeme-form-grammatical-features-header { + white-space: nowrap; + align-self: center; +} .wikibase-lexeme-form-grammatical-features-values { margin: 0 10px; @@ -193,7 +197,7 @@ flex-direction: column; border-left: 6px solid #ededed; padding: 0 9px; - margin: 11px 0; + margin: 0.785em 0; } .representation-widget_representation-value { @@ -206,7 +210,11 @@ .representation-widget_edit-area { display: flex; - border: 2px solid #99ccff; + border: 0.143em solid #99ccff; +} + +.representation-widget_edit-area-controls { + margin: 0; } .representation-widget_controls { @@ -233,18 +241,18 @@ flex-direction: column; justify-content: space-around; border-left: 6px solid #dae8fc; - padding: 0 45px 0 9px; - margin: 11px 0; + padding: 0 18px 0 9px; + margin: calc(0.785em - 0.143em) 0; - height: 132px; + height: 3.150em; } .representation-widget_representation-value-input { resize: horizontal; - min-width: 120px; - padding-right: 20px; + min-width: 7.5em; + padding-right: 1.25em; - font-size: 2em; + font-size: 1em; } .representation-widget_representation-value-input:active { @@ -253,9 +261,9 @@ .representation-widget_representation-language-input { resize: horizontal; - min-width: 120px; + min-width: 7.5em; font-size: 1em; - padding-right: 20px; + padding-right: 1.25em; } .representation-widget_representation-language-input:active { @@ -266,18 +274,18 @@ border: none; background: transparent; color: #074c99; - font-size: 2em; + font-size: 1em; cursor: pointer; position: absolute; - top: -11px; - right: 23px; + top: -0.3em; + right: 0.125em; } .representation-widget_add { height: 100%; border: none; - font-size: 2em; + font-size: 1em; text-align: center; background: #dae8fc; cursor: pointer; diff --git a/src/View/LexemeFormsView.php b/src/View/LexemeFormsView.php index 017591f..20d119b 100644 --- a/src/View/LexemeFormsView.php +++ b/src/View/LexemeFormsView.php @@ -180,7 +180,7 @@ × - + + -- To view, visit https://gerrit.wikimedia.org/r/364723 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I42bc85fd7e1a9ca5100eed1471b5f3172da05fdc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Remove unused styles for nonexistent form representation widget
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/364694 ) Change subject: Remove unused styles for nonexistent form representation widget .. Remove unused styles for nonexistent form representation widget Bug: T170388 Change-Id: Ibe30489acad37ceacfe29c20b5602afcb7406a25 --- M resources/lexeme.css 1 file changed, 0 insertions(+), 19 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/94/364694/1 diff --git a/resources/lexeme.css b/resources/lexeme.css index bd93565..cec2726 100644 --- a/resources/lexeme.css +++ b/resources/lexeme.css @@ -42,25 +42,6 @@ font-size: 1em; } -.wikibase-lexeme-forms .wikibase-lexeme-form-representation { - clear: left; - margin-left: 10px; /* same as .wb-section-heading */ - position: relative; - border-bottom: 1px solid #a2a9b1; - font-weight: normal; -} - -.wikibase-lexeme-form-representation .wikibase-toolbar-container { - font-size: 0.833em; /* reset from h3 size to 100% for toolbar alignment */ -} - -.wikibase-lexeme-forms .wikibase-lexeme-form-representation textarea { - display: inline-block; - font-size: 0.9em; - height: 1.5em; - vertical-align: middle; -} - .wikibase-lexeme-forms-section > .wikibase-toolbar-container { position: static; float: left; -- To view, visit https://gerrit.wikimedia.org/r/364694 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibe30489acad37ceacfe29c20b5602afcb7406a25 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Align form contents with headline 'Morphology'
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/364693 ) Change subject: Align form contents with headline 'Morphology' .. Align form contents with headline 'Morphology' Also: * Font size < headline * Form representation should not bold and also smaller font-size Bug: T170388 Change-Id: If418e9ff4716ed45d692e9753e3a2da1e2b3f3d4 --- M resources/lexeme.css M resources/templates.php 2 files changed, 22 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/93/364693/1 diff --git a/resources/lexeme.css b/resources/lexeme.css index 4b31252..bd93565 100644 --- a/resources/lexeme.css +++ b/resources/lexeme.css @@ -13,9 +13,14 @@ width: 60%; } +.wikibase-lexeme-forms { + margin-left: 10px; +} + .wikibase-lexeme-forms .wikibase-lexeme-form { position: relative; clear: left; + margin-bottom: 2em; } .wikibase-lexeme-form-header { @@ -23,7 +28,18 @@ align-items: center; } .wikibase-lexeme-form-id { - font-size: 2em; + font-size: 1em; + min-width: 2.5em; + margin-right: 1.25em; +} + +.wikibase-lexeme-form-body { + margin-left: 3.75em; +} + +.wikibase-lexeme-form h2.wb-section-heading { + padding-left: 0; + font-size: 1em; } .wikibase-lexeme-forms .wikibase-lexeme-form-representation { @@ -180,7 +196,6 @@ .representation-widget { display: flex; - margin: 0 2em; } .representation-widget_representation-list { @@ -201,8 +216,7 @@ } .representation-widget_representation-value { - font-size: 2em; - font-weight: bold; + font-size: 1em; } .representation-widget_representation-language { diff --git a/resources/templates.php b/resources/templates.php index d39eb20..6ca4900 100644 --- a/resources/templates.php +++ b/resources/templates.php @@ -20,8 +20,10 @@ $1 $2 - $3 - $4 + + $3 + $4 + HTML; -- To view, visit https://gerrit.wikimedia.org/r/364693 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If418e9ff4716ed45d692e9753e3a2da1e2b3f3d4 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Rename title Forms to Morphology
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/364690 ) Change subject: Rename title Forms to Morphology .. Rename title Forms to Morphology Change-Id: Iac15a2e7f1684876e60f7fab9a56cb7e1bb445fe --- M i18n/en.json M i18n/qqq.json 2 files changed, 2 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/90/364690/1 diff --git a/i18n/en.json b/i18n/en.json index 7e9fce5..6480be1 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -11,7 +11,7 @@ "wikibase-newlexeme-lexicalcategory": "Lexical category", "wikibase-newlexeme-language": "Language of lexeme", "wikibase-lexeme-view-language-lexical-category": "$1 in $2", - "wikibase-lexeme-view-forms": "Forms", + "wikibase-lexeme-view-forms": "Morphology", "wikibase-lexeme-enter-form-representation": "Enter new form representation", "wikibase-lexeme-empty-form-representation": "No form representation defined", "wikibase-lexeme-view-senses": "Senses", diff --git a/i18n/qqq.json b/i18n/qqq.json index 22b35bc..0d013fe 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -16,7 +16,7 @@ "wikibase-newlexeme-lexicalcategory": "Name for \"lexical category\"", "wikibase-newlexeme-language": "Label for field in the lexeme creation form.", "wikibase-lexeme-view-language-lexical-category": "Description when both lexical category and language are present\n{{Identical|In}}", - "wikibase-lexeme-view-forms": "Subheading for the forms section on a lexeme page.\n{{Identical|Form}}", + "wikibase-lexeme-view-forms": "Subheading for the morphology (forms) section on a lexeme page.\n{{Identical|Form}}", "wikibase-lexeme-enter-form-representation": "Placeholder for the lexeme form representation input field.", "wikibase-lexeme-empty-form-representation": "Placeholder message displayed instead of the lexeme form representation in case no representation has been specified yet.", "wikibase-lexeme-view-senses": "Subheading for the senses section on a lexeme page.\n{{Identical|Sense}}", -- To view, visit https://gerrit.wikimedia.org/r/364690 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iac15a2e7f1684876e60f7fab9a56cb7e1bb445fe Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseJavaScriptApi[master]: Fix multivalue serialization
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/364192 ) Change subject: Fix multivalue serialization .. Fix multivalue serialization Empty array was converted to `undefined`, which is not correct. Should be empty string Change-Id: If37a3dffad649397d12268f2dbbc23dd3c1364bd --- M src/RepoApi.js M tests/RepoApi.tests.js 2 files changed, 14 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseJavaScriptApi refs/changes/92/364192/1 diff --git a/src/RepoApi.js b/src/RepoApi.js index 14c0365..fddadf4 100644 --- a/src/RepoApi.js +++ b/src/RepoApi.js @@ -849,7 +849,9 @@ */ normalizeMultiValue: function ( value ) { if ( Array.isArray( value ) ) { - value = value.join( '\x1f' ); + return value.map( function (item) { + return '\x1f' + item; + } ).join(''); } // We must enforce the alternative separation character, see ApiBase.php::explodeMultiValue. diff --git a/tests/RepoApi.tests.js b/tests/RepoApi.tests.js index c75213b..ed0cb96 100644 --- a/tests/RepoApi.tests.js +++ b/tests/RepoApi.tests.js @@ -662,4 +662,15 @@ assert.strictEqual( getParam( mock.spy, 'summary', 2 ), undefined ); } ); +QUnit.test( 'normalizeMultiValue()', function ( assert ) { + var mock = mockApi(); + + assert.equal( mock.api.normalizeMultiValue( [] ), '', 'empty array -> empty string' ); + assert.equal( + mock.api.normalizeMultiValue( ['val1', 'val2'] ), + '\x1fval1\x1fval2', + 'array values are prefixed with `\\x1f`' + ); +} ); + }( mediaWiki, wikibase, QUnit, sinon ) ); -- To view, visit https://gerrit.wikimedia.org/r/364192 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If37a3dffad649397d12268f2dbbc23dd3c1364bd Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseJavaScriptApi Gerrit-Branch: master Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Make GlossWidget controlled by jquery.wikibase.senseview
Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/363625 ) Change subject: Make GlossWidget controlled by jquery.wikibase.senseview .. Make GlossWidget controlled by jquery.wikibase.senseview TODO: * Wrong state when edit is canceled Bug: T169639 Change-Id: I6da061c062eb6b4065983c44c72fe2d311f46f1e --- M resources/jquery.wikibase.senseview.js M resources/lexeme.css M resources/view/ControllerViewFactory.js M resources/widgets/GlossWidget.js M src/View/SensesView.php M tests/qunit/widgets/GlossWidget.tests.js 6 files changed, 108 insertions(+), 255 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/25/363625/1 diff --git a/resources/jquery.wikibase.senseview.js b/resources/jquery.wikibase.senseview.js index 1e5809d..5db42d4 100644 --- a/resources/jquery.wikibase.senseview.js +++ b/resources/jquery.wikibase.senseview.js @@ -54,10 +54,18 @@ value: function ( sense ) { if ( sense instanceof wikibase.lexeme.datamodel.Sense ) { this.option( 'value', sense ); + this.draw(); return; } - return this.options.value; + if ( !this.isInEditMode() ) { + return this.options.value; + } + + return new wikibase.lexeme.datamodel.Sense( + this.options.value ? this.options.value.getId() : null, + convertGlossWidgetModelToGlossHashMap( this.glossWidget.glosses ) + ); }, _create: function () { @@ -71,16 +79,21 @@ this.glossWidget = GlossWidget.applyGlossWidget( $( '.wikibase-lexeme-sense-glosses', this.element )[ 0 ], this.value().getId(), - convertGlossesToGlossWidgetModel( this.value().getGlosses() ) + convertGlossesToGlossWidgetModel( this.value().getGlosses() ), + function () { + this._trigger( 'change' ); + }.bind( this ) ); - - if ( !this.value().getId() ) { - this.startEditing(); - } }, _startEditing: function () { this.glossWidget.edit(); + + return $.Deferred().resolve().promise(); + }, + + _stopEditing: function () { + this.glossWidget.stopEditing(); return $.Deferred().resolve().promise(); }, @@ -100,4 +113,14 @@ return result; } + function convertGlossWidgetModelToGlossHashMap( glosses ) { + var result = {}; + + glosses.forEach( function ( gloss ) { + result[ gloss.language ] = gloss.value; + } ); + + return result; + } + }( jQuery, mediaWiki ) ); diff --git a/resources/lexeme.css b/resources/lexeme.css index f2ff901..4b31252 100644 --- a/resources/lexeme.css +++ b/resources/lexeme.css @@ -303,18 +303,10 @@ float: left; } -.wikibase-lexeme-sense .wikibase-edittoolbar-container { - display: none; /* TODO: use toolbar or vue buttons */ -} - /* === wikibase-lexeme-sense-glosses === */ .wikibase-lexeme-sense-glosses { - display: flex; -} - -.wikibase-lexeme-sense-glosses-list { - flex-grow: 1; + margin-right: 252px; } .wikibase-lexeme-sense-glosses-table { @@ -345,14 +337,6 @@ .wikibase-lexeme-sense-gloss-value-input { width: 100%; resize: horizontal; -} - -.wikibase-lexeme-sense-glosses-controls { - /* width: 18em; */ - display: flex; - flex-direction: column; - justify-content: flex-start; - align-items: flex-end; } .wikibase-lexeme-sense-glosses-control { diff --git a/resources/view/ControllerViewFactory.js b/resources/view/ControllerViewFactory.js index 60cc706..c553fea 100644 --- a/resources/view/ControllerViewFactory.js +++ b/resources/view/ControllerViewFactory.js @@ -205,6 +205,10 @@ startEditingCallback ); + if ( !sense ) { + controller.startEditing().done( senseView.focus.bind( senseView ) ); + } + return senseView; }; diff --git a/resources/widgets/GlossWidget.js b/resources/widgets/GlossWidget.js index 73d2774..8b432ca 100644 --- a/resources/widgets/GlossWidget.js +++ b/resour