Add licensing for extensions to Special:Version
[lhc/web/wiklou.git] / includes / api / ApiQuerySiteinfo.php
index 464693a..5e9cd08 100644 (file)
@@ -99,6 +99,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 +109,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,9 +117,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
        }
 
        protected function appendGeneralInfo( $property ) {
-               global $wgContLang,
-                       $wgDisableLangConversion,
-                       $wgDisableTitleConversion;
+               global $wgContLang, $wgDisableLangConversion, $wgDisableTitleConversion;
 
                $data = array();
                $mainPage = Title::newMainPage();
@@ -153,8 +154,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'] = '';
                }
 
@@ -237,6 +242,14 @@ 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] );
+               }
+
                wfRunHooks( 'APIQuerySiteInfoGeneralInfo', array( $this, &$data ) );
 
                return $this->getResult()->addValue( 'query', $property, $data );
@@ -276,6 +289,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                }
 
                $this->getResult()->setIndexedTagName( $data, 'ns' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -299,6 +313,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                sort( $data );
 
                $this->getResult()->setIndexedTagName( $data, 'ns' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -314,6 +329,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        }
                }
                $this->getResult()->setIndexedTagName( $data, 'specialpage' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -330,6 +346,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        $data[] = $arr;
                }
                $this->getResult()->setIndexedTagName( $data, 'magicword' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -375,6 +392,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                }
 
                $this->getResult()->setIndexedTagName( $data, 'iw' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -384,7 +402,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();
@@ -406,6 +427,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
 
                $result = $this->getResult();
                $result->setIndexedTagName( $data, 'db' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -446,7 +468,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 );
@@ -472,6 +493,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                }
 
                $result->setIndexedTagName( $data, 'group' );
+
                return $result->addValue( 'query', $property, $data );
        }
 
@@ -483,6 +505,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        $data[] = array( 'ext' => $ext );
                }
                $this->getResult()->setIndexedTagName( $data, 'fe' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -517,18 +540,44 @@ 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 );
        }
 
@@ -562,6 +611,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        $data[] = $lang;
                }
                $this->getResult()->setIndexedTagName( $data, 'lang' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -581,6 +631,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        $data[] = $skin;
                }
                $this->getResult()->setIndexedTagName( $data, 'skin' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -589,6 +640,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 );
        }
 
@@ -597,12 +649,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 );
        }
 
@@ -611,9 +665,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}>";
        }
@@ -635,6 +694,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                }
 
                $this->getResult()->setIndexedTagName( $data, 'hook' );
+
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
@@ -667,6 +727,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                        'showhooks',
                                        'variables',
                                        'protocols',
+                                       'defaultoptions',
                                )
                        ),
                        'filteriw' => array(
@@ -683,6 +744,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
 
        public function getParamDescription() {
                $p = $this->getModulePrefix();
+
                return array(
                        'prop' => array(
                                'Which sysinfo properties to get:',
@@ -692,14 +754,14 @@ 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 " .
+                               ' 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" .
+                               ' 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',
@@ -707,11 +769,13 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                ' 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)',
                );
        }