Merge "mw.Feedback: If the message is posted remotely, link the title correctly"
[lhc/web/wiklou.git] / includes / api / ApiMain.php
index aea441b..2c2dd9a 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 /**
- * Created on Sep 4, 2006
- *
  * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
  *
  * This program is free software; you can redistribute it and/or modify
@@ -57,75 +55,74 @@ class ApiMain extends ApiBase {
         * List of available modules: action name => module class
         */
        private static $Modules = [
-               'login' => 'ApiLogin',
-               'clientlogin' => 'ApiClientLogin',
-               'logout' => 'ApiLogout',
-               'createaccount' => 'ApiAMCreateAccount',
-               'linkaccount' => 'ApiLinkAccount',
-               'unlinkaccount' => 'ApiRemoveAuthenticationData',
-               'changeauthenticationdata' => 'ApiChangeAuthenticationData',
-               'removeauthenticationdata' => 'ApiRemoveAuthenticationData',
-               'resetpassword' => 'ApiResetPassword',
-               'query' => 'ApiQuery',
-               'expandtemplates' => 'ApiExpandTemplates',
-               'parse' => 'ApiParse',
-               'stashedit' => 'ApiStashEdit',
-               'opensearch' => 'ApiOpenSearch',
-               'feedcontributions' => 'ApiFeedContributions',
-               'feedrecentchanges' => 'ApiFeedRecentChanges',
-               'feedwatchlist' => 'ApiFeedWatchlist',
-               'help' => 'ApiHelp',
-               'paraminfo' => 'ApiParamInfo',
-               'rsd' => 'ApiRsd',
-               'compare' => 'ApiComparePages',
-               'tokens' => 'ApiTokens',
-               'checktoken' => 'ApiCheckToken',
-               'cspreport' => 'ApiCSPReport',
-               'validatepassword' => 'ApiValidatePassword',
+               'login' => ApiLogin::class,
+               'clientlogin' => ApiClientLogin::class,
+               'logout' => ApiLogout::class,
+               'createaccount' => ApiAMCreateAccount::class,
+               'linkaccount' => ApiLinkAccount::class,
+               'unlinkaccount' => ApiRemoveAuthenticationData::class,
+               'changeauthenticationdata' => ApiChangeAuthenticationData::class,
+               'removeauthenticationdata' => ApiRemoveAuthenticationData::class,
+               'resetpassword' => ApiResetPassword::class,
+               'query' => ApiQuery::class,
+               'expandtemplates' => ApiExpandTemplates::class,
+               'parse' => ApiParse::class,
+               'stashedit' => ApiStashEdit::class,
+               'opensearch' => ApiOpenSearch::class,
+               'feedcontributions' => ApiFeedContributions::class,
+               'feedrecentchanges' => ApiFeedRecentChanges::class,
+               'feedwatchlist' => ApiFeedWatchlist::class,
+               'help' => ApiHelp::class,
+               'paraminfo' => ApiParamInfo::class,
+               'rsd' => ApiRsd::class,
+               'compare' => ApiComparePages::class,
+               'tokens' => ApiTokens::class,
+               'checktoken' => ApiCheckToken::class,
+               'cspreport' => ApiCSPReport::class,
+               'validatepassword' => ApiValidatePassword::class,
 
                // Write modules
-               'purge' => 'ApiPurge',
-               'setnotificationtimestamp' => 'ApiSetNotificationTimestamp',
-               'rollback' => 'ApiRollback',
-               'delete' => 'ApiDelete',
-               'undelete' => 'ApiUndelete',
-               'protect' => 'ApiProtect',
-               'block' => 'ApiBlock',
-               'unblock' => 'ApiUnblock',
-               'move' => 'ApiMove',
-               'edit' => 'ApiEditPage',
-               'upload' => 'ApiUpload',
-               'filerevert' => 'ApiFileRevert',
-               'emailuser' => 'ApiEmailUser',
-               'watch' => 'ApiWatch',
-               'patrol' => 'ApiPatrol',
-               'import' => 'ApiImport',
-               'clearhasmsg' => 'ApiClearHasMsg',
-               'userrights' => 'ApiUserrights',
-               'options' => 'ApiOptions',
-               'imagerotate' => 'ApiImageRotate',
-               'revisiondelete' => 'ApiRevisionDelete',
-               'managetags' => 'ApiManageTags',
-               'tag' => 'ApiTag',
-               'mergehistory' => 'ApiMergeHistory',
-               'setpagelanguage' => 'ApiSetPageLanguage',
+               'purge' => ApiPurge::class,
+               'setnotificationtimestamp' => ApiSetNotificationTimestamp::class,
+               'rollback' => ApiRollback::class,
+               'delete' => ApiDelete::class,
+               'undelete' => ApiUndelete::class,
+               'protect' => ApiProtect::class,
+               'block' => ApiBlock::class,
+               'unblock' => ApiUnblock::class,
+               'move' => ApiMove::class,
+               'edit' => ApiEditPage::class,
+               'upload' => ApiUpload::class,
+               'filerevert' => ApiFileRevert::class,
+               'emailuser' => ApiEmailUser::class,
+               'watch' => ApiWatch::class,
+               'patrol' => ApiPatrol::class,
+               'import' => ApiImport::class,
+               'clearhasmsg' => ApiClearHasMsg::class,
+               'userrights' => ApiUserrights::class,
+               'options' => ApiOptions::class,
+               'imagerotate' => ApiImageRotate::class,
+               'revisiondelete' => ApiRevisionDelete::class,
+               'managetags' => ApiManageTags::class,
+               'tag' => ApiTag::class,
+               'mergehistory' => ApiMergeHistory::class,
+               'setpagelanguage' => ApiSetPageLanguage::class,
        ];
 
        /**
         * List of available formats: format name => format class
         */
        private static $Formats = [
-               'json' => 'ApiFormatJson',
-               'jsonfm' => 'ApiFormatJson',
-               'php' => 'ApiFormatPhp',
-               'phpfm' => 'ApiFormatPhp',
-               'xml' => 'ApiFormatXml',
-               'xmlfm' => 'ApiFormatXml',
-               'rawfm' => 'ApiFormatJson',
-               'none' => 'ApiFormatNone',
+               'json' => ApiFormatJson::class,
+               'jsonfm' => ApiFormatJson::class,
+               'php' => ApiFormatPhp::class,
+               'phpfm' => ApiFormatPhp::class,
+               'xml' => ApiFormatXml::class,
+               'xmlfm' => ApiFormatXml::class,
+               'rawfm' => ApiFormatJson::class,
+               'none' => ApiFormatNone::class,
        ];
 
