Bartosz Dziewoński has uploaded a new change for review.

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

Change subject: [WIP] Allow passing detailed permission errors data to API
......................................................................

[WIP] Allow passing detailed permission errors data to API

Using the new system introduced in
1c57794e371d74e1d88748de567a1c3358c3ad2e (see T47843).

This is the simplest thing that worked for my use case.
Not sure how well it will work in general.

Goes with I42a0c5b0ea7e61088dd609b764dd7d1396c60cd5 in TitleBlacklist.

Bug: T115258
Change-Id: I1334ba21a2862973a9d8ff5be2c9bec06a82698b
---
M includes/OutputPage.php
M includes/Title.php
M includes/api/ApiBase.php
M includes/api/ApiUpload.php
4 files changed, 31 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/75/247275/1

diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index d29ec54..86dc1c3 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -2526,19 +2526,22 @@
                        )->plain() . "\n\n";
                }
 
-               if ( count( $errors ) > 1 ) {
-                       $text .= '<ul class="permissions-errors">' . "\n";
-
-                       foreach ( $errors as $error ) {
-                               $text .= '<li>';
-                               $text .= call_user_func_array( array( $this, 
'msg' ), $error )->plain();
-                               $text .= "</li>\n";
+               foreach ( $errors as &$error ) {
+                       if ( $error instanceof MessageSpecifier ) {
+                               $error = $this->msg( $error )->plain();
+                       } else {
+                               $error = call_user_func_array( array( $this, 
'msg' ), $error )->plain();
                        }
-                       $text .= '</ul>';
+               }
+
+               if ( count( $errors ) > 1 ) {
+                       $text .= '<ul class="permissions-errors">' . "\n" .
+                               '<li>' . implode( "</li>\n<li>", $errors ) . 
"</li>\n" .
+                               '</ul>';
                } else {
                        $text .= "<div class=\"permissions-errors\">\n" .
-                                       call_user_func_array( array( $this, 
'msg' ), reset( $errors ) )->plain() .
-                                       "\n</div>";
+                               reset( $errors ) .
+                               "\n</div>";
                }
 
                return $text;
diff --git a/includes/Title.php b/includes/Title.php
index 9ada4f3..4d1813b 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -2048,8 +2048,11 @@
                if ( is_array( $result ) && count( $result ) && !is_array( 
$result[0] ) ) {
                        // A single array representing an error
                        $errors[] = $result;
-               } elseif ( is_array( $result ) && is_array( $result[0] ) ) {
-                       // A nested array representing multiple errors
+               } elseif ( $result instanceof MessageSpecifier ) {
+                       // A single message specifier representing an error
+                       $errors[] = $result;
+               } elseif ( is_array( $result ) && ( is_array( $result[0] ) || 
$result[0] instanceof MessageSpecifier ) ) {
+                       // Array or arrays or message specifiers representing 
multiple errors
                        $errors = array_merge( $errors, $result );
                } elseif ( $result !== '' && is_string( $result ) ) {
                        // A string representing a message-id
diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php
index 1465543..c584ef7 100644
--- a/includes/api/ApiBase.php
+++ b/includes/api/ApiBase.php
@@ -1991,10 +1991,18 @@
 
        /**
         * Return the error message related to a certain array
-        * @param array $error Element of a getUserPermissionsErrors()-style 
array
+        * @param array|IApiMessage $error Element of a 
getUserPermissionsErrors()-style array
         * @return array('code' => code, 'info' => info)
         */
        public function parseMsg( $error ) {
+               if ( $error instanceof IApiMessage ) {
+                       return array(
+                               'code' => $error->getApiCode(),
+                               'info' => $error->text(),
+                               'data' => $error->getApiData()
+                       );
+               }
+
                $error = (array)$error; // It seems strings sometimes make 
their way in here
                $key = array_shift( $error );
 
diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php
index 320649f..a320828 100644
--- a/includes/api/ApiUpload.php
+++ b/includes/api/ApiUpload.php
@@ -363,6 +363,10 @@
                $data['invalidparameter'] = $parameter;
 
                $parsed = $this->parseMsg( $error );
+               if ( isset( $parsed['data'] ) ) {
+                       $data = array_merge( $data, $parsed['data'] );
+               }
+
                $this->dieUsage( $parsed['info'], $parsed['code'], 0, $data );
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1334ba21a2862973a9d8ff5be2c9bec06a82698b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>

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

Reply via email to