Merge "Rename Skin::getUsableSkins() to Skin::getAllowedSkins()"
[lhc/web/wiklou.git] / includes / api / ApiQuerySiteinfo.php
index 30d2425..b7796ee 100644 (file)
@@ -78,6 +78,9 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                case 'rightsinfo':
                                        $fit = $this->appendRightsInfo( $p );
                                        break;
+                               case 'restrictions':
+                                       $fit = $this->appendRestrictions( $p );
+                                       break;
                                case 'languages':
                                        $fit = $this->appendLanguages( $p );
                                        break;
@@ -99,6 +102,9 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                case 'protocols':
                                        $fit = $this->appendProtocols( $p );
                                        break;
+                               case 'defaultoptions':
+                                       $fit = $this->appendDefaultOptions( $p );
+                                       break;
                                default:
                                        ApiBase::dieDebug( __METHOD__, "Unknown prop=$p" );
                        }
@@ -106,7 +112,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                // Abuse siprop as a query-continue parameter
                                // and set it to all unprocessed props
                                $this->setContinueEnumParameter( 'prop', implode( '|',
-                                               array_diff( $params['prop'], $done ) ) );
+                                       array_diff( $params['prop'], $done ) ) );
                                break;
                        }
                        $done[] = $p;
@@ -114,21 +120,38 @@ class ApiQuerySiteinfo extends ApiQueryBase {
        }
 
        protected function appendGeneralInfo( $property ) {
-               global $wgContLang,
-                       $wgDisableLangConversion,
-                       $wgDisableTitleConversion;
+               global $wgContLang, $wgDisableLangConversion, $wgDisableTitleConversion;
 
                $data = array();
                $mainPage = Title::newMainPage();
                $data['mainpage'] = $mainPage->getPrefixedText();
                $data['base'] = wfExpandUrl( $mainPage->getFullURL(), PROTO_CURRENT );
                $data['sitename'] = $GLOBALS['wgSitename'];
+
+               // wgLogo can either be a relative or an absolute path
+               // make sure we always return an absolute path
+               $data['logo'] = wfExpandUrl( $GLOBALS['wgLogo'], PROTO_RELATIVE );
+
                $data['generator'] = "MediaWiki {$GLOBALS['wgVersion']}";
                $data['phpversion'] = phpversion();
                $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'] = '';
                }
@@ -138,8 +161,12 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                }
 
                if ( $wgContLang->linkPrefixExtension() ) {
-                       $data['linkprefix'] = wfMessage( 'linkprefix' )->inContentLanguage()->text();
+                       $linkPrefixCharset = $wgContLang->linkPrefixCharset();
+                       $data['linkprefixcharset'] = $linkPrefixCharset;
+                       // For backwards compatability
+                       $data['linkprefix'] = "/^((?>.*[^$linkPrefixCharset]|))(.+)$/sDu";
                } else {
+                       $data['linkprefixcharset'] = '';
                        $data['linkprefix'] = '';
                }
 
@@ -163,10 +190,6 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                // 'case-insensitive' option is reserved for future
                $data['case'] = $GLOBALS['wgCapitalLinks'] ? 'first-letter' : 'case-sensitive';
 
-               if ( isset( $GLOBALS['wgRightsCode'] ) ) {
-                       $data['rightscode'] = $GLOBALS['wgRightsCode'];
-               }
-               $data['rights'] = $GLOBALS['wgRightsText'];
                $data['lang'] = $GLOBALS['wgLanguageCode'];
 
                $fallbacks = array();