-       // @codingStandardsIgnoreStart String contenation on "msg" not allowed to break long line
        /**
         * List of user roles that are specifically relevant to the API.
         * [ 'right' => [ 'msg'    => 'Some message with a $1',
@@ -142,7 +139,6 @@ class ApiMain extends ApiBase {
                        'params' => [ ApiBase::LIMIT_SML2, ApiBase::LIMIT_BIG2 ]
                ]
        ];
-       // @codingStandardsIgnoreEnd
 
        /**
         * @var ApiFormatBase
@@ -1454,7 +1450,7 @@ class ApiMain extends ApiBase {
 
                if ( $module->isWriteMode()
                        && $this->getUser()->isBot()
-                       && wfGetLB()->getServerCount() > 1
+                       && MediaWikiServices::getInstance()->getDBLoadBalancer()->getServerCount() > 1
                ) {
                        $this->checkBotReadOnly();
                }
@@ -1468,7 +1464,7 @@ class ApiMain extends ApiBase {
                $numLagged = 0;
                $lagLimit = $this->getConfig()->get( 'APIMaxLagThreshold' );
                $laggedServers = [];
-               $loadBalancer = wfGetLB();
+               $loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer();
                foreach ( $loadBalancer->getLagTimes() as $serverIndex => $lag ) {
                        if ( $lag > $lagLimit ) {
                                ++$numLagged;
@@ -1477,7 +1473,7 @@ class ApiMain extends ApiBase {
                }
 
                // If a majority of replica DBs are too lagged then disallow writes
-               $replicaCount = wfGetLB()->getServerCount() - 1;
+               $replicaCount = $loadBalancer->getServerCount() - 1;
                if ( $numLagged >= ceil( $replicaCount / 2 ) ) {
                        $laggedServers = implode( ', ', $laggedServers );
                        wfDebugLog(
@@ -1935,7 +1931,7 @@ class ApiMain extends ApiBase {
                        $id = Sanitizer::escapeIdForAttribute( 'main/datatypes', Sanitizer::ID_PRIMARY );
                        $idFallback = Sanitizer::escapeIdForAttribute( 'main/datatypes', Sanitizer::ID_FALLBACK );
                        $headline = Linker::makeHeadline( min( 6, $level ),
-                               ' class="apihelp-header"',
+                               ' class="apihelp-header">',
                                $id,
                                $header,
                                '',
@@ -1963,7 +1959,7 @@ class ApiMain extends ApiBase {
                        $id = Sanitizer::escapeIdForAttribute( 'main/credits', Sanitizer::ID_PRIMARY );
                        $idFallback = Sanitizer::escapeIdForAttribute( 'main/credits', Sanitizer::ID_FALLBACK );
                        $headline = Linker::makeHeadline( min( 6, $level ),
-                               ' class="apihelp-header"',
+                               ' class="apihelp-header">',
                                $id,
                                $header,
                                '',