Aude has uploaded a new change for review.
https://gerrit.wikimedia.org/r/120530
Change subject: Handle InvalidArgumentException in ClaimHtmlGenerator
......................................................................
Handle InvalidArgumentException in ClaimHtmlGenerator
see also bug 62495, which is to improve the formatting and make it consistent /
reusable by JS
but let's get this into master
Bug: 61915
Change-Id: I5e623450a4468f9fc31cf7a85b39f6d812723a98
(cherry picked from commit b9aea256ba7a91fffb2c8c52a25a4e18dede2b91)
(cherry picked from commit ecd642da3f0ba08e090f9276500c74811ab8f552)
---
M repo/Wikibase.i18n.php
M repo/includes/ClaimHtmlGenerator.php
2 files changed, 28 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/30/120530/1
diff --git a/repo/Wikibase.i18n.php b/repo/Wikibase.i18n.php
index 0aec76b..4f8baa2 100644
--- a/repo/Wikibase.i18n.php
+++ b/repo/Wikibase.i18n.php
@@ -93,6 +93,8 @@
'wikibase-snakview-snaktypeselector-value' => 'custom value',
'wikibase-snakview-snaktypeselector-somevalue' => 'unknown value',
'wikibase-snakview-snaktypeselector-novalue' => 'no value',
+ 'wikibase-snakformat-invalid-value' => 'Invalid value.',
+ 'wikibase-snakformat-propertynotfound' => 'Property not found.',
'wikibase-shortcopyrightwarning' => 'By clicking "$1", you agree to the
[[$2|terms of use]], and you irrevocably agree to release your contribution
under the $3.',
'wikibase-shortcopyrightwarning-version' => 'wikibase-1', # do not
translate or duplicate this message to other languages
'wikibase-copyrighttooltip-acknowledge' => 'I accept these terms for my
future edits. Do not show this message again.',
@@ -671,6 +673,8 @@
'wikibase-snakview-snaktypeselector-value' => "Short descriptive title
of a 'value' snak (see [[d:Wikidata:Glossary]]) used in a drop-down menu
allowing to select the snak type when adding or editing a snak. The drop-down
menu can be opened by clicking an anchor right next to the input element(s)
used to specify a claim's value. Although this is regarded a 'special', seldom
used feature, the term 'snak' should be avoided here since the concept of snaks
is a technical abstraction that does not give any additional meaning within the
user interface. The basic meaning of this option - which is the default when
adding a claim - is allowing the user to specify a value.",
'wikibase-snakview-snaktypeselector-somevalue' => "Short descriptive
title of a some-value snak (see [[d:Wikidata:Glossary]]) used in a drop-down
menu allowing to select the snak type when adding or editing a snak. The
drop-down menu can be opened by clicking an anchor right next to the input
element(s) used to specify a claim's value. Although this is regarded a
'special', seldom used feature, the term 'snak' should be avoided here since
the concept of snaks is a technical abstraction that does not give any
additional meaning within the user interface. The basic meaning of this option
is that a value exists but it is unknown.",
'wikibase-snakview-snaktypeselector-novalue' => "A short descriptive
title of a no-value snak (see [[d:Wikidata:Glossary]]) used in a drop-down menu
allowing to select the snak type when adding or editing a snak. The drop-down
menu can be opened by clicking an anchor right next to the input element(s)
used to specify a claim's value. Although this is regarded a 'special', seldom
used feature, the term 'snak' should be avoided here since the concept of snaks
is a technical abstraction that does not give any additional meaning within the
user interface. The basic meaning of this option is that no value exists.",
+ 'wikibase-snakformat-invalid-value' => 'Error message displayed on item
page for property value that has an invalid or mismatching property type and
cannot be displayed.',
+ 'wikibase-snakformat-propertynotfound' => 'Error message displayed on
item page for snak with a property that cannot be found.',
'wikibase-shortcopyrightwarning' => 'A short copyright warning
displayed during editing in the JavaScript UI. The copyright warning is
displayed within a tooltip next to the save button.
Parameters:
diff --git a/repo/includes/ClaimHtmlGenerator.php
b/repo/includes/ClaimHtmlGenerator.php
index 6c13b76..a1448bf 100644
--- a/repo/includes/ClaimHtmlGenerator.php
+++ b/repo/includes/ClaimHtmlGenerator.php
@@ -2,6 +2,7 @@
namespace Wikibase;
+use InvalidArgumentException;
use Wikibase\Lib\FormattingException;
use Wikibase\Lib\PropertyNotFoundException;
use Wikibase\Lib\Serializers\ClaimSerializer;
@@ -259,16 +260,36 @@
}
/**
+ * @fixme handle errors more consistently as done in JS UI
+ *
* @param Snak $snak
* @return string
*/
protected function getFormattedSnakValue( $snak ) {
try {
- return $this->snakFormatter->formatSnak( $snak );
+ $formattedSnak = $this->snakFormatter->formatSnak(
$snak );
} catch ( FormattingException $ex ) {
- return '?'; // XXX: perhaps show error message?
+ return $this->getInvalidSnakMessage();
} catch ( PropertyNotFoundException $ex ) {
- return '?'; // XXX: perhaps show error message?
+ return $this->getPropertyNotFoundMessage();
+ } catch ( InvalidArgumentException $ex ) {
+ return $this->getInvalidSnakMessage();
}
+
+ return $formattedSnak;
+ }
+
+ /**
+ * @return string
+ */
+ private function getInvalidSnakMessage() {
+ return wfMessage( 'wikibase-snakformat-invalid-value'
)->parse();
+ }
+
+ /**
+ * @return string
+ */
+ private function getPropertyNotFoundMessage() {
+ return wfMessage ( 'wikibase-snakformat-propertynotfound'
)->parse();
}
}
--
To view, visit https://gerrit.wikimedia.org/r/120530
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5e623450a4468f9fc31cf7a85b39f6d812723a98
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits