X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=blobdiff_plain;f=includes%2Fapi%2FApiMain.php;h=ae3f3f2458fabea074b8e2e2c3dd7c28dfc4a1ef;hb=6244b8c23a7c15be3d9de2130d290a2437bb6587;hp=592df534da63f798f1afba3b1f5e5d9c09caeeab;hpb=bbb705a0b1465725cadccb6da70c1d057b6d1885;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 592df534da..ae3f3f2458 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -25,6 +25,8 @@ * @defgroup API API */ +use MediaWiki\Logger\LoggerFactory; + /** * This is the main API class, used for both external and internal processing. * When executed, it will create the requested formatter object, @@ -117,9 +119,9 @@ class ApiMain extends ApiBase { // @codingStandardsIgnoreStart String contenation on "msg" not allowed to break long line /** * List of user roles that are specifically relevant to the API. - * array( 'right' => array ( 'msg' => 'Some message with a $1', - * 'params' => array ( $someVarToSubst ) ), - * ); + * [ 'right' => [ 'msg' => 'Some message with a $1', + * 'params' => [ $someVarToSubst ] ], + * ]; */ private static $mRights = [ 'writeapi' => [ @@ -206,7 +208,7 @@ class ApiMain extends ApiBase { $config->get( 'CrossSiteAJAXdomainExceptions' ) ) ) ) { - MediaWiki\Logger\LoggerFactory::getInstance( 'cors' )->warning( + LoggerFactory::getInstance( 'cors' )->warning( 'Non-whitelisted CORS request with session cookies', [ 'origin' => $originHeader, 'cookies' => $sessionCookies, @@ -1101,18 +1103,7 @@ class ApiMain extends ApiBase { $this->dieUsageMsg( [ 'missingparam', 'token' ] ); } - if ( !$this->getConfig()->get( 'DebugAPI' ) && - array_key_exists( - $module->encodeParamName( 'token' ), - $this->getRequest()->getQueryValues() - ) - ) { - $this->dieUsage( - "The '{$module->encodeParamName( 'token' )}' parameter was " . - 'found in the query string, but must be in the POST body', - 'mustposttoken' - ); - } + $module->requirePostedParameters( [ 'token' ] ); if ( !$module->validateToken( $moduleParams['token'], $moduleParams ) ) { $this->dieUsageMsg( 'sessionfailure' ); @@ -1308,7 +1299,7 @@ class ApiMain extends ApiBase { } if ( $module->isWriteMode() - && in_array( 'bot', $this->getUser()->getGroups() ) + && $this->getUser()->isBot() && wfGetLB()->getServerCount() > 1 ) { $this->checkBotReadOnly(); @@ -1331,9 +1322,9 @@ class ApiMain extends ApiBase { } } - // If a majority of slaves are too lagged then disallow writes - $slaveCount = wfGetLB()->getServerCount() - 1; - if ( $numLagged >= ceil( $slaveCount / 2 ) ) { + // If a majority of replica DBs are too lagged then disallow writes + $replicaCount = wfGetLB()->getServerCount() - 1; + if ( $numLagged >= ceil( $replicaCount / 2 ) ) { $laggedServers = implode( ', ', $laggedServers ); wfDebugLog( 'api-readonly', @@ -1453,6 +1444,7 @@ class ApiMain extends ApiBase { protected function setRequestExpectations( ApiBase $module ) { $limits = $this->getConfig()->get( 'TrxProfilerLimits' ); $trxProfiler = Profiler::instance()->getTransactionProfiler(); + $trxProfiler->setLogger( LoggerFactory::getInstance( 'DBPerformance' ) ); if ( $this->getRequest()->hasSafeMethod() ) { $trxProfiler->setExpectations( $limits['GET'], __METHOD__ ); } elseif ( $this->getRequest()->wasPosted() && !$module->isWriteMode() ) {