diff options
Diffstat (limited to 'includes/api/ApiQuerySiteinfo.php')
-rw-r--r-- | includes/api/ApiQuerySiteinfo.php | 119 |
1 files changed, 94 insertions, 25 deletions
diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index ec503d64..a7767062 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -96,6 +96,9 @@ class ApiQuerySiteinfo extends ApiQueryBase { case 'variables': $fit = $this->appendVariables( $p ); break; + case 'protocols': + $fit = $this->appendProtocols( $p ); + break; default: ApiBase::dieDebug( __METHOD__, "Unknown prop=$p" ); } @@ -111,19 +114,57 @@ class ApiQuerySiteinfo extends ApiQueryBase { } protected function appendGeneralInfo( $property ) { - global $wgContLang; + global $wgContLang, + $wgDisableLangConversion, + $wgDisableTitleConversion; $data = array(); $mainPage = Title::newMainPage(); $data['mainpage'] = $mainPage->getPrefixedText(); - $data['base'] = wfExpandUrl( $mainPage->getFullUrl(), PROTO_CURRENT ); + $data['base'] = wfExpandUrl( $mainPage->getFullURL(), PROTO_CURRENT ); $data['sitename'] = $GLOBALS['wgSitename']; + $data['logo'] = $GLOBALS['wgLogo']; $data['generator'] = "MediaWiki {$GLOBALS['wgVersion']}"; $data['phpversion'] = phpversion(); - $data['phpsapi'] = php_sapi_name(); + $data['phpsapi'] = PHP_SAPI; $data['dbtype'] = $GLOBALS['wgDBtype']; $data['dbversion'] = $this->getDB()->getServerVersion(); + $allowFrom = array( '' ); + $allowException = true; + if ( !$GLOBALS['wgAllowExternalImages'] ) { + if ( $GLOBALS['wgEnableImageWhitelist'] ) { + $data['imagewhitelistenabled'] = ''; + } + $allowFrom = $GLOBALS['wgAllowExternalImagesFrom']; + $allowException = !empty( $allowFrom ); + } + if ( $allowException ) { + $data['externalimages'] = (array)$allowFrom; + $this->getResult()->setIndexedTagName( $data['externalimages'], 'prefix' ); + } + + if ( !$wgDisableLangConversion ) { + $data['langconversion'] = ''; + } + + if ( !$wgDisableTitleConversion ) { + $data['titleconversion'] = ''; + } + + if ( $wgContLang->linkPrefixExtension() ) { + $data['linkprefix'] = wfMessage( 'linkprefix' )->inContentLanguage()->text(); + } else { + $data['linkprefix'] = ''; + } + + $linktrail = $wgContLang->linkTrail(); + if ( $linktrail ) { + $data['linktrail'] = $linktrail; + } else { + $data['linktrail'] = ''; + } + $git = SpecialVersion::getGitHeadSha1( $GLOBALS['IP'] ); if ( $git ) { $data['git-hash'] = $git; @@ -144,15 +185,15 @@ class ApiQuerySiteinfo extends ApiQueryBase { $data['lang'] = $GLOBALS['wgLanguageCode']; $fallbacks = array(); - foreach( $wgContLang->getFallbackLanguages() as $code ) { + foreach ( $wgContLang->getFallbackLanguages() as $code ) { $fallbacks[] = array( 'code' => $code ); } $data['fallback'] = $fallbacks; $this->getResult()->setIndexedTagName( $data['fallback'], 'lang' ); - if( $wgContLang->hasVariants() ) { + if ( $wgContLang->hasVariants() ) { $variants = array(); - foreach( $wgContLang->getVariants() as $code ) { + foreach ( $wgContLang->getVariants() as $code ) { $variants[] = array( 'code' => $code ); } $data['variants'] = $variants; @@ -227,6 +268,11 @@ class ApiQuerySiteinfo extends ApiQueryBase { if ( MWNamespace::isNonincludable( $ns ) ) { $data[$ns]['nonincludable'] = ''; } + + $contentmodel = MWNamespace::getNamespaceContentModel( $ns ); + if ( $contentmodel ) { + $data[$ns]['defaultcontentmodel'] = $contentmodel; + } } $this->getResult()->setIndexedTagName( $data, 'ns' ); @@ -250,6 +296,8 @@ class ApiQuerySiteinfo extends ApiQueryBase { $data[] = $item; } + sort( $data ); + $this->getResult()->setIndexedTagName( $data, 'ns' ); return $this->getResult()->addValue( 'query', $property, $data ); } @@ -314,10 +362,10 @@ class ApiQuerySiteinfo extends ApiQueryBase { $val['language'] = $langNames[$prefix]; } $val['url'] = wfExpandUrl( $row['iw_url'], PROTO_CURRENT ); - if( isset( $row['iw_wikiid'] ) ) { + if ( isset( $row['iw_wikiid'] ) ) { $val['wikiid'] = $row['iw_wikiid']; } - if( isset( $row['iw_api'] ) ) { + if ( isset( $row['iw_api'] ) ) { $val['api'] = $row['iw_api']; } @@ -345,7 +393,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { ); } } else { - list( $host, $lag, $index ) = $lb->getMaxLag(); + list( , $lag, $index ) = $lb->getMaxLag(); $data[] = array( 'host' => $wgShowHostnames ? $lb->getServerName( $index ) @@ -373,11 +421,15 @@ class ApiQuerySiteinfo extends ApiQueryBase { $data['activeusers'] = intval( SiteStats::activeUsers() ); $data['admins'] = intval( SiteStats::numberingroup( 'sysop' ) ); $data['jobs'] = intval( SiteStats::jobs() ); + + wfRunHooks( 'APIQuerySiteInfoStatisticsInfo', array( &$data ) ); + return $this->getResult()->addValue( 'query', $property, $data ); } protected function appendUserGroups( $property, $numberInGroup ) { - global $wgGroupPermissions, $wgAddGroups, $wgRemoveGroups, $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf; + global $wgGroupPermissions, $wgAddGroups, $wgRemoveGroups; + global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf; $data = array(); $result = $this->getResult(); @@ -425,7 +477,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { global $wgFileExtensions; $data = array(); - foreach ( $wgFileExtensions as $ext ) { + foreach ( array_unique( $wgFileExtensions ) as $ext ) { $data[] = array( 'ext' => $ext ); } $this->getResult()->setIndexedTagName( $data, 'fe' ); @@ -457,7 +509,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { } if ( isset( $ext['author'] ) ) { $ret['author'] = is_array( $ext['author'] ) ? - implode( ', ', $ext['author' ] ) : $ext['author']; + implode( ', ', $ext['author'] ) : $ext['author']; } if ( isset( $ext['url'] ) ) { $ret['url'] = $ext['url']; @@ -489,7 +541,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { $data = array( 'url' => $url ? $url : '', - 'text' => $text ? $text : '' + 'text' => $text ? $text : '' ); return $this->getResult()->addValue( 'query', $property, $data ); @@ -513,9 +565,17 @@ class ApiQuerySiteinfo extends ApiQueryBase { public function appendSkins( $property ) { $data = array(); + $usable = Skin::getUsableSkins(); + $default = Skin::normalizeKey( 'default' ); foreach ( Skin::getSkinNames() as $name => $displayName ) { $skin = array( 'code' => $name ); ApiResult::setContent( $skin, $displayName ); + if ( !isset( $usable[$name] ) ) { + $skin['unusable'] = ''; + } + if ( $name === $default ) { + $skin['default'] = ''; + } $data[] = $skin; } $this->getResult()->setIndexedTagName( $data, 'skin' ); @@ -525,7 +585,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { public function appendExtensionTags( $property ) { global $wgParser; $wgParser->firstCallInit(); - $tags = array_map( array( $this, 'formatParserTags'), $wgParser->getTags() ); + $tags = array_map( array( $this, 'formatParserTags' ), $wgParser->getTags() ); $this->getResult()->setIndexedTagName( $tags, 't' ); return $this->getResult()->addValue( 'query', $property, $tags ); } @@ -544,6 +604,14 @@ class ApiQuerySiteinfo extends ApiQueryBase { return $this->getResult()->addValue( 'query', $property, $variables ); } + public function appendProtocols( $property ) { + global $wgUrlProtocols; + // Make a copy of the global so we don't try to set the _element key of it - bug 45130 + $protocols = array_values( $wgUrlProtocols ); + $this->getResult()->setIndexedTagName( $protocols, 'p' ); + return $this->getResult()->addValue( 'query', $property, $protocols ); + } + private function formatParserTags( $item ) { return "<{$item}>"; } @@ -554,7 +622,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { ksort( $myWgHooks ); $data = array(); - foreach ( $myWgHooks as $hook => $hooks ) { + foreach ( $myWgHooks as $hook => $hooks ) { $arr = array( 'name' => $hook, 'subscribers' => array_map( array( 'SpecialVersion', 'arrayToString' ), $hooks ), @@ -596,6 +664,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { 'functionhooks', 'showhooks', 'variables', + 'protocols', ) ), 'filteriw' => array( @@ -621,20 +690,23 @@ class ApiQuerySiteinfo extends ApiQueryBase { ' specialpagealiases - List of special page aliases', ' magicwords - List of magic words and their aliases', ' statistics - Returns site statistics', - " interwikimap - Returns interwiki map (optionally filtered, (optionally localised by using {$p}inlanguagecode))", + " interwikimap - Returns interwiki map " . + "(optionally filtered, (optionally localised by using {$p}inlanguagecode))", ' dbrepllag - Returns database server with the highest replication lag', ' usergroups - Returns user groups and the associated permissions', ' extensions - Returns extensions installed on the wiki', ' fileextensions - Returns list of file extensions allowed to be uploaded', ' rightsinfo - Returns wiki rights (license) information if available', - " languages - Returns a list of languages MediaWiki supports (optionally localised by using {$p}inlanguagecode)", + " languages - Returns a list of languages MediaWiki supports" . + "(optionally localised by using {$p}inlanguagecode)", ' skins - Returns a list of all enabled skins', ' extensiontags - Returns a list of parser extension tags', ' functionhooks - Returns a list of parser function hooks', ' showhooks - Returns a list of all subscribed hooks (contents of $wgHooks)', ' variables - Returns a list of variable IDs', + ' protocols - Returns a list of protocols that are allowed in external links.', ), - 'filteriw' => 'Return only local or only nonlocal entries of the interwiki map', + 'filteriw' => 'Return only local or only nonlocal entries of the interwiki map', 'showalldb' => 'List all database servers, not just the one lagging the most', 'numberingroup' => 'Lists the number of users in user groups', 'inlanguagecode' => 'Language code for localised language names (best effort, use CLDR extension)', @@ -646,9 +718,10 @@ class ApiQuerySiteinfo extends ApiQueryBase { } public function getPossibleErrors() { - return array_merge( parent::getPossibleErrors(), array( - array( 'code' => 'includeAllDenied', 'info' => 'Cannot view all servers info unless $wgShowHostnames is true' ), - ) ); + return array_merge( parent::getPossibleErrors(), array( array( + 'code' => 'includeAllDenied', + 'info' => 'Cannot view all servers info unless $wgShowHostnames is true' + ), ) ); } public function getExamples() { @@ -662,8 +735,4 @@ class ApiQuerySiteinfo extends ApiQueryBase { public function getHelpUrls() { return 'https://www.mediawiki.org/wiki/API:Meta#siteinfo_.2F_si'; } - - public function getVersion() { - return __CLASS__ . ': $Id$'; - } } |