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

Change subject: Add message parameters to API response
......................................................................


Add message parameters to API response

We previously added the message key as .message property
(97b433286dc086ea5261b1b88736600b5454887f), leaving it for the API
client to know what the parameters are and how to get them.
(Here, the parameters are the .line property and the page title.)

Let's just do this work for the client, so that it doesn't have to
know what TitleBlacklist is - it'll be able to just display the given
message with the given parameters. My specific use case is the upload
dialog in core (core shouldn't have to know about any extensions).

See also AbuseFilter change I5780eae96930211191ecd874aacf53fdacb58f89.

Change-Id: I97c1f5c6bbbdfc0b8ea9914bb075d5299c14df8f
---
M TitleBlacklist.hooks.php
1 file changed, 18 insertions(+), 2 deletions(-)

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



diff --git a/TitleBlacklist.hooks.php b/TitleBlacklist.hooks.php
index 7d6d89b..9a5f260 100644
--- a/TitleBlacklist.hooks.php
+++ b/TitleBlacklist.hooks.php
@@ -53,6 +53,11 @@
                        $blacklisted = TitleBlacklist::singleton()->userCannot( 
$title, $user, $action );
                        if ( $blacklisted instanceof TitleBlacklistEntry ) {
                                $errmsg = $blacklisted->getErrorMessage( 'edit' 
);
+                               $params = array(
+                                       $blacklisted->getRaw(),
+                                       $title->getFullText()
+                               );
+                               ApiResult::setIndexedTagName( $params, 'param' 
);
                                $result = ApiMessage::create(
                                        wfMessage(
                                                $errmsg,
@@ -61,7 +66,10 @@
                                        ),
                                        'titleblacklist-forbidden',
                                        array(
-                                               'message' => $errmsg,
+                                               'message' => array(
+                                                       'key' => $errmsg,
+                                                       'params' => $params,
+                                               ),
                                                'line' => 
$blacklisted->getRaw(),
                                                // As $errmsg usually 
represents a non-default message here, and ApiBase uses
                                                // ->inLanguage( 'en' 
)->useDatabase( false ) for all messages, it will never result in
@@ -175,11 +183,19 @@
                                self::logFilterHitUsername( $creatingUser, 
$title, $blacklisted->getRaw() );
                        }
                        $message = $blacklisted->getErrorMessage( 'new-account' 
);
+                       $params = [
+                               $blacklisted->getRaw(),
+                               $userName,
+                       ];
+                       ApiResult::setIndexedTagName( $params, 'param' );
                        return StatusValue::newFatal( ApiMessage::create(
                                [ $message, $blacklisted->getRaw(), $userName ],
                                'titleblacklist-forbidden',
                                [
-                                       'message' => $message,
+                                       'message' => [
+                                               'key' => $message,
+                                               'params' => $params,
+                                       ],
                                        'line' => $blacklisted->getRaw(),
                                        // The text of the message probably 
isn't useful API info, so do this instead
                                        'info' => 'TitleBlacklist prevents this 
username from being created',

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I97c1f5c6bbbdfc0b8ea9914bb075d5299c14df8f
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/TitleBlacklist
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to