Page Menu
Home
GitPull.it
Search
Configure Global Search
Log In
Files
F12582860
D125.1775833508.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D125.1775833508.diff
View Options
diff --git a/include/wb/DataValueQuantity.php b/include/wb/DataValueQuantity.php
--- a/include/wb/DataValueQuantity.php
+++ b/include/wb/DataValueQuantity.php
@@ -1,6 +1,7 @@
<?php
# Boz-MW - Another MediaWiki API handler in PHP
-# Copyright (C) 2018 Valerio Bozzolan
+# Copyright (C) 2018-2023 Valerio Bozzolan
+# Copyright (C) 2023 Luca Mauri
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@@ -30,10 +31,16 @@
* @param $lower_bound mixed The $value at its minimum error e.g. -1
*/
public function __construct( $amount, $wikidata_unit_id, $upper_bound = null, $lower_bound = null ) {
- $value = [
- 'amount' => self::sign( $amount ),
- 'unit' => "http://www.wikidata.org/entity/$wikidata_unit_id"
- ];
+ $value = [];
+
+ // if the Wikidata unit ID is not specified, just "1"
+ // if that is NOT a Q-ID, just "1" too
+ if (($wikidata_unit_id === null) || (strtoupper(substr($wikidata_unit_id, 0, 1)) !== 'Q')) {
+ $value['unit'] = '1';
+ } else {
+ $value['unit'] = "http://www.wikidata.org/entity/$wikidata_unit_id";
+ }
+
if( null !== $upper_bound ) {
$value['upperBound'] = self::int2string( $upper_bound );
}
diff --git a/include/wb/SnakQuantity.php b/include/wb/SnakQuantity.php
--- a/include/wb/SnakQuantity.php
+++ b/include/wb/SnakQuantity.php
@@ -1,6 +1,7 @@
<?php
# Boz-MW - Another MediaWiki API handler in PHP
-# Copyright (C) 2018 Valerio Bozzolan
+# Copyright (C) 2018-2023 Valerio Bozzolan
+# Copyright (C) 2023 Luca Mauri
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@@ -24,8 +25,11 @@
class SnakQuantity extends Snak {
/**
- * @param $property string Wikidata property as 'P123'
- * @param $value string
+ * @param $property string Property as 'P123'
+ * @param $value mixed amount Any number e.g. 0
+ * @param $wikidata_unit_id string Wikidata ID of a unit e.g. 'Q11573' for metre
+ * @param $upper_bound mixed The $value at its maximum error e.g. +1
+ * @param $lower_bound mixed The $value at its minimum error e.g. -1
*/
public function __construct( $property, $amount, $unit, $upper_bound = null, $lower_bound = null ) {
return parent::__construct(
diff --git a/include/wb/StatementQuantity.php b/include/wb/StatementQuantity.php
--- a/include/wb/StatementQuantity.php
+++ b/include/wb/StatementQuantity.php
@@ -1,6 +1,7 @@
<?php
# Boz-MW - Another MediaWiki API handler in PHP
-# Copyright (C) 2018 Valerio Bozzolan
+# Copyright (C) 2018-2023 Valerio Bozzolan
+# Copyright (C) 2023 Luca Mauri
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@@ -19,7 +20,7 @@
namespace wb;
/**
- * A StatementString is a Statement that contains a SnakString.
+ * A StatementQuantity is a Statement that contains a SnakQuantity.
*/
class StatementQuantity extends Statement {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 10, 17:05 (22 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1830515
Default Alt Text
D125.1775833508.diff (3 KB)
Attached To
Mode
D125: Update DataValueQuantity to work without a unit (for non-Wikidata Wikibases)
Attached
Detach File
Event Timeline
Log In to Comment