@@ -179,7 +202,10 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                if ( $wgContLang->hasVariants() ) {
                        $variants = array();
                        foreach ( $wgContLang->getVariants() as $code ) {
-                               $variants[] = array( 'code' => $code );
+                               $variants[] = array(
+                                       'code' => $code,
+                                       'name' => $wgContLang->getVariantname( $code ),
+                               );
                        }
                        $data['variants'] = $variants;
                        $this->getResult()->setIndexedTagName( $data['variants'], 'lang' );
@@ -222,6 +248,20 @@ class ApiQuerySiteinfo extends ApiQueryBase {
 
                $data['maxuploadsize'] = UploadBase::getMaxUploadSize();
 
+               $data['thumblimits'] = $GLOBALS['wgThumbLimits'];
+               $this->getResult()->setIndexedTagName( $data['thumblimits'], 'limit' );
+               $data['imagelimits'] = array();
+               $this->getResult()->setIndexedTagName( $data['imagelimits'], 'limit' );
+               foreach ( $GLOBALS['wgImageLimits'] as $k => $limit ) {
+                       $data['imagelimits'][$k] = array( 'width' => $limit[0], 'height' => $limit[1] );
+               }
+
+               if ( !empty( $GLOBALS['wgFavicon'] ) ) {
+                       // wgFavicon can either be a relative or an absolute path
+                       // make sure we always return an absolute path
+                       $data['favicon'] = wfExpandUrl( $GLOBALS['wgFavicon'], PROTO_RELATIVE );
+               }
+
                wfRunHooks( 'APIQuerySiteInfoGeneralInfo', array( $this, &$data ) );
 
                return $this->getResult()->addValue( 'query', $property, $data );
@@ -261,6 +301,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                }
 
                $this->getResult()->setIndexedTagName( $data, 'ns' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -281,7 +322,10 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        $data[] = $item;
                }
 
+               sort( $data );
+
                $this->getResult()->setIndexedTagName( $data, 'ns' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -297,6 +341,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        }
                }
                $this->getResult()->setIndexedTagName( $data, 'specialpage' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -313,6 +358,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        $data[] = $arr;
                }
                $this->getResult()->setIndexedTagName( $data, 'magicword' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -340,7 +386,9 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        if ( $row['iw_local'] == '1' ) {
                                $val['local'] = '';
                        }
-                       // $val['trans'] = intval( $row['iw_trans'] ); // should this be exposed?
+                       if ( $row['iw_trans'] == '1' ) {
+                               $val['trans'] = '';
+                       }
                        if ( isset( $langNames[$prefix] ) ) {
                                $val['language'] = $langNames[$prefix];
                        }
@@ -356,6 +404,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                }
 
                $this->getResult()->setIndexedTagName( $data, 'iw' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -365,7 +414,10 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $lb = wfGetLB();
                if ( $includeAll ) {
                        if ( !$wgShowHostnames ) {
-                               $this->dieUsage( 'Cannot view all servers info unless $wgShowHostnames is true', 'includeAllDenied' );
+                               $this->dieUsage(
+                                       'Cannot view all servers info unless $wgShowHostnames is true',
+                                       'includeAllDenied'
+                               );
                        }
 
                        $lags = $lb->getLagTimes();
@@ -387,6 +439,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
 
                $result = $this->getResult();
                $result->setIndexedTagName( $data, 'db' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -404,11 +457,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();
@@ -423,7 +480,6 @@ class ApiQuerySiteinfo extends ApiQueryBase {
 
                                if ( $group == 'user' ) {
                                        $arr['number'] = SiteStats::users();
-
                                // '*' and autopromote groups have no size
                                } elseif ( $group !== '*' && !isset( $wgAutopromote[$group] ) ) {
                                        $arr['number'] = SiteStats::numberInGroup( $group );
@@ -449,6 +505,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                }
 
                $result->setIndexedTagName( $data, 'group' );
+
                return $result->addValue( 'query', $property, $data );
        }
 
@@ -456,10 +513,11 @@ 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' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -494,18 +552,52 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                        $ret['url'] = $ext['url'];
                                }
                                if ( isset( $ext['version'] ) ) {
-                                               $ret['version'] = $ext['version'];
+                                       $ret['version'] = $ext['version'];
                                } elseif ( isset( $ext['svn-revision'] ) &&
                                        preg_match( '/\$(?:Rev|LastChangedRevision|Revision): *(\d+)/',
-                                               $ext['svn-revision'], $m ) )
-                               {
-                                               $ret['version'] = 'r' . $m[1];
+                                               $ext['svn-revision'], $m )
+                               ) {
+                                       $ret['version'] = 'r' . $m[1];
+                               }
+                               if ( isset( $ext['path'] ) ) {
+                                       $extensionPath = dirname( $ext['path'] );
+                                       $gitInfo = new GitInfo( $extensionPath );
+                                       $vcsVersion = $gitInfo->getHeadSHA1();
+                                       if ( $vcsVersion !== false ) {
+                                               $ret['vcs-system'] = 'git';
+                                               $ret['vcs-version'] = $vcsVersion;
+                                               $ret['vcs-url'] = $gitInfo->getHeadViewUrl();
+                                               $ret['vcs-date'] = wfTimestamp( TS_ISO_8601, $gitInfo->getHeadCommitDate() );
+                                       } else {
+                                               $svnInfo = SpecialVersion::getSvnInfo( $extensionPath );
+                                               if ( $svnInfo !== false ) {
+                                                       $ret['vcs-system'] = 'svn';
+                                                       $ret['vcs-version'] = $svnInfo['checkout-rev'];
+                                                       $ret['vcs-url'] = isset( $svnInfo['viewvc-url'] ) ? $svnInfo['viewvc-url'] : '';
+                                               }
+                                       }
+
+                                       if ( SpecialVersion::getExtLicenseFileName( $extensionPath ) ) {
+                                               $ret['license-name'] = isset( $ext['license-name'] ) ? $ext['license-name'] : '';
+                                               $ret['license'] = SpecialPage::getTitleFor(
+                                                       'Version',
+                                                       "License/{$ext['name']}"
+                                               )->getLinkURL();
+                                       }
+
+                                       if ( SpecialVersion::getExtAuthorsFileName( $extensionPath ) ) {
+                                               $ret['credits'] = SpecialPage::getTitleFor(
+                                                       'Version',
+                                                       "Credits/{$ext['name']}"
+                                               )->getLinkURL();
+                                       }
                                }
                                $data[] = $ret;
                        }
                }
 
                $this->getResult()->setIndexedTagName( $data, 'ext' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -526,6 +618,25 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
+       protected function appendRestrictions( $property ) {
+               global $wgRestrictionTypes, $wgRestrictionLevels,
+                       $wgCascadingRestrictionLevels, $wgSemiprotectedRestrictionLevels;
+
+               $data = array(
+                       'types' => $wgRestrictionTypes,
+                       'levels' => $wgRestrictionLevels,
+                       'cascadinglevels' => $wgCascadingRestrictionLevels,
+                       'semiprotectedlevels' => $wgSemiprotectedRestrictionLevels,
+               );
+
+               $this->getResult()->setIndexedTagName( $data['types'], 'type' );
+               $this->getResult()->setIndexedTagName( $data['levels'], 'level' );
+               $this->getResult()->setIndexedTagName( $data['cascadinglevels'], 'level' );
+               $this->getResult()->setIndexedTagName( $data['semiprotectedlevels'], 'level' );
+
+               return $this->getResult()->addValue( 'query', $property, $data );
+       }
+
        public function appendLanguages( $property ) {
                $params = $this->extractRequestParams();
                $langCode = isset( $params['inlanguagecode'] ) ? $params['inlanguagecode'] : '';
@@ -539,6 +650,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        $data[] = $lang;
                }
                $this->getResult()->setIndexedTagName( $data, 'lang' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -558,6 +670,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        $data[] = $skin;
                }
                $this->getResult()->setIndexedTagName( $data, 'skin' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -566,6 +679,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $wgParser->firstCallInit();
                $tags = array_map( array( $this, 'formatParserTags' ), $wgParser->getTags() );
                $this->getResult()->setIndexedTagName( $tags, 't' );
+
                return $this->getResult()->addValue( 'query', $property, $tags );
        }
 
@@ -574,12 +688,14 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $wgParser->firstCallInit();
                $hooks = $wgParser->getFunctionHooks();
                $this->getResult()->setIndexedTagName( $hooks, 'h' );
+
                return $this->getResult()->addValue( 'query', $property, $hooks );
        }
 
        public function appendVariables( $property ) {
                $variables = MagicWord::getVariableIDs();
                $this->getResult()->setIndexedTagName( $variables, 'v' );
+
                return $this->getResult()->addValue( 'query', $property, $variables );
        }
 
