Umherirrender has uploaded a new change for review.

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


Change subject: API: Add new type 'language'
......................................................................

API: Add new type 'language'

Working the same way than 'namespace' by override the type to a array of
the valid values and use the existing validation code.

Using the new type in some modules

Change-Id: I03008949d964dc7a122e2fce2deae19c997887d0
---
M includes/api/ApiBase.php
M includes/api/ApiCreateAccount.php
M includes/api/ApiParse.php
M includes/api/ApiQueryAllMessages.php
M includes/api/ApiQuerySiteinfo.php
M includes/api/ApiWatch.php
6 files changed, 31 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/47/57047/1

diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php
index 741e908..39b7e6f 100644
--- a/includes/api/ApiBase.php
+++ b/includes/api/ApiBase.php
@@ -444,6 +444,13 @@
                                                                        100, 
$descWordwrap );
                                                                
$hintPipeSeparated = false;
                                                                break;
+                                                       case 'language':
+                                                               $langCodes = 
array_keys( Language::fetchLanguageNames( null, 'all' ) );
+                                                               sort( 
$langCodes );
+                                                               $desc .= 
$paramPrefix . $prompt;
+                                                               $desc .= 
wordwrap( implode( ', ', $langCodes ),
+                                                                       100, 
$descWordwrap );
+                                                               break;
                                                        case 'limit':
                                                                $desc .= 
$paramPrefix . "No more than {$paramSettings[self :: PARAM_MAX]}";
                                                                if ( isset( 
$paramSettings[self::PARAM_MAX2] ) ) {
@@ -945,8 +952,15 @@
                } else {
                        $value = $this->getMain()->getVal( $encParamName, 
$default );
 
-                       if ( isset( $value ) && $type == 'namespace' ) {
-                               $type = MWNamespace::getValidNamespaces();
+                       if ( isset( $value ) ) {
+                               switch( $type ) {
+                                       case 'namespace':
+                                               $type = 
MWNamespace::getValidNamespaces();
+                                               break;
+                                       case 'language':
+                                               $type = 
Language::fetchLanguageNames( null, 'all' );
+                                               break;
+                               }
                        }
                }
 
diff --git a/includes/api/ApiCreateAccount.php 
b/includes/api/ApiCreateAccount.php
index a521346..a3c8d90 100644
--- a/includes/api/ApiCreateAccount.php
+++ b/includes/api/ApiCreateAccount.php
@@ -194,7 +194,9 @@
                                ApiBase::PARAM_DFLT => false
                        ),
                        'reason' => null,
-                       'language' => null
+                       'language' => array(
+                               ApiBase::PARAM_TYPE => 'language',
+                       ),
                );
        }
 
diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php
index 09b7a88..306cab6 100644
--- a/includes/api/ApiParse.php
+++ b/includes/api/ApiParse.php
@@ -575,7 +575,9 @@
                        ),
                        'pst' => false,
                        'onlypst' => false,
-                       'uselang' => null,
+                       'uselang' => array(
+                               ApiBase::PARAM_TYPE => 'language',
+                       ),
                        'section' => null,
                        'disablepp' => false,
                        'generatexml' => false,
diff --git a/includes/api/ApiQueryAllMessages.php 
b/includes/api/ApiQueryAllMessages.php
index c9811b0..5978106 100644
--- a/includes/api/ApiQueryAllMessages.php
+++ b/includes/api/ApiQueryAllMessages.php
@@ -40,8 +40,6 @@
 
                if ( is_null( $params['lang'] ) ) {
                        $langObj = $this->getLanguage();
-               } elseif ( !Language::isValidCode( $params['lang'] ) ) {
-                       $this->dieUsage( 'Invalid language code for parameter 
lang', 'invalidlang' );
                } else {
                        $langObj = Language::factory( $params['lang'] );
                }
@@ -228,7 +226,9 @@
                                        'unmodified'
                                )
                        ),
-                       'lang' => null,
+                       'lang' => array(
+                               ApiBase::PARAM_TYPE => 'language',
+                       ),
                        'from' => null,
                        'to' => null,
                        'title' => null,
@@ -255,12 +255,6 @@
                        'from' => 'Return messages starting at this message',
                        'to' => 'Return messages ending at this message',
                );
-       }
-
-       public function getPossibleErrors() {
-               return array_merge( parent::getPossibleErrors(), array(
-                       array( 'code' => 'invalidlang', 'info' => 'Invalid 
language code for parameter lang' ),
-               ) );
        }
 
        public function getResultProperties() {
diff --git a/includes/api/ApiQuerySiteinfo.php 
b/includes/api/ApiQuerySiteinfo.php
index f79083e..0838eb5 100644
--- a/includes/api/ApiQuerySiteinfo.php
+++ b/includes/api/ApiQuerySiteinfo.php
@@ -646,7 +646,9 @@
                        ),
                        'showalldb' => false,
                        'numberingroup' => false,
-                       'inlanguagecode' => null,
+                       'inlanguagecode' => array(
+                               ApiBase::PARAM_TYPE => 'language',
+                       ),
                );
        }
 
diff --git a/includes/api/ApiWatch.php b/includes/api/ApiWatch.php
index 3e51299..fe4822a 100644
--- a/includes/api/ApiWatch.php
+++ b/includes/api/ApiWatch.php
@@ -97,7 +97,9 @@
                                ApiBase::PARAM_REQUIRED => true
                        ),
                        'unwatch' => false,
-                       'uselang' => null,
+                       'uselang' => array(
+                               ApiBase::PARAM_TYPE => 'language',
+                       ),
                        'token' => array(
                                ApiBase::PARAM_TYPE => 'string',
                                ApiBase::PARAM_REQUIRED => true

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I03008949d964dc7a122e2fce2deae19c997887d0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>

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

Reply via email to