-
Notifications
You must be signed in to change notification settings - Fork 6
Rel1_43 #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Rel1_43 #12
Changes from all commits
750ee37
8b8be88
dadf595
04071f8
9caf3fe
7c1856b
3740583
c4f259a
2523e74
10d40bd
35b1536
7a4d0f0
bf05480
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,11 +4,22 @@ | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| namespace MediaWiki\Extension\SemanticWikibase\EntryPoints; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| use MediaWiki\Revision\RenderedRevision; | ||||||||||||||||||||||||||||||
| use MediaWiki\User\UserIdentity; | ||||||||||||||||||||||||||||||
| use CommentStoreComment; | ||||||||||||||||||||||||||||||
| use Status; | ||||||||||||||||||||||||||||||
| use MediaWiki\MediaWikiServices; | ||||||||||||||||||||||||||||||
| use MediaWiki\TitleFactory; | ||||||||||||||||||||||||||||||
| use MediaWiki\Extension\SemanticWikibase\SemanticWikibase; | ||||||||||||||||||||||||||||||
| use SMW\Services\ServicesFactory as ApplicationFactory; | ||||||||||||||||||||||||||||||
| use SMW\PropertyRegistry; | ||||||||||||||||||||||||||||||
| use SMW\SemanticData; | ||||||||||||||||||||||||||||||
| use SMW\DIWikiPage; | ||||||||||||||||||||||||||||||
| use SMW\StoreFactory; | ||||||||||||||||||||||||||||||
| use SMW\Store; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| use Parser; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| class HookHandlers { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public static function onExtensionRegistration(): void { | ||||||||||||||||||||||||||||||
|
|
@@ -17,18 +28,52 @@ public static function onExtensionRegistration(): void { | |||||||||||||||||||||||||||||
| $smwgNamespacesWithSemanticLinks[WB_NS_PROPERTY] = true; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public static function onParserFirstCallInit( Parser $parser ) { | ||||||||||||||||||||||||||||||
| # getInstance() will call initProperties() which aktivates existing hook onSmwInitProperties() | ||||||||||||||||||||||||||||||
| wfDebug( __METHOD__ . "SWB: onParserFirstCallInit" ); | ||||||||||||||||||||||||||||||
| PropertyRegistry::getInstance(); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public static function onSmwInitProperties( PropertyRegistry $propertyRegistry ): void { | ||||||||||||||||||||||||||||||
| SemanticWikibase::getGlobalInstance()->registerProperties( $propertyRegistry ); | ||||||||||||||||||||||||||||||
| wfDebug( __METHOD__ . "SWB: onSmwInitProperties..." ); | ||||||||||||||||||||||||||||||
| SemanticWikibase::getGlobalInstance()->registerProperties( $propertyRegistry ); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public static function onSmwAddCustomFixedPropertyTables( array &$customFixedProperties, array &$fixedPropertyTablePrefix ): void { | ||||||||||||||||||||||||||||||
| wfDebug( __METHOD__ . "SWB: onSmwAddCustomFixedPropertyTables" ); | ||||||||||||||||||||||||||||||
| SemanticWikibase::getGlobalInstance()->getFixedProperties() | ||||||||||||||||||||||||||||||
| ->registerFixedTables( $customFixedProperties, $fixedPropertyTablePrefix ); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public static function onSmwUpdateDataBefore( Store $store, SemanticData $semanticData ): void { | ||||||||||||||||||||||||||||||
| wfDebug( __METHOD__ . "SWB: onSmwUpdateDataBefore" ); | ||||||||||||||||||||||||||||||
| SemanticWikibase::getGlobalInstance()->getSemanticDataUpdate() | ||||||||||||||||||||||||||||||
| ->run( $semanticData ); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public static function onPageSaveComplete( WikiPage $wikiPage, MediaWiki\User\UserIdentity $user, string $summary, int $flags, MediaWiki\Revision\RevisionRecord $revisionRecord, MediaWiki\Storage\EditResult $editResult ) { | ||||||||||||||||||||||||||||||
| wfDebug( __METHOD__ . "SWB: onPageSaveComplete" ); | ||||||||||||||||||||||||||||||
| // Access the semantic data of the page via the Semantic MediaWiki API | ||||||||||||||||||||||||||||||
| $semanticData = \SMW\MediaWiki\Hooks\ParserHooks::getSemanticDataForPage($wikiPage); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| onSmwUpdateDataBefore(null, $semanticData); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+55
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's see the actual file and the specific lines
cat -n src/EntryPoints/HookHandlers.php | sed -n '50,70p'Repository: ProfessionalWiki/SemanticWikibase Length of output: 1374 🏁 Script executed: # Check if onSmwUpdateDataBefore is defined in the class as static
rg -A 5 'function onSmwUpdateDataBefore' src/EntryPoints/HookHandlers.phpRepository: ProfessionalWiki/SemanticWikibase Length of output: 326 🏁 Script executed: # Search for all function definitions in HookHandlers.php to understand structure
rg -n 'public\s+static\s+function' src/EntryPoints/HookHandlers.phpRepository: ProfessionalWiki/SemanticWikibase Length of output: 927 🏁 Script executed: # Search for ParserHooks class definition
find . -name "*.php" -type f | xargs rg -l "class ParserHooks"Repository: ProfessionalWiki/SemanticWikibase Length of output: 61 🏁 Script executed: # Search for getSemanticDataForPage method
rg -n "getSemanticDataForPage" --type phpRepository: ProfessionalWiki/SemanticWikibase Length of output: 205 🏁 Script executed: # Check if there are any imports or references to SMW\MediaWiki\Hooks\ParserHooks
rg "ParserHooks" src/EntryPoints/HookHandlers.php -A 2 -B 2Repository: ProfessionalWiki/SemanticWikibase Length of output: 354 Fix critical fatal error: missing Line 60 calls Proposed fix public static function onPageSaveComplete( WikiPage $wikiPage, MediaWiki\User\UserIdentity $user, string $summary, int $flags, MediaWiki\Revision\RevisionRecord $revisionRecord, MediaWiki\Storage\EditResult $editResult ) {
wfDebug( __METHOD__ . "SWB: onPageSaveComplete" );
// Access the semantic data of the page via the Semantic MediaWiki API
$semanticData = \SMW\MediaWiki\Hooks\ParserHooks::getSemanticDataForPage($wikiPage);
- onSmwUpdateDataBefore(null, $semanticData);
+ self::onSmwUpdateDataBefore(null, $semanticData);
}📝 Committable suggestion
Suggested change
🧰 Tools🪛 PHPMD (2.15.0)[warning] 55-55: Avoid unused parameters such as '$user'. (undefined) (UnusedFormalParameter) [warning] 55-55: Avoid unused parameters such as '$summary'. (undefined) (UnusedFormalParameter) [warning] 55-55: Avoid unused parameters such as '$flags'. (undefined) (UnusedFormalParameter) [warning] 55-55: Avoid unused parameters such as '$revisionRecord'. (undefined) (UnusedFormalParameter) [warning] 55-55: Avoid unused parameters such as '$editResult'. (undefined) (UnusedFormalParameter) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public static function onMultiContentSave( RenderedRevision $renderedRevision, UserIdentity $user, CommentStoreComment $summary, $flags, Status $hookStatus ) { | ||||||||||||||||||||||||||||||
| wfDebug( __METHOD__ . "SWB: onMultiContentSave" ); | ||||||||||||||||||||||||||||||
| $revision = $renderedRevision->getRevision(); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| $titleFactory = MediaWikiServices::getInstance()->getTitleFactory(); | ||||||||||||||||||||||||||||||
| $title = $titleFactory->newFromLinkTarget($revision->getPageAsLinkTarget()); | ||||||||||||||||||||||||||||||
| wfDebug( __METHOD__ . "SWB: onMultiContentSave...title:".$title ); | ||||||||||||||||||||||||||||||
| $subject = DIWikiPage::newFromTitle( $title ); | ||||||||||||||||||||||||||||||
| #$new_content = $revision->getContent(SlotRecord::MAIN, RevisionRecord::RAW)->getNativeData(); | ||||||||||||||||||||||||||||||
| $semanticData = StoreFactory::getStore()->getSemanticData( DIWikiPage::newFromTitle( $title ) ); | ||||||||||||||||||||||||||||||
| wfDebug( __METHOD__ . "SWB: onMultiContentSave: ".json_encode($semanticData) ); | ||||||||||||||||||||||||||||||
| SemanticWikibase::getGlobalInstance()->getSemanticDataUpdate()->run( $semanticData ); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+63
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant variable and duplicated call.
🔧 Proposed fix to remove dead code public static function onMultiContentSave( RenderedRevision $renderedRevision, UserIdentity $user, CommentStoreComment $summary, $flags, Status $hookStatus ) {
wfDebug( __METHOD__ . "SWB: onMultiContentSave" );
$revision = $renderedRevision->getRevision();
$titleFactory = MediaWikiServices::getInstance()->getTitleFactory();
$title = $titleFactory->newFromLinkTarget($revision->getPageAsLinkTarget());
wfDebug( __METHOD__ . "SWB: onMultiContentSave...title:".$title );
- $subject = DIWikiPage::newFromTitle( $title );
- #$new_content = $revision->getContent(SlotRecord::MAIN, RevisionRecord::RAW)->getNativeData();
- $semanticData = StoreFactory::getStore()->getSemanticData( DIWikiPage::newFromTitle( $title ) );
+ $semanticData = StoreFactory::getStore()->getSemanticData( DIWikiPage::newFromTitle( $title ) );
wfDebug( __METHOD__ . "SWB: onMultiContentSave: ".json_encode($semanticData) );
SemanticWikibase::getGlobalInstance()->getSemanticDataUpdate()->run( $semanticData );
return true;
} 🧰 Tools🪛 PHPMD (2.15.0)[warning] 63-63: Avoid unused parameters such as '$user'. (undefined) (UnusedFormalParameter) [warning] 63-63: Avoid unused parameters such as '$summary'. (undefined) (UnusedFormalParameter) [warning] 63-63: Avoid unused parameters such as '$flags'. (undefined) (UnusedFormalParameter) [warning] 63-63: Avoid unused parameters such as '$hookStatus'. (undefined) (UnusedFormalParameter) [warning] 70-70: Avoid unused local variables such as '$subject'. (undefined) (UnusedLocalVariable) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,28 +8,34 @@ | |
| use SMW\DIWikiPage; | ||
| use SMW\SemanticData; | ||
| use SMWDataItem; | ||
| use SMW\Subobject; | ||
|
|
||
| class SemanticEntity { | ||
|
|
||
| private array $dataItemsPerProperty = []; | ||
| private array $subObjectsPerProperty=[]; | ||
|
|
||
| public function addPropertyValue( string $propertyId, SMWDataItem $dataItem ) { | ||
| $this->dataItemsPerProperty[$propertyId][] = $dataItem; | ||
| public function addPropertyValue( string $NumericPropertyId, SMWDataItem $dataItem ) { | ||
| $this->dataItemsPerProperty[$NumericPropertyId][] = $dataItem; | ||
| } | ||
|
|
||
| public function addSubobject( string $NumericPropertyId, SubObject $subobject ){ | ||
| $this->subObjectsPerProperty[$NumericPropertyId][] = $subobject; | ||
| } | ||
|
|
||
| /** | ||
| * @param string $propertyId | ||
| * @param string $NumericPropertyId | ||
| * @return SMWDataItem[] | ||
| */ | ||
| public function getDataItemsForProperty( string $propertyId ): array { | ||
| return $this->dataItemsPerProperty[$propertyId] ?? []; | ||
| public function getDataItemsForProperty( string $NumericPropertyId ): array { | ||
| return $this->dataItemsPerProperty[$NumericPropertyId] ?? []; | ||
| } | ||
|
|
||
| public function toSemanticData( DIWikiPage $subject ): SemanticData { | ||
| $semanticData = new SemanticData( $subject ); | ||
|
|
||
| foreach ( $this->dataItemsPerProperty as $propertyId => $dataItems ) { | ||
| $property = new DIProperty( $propertyId ); | ||
| foreach ( $this->dataItemsPerProperty as $NumericPropertyId => $dataItems ) { | ||
| $property = new DIProperty( $NumericPropertyId ); | ||
|
|
||
| foreach ( $dataItems as $dataItem ) { | ||
| $semanticData->addPropertyObjectValue( | ||
|
|
@@ -39,6 +45,14 @@ public function toSemanticData( DIWikiPage $subject ): SemanticData { | |
| } | ||
| } | ||
|
|
||
| foreach ( $this->subObjectsPerProperty as $NumericPropertyId => $subobjects ) { | ||
| $property = new DIProperty( $NumericPropertyId ); | ||
|
|
||
| foreach ( $subobjects as $subobject ) { | ||
| $semanticData->addSubobject($subobject); | ||
| } | ||
| } | ||
|
|
||
| return $semanticData; | ||
| } | ||
|
|
||
|
|
@@ -52,9 +66,9 @@ public function functionalMerge( self $entity ): self { | |
| } | ||
|
|
||
| public function add( self $entity ): void { | ||
| foreach ( $entity->dataItemsPerProperty as $propertyId => $dataItems ) { | ||
| foreach ( $entity->dataItemsPerProperty as $NumericPropertyId => $dataItems ) { | ||
| foreach ( $dataItems as $dataItem ) { | ||
| $this->addPropertyValue( $propertyId, $dataItem ); | ||
| $this->addPropertyValue( $NumericPropertyId, $dataItem ); | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
68
to
74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Subobjects are dropped during entity merge.
Suggested fix public function add( self $entity ): void {
foreach ( $entity->dataItemsPerProperty as $NumericPropertyId => $dataItems ) {
foreach ( $dataItems as $dataItem ) {
$this->addPropertyValue( $NumericPropertyId, $dataItem );
}
}
+
+ foreach ( $entity->subObjectsPerProperty as $NumericPropertyId => $subobjects ) {
+ foreach ( $subobjects as $subobject ) {
+ $this->addSubobject( $NumericPropertyId, $subobject );
+ }
+ }
}🤖 Prompt for AI Agents |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
| use SMW\SemanticData; | ||
| use Title; | ||
| use Wikibase\DataModel\Entity\ItemId; | ||
| use Wikibase\DataModel\Entity\PropertyId; | ||
| use Wikibase\DataModel\Entity\NumericPropertyId; | ||
| use Wikibase\DataModel\Services\Lookup\ItemLookup; | ||
| use Wikibase\DataModel\Services\Lookup\PropertyLookup; | ||
|
|
||
|
|
@@ -63,8 +63,13 @@ private function newItemTranslator( Title $title ): ItemTranslator { | |
| } | ||
|
|
||
| private function getSemanticEntityForPropertyTitle( Title $title ): SemanticEntity { | ||
| wfDebug(__METHOD__. "swb: getSemanticEntity:".json_encode($title)); | ||
| wfDebug(__METHOD__. "swb: getSemanticEntity:".json_encode($title->getText())); | ||
| wfDebug(__METHOD__. "swb: getSemanticEntity:".json_encode(new NumericPropertyId( $title->getText() ))); | ||
| wfDebug(__METHOD__. "swb: getSemanticEntity:".json_encode($this->propertyLookup->getPropertyForId( new NumericPropertyId( $title->getText() ) ))); | ||
|
|
||
| return $this->newPropertyTranslator( $title )->translateProperty( | ||
| $this->propertyLookup->getPropertyForId( new PropertyId( $title->getText() ) ) | ||
| $this->propertyLookup->getPropertyForId( new NumericPropertyId( $title->getText() ) ) | ||
| ); | ||
|
Comment on lines
+66
to
73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove temporary debug logging and avoid duplicate property lookups. Lines 66-70 add verbose debug output and perform an extra Suggested cleanup private function getSemanticEntityForPropertyTitle( Title $title ): SemanticEntity {
- wfDebug(__METHOD__. "swb: getSemanticEntity:".json_encode($title));
- wfDebug(__METHOD__. "swb: getSemanticEntity:".json_encode($title->getText()));
- wfDebug(__METHOD__. "swb: getSemanticEntity:".json_encode(new NumericPropertyId( $title->getText() )));
- wfDebug(__METHOD__. "swb: getSemanticEntity:".json_encode($this->propertyLookup->getPropertyForId( new NumericPropertyId( $title->getText() ) )));
-
- return $this->newPropertyTranslator( $title )->translateProperty(
- $this->propertyLookup->getPropertyForId( new NumericPropertyId( $title->getText() ) )
- );
+ $propertyId = new NumericPropertyId( $title->getText() );
+ $property = $this->propertyLookup->getPropertyForId( $propertyId );
+
+ return $this->newPropertyTranslator( $title )->translateProperty( $property );
}🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,15 +62,18 @@ protected function getPropertyTypeLookup(): PropertyDataTypeLookup { | |
| } | ||
|
|
||
| public function registerProperties( PropertyRegistry $propertyRegistry ) { | ||
| wfDebug("SWB: register properties ".json_encode($this->getAllProperties())); | ||
| foreach ( $this->getAllProperties() as $property ) { | ||
| $propertyRegistry->registerProperty( | ||
| $property->getId(), | ||
| $property->getType(), | ||
| $property->getLabel(), | ||
| true, | ||
| false | ||
| true, #is_visible | ||
| true, #is_annotable | ||
| false #is_declarative | ||
| ); | ||
|
|
||
| wfDebug("SWB: register property ".$property->getId()); | ||
| wfDebug("SWB: register property ".$property->getType()); | ||
| foreach ( $property->getAliases() as $alias ) { | ||
|
Comment on lines
+65
to
77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid duplicate property retrieval and remove transient debug logs. Line 65 computes Suggested cleanup public function registerProperties( PropertyRegistry $propertyRegistry ) {
- wfDebug("SWB: register properties ".json_encode($this->getAllProperties()));
- foreach ( $this->getAllProperties() as $property ) {
+ $properties = $this->getAllProperties();
+ foreach ( $properties as $property ) {
$propertyRegistry->registerProperty(
$property->getId(),
$property->getType(),
$property->getLabel(),
true, `#is_visible`
true, `#is_annotable`
false `#is_declarative`
);
- wfDebug("SWB: register property ".$property->getId());
- wfDebug("SWB: register property ".$property->getType());
foreach ( $property->getAliases() as $alias ) {
$propertyRegistry->registerPropertyAlias( $property->getId(), $alias );
}
}
}🤖 Prompt for AI Agents |
||
| $propertyRegistry->registerPropertyAlias( $property->getId(), $alias ); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,14 +19,33 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use Wikibase\DataModel\Entity\EntityId; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use Wikibase\DataModel\Entity\EntityIdValue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use Wikibase\DataModel\Entity\ItemId; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use Wikibase\DataModel\Entity\PropertyId; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use Wikibase\DataModel\Entity\NumericPropertyId; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use Wikibase\EDTF\Services\TimeValueBuilder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use Wikibase\EDTF\EdtfValue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use MediaWiki\Logger\LoggerFactory; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use EDTF\EdtfFactory; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use EDTF\Model\ExtDate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use EDTF\Model\ExtDateTime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use EDTF\Model\Interval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class DataValueTranslator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function translate( TypedDataValue $typedValue ): SMWDataItem { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $value = $typedValue->getValue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $propertyType = $typedValue->getPropertyType(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if( $value != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| wfDebug( 'swb: translate: '.get_class( $value ).' ptype: '.$propertyType ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( $value instanceof StringValue ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| wfDebug( 'swb: translate: '. $typedValue->getValue()->getValue() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if( $propertyType == 'edtf') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $this->translateEDTF("".$value->getValue()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }else if ($propertyType == 'localMedia') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $this->translateLocalMedia("".$value->getValue()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $this->translateStringValue( $typedValue ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( $value instanceof BooleanValue ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -44,10 +63,12 @@ public function translate( TypedDataValue $typedValue ): SMWDataItem { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( $value instanceof GlobeCoordinateValue ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $this->translateGlobeCoordinateValue( $value ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( $value instanceof TimeValue ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $this->translateTimeValue( $value ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new \RuntimeException( 'Support for DataValue type "' . get_class( $value ) . '" not implemented' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -66,6 +87,12 @@ private function translateGlobeCoordinateValue( GlobeCoordinateValue $globeValue | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private function translateLocalMedia( String $imagePage): SMWDataItem { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new DIWikiPage( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $imagePage, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| NS_FILE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private function translateEntityIdValue( EntityIdValue $idValue ): SMWDataItem { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new DIWikiPage( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $idValue->getEntityId()->getSerialization(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -78,7 +105,7 @@ private function entityIdToNamespaceId( EntityId $idValue ): int { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return WB_NS_ITEM; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( $idValue instanceof PropertyId ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( $idValue instanceof NumericPropertyId ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return WB_NS_PROPERTY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -89,6 +116,59 @@ public function translateDecimalValue( DecimalValue $value ): SMWDataItem { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new \SMWDINumber( $value->getValueFloat() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private function translateEDTF( String $value ): \SMWDITime { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| wfDebug( 'swb: translate edtf' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $tvb = new TimeValueBuilder( EdtfFactory::newParser() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $tvArr = $tvb->edtfToTimeValues( $value ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $parser = \EDTF\EdtfFactory::newParser(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $parsingResult = $parser->parse($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| wfDebug($parsingResult->isValid()); // true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $edtfValue = $parsingResult->getEdtfValue(); // \EDTF\EdtfValue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $humanizer = \EDTF\EdtfFactory::newHumanizerForLanguage( 'en' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| wfDebug($humanizer->humanize($edtfValue)); // string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| wfDebug(get_class($edtfValue)); // string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $result = null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( $edtfValue instanceof Interval ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if($edtfValue->hasStartDate()){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $edtfValue = $edtfValue->getStartDate(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if ($edtfValue->hasEndDate()){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $edtfValue = $edtfValue->getEndDate(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| wfDebug('ERROR: unable to translate empty edtf interval to smw date'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+119
to
+141
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type error: Method returns Line 139 returns 🐛 Proposed fix - change return type to nullable- private function translateEDTF( String $value ): \SMWDITime {
+ private function translateEDTF( String $value ): ?\SMWDITime {Additionally, the caller in 📝 Committable suggestion
Suggested change
🧰 Tools🪛 PHPMD (2.15.0)[warning] 122-122: Avoid unused local variables such as '$tvArr'. (undefined) (UnusedLocalVariable) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if( $edtfValue instanceof ExtDate ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $result = new \SMWDITime( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SMWDITime::CM_GREGORIAN, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $edtfValue->getYear(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $edtfValue->getMonth(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $edtfValue->getDay() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if ( $edtfValue instanceof ExtDateTime ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $result = new \SMWDITime( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SMWDITime::CM_GREGORIAN, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $edtfValue->getYear(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $edtfValue->getMonth(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $edtfValue->getDay(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $edtfValue->getHour(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $edtfValue->getMinute(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $edtfValue->getSecond() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $result = new \SMWDITime( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SMWDITime::CM_GREGORIAN, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1970 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+161
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Silent fallback to epoch date (1970) can cause data integrity issues. When Consider logging a warning or throwing an exception for unexpected types. 🔧 Proposed fix } else {
- $result = new \SMWDITime(
- SMWDITime::CM_GREGORIAN,
- 1970
- );
-
+ wfDebug( 'swb: WARNING - Unhandled EDTF type: ' . get_class($edtfValue) . ', falling back to epoch' );
+ $result = new \SMWDITime(
+ SMWDITime::CM_GREGORIAN,
+ 1970
+ );
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private function translateTimeValue( TimeValue $value ): \SMWDITime { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $components = ( new TimeValueParser() )->parse( $value->getTime() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in comment.
Line 32: "aktivates" should be "activates".
📝 Proposed fix
public static function onParserFirstCallInit( Parser $parser ) { - # getInstance() will call initProperties() which aktivates existing hook onSmwInitProperties() + # getInstance() will call initProperties() which activates existing hook onSmwInitProperties() wfDebug( __METHOD__ . "SWB: onParserFirstCallInit" ); PropertyRegistry::getInstance(); }🧰 Tools
🪛 PHPMD (2.15.0)
[warning] 31-31: Avoid unused parameters such as '$parser'. (undefined)
(UnusedFormalParameter)
🤖 Prompt for AI Agents