@@ -588,9 +704,14 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                // 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 );
        }
 
+       public function appendDefaultOptions( $property ) {
+               return $this->getResult()->addValue( 'query', $property, User::getDefaultOptions() );
+       }
+
        private function formatParserTags( $item ) {
                return "<{$item}>";
        }
@@ -612,6 +733,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                }
 
                $this->getResult()->setIndexedTagName( $data, 'hook' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -637,6 +759,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                        'extensions',
                                        'fileextensions',
                                        'rightsinfo',
+                                       'restrictions',
                                        'languages',
                                        'skins',
                                        'extensiontags',
@@ -644,6 +767,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                        'showhooks',
                                        'variables',
                                        'protocols',
+                                       'defaultoptions',
                                )
                        ),
                        'filteriw' => array(
@@ -660,6 +784,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
 
        public function getParamDescription() {
                $p = $this->getModulePrefix();
+
                return array(
                        'prop' => array(
                                'Which sysinfo properties to get:',
@@ -669,35 +794,41 @@ 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)",
+                               ' restrictions          - Returns information on available restriction (protection) types',
+                               ' 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.',
+                               ' defaultoptions        - Returns the default values for user preferences.',
                        ),
                        '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)',
+                       'inlanguagecode' => 'Language code for localised language names ' .
+                               '(best effort, use CLDR extension)',
                );
        }
 
        public function getDescription() {
-               return 'Return general information about the site';
+               return 'Return general information about the site.';
        }
 
        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() {