Merge "Remove unused 'XMPGetInfo' and 'XMPGetResults' hooks"
[lhc/web/wiklou.git] / includes / api / ApiQuerySiteinfo.php
index d4f7e6a..1dc9985 100644 (file)
@@ -150,24 +150,17 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $allowFrom = array( '' );
                $allowException = true;
                if ( !$config->get( 'AllowExternalImages' ) ) {
-                       if ( $config->get( 'EnableImageWhitelist' ) ) {
-                               $data['imagewhitelistenabled'] = '';
-                       }
+                       $data['imagewhitelistenabled'] = (bool)$config->get( 'EnableImageWhitelist' );
                        $allowFrom = $config->get( 'AllowExternalImagesFrom' );
                        $allowException = !empty( $allowFrom );
                }
                if ( $allowException ) {
                        $data['externalimages'] = (array)$allowFrom;
-                       $this->getResult()->setIndexedTagName( $data['externalimages'], 'prefix' );
+                       ApiResult::setIndexedTagName( $data['externalimages'], 'prefix' );
                }
 
-               if ( !$config->get( 'DisableLangConversion' ) ) {
-                       $data['langconversion'] = '';
-               }
-
-               if ( !$config->get( 'DisableTitleConversion' ) ) {
-                       $data['titleconversion'] = '';
-               }
+               $data['langconversion'] = !$config->get( 'DisableLangConversion' );
+               $data['titleconversion'] = !$config->get( 'DisableTitleConversion' );
 
                if ( $wgContLang->linkPrefixExtension() ) {
                        $linkPrefixCharset = $wgContLang->linkPrefixCharset();
@@ -180,13 +173,10 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                }
 
                $linktrail = $wgContLang->linkTrail();
-               if ( $linktrail ) {
-                       $data['linktrail'] = $linktrail;
-               } else {
-                       $data['linktrail'] = '';
-               }
+               $data['linktrail'] = $linktrail ?: '';
 
                $data['legaltitlechars'] = Title::legalChars();
+               $data['invalidusernamechars'] = $config->get( 'InvalidUsernameCharacters' );
 
                global $IP;
                $git = SpecialVersion::getGitHeadSha1( $IP );
@@ -210,7 +200,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        $fallbacks[] = array( 'code' => $code );
                }
                $data['fallback'] = $fallbacks;
-               $this->getResult()->setIndexedTagName( $data['fallback'], 'lang' );
+               ApiResult::setIndexedTagName( $data['fallback'], 'lang' );
 
                if ( $wgContLang->hasVariants() ) {
                        $variants = array();
@@ -221,21 +211,17 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                );
                        }
                        $data['variants'] = $variants;
-                       $this->getResult()->setIndexedTagName( $data['variants'], 'lang' );
+                       ApiResult::setIndexedTagName( $data['variants'], 'lang' );
                }
 
-               if ( $wgContLang->isRTL() ) {
-                       $data['rtl'] = '';
-               }
+               $data['rtl'] = $wgContLang->isRTL();
                $data['fallback8bitEncoding'] = $wgContLang->fallback8bitEncoding();
 
-               if ( wfReadOnly() ) {
-                       $data['readonly'] = '';
+               $data['readonly'] = wfReadOnly();
+               if ( $data['readonly'] ) {
                        $data['readonlyreason'] = wfReadOnlyReason();
                }
-               if ( $config->get( 'EnableWriteAPI' ) ) {
-                       $data['writeapi'] = '';
-               }
+               $data['writeapi'] = (bool)$config->get( 'EnableWriteAPI' );
 
                $tz = $config->get( 'Localtimezone' );
                $offset = $config->get( 'LocalTZoffset' );
@@ -251,21 +237,22 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $data['scriptpath'] = $config->get( 'ScriptPath' );
                $data['script'] = $config->get( 'Script' );
                $data['variantarticlepath'] = $config->get( 'VariantArticlePath' );
+               $data[ApiResult::META_BC_BOOLS][] = 'variantarticlepath';
                $data['server'] = $config->get( 'Server' );
                $data['servername'] = $config->get( 'ServerName' );
                $data['wikiid'] = wfWikiID();
                $data['time'] = wfTimestamp( TS_ISO_8601, time() );
 
-               if ( $config->get( 'MiserMode' ) ) {
-                       $data['misermode'] = '';
-               }
+               $data['misermode'] = (bool)$config->get( 'MiserMode' );
 
                $data['maxuploadsize'] = UploadBase::getMaxUploadSize();
 
                $data['thumblimits'] = $config->get( 'ThumbLimits' );
-               $this->getResult()->setIndexedTagName( $data['thumblimits'], 'limit' );
+               ApiResult::setArrayType( $data['thumblimits'], 'BCassoc' );
+               ApiResult::setIndexedTagName( $data['thumblimits'], 'limit' );
                $data['imagelimits'] = array();
-               $this->getResult()->setIndexedTagName( $data['imagelimits'], 'limit' );
+               ApiResult::setArrayType( $data['imagelimits'], 'BCassoc' );
+               ApiResult::setIndexedTagName( $data['imagelimits'], 'limit' );
                foreach ( $config->get( 'ImageLimits' ) as $k => $limit ) {
                        $data['imagelimits'][$k] = array( 'width' => $limit[0], 'height' => $limit[1] );
                }
@@ -284,30 +271,25 @@ class ApiQuerySiteinfo extends ApiQueryBase {
 
        protected function appendNamespaces( $property ) {
                global $wgContLang;
-               $data = array();
+               $data = array(
+                       ApiResult::META_TYPE => 'assoc',
+               );
                foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
                        $data[$ns] = array(
                                'id' => intval( $ns ),
                                'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
                        );
-                       ApiResult::setContent( $data[$ns], $title );
+                       ApiResult::setContentValue( $data[$ns], 'name', $title );
                        $canonical = MWNamespace::getCanonicalName( $ns );
 
-                       if ( MWNamespace::hasSubpages( $ns ) ) {
-                               $data[$ns]['subpages'] = '';
-                       }
+                       $data[$ns]['subpages'] = MWNamespace::hasSubpages( $ns );
 
                        if ( $canonical ) {
                                $data[$ns]['canonical'] = strtr( $canonical, '_', ' ' );
                        }
 
-                       if ( MWNamespace::isContent( $ns ) ) {
-                               $data[$ns]['content'] = '';
-                       }
-
-                       if ( MWNamespace::isNonincludable( $ns ) ) {
-                               $data[$ns]['nonincludable'] = '';
-                       }
+                       $data[$ns]['content'] = MWNamespace::isContent( $ns );
+                       $data[$ns]['nonincludable'] = MWNamespace::isNonincludable( $ns );
 
                        $contentmodel = MWNamespace::getNamespaceContentModel( $ns );
                        if ( $contentmodel ) {
@@ -315,7 +297,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        }
                }
 
-               $this->getResult()->setIndexedTagName( $data, 'ns' );
+               ApiResult::setIndexedTagName( $data, 'ns' );
 
                return $this->getResult()->addValue( 'query', $property, $data );
        }
@@ -334,13 +316,13 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        $item = array(
                                'id' => intval( $ns )
                        );
-                       ApiResult::setContent( $item, strtr( $title, '_', ' ' ) );
+                       ApiResult::setContentValue( $item, 'alias', strtr( $title, '_', ' ' ) );
                        $data[] = $item;
                }
 
                sort( $data );
 
-               $this->getResult()->setIndexedTagName( $data, 'ns' );
+               ApiResult::setIndexedTagName( $data, 'ns' );
 
                return $this->getResult()->addValue( 'query', $property, $data );
        }
@@ -352,11 +334,11 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                foreach ( SpecialPageFactory::getNames() as $specialpage ) {
                        if ( isset( $aliases[$specialpage] ) ) {
                                $arr = array( 'realname' => $specialpage, 'aliases' => $aliases[$specialpage] );
-                               $this->getResult()->setIndexedTagName( $arr['aliases'], 'alias' );
+                               ApiResult::setIndexedTagName( $arr['aliases'], 'alias' );
                                $data[] = $arr;
                        }
                }
-               $this->getResult()->setIndexedTagName( $data, 'specialpage' );
+               ApiResult::setIndexedTagName( $data, 'specialpage' );
 
                return $this->getResult()->addValue( 'query', $property, $data );
        }
@@ -367,13 +349,11 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                foreach ( $wgContLang->getMagicWords() as $magicword => $aliases ) {
                        $caseSensitive = array_shift( $aliases );
                        $arr = array( 'name' => $magicword, 'aliases' => $aliases );
-                       if ( $caseSensitive ) {
-                               $arr['case-sensitive'] = '';
-                       }
-                       $this->getResult()->setIndexedTagName( $arr['aliases'], 'alias' );
+                       $arr['case-sensitive'] = (bool)$caseSensitive;
+                       ApiResult::setIndexedTagName( $arr['aliases'], 'alias' );
                        $data[] = $arr;
                }
-               $this->getResult()->setIndexedTagName( $data, 'magicword' );
+               ApiResult::setIndexedTagName( $data, 'magicword' );
 
                return $this->getResult()->addValue( 'query', $property, $data );
        }
@@ -402,20 +382,20 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        $val = array();
                        $val['prefix'] = $prefix;
                        if ( isset( $row['iw_local'] ) && $row['iw_local'] == '1' ) {
-                               $val['local'] = '';
+                               $val['local'] = true;
                        }
                        if ( isset( $row['iw_trans'] ) && $row['iw_trans'] == '1' ) {
-                               $val['trans'] = '';
+                               $val['trans'] = true;
                        }
 
                        if ( isset( $langNames[$prefix] ) ) {
                                $val['language'] = $langNames[$prefix];
                        }
                        if ( in_array( $prefix, $localInterwikis ) ) {
-                               $val['localinterwiki'] = '';
+                               $val['localinterwiki'] = true;
                        }
                        if ( in_array( $prefix, $extraLangPrefixes ) ) {
-                               $val['extralanglink'] = '';
+                               $val['extralanglink'] = true;
 
                                $linktext = wfMessage( "interlanguage-link-$prefix" );
                                if ( !$linktext->isDisabled() ) {
@@ -429,9 +409,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        }
 
                        $val['url'] = wfExpandUrl( $row['iw_url'], PROTO_CURRENT );
-                       if ( substr( $row['iw_url'], 0, 2 ) == '//' ) {
-                               $val['protorel'] = '';
-                       }
+                       $val['protorel'] = substr( $row['iw_url'], 0, 2 ) == '//';
                        if ( isset( $row['iw_wikiid'] ) && $row['iw_wikiid'] !== '' ) {
                                $val['wikiid'] = $row['iw_wikiid'];
                        }
@@ -442,7 +420,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        $data[] = $val;
                }
 
-               $this->getResult()->setIndexedTagName( $data, 'iw' );
+               ApiResult::setIndexedTagName( $data, 'iw' );
 
                return $this->getResult()->addValue( 'query', $property, $data );
        }
@@ -477,7 +455,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                }
 
                $result = $this->getResult();
-               $result->setIndexedTagName( $data, 'db' );
+               ApiResult::setIndexedTagName( $data, 'db' );
 
                return $this->getResult()->addValue( 'query', $property, $data );
        }
@@ -533,16 +511,16 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                        $groups = array_intersect( $rights[$group], $allGroups );
                                        if ( $groups ) {
                                                $arr[$type] = $groups;
-                                               $result->setIndexedTagName( $arr[$type], 'group' );
+                                               ApiResult::setIndexedTagName( $arr[$type], 'group' );
                                        }
                                }
                        }
 
-                       $result->setIndexedTagName( $arr['rights'], 'permission' );
+                       ApiResult::setIndexedTagName( $arr['rights'], 'permission' );
                        $data[] = $arr;
                }
 
-               $result->setIndexedTagName( $data, 'group' );
+               ApiResult::setIndexedTagName( $data, 'group' );
 
                return $result->addValue( 'query', $property, $data );
        }
@@ -552,7 +530,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                foreach ( array_unique( $this->getConfig()->get( 'FileExtensions' ) ) as $ext ) {
                        $data[] = array( 'ext' => $ext );
                }
-               $this->getResult()->setIndexedTagName( $data, 'fe' );
+               ApiResult::setIndexedTagName( $data, 'fe' );
 
                return $this->getResult()->addValue( 'query', $property, $data );
        }
@@ -581,7 +559,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                'version' => $info['version'],
                        );
                }
-               $this->getResult()->setIndexedTagName( $data, 'library' );
+               ApiResult::setIndexedTagName( $data, 'library' );
 
                return $this->getResult()->addValue( 'query', $property, $data );
 
@@ -607,7 +585,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                        if ( is_array( $ext['descriptionmsg'] ) ) {
                                                $ret['descriptionmsg'] = $ext['descriptionmsg'][0];
                                                $ret['descriptionmsgparams'] = array_slice( $ext['descriptionmsg'], 1 );
-                                               $this->getResult()->setIndexedTagName( $ret['descriptionmsgparams'], 'param' );
+                                               ApiResult::setIndexedTagName( $ret['descriptionmsgparams'], 'param' );
                                        } else {
                                                $ret['descriptionmsg'] = $ext['descriptionmsg'];
                                        }
@@ -667,7 +645,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        }
                }
 
-               $this->getResult()->setIndexedTagName( $data, 'ext' );
+               ApiResult::setIndexedTagName( $data, 'ext' );
 
                return $this->getResult()->addValue( 'query', $property, $data );
        }
@@ -704,10 +682,10 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        'semiprotectedlevels' => $config->get( 'SemiprotectedRestrictionLevels' ),
                );
 
-               $this->getResult()->setIndexedTagName( $data['types'], 'type' );
-               $this->getResult()->setIndexedTagName( $data['levels'], 'level' );
-               $this->getResult()->setIndexedTagName( $data['cascadinglevels'], 'level' );
-               $this->getResult()->setIndexedTagName( $data['semiprotectedlevels'], 'level' );
+               ApiResult::setIndexedTagName( $data['types'], 'type' );
+               ApiResult::setIndexedTagName( $data['levels'], 'level' );
+               ApiResult::setIndexedTagName( $data['cascadinglevels'], 'level' );
+               ApiResult::setIndexedTagName( $data['semiprotectedlevels'], 'level' );
 
                return $this->getResult()->addValue( 'query', $property, $data );
        }
@@ -721,10 +699,10 @@ class ApiQuerySiteinfo extends ApiQueryBase {
 
                foreach ( $langNames as $code => $name ) {
                        $lang = array( 'code' => $code );
-                       ApiResult::setContent( $lang, $name );
+                       ApiResult::setContentValue( $lang, 'name', $name );
                        $data[] = $lang;
                }
-               $this->getResult()->setIndexedTagName( $data, 'lang' );
+               ApiResult::setIndexedTagName( $data, 'lang' );
 
                return $this->getResult()->addValue( 'query', $property, $data );
        }
@@ -745,16 +723,16 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                $displayName = $msg->text();
                        }
                        $skin = array( 'code' => $name );
-                       ApiResult::setContent( $skin, $displayName );
+                       ApiResult::setContentValue( $skin, 'name', $displayName );
                        if ( !isset( $allowed[$name] ) ) {
-                               $skin['unusable'] = '';
+                               $skin['unusable'] = true;
                        }
                        if ( $name === $default ) {
-                               $skin['default'] = '';
+                               $skin['default'] = true;
                        }
                        $data[] = $skin;
                }
-               $this->getResult()->setIndexedTagName( $data, 'skin' );
+               ApiResult::setIndexedTagName( $data, 'skin' );
 
                return $this->getResult()->addValue( 'query', $property, $data );
        }
@@ -763,7 +741,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                global $wgParser;
                $wgParser->firstCallInit();
                $tags = array_map( array( $this, 'formatParserTags' ), $wgParser->getTags() );
-               $this->getResult()->setIndexedTagName( $tags, 't' );
+               ApiResult::setIndexedTagName( $tags, 't' );
 
                return $this->getResult()->addValue( 'query', $property, $tags );
        }
@@ -772,14 +750,14 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                global $wgParser;
                $wgParser->firstCallInit();
                $hooks = $wgParser->getFunctionHooks();
-               $this->getResult()->setIndexedTagName( $hooks, 'h' );
+               ApiResult::setIndexedTagName( $hooks, 'h' );
 
                return $this->getResult()->addValue( 'query', $property, $hooks );
        }
 
        public function appendVariables( $property ) {
                $variables = MagicWord::getVariableIDs();
-               $this->getResult()->setIndexedTagName( $variables, 'v' );
+               ApiResult::setIndexedTagName( $variables, 'v' );
 
                return $this->getResult()->addValue( 'query', $property, $variables );
        }
@@ -787,13 +765,15 @@ class ApiQuerySiteinfo extends ApiQueryBase {
        public function appendProtocols( $property ) {
                // Make a copy of the global so we don't try to set the _element key of it - bug 45130
                $protocols = array_values( $this->getConfig()->get( 'UrlProtocols' ) );
-               $this->getResult()->setIndexedTagName( $protocols, 'p' );
+               ApiResult::setIndexedTagName( $protocols, 'p' );
 
                return $this->getResult()->addValue( 'query', $property, $protocols );
        }
 
        public function appendDefaultOptions( $property ) {
-               return $this->getResult()->addValue( 'query', $property, User::getDefaultOptions() );
+               $options = User::getDefaultOptions();
+               $options[ApiResult::META_BC_BOOLS] = array_keys( $options );
+               return $this->getResult()->addValue( 'query', $property, $options );
        }
 
        private function formatParserTags( $item ) {
@@ -812,11 +792,11 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                'subscribers' => array_map( array( 'SpecialVersion', 'arrayToString' ), $subscribers ),
                        );
 
-                       $this->getResult()->setIndexedTagName( $arr['subscribers'], 's' );
+                       ApiResult::setIndexedTagName( $arr['subscribers'], 's' );
                        $data[] = $arr;
                }
 
-               $this->getResult()->setIndexedTagName( $data, 'hook' );
+               ApiResult::setIndexedTagName( $data, 'hook' );
 
                return $this->getResult()->addValue( 'query', $property, $data );
        }
@@ -888,6 +868,6 @@ class ApiQuerySiteinfo extends ApiQueryBase {
        }
 
        public function getHelpUrls() {
-               return 'https://www.mediawiki.org/wiki/API:Meta#siteinfo_.2F_si';
+               return 'https://www.mediawiki.org/wiki/API:Siteinfo';
        }
 }