jenkins-bot has submitted this change and it was merged.

Change subject: Polish error messages
......................................................................


Polish error messages

* Fix the goddamn thing to actually output something sensible
* Add a separate error for missing parameters

Bug: T128551
Change-Id: Ia59561f73e381e633e1b48c8afd93c1ea6a75758
---
M i18n/en.json
M i18n/qqq.json
M includes/Tag/MapFrame.php
M includes/Tag/MapLink.php
M includes/Tag/TagHandler.php
M tests/parserTests.txt
6 files changed, 48 insertions(+), 3 deletions(-)

Approvals:
  Siebrand: Looks good to me, but someone else must approve
  Yurik: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index d602343..931896e 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -10,7 +10,8 @@
        "kartographer-desc": "Allows maps to be added to the wiki pages",
        "kartographer-error-context": "<$1>: $2",
        "kartographer-error-context-multi": "<$1> problems:\n$2",
-       "kartographer-error-bad_attr": "Attribute '$1' has an invalid value",
+       "kartographer-error-missing-attr": "Attribute \"$1\" is missing",
+       "kartographer-error-bad_attr": "Attribute \"$1\" has an invalid value",
        "kartographer-error-bad_data": "The JSON content is not correct",
        "kartographer-tracking-category": "Pages with maps",
        "kartographer-tracking-category-desc": "The page includes a map",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 4ec1002..ebd15ea 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -12,6 +12,7 @@
        "kartographer-desc": 
"{{desc|name=Kartographer|url=https://www.mediawiki.org/wiki/Extension:Kartographer}}";,
        "kartographer-error-context": "General message shown before a single 
specific error\n\nParameters:\n* $1 - tag name, 'mapframe' or 'maplink'\n* $2 - 
error message",
        "kartographer-error-context-multi": "General message shown before 
multiple errors\n\nParameters:\n* $1 - tag name, 'mapframe', 'maplink' or 
'mapdata'\n* $2 - list of errors combined into a bullet list",
+       "kartographer-error-missing-attr": "Error shown instead of a map when 
required parameter(s) is missing.\n\nParameters:\n* $1 - non-localized 
attribute name, such as 'height', 'latitude', etc",
        "kartographer-error-bad_attr": "Error shown instead of a map in case of 
a problem with parameters.\n\nParameters:\n* $1 - non-localized attribute name, 
such as 'height', 'latitude', etc",
        "kartographer-error-bad_data": "This error is shown if the JSON content 
of the tag does not pass validation",
        "kartographer-tracking-category": "Name of the tracking category",
diff --git a/includes/Tag/MapFrame.php b/includes/Tag/MapFrame.php
index e5ea2bc..610bdb4 100644
--- a/includes/Tag/MapFrame.php
+++ b/includes/Tag/MapFrame.php
@@ -11,6 +11,8 @@
  * The <mapframe> tag inserts a map into wiki page
  */
 class MapFrame extends TagHandler {
+       protected $tag = 'mapframe';
+
        private $width;
        private $height;
 
diff --git a/includes/Tag/MapLink.php b/includes/Tag/MapLink.php
index 289cfc6..834365a 100644
--- a/includes/Tag/MapLink.php
+++ b/includes/Tag/MapLink.php
@@ -8,6 +8,7 @@
  * The <maplink> tag creates a link that, when clicked,
  */
 class MapLink extends TagHandler {
+       protected $tag = 'maplink';
 
        protected function parseArgs() {
                $this->parseMapArgs();
diff --git a/includes/Tag/TagHandler.php b/includes/Tag/TagHandler.php
index 29af921..887708f 100644
--- a/includes/Tag/TagHandler.php
+++ b/includes/Tag/TagHandler.php
@@ -9,9 +9,11 @@
 
 namespace Kartographer\Tag;
 
+use Exception;
 use FormatJson;
 use Html;
 use Kartographer\SimpleStyleSanitizer;
+use Message;
 use Parser;
 use ParserOutput;
 use PPFrame;
@@ -22,6 +24,9 @@
  * Base class for all <map...> tags
  */
 abstract class TagHandler {
+       /** @var string */
+       protected $tag;
+
        /** @var Status */
        protected $status;
 
@@ -176,7 +181,7 @@
        protected function getText( $name, $default, $regexp = false ) {
                if ( !isset( $this->args[$name] ) ) {
                        if ( $default === false ) {
-                               $this->status->fatal( 
'kartographer-error-bad_attr', $name );
+                               $this->status->fatal( 
'kartographer-error-missing-attr', $name );
                        }
                        return $default;
                }
@@ -302,7 +307,26 @@
         */
        private function reportError() {
                $this->parser->getOutput()->setExtensionData( 
'kartographer_broken', true );
+               $errors = array_merge( $this->status->getErrorsByType( 'error' 
),
+                       $this->status->getErrorsByType( 'warning' )
+               );
+               if ( !count( $errors ) ) {
+                       throw new Exception( __METHOD__ , '(): attempt to 
report error when none took place' );
+               }
+               $lang = $this->parser->getTitle()->getPageLanguage();
+               $message = count( $errors ) > 1 ? 
'kartographer-error-context-multi'
+                       : 'kartographer-error-context';
+               // Status sucks, redoing a bunch of its code here
+               $errorText = implode( "\n* ", array_map( function( array $err ) 
use ( $lang ) {
+                               return wfMessage( $err['message'] )
+                                       ->params( $err['params'] )
+                                       ->inLanguage( $lang )
+                                       ->plain();
+                       }, $errors ) );
+               if ( count( $errors ) > 1 ) {
+                       $errorText = '* ' . $errorText;
+               }
                return Html::rawElement( 'div', array( 'class' => 
'mw-kartographer mw-kartographer-error' ),
-                       $this->status->getHTML( 'kartographer-error-context', 
'kartographer-error-context-multi' ) );
+                       wfMessage( $message, $this->tag, $errorText 
)->inLanguage( $lang )->parse() );
        }
 }
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index be4e079..6703913 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -86,3 +86,19 @@
 <div class="mw-kartographer mw-kartographer-interactive" mw-data="interface" 
style="width:640px; height:480px;" data-style="osm-intl" data-zoom="13" 
data-lat="10" data-lon="20" data-overlays="[&quot;*&quot;]"></div>
 
 !! end
+
+!! test
+Error messages
+!! input
+<maplink latitude=10 longitude=fail text=Derp>>Derp goes here</maplink>
+<mapframe latitude=10 longitude=20 zoom=13 width=640 height=480 align=crap 
style=derp />
+!! result
+<div class="mw-kartographer mw-kartographer-error"><p>&lt;maplink&gt; problems:
+</p>
+<ul><li> Syntax error</li>
+<li> Attribute "longitude" has an invalid value</li>
+<li> Attribute "zoom" is missing</li></ul>
+</div>
+<div class="mw-kartographer mw-kartographer-error">&lt;mapframe&gt;: Attribute 
"style" has an invalid value</div>
+
+!! end
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/274611
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia59561f73e381e633e1b48c8afd93c1ea6a75758
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/Kartographer
Gerrit-Branch: master
Gerrit-Owner: MaxSem <maxsem.w...@gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: Yurik <yu...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to