Hoo man has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/117219

Change subject: Handle InvalidArgumentException in ClaimHtmlGenerator
......................................................................

Handle InvalidArgumentException in ClaimHtmlGenerator

Bug: 61915
Change-Id: I5e623450a4468f9fc31cf7a85b39f6d812723a98
(cherry picked from commit b9aea256ba7a91fffb2c8c52a25a4e18dede2b91)
---
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/19/117219/1

diff --git a/repo/Wikibase.i18n.php b/repo/Wikibase.i18n.php
index 55d9595..de8cd20 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.',
@@ -704,6 +706,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 3e7e254..bf33c83 100644
--- a/repo/includes/ClaimHtmlGenerator.php
+++ b/repo/includes/ClaimHtmlGenerator.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase;
 
+use InvalidArgumentException;
 use DataValues\DataValue;
 use Wikibase\Lib\FormattingException;
 use Wikibase\Lib\PropertyNotFoundException;
@@ -257,16 +258,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/117219
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: mw1.23-wmf17
Gerrit-Owner: Hoo man <h...@online.de>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to